chenyu 2 年 前
コミット
4c18cccb0a

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

@@ -4,6 +4,7 @@ import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.model.dto.StructureAddNewDTO;
 import cn.cslg.pas.common.model.dto.StructureQueryPageDTO;
 import cn.cslg.pas.common.model.dto.StructureUpdateDTO;
+import cn.cslg.pas.common.model.vo.PathStructureNameVO;
 import cn.cslg.pas.common.model.vo.StructureVO;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.exception.XiaoShiException;
@@ -48,14 +49,6 @@ public class StructureController {
         return Response.error("请求参数为null");
     }
 
-    @Operation(summary = "查询架构树")
-    @PostMapping("/query")
-    public String query(@RequestBody StructureQueryPageDTO structureQueryPageDTO) {
-        log.info("开始处理【查询架构树】的请求,请求参数为:{}", structureQueryPageDTO);
-        StructureVO queryResult = structureService.query(structureQueryPageDTO);
-        return Response.success(queryResult);
-    }
-
     @Operation(summary = "修改架构")
     @PostMapping("/update")
     public String update(String jsons, List<MultipartFile> files) {
@@ -72,6 +65,22 @@ public class StructureController {
         return Response.error("请求参数为null");
     }
 
+    @Operation(summary = "查询架构树")
+    @PostMapping("/query")
+    public String query(@RequestBody StructureQueryPageDTO structureQueryPageDTO) {
+        log.info("开始处理【查询架构树】的请求,请求参数为:{}", structureQueryPageDTO);
+        StructureVO queryResult = structureService.query(structureQueryPageDTO);
+        return Response.success(queryResult);
+    }
+
+    @Operation(summary = "查询拼接路径名")
+    @GetMapping("/queryPathStructureName")
+    public String queryPathStructureName(Integer productId) {
+        log.info("开始处理【查询所有架构路径和路径架构名称】的业务,参数为:{}", productId);
+        List<PathStructureNameVO> queryResults = structureService.queryPathStructureName(productId);
+        return Response.success(queryResults);
+    }
+
     @Operation(summary = "删除架构")
     @GetMapping("/delete")
     public String delete(Integer id) {

+ 1 - 1
PAS/src/main/java/cn/cslg/pas/service/IStructureService.java

@@ -46,7 +46,7 @@ public interface IStructureService {
     StructureVO query(StructureQueryPageDTO structureQueryPageDTO);
 
     /**
-     * 查询架构路径和路径架构名称
+     * 查询所有架构路径和路径拼接成的架构名称
      *
      * @return 返回查询到的数据
      */

+ 22 - 25
PAS/src/main/java/cn/cslg/pas/service/impl/StructureServiceImpl.java

@@ -265,15 +265,19 @@ public class StructureServiceImpl implements IStructureService {
     }
 
     /**
-     * 查询架构路径和路径架构名称
+     * 查询所有架构路径和路径拼接成的架构名称
      *
      * @return 返回查询到的数据
      */
     @Override
     public List<PathStructureNameVO> queryPathStructureName(Integer productId) {
-        log.info("开始处理【查询所有架构路径和路径架构名称】的业务");
+        log.info("开始处理【查询所有架构路径和路径架构名称】的业务,参数为:{}", productId);
 
+        ArrayList<PathStructureNameVO> pathStructureNames = new ArrayList<>();
+
+        log.info("根据产品id查询所有架构数据");
         List<StructureVO> structures = structureMapper.selectAllByProductId(productId);
+        //map存储所有架构id(key)和架构名称(value)
         HashMap<String, String> map = new HashMap<>();
         for (StructureVO structure : structures) {
             Integer structureId = structure.getId();
@@ -281,17 +285,25 @@ public class StructureServiceImpl implements IStructureService {
             String structureName = structure.getStructureName();
             map.put(structureStrId, structureName);
         }
+
         for (StructureVO structure : structures) {
             String path = structure.getPath();
-            path = path.substring(path.indexOf(",") + 1);
-            String[] split = path.split(",");
-            for (String id : split) {
-                map.get(id)
+            //path = path.substring(path.indexOf(",") + 1);
+            String[] pathSplit = path.split(",");
+            //String pathStructureName = "";
+            StringBuilder builder = new StringBuilder();
+            for (int i = 1; i < pathSplit.length; i++) {
+                String structureName = map.get(pathSplit[i]);
+                //pathStructureName = pathStructureName + structureName + "/";
+                builder.append(structureName).append("/");
             }
-
+            PathStructureNameVO pathStructureNameVO = new PathStructureNameVO()
+                    .setPath(path)
+                    .setPathStructureName(builder + "");
+            pathStructureNames.add(pathStructureNameVO);
         }
 
-        return null;
+        return pathStructureNames;
     }
 
     /**
@@ -311,11 +323,11 @@ public class StructureServiceImpl implements IStructureService {
             throw new XiaoShiException(message);
         }
 
-        //根据架构id查询其所有子级架构
         ArrayList<Integer> structureIds = new ArrayList<>();
         structureIds.add(id);
+        //根据架构路径查询其所有子级架构
         String path = queryResult.getPath();
-        log.info("根据架构id查询其所有子级架构");
+        log.info("根据架构路径查询其所有子级架构");
         List<StructureVO> structures = structureMapper.selectByFindInSetPath(path);
         for (StructureVO structure : structures) {
             Integer childStructureId = structure.getId();
@@ -325,29 +337,14 @@ public class StructureServiceImpl implements IStructureService {
         //架构和专利关联表删除数据
         log.info("架构和专利关联表删除数据");
         assoStructurePictureMapper.deleteByIds(structureIds);
-//        if (rows != structureIds.size()) {
-//            String message = "删除架构失败,架构和专利关联表删除数据失败,服务器忙请稍后再次尝试";
-//            log.info("{}", message);
-//            throw new XiaoShiException(message);
-//        }
 
         //架构和图片关联表删除数据
         log.info("架构和图片关联表删除数据");
         assoStructurePictureMapper.deleteByStructureIds(structureIds);
-//        if (rows != structureIds.size()) {
-//            String message = "删除架构失败,架构和图片关联表删除数据失败,服务器忙请稍后再次尝试";
-//            log.info("{}", message);
-//            throw new XiaoShiException(message);
-//        }
 
         //架构表删除数据
         log.info("架构表删除数据");
         int rows = structureMapper.deleteByIds(structureIds);
-        if (rows != structureIds.size()) {
-            String message = "删除架构失败,架构表删除数据失败,服务器忙请稍后再次尝试";
-            log.info("{}", message);
-            throw new XiaoShiException(message);
-        }
 
         log.info("删除架构完成");
 

+ 52 - 15
PAS/src/main/resources/mapper/StructureMapper.xml

@@ -17,6 +17,18 @@
         where id = #{id}
     </delete>
 
+    <!--根据id批量删除数据-->
+    <!--int deleteByIds(List<Integer> ids);-->
+    <delete id="deleteByIds">
+        delete
+        from structure
+        where id in (
+        <foreach collection="list" item="n" separator=",">
+            #{n}
+        </foreach>
+        )
+    </delete>
+
     <!--根据id修改数据-->
     <!--int update(Structure structure);-->
     <update id="update">
@@ -56,7 +68,12 @@
     <!--根据id查询数据-->
     <!--Structure selectById(Integer id);-->
     <select id="getStandardById" resultMap="getStandardByIdMap">
-        select id, parent_id, structure_name, path, remark, product_id
+        select id,
+               parent_id,
+               structure_name,
+               path,
+               remark,
+               product_id
         from structure
         where id = #{id}
     </select>
@@ -82,12 +99,12 @@
         from structure
         where parent_id = #{parentId}
           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"/>
@@ -130,17 +147,23 @@
                product_id
         from structure
         where find_in_set(#{findInSetPath}, path)
+        order by id
     </select>
-    <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}, '%')-->
+    <!--        order By LENGTH(path)-->
+    <!--    </select>-->
+
     <resultMap id="selectByFindInSetPathMap" type="cn.cslg.pas.common.model.vo.StructureVO">
         <id column="id" property="id"/>
         <result column="parent_id" property="parentId"/>
@@ -150,4 +173,18 @@
         <result column="product_id" property="productId"/>
     </resultMap>
 
+    <!--根据产品id查询数据-->
+    <!--List<StructureVO> selectAllByProductId(Integer productId);-->
+    <select id="selectAllByProductId" resultMap="selectByFindInSetPathMap">
+        select id,
+               parent_id,
+               structure_name,
+               path,
+               remark,
+               product_id
+        from structure
+        where product_id = #{productId}
+        order by id
+    </select>
+
 </mapper>

+ 9 - 0
PAS/src/test/java/cn/cslg/pas/mapper/StructureMapperTests.java

@@ -92,4 +92,13 @@ public class StructureMapperTests {
         }
     }
 
+    @Test
+    void selectAllByProductId() {
+        List<StructureVO> queryResults = structureMapper.selectAllByProductId(22);
+        log.info("根据产品id查询数据完成,数据信息为:");
+        for (StructureVO queryResult : queryResults) {
+            log.info("{}", queryResult);
+        }
+    }
+
 }

+ 12 - 0
PAS/src/test/java/cn/cslg/pas/service/StructureServiceImplTests.java

@@ -1,12 +1,15 @@
 package cn.cslg.pas.service;
 
 import cn.cslg.pas.common.model.dto.StructureQueryPageDTO;
+import cn.cslg.pas.common.model.vo.PathStructureNameVO;
 import cn.cslg.pas.common.model.vo.StructureVO;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.util.List;
+
 /**
  * @Author 陈宇
  * @Date 2023/3/11
@@ -26,4 +29,13 @@ public class StructureServiceImplTests {
         log.info("{}", queryResult);
     }
 
+    @Test
+    void queryPathStructureName() {
+        List<PathStructureNameVO> queryResults = structureService.queryPathStructureName(22);
+        log.info("查询架构路径和路径架构名称完成,数据信息为:");
+        for (PathStructureNameVO queryResult : queryResults) {
+            log.info("{}", queryResult);
+        }
+    }
+
 }