liujunchi 3 лет назад
Родитель
Сommit
e2d02f5724

+ 91 - 2
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/HomeOrderStatistical.java

@@ -1,8 +1,10 @@
 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
@@ -13,22 +15,109 @@ import java.math.BigDecimal;
 @ApiModel("首页订单统计数据")
 public class HomeOrderStatistical {
 
-    private Long monthOrderCount;
+    @ApiModelProperty("本月订单数")
+    private Integer monthOrderCount;
 
+    @ApiModelProperty("订单数同比上月")
     private String monthOrderCountProportion;
 
-    private Long weekOrderCount;
+    @ApiModelProperty("本周订单数")
+    private Integer weekOrderCount;
 
+
+    @ApiModelProperty("订单数同比上周")
     private String weekOrderCountProportion;
 
+
+    @ApiModelProperty("本月订单金额")
     private BigDecimal monthOrderAmount;
 
+
+    @ApiModelProperty("本月订单同比金额")
     private String monthOrderAmountProportion;
 
+
+    @ApiModelProperty("本周订单数")
     private BigDecimal weekOrderAmount;
 
+
+    @ApiModelProperty("本周订单同比金额")
     private String weekOrderAmountProportion;
 
+    @ApiModelProperty("统计图数据")
+    private List<OrderStatistical> orderStatisticalList;
+
+
+    public Integer getMonthOrderCount() {
+        return monthOrderCount;
+    }
+
+    public void setMonthOrderCount(Integer monthOrderCount) {
+        this.monthOrderCount = monthOrderCount;
+    }
+
+    public String getMonthOrderCountProportion() {
+        return monthOrderCountProportion;
+    }
+
+    public void setMonthOrderCountProportion(String monthOrderCountProportion) {
+        this.monthOrderCountProportion = monthOrderCountProportion;
+    }
+
+    public Integer getWeekOrderCount() {
+        return weekOrderCount;
+    }
+
+    public void setWeekOrderCount(Integer weekOrderCount) {
+        this.weekOrderCount = weekOrderCount;
+    }
+
+    public String getWeekOrderCountProportion() {
+        return weekOrderCountProportion;
+    }
+
+    public void setWeekOrderCountProportion(String weekOrderCountProportion) {
+        this.weekOrderCountProportion = weekOrderCountProportion;
+    }
+
+    public BigDecimal getMonthOrderAmount() {
+        return monthOrderAmount;
+    }
+
+    public void setMonthOrderAmount(BigDecimal monthOrderAmount) {
+        this.monthOrderAmount = monthOrderAmount;
+    }
+
+    public String getMonthOrderAmountProportion() {
+        return monthOrderAmountProportion;
+    }
+
+    public void setMonthOrderAmountProportion(String monthOrderAmountProportion) {
+        this.monthOrderAmountProportion = monthOrderAmountProportion;
+    }
+
+    public BigDecimal getWeekOrderAmount() {
+        return weekOrderAmount;
+    }
+
+    public void setWeekOrderAmount(BigDecimal weekOrderAmount) {
+        this.weekOrderAmount = weekOrderAmount;
+    }
+
+    public String getWeekOrderAmountProportion() {
+        return weekOrderAmountProportion;
+    }
+
+    public void setWeekOrderAmountProportion(String weekOrderAmountProportion) {
+        this.weekOrderAmountProportion = weekOrderAmountProportion;
+    }
+
+    public List<OrderStatistical> getOrderStatisticalList() {
+        return orderStatisticalList;
+    }
 
+    public void setOrderStatisticalList(List<OrderStatistical> orderStatisticalList) {
+        this.orderStatisticalList = orderStatisticalList;
+    }
 }
 

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

@@ -12,10 +12,10 @@ import io.swagger.annotations.ApiModelProperty;
 @ApiModel("商城首页订单统计")
 public class OrderStatisticalSearch {
 
-    @ApiModelProperty("开始日期")
+    @ApiModelProperty("开始日期 (yyyy-MM-dd)")
     private String startDate;
 
-    @ApiModelProperty("结束日期")
+    @ApiModelProperty("结束日期(yyyy-MM-dd)")
     private String endDate;
 
     public String getStartDate() {

+ 74 - 20
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -19,11 +19,14 @@ import com.yonge.toolset.utils.date.DateUtil;
 import enums.OrderStatisticalEnum;
 import org.joda.time.LocalDate;
 import org.joda.time.LocalDateTime;
+import org.joda.time.LocalTime;
+import org.joda.time.format.DateTimeFormatter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -205,27 +208,13 @@ public class OmsOrderServiceImpl implements OmsOrderService {
 
         Map<String, List<OrderStatistical>> collect = orderStatistical.stream()
                               .collect(Collectors.groupingBy(OrderStatistical::getDate));
-        List<OrderStatistical> yesterdayOrderStatistical = collect.get(DateUtil.format(startTime, "yyyy-MM-dd"));
+        OrderStatistical statistical = getOrderStatistical(collect, DateUtil.format(startTime, "yyyy-MM-dd"));
+        homeStatistical.setYesterdayOrderNum(statistical.getOrderNum());
+        homeStatistical.setYesterdayOrderAmount(statistical.getOrderAmount());
 
-        if (!CollectionUtils.isEmpty(yesterdayOrderStatistical)) {
-            OrderStatistical startOrder = yesterdayOrderStatistical.get(0);
-            homeStatistical.setYesterdayOrderNum(startOrder.getOrderNum());
-            homeStatistical.setYesterdayOrderAmount(startOrder.getOrderAmount());
-        } else {
-            homeStatistical.setYesterdayOrderNum(0);
-            homeStatistical.setYesterdayOrderAmount(BigDecimal.ZERO);
-        }
-
-        List<OrderStatistical> todayOrderStatistical = collect.get(DateUtil.format(endTime, "yyyy-MM-dd"));
-
-        if (!CollectionUtils.isEmpty(todayOrderStatistical)) {
-            OrderStatistical startOrder = todayOrderStatistical.get(0);
-            homeStatistical.setTodayOrderNum(startOrder.getOrderNum());
-            homeStatistical.setTodayOrderAmount(startOrder.getOrderAmount());
-        } else {
-            homeStatistical.setTodayOrderNum(0);
-            homeStatistical.setTodayOrderAmount(BigDecimal.ZERO);
-        }
+        statistical = getOrderStatistical(collect, DateUtil.format(endTime, "yyyy-MM-dd"));
+        homeStatistical.setTodayOrderNum(statistical.getOrderNum());
+        homeStatistical.setTodayOrderAmount(statistical.getOrderAmount());
 
         return homeStatistical;
     }
@@ -233,7 +222,72 @@ public class OmsOrderServiceImpl implements OmsOrderService {
     @Override
     public HomeStatistical orderStatistical(OrderStatisticalSearch search) {
 
+        HomeOrderStatistical homeOrderStatistical = new HomeOrderStatistical();
+
+        // 整理出时间数据
+        LocalDate start = LocalDate.parse(search.getStartDate());
+        Date startTime = start.toDate();
+        LocalDate end = LocalDate.parse(search.getEndDate());
+        end.plusDays(1);
+        LocalDateTime localDateTime = end.toLocalDateTime(LocalTime.MIDNIGHT);
+        Date endTime = localDateTime.plusMillis(-1).toDate();
+
+        // 查询每天的订单数据
+        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.toString("yyyy-MM-dd");
+            OrderStatistical statisticalInfo = getOrderStatistical(map, date);
+            statisticalList.add(statisticalInfo);
+        }
+        homeOrderStatistical.setOrderStatisticalList(statisticalList);
+
+        // 本月订单
+
+        LocalDate now = LocalDate.now();
+        endTime = now.toDate();
+        startTime = now.plusMonths(-1).toDate();
+
+
+        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);
+
+        if (homeOrderStatistical.getMonthOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
+            
+        }
+
         return null;
 
     }
+
+    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;
+    }
 }