|
@@ -8,6 +8,8 @@ import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.ReTreeNodeVO;
|
|
|
+import cn.cslg.pas.common.vo.business.ProductVO;
|
|
|
import cn.cslg.pas.common.vo.business.TreeNodeVO;
|
|
|
import cn.cslg.pas.domain.business.AssoTreeNodeFile;
|
|
|
import cn.cslg.pas.domain.business.TreeNode;
|
|
@@ -22,6 +24,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,6 +33,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -65,31 +70,119 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
|
|
|
@Override
|
|
|
public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
|
+ List<String> sqls = formatQueryService.reSqls(queryRequest, "treeNode");
|
|
|
|
|
|
- return null;
|
|
|
+ //根据sql查询节点信息
|
|
|
+ List<TreeNodeVO> treeNodeVOS = this.getBaseMapper().getTreeNodes(sqls.get(0), sqls.get(1), sqls.get(2));
|
|
|
+ //查询节点总数
|
|
|
+ Long total = this.getBaseMapper().getTreeNodeCount(sqls.get(0));
|
|
|
+ //装载节点信息
|
|
|
+ if (treeNodeVOS.size() != 0) {
|
|
|
+ this.loadTreeNode(treeNodeVOS);
|
|
|
+ this.loadPath(treeNodeVOS);
|
|
|
+ }
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(queryRequest.getCurrent());
|
|
|
+ records.setSize(queryRequest.getSize());
|
|
|
+ records.setData(treeNodeVOS);
|
|
|
+ records.setTotal(total);
|
|
|
+ return records;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询树
|
|
|
+ *
|
|
|
+ * @param queryTreeNodeDTO
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Records queryMessage(QueryTreeNodeDTO queryTreeNodeDTO) throws Exception {
|
|
|
+ //返回数据
|
|
|
+ Records records = new Records();
|
|
|
|
|
|
- public Object queryMessage(QueryTreeNodeDTO queryTreeNodeDTO) throws Exception {
|
|
|
+ List<ReTreeNodeVO> reTreeNodeVOS = new ArrayList<>();
|
|
|
Integer type = queryTreeNodeDTO.getType();
|
|
|
Integer typeId = queryTreeNodeDTO.getTypeId();
|
|
|
- Integer id = queryTreeNodeDTO.getId();
|
|
|
- String name = queryTreeNodeDTO.getName();
|
|
|
+
|
|
|
//校验格式
|
|
|
if (type == null || typeId == null) {
|
|
|
throw new XiaoShiException("参数错误");
|
|
|
}
|
|
|
- LambdaQueryWrapper<TreeNode> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(TreeNode::getType,type)
|
|
|
- .eq(TreeNode::getTypeId,typeId);
|
|
|
- if(id!=null){
|
|
|
- queryWrapper.eq(TreeNode::getId,id);
|
|
|
+
|
|
|
+ //
|
|
|
+ List<TreeNodeVO> treeNodes = treeNodeMapper.getTreeNode(queryTreeNodeDTO);
|
|
|
+
|
|
|
+ //如果根据名称查询
|
|
|
+ if (queryTreeNodeDTO.getName() != null) {
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+
|
|
|
+ //当根据名称查出了节点
|
|
|
+ if (treeNodes != null && treeNodes.size() != 0) {
|
|
|
+ List<String> pathStrs = treeNodes.stream().map(TreeNodeVO::getPath).collect(Collectors.toList());
|
|
|
+ List<Integer> nameIds = treeNodes.stream().map(TreeNodeVO::getId).collect(Collectors.toList());
|
|
|
+ ids.addAll(nameIds);
|
|
|
+ pathStrs.forEach(item -> {
|
|
|
+ if (item != null && !item.trim().equals("")) {
|
|
|
+ List<Integer> paths = Arrays.stream(item.split("/")).map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
|
|
|
+ ids.addAll(paths);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //返回树
|
|
|
+ List<TreeNodeVO> treeNodeVOS = treeNodeMapper.getTreeNodeByIds(ids);
|
|
|
+ this.loadTreeNode(treeNodeVOS);
|
|
|
+ reTreeNodeVOS = this.reTrees(treeNodeVOS);
|
|
|
+ records.setData(reTreeNodeVOS);
|
|
|
+ return records;
|
|
|
+ } else {
|
|
|
+ records.setData(reTreeNodeVOS);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
}
|
|
|
- if(name!=null){
|
|
|
- queryWrapper.like(TreeNode::getName,name);
|
|
|
+
|
|
|
+ //返回树
|
|
|
+ this.loadTreeNode(treeNodes);
|
|
|
+ reTreeNodeVOS = this.reTrees(treeNodes);
|
|
|
+ records.setData(reTreeNodeVOS);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载树
|
|
|
+ List<ReTreeNodeVO> reTrees(List<TreeNodeVO> treeNodes) {
|
|
|
+ treeNodes = treeNodes.stream().sorted(Comparator.comparing(TreeNodeVO::getLevel).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ReTreeNodeVO> reTreeNodeVOS = new ArrayList<>();
|
|
|
+ for (TreeNodeVO treeNode : treeNodes) {
|
|
|
+ ReTreeNodeVO reTreeNodeVO = new ReTreeNodeVO();
|
|
|
+ BeanUtils.copyProperties(treeNode, reTreeNodeVO);
|
|
|
+ List<String> pathNames = new ArrayList<>();
|
|
|
+ if (treeNode.getPath() != null && !treeNode.getPath().trim().equals("")) {
|
|
|
+ List<Integer> paths = Arrays.stream(treeNode.getPath().split("/")).map(s -> {
|
|
|
+ if (!s.equals("")) {
|
|
|
+ return Integer.parseInt(s.trim());
|
|
|
+ } else return null;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ for (Integer tem : paths) {
|
|
|
+ TreeNodeVO treeNode1 = treeNodes.stream().filter(item -> item.getId().equals(tem)).findFirst().orElse(null);
|
|
|
+ if (treeNode1 != null) {
|
|
|
+ pathNames.add(treeNode1.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pathNames.size() != 0) {
|
|
|
+ reTreeNodeVO.setPathName("/" + StringUtils.join(pathNames, "/"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ reTreeNodeVO.setPathName("/");
|
|
|
+ }
|
|
|
+ List<ReTreeNodeVO> childReTreeNodeVOs = reTreeNodeVOS.stream().filter(item -> item.getParentId().equals(treeNode.getId())).collect(Collectors.toList());
|
|
|
+ reTreeNodeVO.setChild(childReTreeNodeVOs);
|
|
|
+ reTreeNodeVOS.removeAll(childReTreeNodeVOs);
|
|
|
+ reTreeNodeVOS.add(reTreeNodeVO);
|
|
|
}
|
|
|
- List<TreeNode> treeNodes =new ArrayList<>();
|
|
|
- return null;
|
|
|
+
|
|
|
+ return reTreeNodeVOS;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -303,21 +396,25 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
return treeNode.getId();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public GroupVO getGroup(GroupRequest groupRequest, String tableName) throws Exception {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Object addMessage(Object object) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public Object updateMessage(Object object) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void loadTreeNode(List<TreeNodeVO> treeNodeVOS) throws IOException {
|
|
|
List<String> createIds = new ArrayList<>();
|
|
|
List<Integer> ids = new ArrayList<>();
|
|
@@ -356,14 +453,13 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
//查询文件
|
|
|
if (guids.size() != 0) {
|
|
|
String res = fileManagerService.getSystemFileFromFMS(guids);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- systemFiles = JSONObject.parseArray(jsonObject.getString("data"), SystemFile.class);
|
|
|
+ systemFiles = JSONObject.parseArray(res, SystemFile.class);
|
|
|
}
|
|
|
|
|
|
//装载信息
|
|
|
for (TreeNodeVO treeNodeVO : treeNodeVOS) {
|
|
|
//装载人员信息
|
|
|
- Personnel personnel = personnels.stream().filter(item -> item.getGuid().equals(treeNodeVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(treeNodeVO.getCreateId())).findFirst().orElse(null);
|
|
|
if (personnel != null) {
|
|
|
treeNodeVO.setCreateName(personnel.getPersonnelName());
|
|
|
}
|
|
@@ -380,4 +476,132 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //复制节点
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void copy(Integer copiedId, Integer toId, Integer type, Integer typeId) {
|
|
|
+
|
|
|
+//根据id查出树
|
|
|
+ QueryTreeNodeDTO queryTreeNodeDTO1 = new QueryTreeNodeDTO();
|
|
|
+ queryTreeNodeDTO1.setId(copiedId);
|
|
|
+ List<TreeNodeVO> copiedTreeNodeVOs = treeNodeMapper.getTreeNode(queryTreeNodeDTO1);
|
|
|
+ List<ReTreeNodeVO> copiedReTreeNodeVOs = this.reTrees(copiedTreeNodeVOs);
|
|
|
+ Integer level = 0;
|
|
|
+
|
|
|
+ //根据copyId 查询节点
|
|
|
+ if (toId != null) {
|
|
|
+ TreeNode treeNode = this.getById(toId);
|
|
|
+ level = treeNode.getLevel();
|
|
|
+ for (ReTreeNodeVO item : copiedReTreeNodeVOs) {
|
|
|
+ item.setParentId(toId);
|
|
|
+ item.setPath(treeNode.getPath() + "/" + treeNode.getId());
|
|
|
+ item.setLevel(level);
|
|
|
+ item.setType(treeNode.getType());
|
|
|
+ item.setTypeId(treeNode.getTypeId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (ReTreeNodeVO item : copiedReTreeNodeVOs) {
|
|
|
+ item.setParentId(0);
|
|
|
+ item.setPath("");
|
|
|
+ item.setLevel(level);
|
|
|
+ item.setType(type);
|
|
|
+ item.setTypeId(typeId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TreeNodeVO> toTreeNodeVOs = new ArrayList<>();
|
|
|
+ if (toId != null) {
|
|
|
+ QueryTreeNodeDTO queryTreeNodeDTO2 = new QueryTreeNodeDTO();
|
|
|
+ queryTreeNodeDTO2.setId(toId);
|
|
|
+ toTreeNodeVOs = treeNodeMapper.getTreeNode(queryTreeNodeDTO2);
|
|
|
+ }
|
|
|
+ while (copiedReTreeNodeVOs.size() != 0) {
|
|
|
+ List<ReTreeNodeVO> reTreeNodeVOS = new ArrayList<>();
|
|
|
+ for (ReTreeNodeVO reTreeNodeVO : copiedReTreeNodeVOs) {
|
|
|
+ //根据父id查找子节点
|
|
|
+ TreeNodeVO treeNodeVO = toTreeNodeVOs.stream().filter(item -> item.getParentId().equals(reTreeNodeVO.getParentId()) && reTreeNodeVO.getName().equals(reTreeNodeVO.getName())).findFirst().orElse(null);
|
|
|
+
|
|
|
+ //当有相同节点时
|
|
|
+ if (treeNodeVO != null) {
|
|
|
+ BeanUtils.copyProperties(treeNodeVO, reTreeNodeVO);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ TreeNode treeNode1 = new TreeNode();
|
|
|
+ BeanUtils.copyProperties(reTreeNodeVO, treeNode1);
|
|
|
+ treeNode1.setId(null);
|
|
|
+ treeNode1.insert();
|
|
|
+ reTreeNodeVO.setId(treeNode1.getId());
|
|
|
+ }
|
|
|
+//TODO复制相关专利
|
|
|
+ List<ReTreeNodeVO> childNodes = reTreeNodeVO.getChild();
|
|
|
+ if (childNodes != null && childNodes.size() > 0) {
|
|
|
+ childNodes.forEach(item -> {
|
|
|
+ item.setParentId(reTreeNodeVO.getId());
|
|
|
+ item.setPath(reTreeNodeVO.getPath() + "/" + reTreeNodeVO.getId());
|
|
|
+ item.setTypeId(reTreeNodeVO.getTypeId());
|
|
|
+ item.setType(reTreeNodeVO.getType());
|
|
|
+ });
|
|
|
+ reTreeNodeVOS.addAll(childNodes);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ copiedReTreeNodeVOs = reTreeNodeVOS;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void loadPath(List<TreeNodeVO> treeNodeVOS) {
|
|
|
+
|
|
|
+ //装载所有的父节点id
|
|
|
+ List<Integer> parentIds = new ArrayList<>();
|
|
|
+ treeNodeVOS.forEach(item -> {
|
|
|
+ if (item.getPath() != null && !item.getPath().trim().equals("")) {
|
|
|
+ List<Integer> pathIds = Arrays.stream(item.getPath().split("/")).map(s -> {
|
|
|
+ if (!s.equals("")) {
|
|
|
+ return Integer.parseInt(s.trim());
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ parentIds.addAll(pathIds);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //根据父节点id查询
|
|
|
+ List<TreeNode> parentNodes =new ArrayList<>();
|
|
|
+ if(parentIds.size()!=0) {
|
|
|
+ LambdaQueryWrapper<TreeNode> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(TreeNode::getId,parentIds);
|
|
|
+ parentNodes=this.list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载路径
|
|
|
+ for(TreeNodeVO treeNode :treeNodeVOS){
|
|
|
+ List<String> pathNames=new ArrayList<>();
|
|
|
+ if (treeNode.getPath() != null && !treeNode.getPath().trim().equals("")) {
|
|
|
+ List<Integer> paths = Arrays.stream(treeNode.getPath().split("/")).map(s -> {
|
|
|
+ if (!s.equals("")) {
|
|
|
+ return Integer.parseInt(s.trim());
|
|
|
+ } else return null;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ for (Integer tem : paths) {
|
|
|
+ TreeNode treeNode1 = parentNodes.stream().filter(item -> item.getId().equals(tem)).findFirst().orElse(null);
|
|
|
+ if (treeNode1 != null) {
|
|
|
+ pathNames.add(treeNode1.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pathNames.size() != 0) {
|
|
|
+ treeNode.setPathName("/" + StringUtils.join(pathNames, "/"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ treeNode.setPathName("/");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|