lwhhszx 1 rok temu
rodzic
commit
39d11683a4

+ 4 - 4
src/main/java/cn/cslg/pas/common/config/WebSocketConfig.java

@@ -6,8 +6,8 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
 
 @Configuration
 public class WebSocketConfig {
-//    @Bean
-//    public ServerEndpointExporter serverEndpointExporter() {
-//        return new ServerEndpointExporter();
-//    }
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
 }

+ 8 - 5
src/main/java/cn/cslg/pas/factorys/EsBuilderFactory/PersonNameQueryBuilder.java

@@ -1,8 +1,8 @@
 package cn.cslg.pas.factorys.EsBuilderFactory;
 
 import cn.cslg.pas.service.permissions.PermissionService;
-import co.elastic.clients.elasticsearch._types.query_dsl.Query;
-import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
+import co.elastic.clients.elasticsearch._types.FieldValue;
+import co.elastic.clients.elasticsearch._types.query_dsl.*;
 import co.elastic.clients.json.JsonData;
 import com.alibaba.fastjson.JSON;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,10 +34,13 @@ public class PersonNameQueryBuilder implements IQueryBuilder {
             ids = new ArrayList<>();
             ids.add("0");
         }
-        List<String> aa =new ArrayList<>();
-        String strs = JsonData.of(ids).toString();
-        Query query = QueryBuilders.terms(t -> t.field(field));
+        List<FieldValue> fieldValues = new ArrayList<>();
 
+        ids.forEach(item -> {
+            fieldValues.add(FieldValue.of(item));
+        });
+
+        Query query = QueryBuilders.terms(t -> t.field(field).terms(new TermsQueryField.Builder().value(fieldValues).build()));
         return query;
     }
 

+ 39 - 15
src/main/java/cn/cslg/pas/service/business/es/EsScratchWordsService.java

@@ -23,6 +23,7 @@ import cn.cslg.pas.service.business.CommonService;
 import cn.cslg.pas.service.permissions.PermissionService;
 import cn.cslg.pas.service.query.FormatQueryService;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.Time;
 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;
@@ -187,7 +188,7 @@ public class EsScratchWordsService {
                 reQuery = QueryBuilders.bool(i -> i.must(riBool, q));
             }
         } catch (Exception e) {
-          System.out.println(e.getMessage());
+            System.out.println(e.getMessage());
         }
         return reQuery;
     }
@@ -253,11 +254,19 @@ public class EsScratchWordsService {
         builder.index("patent_marking");
         builder.query(searchQuerys);
         Aggregation hits = AggregationBuilders.bucketSort(i -> i.size(size.intValue()).from((current.intValue() - 1) * size.intValue()));
-        Aggregation aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
-                .field(esGroupFiled).build()).aggregations(new HashMap() {{
-            put("pageAgg", hits);
-        }}).build();
-
+        Aggregation aggregation = null;
+        if (esGroupFiled.equals("mark_time")) {
+            aggregation =
+                    new Aggregation.Builder().dateHistogram(new DateHistogramAggregation.Builder().field(esGroupFiled).calendarInterval(CalendarInterval.Day).format("yyyy_MM_dd").build()).aggregations(new HashMap() {{
+                        put("pageAgg", hits);
+                    }}).build();
+        }
+        else {
+           aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
+                    .field(esGroupFiled).build()).aggregations(new HashMap() {{
+                put("pageAgg", hits);
+            }}).build();
+        }
         builder.aggregations("agg", aggregation);
         builder.size(0);
 
@@ -267,17 +276,31 @@ public class EsScratchWordsService {
         try {
             SearchResponse<Marking> response = client.search(builder.build(), Marking.class);
             Aggregate agg = response.aggregations().get("agg");
-            List<StringTermsBucket> list = agg.sterms().buckets().array();
             List<Map<String, Object>> maps = new ArrayList<>();
-            for (StringTermsBucket bucket : list) {
-                String key = bucket.key().stringValue();
-                Long count = bucket.docCount();
-                Map map = new HashMap();
-                map.put("key", key);
-                map.put("count", count);
-                maps.add(map);
+            if (esGroupFiled.equals("mark_time")) {
+                List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
+                for (DateHistogramBucket bucket : list) {
+                    String key = bucket.keyAsString();
+                    Long count = bucket.docCount();
+                    Map map = new HashMap();
+                    map.put("key", key);
+                    map.put("count", count);
+                    maps.add(map);
+                }
             }
-          maps =this.loadNameMap(maps,groupField);
+            else {
+                List<StringTermsBucket> list = agg.sterms().buckets().array();
+                for (StringTermsBucket bucket : list) {
+                    String key = bucket.key().stringValue();
+                    Long count = bucket.docCount();
+                    Map map = new HashMap();
+                    map.put("key", key);
+                    map.put("count", count);
+                    maps.add(map);
+                }
+            }
+
+            maps = this.loadNameMap(maps, groupField);
             records.setData(maps);
 
             Aggregate totalAgg = response.aggregations().get("total");
@@ -286,6 +309,7 @@ public class EsScratchWordsService {
             records.setCurrent(current);
             records.setSize(size);
         } catch (Exception e) {
+            System.out.println(e.getMessage());
         }
         return records;
     }