|
@@ -1,10 +1,13 @@
|
|
|
package cn.cslg.pas.service.impl;
|
|
|
|
|
|
+import cn.cslg.pas.common.model.PersonnelVO;
|
|
|
import cn.cslg.pas.common.model.dto.*;
|
|
|
import cn.cslg.pas.common.model.vo.PathStructureNameVO;
|
|
|
import cn.cslg.pas.common.model.vo.StructurePictureVO;
|
|
|
import cn.cslg.pas.common.model.vo.StructureVO;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
|
+import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
|
|
|
import cn.cslg.pas.domain.Structure;
|
|
|
import cn.cslg.pas.domain.asso.AssoStructurePicture;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
@@ -37,6 +40,8 @@ import java.util.stream.Collectors;
|
|
|
public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure> implements IStructureService {
|
|
|
private final StructureMapper structureMapper;
|
|
|
private final AssoStructurePictureMapper assoStructurePictureMapper;
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
private final FileUtils fileUtils;
|
|
|
|
|
|
/**
|
|
@@ -49,11 +54,6 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
public void addNew(StructureAddNewDTO structureAddNewDTO, List<MultipartFile> files) {
|
|
|
log.info("开始处理【新增架构】的业务,参数为:{}, {}", structureAddNewDTO, files);
|
|
|
|
|
|
- //取出DTO中父级id,若父级id为null则表示该架构为第1级架构,手动给其父级id设为0
|
|
|
- if (structureAddNewDTO.getParentId() == null) {
|
|
|
- structureAddNewDTO.setParentId(0);
|
|
|
- }
|
|
|
-
|
|
|
Integer parentId = structureAddNewDTO.getParentId();
|
|
|
String structureName = structureAddNewDTO.getStructureName();
|
|
|
//检查名称是否被占用(检查当前架构父级下是否有同名架构)
|
|
@@ -68,6 +68,12 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
//DTO对象赋值给实体类
|
|
|
Structure structure = new Structure();
|
|
|
BeanUtils.copyProperties(structureAddNewDTO, structure);
|
|
|
+
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ structure
|
|
|
+ .setCreatePersonId(personnelVO.getId())
|
|
|
+ .setCreatePersonName(personnelVO.getName());
|
|
|
+
|
|
|
//数据入架构表(此时数据暂不含路径path)
|
|
|
log.info("数据入架构表");
|
|
|
int rows = structureMapper.insert(structure);
|
|
@@ -139,10 +145,16 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
throw new XiaoShiException(message);
|
|
|
}
|
|
|
|
|
|
+ //获取该架构原父级id和原路径
|
|
|
Integer oldParentId = queryResult.getParentId();
|
|
|
String oldPath = queryResult.getPath();
|
|
|
+ //获取DTO中该架构当前父级id和父路径
|
|
|
Integer newParentId = structureUpdateDTO.getParentId();
|
|
|
+ String parentPath = structureUpdateDTO.getParentPath();
|
|
|
+ String newPath = parentPath + "," + structureId;
|
|
|
+ //获取DTO中该架构当前名称
|
|
|
String newStructureName = structureUpdateDTO.getStructureName();
|
|
|
+
|
|
|
//检查名称是否被占用(检查当前尝试修改的架构父级下是否有同名架构)
|
|
|
log.info("检查名称是否被占用(检查当前尝试修改的架构父级下是否有同名架构)");
|
|
|
int count = structureMapper.countByparentIdAndStructureName(newParentId, newStructureName, structureId);
|
|
@@ -155,31 +167,14 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
//DTO对象赋值给实体类
|
|
|
Structure structure = new Structure();
|
|
|
BeanUtils.copyProperties(structureUpdateDTO, structure);
|
|
|
- String parentPath = structureUpdateDTO.getParentPath();
|
|
|
- if (parentPath == null) {
|
|
|
- parentPath = "0";
|
|
|
- }
|
|
|
|
|
|
- //该架构新的path路径
|
|
|
- String newPath = parentPath + "," + structureId;
|
|
|
//如果新路径和原路径不一样,则表示架构更换了父级
|
|
|
if (!oldParentId.equals(newParentId)) {
|
|
|
structure.setParentId(newParentId);
|
|
|
structure.setPath(newPath);
|
|
|
- }
|
|
|
-
|
|
|
- //架构表修改数据
|
|
|
- log.info("架构表修改数据");
|
|
|
- int rows = structureMapper.update(structure);
|
|
|
- if (rows != 1) {
|
|
|
- String message = "修改架构失败,服务器忙请稍后再次尝试!";
|
|
|
- log.info("{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
- }
|
|
|
-
|
|
|
- //如果当前修改的架构更换了父级,则要将当前架构下所有子级架构的路径也都更新
|
|
|
- if (!oldParentId.equals(newParentId)) {
|
|
|
+ //还要将当前架构下所有子级架构的路径也都更新
|
|
|
//根据当前架构原来的路径查询所有子级架构
|
|
|
+ log.info("根据当前架构原来的路径查询所有子级架构");
|
|
|
List<StructureVO> structures = structureMapper.selectByFindInSetPath(oldPath);
|
|
|
for (StructureVO n : structures) {
|
|
|
String path = n.getPath();
|
|
@@ -190,7 +185,7 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
Structure structure2 = new Structure();
|
|
|
BeanUtils.copyProperties(n, structure2);
|
|
|
log.info("修改当前已更换父级的架构的子级架构路径path");
|
|
|
- rows = structureMapper.update(structure2);
|
|
|
+ int rows = structureMapper.update(structure2);
|
|
|
if (rows != 1) {
|
|
|
String message = "修改架构失败,修改当前已更换父级的架构的子级架构路径path失败,服务器忙请稍后再次尝试!";
|
|
|
log.info("{}", message);
|
|
@@ -199,6 +194,15 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //架构表修改数据
|
|
|
+ log.info("架构表修改数据");
|
|
|
+ int rows = structureMapper.update(structure);
|
|
|
+ if (rows != 1) {
|
|
|
+ String message = "修改架构失败,服务器忙请稍后再次尝试!";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+
|
|
|
//架构图片关联表删除数据(若有原有图片被删除)
|
|
|
//根据架构id查询出所有原有图片
|
|
|
log.info("根据架构id查询出所有原有图片");
|
|
@@ -217,7 +221,6 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
}
|
|
|
//图片id集合去重,保留下来的即被删除的图片id
|
|
|
oldPictureIds.removeAll(newOldPictureIds);
|
|
|
-
|
|
|
if (oldPictureIds.size() > 0) {
|
|
|
log.info("架构图片关联表删除数据");
|
|
|
rows = assoStructurePictureMapper.deleteByIds(oldPictureIds);
|
|
@@ -262,17 +265,34 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
@Override
|
|
|
public StructureVO query(StructureQueryPageDTO structureQueryPageDTO) {
|
|
|
log.info("开始处理【查询架构树】的业务,参数为:{}", structureQueryPageDTO);
|
|
|
- StructureVO structureVO = new StructureVO();
|
|
|
//从DTO中取出产品id、架构id
|
|
|
Integer productId = structureQueryPageDTO.getProductId();
|
|
|
Integer structureId = structureQueryPageDTO.getStructureId();
|
|
|
- if (structureId == null) {
|
|
|
- structureId = 0;
|
|
|
- }
|
|
|
String structureName = structureQueryPageDTO.getStructureName();
|
|
|
+
|
|
|
+ //查询出当前架构信息
|
|
|
+ StructureVO structureVO = null;
|
|
|
+ if (structureId == 0) {
|
|
|
+ structureVO = new StructureVO();
|
|
|
+ } else {
|
|
|
+ structureVO = structureMapper.getStandardAndPictureById(structureId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //以下代码表示查询所有架构的路径和路径拼接成的架构名称并封装成map集合,从map集合中取值为后面给每一个架构的pathName中文路径赋值
|
|
|
+ List<StructureVO> allStructures = structureMapper.selectAllByProductId(productId);
|
|
|
+ //map存储所有架构id(key)和架构名称(value)
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ for (StructureVO structure : allStructures) {
|
|
|
+ Integer id = structure.getId();
|
|
|
+ String structureStrId = id + "";
|
|
|
+ String name = structure.getStructureName();
|
|
|
+ map.put(structureStrId, name);
|
|
|
+ }
|
|
|
+
|
|
|
+ //以下代码表示若架构名称structureName有值则要根据架构名称模糊查询树,若架构名称structureName为null则表示查询了所有架构(不受影响)
|
|
|
LambdaQueryWrapper<Structure> wrapper = new LambdaQueryWrapper<>();
|
|
|
if (structureName != null) {
|
|
|
- wrapper.like(Structure::getStructureName, structureQueryPageDTO.getStructureName());
|
|
|
+ wrapper.like(Structure::getStructureName, structureName);
|
|
|
}
|
|
|
List<Structure> structures = this.list(wrapper);
|
|
|
List<Integer> ids = structures.stream().map(Structure::getId).collect(Collectors.toList());
|
|
@@ -291,8 +311,9 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
);
|
|
|
}
|
|
|
);
|
|
|
+ //若ids.size == 0,则表示根据名称模糊查询不到数据,则直接返回空structureVO
|
|
|
if (ids.size() != 0) {
|
|
|
- diGui(structureVO, structureId, productId, ids);
|
|
|
+ diGui(structureVO, map, structureId, productId, ids);
|
|
|
}
|
|
|
return structureVO;
|
|
|
}
|
|
@@ -320,6 +341,7 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
}
|
|
|
|
|
|
for (StructureVO structure : structures) {
|
|
|
+ Integer id = structure.getId();
|
|
|
String path = structure.getPath();
|
|
|
//path = path.substring(path.indexOf(",") + 1);
|
|
|
String[] pathSplit = path.split(",");
|
|
@@ -331,6 +353,7 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
builder.append(structureName).append("/");
|
|
|
}
|
|
|
PathStructureNameVO pathStructureNameVO = new PathStructureNameVO()
|
|
|
+ .setId(id)
|
|
|
.setPath(path)
|
|
|
.setPathStructureName(builder + "");
|
|
|
pathStructureNames.add(pathStructureNameVO);
|
|
@@ -384,14 +407,24 @@ public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure
|
|
|
}
|
|
|
|
|
|
//递归组装架构树集合
|
|
|
- //递归组装架构树集合
|
|
|
- private void diGui(StructureVO structureVO, Integer structureId, Integer productId, List<Integer> ids) {
|
|
|
+ private void diGui(StructureVO structureVO, HashMap<String, String> map, Integer structureId, Integer productId, List<Integer> ids) {
|
|
|
List<StructureVO> structureVOs = structureMapper.selectByParentIdAndProductId(structureId, productId, ids);
|
|
|
if (structureVOs != null) {
|
|
|
structureVO.setChildren(structureVOs);
|
|
|
+ //给架构的路径名称pathName进行拼接赋值
|
|
|
+ String path = structureVO.getPath();
|
|
|
+ if (path != null && !path.equals("")) {
|
|
|
+ String[] pathSplit = path.split(",");
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ for (int i = 1; i < pathSplit.length; i++) {
|
|
|
+ String structureName = map.get(pathSplit[i]);
|
|
|
+ builder.append(structureName).append("/");
|
|
|
+ }
|
|
|
+ structureVO.setPathName(builder + "");
|
|
|
+ }
|
|
|
for (StructureVO n : structureVOs) {
|
|
|
structureId = n.getId();
|
|
|
- diGui(n, structureId, productId, ids);
|
|
|
+ diGui(n, map, structureId, productId, ids);
|
|
|
}
|
|
|
}
|
|
|
}
|