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