|
@@ -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);
|