‘linchangsheng’ 1 month ago
parent
commit
a0f7a67cd6

+ 56 - 24
mall-server-api/src/main/java/com/gree/mall/manager/logic/workorder/OrderBaseCountLogic.java

@@ -64,7 +64,6 @@ public class OrderBaseCountLogic {
                                              String endTime){
         AdminUserCom adminUser = commonLogic.getAdminUser();
         OrderBaseCountBean orderBaseCountBean = new OrderBaseCountBean();
-        adminUser.setAdminWebsitIds(null);
         BoolQueryBuilder queryBuilderCount = QueryBuilders.boolQuery();
 
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(adminUser.getAdminWebsitIds())) {
@@ -366,39 +365,72 @@ public class OrderBaseCountLogic {
         collect.add(OrderTypeEnum.REPAIR.getRemark());
 
         Map<String,List<Long>> wglxfb = new HashMap<>();
-        for (String orderTypeText : collect) {
 
-            List<Long> list = new ArrayList<>();
-            for (int i = 0; i < 30; i++) {
-                Integer day = i*-1;
+        NativeSearchQuery searchQueryAZ= new NativeSearchQueryBuilder()
+                .withQuery(QueryBuilders.boolQuery()
+                        .must( QueryBuilders.boolQuery().should(QueryBuilders.termsQuery("create_websit_id", adminUser.getAdminWebsitIds()))
+                                .should(QueryBuilders.termsQuery("websit_id", adminUser.getAdminWebsitIds())))
+                        .must(QueryBuilders.boolQuery()
+                                .must(QueryBuilders.termsQuery("order_type_text",OrderTypeEnum.INSTALL.getRemark()))
+                                .must(QueryBuilders.rangeQuery("create_time")
+                                        .gte(DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), (-29))),"yyyy-MM-dd HH:mm:ss"))
+                                        .lte(DateUtil.format(DateUtil.endOfDay(new Date()),"yyyy-MM-dd HH:mm:ss")))))
+                .withPageable(PageRequest.of(1, 1))
+                .addAggregation(AggregationBuilders.dateHistogram("AZ")
+                        .field("create_time")
+                        .calendarInterval(DateHistogramInterval.DAY)
+                        .format("yyyy-MM-dd"))
+                .build();
+        SearchHits responseAZ = elasticsearchRestTemplate.search(searchQueryAZ, OrderBaseEs.class);
 
-       /*         Long num = pgOrderBaseList.stream().filter(item -> item.getCreateTime().before(DateUtil.endOfDay(DateUtil.offsetDay(new Date(), (day)))) &&
-                        item.getCreateTime().after(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), (day))))
-                        && item.getOrderTypeText().equals(orderTypeText)
-                ).count();*/
+        var aggregationsAZ = responseAZ.getAggregations();
 
+        if (aggregationsAZ != null) {
+            ParsedDateHistogram dateHistogram = aggregationsAZ.get("AZ");
+            List<? extends Histogram.Bucket> buckets = dateHistogram.getBuckets();
+            List<Long> list = new ArrayList<>();
+            // 遍历每天的统计结果
+            for (Histogram.Bucket bucket : buckets) {
+                String date = bucket.getKeyAsString();
+                long count = bucket.getDocCount();
+                list.add(count);
+            }
 
+            wglxfb.put(OrderTypeEnum.INSTALL.getRemark(),list);
+        }
 
-                //工单类型
-                NativeSearchQuery searchQueryGDLX= new NativeSearchQueryBuilder()
-                        .withQuery(queryBuilder)
-                        .withPageable(PageRequest.of(1, 1))
-                        .addAggregation(this.getAggs(AggregationBuilders.filter("gdlx", QueryBuilders.boolQuery()
-                                .must(QueryBuilders.termsQuery("order_type_text",orderTypeText))
+
+        NativeSearchQuery searchQueryWX= new NativeSearchQueryBuilder()
+                .withQuery(QueryBuilders.boolQuery()
+                        .must( QueryBuilders.boolQuery().should(QueryBuilders.termsQuery("create_websit_id", adminUser.getAdminWebsitIds()))
+                                .should(QueryBuilders.termsQuery("websit_id", adminUser.getAdminWebsitIds())))
+                        .must(QueryBuilders.boolQuery()
+                                .must(QueryBuilders.termsQuery("order_type_text",OrderTypeEnum.REPAIR.getRemark()))
                                 .must(QueryBuilders.rangeQuery("create_time")
-                                        .gte(DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), (day))),"yyyy-MM-dd HH:mm:ss"))
-                                        .lte(DateUtil.format(DateUtil.endOfDay(DateUtil.offsetDay(new Date(), (day))),"yyyy-MM-dd HH:mm:ss"))))))
-                        .build();
-                SearchHits responseGDLX = elasticsearchRestTemplate.search(searchQueryGDLX, OrderBaseEs.class);
+                                        .gte(DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), (-29))),"yyyy-MM-dd HH:mm:ss"))
+                                        .lte(DateUtil.format(DateUtil.endOfDay(new Date()),"yyyy-MM-dd HH:mm:ss")))))
+                .withPageable(PageRequest.of(1, 1))
+                .addAggregation(AggregationBuilders.dateHistogram("WX")
+                        .field("create_time")
+                        .calendarInterval(DateHistogramInterval.DAY)
+                        .format("yyyy-MM-dd"))
+                .build();
+        SearchHits responseWX = elasticsearchRestTemplate.search(searchQueryWX, OrderBaseEs.class);
 
+        var aggregationsWX = responseWX.getAggregations();
 
-                list.add(this.getWorkerOrderCountResult(responseGDLX.getAggregations(),"gdlx"));
+        if (aggregationsWX != null) {
+            ParsedDateHistogram dateHistogram = aggregationsWX.get("AZ");
+            List<? extends Histogram.Bucket> buckets = dateHistogram.getBuckets();
+            List<Long> list = new ArrayList<>();
+            // 遍历每天的统计结果
+            for (Histogram.Bucket bucket : buckets) {
+                String date = bucket.getKeyAsString();
+                long count = bucket.getDocCount();
+                list.add(count);
             }
 
-            Collections.reverse(list);
-
-            wglxfb.put(orderTypeText,list);
-
+            wglxfb.put(OrderTypeEnum.REPAIR.getRemark(),list);
         }