Przeglądaj źródła

add:商城首页统计

liujunchi 3 lat temu
rodzic
commit
41c5a9692e

+ 4 - 3
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/AdminStatisticalController.java

@@ -1,5 +1,6 @@
 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.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.service.OmsOrderService;
@@ -40,11 +41,11 @@ public class AdminStatisticalController {
     @ApiOperation("商城首页统计")
     @PostMapping(value = "/orderStatistical")
     @ResponseBody
-    public CommonResult<HomeStatistical> orderStatistical(@RequestBody OrderStatisticalSearch search) {
+    public CommonResult<HomeOrderStatistical> orderStatistical(@RequestBody OrderStatisticalSearch search) {
 
-        HomeStatistical statistical = orderService.orderStatistical(search);
+        HomeOrderStatistical homeOrderStatistical = orderService.orderStatistical(search);
 
-        return CommonResult.success(statistical);
+        return CommonResult.success(homeOrderStatistical);
 
     }
 }

+ 2 - 1
cooleshow-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dao/OmsOrderDao.java

@@ -44,5 +44,6 @@ public interface OmsOrderDao {
      * @param dateFormat 时间统计格式   (DAY:按天统计, WEEK:按周统计, MONTH:按月统计)
      * @return
      */
-    List<OrderStatistical> selectOrderCountAndAmount(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("dateFormat") String dateFormat);
+    List<OrderStatistical> selectOrderCountAndAmount(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
+                                                     @Param("dateFormat") String dateFormat);
 }

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

@@ -19,14 +19,14 @@ public class HomeOrderStatistical {
     private Integer monthOrderCount;
 
     @ApiModelProperty("订单数同比上月")
-    private String monthOrderCountProportion;
+    private Integer monthOrderCountProportion;
 
     @ApiModelProperty("本周订单数")
     private Integer weekOrderCount;
 
 
     @ApiModelProperty("订单数同比上周")
-    private String weekOrderCountProportion;
+    private Integer weekOrderCountProportion;
 
 
     @ApiModelProperty("本月订单金额")
@@ -34,7 +34,7 @@ public class HomeOrderStatistical {
 
 
     @ApiModelProperty("本月订单同比金额")
-    private String monthOrderAmountProportion;
+    private Integer monthOrderAmountProportion;
 
 
     @ApiModelProperty("本周订单数")
@@ -42,7 +42,7 @@ public class HomeOrderStatistical {
 
 
     @ApiModelProperty("本周订单同比金额")
-    private String weekOrderAmountProportion;
+    private Integer weekOrderAmountProportion;
 
     @ApiModelProperty("统计图数据")
     private List<OrderStatistical> orderStatisticalList;
@@ -56,11 +56,11 @@ public class HomeOrderStatistical {
         this.monthOrderCount = monthOrderCount;
     }
 
-    public String getMonthOrderCountProportion() {
+    public Integer getMonthOrderCountProportion() {
         return monthOrderCountProportion;
     }
 
-    public void setMonthOrderCountProportion(String monthOrderCountProportion) {
+    public void setMonthOrderCountProportion(Integer monthOrderCountProportion) {
         this.monthOrderCountProportion = monthOrderCountProportion;
     }
 
@@ -72,11 +72,11 @@ public class HomeOrderStatistical {
         this.weekOrderCount = weekOrderCount;
     }
 
-    public String getWeekOrderCountProportion() {
+    public Integer getWeekOrderCountProportion() {
         return weekOrderCountProportion;
     }
 
-    public void setWeekOrderCountProportion(String weekOrderCountProportion) {
+    public void setWeekOrderCountProportion(Integer weekOrderCountProportion) {
         this.weekOrderCountProportion = weekOrderCountProportion;
     }
 
@@ -88,11 +88,11 @@ public class HomeOrderStatistical {
         this.monthOrderAmount = monthOrderAmount;
     }
 
-    public String getMonthOrderAmountProportion() {
+    public Integer getMonthOrderAmountProportion() {
         return monthOrderAmountProportion;
     }
 
-    public void setMonthOrderAmountProportion(String monthOrderAmountProportion) {
+    public void setMonthOrderAmountProportion(Integer monthOrderAmountProportion) {
         this.monthOrderAmountProportion = monthOrderAmountProportion;
     }
 
@@ -104,11 +104,11 @@ public class HomeOrderStatistical {
         this.weekOrderAmount = weekOrderAmount;
     }
 
-    public String getWeekOrderAmountProportion() {
+    public Integer getWeekOrderAmountProportion() {
         return weekOrderAmountProportion;
     }
 
-    public void setWeekOrderAmountProportion(String weekOrderAmountProportion) {
+    public void setWeekOrderAmountProportion(Integer weekOrderAmountProportion) {
         this.weekOrderAmountProportion = weekOrderAmountProportion;
     }
 

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

@@ -88,5 +88,5 @@ public interface OmsOrderService {
      * @param search 条件
      * @return
      */
-    HomeStatistical orderStatistical(OrderStatisticalSearch search);
+    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());

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

@@ -13,19 +13,19 @@ 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.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.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;
@@ -197,10 +197,10 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         // 已下架 已上架 全部商品
         homeStatistical = productService.countProductShowStatus();
 
-        Date endTime = LocalDateTime.now().toDate();
+        Date endTime = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
         LocalDateTime localDateTime = LocalDateTime.now().plusDays(-1);
         LocalDate localDate = localDateTime.toLocalDate();
-        Date startTime = localDate.toDate();
+        Date startTime = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
 
         // 今日、昨日 订单总数和销售总额
         List<OrderStatistical> orderStatistical = orderDao
@@ -220,17 +220,16 @@ public class OmsOrderServiceImpl implements OmsOrderService {
     }
 
     @Override
-    public HomeStatistical orderStatistical(OrderStatisticalSearch search) {
+    public HomeOrderStatistical orderStatistical(OrderStatisticalSearch search) {
 
         HomeOrderStatistical homeOrderStatistical = new HomeOrderStatistical();
 
         // 整理出时间数据
         LocalDate start = LocalDate.parse(search.getStartDate());
-        Date startTime = start.toDate();
+        Date startTime = Date.from(start.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
         LocalDate end = LocalDate.parse(search.getEndDate());
-        end.plusDays(1);
-        LocalDateTime localDateTime = end.toLocalDateTime(LocalTime.MIDNIGHT);
-        Date endTime = localDateTime.plusMillis(-1).toDate();
+        LocalDateTime localDateTime = end.plusDays(1).atStartOfDay();
+        Date endTime = Date.from( localDateTime.plusSeconds(-1).atZone(ZoneId.systemDefault()).toInstant());
 
         // 查询每天的订单数据
         List<OrderStatistical> orderStatistical = orderDao
@@ -242,19 +241,19 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         // 整理统计数据
         List<OrderStatistical> statisticalList = new ArrayList<>();
         while (start.compareTo(end) <=0) {
-            String date = start.toString("yyyy-MM-dd");
+            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 = now.toDate();
-        startTime = now.plusMonths(-1).toDate();
-
-
+        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));
@@ -269,14 +268,71 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         date = DateUtil.format(startTime, "yyyy-MM");
         statistical = getOrderStatistical(map, date);
 
-        if (homeOrderStatistical.getMonthOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
-            
+        // 月 同比 金额
+        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());
 
-        return null;
+        // 上周订单统计数据
+        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);