Ver Fonte

3/14 产品类别和产品可视化代码

chendayu há 2 anos atrás
pai
commit
0a2d6ac612

+ 6 - 2
PAS/src/main/java/cn/cslg/pas/common/model/vo/PathStructureNameVO.java

@@ -15,11 +15,15 @@ import java.io.Serializable;
 @Data
 public class PathStructureNameVO implements Serializable {
     /**
-     * 路径
+     * 架构id
+     */
+    private Integer id;
+    /**
+     * 架构路径
      */
     private String path;
     /**
-     * 路径对应的完整架构名称
+     * 架构路径拼接名称
      */
     private String pathStructureName;
 

+ 4 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/ProductVO.java

@@ -60,5 +60,9 @@ public class ProductVO implements Serializable {
      * 产品图片
      */
     private List<ProductPictureVO> pictures;
+    /**
+     * 相关专利数量
+     */
+    private Integer patentNum;
 
 }

+ 17 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/StructureVO.java

@@ -4,6 +4,7 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -29,6 +30,10 @@ public class StructureVO implements Serializable {
      */
     private String path;
     /**
+     * 路径名称
+     */
+    private String pathName;
+    /**
      * 说明
      */
     private String remark;
@@ -44,5 +49,17 @@ public class StructureVO implements Serializable {
      * 子架构集合
      */
     private List<StructureVO> children;
+    /**
+     * 相关专利数量
+     */
+    private Integer patentNum;
+    /**
+     * 创建人名称
+     */
+    private String createPersonName;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
 
 }

+ 17 - 0
PAS/src/main/java/cn/cslg/pas/domain/Structure.java

@@ -8,6 +8,7 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * 元素表实体类
@@ -41,5 +42,21 @@ public class Structure implements Serializable {
      * 产品id
      */
     private Integer productId;
+    /**
+     * 创建人id
+     */
+    private Integer createPersonId;
+    /**
+     * 创建人名称
+     */
+    private String createPersonName;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+    /**
+     * 最后修改时间
+     */
+    private Date modifiedTime;
 
 }

+ 3 - 3
PAS/src/main/java/cn/cslg/pas/mapper/ProductMapper.java

@@ -34,7 +34,6 @@ public interface ProductMapper extends BaseMapper<Product> {
     int deleteById(Integer id);
 
     /**
-     *
      * @param productCategoryId
      * @return
      */
@@ -51,10 +50,11 @@ public interface ProductMapper extends BaseMapper<Product> {
     /**
      * 根据产品名称统计数量
      *
-     * @param productName 产品名称
+     * @param productName       产品名称
+     * @param productCategoryId 产品类别id
      * @return 返回统计到的数量
      */
-    int countByProductName(String productName);
+    int countByProductName(String productName, Integer productCategoryId);
 
     /**
      * 根据id统计数量

+ 10 - 3
PAS/src/main/java/cn/cslg/pas/mapper/StructureMapper.java

@@ -66,13 +66,21 @@ public interface StructureMapper extends BaseMapper<Structure> {
     Structure getStandardById(Integer id);
 
     /**
+     * 根据id查询数据和图片
+     *
+     * @param id 架构id
+     * @return 返回查询到的数据
+     */
+    StructureVO getStandardAndPictureById(Integer id);
+
+    /**
      * 根据父级id和产品id查询数据
      *
      * @param parentId  父级id
      * @param productId 产品id
      * @return 返回查询到的数据
      */
-    List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId,List<Integer> ids);
+    List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId, List<Integer> ids);
 
     /**
      * 根据模糊路径查询数据
@@ -83,8 +91,7 @@ public interface StructureMapper extends BaseMapper<Structure> {
     List<StructureVO> selectByFindInSetPath(String findInSetPath);
 
     /**/
-    /**/
-    List<StructureVO> selectByName(String name);
+    //List<StructureVO> selectByName(String name);
 
     /**
      * 根据产品id查询数据

+ 4 - 3
PAS/src/main/java/cn/cslg/pas/service/impl/ProductServiceImpl.java

@@ -37,7 +37,7 @@ import java.util.List;
 @RequiredArgsConstructor
 @Slf4j
 @Service
-public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>  implements IProductService  {
+public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
     private final ProductMapper productMapper;
     private final AssoProductPictureMapper assoProductPictureMapper;
     private final CacheUtils cacheUtils;
@@ -56,8 +56,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>  imp
 
         //检查产品名称是否被占用
         String productName = productAddNewDTO.getProductName();
+        Integer productCategoryId = productAddNewDTO.getProductCategoryId();
         log.info("检查产品名称是否被占用");
-        int count = productMapper.countByProductName(productName);
+        int count = productMapper.countByProductName(productName, productCategoryId);
         if (count > 0) {
             String message = "新增产品失败,产品名称【" + productName + "】已存在,请尝试更换名称";
             log.info("{}", message);
@@ -65,7 +66,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>  imp
         }
 
         Double licenseRate = productAddNewDTO.getLicenseRate();
-        if (licenseRate < 0 || licenseRate > 1) {
+        if (licenseRate != null && (licenseRate < 0 || licenseRate > 1)) {
             String message = "新增产品失败,许可费率不合法,请填写正确数值";
             log.info("{}", message);
             throw new XiaoShiException(message);

+ 68 - 35
PAS/src/main/java/cn/cslg/pas/service/impl/StructureServiceImpl.java

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

+ 11 - 1
PAS/src/main/resources/mapper/ProductMapper.xml

@@ -50,11 +50,12 @@
     </update>
 
     <!--根据产品名称统计数量-->
-    <!--int countByProductName(String productName);-->
+    <!--int countByProductName(String productName, Integer productCategoryId);-->
     <select id="countByProductName" resultType="int">
         select count(*)
         from product
         where product_name = #{productName}
+          and product_category_id = #{productCategoryId}
     </select>
 
     <!--根据id统计数量-->
@@ -116,6 +117,9 @@
         <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.ProductPictureVO"
                     select="query2" column="p_id">
         </collection>
+        <collection property="patentNum" ofType="integer"
+                    select="query3" column="p_id">
+        </collection>
     </resultMap>
 
     <select id="query2" resultMap="query2Map">
@@ -132,4 +136,10 @@
         <result column="url" property="url"/>
     </resultMap>
 
+    <select id="query3" resultType="integer">
+        select count(*)
+        from asso_product_patent
+        where product_id = #{p_id}
+    </select>
+
 </mapper>

+ 55 - 19
PAS/src/main/resources/mapper/StructureMapper.xml

@@ -5,8 +5,10 @@
     <!--插入数据-->
     <!--int insert(Structure structure);-->
     <insert id="insert" useGeneratedKeys="true" keyProperty="id">
-        insert into structure (parent_id, structure_name, path, remark, product_id)
-        values (#{parentId}, #{structureName}, #{path}, #{remark}, #{productId});
+        insert into structure (parent_id, structure_name, path, remark, product_id, create_person_id,
+                               create_person_name)
+        values (#{parentId}, #{structureName}, #{path}, #{remark}, #{productId}, #{createPersonId},
+                #{createPersonName});
     </insert>
 
     <!--根据id删除数据-->
@@ -73,7 +75,9 @@
                structure_name,
                path,
                remark,
-               product_id
+               product_id,
+               create_person_name,
+               create_time
         from structure
         where id = #{id}
     </select>
@@ -85,24 +89,45 @@
         <result column="path" property="path"/>
         <result column="remark" property="remark"/>
         <result column="product_id" property="productId"/>
+        <result column="create_person_name" property="createPersonName"/>
+        <result column="create_time" property="createTime"/>
     </resultMap>
 
+    <!--根据id查询数据和图片-->
+    <!--StructureVO getStandAndPictureById(Integer id);-->
+    <select id="getStandardAndPictureById" resultMap="selectByParentIdMap">
+        select id,
+               parent_id,
+               structure_name,
+               path,
+               remark,
+               product_id,
+               create_person_name,
+               create_time
+        from structure
+        where id = #{id}
+    </select>
+
     <!--根据父级id和产品id查询数据-->
-    <!--List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId);-->
+    <!--List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId, List<Integer> ids);-->
     <select id="selectByParentIdAndProductId" resultMap="selectByParentIdMap">
         select id s_id,
         parent_id,
         structure_name,
         path,
         remark,
-        product_id
+        product_id,
+        create_person_name,
+        create_time
         from structure
         where parent_id = #{parentId}
         and product_id = #{productId}
-        and id in
-        <foreach collection="ids" item="item" separator="," open="(" close=")">
-            #{item}
-        </foreach>
+        <if test="ids != null">
+            and id in
+            <foreach collection="ids" item="item" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
         order by s_id
     </select>
 
@@ -114,9 +139,14 @@
         <result column="path" property="path"/>
         <result column="remark" property="remark"/>
         <result column="product_id" property="productId"/>
+        <result column="create_person_name" property="createPersonName"/>
+        <result column="create_time" property="createTime"/>
         <collection property="pictures" ofType="cn.cslg.pas.common.model.vo.StructurePictureVO"
                     select="selectByParentId2" column="s_id">
         </collection>
+        <collection property="patentNum" ofType="integer"
+                    select="selectByParentId3" column="s_id">
+        </collection>
     </resultMap>
 
     <select id="selectByParentId2" resultMap="selectByParentIdMap2">
@@ -137,6 +167,12 @@
         <result column="url" property="url"/>
     </resultMap>
 
+    <select id="selectByParentId3" resultType="integer">
+        select count(*)
+        from asso_structure_patent
+        where structure_id = #{s_id}
+    </select>
+
     <!--根据模糊路径查询数据-->
     <!--List<StructureVO> selectByFindInSetPath(String findInSetPath);-->
     <select id="selectByFindInSetPath" resultMap="selectByFindInSetPathMap">
@@ -153,16 +189,16 @@
 
     <!---->
     <!---->
-    <select id="selectByName" resultMap="selectByFindInSetPathMap">
-        select id,
-               parent_id,
-               structure_name,
-               path,
-               remark,
-               product_id
-        from structure
-        where structure_name like concat('%', #{name}, '%')
-    </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"/>