فهرست منبع

Merge branch 'mall_home'

liujunchi 3 سال پیش
والد
کامیت
b638917e0b

+ 17 - 10
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/AdminStatisticalController.java

@@ -1,20 +1,15 @@
 package com.yonge.cooleshow.admin.controller;
 
+import com.yonge.cooleshow.admin.dto.HomeOrderStatistical;
 import com.yonge.cooleshow.admin.dto.HomeStatistical;
-import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
+import com.yonge.cooleshow.admin.dto.search.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.service.OmsOrderService;
 import com.yonge.cooleshow.mall.common.api.CommonResult;
-import com.yonge.cooleshow.mbg.model.CmsPrefrenceArea;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import java.util.List;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * Description
@@ -34,11 +29,23 @@ public class AdminStatisticalController {
     @ApiOperation("商城首页统计")
     @RequestMapping(value = "/home", method = RequestMethod.GET)
     @ResponseBody
-    public CommonResult<HomeStatistical> userStatistical() {
+    public CommonResult<HomeStatistical> count() {
 
-        HomeStatistical statistical = orderService.statistical();
+        HomeStatistical statistical = orderService.countStatistical();
 
         return CommonResult.success(statistical);
 
     }
+
+
+    @ApiOperation("商城首页统计")
+    @PostMapping(value = "/orderStatistical")
+    @ResponseBody
+    public CommonResult<HomeOrderStatistical> orderStatistical(@RequestBody OrderStatisticalSearch search) {
+
+        HomeOrderStatistical homeOrderStatistical = orderService.orderStatistical(search);
+
+        return CommonResult.success(homeOrderStatistical);
+
+    }
 }

+ 14 - 5
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dao/OmsOrderDao.java

@@ -1,13 +1,11 @@
 package com.yonge.cooleshow.admin.dao;
 
-import com.yonge.cooleshow.admin.dto.HomeStatistical;
-import com.yonge.cooleshow.admin.dto.OmsOrderDeliveryParam;
-import com.yonge.cooleshow.admin.dto.OmsOrderDetail;
-import com.yonge.cooleshow.admin.dto.OmsOrderQueryParam;
+import com.yonge.cooleshow.admin.dto.*;
 import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
 import com.yonge.cooleshow.mbg.model.OmsOrder;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -31,10 +29,21 @@ public interface OmsOrderDao {
      */
     OmsOrderDetail getDetail(@Param("id") Long id);
 
-    List<Map<String,Object>> getUserOrderInfoList(Map<String, Object> param);
+    List<Map<String, Object>> getUserOrderInfoList(Map<String, Object> param);
 
     /**
      * 统计订单状态数量
      */
     HomeStatistical selectOrderStatusNum();
+
+    /**
+     * 统计订单完成数量 和订单金额
+     *
+     * @param startTime  开始时间
+     * @param endTime    结束时间
+     * @param dateFormat 时间统计格式   (DAY:按天统计, WEEK:按周统计, MONTH:按月统计)
+     * @return
+     */
+    List<OrderStatistical> selectOrderCountAndAmount(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
+                                                     @Param("dateFormat") String dateFormat);
 }

+ 123 - 0
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/HomeOrderStatistical.java

@@ -0,0 +1,123 @@
+package com.yonge.cooleshow.admin.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2022-05-25
+ */
+@ApiModel("首页订单统计数据")
+public class HomeOrderStatistical {
+
+    @ApiModelProperty("本月订单数")
+    private Integer monthOrderCount;
+
+    @ApiModelProperty("订单数同比上月")
+    private Integer monthOrderCountProportion;
+
+    @ApiModelProperty("本周订单数")
+    private Integer weekOrderCount;
+
+
+    @ApiModelProperty("订单数同比上周")
+    private Integer weekOrderCountProportion;
+
+
+    @ApiModelProperty("本月订单金额")
+    private BigDecimal monthOrderAmount;
+
+
+    @ApiModelProperty("本月订单同比金额")
+    private Integer monthOrderAmountProportion;
+
+
+    @ApiModelProperty("本周订单数")
+    private BigDecimal weekOrderAmount;
+
+
+    @ApiModelProperty("本周订单同比金额")
+    private Integer weekOrderAmountProportion;
+
+    @ApiModelProperty("统计图数据")
+    private List<OrderStatistical> orderStatisticalList;
+
+
+    public Integer getMonthOrderCount() {
+        return monthOrderCount;
+    }
+
+    public void setMonthOrderCount(Integer monthOrderCount) {
+        this.monthOrderCount = monthOrderCount;
+    }
+
+    public Integer getMonthOrderCountProportion() {
+        return monthOrderCountProportion;
+    }
+
+    public void setMonthOrderCountProportion(Integer monthOrderCountProportion) {
+        this.monthOrderCountProportion = monthOrderCountProportion;
+    }
+
+    public Integer getWeekOrderCount() {
+        return weekOrderCount;
+    }
+
+    public void setWeekOrderCount(Integer weekOrderCount) {
+        this.weekOrderCount = weekOrderCount;
+    }
+
+    public Integer getWeekOrderCountProportion() {
+        return weekOrderCountProportion;
+    }
+
+    public void setWeekOrderCountProportion(Integer weekOrderCountProportion) {
+        this.weekOrderCountProportion = weekOrderCountProportion;
+    }
+
+    public BigDecimal getMonthOrderAmount() {
+        return monthOrderAmount;
+    }
+
+    public void setMonthOrderAmount(BigDecimal monthOrderAmount) {
+        this.monthOrderAmount = monthOrderAmount;
+    }
+
+    public Integer getMonthOrderAmountProportion() {
+        return monthOrderAmountProportion;
+    }
+
+    public void setMonthOrderAmountProportion(Integer monthOrderAmountProportion) {
+        this.monthOrderAmountProportion = monthOrderAmountProportion;
+    }
+
+    public BigDecimal getWeekOrderAmount() {
+        return weekOrderAmount;
+    }
+
+    public void setWeekOrderAmount(BigDecimal weekOrderAmount) {
+        this.weekOrderAmount = weekOrderAmount;
+    }
+
+    public Integer getWeekOrderAmountProportion() {
+        return weekOrderAmountProportion;
+    }
+
+    public void setWeekOrderAmountProportion(Integer weekOrderAmountProportion) {
+        this.weekOrderAmountProportion = weekOrderAmountProportion;
+    }
+
+    public List<OrderStatistical> getOrderStatisticalList() {
+        return orderStatisticalList;
+    }
+
+    public void setOrderStatisticalList(List<OrderStatistical> orderStatisticalList) {
+        this.orderStatisticalList = orderStatisticalList;
+    }
+}
+

+ 3 - 3
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/HomeStatistical.java

@@ -24,7 +24,7 @@ public class HomeStatistical {
     private Integer yesterdayOrderNum;
 
     @ApiModelProperty("昨日销售金额")
-    private Integer yesterdayOrderAmount;
+    private BigDecimal yesterdayOrderAmount;
 
 
     @ApiModelProperty("待付款订单")
@@ -90,11 +90,11 @@ public class HomeStatistical {
         this.yesterdayOrderNum = yesterdayOrderNum;
     }
 
-    public Integer getYesterdayOrderAmount() {
+    public BigDecimal getYesterdayOrderAmount() {
         return yesterdayOrderAmount;
     }
 
-    public void setYesterdayOrderAmount(Integer yesterdayOrderAmount) {
+    public void setYesterdayOrderAmount(BigDecimal yesterdayOrderAmount) {
         this.yesterdayOrderAmount = yesterdayOrderAmount;
     }
 

+ 50 - 0
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/OrderStatistical.java

@@ -0,0 +1,50 @@
+package com.yonge.cooleshow.admin.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2022-05-25
+ */
+@ApiModel("订单统计")
+public class OrderStatistical {
+
+    @ApiModelProperty("日期")
+    private String date;
+
+    @ApiModelProperty("订单数")
+    private Integer orderNum;
+
+    @ApiModelProperty("订单总额")
+    private BigDecimal orderAmount;
+
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public Integer getOrderNum() {
+        return orderNum;
+    }
+
+    public void setOrderNum(Integer orderNum) {
+        this.orderNum = orderNum;
+    }
+
+    public BigDecimal getOrderAmount() {
+        return orderAmount;
+    }
+
+    public void setOrderAmount(BigDecimal orderAmount) {
+        this.orderAmount = orderAmount;
+    }
+}

+ 36 - 0
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/search/OrderStatisticalSearch.java

@@ -0,0 +1,36 @@
+package com.yonge.cooleshow.admin.dto.search;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2022-05-25
+ */
+@ApiModel("商城首页订单统计")
+public class OrderStatisticalSearch {
+
+    @ApiModelProperty("开始日期 (yyyy-MM-dd)")
+    private String startDate;
+
+    @ApiModelProperty("结束日期(yyyy-MM-dd)")
+    private String endDate;
+
+    public String getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(String startDate) {
+        this.startDate = startDate;
+    }
+
+    public String getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(String endDate) {
+        this.endDate = endDate;
+    }
+}

+ 10 - 2
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/OmsOrderService.java

@@ -1,9 +1,9 @@
 package com.yonge.cooleshow.admin.service;
 
 import com.yonge.cooleshow.admin.dto.*;
+import com.yonge.cooleshow.admin.dto.search.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
 import com.yonge.cooleshow.mbg.model.OmsOrder;
-import com.yonge.cooleshow.admin.dto.*;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
@@ -80,5 +80,13 @@ public interface OmsOrderService {
     /**
      * 首页统计
      */
-    HomeStatistical statistical();
+    HomeStatistical countStatistical();
+
+    /**
+     * 订单统计
+     *
+     * @param search 条件
+     * @return
+     */
+    HomeOrderStatistical orderStatistical(OrderStatisticalSearch search);
 }

+ 3 - 0
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderReturnApplyServiceImpl.java

@@ -112,6 +112,9 @@ public class OmsOrderReturnApplyServiceImpl implements OmsOrderReturnApplyServic
     private void refundAmount(OmsOrderReturnApply returnApply) {
         // 退款
         UserOrderPayment userOrderPayment = userOrderPaymentMapper.selectByOrderNoAndStatusSucceeded(returnApply.getOrderSn());
+        if (userOrderPayment == null) {
+            throw new BizException("未找到付款信息");
+        }
         OrderRefundReq refundReq = new OrderRefundReq();
         refundReq.setOrderNo(returnApply.getOrderSn());
         refundReq.setRefundAmount(returnApply.getReturnAmount().setScale(2, RoundingMode.HALF_UP).toString());

+ 159 - 2
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
 import com.yonge.cooleshow.admin.dao.OmsOrderDao;
 import com.yonge.cooleshow.admin.dao.OmsOrderOperateHistoryDao;
 import com.yonge.cooleshow.admin.dto.*;
+import com.yonge.cooleshow.admin.dto.search.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
 import com.yonge.cooleshow.admin.service.OmsOrderReturnApplyService;
 import com.yonge.cooleshow.admin.service.PmsProductService;
@@ -12,11 +13,20 @@ import com.yonge.cooleshow.mbg.mapper.OmsOrderOperateHistoryMapper;
 import com.yonge.cooleshow.mbg.model.OmsOrder;
 import com.yonge.cooleshow.mbg.model.OmsOrderExample;
 import com.yonge.cooleshow.mbg.model.OmsOrderOperateHistory;
-import com.yonge.cooleshow.admin.dto.*;
 import com.yonge.cooleshow.admin.service.OmsOrderService;
+import com.yonge.toolset.utils.date.DateUtil;
+import enums.OrderStatisticalEnum;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.WeekFields;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -173,7 +183,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
     }
 
     @Override
-    public HomeStatistical statistical() {
+    public HomeStatistical countStatistical() {
         HomeStatistical  homeStatistical = new HomeStatistical();
         // 订单状态
         homeStatistical = orderDao.selectOrderStatusNum();
@@ -187,6 +197,153 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         // 已下架 已上架 全部商品
         homeStatistical = productService.countProductShowStatus();
 
+        Date endTime = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
+        LocalDateTime localDateTime = LocalDateTime.now().plusDays(-1);
+        LocalDate localDate = localDateTime.toLocalDate();
+        Date startTime = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
+
+        // 今日、昨日 订单总数和销售总额
+        List<OrderStatistical> orderStatistical = orderDao
+                .selectOrderCountAndAmount(startTime, endTime, OrderStatisticalEnum.DAY.name());
+
+        Map<String, List<OrderStatistical>> collect = orderStatistical.stream()
+                              .collect(Collectors.groupingBy(OrderStatistical::getDate));
+        OrderStatistical statistical = getOrderStatistical(collect, DateUtil.format(startTime, "yyyy-MM-dd"));
+        homeStatistical.setYesterdayOrderNum(statistical.getOrderNum());
+        homeStatistical.setYesterdayOrderAmount(statistical.getOrderAmount());
+
+        statistical = getOrderStatistical(collect, DateUtil.format(endTime, "yyyy-MM-dd"));
+        homeStatistical.setTodayOrderNum(statistical.getOrderNum());
+        homeStatistical.setTodayOrderAmount(statistical.getOrderAmount());
+
         return homeStatistical;
     }
+
+    @Override
+    public HomeOrderStatistical orderStatistical(OrderStatisticalSearch search) {
+
+        HomeOrderStatistical homeOrderStatistical = new HomeOrderStatistical();
+
+        // 整理出时间数据
+        LocalDate start = LocalDate.parse(search.getStartDate());
+        Date startTime = Date.from(start.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
+        LocalDate end = LocalDate.parse(search.getEndDate());
+        LocalDateTime localDateTime = end.plusDays(1).atStartOfDay();
+        Date endTime = Date.from( localDateTime.plusSeconds(-1).atZone(ZoneId.systemDefault()).toInstant());
+
+        // 查询每天的订单数据
+        List<OrderStatistical> orderStatistical = orderDao
+                .selectOrderCountAndAmount(startTime, endTime, OrderStatisticalEnum.DAY.name());
+
+        Map<String, List<OrderStatistical>> map = orderStatistical.stream()
+                                      .collect(Collectors.groupingBy(OrderStatistical::getDate));
+
+        // 整理统计数据
+        List<OrderStatistical> statisticalList = new ArrayList<>();
+        while (start.compareTo(end) <=0) {
+            String date = start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+            OrderStatistical statisticalInfo = getOrderStatistical(map, date);
+            statisticalList.add(statisticalInfo);
+            start = start.plusDays(1);
+        }
+        homeOrderStatistical.setOrderStatisticalList(statisticalList);
+
+        // 本月订单
+
+        LocalDate now = LocalDate.now();
+        endTime =  Date.from( now.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
+        startTime = Date.from( now.plusMonths(-1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
+        // 查询统计数据
+        orderStatistical = orderDao.selectOrderCountAndAmount(startTime, endTime, OrderStatisticalEnum.MONTH.name());
+
+        map = orderStatistical.stream().collect(Collectors.groupingBy(OrderStatistical::getDate));
+
+        // 本月订单统计数据
+        String date = DateUtil.format(endTime, "yyyy-MM");
+        OrderStatistical statistical = getOrderStatistical(map, date);
+        homeOrderStatistical.setMonthOrderAmount(statistical.getOrderAmount());
+        homeOrderStatistical.setMonthOrderCount(statistical.getOrderNum());
+
+        // 上月订单统计数据
+        date = DateUtil.format(startTime, "yyyy-MM");
+        statistical = getOrderStatistical(map, date);
+
+        // 月 同比 金额
+        homeOrderStatistical.setMonthOrderAmountProportion(getProportion(homeOrderStatistical.getMonthOrderAmount(),
+                                                                         statistical.getOrderAmount()));
+        // 月同比 数量
+        homeOrderStatistical.setMonthOrderCountProportion(getProportion(new BigDecimal(homeOrderStatistical.getMonthOrderCount()),
+                                                          new BigDecimal(statistical.getOrderNum())));
+
+        // 周数据
+        startTime = Date.from( now.plusDays(-7).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
+
+        // 查询统计数据
+        orderStatistical = orderDao.selectOrderCountAndAmount(startTime, endTime, OrderStatisticalEnum.WEEK.name());
+
+        map = orderStatistical.stream().collect(Collectors.groupingBy(obj -> obj.getDate().substring(4)));
+
+        // 本周订单统计数据
+        WeekFields weekFields = WeekFields.ISO;
+        int i = now.get(weekFields.weekOfWeekBasedYear());
+        if (i <10) {
+            date =  "0" + i;
+        } else {
+            date =  "" + i;
+        }
+        statistical = getOrderStatistical(map, date);
+        homeOrderStatistical.setWeekOrderAmount(statistical.getOrderAmount());
+        homeOrderStatistical.setWeekOrderCount(statistical.getOrderNum());
+
+        // 上周订单统计数据
+        i = now.plusDays(-7).get(weekFields.weekOfWeekBasedYear());
+        if (i <10) {
+            date =  "0" + i;
+        } else {
+            date =  "" + i;
+        }
+        statistical = getOrderStatistical(map, date);
+
+        // 月 同比 金额
+        homeOrderStatistical.setWeekOrderAmountProportion(getProportion(homeOrderStatistical.getWeekOrderAmount(),
+                                                                         statistical.getOrderAmount()));
+        // 月同比 数量
+        homeOrderStatistical.setWeekOrderCountProportion(getProportion(new BigDecimal(homeOrderStatistical.getWeekOrderCount()),
+                                                                        new BigDecimal(statistical.getOrderNum())));
+        return homeOrderStatistical;
+
+    }
+
+    private Integer getProportion(BigDecimal now, BigDecimal last) {
+        if (now.compareTo(BigDecimal.ZERO) == 0) {
+            if(last.compareTo(BigDecimal.ZERO) == 0) {
+                return 0;
+            }  else {
+                return -100;
+            }
+        } else {
+            if(last.compareTo(BigDecimal.ZERO) == 0) {
+                return 100;
+            }  else {
+                double monthAmount = now.doubleValue();
+                double lastMonthAmount =last.doubleValue();
+                double v = 100 * (monthAmount / lastMonthAmount - 1);
+                return Double.valueOf(v).intValue();
+            }
+        }
+    }
+
+    private OrderStatistical getOrderStatistical(Map<String, List<OrderStatistical>> map, String date) {
+        OrderStatistical statisticalInfo = new OrderStatistical();
+        statisticalInfo.setDate(date);
+        List<OrderStatistical> orderStatisticals = map.get(date);
+        if (CollectionUtils.isEmpty(orderStatisticals)) {
+            statisticalInfo.setOrderAmount(BigDecimal.ZERO);
+            statisticalInfo.setOrderNum(0);
+        } else {
+            statisticalInfo.setOrderAmount(orderStatisticals.get(0).getOrderAmount());
+            statisticalInfo.setOrderNum(orderStatisticals.get(0).getOrderNum());
+        }
+        return statisticalInfo;
+    }
 }

+ 29 - 0
cooleshow-mall/mall-admin/src/main/java/enums/OrderStatisticalEnum.java

@@ -0,0 +1,29 @@
+package enums;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2022-05-25
+ */
+public enum OrderStatisticalEnum {
+
+    DAY("按天统计"),
+    WEEK("按周统计"),
+    MONTH("按月统计"),
+    ;
+
+    private String msg;
+
+    OrderStatisticalEnum(String msg) {
+        this.msg = msg;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}

+ 47 - 0
cooleshow-mall/mall-admin/src/main/resources/config/mybatis/OmsOrderDao.xml

@@ -120,4 +120,51 @@
             sum(if(status = 2 and confirm_status = 0,1,0)) as waitReceiptOrder
         from oms_order
     </select>
+
+    <select id="selectOrderCountAndAmount" resultType="com.yonge.cooleshow.admin.dto.OrderStatistical">
+
+        select
+        <choose>
+            <when test="dateFormat == 'DAY'">
+                date_format(create_time,'%Y-%m-%d') as date,
+            </when>
+            <when test="dateFormat == 'WEEK'">
+                YEARWEEK(date_format(create_time,'%Y-%m-%d'),7) as date,
+            </when>
+            <when test="dateFormat == 'MONTH'">
+                date_format(create_time,'%Y-%m')  as date,
+            </when>
+        </choose>
+        count(1) as orderNum,
+        sum(pay_amount) as orderAmount
+        from oms_order
+        where status in (1,2,3) and create_time between #{startTime} and  #{endTime}
+
+        group by
+
+        <choose>
+            <when test="dateFormat == 'DAY'">
+                date_format(create_time,'%Y-%m-%d')
+            </when>
+            <when test="dateFormat == 'WEEK'">
+                YEARWEEK(date_format(create_time,'%Y-%m-%d'),7)
+            </when>
+            <when test="dateFormat == 'MONTH'">
+                date_format(create_time,'%Y-%m')
+            </when>
+        </choose>
+
+        order by
+        <choose>
+            <when test="dateFormat == 'DAY'">
+                date_format(create_time,'%Y-%m-%d')
+            </when>
+            <when test="dateFormat == 'WEEK'">
+                YEARWEEK(date_format(create_time,'%Y-%m-%d'),7)
+            </when>
+            <when test="dateFormat == 'MONTH'">
+                date_format(create_time,'%Y-%m')
+            </when>
+        </choose>
+    </select>
 </mapper>

+ 1 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -670,6 +670,7 @@
         left join course_schedule_replied csr on cs.id_ = csr.course_schedule_id_
         where cs.teacher_id_ = #{userId} and cs.status_ = 'COMPLETE' and cs.type_ = 'PRACTICE'
         and csr.student_replied_ is not null
+        and YEARWEEK(date_format(csr.create_time_,'%Y-%m-%d'),7) = YEARWEEK(now(),7)
     </select>
     <select id="selectStartTime" resultType="java.lang.String" parameterType="java.lang.String">
         SELECT s.start_time_