Parcourir la source

Merge branch 'dev/2024/0806/update-business-Y' of Harper/feifan-backend-zx-business into master

商户查看统计图
Yangzw il y a 7 mois
Parent
commit
528b361acd

+ 2 - 1
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/mysql/order/TradeOrderMapper.java

@@ -9,6 +9,7 @@ import cn.newfeifan.mall.module.trade.controller.app.order.vo.AppTradeOrderPageR
 import cn.newfeifan.mall.module.trade.dal.dataobject.order.TradeOrderDO;
 import cn.newfeifan.mall.module.trade.enums.order.TradeOrderRefundStatusEnum;
 import cn.newfeifan.mall.module.trade.enums.order.TradeOrderStatusEnum;
+import cn.newfeifan.mall.module.trade.service.order.TradeOrderCountWithMoney;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -215,5 +216,5 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
      * @param shopId 店铺id
      * @return 订单统计
      */
-    List<Object> selectOrderCountWithTime(@Param("start") LocalDate startTime, @Param("end") LocalDate endTime, @Param("merId") Long merId, @Param("shopId") Long shopId);
+    List<TradeOrderCountWithMoney> selectOrderCountWithTime(@Param("start") LocalDate startTime, @Param("end") LocalDate endTime, @Param("merId") Long merId, @Param("shopId") Long shopId);
 }

+ 1 - 1
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderCountWithMoney.java

@@ -8,7 +8,7 @@ import lombok.Data;
 
 @Data
 public class TradeOrderCountWithMoney {
-
+    private String date;
     private Integer count;
     private Long money;
 }

+ 11 - 2
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderQueryServiceImpl.java

@@ -7,7 +7,6 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.framework.common.pojo.echarts.EChartsResult;
-import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
 import cn.newfeifan.mall.module.distri.dal.mysql.ordersettlement.OrderSettlementMapper;
 import cn.newfeifan.mall.module.member.api.user.MemberUserApi;
 import cn.newfeifan.mall.module.member.api.user.dto.MemberUserRespDTO;
@@ -299,10 +298,20 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
             endTime = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); // 获取本周的结束日期
         }
         List<LocalDate> weekDates = generateWeekDates(startTime, endTime); // 生成本周的日期数组
+        List<EChartsResult.Series> series = weekDates.stream().map(ignored -> new EChartsResult.Series().setCount(0).setMoney(0L)).collect(Collectors.toList());
+
+        List<TradeOrderCountWithMoney> result = tradeOrderMapper.selectOrderCountWithTime(startTime, endTime, userShopDetails.getMerId(), userShopDetails.getShopId());
+        for (int i = 0; i < weekDates.size(); i++) {
+            for (TradeOrderCountWithMoney tradeOrderCountWithMoney : result) {
+                if (weekDates.get(i).toString().equals(tradeOrderCountWithMoney.getDate())) {
+                    series.get(i).setCount(tradeOrderCountWithMoney.getCount()).setMoney(tradeOrderCountWithMoney.getMoney());
+                }
+            }
+        }
         return EChartsResult.builder()
                 .xaxis(new EChartsResult.Axis()
                         .setData(weekDates))
-                .series(BeanUtils.toBean(tradeOrderMapper.selectOrderCountWithTime(startTime, endTime, userShopDetails.getMerId(), userShopDetails.getShopId()), EChartsResult.Series.class))
+                .series(series)
                 .build()
                 ;
     }

+ 11 - 15
feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/order/BrokerageUserMapper.xml

@@ -4,21 +4,17 @@
 
     <select id="selectOrderCountWithTime"
             resultType="cn.newfeifan.mall.module.trade.service.order.TradeOrderCountWithMoney">
-        WITH RECURSIVE date_series AS (
-        SELECT #{start} AS date_val
-        UNION ALL
-        SELECT DATE_ADD(date_val, INTERVAL 1 DAY)
-        FROM date_series
-        WHERE date_val &lt; #{end}
-        )
         SELECT
-            ds.date_val AS order_date,
-            COUNT(o.id) AS count,
-        IFNULL(SUM(o.pay_rmb) + (SUM(o.pay_integral) / 10000), 0) AS money
-        FROM date_series ds
-            LEFT JOIN trade_order o ON DATE(o.create_time) = ds.date_val and o.merchant_id = #{merId} and o.shop_id = #{shopId} and o.pay_status = 1
-        WHERE ds.date_val BETWEEN #{start} AND #{end}
-        GROUP BY ds.date_val
-        ORDER BY ds.date_val;
+            DATE(o.create_time) `date`,
+            SUM(o.pay_rmb) + (SUM(o.pay_integral) / 10000) money,
+            count(*) count
+        FROM
+            trade_order o
+        WHERE
+            o.create_time BETWEEN #{start} AND #{end} and o.merchant_id = #{merId} and o.shop_id = #{shopId} and o.pay_status = 1
+        GROUP BY
+            DATE(o.create_time)
+        ORDER BY
+            `date`;
     </select>
 </mapper>