Bladeren bron

Merge remote-tracking branch 'origin/master'

lwhhszx 1 jaar geleden
bovenliggende
commit
fc47c614c7

+ 5 - 0
src/main/java/cn/cslg/pas/common/dto/MergePersonQueryDTO.java

@@ -3,6 +3,7 @@ package cn.cslg.pas.common.dto;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 @Data
 public class MergePersonQueryDTO {
@@ -11,6 +12,8 @@ public class MergePersonQueryDTO {
 
     private String name;
 
+    private String abbreviation;
+
     private String country;
 
     private String address;
@@ -18,4 +21,6 @@ public class MergePersonQueryDTO {
     private String remark;
 
     private Date createTime;
+
+    private List<String> mergedName;
 }

+ 2 - 0
src/main/java/cn/cslg/pas/common/vo/business/MergePersonIdVO.java

@@ -7,4 +7,6 @@ public class MergePersonIdVO {
 
     private Integer id;
 
+    private Integer type;
+
 }

+ 4 - 0
src/main/java/cn/cslg/pas/common/vo/business/MergePersonQueryVO.java

@@ -5,6 +5,10 @@ import lombok.Data;
 @Data
 public class MergePersonQueryVO {
 
+    private Integer type;
+
+    private Integer projectId;
+
     private String name;
 
     private String country;

+ 66 - 2
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -4,11 +4,15 @@ import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.dto.GetAllPersonDTO;
 import cn.cslg.pas.common.dto.PatentColumnDTO;
 import cn.cslg.pas.common.dto.PatentDetailDTO;
+import cn.cslg.pas.common.dto.PatentExport.PatentExportParams;
+import cn.cslg.pas.common.dto.PatentExport.TaskParams;
 import cn.cslg.pas.common.dto.PatentKinDTO;
 import cn.cslg.pas.common.dto.business.EsCountDTO;
 import cn.cslg.pas.common.dto.business.SelectClaimDTO;
 import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.model.request.StringRequest;
+import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.common.vo.business.*;
 import cn.cslg.pas.common.vo.PatentPageMessageVO;
@@ -20,16 +24,29 @@ import cn.cslg.pas.common.vo.business.PatentKinVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
 import cn.cslg.pas.factorys.businessFactory.Business;
 import cn.cslg.pas.factorys.businessFactory.BusinessFactory;
+import cn.cslg.pas.service.business.PDFExportFirstPageService;
+import cn.cslg.pas.service.business.PatentExportService;
 import cn.cslg.pas.service.business.MergePersonService;
 import cn.cslg.pas.service.business.es.EsCountService;
 import cn.cslg.pas.service.business.es.EsPatentService;
 import cn.cslg.pas.service.business.es.EsService;
+import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
+import cn.hutool.core.util.IdUtil;
 import io.swagger.v3.oas.annotations.Operation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
 import java.util.List;
 
 @RequestMapping(Constants.API_XiaoSHI + "/patent")
@@ -54,6 +71,15 @@ public class PatentController {
     @Autowired
     private PatentStarApiService patentStarApiService;
 
+    @Autowired
+    private CacheUtils cacheUtils;
+    @Autowired
+    private PatentExportService patentExportService;
+    @Autowired
+    private PDFExportFirstPageService pdfExportFirstPageService;
+    @Autowired
+    private FileManagerService fileManagerService;
+
     @Operation(summary = "查询专利")
     @PostMapping("/queryPatent")
     public Response queryPatent(@RequestBody StringRequest stringRequest) throws Exception {
@@ -129,7 +155,7 @@ public class PatentController {
 
     @Operation(summary = "专利列表上编辑发明人/权利人/申请人合并")
     @PostMapping("/updateMergePerson")
-    public Response updateMergePerson(@RequestBody MergePersonVO personVO) {
+    public Response updateMergePerson(@RequestBody MergePersonVO personVO) throws Exception{
         Integer personId = mergePersonService.updateMergePerson(personVO);
         return Response.success(personId);
     }
@@ -150,8 +176,46 @@ public class PatentController {
 
     @Operation(summary = "发明人/权利人/申请人合并记录删除")
     @PostMapping("/delMergePerson")
-    public Response delMergePerson(@RequestBody MergePersonIdVO vo) {
+    public Response delMergePerson(@RequestBody MergePersonIdVO vo) throws Exception {
         Integer id = mergePersonService.delMergePerson(vo);
         return Response.success(id);
     }
+
+    @GetMapping("/exportPDFFirstPage")
+    @Operation(summary = "导出专利PDF")
+    public ResponseEntity<InputStreamResource> exportPDFFirstPage(Integer projectId) throws IOException {
+        byte[] fileData = pdfExportFirstPageService.mergeAndExportPDFFirstPage(projectId);
+        //保存生成excel的地址
+        String fileName = IdUtil.simpleUUID() + ".pdf";
+        //文件原始名中的中文字符可能会乱码,对文件名进行URL编码
+        String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
+        return ResponseEntity.ok().contentLength(fileData.length)
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\"")
+                .contentType(MediaType.parseMediaType("application/octet-stream"))
+                .body(new InputStreamResource(new ByteArrayInputStream(fileData)));
+    }
+
+    @PostMapping("/export")
+    @Operation(summary = "导出专利")
+    public ResponseEntity<InputStreamResource> export(@RequestBody PatentExportParams params) throws IOException {
+        Integer taskId = 1;
+        TaskParams taskParams = new TaskParams();
+        taskParams.setTaskId(taskId);
+        taskParams.setTaskType(2);
+        taskParams.setProjectId(params.getProjectId());
+        taskParams.setSelected(JsonUtils.objectToJson(params.getSelected()));
+        taskParams.setCreateId("328");
+        byte[] fileData = patentExportService.exportPatent(taskParams);
+        //保存生成excel的地址
+        String fileName = "导出专利报表.xlsx";
+//        String fileName = IdUtil.simpleUUID() + ".xls";
+//        String directoryName = fileUtils.createDirectory();
+//        String savePath = fileUtils.getSavePath(directoryName);
+        //文件原始名中的中文字符可能会乱码,对文件名进行URL编码
+        String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
+        return ResponseEntity.ok().contentLength(fileData.length)
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\"")
+                .contentType(MediaType.parseMediaType("application/octet-stream"))
+                .body(new InputStreamResource(new ByteArrayInputStream(fileData)));
+    }
 }

+ 9 - 0
src/main/java/cn/cslg/pas/controller/outApi/PatentStarController.java

@@ -1,10 +1,12 @@
 package cn.cslg.pas.controller.outApi;
 
 import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.dto.PatentColumnDTO;
 import cn.cslg.pas.common.dto.PatentStarListDTO;
 import cn.cslg.pas.common.dto.business.SelectClaimDTO;
 import cn.cslg.pas.common.model.cronModel.Records;
 import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.common.vo.business.PatentNoVO;
 import cn.cslg.pas.service.common.PatentStarApiService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -98,4 +100,11 @@ public class PatentStarController {
         SelectClaimDTO dto = patentStarApiService.selectClaim(patentNo);
         return Response.success(dto);
     }
+
+    @Operation(summary = "查询外部专利详情")
+    @PostMapping("/queryExternalDetail")
+    public Response queryExternalDetail(@RequestBody PatentNoVO vo) throws Exception {
+        PatentColumnDTO dto = patentStarApiService.queryExternalDetail(vo);
+        return Response.success(dto);
+    }
 }

+ 112 - 18
src/main/java/cn/cslg/pas/service/business/MergePersonService.java

@@ -93,10 +93,11 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
         }
         MergePerson person = new MergePerson();
         BeanUtils.copyProperties(vo, person);
+        person.setMergedName(JSONArray.toJSONString(mergedNames));
         person.setCreateId(personnelVO.getId());
         person.setCreateTime(new Date());
         person.insert();
-        //todo  关联相关专利
+
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");
@@ -119,14 +120,13 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
         builder.query(query);
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         List<Hit<Patent>> hits = response.hits().hits();
-        List<String> ids = new ArrayList<>();
         Map<String, Patent> map = new HashMap<>();
         for (Hit<Patent> hit : hits) {
             String id = hit.id();
             map.put(id, hit.source());
         }
 
-        if (!CollectionUtils.isEmpty(ids)) {
+        if (!CollectionUtils.isEmpty(map)) {
             List<PatentMergePerson> mergePersonList = new ArrayList<>();
             PatentMergePerson mergePerson = new PatentMergePerson();
             mergePerson.setName(vo.getName());
@@ -137,8 +137,9 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
 
             for (String id : map.keySet()) {
                 Patent patent = map.get(id);
-                List<PatentMergePerson> mergeApplicant = patent.getMergeApplicant();
-
+                List<PatentMergePerson> mergeApplicants = patent.getMergeApplicant();
+                List<String> Names = mergeApplicants.stream().map(PatentMergePerson::getName).collect(Collectors.toList());
+                mergePersonList.addAll(mergeApplicants);
                 patent.setMergeApplicant(mergePersonList);
                 patent.setMergeRightHolder(mergePersonList);
                 esService.updateMergePerson(patent, id);
@@ -148,21 +149,70 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
     }
 
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
-    public Integer updateMergePerson(MergePersonVO vo) {
+    public Integer updateMergePerson(MergePersonVO vo) throws IOException {
         //获取登陆人信息 用于设置创建人
         PersonnelVO personnelVO = new PersonnelVO();
+        Integer type = vo.getType();
         try {
             personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
         } catch (Exception e) {
             throw new UnLoginException("未登录");
         }
         MergePerson person = this.getById(vo.getId());
+        String mergedName = person.getMergedName();
+        String name = person.getName();
         if (ObjectUtil.isNotEmpty(person)) {
             BeanUtils.copyProperties(vo, person);
+            person.setMergedName(JSONArray.toJSONString(vo.getMergedName()));
             person.setCreateId(personnelVO.getId());
             person.setCreateTime(new Date());
             person.updateById();
-            //todo  关联相关专利
+
+            List<String> mergedNames = JSONArray.parseArray(mergedName, String.class);
+            SearchRequest.Builder builder = new SearchRequest.Builder();
+            //设置查询索引
+            builder.index("patent");
+
+            List<Query> queries = new ArrayList<>();
+            if (type == 0) {
+                for (String merged : mergedNames) {
+                    Query q = QueryBuilders.term(i -> i.field("applicant.name").value(merged));
+                    Query query = QueryBuilders.nested(i -> i.path("applicant").query(q));
+                    queries.add(query);
+                }
+            } else {
+                for (String merged : mergedNames) {
+                    Query q = QueryBuilders.term(i -> i.field("inventor.name").value(merged));
+                    Query query = QueryBuilders.nested(i -> i.path("inventor").query(q));
+                    queries.add(query);
+                }
+            }
+            Query query = QueryBuilders.bool(i -> i.should(queries));
+            builder.query(query);
+            SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+            List<Hit<Patent>> hits = response.hits().hits();
+            Map<String, Patent> map = new HashMap<>();
+            for (Hit<Patent> hit : hits) {
+                String id = hit.id();
+                map.put(id, hit.source());
+            }
+
+            if (!CollectionUtils.isEmpty(map)) {
+                for (String id : map.keySet()) {
+                    Patent patent = map.get(id);
+                    List<PatentMergePerson> mergeApplicants = patent.getMergeApplicant();
+                    if (!name.equals(vo.getName())) {
+                        for (PatentMergePerson mergeApplicant : mergeApplicants) {
+                            if (mergeApplicant.getName().equals(name)) {
+                                mergeApplicant.setName(vo.getName());
+                            }
+                        }
+                    }
+                    patent.setMergeApplicant(mergeApplicants);
+                    patent.setMergeRightHolder(mergeApplicants);
+                    esService.updateMergePerson(patent, id);
+                }
+            }
         } else {
             person = new MergePerson();
         }
@@ -173,6 +223,8 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
         List<MergePersonQueryDTO> list = new ArrayList<>();
         IPage<MergePerson> page = new Page<>(vo.getPageNum(), vo.getPageSize());
         LambdaQueryWrapper<MergePerson> wrapper = new LambdaQueryWrapper<MergePerson>()
+                .eq(MergePerson::getProjectId, vo.getProjectId())
+                .eq(MergePerson::getType, vo.getType())
                 .eq(StringUtils.isNotEmpty(vo.getCountry()), MergePerson::getCountry, vo.getCountry())
                 .like(StringUtils.isNotEmpty(vo.getName()), MergePerson::getName, vo.getName());
         IPage<MergePerson> record = mergePersonMapper.selectPage(page, wrapper);
@@ -183,7 +235,10 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
             dto.setAddress(person.getAddress());
             dto.setCountry(person.getCountry());
             dto.setRemark(person.getRemark());
+            dto.setAbbreviation(person.getAbbreviation());
             dto.setCreateTime(person.getCreateTime());
+            List<String> names = JSONArray.parseArray(person.getMergedName(), String.class);
+            dto.setMergedName(names);
             list.add(dto);
         }
         Records records = new Records();
@@ -195,16 +250,30 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
     }
 
     public Records getMergePerson(GetAllPersonVO vo) throws Exception {
-        String searchCondition = "";
         Integer projectId = vo.getProjectId();
         Integer taskId = vo.getTaskId();
         Integer pageNum = vo.getPageNum();
         Integer pageSize = vo.getPageSize();
+        Integer type = vo.getType();
+        String searchCondition = "";
+        if (type == 0 && StringUtils.isNotEmpty(vo.getName())) {
+            searchCondition = searchCondition + "PA = " + vo.getName();
+        } else if (type == 2 && StringUtils.isNotEmpty(vo.getName())){
+            searchCondition = searchCondition + "IN = " + vo.getName();
+        }
         if (taskId != null) {
-            searchCondition = "taskId = " + taskId;
+            if (searchCondition != null && !"".equals(searchCondition.trim())) {
+                searchCondition = "taskId = " + taskId + " AND " + searchCondition;
+            } else {
+                searchCondition = "taskId = " + taskId;
+            }
         } else {
             if (projectId != null) {
-                searchCondition = "projectId = " + projectId;
+                if (searchCondition != null && !"".equals(searchCondition.trim())) {
+                    searchCondition = "projectId = " + projectId + " AND " + searchCondition;
+                } else {
+                    searchCondition = "projectId = " + projectId;
+                }
             }
         }
         SearchRequest.Builder builder = new SearchRequest.Builder();
@@ -215,11 +284,11 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
         //格式化检索式
         //3. 从es中检索数据
         Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
+        builder.query(q);
         //分页
         if (pageNum > 0 && pageSize > 0) {
             builder.from((pageNum - 1) * pageSize).size(pageSize);
         }
-        builder.query(q);
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         List<Hit<Patent>> hits = response.hits().hits();
         long total = response.hits().total().value();
@@ -284,7 +353,7 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
             int size = applicantDTOS.size();
             records.setData(applicantDTOS.stream().limit(vo.getPageSize()).collect(Collectors.toList()));
             if (total >= size) {
-                records.setTotal((long)size);
+                records.setTotal((long) size);
             } else {
                 records.setTotal(total);
             }
@@ -292,7 +361,7 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
             int size = inventorDTOS.size();
             records.setData(inventorDTOS.stream().limit(vo.getPageSize()).collect(Collectors.toList()));
             if (total >= size) {
-                records.setTotal((long)size);
+                records.setTotal((long) size);
             } else {
                 records.setTotal(total);
             }
@@ -300,12 +369,37 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
         return records;
     }
 
-    public Integer delMergePerson(MergePersonIdVO vo) {
-        LambdaQueryWrapper<MergePerson> wrapper = new LambdaQueryWrapper<MergePerson>()
-                .eq(BaseEntity::getId, vo.getId());
-        this.remove(wrapper);
+    public Integer delMergePerson(MergePersonIdVO vo) throws IOException {
+        Integer type = vo.getType();
+        MergePerson mergePerson = mergePersonMapper.selectById(vo.getId());
+        if (ObjectUtil.isNotEmpty(mergePerson)) {
+            LambdaQueryWrapper<MergePerson> wrapper = new LambdaQueryWrapper<MergePerson>()
+                    .eq(BaseEntity::getId, vo.getId());
+            this.remove(wrapper);
+
+            //todo 删掉相关合并的名称
+            SearchRequest.Builder builder = new SearchRequest.Builder();
+            //设置查询索引
+            builder.index("patent");
+
+            Query q = QueryBuilders.term(i -> i.field("merge_applicant.name").value(mergePerson.getName()));
+            Query query = QueryBuilders.nested(i -> i.path("merge_applicant").query(q));
+            builder.query(query);
+            SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+            List<Hit<Patent>> hits = response.hits().hits();
+            Map<String, Patent> map = new HashMap<>();
+            for (Hit<Patent> hit : hits) {
+                String id = hit.id();
+                map.put(id, hit.source());
+            }
 
-        //todo 删掉相关合并的名称
+            if (!CollectionUtils.isEmpty(map)) {
+                for (String id : map.keySet()) {
+                    Patent patent = map.get(id);
+                    esService.delMergePerson(patent, id, type,mergePerson.getName());
+                }
+            }
+        }
         return vo.getId();
     }
 }

+ 24 - 5
src/main/java/cn/cslg/pas/service/business/PDFExportFirstPageService.java

@@ -7,7 +7,6 @@ import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.service.business.es.EsService;
 import cn.cslg.pas.service.common.FileManagerService;
-import com.spire.pdf.PdfPageSize;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.pdfbox.multipdf.PDFMergerUtility;
 import org.apache.pdfbox.io.MemoryUsageSetting;
@@ -21,6 +20,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -49,15 +49,28 @@ public class PDFExportFirstPageService {
         try {
             patentDTO = esService.esSearch(queryRequest);
         } catch (Exception e) {
-            throw new XiaoShiException("错误");
+            throw new XiaoShiException("检索专利错误");
         }
         List<PatentColumnDTO> patents = patentDTO.getPatents();
         byte[][] pdfDocuments = this.getPDFByteByAppNo(patents);
-        byte[] pdfData = this.mergeFirstPage(pdfDocuments);
+        byte[] pdfData = new byte[0];
+        // 判断 byte[][] 数组是否为空
+        if (!this.isByteEmpty(pdfDocuments)) {
+            pdfData = this.mergeFirstPage(pdfDocuments);
+        }
         return pdfData;
     }
 
     /**
+     * 判断文件数组是否为空
+     * @param pdfDocuments
+     * @return
+     */
+    private boolean isByteEmpty(byte[][] pdfDocuments) {
+        return pdfDocuments == null || pdfDocuments.length == 0 || Arrays.stream(pdfDocuments).allMatch(array -> array == null || array.length == 0);
+    }
+
+    /**
      * 3
      * @param pdfDatas
      * @return
@@ -113,17 +126,23 @@ public class PDFExportFirstPageService {
                 byte[] pdfData = new byte[0];
                 try {
                     pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid);
-                    if (pdfData == null) {
+                    if (pdfData == null  || pdfData.length == 0) {
                         //获取公开专利pdf文档guid
                         Integer type2 = 0;
                         String pdfGuid2 = FormatUtil.getPDFFormat(appNo, type2);
                         pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid2);
+                        if (pdfData == null  || pdfData.length == 0) {
+                            continue;
+                        } else {
+                            pdfDatas.add(pdfData);
+                        }
+                    } else {
+                        pdfDatas.add(pdfData);
                     }
                 } catch (IOException e) {
                     e.printStackTrace();
                     continue;//继续处理下一件专利
                 }
-                pdfDatas.add(pdfData);
             }
         }
         byte[][] pdfDataArray = new byte[pdfDatas.size()][];

+ 1 - 1
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class EsCountService {
     private final List<String> childList = Arrays.asList("field");
-    private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH");
+    private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH","MIN");
     private final List<String> dateList = Arrays.asList("PD", "AD", "GD");
     private final List<String> numberList = Arrays.asList("QPN", "QDPN", "SFN", "IFN", "PFN");
 

+ 40 - 9
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -37,6 +37,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
+import org.elasticsearch.client.RequestOptions;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -44,6 +45,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 
@@ -437,7 +439,7 @@ public class EsService {
     }
     }*/
     //更新子文档
-    public Integer updateByQuery(Patent patent, String id) {
+    public Integer updateByQuery(Patent patent, String id) throws IOException {
         ESCustomField customField = patent.getESCustomField();
         String valueField = "[";
         List<String> fieldValueList = customField.getFieldValue();
@@ -468,16 +470,18 @@ public class EsService {
             }
         }
         valueStats = valueStats + "]";
-
-        String projectId = "ctx._source.custom_field.project_id = " + customField.getProjectId() + ";" + "\n";
-        String field = "ctx._source.custom_field.field=" + customField.getField() + ";" + "\n";
-        String fieldType = "ctx._source.custom_field.field_type = " + customField.getFieldType() + ";" + "\n";
-        String personId = "ctx._source.custom_field.person_id = " + customField.getPersonId() + ";" + "\n";
-        String createTime = "ctx._source.custom_field.create_time = " + customField.getCreateTime().getTime() + ";" + "\n";
-        String fieldValue = "ctx._source.custom_field.field_value = " + valueField + ";" + "\n";
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        String s = format.format(customField.getCreateTime());
+        String dateStr = "\'" + s + "\'";
+        String projectId = "ctx._source.custom_field.project_id = " + customField.getProjectId() + ";";
+        String field = "ctx._source.custom_field.field=" + customField.getField() + ";";
+        String fieldType = "ctx._source.custom_field.field_type = " + customField.getFieldType() + ";";
+        String personId = "ctx._source.custom_field.person_id = " + customField.getPersonId() + ";";
+        String createTime = "ctx._source.custom_field.create_time = " + dateStr + ";";
+        String fieldValue = "ctx._source.custom_field.field_value = " + valueField + ";";
         String statsValue = "ctx._source.custom_field.stats_value = " + valueStats;
 
-        String source = "\"\"\"" + projectId + field + fieldType + personId + createTime + fieldValue + statsValue  + "\n" + "\"\"\"";
+        String source = projectId + field + fieldType + personId + createTime + fieldValue + statsValue;
         InlineScript inlineScript = InlineScript.of(i -> i.lang("painless").source(source));
         Script script = Script.of(i -> i.inline(inlineScript));
         Query query = QueryBuilders.term(i -> i.field("_id").value(id));
@@ -1070,6 +1074,33 @@ public class EsService {
             return -1;
         }
     }
+
+    /**
+     * 删除申请人/权利人/发明人合并名称
+     *
+     * @param patent
+     * @param id
+     * @return
+     */
+    public Integer delMergePerson(Patent patent, String id,Integer type, String name) {
+        String source = "";
+        if (type == 0) {
+            source = "if (ctx._source.merge_applicant != null) { ctx._source.merge_applicant.removeIf(item -> item.name == params.name); } if (ctx._source.merge_right_holder  != null) { ctx._source.merge_right_holder .removeIf(item -> item.name == params.name); }";
+        } else {
+            source = "if (ctx._source.merge_inventor != null) { ctx._source.merge_inventor.removeIf(item -> item.name == params.name); }";
+        }
+        String finalSource = source;
+        InlineScript inlineScript = InlineScript.of(i -> i.lang("painless").params("name",JsonData.of(name)).source(finalSource));
+        Script script = Script.of(i -> i.inline(inlineScript));
+        Query query = QueryBuilders.term(i -> i.field("_id").value(id));
+        UpdateByQueryRequest request = UpdateByQueryRequest.of(i -> i.index("patent").script(script).query(query));
+        try {
+            client.updateByQuery(request);
+            return 1;
+        } catch (IOException e) {
+            return -1;
+        }
+    }
 }
 
 

+ 31 - 5
src/main/java/cn/cslg/pas/service/common/PatentStarApiService.java

@@ -12,6 +12,7 @@ import cn.cslg.pas.common.model.importTaskModel.PatentApplicant;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.vo.ContentVO;
 import cn.cslg.pas.common.vo.StarPatentVO;
+import cn.cslg.pas.common.vo.business.PatentNoVO;
 import cn.cslg.pas.domain.WebLoginConfig;
 import cn.cslg.pas.domain.business.RetrieveRecord;
 import cn.cslg.pas.domain.es.PatentClassify;
@@ -829,7 +830,7 @@ public class PatentStarApiService {
             }
             patentColumnDTO.setIpc(classifies);
             //获取摘要附图
-            String pictureApi = this.getPictureApi(patentColumnDTO.getAppNo());
+            String pictureApi = this.getPictureApi(item.getRowApplicationNo());
             patentColumnDTO.setPictureGuid(pictureApi);
             //装载公开日
             if (item.getPublicDate() != null && !item.getPublicDate().trim().equals("")) {
@@ -848,26 +849,23 @@ public class PatentStarApiService {
                 patentColumnDTO.setInventor(names);
             }
 
-
-
             //装载权利人
             if (item.getCurrentApplicantStr() != null && !item.getCurrentApplicantStr().trim().equals("")) {
                 List<String> names = Arrays.asList(item.getCurrentApplicantStr().split(";"));
                 patentColumnDTO.setRightHolder(names);
             }
 
-
             //装载代理人
             if (item.getAgentStr() != null && !item.getAgentStr().trim().equals("")) {
                 List<String> names = Arrays.asList(item.getAgentStr().split(";"));
                 patentColumnDTO.setAgent(names);
             }
+
             //装载代理机构
             if (item.getAgencyStr() != null && !item.getAgencyStr() .trim().equals("")) {
                 patentColumnDTO.setAgency(item.getAgencyStr() );
             }
 
-
             patentColumnDTOS.add(patentColumnDTO);
         });
 
@@ -903,4 +901,32 @@ public class PatentStarApiService {
         return dto;
     }
 
+    /**
+     * 根据专利号查询外部权利要求
+     * @param vo
+     * @return
+     * @throws IOException
+     */
+    public PatentColumnDTO queryExternalDetail(PatentNoVO vo) throws IOException {
+        PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
+        String condition = "AN=" + vo.getPatentNo();
+        patentStarListDTO.setCurrentQuery(condition);
+        patentStarListDTO.setDBType("CN");
+        patentStarListDTO.setOrderBy("AD");
+        patentStarListDTO.setOrderByType("DESC");
+        patentStarListDTO.setPageNum(1);
+        patentStarListDTO.setRowCount(10);
+        Records records = this.patentStarSearchLocal(patentStarListDTO);
+        Object data = records.getData();
+        String s = JSONArray.toJSONString(data);
+        List<PatentColumnDTO> list = JSONArray.parseArray(s, PatentColumnDTO.class);
+        PatentColumnDTO dto = new PatentColumnDTO();
+        if (!CollectionUtils.isEmpty(list)) {
+            for (PatentColumnDTO columnDTO : list) {
+                BeanUtils.copyProperties(columnDTO, dto);
+            }
+        }
+        return dto;
+    }
+
 }

+ 16 - 4
src/main/resources/jsons/esCountAnalysis.json

@@ -208,7 +208,7 @@
     "type": "String",
     "value": "standerApplicant",
     "field": "SAT",
-    "esField": "stander_applicant.name.key",
+    "esField": "stander_applicant.name.raw",
     "esClass": "nestedCountAnalysisBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
@@ -220,7 +220,7 @@
     "type": "String",
     "value": "mergeApplicant",
     "field": "MAT",
-    "esField": "merge_applicant.name.key",
+    "esField": "merge_applicant.name.raw",
     "esClass": "nestedCountAnalysisBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
@@ -244,7 +244,7 @@
     "type": "String",
     "value": "standerRightHolder",
     "field": "SRH",
-    "esField": "stander_right_holder.name.key",
+    "esField": "stander_right_holder.name.raw",
     "esClass": "nestedCountAnalysisBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
@@ -256,7 +256,7 @@
     "type": "String",
     "value": "mergeRightHolder",
     "field": "MRH",
-    "esField": "merge_right_holder.name.key",
+    "esField": "merge_right_holder.name.raw",
     "esClass": "nestedCountAnalysisBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
@@ -276,6 +276,18 @@
     "ifAsCondition": "true"
   },
   {
+    "name": "合并发明人",
+    "type": "Array",
+    "value": "mergeRightHolder",
+    "field": "MIN",
+    "esField": "merge_inventor.name.raw",
+    "esClass": "nestedCountAnalysisBuilder",
+    "ifSearch": "false",
+    "ifGroup": "false",
+    "ifShow": "true",
+    "ifAsCondition": "true"
+  },
+  {
     "name": "代理机构",
     "type": "String",
     "value": "agency",

+ 18 - 4
src/main/resources/jsons/patent.json

@@ -171,7 +171,7 @@
     "type": "String",
     "value": "standerApplicant",
     "field": "SAT",
-    "esField": "stander_applicant.name.key",
+    "esField": "stander_applicant.name",
     "esClass": "nestedQueryBuilder",
     "ifSearch": "true",
     "ifGroup": "false",
@@ -185,7 +185,7 @@
     "type": "String",
     "value": "mergeApplicant",
     "field": "MAT",
-    "esField": "merge_applicant.name.key",
+    "esField": "merge_applicant.name",
     "esClass": "nestedQueryBuilder",
     "ifSearch": "true",
     "ifGroup": "false",
@@ -209,6 +209,20 @@
     "groupBy": "company"
   },
   {
+    "name": "合并发明人",
+    "type": "Array",
+    "value": "mergeRightHolder",
+    "field": "MIN",
+    "esField": "merge_inventor.name",
+    "esClass": "nestedQueryBuilder",
+    "ifSearch": "true",
+    "ifGroup": "false",
+    "ifShow": "true",
+    "ifStats": "true",
+    "ifAsCondition": "true",
+    "groupBy": "company"
+  },
+  {
     "name": "权利人",
     "type": "Array",
     "value": "rightHolder",
@@ -227,7 +241,7 @@
     "type": "String",
     "value": "standerRightHolder",
     "field": "SRH",
-    "esField": "stander_right_holder.name.key",
+    "esField": "stander_right_holder.name",
     "esClass": "nestedQueryBuilder",
     "ifSearch": "true",
     "ifGroup": "false",
@@ -241,7 +255,7 @@
     "type": "String",
     "value": "mergeRightHolder",
     "field": "MRH",
-    "esField": "merge_right_holder.name.key",
+    "esField": "merge_right_holder.name",
     "esClass": "nestedQueryBuilder",
     "ifSearch": "true",
     "ifGroup": "false",

+ 10 - 3
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -22,6 +22,7 @@ import cn.cslg.pas.common.vo.business.TempleByReportTypeVO;
 import cn.cslg.pas.controller.EventController;
 import cn.cslg.pas.controller.PatentController;
 import cn.cslg.pas.domain.es.FamilyPatent;
+import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.domain.es.PatentFamilyMessage;
 import cn.cslg.pas.service.business.ProductMarketDataService;
 import cn.cslg.pas.service.business.TempleService;
@@ -376,7 +377,7 @@ public class EventServiceTests {
 
     @Test
     public void aaaaa() throws Exception {
-        List<String> list = Arrays.asList("");
+        List<String> list = Arrays.asList("gh,ji");
         String str = "[";
         if (list.size() >= 1) {
             for (int i = 0; i < list.size(); i++) {
@@ -398,11 +399,17 @@ public class EventServiceTests {
         String personId = "ctx._source.custom_field.person_id = " + 1 + ";" + "\n";
         String createTime = "ctx._source.custom_field.create_time = " + new Date().getTime() + ";" + "\n";
         String fieldValue = "ctx._source.custom_field.field_value = " + str + ";" + "\n";
-        String statsValue = "ctx._source.custom_field.stats_value = " + list + ";";
+        String statsValue = "ctx._source.custom_field.stats_value = " + list;
 
-        String source = "\"\"" + projectId + field + fieldType + personId + createTime + fieldValue + statsValue + "\"\"";
+        String source = "\"" + projectId + field + fieldType + personId + createTime + fieldValue + statsValue + "\"";
 //        String source = "\"\"ctx._source.custom_field.project_id = " + 1 + ";" + "\n" +
 //                "ctx._source.custom_field.field=" + 2 + ";" + "\n" + "\"\"";
         System.out.println(source);
+
+        Patent patent = new Patent();
+        String id = "hy7ayIwB68vilgBjUWBz";
+        String name = "士大夫";
+        Integer type = 0;
+        esService.delMergePerson(patent, id, type, name);
     }
 }