|
@@ -1,6 +1,9 @@
|
|
package cn.cslg.pas.service.business.es;
|
|
package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.ExportDTO;
|
|
import cn.cslg.pas.common.dto.ExportDTO;
|
|
|
|
+import cn.cslg.pas.common.dto.ImportTaskDTO;
|
|
|
|
+import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
|
|
+import cn.cslg.pas.common.dto.PatentStarListDTO;
|
|
import cn.cslg.pas.common.utils.ExcelUtils;
|
|
import cn.cslg.pas.common.utils.ExcelUtils;
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
import cn.cslg.pas.common.utils.ReadExcelUtils;
|
|
import cn.cslg.pas.common.utils.ReadExcelUtils;
|
|
@@ -8,12 +11,32 @@ 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.business.EsExportRefreshVO;
|
|
|
|
+import cn.cslg.pas.domain.es.Patent;
|
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
|
+import cn.cslg.pas.service.business.ImportTaskService;
|
|
|
|
+import cn.cslg.pas.service.common.PatentStarApiService;
|
|
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._types.SortOptions;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
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.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
|
+import com.google.gson.Gson;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
+import okhttp3.MediaType;
|
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
|
+import okhttp3.Request;
|
|
|
|
+import okhttp3.RequestBody;
|
|
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
@@ -23,6 +46,7 @@ import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
@@ -30,18 +54,23 @@ import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
public class EsExportService {
|
|
public class EsExportService {
|
|
|
|
+ private final ElasticsearchClient client;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private FormatQueryService formatQueryService;
|
|
private FormatQueryService formatQueryService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ImportTaskService importTaskService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PatentStarApiService patentStarApiService;
|
|
|
|
+
|
|
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;
|
|
@@ -220,4 +249,623 @@ public class EsExportService {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void timingImportPatent() throws IOException {
|
|
|
|
+ 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.getPatentNO1(startSize, pageSize);
|
|
|
|
+ pageNum += 1;
|
|
|
|
+ } while (endSize < total);
|
|
|
|
+ System.out.println("The Refresh patent is finished");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getPatentNO1(Long startSize, Long endSize) throws IOException {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ ImportTaskDTO vo = new ImportTaskDTO();
|
|
|
|
+ vo.setImportContent(1000);
|
|
|
|
+ vo.setImportToId(5473);
|
|
|
|
+ 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("https://xsip.cn/api/xiaoshi/importTask/addImportTask")
|
|
|
|
+ .addHeader("Cookie","_ga=GA1.1.1311128280.1715044933; _ga_73YJPXJTLX=GS1.1.1732081012.6.0.1732081012.0.0.0; token=dj_DhTjDciRmbDGb4_SWqCQnLWFDsu0CjQ__")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ String s = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ if (ObjectUtils.isNotEmpty(s)) {
|
|
|
|
+ System.out.println("专利刷新从第" + startSize + "开始到第" + endSize + "刷新20241111111111");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void timingImportWorldPatent() throws IOException {
|
|
|
|
+ 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.getWorldPatentNO1(startSize, pageSize);
|
|
|
|
+ pageNum += 1;
|
|
|
|
+ } while (endSize < total);
|
|
|
|
+ System.out.println("The Refresh patent is finished");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getWorldPatentNO1(Long startSize, Long endSize) throws IOException {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ ImportTaskDTO vo = new ImportTaskDTO();
|
|
|
|
+ vo.setImportContent(1000);
|
|
|
|
+ vo.setImportToId(5473);
|
|
|
|
+ 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("https://xsip.cn/api/xiaoshi/importTask/addImportTask")
|
|
|
|
+ .addHeader("Cookie","_ga=GA1.1.1311128280.1715044933; _ga_73YJPXJTLX=GS1.1.1732081012.6.0.1732081012.0.0.0; token=MZ_GPPbOKOQOHO5M5_MXlpLUQOH9E3LB28__")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ String s = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ if (ObjectUtils.isNotEmpty(s)) {
|
|
|
|
+ System.out.println("专利刷新从第" + startSize + "开始到第" + endSize + "刷新20241111111111");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getCNPatentNO() 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(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();
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ loadExport(list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getWorldPatentNO() 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(20000).size(3000);
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ loadExport(list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loadExport(List<String> list) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("专利号");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ String no = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 800);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(no);
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, "专利号", ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public Long getCNNumber() {
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ return response.hits().total().value();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Long getWorldNumber() {
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ return response.hits().total().value();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getCNNum() 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(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();
|
|
|
|
+ List<EsExportRefreshVO> list = new ArrayList<>();
|
|
|
|
+ if (!CollectionUtils.isEmpty(hits)) {
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ String patentNo = patent.getPatentNo();
|
|
|
|
+ String number = null;
|
|
|
|
+ if (StringUtils.isNotEmpty(patent.getPublicNo())) {
|
|
|
|
+ number = patent.getPublicNo();
|
|
|
|
+ } else if (StringUtils.isNotEmpty(patent.getGrantNo())) {
|
|
|
|
+ number = patent.getGrantNo();
|
|
|
|
+ }
|
|
|
|
+ EsExportRefreshVO esExportRefreshVO = new EsExportRefreshVO();
|
|
|
|
+ esExportRefreshVO.setPatentNo(patentNo);
|
|
|
|
+ if (StringUtils.isNotEmpty(number)) {
|
|
|
|
+ esExportRefreshVO.setPublicNo(number);
|
|
|
|
+ final String s = get(number);
|
|
|
|
+ esExportRefreshVO.setPatentNo1(s);
|
|
|
|
+ } else {
|
|
|
|
+ final String s = get(patentNo);
|
|
|
|
+ if (StringUtils.isNotEmpty(s)) {
|
|
|
|
+ esExportRefreshVO.setPatentNo1(s);
|
|
|
|
+ esExportRefreshVO.setRemark("专利号不完整");
|
|
|
|
+ } else {
|
|
|
|
+ String result = this.getCNDeficency(esExportRefreshVO.getPatentNo());
|
|
|
|
+ esExportRefreshVO.setRemark(result);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ list.add(esExportRefreshVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ this.loadExport1(list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String get(String number) throws Exception{
|
|
|
|
+ PatentStarListDTO vo = new PatentStarListDTO();
|
|
|
|
+ vo.setPageNum(1);
|
|
|
|
+ vo.setRowCount(10);
|
|
|
|
+ vo.setDBType("CN");
|
|
|
|
+ vo.setOrderBy("AD");
|
|
|
|
+ vo.setOrderByType("DESC");
|
|
|
|
+ vo.setNumberQuery(number);
|
|
|
|
+ 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.110:8879/api/xiaoshi/patentStar/select")
|
|
|
|
+ .addHeader("Cookie","token=4o_bEuMTiRgqCVeN3_xdaQNY4CNc1qDMaU__")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ String s = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(s);
|
|
|
|
+ JSONObject jsonObject1 = jsonObject.getJSONObject("data");
|
|
|
|
+ if (ObjectUtils.isEmpty(jsonObject1)) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ JSONArray data = jsonObject1.getJSONArray("data");
|
|
|
|
+ PatentColumnDTO columnDTO = data.getObject(0, PatentColumnDTO.class);
|
|
|
|
+ String patentNo = "";
|
|
|
|
+ if (StringUtils.isNotEmpty(columnDTO.getPatentNo()) && !StringUtils.equals(number,columnDTO.getPatentNo())) {
|
|
|
|
+ patentNo = columnDTO.getPatentNo();
|
|
|
|
+ }
|
|
|
|
+ return patentNo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loadExport1(List<EsExportRefreshVO> list) throws Exception {
|
|
|
|
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
|
+ List<String> headers = Arrays.asList("缺失专利号","公开或公告号","正确专利号","备注");
|
|
|
|
+ HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
|
|
|
|
+ HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
|
|
|
|
+ sheet.setDefaultColumnWidth(30);
|
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);//新建标头行
|
|
|
|
+ headerRow.setHeight((short) 500);
|
|
|
|
+ HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
|
|
|
|
+ HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
|
|
|
|
+ for (int i = 0; i < headers.size(); i++) {//遍历设置标头
|
|
|
|
+ HSSFCell cell = headerRow.createCell(i);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(headerCellStyle);
|
|
|
|
+ headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
|
|
|
|
+ headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ headerCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(headerCellStyle);
|
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ EsExportRefreshVO esExportRefreshVO = list.get(i);
|
|
|
|
+ HSSFRow row = sheet.createRow(i + 1);//新建一普通行
|
|
|
|
+ row.setHeight((short) 800);
|
|
|
|
+ HSSFCell cell = row.createCell(0);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell.setCellStyle(commonCellStyle);
|
|
|
|
+ cell.setCellValue(esExportRefreshVO.getPatentNo());
|
|
|
|
+
|
|
|
|
+ HSSFCell cell1 = row.createCell(1);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell1.setCellStyle(commonCellStyle);
|
|
|
|
+ cell1.setCellValue(esExportRefreshVO.getPublicNo());
|
|
|
|
+
|
|
|
|
+ HSSFCell cell2 = row.createCell(2);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell2.setCellStyle(commonCellStyle);
|
|
|
|
+ cell2.setCellValue(esExportRefreshVO.getPatentNo1());
|
|
|
|
+
|
|
|
|
+ HSSFCell cell3 = row.createCell(3);
|
|
|
|
+ ExcelUtils.setExcelCellStyle(commonCellStyle);
|
|
|
|
+ commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
|
+ commonCellStyle.setWrapText(true);
|
|
|
|
+ cell3.setCellStyle(commonCellStyle);
|
|
|
|
+ cell3.setCellValue(esExportRefreshVO.getRemark());
|
|
|
|
+ }
|
|
|
|
+ hssfWorkbook.write(out);
|
|
|
|
+ byte[] bytes = out.toByteArray();
|
|
|
|
+ FileUtils.getFileByBytes(bytes, "缺失专利号匹配", ".xlsx");
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ throw new FileNotFoundException();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getCNDeficency(String patentNo) {
|
|
|
|
+ String res = "";
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query query = QueryBuilders.term(i -> i.field("patent_no.keyword").value(patentNo));
|
|
|
|
+ builder.query(query);
|
|
|
|
+ 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(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());
|
|
|
|
+ }
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ if (total > 1) {
|
|
|
|
+ res = "该专利号存在两条数据,该条含有专利号但缺少其他数据";
|
|
|
|
+ } else {
|
|
|
|
+ res = "没有该专利";
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
}
|
|
}
|