|
@@ -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;
|
|
|
+ }
|
|
|
}
|