‘linchangsheng’ 1 month ago
parent
commit
4a0e3f88c0

+ 2 - 2
mall-server-api/src/main/java/com/gree/mall/manager/controller/big/BigController.java

@@ -124,8 +124,8 @@ public class BigController {
     @ApiOperation(value = "近30天工单趋势")
     public ResponseHelper<List<LargeWorkerOrderDateBean>> getLarge6(
     ) throws IOException, RemoteServiceException {
-       // List<LargeWorkerOrderDateBean> largeMpBean = bigLogic.getLarge6();
-        return ResponseHelper.success();
+        List<LargeWorkerOrderDateBean> largeMpBean = bigLogic.getLarge6Es();
+        return ResponseHelper.success(largeMpBean);
     }
 
 

+ 125 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/big/BigLogic.java

@@ -1,5 +1,6 @@
 package com.gree.mall.manager.logic.big;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
@@ -12,6 +13,7 @@ import com.gree.mall.manager.bean.big.*;
 import com.gree.mall.manager.bean.es.OrderBaseEs;
 import com.gree.mall.manager.enums.IsYesNoEnum;
 import com.gree.mall.manager.enums.UserTypeEnum;
+import com.gree.mall.manager.enums.workorder.OrderTypeEnum;
 import com.gree.mall.manager.logic.common.CommonLogic;
 import com.gree.mall.manager.logic.workorder.OrderBaseCountLogic;
 import com.gree.mall.manager.plus.entity.*;
@@ -20,10 +22,16 @@ import com.gree.mall.manager.utils.HttpUtils;
 import com.gree.mall.manager.utils.RedisUtil;
 import com.gree.mall.manager.utils.StringUtil;
 import io.swagger.annotations.ApiModel;
+import lombok.var;
 import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.aggregations.Aggregation;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
+import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
+import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
+import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
+import org.elasticsearch.search.aggregations.metrics.ParsedSum;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
@@ -712,6 +720,123 @@ public class BigLogic {
 
     }
 
+
+
+    public List<LargeWorkerOrderDateBean> getLarge6Es() {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        List<OrderSmallType> orderSmallTypes = orderSmallTypeService.lambdaQuery()
+                .in(!StringUtil.isEmpty(adminUser.getCompanyWechatId()), OrderSmallType::getCompanyWechatId, adminUser.getCompanyWechatId())
+                .eq(OrderSmallType::getStatus, true)
+                .groupBy(OrderSmallType::getOrderSmallTypeText).list();
+
+
+        List<LargeWorkerOrderDateBean> largeWorkerOrderDateBeans = new ArrayList<>();
+
+        List<String> status = new ArrayList<>();
+        status.add("YWG");
+        status.add("YJS");
+        status.add("GCSZX");
+        status.add("WDWG");
+        status.add("YWGO");
+        status.add("LRCD");
+
+
+        for (OrderSmallType orderSmallType : orderSmallTypes) {
+
+            LargeWorkerOrderDateBean largeWorkerOrderDateBean = new LargeWorkerOrderDateBean();
+            largeWorkerOrderDateBean.setLx(orderSmallType.getOrderSmallTypeText());
+
+            List<Integer> unitNum = new ArrayList<>();
+            List<Integer> unitNumWwg = new ArrayList<>();
+
+            NativeSearchQuery searchQueryWG = new NativeSearchQueryBuilder()
+                    .withQuery(QueryBuilders.boolQuery()
+                            .must(QueryBuilders.termsQuery("order_status", status))
+                            .must(QueryBuilders.termsQuery("order_small_type_text", orderSmallType.getOrderSmallTypeText()))
+                            .must(QueryBuilders.rangeQuery("over_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")))
+                            .must(QueryBuilders.boolQuery().should(QueryBuilders.termsQuery("create_websit_id", adminUser.getAdminWebsitIds()))
+                            ))
+                    .withPageable(PageRequest.of(1, 1))
+                    .addAggregation(AggregationBuilders.dateHistogram("WG")
+                            .field("over_time")
+                            .calendarInterval(DateHistogramInterval.DAY)
+                            .format("yyyy-MM-dd")
+                            .subAggregation(AggregationBuilders.sum("total_num").field("total_num")))
+                    .build();
+            SearchHits responseWG = elasticsearchRestTemplate.search(searchQueryWG, OrderBaseEs.class);
+
+            var aggregationsWG = responseWG.getAggregations();
+
+
+            NativeSearchQuery searchQueryWWG = new NativeSearchQueryBuilder()
+                    .withQuery(QueryBuilders.boolQuery()
+                            .must(QueryBuilders.termsQuery("order_status", status))
+                            .must(QueryBuilders.termsQuery("order_small_type_text", orderSmallType.getOrderSmallTypeText()))
+                            .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")))
+                            .must(QueryBuilders.boolQuery().should(QueryBuilders.termsQuery("create_websit_id", adminUser.getAdminWebsitIds()))
+                            ))
+                    .withPageable(PageRequest.of(1, 1))
+                    .addAggregation(AggregationBuilders.dateHistogram("WWG")
+                            .field("create_time")
+                            .calendarInterval(DateHistogramInterval.DAY)
+                            .format("yyyy-MM-dd")
+                            .subAggregation(AggregationBuilders.sum("undone_num").field("undone_num")))
+                    .build();
+            SearchHits responseWWG = elasticsearchRestTemplate.search(searchQueryWWG, OrderBaseEs.class);
+
+            var aggregationsWWG = responseWWG.getAggregations();
+
+
+            for (int i = 29; i > -1; i--) {
+                String format = DateUtil.format(DateUtil.offsetDay(new Date(), -1 * i), "yyyy-MM-dd");
+                if (aggregationsWG != null) {
+                    ParsedDateHistogram dateHistogram = aggregationsWG.get("WG");
+                    List<? extends Histogram.Bucket> buckets = dateHistogram.getBuckets();
+
+                    List<? extends Histogram.Bucket> list = buckets.stream().filter(item -> item.getKeyAsString().equals(format)).collect(Collectors.toList());
+
+                    if (!CollectionUtil.isEmpty(list)) {
+                        ParsedSum total_num = list.get(0).getAggregations().get("total_num");
+                        unitNum.add(Convert.toInt(total_num.getValue()));
+                    }else {
+                        unitNum.add(0);
+                    }
+                }
+
+                if (aggregationsWWG != null) {
+                    ParsedDateHistogram dateHistogram = aggregationsWWG.get("WWG");
+                    List<? extends Histogram.Bucket> buckets = dateHistogram.getBuckets();
+
+                    List<? extends Histogram.Bucket> list = buckets.stream().filter(item -> item.getKeyAsString().equals(format)).collect(Collectors.toList());
+
+                    if (!CollectionUtil.isEmpty(list)) {
+                        ParsedSum undone_num = list.get(0).getAggregations().get("undone_num");
+                        unitNumWwg.add(Convert.toInt(undone_num.getValue()));
+                    }else{
+                        unitNumWwg.add(0);
+                    }
+                }
+            }
+
+
+            largeWorkerOrderDateBean.setUnitNum(unitNum);
+            largeWorkerOrderDateBean.setUnitNumWwg(unitNumWwg);
+
+            largeWorkerOrderDateBeans.add(largeWorkerOrderDateBean);
+
+
+        }
+
+
+        return largeWorkerOrderDateBeans;
+
+    }
+
     public LargeOrderBean getLarge7() {
         AdminUserCom adminUser = commonLogic.getAdminUser();
         List<OrderInfo> orderInfoList = orderInfoService.lambdaQuery()