|
@@ -11,11 +11,17 @@ import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
import cn.cslg.pas.common.vo.PatentData;
|
|
import cn.cslg.pas.common.vo.PatentData;
|
|
|
|
+import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
|
|
+import cn.cslg.pas.common.vo.StarPatentVO;
|
|
import cn.cslg.pas.common.vo.business.EsExportRefreshVO;
|
|
import cn.cslg.pas.common.vo.business.EsExportRefreshVO;
|
|
|
|
+import cn.cslg.pas.domain.es.ESCustomField;
|
|
|
|
+import cn.cslg.pas.domain.es.EsProjectTask;
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
|
+import cn.cslg.pas.domain.es.PatentJoin;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.service.business.ImportTaskService;
|
|
import cn.cslg.pas.service.business.ImportTaskService;
|
|
import cn.cslg.pas.service.common.PatentStarApiService;
|
|
import cn.cslg.pas.service.common.PatentStarApiService;
|
|
|
|
+import cn.cslg.pas.service.importPatent.ImportSinglePatentService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch._types.SortOptions;
|
|
import co.elastic.clients.elasticsearch._types.SortOptions;
|
|
@@ -71,6 +77,12 @@ public class EsExportService {
|
|
@Autowired
|
|
@Autowired
|
|
private PatentStarApiService patentStarApiService;
|
|
private PatentStarApiService patentStarApiService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private EsService esService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ImportSinglePatentService importSinglePatentService;
|
|
|
|
+
|
|
public void exportTree(File file) throws Exception {
|
|
public void exportTree(File file) throws Exception {
|
|
Sheet sheet = ReadExcelUtils.readExcel(file);
|
|
Sheet sheet = ReadExcelUtils.readExcel(file);
|
|
int total = sheet.getPhysicalNumberOfRows() - 1;
|
|
int total = sheet.getPhysicalNumberOfRows() - 1;
|
|
@@ -868,4 +880,675 @@ public class EsExportService {
|
|
}
|
|
}
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //-------------------------------------专利缺少信息的脏数据进行删除并且对于缺少信息的专利重新进行刷新---------------------------
|
|
|
|
+ // 导入接口
|
|
|
|
+ public String importPatent(List<String> list,Integer projectId) throws IOException {
|
|
|
|
+ ImportTaskDTO vo = new ImportTaskDTO();
|
|
|
|
+ vo.setImportContent(1111);
|
|
|
|
+ vo.setImportToId(projectId);
|
|
|
|
+ vo.setImportToType(0);
|
|
|
|
+ vo.setType(2);
|
|
|
|
+ vo.setFieldDTOS(new ArrayList<>());
|
|
|
|
+ vo.setSearchCondition(StringUtils.join(list, ","));
|
|
|
|
+ String param = new Gson().toJson(vo);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .writeTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS)
|
|
|
|
+ .build();
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url("http://192.168.2.107:8087/api/xiaoshi/importTask/addImportTask")
|
|
|
|
+ .addHeader("Cookie", "token=5T_nvys1wCh4QKm4t_XYSxxNz0Me6O4PrV__")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询出中国缺少信息的专利总数用于分页遍历
|
|
|
|
+ public void cnPatent() throws Exception {
|
|
|
|
+ System.out.println("The Refresh patent is starting");
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("applicant.name"));
|
|
|
|
+ Query n1 = QueryBuilders.nested(i -> i.path("applicant").query(q1));
|
|
|
|
+ Query b1 = QueryBuilders.bool(i -> i.mustNot(n1));
|
|
|
|
+ Query q2 = QueryBuilders.exists(i -> i.field("right_holder.name"));
|
|
|
|
+ Query n2 = QueryBuilders.nested(i -> i.path("right_holder").query(q2));
|
|
|
|
+ Query b2 = QueryBuilders.bool(i -> i.mustNot(n2));
|
|
|
|
+ Query q3 = QueryBuilders.exists(i -> i.field("inventor.name"));
|
|
|
|
+ Query n3 = QueryBuilders.nested(i -> i.path("inventor").query(q3));
|
|
|
|
+ Query b3 = QueryBuilders.bool(i -> i.mustNot(n3));
|
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(b1, b2, b3));
|
|
|
|
+ Query q = QueryBuilders.prefix(i -> i.field("patent_no.keyword").value("CN"));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q, query));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(10);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ System.out.println("total:" + total);
|
|
|
|
+ //分页
|
|
|
|
+ long pageNum = 1;
|
|
|
|
+ long pageSize = 1000;
|
|
|
|
+ long startSize;
|
|
|
|
+ long endSize;
|
|
|
|
+ do {
|
|
|
|
+ startSize = (pageNum - 1) * pageSize;
|
|
|
|
+ endSize = Math.min(startSize + pageSize, total);
|
|
|
|
+ this.queryCnPatentInfo(startSize, pageSize);
|
|
|
|
+ pageNum += 1;
|
|
|
|
+ } while (endSize < total);
|
|
|
|
+ System.out.println("The Refresh patent is finished");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询出中国缺少信息的专利信息
|
|
|
|
+ public void queryCnPatentInfo(Long startSize, Long endSize) throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("applicant.name"));
|
|
|
|
+ Query n1 = QueryBuilders.nested(i -> i.path("applicant").query(q1));
|
|
|
|
+ Query b1 = QueryBuilders.bool(i -> i.mustNot(n1));
|
|
|
|
+ Query q2 = QueryBuilders.exists(i -> i.field("right_holder.name"));
|
|
|
|
+ Query n2 = QueryBuilders.nested(i -> i.path("right_holder").query(q2));
|
|
|
|
+ Query b2 = QueryBuilders.bool(i -> i.mustNot(n2));
|
|
|
|
+ Query q3 = QueryBuilders.exists(i -> i.field("inventor.name"));
|
|
|
|
+ Query n3 = QueryBuilders.nested(i -> i.path("inventor").query(q3));
|
|
|
|
+ Query b3 = QueryBuilders.bool(i -> i.mustNot(n3));
|
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(b1, b2, b3));
|
|
|
|
+ Query q = QueryBuilders.prefix(i -> i.field("patent_no.keyword").value("CN"));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q, query));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ List<SortOptions> optionsList = new ArrayList<>();
|
|
|
|
+ SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field("patent_no.keyword").order(SortOrder.Desc).missing(-1)));
|
|
|
|
+ optionsList.add(sortOptions);
|
|
|
|
+ builder.sort(optionsList);
|
|
|
|
+ builder.from(startSize.intValue()).size(endSize.intValue());
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ String patentNo = patent.getPatentNo();
|
|
|
|
+ list.add(patentNo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.formatPatentNO(list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void worldPatent() throws Exception {
|
|
|
|
+ System.out.println("The Refresh patent is starting");
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("applicant.name"));
|
|
|
|
+ Query n1 = QueryBuilders.nested(i -> i.path("applicant").query(q1));
|
|
|
|
+ Query b1 = QueryBuilders.bool(i -> i.mustNot(n1));
|
|
|
|
+ Query q2 = QueryBuilders.exists(i -> i.field("right_holder.name"));
|
|
|
|
+ Query n2 = QueryBuilders.nested(i -> i.path("right_holder").query(q2));
|
|
|
|
+ Query b2 = QueryBuilders.bool(i -> i.mustNot(n2));
|
|
|
|
+ Query q3 = QueryBuilders.exists(i -> i.field("inventor.name"));
|
|
|
|
+ Query n3 = QueryBuilders.nested(i -> i.path("inventor").query(q3));
|
|
|
|
+ Query b3 = QueryBuilders.bool(i -> i.mustNot(n3));
|
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(b1, b2, b3));
|
|
|
|
+ Query q = QueryBuilders.wildcard(i -> i.field("patent_no.keyword").value("*CN*"));
|
|
|
|
+ Query bool1 = QueryBuilders.bool(i -> i.mustNot(q));
|
|
|
|
+ Query q4 = QueryBuilders.exists(i -> i.field("patent_no"));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q4, bool1,query));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(10);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ System.out.println("total:" + total);
|
|
|
|
+ //分页
|
|
|
|
+ long pageNum = 1;
|
|
|
|
+ long pageSize = 1000;
|
|
|
|
+ long startSize;
|
|
|
|
+ long endSize;
|
|
|
|
+ do {
|
|
|
|
+ startSize = (pageNum - 1) * pageSize;
|
|
|
|
+ endSize = Math.min(startSize + pageSize, total);
|
|
|
|
+ this.queryWorldPatentInfo(startSize, pageSize);
|
|
|
|
+ pageNum += 1;
|
|
|
|
+ } while (endSize < total);
|
|
|
|
+ System.out.println("The Refresh patent is finished");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void queryWorldPatentInfo(Long startSize, Long endSize) throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("applicant.name"));
|
|
|
|
+ Query n1 = QueryBuilders.nested(i -> i.path("applicant").query(q1));
|
|
|
|
+ Query b1 = QueryBuilders.bool(i -> i.mustNot(n1));
|
|
|
|
+ Query q2 = QueryBuilders.exists(i -> i.field("right_holder.name"));
|
|
|
|
+ Query n2 = QueryBuilders.nested(i -> i.path("right_holder").query(q2));
|
|
|
|
+ Query b2 = QueryBuilders.bool(i -> i.mustNot(n2));
|
|
|
|
+ Query q3 = QueryBuilders.exists(i -> i.field("inventor.name"));
|
|
|
|
+ Query n3 = QueryBuilders.nested(i -> i.path("inventor").query(q3));
|
|
|
|
+ Query b3 = QueryBuilders.bool(i -> i.mustNot(n3));
|
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(b1, b2, b3));
|
|
|
|
+ Query q = QueryBuilders.wildcard(i -> i.field("patent_no.keyword").value("*CN*"));
|
|
|
|
+ Query bool1 = QueryBuilders.bool(i -> i.mustNot(q));
|
|
|
|
+ Query q4 = QueryBuilders.exists(i -> i.field("patent_no"));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q4, bool1,query));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ List<SortOptions> optionsList = new ArrayList<>();
|
|
|
|
+ SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field("patent_no.keyword").order(SortOrder.Desc).missing(-1)));
|
|
|
|
+ optionsList.add(sortOptions);
|
|
|
|
+ builder.sort(optionsList);
|
|
|
|
+ builder.from(startSize.intValue()).size(endSize.intValue());
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ String patentNo = patent.getPatentNo();
|
|
|
|
+ list.add(patentNo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.formatPatentNO(list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void formatPatentNO(List<String> list) throws Exception {
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ for (String patentNo : list) {
|
|
|
|
+ String oldPatentId = this.queryOldByPatentNo(patentNo);
|
|
|
|
+ if (StringUtils.isEmpty(oldPatentId)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String newPatentId = "";
|
|
|
|
+ if (patentNo.startsWith("CN")) {
|
|
|
|
+ //中国专利
|
|
|
|
+ if (patentNo.length() == 12 && patentNo.contains(".")) {
|
|
|
|
+ String newPatentNo = this.formatCnNumber(patentNo);
|
|
|
|
+ newPatentId = this.queryNewByPatentNo(newPatentNo, oldPatentId);
|
|
|
|
+ } else if (patentNo.length() == 15){
|
|
|
|
+ String newPatentNo = this.formatNumber(patentNo);
|
|
|
|
+ newPatentId = this.queryNewByPatentNo(newPatentNo, oldPatentId);
|
|
|
|
+ } else {
|
|
|
|
+ newPatentId = this.queryNewByPatentNo(patentNo, oldPatentId);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //世界专利
|
|
|
|
+ newPatentId = this.queryNewByPatentNo(patentNo, oldPatentId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(newPatentId)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ this.getProjectPatent(oldPatentId,newPatentId);
|
|
|
|
+ this.getProductPatent(oldPatentId,newPatentId);
|
|
|
|
+ this.getProjectTaskPatent(oldPatentId,newPatentId);
|
|
|
|
+ this.getCustomFieldPatent(oldPatentId,newPatentId);
|
|
|
|
+ esService.deleteByIds(Collections.singletonList(oldPatentId));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String formatNumber(String str) {
|
|
|
|
+ return str.substring(0, 14) +
|
|
|
|
+ "." +
|
|
|
|
+ str.substring(14, 15);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String formatCnNumber(String str) {
|
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
|
+ builder.append(str, 0, 2);
|
|
|
|
+ int num = Integer.parseInt(str.substring(2, 3));
|
|
|
|
+ if (num > 6) {
|
|
|
|
+ builder.append("19");
|
|
|
|
+ } else {
|
|
|
|
+ builder.append("20");
|
|
|
|
+ }
|
|
|
|
+ builder.append(str, 2, 5);
|
|
|
|
+ builder.append("00");
|
|
|
|
+ builder.append(str, 5, str.indexOf("."));
|
|
|
|
+ String s = builder.toString();
|
|
|
|
+ String s1 = s.substring(2);
|
|
|
|
+ char c = this.calculateChecksum(s1);
|
|
|
|
+ builder.append(".").append(c);
|
|
|
|
+ return builder.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public char calculateChecksum(String input) {
|
|
|
|
+ int sum = 0;
|
|
|
|
+ int[] weights = {2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5};
|
|
|
|
+
|
|
|
|
+ // 遍历字符串中的每个字符,并计算乘积之和
|
|
|
|
+ for (int i = 0; i < input.length(); i++) {
|
|
|
|
+ char digit = input.charAt(i);
|
|
|
|
+ int num = Character.getNumericValue(digit);
|
|
|
|
+ sum += num * weights[i];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 计算总和除以11的余数
|
|
|
|
+ int remainder = sum % 11;
|
|
|
|
+
|
|
|
|
+ // 根据余数确定校验位
|
|
|
|
+ char checksum;
|
|
|
|
+ if (remainder < 10) {
|
|
|
|
+ checksum = (char) ('0' + remainder);
|
|
|
|
+ } else {
|
|
|
|
+ checksum = 'X';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return checksum;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //根据问题类型中的专利号查询
|
|
|
|
+ public String queryOldByPatentNo(String oldPatentNo) throws Exception {
|
|
|
|
+ String patentId = "";
|
|
|
|
+ if (StringUtils.isNotEmpty(oldPatentNo)) {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query query = QueryBuilders.term(t -> t.field("patent_no.keyword").value(oldPatentNo));
|
|
|
|
+ builder.query(query);
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ patentId = hits.get(0).id();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return patentId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //根据格式化后的专利号查询
|
|
|
|
+ public String queryNewByPatentNo(String newPatentNo,String oldPatentId) throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query query = QueryBuilders.term(t -> t.field("patent_no.keyword").value(newPatentNo));
|
|
|
|
+ builder.query(query);
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ String newPatentId = "";
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String patentId = hit.id();
|
|
|
|
+ if (!patentId.equals(oldPatentId)) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ if (!CollectionUtils.isEmpty(patent.getApplicant()) &&
|
|
|
|
+ !CollectionUtils.isEmpty(patent.getRightHolder()) &&
|
|
|
|
+ !CollectionUtils.isEmpty(patent.getInventor())) {
|
|
|
|
+ newPatentId = patentId;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(newPatentId)) {
|
|
|
|
+ Hit<Patent> hit = hits.stream().filter(i -> !i.id().equals(oldPatentId)).findFirst().orElse(null);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(hit) && hit != null) {
|
|
|
|
+ newPatentId = hit.id();
|
|
|
|
+ } else {
|
|
|
|
+ newPatentId = this.queryWDExtra(newPatentNo);
|
|
|
|
+// Boolean flag = this.queryExtra(newPatentNo);
|
|
|
|
+// if (Boolean.TRUE.equals(flag)) {
|
|
|
|
+// this.importPatent(Collections.singletonList(newPatentNo), 614);
|
|
|
|
+// Thread.sleep(3000);
|
|
|
|
+// newPatentId = this.queryOldByPatentNo(newPatentNo);
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String patentId = hit.id();
|
|
|
|
+ if (!patentId.equals(oldPatentId) && !patentId.equals(newPatentId)) {
|
|
|
|
+ list.add(patentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ newPatentId = this.queryWDExtra(newPatentNo);
|
|
|
|
+// Boolean flag = this.queryExtra(newPatentNo);
|
|
|
|
+// if (Boolean.TRUE.equals(flag)) {
|
|
|
|
+// this.importPatent(Collections.singletonList(newPatentNo), 614);
|
|
|
|
+// Thread.sleep(3000);
|
|
|
|
+// newPatentId = this.queryOldByPatentNo(newPatentNo);
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ esService.deleteByIds(list);
|
|
|
|
+ }
|
|
|
|
+ return newPatentId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Boolean queryExtra(String patentNo) throws IOException {
|
|
|
|
+ boolean flag = true;
|
|
|
|
+ PatentStarListDTO vo = new PatentStarListDTO();
|
|
|
|
+ vo.setCurrentQuery("F XX (" + patentNo + "/PN-CN/GJ)");
|
|
|
|
+ vo.setDBType("WD");
|
|
|
|
+ vo.setPageNum(1);
|
|
|
|
+ vo.setRowCount(10);
|
|
|
|
+ vo.setOrderBy("AD");
|
|
|
|
+ vo.setOrderByType("DESC");
|
|
|
|
+ vo.setFormed(true);
|
|
|
|
+ Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(vo);
|
|
|
|
+ if (resultMap == null || (Integer) resultMap.get("total") == 0) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
|
|
|
|
+ if (CollectionUtils.isEmpty(starPatents)) {
|
|
|
|
+ flag = false;
|
|
|
|
+ }
|
|
|
|
+ return flag;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String queryWDExtra(String patentNo) throws Exception {
|
|
|
|
+ String patentId = "";
|
|
|
|
+ PatentStarListDTO vo = new PatentStarListDTO();
|
|
|
|
+ vo.setCurrentQuery("F XX (" + patentNo + "/PN-CN/GJ)");
|
|
|
|
+ vo.setDBType("WD");
|
|
|
|
+ vo.setPageNum(1);
|
|
|
|
+ vo.setRowCount(10);
|
|
|
|
+ vo.setOrderBy("AD");
|
|
|
|
+ vo.setOrderByType("DESC");
|
|
|
|
+ vo.setFormed(true);
|
|
|
|
+ Map<String, Object> resultMap = null;
|
|
|
|
+ try {
|
|
|
|
+ resultMap = patentStarApiService.patentStarSearchApi(vo);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if (resultMap == null || (Integer) resultMap.get("total") == 0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
|
|
|
|
+ if (!CollectionUtils.isEmpty(starPatents)) {
|
|
|
|
+ StarPatentVO starPatentVO = starPatents.get(0);
|
|
|
|
+ patentId = this.addNewPatent(starPatentVO);
|
|
|
|
+ }
|
|
|
|
+ return patentId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public String addNewPatent(StarPatentVO starPatentVO) throws Exception {
|
|
|
|
+ Patent patent = importSinglePatentService.getPatentCataloguingFromWeb(starPatentVO);
|
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
|
+ patentJoin.setName("patent");
|
|
|
|
+ patent.setPatentJoin(patentJoin);
|
|
|
|
+ return esService.addPatent(patent);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取项目
|
|
|
|
+ public void getProjectPatent(String oldPatentId,String newPatentId) throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("project_id"));
|
|
|
|
+ Query q2 = QueryBuilders.ids(i -> i.values(oldPatentId));
|
|
|
|
+ Query q3 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q2));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q3));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(200);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ Integer projectId = patent.getProjectId();
|
|
|
|
+ Patent patentChild = new Patent();
|
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
|
+ patentJoin.setParent(newPatentId);
|
|
|
|
+ patentJoin.setName("project");
|
|
|
|
+ patentChild.setPatentJoin(patentJoin);
|
|
|
|
+ patentChild.setProjectId(projectId);
|
|
|
|
+ esService.addChildPatent(patentChild, newPatentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取任务
|
|
|
|
+ public void getProjectTaskPatent(String oldPatentId,String newPatentId) {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("project_task"));
|
|
|
|
+ Query q2 = QueryBuilders.ids(i -> i.values(oldPatentId));
|
|
|
|
+ Query q3 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q2));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q3));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(200);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ EsProjectTask projectTask = patent.getProjectTask();
|
|
|
|
+ Patent patent1 = new Patent();
|
|
|
|
+ EsProjectTask esProjectTask = new EsProjectTask();
|
|
|
|
+ esProjectTask.setProjectId(projectTask.getProjectId());
|
|
|
|
+ esProjectTask.setTaskId(projectTask.getTaskId());
|
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
|
+ patentJoin.setParent(newPatentId);
|
|
|
|
+ patentJoin.setName("task");
|
|
|
|
+ patent1.setPatentJoin(patentJoin);
|
|
|
|
+ patent1.setProjectTask(esProjectTask);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取导入任务
|
|
|
|
+ public void getImportTaskPatent(String oldPatentId,String newPatentId) {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("import_task"));
|
|
|
|
+ Query q2 = QueryBuilders.ids(i -> i.values(oldPatentId));
|
|
|
|
+ Query q3 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q2));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q3));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(200);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取产品
|
|
|
|
+ public void getProductPatent(String oldPatentId,String newPatentId) throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("product_id"));
|
|
|
|
+ Query q2 = QueryBuilders.ids(i -> i.values(oldPatentId));
|
|
|
|
+ Query q3 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q2));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q3));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(200);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ Integer productId = patent.getProductId();
|
|
|
|
+ Patent patentChild = new Patent();
|
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
|
+ patentJoin.setParent(newPatentId);
|
|
|
|
+ patentJoin.setName("product");
|
|
|
|
+ patentChild.setPatentJoin(patentJoin);
|
|
|
|
+ patentChild.setProductId(productId);
|
|
|
|
+ esService.addChildPatent(patentChild, newPatentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取自定义字段栏位
|
|
|
|
+ public void getCustomFieldPatent(String oldPatentId,String newPatentId) throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("custom_field"));
|
|
|
|
+ Query q2 = QueryBuilders.ids(i -> i.values(oldPatentId));
|
|
|
|
+ Query q3 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q2));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q3));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(200);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ ESCustomField esCustomField = patent.getESCustomField();
|
|
|
|
+ Patent patentChild = new Patent();
|
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
|
+ patentJoin.setParent(newPatentId);
|
|
|
|
+ patentJoin.setName("project_customfield");
|
|
|
|
+ patentChild.setPatentJoin(patentJoin);
|
|
|
|
+ patentChild.setESCustomField(esCustomField);
|
|
|
|
+ esService.addChildPatent(patentChild, newPatentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取标注
|
|
|
|
+ public void getMarkingsPatent(String oldPatentId,String newPatentId) {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("markings"));
|
|
|
|
+ Query q2 = QueryBuilders.ids(i -> i.values(oldPatentId));
|
|
|
|
+ Query q3 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q2));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q3));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(200);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getWOErrorPatent() throws Exception {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.prefix(i -> i.field("public_no.keyword").value("WO"));
|
|
|
|
+ Query q2 = QueryBuilders.prefix(i -> i.field("patent_no.keyword").value("CN"));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q2));
|
|
|
|
+ builder.query(bool);
|
|
|
|
+ builder.from(0).size(1000);
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
|
+ try {
|
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String oldPatentId = hit.id();
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ String publicNo = patent.getPublicNo();
|
|
|
|
+ String newPatentId = this.queryNewByPatentNo(publicNo, oldPatentId);
|
|
|
|
+ if (StringUtils.isEmpty(newPatentId)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ map.put(oldPatentId, newPatentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!CollectionUtils.isEmpty(map)) {
|
|
|
|
+ for (String oldPatentId : map.keySet()) {
|
|
|
|
+ String newPatentId = map.get(oldPatentId);
|
|
|
|
+ if (StringUtils.isEmpty(newPatentId)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ this.getProjectPatent(oldPatentId,newPatentId);
|
|
|
|
+ this.getProductPatent(oldPatentId,newPatentId);
|
|
|
|
+ this.getProjectTaskPatent(oldPatentId,newPatentId);
|
|
|
|
+ this.getCustomFieldPatent(oldPatentId,newPatentId);
|
|
|
|
+ esService.deleteByIds(Collections.singletonList(oldPatentId));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|