Browse Source

add 商品化专利

zero 1 year ago
parent
commit
d476be74f1

+ 29 - 0
src/main/java/cn/cslg/pas/common/dto/SelectProductDTO.java

@@ -0,0 +1,29 @@
+package cn.cslg.pas.common.dto;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class SelectProductDTO {
+
+    private String name;
+
+    private Double licenseRate;
+
+    private Date marketTime;
+
+    private Integer categoryId;
+
+    private Integer showType;
+
+    private String description;
+
+    private String companyName;
+
+    private String createId;
+
+    private String createName;
+
+    private String categoryName;
+}

+ 14 - 0
src/main/java/cn/cslg/pas/common/dto/SelectProductMapDTO.java

@@ -0,0 +1,14 @@
+package cn.cslg.pas.common.dto;
+
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class SelectProductMapDTO {
+
+    private Map<String,List<SelectProductDTO>> productMap;
+
+    private Long total;
+}

+ 13 - 0
src/main/java/cn/cslg/pas/common/vo/business/SelectProductVO.java

@@ -6,4 +6,17 @@ import lombok.Data;
 public class SelectProductVO {
 
     private String patentNo;
+
+    private String name;
+
+    private String companyName;
+
+    private String categoryName;
+    //0不分组 1类别 2公司
+    private Integer type;
+
+    //页码
+    private Long pageNum;
+    //页的大小
+    private Long pageSize;
 }

+ 8 - 7
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -22,6 +22,7 @@ import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
 import cn.cslg.pas.common.vo.es.EsDateRangeVO;
 import cn.cslg.pas.common.vo.es.EsProductPatentVO;
 import cn.cslg.pas.domain.business.ImportTask;
+import cn.cslg.pas.domain.business.Product;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.factorys.businessFactory.Business;
 import cn.cslg.pas.factorys.businessFactory.BusinessFactory;
@@ -126,13 +127,6 @@ public class PatentController {
         return Response.success(dto);
     }
 
-    @Operation(summary = "根据专利号查询商品化专利")
-    @PostMapping("/selectProductByPatentNo")
-    public Response selectProductByPatentNo(@RequestBody PatentKinVO vo) throws Exception {
-        List<PatentKinDTO> dto = patentService.selectKinByPatentNo(vo);
-        return Response.success(dto);
-    }
-
     @Operation(summary = "查询分页信息")
     @PostMapping("/getPatentPageMessage")
     public Response getPatentPageMessage(@RequestBody StringRequest stringRequest) throws Exception {
@@ -308,6 +302,13 @@ public class PatentController {
     }
 
     //---------------------------------商品化专利----------------
+    @Operation(summary = "根据专利号查询商品化专利")
+    @PostMapping("/selectProductByPatentNo")
+    public Response selectProductByPatentNo(@RequestBody SelectProductVO vo) throws Exception {
+        SelectProductMapDTO mapDTO = patentService.selectProductByPatentNo(vo);
+        return Response.success(mapDTO);
+    }
+
     @Operation(summary = "添加商品化专利")
     @PostMapping("/addProductPatent")
     public Response addProductPatent(@RequestBody EsProductPatentVO vo) throws Exception {

+ 37 - 34
src/main/java/cn/cslg/pas/service/business/ProductService.java

@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
 
 /**
  * 产品的Service层
+ *
  * @Author xiexiang
  * @Date 2023/10/26
  */
@@ -69,8 +70,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Object queryMessage(QueryRequest queryRequest) throws Exception {
-        List<String> sqls = formatQueryService.reSqls(queryRequest,"product");
-       sqls= this.loadSearchSql(sqls);
+        List<String> sqls = formatQueryService.reSqls(queryRequest, "product");
+        sqls = this.loadSearchSql(sqls);
         //根据sql查询产品信息
         List<ProductVO> productVOS = productMapper.getProduct(sqls.get(0), sqls.get(1), sqls.get(2));
         //查询总数
@@ -88,6 +89,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 新增产品
+     *
      * @param object
      * @param files
      * @return
@@ -140,10 +142,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         }
         //判断可见类型:
         Integer showType = productDTO.getShowType();
-        if(showType != 0 && showType != 1){
+        if (showType != 0 && showType != 1) {
             List<String> showPersonIds = productDTO.getShowPersonIds();
             //0所有人可见,1本人可见
-            if(showPersonIds != null && showPersonIds.size() != 0){
+            if (showPersonIds != null && showPersonIds.size() != 0) {
                 for (String showPersonId : showPersonIds) {
                     AssoProductPerson assoProductPerson = new AssoProductPerson();
                     assoProductPerson.setProductId(product.getId());
@@ -161,11 +163,11 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
                 }
             }
         }
-        if(assoProductPeople != null && assoProductPeople.size() != 0){
+        if (assoProductPeople != null && assoProductPeople.size() != 0) {
             assoProductPersonService.saveBatch(assoProductPeople);
         }
         //判断文件是否为空
-        if(files != null && files.size() != 0) {
+        if (files != null && files.size() != 0) {
             try {
                 //调用上传文件接口
                 List<String> guids = fileManagerService.uploadFileGetGuid(files);
@@ -190,6 +192,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 删除产品
+     *
      * @param ids
      * @return
      */
@@ -218,6 +221,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 更新产品
+     *
      * @param object
      * @param files
      * @return
@@ -226,7 +230,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
     public Object updateMessage(Object object, List<MultipartFile> files) {
         //object to updateProductDTO
         UpdateProductDTO updateProductDTO = (UpdateProductDTO) object;
-        if(updateProductDTO == null || updateProductDTO.getId() == null){
+        if (updateProductDTO == null || updateProductDTO.getId() == null) {
             throw new XiaoShiException("参数错误");
         }
         //获取登陆人信息 用于设置创建人
@@ -244,7 +248,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(Product::getName, name);
         List<Product> products = this.list(queryWrapper);
-        if(!updateProductDTO.getName().equals(product.getName()) && products.size() != 0){
+        if (!updateProductDTO.getName().equals(product.getName()) && products.size() != 0) {
             throw new XiaoShiException("名称重复");
         }
         BeanUtils.copyProperties(updateProductDTO, product);
@@ -279,10 +283,10 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         }
         //判断可见类型:
         Integer showType = updateProductDTO.getShowType();
-        if(showType != 0 && showType != 1){
+        if (showType != 0 && showType != 1) {
             List<String> showPersonIds = updateProductDTO.getShowPersonIds();
             //0所有人可见,1本人可见
-            if(showPersonIds != null && showPersonIds.size() != 0){
+            if (showPersonIds != null && showPersonIds.size() != 0) {
                 for (String showPersonId : showPersonIds) {
                     AssoProductPerson assoProductPerson = new AssoProductPerson();
                     assoProductPerson.setProductId(product.getId());
@@ -300,7 +304,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
                 }
             }
         }
-        if(assoProductPeople != null && assoProductPeople.size() != 0){
+        if (assoProductPeople != null && assoProductPeople.size() != 0) {
             assoProductPersonService.saveBatch(assoProductPeople);
         }
         /**
@@ -313,20 +317,20 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         List<String> fileGuIds = assoFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
         //获取更新后的附件ids
         List<String> updateFileGuIds = new ArrayList<>();
-        if(updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0){
+        if (updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0) {
             updateFileGuIds = updateProductDTO.getGuids();
             fileGuIds.retainAll(updateFileGuIds);
         }
         //做差获得被删除的文件id
-        if(fileGuIds.size() != 0){
+        if (fileGuIds.size() != 0) {
             //根据文件id删除产品与文件关联表记录
             LambdaQueryWrapper<AssoProductFile> deleteWrapper = new LambdaQueryWrapper<>();
             deleteWrapper.in(AssoProductFile::getFileGuid, fileGuIds);
             assoProductFileService.remove(deleteWrapper);
             //远程删除服务器上的文件
-            try{
+            try {
                 fileManagerService.deleteFileFromFMS(fileGuIds);
-            } catch (Exception e){
+            } catch (Exception e) {
 
             }
         }
@@ -353,7 +357,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
     }
 
     @Override
-    public GroupVO getGroup(GroupRequest groupRequest,String tableName) throws Exception {
+    public GroupVO getGroup(GroupRequest groupRequest, String tableName) throws Exception {
         return null;
     }
 
@@ -369,6 +373,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     /**
      * 装载productVO
+     *
      * @param productVOS
      * @throws IOException
      */
@@ -377,7 +382,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         List<Integer> ids = new ArrayList<>();
         productVOS.forEach(
                 item -> {
-                    if(item.getCreateId() != null){
+                    if (item.getCreateId() != null) {
                         createIds.add(item.getCreateId());
                     }
                     if (item.getId() != null) {
@@ -409,8 +414,8 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         if (guids.size() != 0) {
             String res = fileManagerService.getSystemFileFromFMS(guids);
             systemFiles = JSONObject.parseArray(res, SystemFile.class);
-            if(systemFiles==null){
-                systemFiles=new ArrayList<>();
+            if (systemFiles == null) {
+                systemFiles = new ArrayList<>();
             }
         }
 
@@ -418,7 +423,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         for (ProductVO productVO : productVOS) {
             //装载人员信息
             Personnel personnel = personnels.stream().filter(item -> item.getId().toString().equals(productVO.getCreateId())).findFirst().orElse(null);
-            if(personnel != null){
+            if (personnel != null) {
                 productVO.setCreateName(personnel.getPersonnelName());
             } else {
                 throw new XiaoShiException("未获取到当前登陆人信息");
@@ -497,21 +502,19 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
 
     //装载查询语句
     //装载查询语句
-    private List<String> loadSearchSql(List<String> sqls){
-        PersonnelVO personnelVO =cacheUtils.getLoginUser(loginUtils.getId());
-        String id =personnelVO.getId();
-        Integer tenantId =personnelVO.getTenantId();
-        String rootSql ="product.create_id="+id+" or(product.show_type =0 and product.tenant_id ="+tenantId+") or ( product.id in (select product_id from asso_product_person where" +
-                " person_id="+id+" and role=0)) or (product.show_type=2 and  product.id in (select product_id from asso_product_person where" +
-                " person_id="+id+" and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
-                " person_id="+id+" and role=2))";
-        if(sqls.get(0)!=null&&!sqls.get(0).equals(""))
-        {
-            sqls.set(0,rootSql+" and"+"("+sqls.get(0)+")");
+    private List<String> loadSearchSql(List<String> sqls) {
+        PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        String id = personnelVO.getId();
+        Integer tenantId = personnelVO.getTenantId();
+        String rootSql = "product.create_id=" + id + " or(product.show_type =0 and product.tenant_id =" + tenantId + ") or ( product.id in (select product_id from asso_product_person where" +
+                " person_id=" + id + " and role=0)) or (product.show_type=2 and  product.id in (select product_id from asso_product_person where" +
+                " person_id=" + id + " and role=1)) or(product.show_type =3 and product.id not in(select product_id from asso_product_person where" +
+                " person_id=" + id + " and role=2))";
+        if (sqls.get(0) != null && !sqls.get(0).equals("")) {
+            sqls.set(0, rootSql + " and" + "(" + sqls.get(0) + ")");
 
-        }
-        else {
-            sqls.set(0,rootSql);
+        } else {
+            sqls.set(0, rootSql);
         }
 
         return sqls;

+ 111 - 4
src/main/java/cn/cslg/pas/service/business/es/EsPatentService.java

@@ -3,11 +3,14 @@ package cn.cslg.pas.service.business.es;
 import cn.cslg.pas.common.core.base.IfConstant;
 import cn.cslg.pas.common.dto.*;
 import cn.cslg.pas.common.dto.business.ContentDetailDTO;
+import cn.cslg.pas.common.model.cronModel.Personnel;
+import cn.cslg.pas.common.model.cronModel.PersonnelVO;
 import cn.cslg.pas.common.model.cronModel.Records;
 import cn.cslg.pas.common.model.request.MapRequest;
 import cn.cslg.pas.common.model.request.OrderDTO;
 import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.model.request.StringRequest;
+import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
 import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
@@ -19,9 +22,15 @@ import cn.cslg.pas.common.vo.PatentWithIdVO;
 import cn.cslg.pas.common.vo.business.PatentKinDetailVO;
 import cn.cslg.pas.common.vo.business.PatentKinVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
+import cn.cslg.pas.common.vo.business.SelectProductVO;
+import cn.cslg.pas.domain.business.Product;
+import cn.cslg.pas.domain.business.ProductCategory;
 import cn.cslg.pas.domain.es.*;
+import cn.cslg.pas.mapper.ProductCategoryMapper;
+import cn.cslg.pas.mapper.ProductMapper;
 import cn.cslg.pas.service.business.CommonService;
 import cn.cslg.pas.service.common.FileManagerService;
+import cn.cslg.pas.service.permissions.PermissionService;
 import cn.cslg.pas.service.query.FormatQueryService;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.SortOrder;
@@ -38,6 +47,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,10 +56,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -60,8 +67,17 @@ public class EsPatentService {
     private final FormatQueryService formatQueryService;
 
     @Autowired
+    private PermissionService permissionService;
+
+    @Autowired
     private FileManagerService fileManagerService;
 
+    @Autowired
+    private ProductMapper productMapper;
+
+    @Autowired
+    private ProductCategoryMapper productCategoryMapper;
+
     /**
      * 根据专利号查询专利详情
      *
@@ -298,6 +314,97 @@ public class EsPatentService {
     }
 
     /**
+     * 根据专利号查询出商品化专利
+     *
+     * @param vo
+     * @return
+     * @throws IOException
+     */
+    public SelectProductMapDTO selectProductByPatentNo(SelectProductVO vo) throws IOException {
+        String patentNo = vo.getPatentNo();
+        Long pageNum = vo.getPageNum();
+        Long pageSize = vo.getPageSize();
+        Integer type = vo.getType();
+        List<SelectProductDTO> list = new ArrayList<>();
+        List<Integer> productIds = new ArrayList<>();
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+        //申请号
+        Query q1 = QueryBuilders.term(t -> t.field("app_no.keyword").value(patentNo));
+        //公开号
+        Query q2 = QueryBuilders.term(t -> t.field("public_no.keyword").value(patentNo));
+        //授权号
+        Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
+        Query bool = QueryBuilders.bool(i -> i.should(q1, q2, q3));
+        builder.query(bool);
+
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        for (Hit<Patent> hit : hits) {
+            Patent patent = hit.source();
+            if (patent.getProductId() != null) {
+                productIds.add(patent.getProductId());
+            }
+        }
+
+        List<Product> products = productMapper.selectBatchIds(productIds);
+        if (!CollectionUtils.isEmpty(products)) {
+            for (Product product : products) {
+                ProductCategory category = new ProductCategory();
+                if (product.getCategoryId() != null) {
+                     category = productCategoryMapper.selectById(product.getCategoryId());
+                }
+                SelectProductDTO dto = new SelectProductDTO();
+                BeanUtils.copyProperties(product, dto);
+                //获取产品类别名称
+                dto.setCategoryName(category.getName());
+                list.add(dto);
+            }
+        }
+
+        List<Personnel> personnels = new ArrayList<>();
+        List<String> createIds = list.stream().map(SelectProductDTO::getCreateId).collect(Collectors.toList());
+        if (!CollectionUtils.isEmpty(createIds)) {
+            String res = permissionService.getPersonnelByIdsFromPCS(createIds);
+            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(res);
+            personnels = com.alibaba.fastjson.JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
+        }
+
+        for (SelectProductDTO dto : list) {
+            //装载创建人人员信息
+            Personnel personnel = personnels.stream().filter(item -> item.getId().equals(dto.getCreateId())).findFirst().orElse(null);
+            if (personnel != null) {
+                dto.setCreateName(personnel.getPersonnelName());
+            }
+        }
+
+        List<SelectProductDTO> sortList = list.stream().sorted(Comparator.comparing(SelectProductDTO::getMarketTime).reversed()).collect(Collectors.toList());
+        List<SelectProductDTO> filterList = sortList.stream().filter(i -> StringUtils.isNotEmpty(vo.getName()) && i.getName().equals(vo.getName()))
+                .filter(i -> StringUtils.isNotEmpty(vo.getCategoryName()) && i.getCategoryName().equals(vo.getCategoryName()))
+                .filter(i -> StringUtils.isNotEmpty(vo.getCompanyName()) && i.getCompanyName().equals(vo.getCompanyName()))
+                .collect(Collectors.toList());
+        SelectProductMapDTO mapDTO = new SelectProductMapDTO();
+        if (type == 0) {
+            Map<String, List<SelectProductDTO>> map = new HashMap<>();
+            List<SelectProductDTO> returnData = filterList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
+            map.put("无分组", returnData);
+            mapDTO.setProductMap(map);
+            mapDTO.setTotal(Long.valueOf(String.valueOf(filterList.size())));
+        } else if (type == 1) {
+            Map<String, List<SelectProductDTO>> collect = filterList.stream().collect(Collectors.groupingBy(SelectProductDTO::getCategoryName));
+            mapDTO.setProductMap(collect);
+            mapDTO.setTotal(Long.valueOf(String.valueOf(collect.keySet().size())));
+        } else if (type == 2) {
+            Map<String, List<SelectProductDTO>> collect = filterList.stream().collect(Collectors.groupingBy(SelectProductDTO::getCompanyName));
+            mapDTO.setProductMap(collect);
+            mapDTO.setTotal(Long.valueOf(String.valueOf(collect.keySet().size())));
+        }
+
+        return mapDTO;
+    }
+
+    /**
      * 根据专利号批量查询专利
      *
      * @param patentNos

+ 12 - 11
src/main/java/cn/cslg/pas/service/business/es/EsProductPatentService.java

@@ -6,16 +6,17 @@ import cn.cslg.pas.common.vo.PatentWithIdVO;
 import cn.cslg.pas.common.vo.es.EsProductPatentVO;
 import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.domain.es.PatentJoin;
+import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.service.query.FormatQueryService;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.InlineScript;
+import co.elastic.clients.elasticsearch._types.Script;
 import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
-import co.elastic.clients.elasticsearch.core.DeleteRequest;
-import co.elastic.clients.elasticsearch.core.SearchRequest;
-import co.elastic.clients.elasticsearch.core.SearchResponse;
-import co.elastic.clients.elasticsearch.core.UpdateRequest;
+import co.elastic.clients.elasticsearch.core.*;
 import co.elastic.clients.elasticsearch.core.search.Hit;
+import co.elastic.clients.json.JsonData;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -60,8 +61,8 @@ public class EsProductPatentService {
 
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public List<Integer> delProductPatent(EsProductPatentVO vo) throws Exception {
-        List<Integer> ids = new ArrayList<>();
         List<Integer> productIds = vo.getProductIds();
+        List<Integer> ids = new ArrayList<>(productIds);
         List<String> patentNos = vo.getPatentNos();
         for (Integer productId : productIds) {
             List<String> productIdList = new ArrayList<>();
@@ -88,19 +89,19 @@ public class EsProductPatentService {
                     productIdList.add(id);
                 }
             }
-
+            this.delProduct(productIdList);
         }
-
         return ids;
     }
 
-    public Integer delProduct(String id) {
-        DeleteRequest request = DeleteRequest.of(i -> i.index("patent").id(id));
+    public Integer delProduct(List<String> ids) {
+        Query query = QueryBuilders.ids(n -> n.values(ids));
+        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").query(query));
         try {
-            client.delete(request);
+            client.deleteByQuery(request);
             return 1;
         } catch (IOException e) {
-            return -1;
+            throw new XiaoShiException("删除失败");
         }
     }
 }