Browse Source

4/8 专题库批量新增专利架构标引

chendayu 2 years ago
parent
commit
135515e1db

+ 31 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/AssoStructurePatentAddNewBatchDTO.java

@@ -0,0 +1,31 @@
+package cn.cslg.pas.common.model.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 专题库批量新增标引(一个专题库给多个专利选择同样的多个产品架构)的DTO类
+ *
+ * @Author chenyu
+ * @Date 2023/4/7
+ */
+@Accessors(chain = true)
+@Data
+public class AssoStructurePatentAddNewBatchDTO implements Serializable {
+    /**
+     * 专题库id
+     */
+    private Integer projectId;
+    /**
+     * 多个专利号
+     */
+    private List<String> patentNos;
+    /**
+     * 多个产品架构id和产品id
+     */
+    private List<StructureAndProductIds> structureAndProductIds;
+
+}

+ 26 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/StructureAndProductIds.java

@@ -0,0 +1,26 @@
+package cn.cslg.pas.common.model.dto;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * 新增产品架构id和产品id的DTO类
+ *
+ * @Author chenyu
+ * @Date 2023/4/7
+ */
+@Accessors(chain = true)
+@Data
+public class StructureAndProductIds implements Serializable {
+    /**
+     * 架构id
+     */
+    private Integer structureId;
+    /**
+     * 产品id
+     */
+    private Integer productId;
+
+}

+ 13 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/report/PatentStructuresDTO.java

@@ -0,0 +1,13 @@
+package cn.cslg.pas.common.model.dto.report;
+
+import lombok.Data;
+
+/**
+ * 一个专利对应多个产品架构DTO类
+ *
+ * @Author chenyu
+ * @Date 2023/4/7
+ */
+@Data
+public class PatentStructuresDTO {
+}

+ 10 - 1
PAS/src/main/java/cn/cslg/pas/controller/ProductStructurePatentIndexController.java

@@ -1,6 +1,7 @@
 package cn.cslg.pas.controller;
 
 import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.model.dto.AssoStructurePatentAddNewBatchDTO;
 import cn.cslg.pas.common.model.dto.AssoStructurePatentQueryDTO;
 import cn.cslg.pas.common.model.dto.AssoStructurePatentUpdateDTO;
 import cn.cslg.pas.common.model.vo.AssoStructurePatentVO;
@@ -41,7 +42,15 @@ public class ProductStructurePatentIndexController {
         } catch (XiaoShiException e) {
             return Response.error(e.getMessage());
         }
-        return Response.success("更新标引");
+        return Response.success("更新标引完成");
+    }
+
+    @Operation(summary = "批量新增标引")
+    @PostMapping("/addNewBatch")
+    public String addNewBatch(@RequestBody AssoStructurePatentAddNewBatchDTO assoStructurePatentAddNewBatchDTO) {
+        log.info("开始处理【批量新增标引】的请求,请求参数为:{}", assoStructurePatentAddNewBatchDTO);
+        structurePatentService.addNewBatch(assoStructurePatentAddNewBatchDTO);
+        return Response.success("批量新增标引完成");
     }
 
     @Operation(summary = "查询标引")

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

@@ -1,8 +1,12 @@
 package cn.cslg.pas.service;
 
+import cn.cslg.pas.common.model.dto.AssoStructurePatentAddNewBatchDTO;
 import cn.cslg.pas.common.model.dto.AssoStructurePatentQueryDTO;
 import cn.cslg.pas.common.model.dto.AssoStructurePatentUpdateDTO;
 import cn.cslg.pas.common.model.vo.AssoStructurePatentVO;
+import cn.cslg.pas.domain.asso.AssoStructurePatent;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -12,15 +16,24 @@ import java.util.List;
  * @Author chenyu
  * @Date 2023/3/15
  */
-public interface IStructurePatentService {
+public interface IStructurePatentService extends IService<AssoStructurePatent> {
     /**
      * 更新标引(新增或删除)
      *
      * @param assoStructurePatentUpdateDTO 专题库产品架构专利号标引的修改DTO类对象
      */
+    @Transactional
     void update(AssoStructurePatentUpdateDTO assoStructurePatentUpdateDTO);
 
     /**
+     * 批量新增标引
+     *
+     * @param assoStructurePatentAddNewBatchDTO 专题库批量新增标引(一个专题库给多个专利选择同样的多个产品架构)的DTO类
+     */
+    @Transactional
+    void addNewBatch(AssoStructurePatentAddNewBatchDTO assoStructurePatentAddNewBatchDTO);
+
+    /**
      * 查询标引
      *
      * @param assoStructurePatentQueryDTO 专题库产品架构专利号标引的查询DTO类

+ 55 - 0
PAS/src/main/java/cn/cslg/pas/service/impl/StructurePatentServiceImpl.java

@@ -1,18 +1,22 @@
 package cn.cslg.pas.service.impl;
 
+import cn.cslg.pas.common.model.dto.AssoStructurePatentAddNewBatchDTO;
 import cn.cslg.pas.common.model.dto.AssoStructurePatentQueryDTO;
 import cn.cslg.pas.common.model.dto.AssoStructurePatentUpdateDTO;
+import cn.cslg.pas.common.model.dto.StructureAndProductIds;
 import cn.cslg.pas.common.model.vo.AssoStructurePatentVO;
 import cn.cslg.pas.domain.asso.AssoStructurePatent;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.mapper.asso.AssoStructurePatentMapper;
 import cn.cslg.pas.service.IStructurePatentService;
+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;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -65,6 +69,57 @@ public class StructurePatentServiceImpl extends ServiceImpl<AssoStructurePatentM
     }
 
     /**
+     * 批量新增标引
+     *
+     * @param assoStructurePatentAddNewBatchDTO 专题库批量新增标引(一个专题库给多个专利选择同样的多个产品架构)的DTO类
+     */
+    @Override
+    public void addNewBatch(AssoStructurePatentAddNewBatchDTO assoStructurePatentAddNewBatchDTO) {
+        log.info("开始处理【批量新增标引】的业务,参数为:{}", assoStructurePatentAddNewBatchDTO);
+
+        //专题库id
+        Integer projectId = assoStructurePatentAddNewBatchDTO.getProjectId();
+        //多件专利
+        List<String> patentNos = assoStructurePatentAddNewBatchDTO.getPatentNos();
+        //多件专利共用的架构id和架构所属产品id
+        List<StructureAndProductIds> structureAndProductIds = assoStructurePatentAddNewBatchDTO.getStructureAndProductIds();
+
+        //DTO赋值给实体类
+        ArrayList<AssoStructurePatent> assoStructurePatents = new ArrayList<>();
+        for (String patentNo : patentNos) {
+            for (StructureAndProductIds structureAndProductId : structureAndProductIds) {
+                AssoStructurePatent assoStructurePatent = new AssoStructurePatent()
+                        .setProjectId(projectId)
+                        .setPatentNo(patentNo)
+                        .setStructureId(structureAndProductId.getStructureId())
+                        .setProductId(structureAndProductId.getProductId());
+                assoStructurePatents.add(assoStructurePatent);
+            }
+        }
+
+        //根据专题库id从库中查询数据
+        LambdaQueryWrapper<AssoStructurePatent> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(AssoStructurePatent::getProjectId, projectId);
+        List<AssoStructurePatent> assoStructurePatents2 = this.list(wrapper);
+        if (assoStructurePatents2 != null && assoStructurePatents2.size() > 0) {
+            //遍历查询出来的所有数据,将id改为Null
+            for (AssoStructurePatent assoStructurePatent2 : assoStructurePatents2) {
+                assoStructurePatent2.setId(null);
+            }
+        }
+
+        //集合去重,去重后留下来的数据即为新增的标引就可以直接入库了
+        boolean flag = assoStructurePatents.removeAll(assoStructurePatents2);
+        //若有新增的标引则入库
+        if (flag) {
+            //数据批量插入架构和专利关联表
+            log.info("数据批量插入架构和专利关联表");
+            this.saveBatch(assoStructurePatents);
+        }
+
+    }
+
+    /**
      * 查询标引
      *
      * @param assoStructurePatentQueryDTO 专题库产品架构专利号标引的查询DTO类

+ 1 - 1
PAS/src/main/resources/mapper/AssoEventProjectMapper.xml

@@ -6,7 +6,7 @@
     <!--int deleteByEventIdsAndProjectId(List<Integer> eventIds, Integer projectId);-->
     <delete id="deleteByEventIdsAndProjectId">
         delete
-        from pas.asso_event_project
+        from asso_event_project
         where event_id in (
         <foreach collection="eventIds" item="n" separator=",">
             #{n}

+ 5 - 5
PAS/src/main/resources/mapper/EventMapper.xml

@@ -6,7 +6,7 @@
     <!--int countByNameAndTenantId(String questionName, Integer tenantId);-->
     <select id="countByNameAndTenantId" resultType="int">
         select count(*)
-        from pas.event
+        from event
         where question_name = #{questionName}
           and tenant_id = #{tenantId}
     </select>
@@ -27,9 +27,9 @@
         <if test="projectId != null and projectId != ''">
             , project_id
         </if>
-        from pas.event eve
+        from event eve
         <if test="projectId != null and projectId != ''">
-            join pas.asso_event_project asso on eve.id = asso.event_id
+            join asso_event_project asso on eve.id = asso.event_id
         </if>
         <where>
             <if test="projectId != null and projectId != ''">
@@ -71,7 +71,7 @@
 
     <select id="select1" resultType="string">
         select label
-        from pas.os_system_dict
+        from os_system_dict
         where FIND_IN_SET(value, #{applicationScenario})
           and type = "ENTERPRISE_APPLICATION_SCENARIO"
         order by id
@@ -79,7 +79,7 @@
 
     <select id="select2" resultType="integer">
         select project_id
-        from pas.asso_event_project
+        from asso_event_project
         where event_id = #{eventId}
         order by id
     </select>

+ 6 - 1
PAS/src/main/resources/mapper/StructureMapper.xml

@@ -167,10 +167,15 @@
         <result column="url" property="url"/>
     </resultMap>
 
+    <!--    <select id="selectByParentId3" resultType="integer">-->
+    <!--        select count(*)-->
+    <!--        from asso_structure_patent-->
+    <!--        where structure_id = #{s_id}-->
+    <!--    </select>-->
     <select id="selectByParentId3" resultType="integer">
         select count(*)
         from asso_structure_patent
-        where structure_id = #{s_id}
+        where structure_id in (select id from structure where find_in_set(#{s_id}, path))
     </select>
 
     <!--根据模糊路径查询数据-->