|
@@ -11,6 +11,8 @@ import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.mapper.AssoStructurePictureMapper;
|
|
|
import cn.cslg.pas.mapper.StructureMapper;
|
|
|
import cn.cslg.pas.service.IStructureService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -18,8 +20,10 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 架构的Service层接口实现类
|
|
@@ -30,7 +34,7 @@ import java.util.List;
|
|
|
@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class StructureServiceImpl implements IStructureService {
|
|
|
+public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure> implements IStructureService {
|
|
|
private final StructureMapper structureMapper;
|
|
|
private final AssoStructurePictureMapper assoStructurePictureMapper;
|
|
|
private final FileUtils fileUtils;
|
|
@@ -135,6 +139,8 @@ public class StructureServiceImpl implements IStructureService {
|
|
|
throw new XiaoShiException(message);
|
|
|
}
|
|
|
|
|
|
+ Integer oldParentId = queryResult.getParentId();
|
|
|
+ String oldPath = queryResult.getPath();
|
|
|
Integer newParentId = structureUpdateDTO.getParentId();
|
|
|
String newStructureName = structureUpdateDTO.getStructureName();
|
|
|
//检查名称是否被占用(检查当前尝试修改的架构父级下是否有同名架构)
|
|
@@ -153,9 +159,12 @@ public class StructureServiceImpl implements IStructureService {
|
|
|
if (parentPath == null) {
|
|
|
parentPath = "0";
|
|
|
}
|
|
|
- String oldPath = queryResult.getPath();
|
|
|
+
|
|
|
+ //该架构新的path路径
|
|
|
String newPath = parentPath + "," + structureId;
|
|
|
- if (!newPath.equals(oldPath)) {
|
|
|
+ //如果新路径和原路径不一样,则表示架构更换了父级
|
|
|
+ if (!oldParentId.equals(newParentId)) {
|
|
|
+ structure.setParentId(newParentId);
|
|
|
structure.setPath(newPath);
|
|
|
}
|
|
|
|
|
@@ -169,7 +178,6 @@ public class StructureServiceImpl implements IStructureService {
|
|
|
}
|
|
|
|
|
|
//如果当前修改的架构更换了父级,则要将当前架构下所有子级架构的路径也都更新
|
|
|
- Integer oldParentId = queryResult.getParentId();
|
|
|
if (!oldParentId.equals(newParentId)) {
|
|
|
//根据当前架构原来的路径查询所有子级架构
|
|
|
List<StructureVO> structures = structureMapper.selectByFindInSetPath(oldPath);
|
|
@@ -254,13 +262,38 @@ public class StructureServiceImpl implements IStructureService {
|
|
|
@Override
|
|
|
public StructureVO query(StructureQueryPageDTO structureQueryPageDTO) {
|
|
|
log.info("开始处理【查询架构树】的业务,参数为:{}", structureQueryPageDTO);
|
|
|
-
|
|
|
- //从DTO中取出产品id、架构id、架构名称
|
|
|
+ StructureVO structureVO = new StructureVO();
|
|
|
+ //从DTO中取出产品id、架构id
|
|
|
Integer productId = structureQueryPageDTO.getProductId();
|
|
|
Integer structureId = structureQueryPageDTO.getStructureId();
|
|
|
-
|
|
|
- StructureVO structureVO = new StructureVO();
|
|
|
- diGui(structureVO, structureId, productId);
|
|
|
+ if (structureId == null) {
|
|
|
+ structureId = 0;
|
|
|
+ }
|
|
|
+ String structureName = structureQueryPageDTO.getStructureName();
|
|
|
+ LambdaQueryWrapper<Structure> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (structureName != null) {
|
|
|
+ wrapper.like(Structure::getStructureName, structureQueryPageDTO.getStructureName());
|
|
|
+ }
|
|
|
+ List<Structure> structures = this.list(wrapper);
|
|
|
+ List<Integer> ids = structures.stream().map(Structure::getId).collect(Collectors.toList());
|
|
|
+ List<String> paths = structures.stream().map(Structure::getPath).collect(Collectors.toList());
|
|
|
+ paths.forEach(
|
|
|
+ item -> {
|
|
|
+ String[] pathStrs = item.split(",");
|
|
|
+ List<String> pathStr = new ArrayList<>(Arrays.asList(pathStrs));
|
|
|
+ pathStr.forEach(
|
|
|
+ tem -> {
|
|
|
+ Integer paId = Integer.parseInt(tem);
|
|
|
+ if (!ids.contains(paId)) {
|
|
|
+ ids.add(paId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ );
|
|
|
+ if (ids.size() != 0) {
|
|
|
+ diGui(structureVO, structureId, productId, ids);
|
|
|
+ }
|
|
|
return structureVO;
|
|
|
}
|
|
|
|
|
@@ -351,13 +384,14 @@ public class StructureServiceImpl implements IStructureService {
|
|
|
}
|
|
|
|
|
|
//递归组装架构树集合
|
|
|
- private void diGui(StructureVO structureVO, Integer structureId, Integer productId) {
|
|
|
- List<StructureVO> structureVOs = structureMapper.selectByParentIdAndProductId(structureId, productId);
|
|
|
+ //递归组装架构树集合
|
|
|
+ private void diGui(StructureVO structureVO, Integer structureId, Integer productId, List<Integer> ids) {
|
|
|
+ List<StructureVO> structureVOs = structureMapper.selectByParentIdAndProductId(structureId, productId, ids);
|
|
|
if (structureVOs != null) {
|
|
|
structureVO.setChildren(structureVOs);
|
|
|
for (StructureVO n : structureVOs) {
|
|
|
structureId = n.getId();
|
|
|
- diGui(n, structureId, productId);
|
|
|
+ diGui(n, structureId, productId, ids);
|
|
|
}
|
|
|
}
|
|
|
}
|