|
@@ -2,6 +2,7 @@ package cn.cslg.pas.service.business;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.business.QueryTreeNodeDTO;
|
|
|
import cn.cslg.pas.common.dto.business.TreeNodeDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.UpdateTreeNodeDTO;
|
|
|
import cn.cslg.pas.common.model.cronModel.*;
|
|
|
import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
@@ -100,7 +101,7 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
*/
|
|
|
@Override
|
|
|
public Object addMessage(Object object, List<MultipartFile> files) {
|
|
|
- //object to treeNode
|
|
|
+ //object to treeNodeDTO
|
|
|
TreeNodeDTO treeNodeDTO = (TreeNodeDTO) object;
|
|
|
//检测名称是否规范
|
|
|
treeNodeDTO.setName(treeNodeDTO.getName().trim());
|
|
@@ -110,7 +111,7 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
queryWrapper.eq(TreeNode::getName, name);
|
|
|
List<TreeNode> treeNodes = this.list(queryWrapper);
|
|
|
if (treeNodes != null && treeNodes.size() != 0) {
|
|
|
- throw new XiaoShiException("参数错误");
|
|
|
+ throw new XiaoShiException("名称不能重复!");
|
|
|
}
|
|
|
//获取登录人信息
|
|
|
PersonnelVO personnelVO = new PersonnelVO();
|
|
@@ -122,6 +123,28 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
//赋值
|
|
|
TreeNode treeNode = new TreeNode();
|
|
|
BeanUtils.copyProperties(treeNodeDTO, treeNode);
|
|
|
+ Integer parentId = treeNodeDTO.getParentId();
|
|
|
+ //若父id为0,则代表这是顶层id
|
|
|
+ if (parentId.equals(0)) {
|
|
|
+ treeNode.setPath("");
|
|
|
+ treeNode.setLevel(0);
|
|
|
+ } else {//有父id,根据父id获取它的路径,然后加上父id拼接成该条路径
|
|
|
+ TreeNode parentNode = this.getById(parentId);
|
|
|
+ String parentPath = parentNode.getPath();
|
|
|
+ if (parentPath != null) {
|
|
|
+ //父id若为顶层id,则父id没有路径
|
|
|
+ if (parentPath.equals("")) {
|
|
|
+ treeNode.setPath(parentId + "/");
|
|
|
+ treeNode.setLevel(1);
|
|
|
+ } else {
|
|
|
+ //父id不是顶层id,父id有路径
|
|
|
+ treeNode.setPath(parentPath + "/" + parentId + "/");
|
|
|
+ treeNode.setLevel(parentNode.getLevel() + 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("数据库中路径错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
treeNode.setCreateId(personnelVO.getId());
|
|
|
treeNode.insert();
|
|
|
//处理文件
|
|
@@ -182,29 +205,81 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
@Override
|
|
|
public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
//object to treeNode
|
|
|
- TreeNodeDTO treeNodeDTO = (TreeNodeDTO) object;
|
|
|
+ UpdateTreeNodeDTO updateTreeNodeDTO = (UpdateTreeNodeDTO) object;
|
|
|
+ //检测传入参数合理性
|
|
|
+ if (updateTreeNodeDTO == null || updateTreeNodeDTO.getId() == null) {
|
|
|
+ throw new XiaoShiException("传入参数不能为空");
|
|
|
+ }
|
|
|
//获取登录人信息
|
|
|
- PersonnelVO personnelVO;
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
try {
|
|
|
personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
} catch (Exception e) {
|
|
|
throw new UnLoginException("未登录");
|
|
|
}
|
|
|
- treeNodeDTO.setName(treeNodeDTO.getName().trim());
|
|
|
+ TreeNode treeNode = this.getById(updateTreeNodeDTO.getId());
|
|
|
+ //检查名称是否规范
|
|
|
+ updateTreeNodeDTO.setName(updateTreeNodeDTO.getName().trim());
|
|
|
//根据名称查询是否重复
|
|
|
- String name = treeNodeDTO.getName();
|
|
|
+ String name = updateTreeNodeDTO.getName();
|
|
|
LambdaQueryWrapper<TreeNode> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(TreeNode::getName, name);
|
|
|
List<TreeNode> treeNodes = this.list(queryWrapper);
|
|
|
- if (treeNodes == null && treeNodes.size() == 0) {
|
|
|
- return null;
|
|
|
+ if (!updateTreeNodeDTO.getName().equals(treeNode.getName()) && treeNodes.size() != 0) {
|
|
|
+ throw new XiaoShiException("节点名称重复");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(updateTreeNodeDTO, treeNode);
|
|
|
+ Integer parentId = updateTreeNodeDTO.getParentId();
|
|
|
+ //若父id为0,则代表这是顶层id
|
|
|
+ if (parentId.equals(0)) {
|
|
|
+ treeNode.setPath("");
|
|
|
+ treeNode.setLevel(0);
|
|
|
+ } else {//有父id,根据父id获取它的路径,然后加上父id拼接成该条路径
|
|
|
+ TreeNode parentNode = this.getById(parentId);
|
|
|
+ String parentPath = parentNode.getPath();
|
|
|
+ if (parentPath != null) {
|
|
|
+ //父id若为顶层id,则父id没有路径
|
|
|
+ if (parentPath.equals("")) {
|
|
|
+ treeNode.setPath(parentId + "/");
|
|
|
+ treeNode.setLevel(1);
|
|
|
+ } else {
|
|
|
+ //父id不是顶层id,父id有路径
|
|
|
+ treeNode.setPath(parentPath + parentId + "/");
|
|
|
+ treeNode.setLevel(parentNode.getLevel() + 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("数据库中路径错误");
|
|
|
+ }
|
|
|
}
|
|
|
- //赋值
|
|
|
- TreeNode treeNode = this.getById(treeNodeDTO.getId());
|
|
|
- BeanUtils.copyProperties(treeNodeDTO, treeNode);
|
|
|
- treeNode.setCreateId(null);
|
|
|
//数据入表
|
|
|
- treeNode.insert();
|
|
|
+ treeNode.updateById();
|
|
|
+ /**
|
|
|
+ * 与架构节点有关文件的处理
|
|
|
+ */
|
|
|
+ //根据架构id查询对应的附件id
|
|
|
+ LambdaQueryWrapper<AssoTreeNodeFile> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AssoTreeNodeFile::getTreeNodeId, updateTreeNodeDTO.getId());
|
|
|
+ List<AssoTreeNodeFile> assoFiles = assoTreeNodeFileService.list(wrapper);
|
|
|
+ List<String> fileGuIds = assoFiles.stream().map(AssoTreeNodeFile::getFileGuid).collect(Collectors.toList());
|
|
|
+ //获取更新后的附件ids
|
|
|
+ List<String> updateFileGuIds = new ArrayList<>();
|
|
|
+ if (updateTreeNodeDTO.getGuids() != null && updateTreeNodeDTO.getGuids().size() != 0) {
|
|
|
+ updateFileGuIds = updateTreeNodeDTO.getGuids();
|
|
|
+ fileGuIds.retainAll(updateFileGuIds);
|
|
|
+ }
|
|
|
+ //做差获得被删除的文件id
|
|
|
+ if (fileGuIds.size() != 0) {
|
|
|
+ //根据文件id删除架构与文件关联表记录
|
|
|
+ LambdaQueryWrapper<AssoTreeNodeFile> deleteWrapper = new LambdaQueryWrapper<>();
|
|
|
+ deleteWrapper.in(AssoTreeNodeFile::getFileGuid, fileGuIds);
|
|
|
+ assoTreeNodeFileService.remove(deleteWrapper);
|
|
|
+ //远程删除服务器上的文件
|
|
|
+ try {
|
|
|
+ fileManagerService.deleteFileFromFMS(fileGuIds);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
//处理文件
|
|
|
if (files != null && files.size() != 0) {
|
|
|
try {
|
|
@@ -214,8 +289,7 @@ public class TreeNodeService extends ServiceImpl<TreeNodeMapper, TreeNode> imple
|
|
|
AssoTreeNodeFile assoTreeNodeFile = new AssoTreeNodeFile();
|
|
|
assoTreeNodeFile.setTreeNodeId(treeNode.getId());
|
|
|
assoTreeNodeFile.setFileGuid(item);
|
|
|
- //TODO
|
|
|
- assoTreeNodeFile.setCreateId(null);
|
|
|
+ assoTreeNodeFile.setCreateId(personnelVO.getId());
|
|
|
assoTreeNodeFiles.add(assoTreeNodeFile);
|
|
|
}
|
|
|
if (assoTreeNodeFiles != null && assoTreeNodeFiles.size() != 0) {
|