chendayu 2 年之前
父节点
当前提交
542aab4fe2

+ 2 - 2
PAS/src/main/java/cn/cslg/pas/controller/StructureController.java

@@ -67,10 +67,10 @@ public class StructureController {
 
     @Operation(summary = "查询架构树")
     @PostMapping("/query")
-    public String query(@RequestBody StructureQueryPageDTO structureQueryPageDTO) {
+    public Response query(@RequestBody StructureQueryPageDTO structureQueryPageDTO) {
         log.info("开始处理【查询架构树】的请求,请求参数为:{}", structureQueryPageDTO);
         StructureVO queryResult = structureService.query(structureQueryPageDTO);
-        return Response.success(queryResult);
+        return Response.success2(queryResult);
     }
 
     @Operation(summary = "查询拼接路径名")

+ 15 - 2
PAS/src/main/java/cn/cslg/pas/mapper/StructureMapper.java

@@ -2,6 +2,7 @@ package cn.cslg.pas.mapper;
 
 import cn.cslg.pas.common.model.vo.StructureVO;
 import cn.cslg.pas.domain.Structure;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -13,7 +14,7 @@ import java.util.List;
  * @Date 2023/3/10
  */
 @Repository
-public interface StructureMapper {
+public interface StructureMapper extends BaseMapper<Structure> {
     /**
      * 插入数据
      *
@@ -71,7 +72,7 @@ public interface StructureMapper {
      * @param productId 产品id
      * @return 返回查询到的数据
      */
-    List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId);
+    List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId,List<Integer> ids);
 
     /**
      * 根据模糊路径查询数据
@@ -81,6 +82,10 @@ public interface StructureMapper {
      */
     List<StructureVO> selectByFindInSetPath(String findInSetPath);
 
+    /**/
+    /**/
+    List<StructureVO> selectByName(String name);
+
     /**
      * 根据产品id查询数据
      *
@@ -89,4 +94,12 @@ public interface StructureMapper {
      */
     List<StructureVO> selectAllByProductId(Integer productId);
 
+    /**
+     * 根据产品名称模糊查询数据
+     *
+     * @param structureName
+     * @return 返回查询到的数据
+     */
+    List<Structure> getStandardByStructureName(String structureName);
+
 }

+ 46 - 12
PAS/src/main/java/cn/cslg/pas/service/impl/StructureServiceImpl.java

@@ -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);
             }
         }
     }

+ 21 - 21
PAS/src/main/resources/mapper/StructureMapper.xml

@@ -91,20 +91,21 @@
     <!--List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId);-->
     <select id="selectByParentIdAndProductId" resultMap="selectByParentIdMap">
         select id s_id,
-               parent_id,
-               structure_name,
-               path,
-               remark,
-               product_id
+        parent_id,
+        structure_name,
+        path,
+        remark,
+        product_id
         from structure
         where parent_id = #{parentId}
-          and product_id = #{productId}
+        and product_id = #{productId}
+        and id in
+        <foreach collection="ids" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
         order by s_id
     </select>
-<!--    and id in-->
-<!--    <foreach collection="ids" item="item" separator="," open="(" close=")">-->
-<!--        #{item}-->
-<!--    </foreach>-->
+
 
     <resultMap id="selectByParentIdMap" type="cn.cslg.pas.common.model.vo.StructureVO">
         <id column="s_id" property="id"/>
@@ -152,17 +153,16 @@
 
     <!---->
     <!---->
-    <!--    <select id="selectByName" resultMap="selectByFindInSetPathMap">-->
-    <!--        select id,-->
-    <!--               parent_id,-->
-    <!--               structure_name,-->
-    <!--               path,-->
-    <!--               remark,-->
-    <!--               product_id-->
-    <!--        from structure-->
-    <!--        where structure_name like concat('%', #{name}, '%')-->
-    <!--        order By LENGTH(path)-->
-    <!--    </select>-->
+    <select id="selectByName" resultMap="selectByFindInSetPathMap">
+        select id,
+               parent_id,
+               structure_name,
+               path,
+               remark,
+               product_id
+        from structure
+        where structure_name like concat('%', #{name}, '%')
+    </select>
 
     <resultMap id="selectByFindInSetPathMap" type="cn.cslg.pas.common.model.vo.StructureVO">
         <id column="id" property="id"/>