首次提交:

创建脑图接口
pull/274/head
guofy12 3 years ago
parent 4899bcdb81
commit 50a8190dc0

@ -1,6 +1,7 @@
package com.server.xm.controller;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.server.xm.entity.XmTop;
import com.server.xm.entity.vo.XmTopVo;
@ -42,5 +43,10 @@ public class XmTopController extends BaseController {
List<XmTop> list = this.xmTopService.queryAll(xmTop);
return getDataTable(list);
}
@PostMapping("/create")
public AjaxResult create(@RequestBody XmTopVo xmTopVo){
this.xmTopService.insert(xmTopVo);
return AjaxResult.success();
}
}

@ -1,6 +1,10 @@
package com.server.xm.entity;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.utils.uuid.UUID;
import com.ruoyi.common.core.web.domain.BaseEntity;
import com.server.xm.entity.vo.XmTopVo;
import org.springframework.context.annotation.Bean;
import java.util.Date;
import java.io.Serializable;
@ -39,10 +43,20 @@ public class XmNode extends BaseEntity {
* 10
*/
private String delFlag;
public XmNode(){}
public XmNode(XmTopVo xmTopVo,String level,String parentId,String topId){
BeanUtils.copyProperties(xmTopVo,this);
// if(null == xmTopVo.getId()){
// this.setId(UUID.randomUUID().toString());
// }
this.setName(xmTopVo.getTopic());
this.setNodeLevel(level);
this.setParentId(parentId);
this.setTopId(topId);
}
public String getId() {
return id;
return this.id;
}
public void setId(String id) {
@ -90,7 +104,7 @@ public class XmNode extends BaseEntity {
}
public String getDelFlag() {
return delFlag;
return null != this.delFlag?this.delFlag : "0";
}
public void setDelFlag(String delFlag) {

@ -1,6 +1,9 @@
package com.server.xm.entity;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.utils.uuid.UUID;
import com.ruoyi.common.core.web.domain.BaseEntity;
import com.server.xm.entity.vo.XmTopVo;
/**
@ -40,9 +43,22 @@ public class XmNodeStyle extends BaseEntity {
*/
private String nodeId;
public XmNodeStyle(){}
public XmNodeStyle(XmTopVo xmTopVo){
this.setId(UUID.randomUUID().toString());
this.setDirection(xmTopVo.getDirection().toString());
this.setIcons(JSON.toJSONString(xmTopVo.getIcons()));
this.setTags(JSON.toJSONString(xmTopVo.getTags()));
this.setMemo(xmTopVo.getMemo());
this.setHyperLink(xmTopVo.getHyperLink());
this.setStyle(JSON.toJSONString(xmTopVo.getStyle()));
this.setNodeId(xmTopVo.getId());
}
public String getId() {
return id;
return this.id;
}
public void setId(String id) {

@ -1,9 +1,12 @@
package com.server.xm.entity;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.domain.BaseEntity;
import com.server.xm.entity.vo.XmTopVo;
import java.util.Date;
import java.io.Serializable;
import java.util.UUID;
/**
* Xmind(XmTop)
@ -22,19 +25,30 @@ public class XmTop extends BaseEntity {
/**
*
*/
private String typeId;
private String type;
/**
*
*/
private String nodeLevel;
private String parentId;
/**
* 10
*/
private String delFlag;
public XmTop(){}
public XmTop(XmTopVo xmTopVo,String level,String parentId){
BeanUtils.copyProperties(xmTopVo,this);
// if(null == xmTopVo.getId()){
// this.setId(UUID.randomUUID().toString());
// }
this.setName(xmTopVo.getTopic());
this.setNodeLevel(level);
this.setParentId(parentId);
}
public String getId() {
return id;
return this.id;
}
public void setId(String id) {
@ -50,11 +64,11 @@ public class XmTop extends BaseEntity {
}
public String getTypeId() {
return typeId;
return type;
}
public void setTypeId(String typeId) {
this.typeId = typeId;
this.type = typeId;
}
public String getNodeLevel() {
@ -66,11 +80,18 @@ public class XmTop extends BaseEntity {
}
public String getDelFlag() {
return delFlag;
return null != this.delFlag ? this.delFlag : "0";
}
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
}

@ -11,6 +11,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class XmTopVo implements Serializable {
private static final long serialVersionUID = 814901162125497459L;
@ -25,7 +26,11 @@ public class XmTopVo implements Serializable {
private List<String> tags;
private List<XmTopVo> children;
public XmTopVo() {}
public XmTopVo() {
if(null == this.id){
this.setId(UUID.randomUUID().toString());
}
}
public XmTopVo(XmTop top, XmNodeStyle style){
//基本信息同步
BeanUtils.copyProperties(top,this);
@ -33,15 +38,16 @@ public class XmTopVo implements Serializable {
this.setIcons(JSON.parseObject(style.getIcons(), ArrayList.class));
this.setStyle(JSON.parseObject(style.getStyle(),Map.class));
this.setTags(JSON.parseObject(style.getTags(),ArrayList.class));
this.setDirection(Integer.parseInt(style.getDirection()));
this.setHyperLink(style.getHyperLink());
this.setMemo(style.getMemo());
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getId() {
return id;
return this.id;
}
public void setId(String id) {

@ -42,7 +42,7 @@ public interface XmTopService {
* @param xmTop
* @return
*/
XmTop insert(XmTop xmTop);
void insert(XmTopVo xmTopVo);
/**
*

@ -1,17 +1,21 @@
package com.server.xm.service.impl;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.server.xm.entity.XmNode;
import com.server.xm.entity.XmNodeStyle;
import com.server.xm.entity.XmTop;
import com.server.xm.entity.vo.XmTopVo;
import com.server.xm.mapper.XmNodeMapper;
import com.server.xm.mapper.XmNodeStyleMapper;
import com.server.xm.mapper.XmTopMapper;
import com.server.xm.service.XmTopService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -26,6 +30,8 @@ public class XmTopServiceImpl implements XmTopService {
private XmTopMapper xmTopMapper;
@Resource
private XmNodeStyleMapper styleMapper;
@Resource
private XmNodeMapper nodeMapper;
/**
* ID
@ -71,15 +77,58 @@ public class XmTopServiceImpl implements XmTopService {
/**
*
*
* @param xmTop
* @param xmTopVo
* @return
*/
@Override
public XmTop insert(XmTop xmTop) {
this.xmTopMapper.insert(xmTop);
return xmTop;
}
@Transactional
public void insert(XmTopVo xmTopVo) {
//查询头两个节点,存入top
List<XmTop> topList = new ArrayList<>();
XmTop topEntity = new XmTop(xmTopVo,"1","-1");
topList.add(topEntity);
List<XmTopVo> secList = xmTopVo.getChildren();
//保存前两节点style
List<XmNodeStyle> styleList = new ArrayList<>();
styleList.add(new XmNodeStyle(xmTopVo));
if(!CollectionUtils.isEmpty(secList)){
List<XmTop> secTopList = secList.stream().map(e -> new XmTop(e,"2",topEntity.getId())).collect(Collectors.toList());
topList.addAll(secTopList);
//保存节点
xmTopMapper.insertBatch(topList);
List<XmNodeStyle> secStyleList = secList.stream().map(e -> new XmNodeStyle(e)).collect(Collectors.toList());
styleList.addAll(secStyleList);
//保存syle
styleMapper.insertBatch(styleList);
//递归下属节点
List<XmNode> nodes = new ArrayList<>();
List<XmNodeStyle> styles = new ArrayList<>();
secList.stream().forEach(e -> {
if(!CollectionUtils.isEmpty(e.getChildren())){
dealInsertNode(e.getChildren(),nodes,styles,3,e.getId(),topEntity.getId());
}
});
//保存
nodeMapper.insertBatch(nodes);
styleMapper.insertBatch(styles);
}
}
private void dealInsertNode(List<XmTopVo> xmTopVoList, List<XmNode> nodeList,List<XmNodeStyle> styleList,Integer level,String parentId,String topId){
final Integer oldLevel = level;
List<XmNode> nodes = xmTopVoList.stream().map(e -> new XmNode(e,oldLevel.toString(),parentId,topId)).collect(Collectors.toList());
nodeList.addAll(nodes);
List<XmNodeStyle> styles = xmTopVoList.stream().map(e -> new XmNodeStyle(e)).collect(Collectors.toList());
styleList.addAll(styles);
Map<String,List<XmTopVo>> map = xmTopVoList.stream().filter(e -> null != e.getChildren()).collect(Collectors.toMap(e ->e.getId(),e->e.getChildren(),(k1,k2) ->k1));
final Integer newLevel = ++level;
map.forEach((k,v) -> {
if(!CollectionUtils.isEmpty(v)){
dealInsertNode(v,nodeList,styleList,newLevel,k,topId);
}
});
}
/**
*
*

@ -29,7 +29,7 @@
CREATE_BY,
UPDATE_BY,
DEL_FLAG
from sev-xmind.xm_node
from xm_node
where ID = #{id}
</select>
@ -46,7 +46,7 @@
CREATE_BY,
UPDATE_BY,
DEL_FLAG
from sev-xmind.xm_node
from xm_node
limit #{offset}
, #{limit}
</select>
@ -55,7 +55,7 @@
<select id="queryAll" resultMap="XmNodeMap">
select
ID, NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY, UPDATE_BY, DEL_FLAG
from sev-xmind.xm_node
from xm_node
<where>
<if test="id != null and id != ''">
and ID = #{id}
@ -95,23 +95,23 @@
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into sev-xmind.xm_node(NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY,
insert into xm_node(ID,NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY,
UPDATE_BY, DEL_FLAG)
values (#{name}, #{typeId}, #{nodeLevel}, #{parentId}, #{topId}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{delFlag})
values (#{id},#{name}, #{typeId}, #{nodeLevel}, #{parentId}, #{topId}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{delFlag})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into sev-xmind.xm_node(NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY,
insert into xm_node(ID,NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY,
UPDATE_BY, DEL_FLAG)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name}, #{entity.typeId}, #{entity.nodeLevel}, #{entity.parentId}, #{entity.topId},
(#{entity.id},#{entity.name}, #{entity.typeId}, #{entity.nodeLevel}, #{entity.parentId}, #{entity.topId},
#{entity.createTime}, #{entity.updateTime}, #{entity.createBy}, #{entity.updateBy}, #{entity.delFlag})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into sev-xmind.xm_node(NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY,
insert into xm_node(NAME, TYPE_ID, NODE_LEVEL, PARENT_ID, TOP_ID, CREATE_TIME, UPDATE_TIME, CREATE_BY,
UPDATE_BY, DEL_FLAG)
values
<foreach collection="entities" item="entity" separator=",">
@ -127,7 +127,7 @@
<!--通过主键修改数据-->
<update id="update">
update sev-xmind.xm_node
update xm_node
<set>
<if test="name != null and name != ''">
NAME = #{name},
@ -166,7 +166,7 @@
<!--通过主键删除-->
<delete id="deleteById">
delete
from sev-xmind.xm_node
from xm_node
where ID = #{id}
</delete>

@ -92,15 +92,15 @@
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into xm_node_style(DIRECTION, HYPER_LINK, ICONS, MEMO, STYLE, TAGS, NODE_ID)
values (#{direction}, #{hyperLink}, #{icons}, #{memo}, #{style}, #{tags}, #{nodeId})
insert into xm_node_style(ID,DIRECTION, HYPER_LINK, ICONS, MEMO, STYLE, TAGS, NODE_ID)
values (#{id},#{direction}, #{hyperLink}, #{icons}, #{memo}, #{style}, #{tags}, #{nodeId})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into xm_node_style(DIRECTION, HYPER_LINK, ICONS, MEMO, STYLE, TAGS, NODE_ID)
insert into xm_node_style(ID,DIRECTION, HYPER_LINK, ICONS, MEMO, STYLE, TAGS, NODE_ID)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.direction}, #{entity.hyperLink}, #{entity.icons}, #{entity.memo}, #{entity.style}, #{entity.tags},
(#{entity.id},#{entity.direction}, #{entity.hyperLink}, #{entity.icons}, #{entity.memo}, #{entity.style}, #{entity.tags},
#{entity.nodeId})
</foreach>
</insert>

@ -68,10 +68,10 @@
and ID = #{id}
</if>
<if test="name != null and name != ''">
and NAME = #{name}
and NAME like concat('%',#{name},'%')
</if>
<if test="typeId != null and typeId != ''">
and TYPE_ID = #{typeId}
and TYPE_ID like concat('%',#{type},'%')
</if>
<if test="nodeLevel != null and nodeLevel != ''">
and NODE_LEVEL = #{nodeLevel}
@ -97,17 +97,17 @@
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into xm_top(NAME, TYPE_ID, NODE_LEVEL, CREATE_TIME, UPDATE_TIME, CREATE_BY, UPDATE_BY,
insert into xm_top(ID,NAME, TYPE_ID, NODE_LEVEL, PARENT_ID,CREATE_TIME, UPDATE_TIME, CREATE_BY, UPDATE_BY,
DEL_FLAG)
values (#{name}, #{typeId}, #{nodeLevel}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{delFlag})
values (#{entity.id},#{name}, #{typeId}, #{nodeLevel},#{entity.parentId}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{delFlag})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into xm_top(NAME, TYPE_ID, NODE_LEVEL, CREATE_TIME, UPDATE_TIME, CREATE_BY, UPDATE_BY,
insert into xm_top(ID,NAME, TYPE_ID, NODE_LEVEL, PARENT_ID,CREATE_TIME, UPDATE_TIME, CREATE_BY, UPDATE_BY,
DEL_FLAG)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name}, #{entity.typeId}, #{entity.nodeLevel}, #{entity.createTime}, #{entity.updateTime},
(#{entity.id},#{entity.name}, #{entity.typeId}, #{entity.nodeLevel},#{entity.parentId}, #{entity.createTime}, #{entity.updateTime},
#{entity.createBy}, #{entity.updateBy}, #{entity.delFlag})
</foreach>
</insert>

Loading…
Cancel
Save