Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

xiexiang 1 anno fa
parent
commit
98b59e6a69

+ 4 - 2
src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java

@@ -7,7 +7,6 @@ public enum ExceptionEnum {
 
     /*APP端 100000-300000*/
     SUCCESS("000000", "调用成功"),
-    SYSTEM_ERROR("999999", "系统异常"),
     PARAMETER_VERIFICATION_ERROR("000001", "数据参数校验异常"),
     PHONE_FORMAT_ERROR("000002","手机号格式错误"),
 
@@ -19,7 +18,10 @@ public enum ExceptionEnum {
     THE_CODE_IS_NOT_NULL("10006","验证码不能为空"),
 
     //异常20000
-    THE_PARAMETER_EXCEPTION("20001", "参数异常,请传入数据");
+    THE_PARAMETER_EXCEPTION("20001", "参数异常,请传入数据"),
+    THE_GET_INFORMATION_TOKEN_INVALID("20002", "获取用信息token失效"),
+    THE_FAIL_TO_DELETE("20003", "删除失败"),
+    SYSTEM_ERROR("999999", "系统异常");
 
     private String code;// 异常代码
     private String message;// 异常信息

+ 54 - 12
src/main/java/com/example/xiaoshiweixinback/controller/PatentController.java

@@ -5,12 +5,16 @@ import com.example.xiaoshiweixinback.business.common.Constants;
 import com.example.xiaoshiweixinback.business.common.Response;
 import com.example.xiaoshiweixinback.business.common.base.Records;
 import com.example.xiaoshiweixinback.business.utils.FileUtils;
+import com.example.xiaoshiweixinback.checkLogin.checkLogin;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO;
+import com.example.xiaoshiweixinback.entity.dto.patent.CollectPatentDTO;
+import com.example.xiaoshiweixinback.entity.dto.patent.DelCollectPatentDTO;
 import com.example.xiaoshiweixinback.entity.dto.patent.ImportTaskAMVO;
+import com.example.xiaoshiweixinback.entity.dto.patent.SelectCollectPatentDTO;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
-import com.example.xiaoshiweixinback.service.common.EsDenseVectorService;
-import com.example.xiaoshiweixinback.service.common.FileManagerService;
+import com.example.xiaoshiweixinback.service.importPatent.EsDenseVectorService;
+import com.example.xiaoshiweixinback.service.importPatent.EsPatentService;
 import com.example.xiaoshiweixinback.service.importPatent.GetPatentFromExcelService;
 import com.example.xiaoshiweixinback.service.importPatent.ImportFromWebToEsService;
 import io.swagger.v3.oas.annotations.Operation;
@@ -20,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 
@@ -31,12 +36,15 @@ public class PatentController {
     private ImportFromWebToEsService importFromWebToEsService;
 
     @Autowired
-    private FileManagerService fileManagerService;
-
-    @Autowired
     private EsDenseVectorService esDenseVectorService;
+
     @Autowired
     private GetPatentFromExcelService getPatentFromExcelService;
+
+    @Autowired
+    private EsPatentService esPatentService;
+
+    //--------------------------- 导入  --------------------------
     @Operation(summary = "导入专利")
     @GetMapping(value = "/importPatent")
     public Response queryPatent(@RequestBody ImportTaskAMVO importTaskAMVO) {
@@ -48,6 +56,18 @@ public class PatentController {
         return Response.success("");
     }
 
+    @Operation(summary = "excel导入")
+    @GetMapping(value = "/importPatentE")
+    public Response importPatentE(String path) {
+        try {
+            getPatentFromExcelService.run(path);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Response.success("");
+    }
+
+    //--------------------------- 关于图片的专利检索  --------------------------
     @Operation(summary = "根据关键词获取列表(图片用于排序)--zero")
     @PostMapping(value = "/getPatentVectors")
     public Response getPatentVectors(@RequestParam(value = "vectorDTO", required = false) String vectorDTO, @RequestParam(value = "multipartFile", required = false) MultipartFile multipartFile) throws Exception {
@@ -67,15 +87,37 @@ public class PatentController {
         return Response.success(pictureByNo);
     }
 
-    @Operation(summary = "excel导入")
-    @GetMapping(value = "/importPatentE")
-    public Response importPatentE(String path) {
+    //--------------------------- 收藏专利相关  --------------------------
+    @checkLogin
+    @Operation(summary = "收藏专利--zero")
+    @PostMapping(value = "/collectPatent")
+    public Response collectPatent(@RequestBody CollectPatentDTO patentDTO) {
+        boolean b = false;
         try {
-            getPatentFromExcelService.run(path);
-        } catch (Exception e) {
-            e.printStackTrace();
+            b = esPatentService.collectPatent(patentDTO);
+        } catch (IOException e) {
+            return Response.error(e.getMessage());
         }
-        return Response.success("");
+        return Response.success(b);
+    }
+
+    @Operation(summary = "查询收藏专利--zero")
+    @PostMapping(value = "/selectCollectPatent")
+    public Response selectCollectPatent(@RequestBody SelectCollectPatentDTO patentDTO) throws Exception {
+        Records records = esPatentService.selectCollectPatent(patentDTO);
+        return Response.success(records);
     }
 
+    @Operation(summary = "删除收藏专利--zero")
+    @PostMapping(value = "/delCollectPatent")
+    public Response delCollectPatent(@RequestBody DelCollectPatentDTO patentDTO) throws IOException {
+        boolean b = false;
+        try {
+            b = esPatentService.delCollectPatent(patentDTO);
+        } catch (IOException e) {
+            return Response.error(e.getMessage());
+        }
+        return Response.success(b);
+    }
+    //--------------------------- 其他  --------------------------
 }

+ 4 - 2
src/main/java/com/example/xiaoshiweixinback/entity/dto/esPicture/EsPatentVectorDTO.java

@@ -13,7 +13,9 @@ public class EsPatentVectorDTO {
 
     private String description;
 
-    private Long pageNum = 1l;
+    private Long pageNum;
 
-    private Long pageSize = 10l;
+    private Long pageSize;
+
+    private Boolean ifAddSearchRecord = true;
 }

+ 13 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/patent/CollectPatentDTO.java

@@ -0,0 +1,13 @@
+package com.example.xiaoshiweixinback.entity.dto.patent;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CollectPatentDTO {
+
+    private Integer productId;
+
+    private List<String> patentNos;
+}

+ 13 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/patent/DelCollectPatentDTO.java

@@ -0,0 +1,13 @@
+package com.example.xiaoshiweixinback.entity.dto.patent;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class DelCollectPatentDTO {
+
+    private Integer assoPersonProductId;
+
+    private List<String> patentNos;
+}

+ 399 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/patent/PatentColumnDTO.java

@@ -0,0 +1,399 @@
+package com.example.xiaoshiweixinback.entity.dto.patent;
+
+import com.example.xiaoshiweixinback.domain.es.*;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class PatentColumnDTO {
+    /**
+     * 专利号
+     */
+    private String patentNo;
+
+    /**
+     * 标题
+     */
+    private List<Text> title;
+
+    /**
+     * 公开说明书文本
+     */
+    private List<Text> publicFullText;
+
+    /**
+     * 授权说明书文本
+     */
+    private List<Text> grantFullText;
+
+    /**
+     * 摘要
+     */
+    private List<Text> abstractStr;
+
+    /**
+     * 申请人地址
+     */
+    private PersonAddress applicantAddr;
+
+    //申请人地址
+    private String appAddress;
+    //申请人国家
+    private String applicantCountry;
+    //申请人省份
+    private String appProvince;
+    //申请人市
+    private String appCity;
+    //申请人县
+    private String appDistrict;
+
+    //权利人地址
+    private String rightAddress;
+    //权利人国家
+    private String rightCountry;
+    //权利人省份
+    private String rightProvince;
+    //权利人市
+    private String rightCity;
+    //权利人县
+    private String rightDistrict;
+
+    /**
+     * 权利人地址
+     */
+    private PersonAddress rightHolderAddr;
+
+    /**
+     * 审查员
+     */
+    private String examiner;
+
+    /**
+     * 助理审查员
+     */
+    private String aidExaminer;
+
+    /**
+     * 实审日
+     */
+    @JsonFormat(
+            pattern = "yyyy-MM-dd",
+            timezone = "GMT+8"
+    )
+    private Date examinationDate;
+
+    /**
+     * 公开号
+     */
+    private String publicNo;
+
+    /**
+     * 公开日
+     */
+    @JsonFormat(
+            pattern = "yyyy-MM-dd",
+            timezone = "GMT+8"
+    )
+    private Date publicDate;
+
+    /**
+     * 申请号
+     */
+    private String appNo;
+
+    /**
+     * 申请日
+     */
+    @JsonFormat(
+            pattern = "yyyy-MM-dd",
+            timezone = "GMT+8"
+    )
+    private Date appDate;
+
+    /**
+     * 授权号
+     */
+    private String grantNo;
+
+    /**
+     * 授权日
+     */
+    @JsonFormat(
+            pattern = "yyyy-MM-dd",
+            timezone = "GMT+8"
+    )
+    private Date grantDate;
+
+    /**
+     * 优先权
+     */
+    private List<Priorities> priorities;
+
+    /**
+     * 申请国家
+     */
+    private String appCountry;
+
+    /**
+     * IPC分类号(主)
+     */
+    private PatentClassify mipc;
+
+    /**
+     * ipc集合
+     */
+    private List<PatentClassify> ipc;
+
+    /**
+     * CPC分类号(主)
+     */
+    private PatentClassify mcpc;
+
+    /**
+     * cpc集合
+     */
+    private List<PatentClassify> cpc;
+
+    /**
+     * UPC分类号(主)
+     */
+    private PatentClassify mupc;
+
+
+    /**
+     * UPC集合
+     */
+    private List<PatentClassify> upc;
+
+    /**
+     * UPC分类号(主)
+     */
+    private PatentClassify mloc;
+
+
+    /**
+     * UPC集合
+     */
+    private List<PatentClassify> loc;
+
+    /**
+     * 专利状态
+     */
+    private String simpleStatus;
+
+    /**
+     * 类型
+     */
+    private String patentType;
+
+
+    /**
+     * 权利要求
+     */
+    private List<Text> claim;
+
+    /**
+     * pct申请号
+     */
+    private Integer pctAppDate;
+
+    /**
+     * pct申请日
+     */
+    private String pctAppNo;
+
+    /**
+     * pct进入日期
+     */
+    private Integer pctEnterDate;
+
+    /**
+     * pct公开日
+     */
+    private Integer pctPubDate;
+
+    /**
+     * pct公开号
+     */
+    private String pctPubNo;
+
+    /**
+     * wo指定国
+     */
+    private String wo;
+
+    /**
+     * ep申请号
+     */
+    private String epNo;
+
+    /**
+     * ep申请日
+     */
+    private String epDate;
+
+
+    /**
+     * EP指定国状态
+     */
+    private String epCountry;
+
+    /**
+     * 申请人
+     */
+    private List<String> applicant;
+
+    /**
+     * 标准申请人
+     */
+    private List<PatentPerson> standerApplicant;
+
+    /**
+     * 合并申请人
+     */
+    private List<String> mergeApplicant;
+
+    /**
+     * 申请人数量
+     */
+    private Integer applicantsNum;
+
+    /**
+     * 权利人
+     */
+    private List<String> rightHolder;
+    /**
+     * 标准权利人
+     */
+    private List<PatentPerson> standerRightHolder;
+
+    /**
+     * 合并权利人
+     */
+    private List<String> mergeRightHolder;
+
+    /**
+     * 权利人数量
+     */
+    private Integer rightHolderNum;
+
+    /**
+     * 发明人
+     */
+    private List<String> inventor;
+    /**
+     * 合并发明人
+     */
+    private List<String> mergeInventor;
+
+
+    /**
+     * 发明人数量
+     */
+    private Integer inventor_num;
+
+    /**
+     * 代理机构
+     */
+    private String agency;
+
+    /**
+     * 代理机构编号
+     */
+    private String agencyNo;
+
+    /**
+     * 代理人
+     */
+    private List<String> agent;
+
+    /**
+     * 引用专利数量
+     */
+    private Integer quotePatentNoNum;
+
+    /**
+     * 被引用专利数量
+     */
+    private Integer quotedPatentNoNum;
+
+    /**
+     * 自定义栏位
+     */
+    List<ESCustomField> ESCustomField;
+    /**
+     * 扩展同族数量
+     */
+    private Integer patsnapFamilyNum;
+    /**
+     * 扩展同族id
+     */
+    private String patsnapFamilyId;
+
+    /**
+     * INPADOC同族数量
+     */
+    private Integer inpadocFamilyNum;
+    /**
+     * INPADOC同族id
+     */
+    private String inpadocFamilyId;
+
+    /**
+     * 简单同族数量
+     */
+    private Integer simpleFamilyNum;
+    /**
+     * 简单同族id
+     */
+    private String simpleFamilyId;
+
+    /**
+     * 专题库或报告id
+     */
+    private Integer projectId;
+
+    /**
+     * 专题库或报告id
+     */
+    private String productId;
+
+    /**
+     * 专题库或报告的任务
+     */
+    EsProjectTask projectTask;
+
+    /**
+     * 导入任务
+     */
+    ESImportTask importTask;
+
+    /**
+     * 法律状态
+     */
+    List<String> legalStatus;
+
+    /**
+     * 标注
+     */
+    List<Marking> markings;
+
+    PatentJoin patentJoin;
+
+   private String pictureGuid;
+
+    /**
+     * 法律事件
+     */
+    private List<LegalEvent> legalEvents;
+
+    //外部专利的原始申请号
+    private String rowApplicationNo;
+}

+ 13 - 0
src/main/java/com/example/xiaoshiweixinback/entity/dto/patent/SelectCollectPatentDTO.java

@@ -0,0 +1,13 @@
+package com.example.xiaoshiweixinback.entity.dto.patent;
+
+import lombok.Data;
+
+@Data
+public class SelectCollectPatentDTO {
+
+    private Integer assoPersonProductId;
+
+    private Long current;
+
+    private Long size;
+}

+ 6 - 0
src/main/java/com/example/xiaoshiweixinback/entity/vo/searchRecord/SelectSearchRecordVO.java

@@ -3,6 +3,7 @@ package com.example.xiaoshiweixinback.entity.vo.searchRecord;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 @Data
 public class SelectSearchRecordVO {
@@ -21,4 +22,9 @@ public class SelectSearchRecordVO {
 
     private Date createTime;
 
+    private String guid;
+
+    private String description;
+
+    private List<String> productFiles;
 }

+ 3 - 1
src/main/java/com/example/xiaoshiweixinback/service/ProductService.java

@@ -135,7 +135,9 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
 
             if (assoPersonProducts.size() != 0) {
                 AssoPersonProduct assoPersonProduct = assoPersonProducts.stream().filter(item -> item.getProductId().equals(productVO.getId())).findFirst().orElse(null);
-                productVO.setConcernType(assoPersonProduct.getConcernType());
+                if (ToolUtil.isNotEmpty(assoPersonProduct)) {
+                    productVO.setConcernType(assoPersonProduct.getConcernType());
+                }
             }
         }
     }

+ 18 - 0
src/main/java/com/example/xiaoshiweixinback/service/SearchRecordService.java

@@ -11,13 +11,16 @@ import com.example.xiaoshiweixinback.business.utils.BeanUtil;
 import com.example.xiaoshiweixinback.business.utils.CacheUtil;
 import com.example.xiaoshiweixinback.business.utils.LoginUtils;
 import com.example.xiaoshiweixinback.business.utils.ToolUtil;
+import com.example.xiaoshiweixinback.domain.AssoProductFile;
 import com.example.xiaoshiweixinback.domain.SearchRecord;
 
 import com.example.xiaoshiweixinback.entity.dto.searchRecord.AddSearchRecordDTO;
 import com.example.xiaoshiweixinback.entity.dto.searchRecord.SelectSearchRecordDTO;
 import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
 import com.example.xiaoshiweixinback.entity.vo.searchRecord.SelectSearchRecordVO;
+import com.example.xiaoshiweixinback.mapper.AssoProductFileMapper;
 import com.example.xiaoshiweixinback.mapper.SearchRecordMapper;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -26,6 +29,7 @@ import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
 * @author admin
@@ -41,6 +45,9 @@ public class SearchRecordService extends ServiceImpl<SearchRecordMapper, SearchR
     @Autowired
     private CacheUtil cacheUtils;
 
+    @Autowired
+    private AssoProductFileMapper assoProductFileMapper;
+
     /**
      * 添加或更新检索记录
      *
@@ -87,6 +94,17 @@ public class SearchRecordService extends ServiceImpl<SearchRecordMapper, SearchR
             list.forEach(i -> {
                 SelectSearchRecordVO recordVO = new SelectSearchRecordVO();
                 BeanUtil.copy(i, recordVO);
+                List<String> collect = new ArrayList<>();
+                if (i.getProductId() != null) {
+                    List<AssoProductFile> productFiles = assoProductFileMapper.selectList(new LambdaQueryWrapper<AssoProductFile>()
+                            .eq(AssoProductFile::getProductId, i.getProductId()));
+                    collect = productFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
+                } else {
+                    if (StringUtils.isNotEmpty(i.getGuid())) {
+                        collect.add(i.getGuid());
+                    }
+                }
+                recordVO.setProductFiles(collect);
                 recordVOS.add(recordVO);
             });
         }

+ 26 - 19
src/main/java/com/example/xiaoshiweixinback/service/common/EsDenseVectorService.java

@@ -1,4 +1,4 @@
-package com.example.xiaoshiweixinback.service.common;
+package com.example.xiaoshiweixinback.service.importPatent;
 
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.InlineScript;
@@ -15,7 +15,6 @@ import co.elastic.clients.elasticsearch.core.search.Hit;
 import co.elastic.clients.json.JsonData;
 import com.example.xiaoshiweixinback.business.common.base.Records;
 import com.example.xiaoshiweixinback.business.utils.BeanUtil;
-import com.example.xiaoshiweixinback.business.utils.ToolUtil;
 import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.expressManager;
 import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.operateNode;
 import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.treeNode;
@@ -24,11 +23,12 @@ import com.example.xiaoshiweixinback.domain.es.PatentVector;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO;
 import com.example.xiaoshiweixinback.entity.dto.searchRecord.AddSearchRecordDTO;
-import com.example.xiaoshiweixinback.entity.product.ProductIdDTO;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
 import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
 import com.example.xiaoshiweixinback.mapper.ProductMapper;
 import com.example.xiaoshiweixinback.service.SearchRecordService;
+import com.example.xiaoshiweixinback.service.common.FileManagerService;
+import com.example.xiaoshiweixinback.service.common.GetVectorService;
 import com.example.xiaoshiweixinback.service.importPatent.FormatQueryService;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
@@ -41,7 +41,6 @@ import org.springframework.util.CollectionUtils;
 
 import java.io.File;
 import java.io.IOException;
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -64,6 +63,9 @@ public class EsDenseVectorService {
     @Autowired
     private ProductMapper productMapper;
 
+    @Autowired
+    private FileManagerService fileManagerService;
+
     /**
      * 根据图片排序获取列表
      *
@@ -75,6 +77,7 @@ public class EsDenseVectorService {
     public Records getPatentVectors(EsPatentVectorDTO dto,File file) throws Exception {
         Long pageNum = dto.getPageNum();
         Long pageSize = dto.getPageSize();
+        Boolean ifAddSearchRecord = dto.getIfAddSearchRecord();
 
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
@@ -90,8 +93,10 @@ public class EsDenseVectorService {
         //获取图片向量
         List<Float> imageList = new ArrayList<>();
         List<String> stringList = new ArrayList<>();
+        List<String> getGuids = new ArrayList<>();
         if (file != null && file.exists() && file.length() != 0) {
             stringList = getVectorService.getVectorByFile(file);
+            getGuids = fileManagerService.uploadFileGetGuid2(Collections.singletonList(file));
         } else if (StringUtils.isNotEmpty(dto.getDescription())) {
             stringList = getVectorService.getVectorByText(dto.getDescription());
         }
@@ -153,22 +158,24 @@ public class EsDenseVectorService {
         long count = total <= vectorVos.size() ? total : vectorVos.size();
         records.setTotal(count);
 
-        //添加检索历史
-        AddSearchRecordDTO recordDTO = new AddSearchRecordDTO();
-        if (dto.getProductId() != null) {
-            recordDTO.setProductId(dto.getProductId());
-            Product product = productMapper.selectById(dto.getProductId());
-            recordDTO.setSearchCondition(product.getName());
-        } else {
-            recordDTO.setSearchCondition(dto.getKey());
-        }
-        recordDTO.setDescription(dto.getDescription());
-        if (file != null && file.length() != 0) {
-            recordDTO.setGuid(file.getPath());
+        if (Boolean.TRUE.equals(ifAddSearchRecord)) {
+            //添加检索历史
+            AddSearchRecordDTO recordDTO = new AddSearchRecordDTO();
+            if (dto.getProductId() != null) {
+                recordDTO.setProductId(dto.getProductId());
+                Product product = productMapper.selectById(dto.getProductId());
+                recordDTO.setSearchCondition(product.getName());
+            } else {
+                recordDTO.setSearchCondition(dto.getKey());
+            }
+            recordDTO.setDescription(dto.getDescription());
+            if (!CollectionUtils.isEmpty(getGuids)) {
+                recordDTO.setGuid(getGuids.get(0));
+            }
+            recordDTO.setAllNum(Integer.parseInt(String.valueOf(count)));
+            recordDTO.setSearchTime(new Date());
+            searchRecordService.addSearchRecord(recordDTO);
         }
-        recordDTO.setAllNum(Integer.parseInt(String.valueOf(count)));
-        recordDTO.setSearchTime(new Date());
-        searchRecordService.addSearchRecord(recordDTO);
         return records;
     }
 

+ 272 - 0
src/main/java/com/example/xiaoshiweixinback/service/importPatent/EsPatentService.java

@@ -0,0 +1,272 @@
+package com.example.xiaoshiweixinback.service.importPatent;
+
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
+import co.elastic.clients.elasticsearch.core.SearchRequest;
+import co.elastic.clients.elasticsearch.core.SearchResponse;
+import co.elastic.clients.elasticsearch.core.search.Hit;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.example.xiaoshiweixinback.business.common.base.Records;
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
+import com.example.xiaoshiweixinback.business.utils.BeanUtil;
+import com.example.xiaoshiweixinback.business.utils.CacheUtil;
+import com.example.xiaoshiweixinback.business.utils.LoginUtils;
+import com.example.xiaoshiweixinback.business.utils.ToolUtil;
+import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
+import com.example.xiaoshiweixinback.domain.es.*;
+import com.example.xiaoshiweixinback.entity.dto.patent.CollectPatentDTO;
+import com.example.xiaoshiweixinback.entity.dto.patent.DelCollectPatentDTO;
+import com.example.xiaoshiweixinback.entity.dto.patent.PatentColumnDTO;
+import com.example.xiaoshiweixinback.entity.dto.patent.SelectCollectPatentDTO;
+import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
+import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
+import com.example.xiaoshiweixinback.mapper.AssoPersonProductMapper;
+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;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class EsPatentService {
+
+    private final ElasticsearchClient client;
+
+    @Autowired
+    private EsService esService;
+
+    @Autowired
+    private CacheUtil cacheUtils;
+
+    @Autowired
+    private AssoPersonProductMapper assoPersonProductMapper;
+
+    /**
+     * 收藏专利
+     * @param patentDTO
+     * @return
+     */
+    public boolean collectPatent(CollectPatentDTO patentDTO) throws IOException {
+        boolean flag = false;
+        List<String> patentNos = patentDTO.getPatentNos();
+        Integer productId = patentDTO.getProductId();
+        //获取用户
+        PersonnelVO personnelVO = cacheUtils.getLoginUser(LoginUtils.getToken());
+        if (ToolUtil.isEmpty(personnelVO)) {
+            throw new BusinessException(ExceptionEnum.THE_GET_INFORMATION_TOKEN_INVALID);
+        }
+        String uuid = personnelVO.getUuid();
+        //获取人员产品关联表id
+        AssoPersonProduct assoPersonProduct = assoPersonProductMapper.selectOne(new LambdaQueryWrapper<AssoPersonProduct>()
+                .eq(AssoPersonProduct::getProductId, productId)
+                .eq(AssoPersonProduct::getPersonUuid, uuid));
+        Integer assoPersonProductId = assoPersonProduct.getId();
+        //判断该专利是否已经被收藏
+        List<String> patentNoList = this.selectPatentByProductId(assoPersonProductId);
+        patentNos.removeAll(patentNoList);
+        //根据专利号获取专利id
+        List<String> list = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(patentNos)) {
+            for (String patentNo : patentNos) {
+                String patentId = this.selectPatentByPatentNo(patentNo);
+                Patent patent = new Patent();
+                patent.setProductId(assoPersonProductId);
+                PatentJoin patentJoin = new PatentJoin();
+                patentJoin.setParent(patentId);
+                patentJoin.setName("product");
+                patent.setPatentJoin(patentJoin);
+                try {
+                    String id = esService.addChildPatent(patent, patentId);
+                    list.add(id);
+                } catch (Exception e) {
+                }
+            }
+        }
+        if (ToolUtil.equals(list.size(), patentNos.size())) {
+            flag = true;
+        }
+        return flag;
+    }
+
+    /**
+     * 查询收藏专利
+     * @param dto
+     * @return
+     * @throws IOException
+     */
+    public Records selectCollectPatent(SelectCollectPatentDTO dto) throws IOException {
+        Integer assoPersonProductId = dto.getAssoPersonProductId();
+        Long pageNum = dto.getCurrent();
+        Long pageSize = dto.getSize();
+
+        List<PatentColumnDTO> list = new ArrayList<>();
+
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("wxpatent");
+        Query q = QueryBuilders.term(i -> i.field("product_id").value(assoPersonProductId));
+        Query query = QueryBuilders.hasChild(i -> i.type("product").query(q));
+        builder.query(query);
+        //分页
+        if (pageNum != null && pageSize != null && pageNum > 0 && pageSize > 0) {
+            builder.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue());
+        }
+        //解除最大条数限制
+        builder.trackTotalHits(i -> i.enabled(true));
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        long total = response.hits().total().value();
+        for (Hit<Patent> hit : hits) {
+            Patent patent = hit.source();
+            PatentColumnDTO columnDTO = this.getPatentColumnDTO(patent, null, null);
+            list.add(columnDTO);
+        }
+
+        Records records = new Records();
+        records.setCurrent(pageNum);
+        records.setSize(pageSize);
+        records.setData(list);
+        records.setTotal(total);
+        return records;
+    }
+
+    /**
+     * 删除收藏专利
+     * @param patentDTO
+     * @return
+     * @throws IOException
+     */
+    public boolean delCollectPatent(DelCollectPatentDTO patentDTO) throws IOException {
+        Integer assoPersonProductId = patentDTO.getAssoPersonProductId();
+        List<String> patentNos = patentDTO.getPatentNos();
+        List<String> patentIds = new ArrayList<>();
+        for (String patentNo : patentNos) {
+            List<String> list = this.selectPatentId(patentNo, assoPersonProductId);
+            patentIds.addAll(list);
+        }
+
+        if (!CollectionUtils.isEmpty(patentIds)) {
+            Integer num = esService.deleteWxPatent(patentIds);
+            if (num < 1) {
+                throw new BusinessException(ExceptionEnum.THE_FAIL_TO_DELETE);
+            }
+        } else {
+            return false;
+        }
+        return true;
+    }
+
+    //根据专利号、assoPersonProductId查询相关专利id
+    public List<String> selectPatentId(String patentNo,Integer assoPersonProductId) throws IOException {
+        List<String> list = new ArrayList<>();
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("wxpatent");
+        Query query = QueryBuilders.term(i -> i.field("product_id").value(assoPersonProductId));
+        Query q = QueryBuilders.hasChild(i -> i.type("product").query(query));
+        Query q1 = QueryBuilders.term(i -> i.field("patent_no.keyword").value(patentNo));
+        Query bool = QueryBuilders.bool(i -> i.must(q, q1));
+        builder.query(bool);
+        //解除最大条数限制
+        builder.trackTotalHits(i -> i.enabled(true));
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        for (Hit<Patent> hit : hits) {
+            String id = hit.id();
+            list.add(id);
+        }
+        return list;
+    }
+
+    //装载专利清单列表的数据
+    public PatentColumnDTO getPatentColumnDTO(Patent patent, Integer projectId, String id) {
+        PatentColumnDTO columnDTO = new PatentColumnDTO();
+        BeanUtil.copy(patent, columnDTO);
+        if (ToolUtil.isNotEmpty(patent.getApplicantAddr())) {
+            PersonAddress applicantAddr = patent.getApplicantAddr();
+            columnDTO.setAppAddress(applicantAddr.getAddress());
+            columnDTO.setApplicantCountry(applicantAddr.getCountry());
+            columnDTO.setAppProvince(applicantAddr.getProvince());
+            columnDTO.setAppCity(applicantAddr.getCity());
+            columnDTO.setAppDistrict(applicantAddr.getDistrict());
+        }
+        if (ToolUtil.isNotEmpty(patent.getRightHolderAddr())) {
+            PersonAddress rightAddr = patent.getRightHolderAddr();
+            columnDTO.setRightAddress(rightAddr.getAddress());
+            columnDTO.setRightCountry(rightAddr.getCountry());
+            columnDTO.setRightProvince(rightAddr.getProvince());
+            columnDTO.setRightCity(rightAddr.getCity());
+            columnDTO.setRightDistrict(rightAddr.getDistrict());
+        }
+        columnDTO.setApplicant(this.loadName(patent.getApplicant()));
+        columnDTO.setRightHolder(this.loadName(patent.getRightHolder()));
+        columnDTO.setInventor(this.loadName(patent.getInventor()));
+        return columnDTO;
+    }
+
+    //通用返回申请人、权利人、发明人
+    public List<String> loadName(List<PatentPerson> list) {
+        List<String> collect = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(list)) {
+            collect = list.stream().filter(i -> StringUtils.isNotEmpty(i.getName())).map(PatentPerson::getName).collect(Collectors.toList());
+        }
+        return collect;
+    }
+
+    /**
+     * 根据专利号获取专利id
+     * @param patentNo
+     * @return
+     * @throws IOException
+     */
+    public String selectPatentByPatentNo(String patentNo) throws IOException {
+        String id = "";
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("wxpatent");
+        Query q = QueryBuilders.term(i -> i.field("patent_no.keyword").value(patentNo));
+        builder.query(q);
+        builder.size(10);
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        for (Hit<Patent> hit : hits) {
+            id = hit.id();
+        }
+        return id;
+    }
+
+    /**
+     * 判断该专利是否已经被收藏
+     * @param personProductId
+     * @return
+     * @throws IOException
+     */
+    public List<String> selectPatentByProductId(Integer personProductId) throws IOException {
+        List<String> list = new ArrayList<>();
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("wxpatent");
+        Query q = QueryBuilders.term(i -> i.field("product_id").value(personProductId));
+        Query query = QueryBuilders.hasChild(i -> i.type("product").query(q));
+        builder.query(query);
+        builder.size(10);
+        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();
+            list.add(patent.getPatentNo());
+        }
+        return list;
+    }
+}

+ 32 - 0
src/main/java/com/example/xiaoshiweixinback/service/importPatent/EsService.java

@@ -11,6 +11,8 @@ import co.elastic.clients.elasticsearch.core.*;
 import co.elastic.clients.elasticsearch.core.search.Hit;
 import co.elastic.clients.json.JsonData;
 import com.alibaba.fastjson.JSON;
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
 import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.expressManager;
 import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.operateNode;
 import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.treeNode;
@@ -71,6 +73,36 @@ public class EsService {
     }
 
     /**
+     * @param patent
+     * @throws Exception
+     */
+    public String addChildPatent(Patent patent, String id) throws Exception {
+        IndexResponse indexResponse = client.index(i -> i
+                .index("wxpatent")
+                .routing(id)
+                //传入user对象
+                .document(patent).refresh(Refresh.True).waitForActiveShards(WaitForActiveShards.of(t -> t.count(1)))
+        );
+        return indexResponse.id();
+    }
+
+    /**
+     * 根据id删除专利
+     * @param ids
+     * @return
+     */
+    public Integer deleteWxPatent(List<String> ids) {
+        Query query = QueryBuilders.ids(n -> n.values(ids));
+        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("wxpatent").query(query));
+        try {
+            client.deleteByQuery(request);
+            return 1;
+        } catch (IOException e) {
+            throw new BusinessException(ExceptionEnum.THE_FAIL_TO_DELETE);
+        }
+    }
+
+    /**
      * 根据专利号获取专利id
      *
      * @param patentNo

+ 6 - 10
src/test/java/com/example/xiaoshiweixinback/XiaoshiWeixinbackApplicationTests.java

@@ -1,6 +1,6 @@
 package com.example.xiaoshiweixinback;
 
-import com.example.xiaoshiweixinback.service.common.EsDenseVectorService;
+import com.example.xiaoshiweixinback.service.importPatent.EsDenseVectorService;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -9,6 +9,7 @@ import org.springframework.context.annotation.Lazy;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -70,14 +71,9 @@ class XiaoshiWeixinbackApplicationTests {
 
     @Test
     public void test1() {
-        // 获取当前时间
-        LocalDateTime now = LocalDateTime.now();
-        now.format(DateTimeFormatter.ISO_DATE);
-        // 减去三年
-        LocalDateTime threeYearsAgo = now.minusYears(3);
-
-        // 打印结果
-        System.out.println("当前时间: " + now);
-        System.out.println("三年前的时间: " + threeYearsAgo);
+        List<String> list = Arrays.asList("A", "B", "C");
+        List<String> list1 = Arrays.asList("a", "C", "D", "F");
+        list.removeAll(list1);
+        System.out.println(list);
     }
 }