浏览代码

在途查询优化

fgd 1 年之前
父节点
当前提交
eb704cbe74

+ 2 - 6
sd-business/src/main/java/com/sd/business/service/order/impl/OrderSalesShipmentStatisticsServiceImpl.java

@@ -58,12 +58,9 @@ public class OrderSalesShipmentStatisticsServiceImpl implements OrderSalesShipme
 
     @Override
     public Map<Long, OrderSalesShipmentStatisticsBo> getSalesShipmentStatisticsByDate(List<Long> bomSpecIds) {
-        Date date = new Date();
-        Date startDate = DateUtil.beginOfDay(DateUtil.offsetDay(date, -90));
         IWrapper<OrderSku> wrapper = IWrapper.getWrapper();
         wrapper.orderByDesc("os", OrderSku::getId);
         wrapper.in("bs", BomSpec::getId, bomSpecIds);
-        wrapper.between("oi", OrderInfo::getShippingTime, startDate, date);
         wrapper.groupBy("bs.id");
         List<OrderSalesShipmentStatisticsBo> list = orderSalesShipmentStatisticsMapper.getOrderSalesShipmentStatisticsList(wrapper);
         return list.stream().collect(Collectors.toMap(OrderSalesShipmentStatisticsBo::getBomSpecId, Function.identity()));
@@ -77,9 +74,7 @@ public class OrderSalesShipmentStatisticsServiceImpl implements OrderSalesShipme
         String thirtyDaysDate = DateUtil.formatDate(DateUtil.offsetDay(date, -30));
 
         IWrapper<OrderSku> wrapper = IWrapper.getWrapper();
-        wrapper.orderByDesc("os", OrderSku::getId);
-        wrapper.eq("oi", OrderInfo::getDepartmentId, dto.getDepartmentId());
-        wrapper.between("oi", OrderInfo::getShippingTime, ninetyDaysDate, date);
+        wrapper.eq("oq", OrderInfo::getDepartmentId, dto.getDepartmentId());
         if (Objects.equals(dto.getBomClassify(), 1)) {
             wrapper.eq("bc", BomClassify::getCode, "201.G");
         } else if (Objects.equals(dto.getBomClassify(), 2)){
@@ -93,6 +88,7 @@ public class OrderSalesShipmentStatisticsServiceImpl implements OrderSalesShipme
         wrapper.like("bs", BomSpec::getHeight, dto.getHeight());
         wrapper.like("bs", BomSpec::getName, dto.getBomSpecName());
         wrapper.groupBy("bs.id");
+        wrapper.orderByDesc("bs", BomSpec::getId);
         List<OrderSalesShipmentStatisticsBo> statisticsVoList = orderSalesShipmentStatisticsMapper.getOrderSalesShipmentStatisticsList(wrapper);
         if (ObjectUtil.isEmpty(statisticsVoList)) {
             return Collections.emptyList();

+ 18 - 7
sd-business/src/main/resources/mapper/order/OrderSalesShipmentStatisticsMapper.xml

@@ -4,7 +4,7 @@
 
     <select id="getOrderSalesShipmentStatisticsList" resultType="com.sd.business.entity.board.bo.OrderSalesShipmentStatisticsBo">
         select
-            os.bom_spec_id,
+            bs.id bomSpecId,
             bs.code bomSpecCode,
             bs.name bomSpecName,
             bs.width,
@@ -15,15 +15,26 @@
             b.reverse_grain,
             b.chromatophore,
             bs.colour,
-            sum(case when oi.shipping_time >= date(date_sub(now(), interval 90 day)) then os.quantity else 0 end) ninetyDaysSalesQuantity,
-            sum(case when oi.shipping_time >= date(date_sub(now(), interval 60 day)) then os.quantity else 0 end) sixtyDaysSalesQuantity,
-            sum(case when oi.shipping_time >= date(date_sub(now(), interval 30 day)) then os.quantity else 0 end) thirtyDaysSalesQuantity
+            sum(oq.ninetyDaysSalesQuantity),
+            sum(oq.sixtyDaysSalesQuantity),
+            sum(oq.thirtyDaysSalesQuantity)
         from
-            order_info oi
-                inner join order_sku os on oi.id = os.order_id
-                inner join bom_spec bs on os.bom_spec_id = bs.id
+            bom_spec bs
                 inner join bom b on bs.bom_id = b.id
                 inner join bom_classify bc on b.bom_classify_id = bc.id
+                inner join (
+                    select
+                        os.bom_spec_id,
+                        oi.department_id,
+                        sum(case when oi.shipping_time >= date(date_sub(now(), interval 90 day)) then os.quantity else 0 end) ninetyDaysSalesQuantity,
+                        sum(case when oi.shipping_time >= date(date_sub(now(), interval 60 day)) then os.quantity else 0 end) sixtyDaysSalesQuantity,
+                        sum(case when oi.shipping_time >= date(date_sub(now(), interval 30 day)) then os.quantity else 0 end) thirtyDaysSalesQuantity
+                    FROM
+                        order_info oi
+                        inner join order_sku  os on oi.id = os.order_id
+                        where oi.shipping_time >= date(date_sub(now(), INTERVAL 90 day))
+                    group by os.bom_spec_id
+                ) oq on bs.id = oq.bom_spec_id
             ${ew.customSqlSegment}
     </select>