Bladeren bron

Merge remote-tracking branch 'origin/master'

xiexiang 1 jaar geleden
bovenliggende
commit
c06aba40e5

+ 1 - 1
src/main/java/cn/cslg/pas/common/dto/business/EsCountDetailDTO.java

@@ -7,6 +7,6 @@ public class EsCountDetailDTO {
     //名称
     private String name;
     //数量
-    private Integer number;
+    private Long number;
 
 }

+ 3 - 0
src/main/java/cn/cslg/pas/domain/es/ESCustomFieldHistory.java

@@ -47,6 +47,9 @@ public class ESCustomFieldHistory {
     @JsonProperty("field_value")
     List<String> fieldValue;
 
+    @JsonProperty("save_value")
+    List<String> savedValue;
+
     /**
      * 创建人id
      */

+ 1 - 1
src/main/java/cn/cslg/pas/factorys/EsCountBuilderFactory/DateHistogramBuilder.java

@@ -20,7 +20,7 @@ public class DateHistogramBuilder implements IEsCountBuilder{
     public Aggregation createAggregation() {
         Aggregation aggregation = AggregationBuilders.dateHistogram(i -> i.field(field).format("yyyy").calendarInterval(CalendarInterval.Year));
         if (StringUtils.isNotEmpty(valueTwo)) {
-            Query query = QueryBuilders.range(j -> j.from(valueOne).to(valueTwo));
+            Query query = QueryBuilders.range(j -> j.field(field).from(valueOne).to(valueTwo));
             Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
             aggregation.aggregations().put("filter_agg",filter);
         }

+ 75 - 0
src/main/java/cn/cslg/pas/factorys/EsCountBuilderFactory/FilterCountBuilder.java

@@ -0,0 +1,75 @@
+package cn.cslg.pas.factorys.EsCountBuilderFactory;
+
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
+import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
+
+public class FilterCountBuilder implements IEsCountBuilder{
+    public String field = "";
+    public String valueOne = "";
+    public String valueTwo = "";
+    public Integer topN = 10;
+    public String path = "";
+
+
+    @Override
+    public Aggregation createAggregation() {
+        String str = "*";
+        String s = str.concat(valueOne).concat("*");
+        Query query = QueryBuilders.wildcard(i -> i.field(field).value(s));
+        AggregationBuilders.filter(n -> n.term(m -> m.field(field).value(valueOne)));
+//        AggregationBuilders.filters(n -> n.filters(m -> m.array()));
+        return AggregationBuilders.filter(i -> i.bool(j -> j.must(query)));
+    }
+
+    @Override
+    public String getField() {
+        return field;
+    }
+
+    @Override
+    public void setField(String field) {
+        this.field = field;
+    }
+
+    @Override
+    public String getValueOne() {
+        return valueOne;
+    }
+
+    @Override
+    public void setValueOne(String valueOne) {
+        this.valueOne = valueOne;
+    }
+
+    @Override
+    public String getValueTwo() {
+        return valueTwo;
+    }
+
+    @Override
+    public void setValueTwo(String valueTwo) {
+        this.valueTwo = valueTwo;
+    }
+
+    @Override
+    public Integer getTopN() {
+        return topN;
+    }
+
+    @Override
+    public void setTopN(Integer topN) {
+        this.topN = topN;
+    }
+
+    @Override
+    public String getPath() {
+        return path;
+    }
+
+    @Override
+    public void setPath(String path) {
+        this.path = path;
+    }
+}

+ 16 - 4
src/main/java/cn/cslg/pas/factorys/EsCountBuilderFactory/NestedCountBuilder.java

@@ -1,12 +1,14 @@
 package cn.cslg.pas.factorys.EsCountBuilderFactory;
 
-import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
-import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
+import co.elastic.clients.elasticsearch._types.aggregations.*;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
+import java.util.HashMap;
+import java.util.Map;
+
 @Component
 public class NestedCountBuilder implements IEsCountBuilder {
     public String field = "";
@@ -21,9 +23,19 @@ public class NestedCountBuilder implements IEsCountBuilder {
         if (StringUtils.isNotEmpty(valueOne)) {
             Query query = QueryBuilders.term(j -> j.field(field).value(valueOne));
             Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
-            terms.aggregations().put("filter_agg",filter);
+            terms = new Aggregation.Builder().terms(new TermsAggregation.Builder()
+                    .field(field).size(topN).build())
+                    .aggregations(new HashMap() {{
+                        put("filter_agg", filter);
+                    }}).build();
         }
-        return AggregationBuilders.nested(i -> i.path(path)).aggregations().put("terms_agg", terms);
+        Aggregation finalTerms = terms;
+        Aggregation aggregation = new Aggregation.Builder().nested(new NestedAggregation.Builder().
+                path(path).build())
+                .aggregations(new HashMap() {{
+                    put("terms_agg", finalTerms);
+                }}).build();
+        return aggregation;
     }
 
     @Override

+ 11 - 4
src/main/java/cn/cslg/pas/factorys/EsCountBuilderFactory/TermsCountBuilder.java

@@ -2,11 +2,15 @@ package cn.cslg.pas.factorys.EsCountBuilderFactory;
 
 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.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
+import java.util.HashMap;
+
 @Component
 public class TermsCountBuilder implements IEsCountBuilder{
     public String field = "";
@@ -17,11 +21,14 @@ public class TermsCountBuilder implements IEsCountBuilder{
 
     @Override
     public Aggregation createAggregation() {
-        Aggregation aggregation = AggregationBuilders.terms(i -> i.field(field).size(topN));
+        Aggregation aggregation = AggregationBuilders.terms(i -> i.field(field).size(topN)).terms()._toAggregation();
         if (StringUtils.isNotEmpty(valueOne)) {
-            Query query = QueryBuilders.term(j -> j.field(field).value(valueOne));
-            Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
-            aggregation.aggregations().put("filter_agg",filter);
+            Aggregation filter = AggregationBuilders.filter(n -> n.term(m -> m.field(field).value(valueOne)));
+            aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
+                    .field(field).size(topN).build())
+                    .aggregations(new HashMap() {{
+                        put("filter_agg", filter);
+                    }}).build();
         }
         return aggregation;
     }

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

@@ -2,6 +2,7 @@ package cn.cslg.pas.service.business.es;
 
 import cn.cslg.pas.common.dto.PatentDTO;
 import cn.cslg.pas.common.dto.business.EsCountDTO;
+import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
 import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.vo.EsConfigVO;
 import cn.cslg.pas.common.vo.business.EsCountVO;
@@ -15,6 +16,7 @@ import co.elastic.clients.elasticsearch._types.aggregations.*;
 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.json.JsonData;
 import com.alibaba.fastjson.JSON;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +24,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.data.elasticsearch.client.elc.ElasticsearchAggregations;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -47,7 +50,7 @@ public class EsCountService {
         EsCountDTO esCountDTO = new EsCountDTO();
 
         SearchRequest.Builder builder = new SearchRequest.Builder();
-        builder.index("patent");
+        builder.index("patent_v1");
         IEsCountBuilder iEsCountBuilder = null;
         String json = CommonService.readJsonFile("esCount.json");
         List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
@@ -62,11 +65,21 @@ public class EsCountService {
                 String path = iEsCountBuilder.getField().substring(0, iEsCountBuilder.getField().indexOf("."));
                 iEsCountBuilder.setPath(path);
             }
-            Aggregation aggregation = iEsCountBuilder.createAggregation();
 
         }
+        Aggregation aggregation = iEsCountBuilder.createAggregation();
+        builder.aggregations("Agg", aggregation);
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
-        Aggregate aggregate = response.aggregations().get("");
+        Aggregate agg = response.aggregations().get("Agg");
+        List<StringTermsBucket> list = agg.sterms().buckets().array();
+        List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
+        list.forEach(bucket -> {
+            EsCountDetailDTO dto = new EsCountDetailDTO();
+            dto.setName(bucket.key().stringValue());
+            dto.setNumber(bucket.docCount());
+            detailDTOS.add(dto);
+        });
+        esCountDTO.setDetailDTOS(detailDTOS);
         return esCountDTO;
     }
 }

+ 75 - 7
src/main/java/cn/cslg/pas/service/business/es/EsCustomFieldService.java

@@ -14,14 +14,19 @@ import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.service.business.TreeNodeService;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.SortOrder;
+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.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import co.elastic.clients.elasticsearch.core.IndexResponse;
 import co.elastic.clients.elasticsearch.core.SearchRequest;
 import co.elastic.clients.elasticsearch.core.SearchResponse;
 import co.elastic.clients.elasticsearch.core.search.Hit;
+import co.elastic.clients.json.JsonData;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.RequiredArgsConstructor;
+import lombok.Value;
 import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -197,6 +202,7 @@ public class EsCustomFieldService {
             esCustomFieldHistory.setFieldType(fieldType);
             esCustomFieldHistory.setCreateTime(createDate);
             esCustomFieldHistory.setFieldValue(addValues);
+            esCustomFieldHistory.setSavedValue(esCustomField.getFieldValue());
             esCustomFieldHistory.setHistoryType(optionType);
             esCustomFieldHistory.setTaskId(taskId);
             esCustomFieldHistory.setPersonId("1");
@@ -385,18 +391,80 @@ public class EsCustomFieldService {
     /**
      * 回退
      */
-    public void BackTo(String historyId) throws Exception {
-        //根据历史id获得历史
+    public void backTo(String historyId) throws Exception {
+        Hit<ESCustomFieldHistory> hit = this.getEsCustomFieldHistoryById(historyId);
+        ESCustomFieldHistory esCustomFieldHistory = hit.source();
+        List<String> values = esCustomFieldHistory.getSavedValue();
+        String customFieldId = esCustomFieldHistory.getCustomFieldId();
+        //根据id查询customField
+        Patent patent = new Patent();
+        String id = "";
         SearchRequest.Builder builder = new SearchRequest.Builder();
         builder.index("patent");
-        Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(historyId)));
+        Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(customFieldId)));
         builder.query(q);
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         long total = response.hits().total().value();
-        System.out.println(total);
-        //根据历史的创建时间,查询出所有创建时间大于当前创建时间的历史
+        if (total > 0) {
+            patent = response.hits().hits().get(0).source();
+            id = response.hits().hits().get(0).id();
+        }
+        if (values == null || values.size() <= 0) {
+            patent.getESCustomField().setFieldValue(null);
+            patent.getESCustomField().setStatsValue(null);
+        } else {
+            List<Integer> fieldIds = FormatUtil.StringTOIntegerList(values);
+            //根据树节点id查询树节点
+            LambdaQueryWrapper<TreeNode> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(TreeNode::getId, fieldIds);
+            List<TreeNode> treeNodes = treeNodeService.list(queryWrapper);
+            //遍历节点
+            List<String> reStateValues = new ArrayList<>(values);
+            treeNodes.forEach(item -> {
+                String path = item.getPath();
+                if (path != null && path.trim() != "") {
+                    List<String> a = Arrays.asList(path.split("/"));
+                    reStateValues.addAll(a);
+                }
+            });
+            List<String> disReStateValues = new ArrayList<>(new HashSet<>(reStateValues));
+            patent.getESCustomField().setStatsValue(disReStateValues);
+            patent.getESCustomField().setFieldValue(values);
+        }
+        //更新自定义栏位
+        esService.updatePatent(patent, id);
+        //新增历史
+        ESCustomFieldHistory newEsCustomFieldHistory = new ESCustomFieldHistory();
+        newEsCustomFieldHistory.setField(patent.getESCustomField().getField());
+        newEsCustomFieldHistory.setFieldType(patent.getESCustomField().getFieldType());
+        newEsCustomFieldHistory.setCreateTime(new Date());
+        newEsCustomFieldHistory.setFieldValue(patent.getESCustomField().getFieldValue());
+        newEsCustomFieldHistory.setHistoryType(3);
+        newEsCustomFieldHistory.setTaskId(patent.getESCustomField().getTaskId());
+        newEsCustomFieldHistory.setPersonId("1");
+        newEsCustomFieldHistory.setProjectId(patent.getESCustomField().getProjectId());
+        newEsCustomFieldHistory.setCustomFieldId(id);
+        this.addCustomFieldHistory(esCustomFieldHistory);
+
 
-        //遍历历史,根据操作类型,反推
-        //根据反推内容保存并保存历史为回退;
     }
+
+    //查询栏位历史
+    public Hit<ESCustomFieldHistory> getEsCustomFieldHistoryById(String historyId) throws Exception {
+        Hit<ESCustomFieldHistory> esCustomFieldHistoryHit = null;
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        builder.index("custom_field_history");
+        Query q = QueryBuilders.ids(i -> i.values(Arrays.asList(historyId)));
+        builder.query(q);
+        SearchResponse<ESCustomFieldHistory> response = client.search(builder.build(), ESCustomFieldHistory.class);
+        long total = response.hits().total().value();
+        if (total > 0) {
+            esCustomFieldHistoryHit = response.hits().hits().get(0);
+
+        }
+        return esCustomFieldHistoryHit;
+
+    }
+
+
 }

+ 4 - 0
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -23,6 +23,9 @@ import cn.cslg.pas.service.common.PatentStarApiService;
 import cn.cslg.pas.service.query.FormatQueryService;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.SortOrder;
+import co.elastic.clients.elasticsearch._types.aggregations.AggregateBuilders;
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
+import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
 import co.elastic.clients.elasticsearch._types.query_dsl.*;
 import co.elastic.clients.elasticsearch.core.*;
 import co.elastic.clients.elasticsearch.core.search.Hit;
@@ -742,6 +745,7 @@ public class EsService {
      * @return
      */
     public SelectClaimDTO selectClaim(String patentNo) throws IOException {
+
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");

+ 3 - 3
src/main/resources/jsons/esCount.json

@@ -4,7 +4,7 @@
     "type": "String",
     "value": "PA",
     "field": "PA",
-    "esField": "applicant.name",
+    "esField": "applicant.name.key",
     "esClass": "nestedCountBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
@@ -16,7 +16,7 @@
     "type": "String",
     "value": "IN",
     "field": "IN",
-    "esField": "inventor.name",
+    "esField": "inventor.name.key",
     "esClass": "nestedCountBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
@@ -28,7 +28,7 @@
     "type": "String",
     "value": "PE",
     "field": "PE",
-    "esField": "right_holder.name",
+    "esField": "right_holder.name.key",
     "esClass": "nestedCountBuilder",
     "ifSearch": "false",
     "ifGroup": "false",

+ 1 - 1
src/test/java/cn/cslg/pas/service/EsCustomFiedTests.java

@@ -71,6 +71,6 @@ System.out.println(a);
 
     @Test
     public void getBackTo() throws Exception{
-        esCustomFieldService.BackTo("2y5NPowB68vilgBjR1zV");
+        System.out.println("a");
     }
 }

+ 67 - 2
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -1,18 +1,27 @@
 package cn.cslg.pas.service;
 
 import cn.cslg.pas.common.dto.PatentDTO;
+import cn.cslg.pas.common.dto.business.EsCountDTO;
 import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
 import cn.cslg.pas.common.dto.business.SelectClaimDTO;
 import cn.cslg.pas.common.model.cronModel.Records;
 import cn.cslg.pas.common.model.request.*;
 import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.common.vo.business.EsCountVO;
 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.PatentFamilyMessage;
 import cn.cslg.pas.service.business.ProductMarketDataService;
+import cn.cslg.pas.service.business.es.EsCountService;
 import cn.cslg.pas.service.business.es.EsService;
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
+import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
+import co.elastic.clients.elasticsearch._types.aggregations.CalendarInterval;
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.http.entity.ContentType;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +47,8 @@ public class EventServiceTests {
     PatentController patentController;
     @Autowired
     private EsService esService;
+    @Autowired
+    private EsCountService esCountService;
 
 
 
@@ -199,7 +210,61 @@ public class EventServiceTests {
 
     @Test
     void test5() throws IOException {
-        SelectClaimDTO dto = esService.selectClaim("CN102324864A");
-        System.out.println(dto);
+//        SelectClaimDTO dto = esService.selectClaim("CN102324864A");
+//        System.out.println(dto);
+
+        Aggregation range = AggregationBuilders.range(n -> n.field("app_date").format("yyyy"));
+        Aggregation aggregation = AggregationBuilders.dateHistogram(i -> i.field("app_date").format("yyyy").calendarInterval(CalendarInterval.Year));
+        Query query = QueryBuilders.range(j -> j.field("app_date").from("2021").to("2023"));
+        Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
+        aggregation.aggregations().put("filter_agg",filter);
+
+        System.out.println(aggregation);
+
+    }
+
+    @Test
+    void test6() {
+        String valueOne = "H02";
+        Aggregation aggregation = AggregationBuilders.terms(i -> i.field("mipc.level2").size(10));
+        if (StringUtils.isNotEmpty(valueOne)) {
+            Query query = QueryBuilders.term(j -> j.field("mipc.level2").value(valueOne));
+            Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
+            Map<String, Aggregation> map = aggregation.aggregations();
+            System.out.println(map + "----------------");
+            map.put("filter_agg", filter);
+            System.out.println(map);
+        }
+        System.out.println(aggregation);
+    }
+
+    @Test
+    void test7() {
+        String valueOne = "";
+        Aggregation terms = AggregationBuilders.terms(j -> j.field("applicant.name.key").size(10));
+        if (StringUtils.isNotEmpty(valueOne)) {
+            Query query = QueryBuilders.term(j -> j.field("applicant.name.key").value(valueOne));
+            Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
+            terms.aggregations().put("filter_agg",filter);
+        }
+        Aggregation aggregation = AggregationBuilders.nested(i -> i.path("applicant")).aggregations().put("terms_agg", terms);
+        System.out.println(aggregation);
+    }
+
+    @Test
+    void test8() throws Exception {
+//        String valueOne = "";
+//        String str = "*";
+//        String s = str.concat(valueOne).concat("*");
+//        Query query = QueryBuilders.wildcard(i -> i.field("").value(s));
+//        Aggregation aggregation = AggregationBuilders.filter(i -> i.bool(j -> j.must(query)));
+//        System.out.println(aggregation);
+        EsCountVO vo = new EsCountVO();
+        vo.setField("PT");
+        vo.setValueOne("1");
+//        vo.setField("PA");
+        EsCountDTO esCountDTO = esCountService.esCountSearch(vo);
+        System.out.println(esCountDTO);
+
     }
 }

+ 6 - 2
src/test/java/cn/cslg/pas/service/FeatureTests.java

@@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -50,7 +51,10 @@ public class FeatureTests {
 
     @Test
     public  void getTree(){
-   List<PatentRightTree> a= featureService.getPatentRightTree("CN102324864A");
-    System.out.println(a);
+ List<String> a =new ArrayList<>();
+ a.add("a");
+ a.add("b");
+ List<String> b =a.subList(1,1);
+ System.out.println(b);
     }
 }