|
@@ -31,10 +31,7 @@ import cn.hutool.core.util.PageUtil;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
import co.elastic.clients.elasticsearch._types.InlineScript;
|
|
|
import co.elastic.clients.elasticsearch._types.Script;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.NestedAggregation;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.TermsAggregation;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
@@ -669,7 +666,19 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
builder.index("patent");
|
|
|
-// Query mustQ = QueryBuilders.hasChild(i -> i.type("project").query(j -> j.term(n -> n.field("project_id").value(projectId))));
|
|
|
+// Query query11 = null;
|
|
|
+// if (type == 0) {
|
|
|
+// if (StringUtils.isNotEmpty(condition)) {
|
|
|
+// String s = condition.substring(condition.indexOf("=")+1);
|
|
|
+// //1. 解析检索条件
|
|
|
+// treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
+// //2. 从es中检索数据
|
|
|
+// query11 = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
if (!CollectionUtils.isEmpty(conditionList)) {
|
|
|
for (String name : conditionList) {
|
|
|
List<Query> queries = new ArrayList<>();
|
|
@@ -911,6 +920,217 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
|
|
|
return records;
|
|
|
}
|
|
|
|
|
|
+ public Records getAllMergePerson(GetAllPersonVO vo) throws Exception {
|
|
|
+ Integer projectId = vo.getProjectId();
|
|
|
+ Long pageNum = vo.getPageNum();
|
|
|
+ Long pageSize = vo.getPageSize();
|
|
|
+ Integer type = vo.getType();
|
|
|
+ String condition = vo.getSearchQuery();
|
|
|
+
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ builder.size(0);
|
|
|
+ String searchCondition = "";
|
|
|
+ if (StringUtils.isNotEmpty(condition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
+ //3. 从es中检索数据
|
|
|
+ Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
|
|
|
+ builder.query(q);
|
|
|
+ if (type == 0) {
|
|
|
+ Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue()));
|
|
|
+ Aggregation termAgg = new Aggregation.Builder().terms(i -> i.field("merge_applicant.name.raw").size(100000))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("termAgg", bucketSort);
|
|
|
+ }}).build();
|
|
|
+ Aggregation aggregation = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_applicant").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("nestedAgg", termAgg);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+
|
|
|
+ Aggregation cardinality = AggregationBuilders.cardinality(i -> i.field("merge_applicant.name.raw"));
|
|
|
+ Aggregation totalAgg = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_applicant").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("total", cardinality);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("totalAgg", totalAgg);
|
|
|
+
|
|
|
+ //权利人
|
|
|
+ Aggregation bucketSort1 = AggregationBuilders.bucketSort(i -> i.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue()));
|
|
|
+ Aggregation termAgg1 = new Aggregation.Builder().terms(i -> i.field("merge_right_holder.name.raw").size(100000))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("rightTermAgg", bucketSort1);
|
|
|
+ }}).build();
|
|
|
+ Aggregation aggregation1 = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_right_holder").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("rightNestedAgg", termAgg1);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("rightAgg", aggregation1);
|
|
|
+ } else {
|
|
|
+ Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue()));
|
|
|
+ Aggregation termAgg = new Aggregation.Builder().terms(i -> i.field("merge_inventor.name.raw").size(100000))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("termAgg", bucketSort);
|
|
|
+ }}).build();
|
|
|
+ Aggregation aggregation = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_inventor").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("nestedAgg", termAgg);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+
|
|
|
+ Aggregation cardinality = AggregationBuilders.cardinality(i -> i.field("merge_inventor.name.raw"));
|
|
|
+ Aggregation totalAgg = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_inventor").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("total", cardinality);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("totalAgg", totalAgg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (type == 0) {
|
|
|
+ //申请人
|
|
|
+ Query q1 = QueryBuilders.term(i -> i.field("merge_applicant.project_id").value(projectId));
|
|
|
+ Query nestedQ1 = QueryBuilders.nested(i -> i.path("merge_applicant").query(q1));
|
|
|
+ Query q2 = QueryBuilders.term(i -> i.field("merge_right_holder.project_id").value(projectId));
|
|
|
+ Query nestedQ2 = QueryBuilders.nested(i -> i.path("merge_right_holder").query(q2));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.should(nestedQ1, nestedQ2));
|
|
|
+ builder.query(bool);
|
|
|
+ Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue()));
|
|
|
+ Aggregation termAgg = new Aggregation.Builder().terms(i -> i.field("merge_applicant.name.raw").size(100000))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("termAgg", bucketSort);
|
|
|
+ }}).build();
|
|
|
+ Aggregation aggregation = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_applicant").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("nestedAgg", termAgg);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+
|
|
|
+ Aggregation cardinality = AggregationBuilders.cardinality(i -> i.field("merge_applicant.name.raw"));
|
|
|
+ Aggregation totalAgg = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_applicant").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("total", cardinality);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("totalAgg", totalAgg);
|
|
|
+
|
|
|
+ //权利人
|
|
|
+ Aggregation bucketSort1 = AggregationBuilders.bucketSort(i -> i.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue()));
|
|
|
+ Aggregation termAgg1 = new Aggregation.Builder().terms(i -> i.field("merge_right_holder.name.raw").size(100000))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("rightTermAgg", bucketSort1);
|
|
|
+ }}).build();
|
|
|
+ Aggregation aggregation1 = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_right_holder").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("rightNestedAgg", termAgg1);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("rightAgg", aggregation1);
|
|
|
+ } else {
|
|
|
+ Query q = QueryBuilders.term(i -> i.field("merge_inventor.project_id").value(projectId));
|
|
|
+ Query nestedQ = QueryBuilders.nested(i -> i.path("merge_inventor").query(q));
|
|
|
+ builder.query(nestedQ);
|
|
|
+ Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue()));
|
|
|
+ Aggregation termAgg = new Aggregation.Builder().terms(i -> i.field("merge_inventor.name.raw").size(100000))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("termAgg", bucketSort);
|
|
|
+ }}).build();
|
|
|
+ Aggregation aggregation = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_inventor").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("nestedAgg", termAgg);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+
|
|
|
+ Aggregation cardinality = AggregationBuilders.cardinality(i -> i.field("merge_inventor.name.raw"));
|
|
|
+ Aggregation totalAgg = new Aggregation.Builder().nested(new NestedAggregation.Builder().
|
|
|
+ path("merge_inventor").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("total", cardinality);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("totalAgg", totalAgg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate totalAgg = response.aggregations().get("totalAgg");
|
|
|
+ Aggregate totalAggregate = totalAgg.nested().aggregations().get("total");
|
|
|
+ long total = totalAggregate.cardinality().value();
|
|
|
+ List<String> mergeList = new ArrayList<>();
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
+ Aggregate nestedAgg = agg.nested().aggregations().get("nestedAgg");
|
|
|
+ List<StringTermsBucket> buckets = nestedAgg.sterms().buckets().array();
|
|
|
+ for (StringTermsBucket bucket : buckets) {
|
|
|
+ String value = bucket.key().stringValue();
|
|
|
+ mergeList.add(value);
|
|
|
+ }
|
|
|
+ Aggregate rightAgg = response.aggregations().get("rightAgg");
|
|
|
+ Aggregate rightNestedAgg = rightAgg.nested().aggregations().get("rightNestedAgg");
|
|
|
+ List<StringTermsBucket> bucketList = rightNestedAgg.sterms().buckets().array();
|
|
|
+ if (!CollectionUtils.isEmpty(bucketList)) {
|
|
|
+ for (StringTermsBucket bucket : bucketList) {
|
|
|
+ String value = bucket.key().stringValue();
|
|
|
+ mergeList.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<GetAllPersonDTO> personDTOList = new ArrayList<>();
|
|
|
+ List<GetAllPersonDTO> mergePersonList = new ArrayList<>();
|
|
|
+ List<GetAllPersonDTO> personList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<String> nameList = mergeList.stream().distinct().collect(Collectors.toList());
|
|
|
+ if (nameList.size() > pageSize) {
|
|
|
+ nameList.remove(nameList.size() - 1);
|
|
|
+ }
|
|
|
+ List<MergePerson> mergePeopleList = mergePersonMapper.selectList(new LambdaQueryWrapper<MergePerson>()
|
|
|
+ .eq(MergePerson::getProjectId, projectId));
|
|
|
+ if (!CollectionUtils.isEmpty(mergePeopleList)) {
|
|
|
+ for (MergePerson person : mergePeopleList) {
|
|
|
+ GetAllPersonDTO dto = new GetAllPersonDTO();
|
|
|
+ dto.setName(person.getName());
|
|
|
+ dto.setMergeId(person.getId());
|
|
|
+ dto.setType(person.getType());
|
|
|
+ dto.setRemark(person.getRemark());
|
|
|
+ dto.setAbbreviation(person.getAbbreviation());
|
|
|
+ dto.setCountry(person.getCountry());
|
|
|
+ dto.setProvince(person.getProvince());
|
|
|
+ dto.setAddress(person.getAddress());
|
|
|
+ mergePersonList.add(dto);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (String name : nameList) {
|
|
|
+ GetAllPersonDTO dto = new GetAllPersonDTO();
|
|
|
+ dto.setName(name);
|
|
|
+ personList.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(mergePersonList)) {
|
|
|
+ List<GetAllPersonDTO> collect = mergePersonList.stream().sorted(Comparator.comparing(GetAllPersonDTO::getName)).collect(Collectors.toList());
|
|
|
+ personDTOList.addAll(collect);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(personList)) {
|
|
|
+ List<GetAllPersonDTO> collect = personList.stream().filter(i -> !StringUtils.isEmpty(i.getName())).collect(Collectors.toList());
|
|
|
+ List<GetAllPersonDTO> list = collect.stream().sorted(Comparator.comparing(GetAllPersonDTO::getName).reversed()).collect(Collectors.toList());
|
|
|
+ personDTOList.addAll(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(pageNum);
|
|
|
+ records.setSize(pageSize);
|
|
|
+ records.setData(personDTOList);
|
|
|
+ records.setTotal(total);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发明人/权利人/申请人合并后的名称移除
|
|
|
*
|