瀏覽代碼

统计页

wangqifan 4 年之前
父節點
當前提交
e999064673

+ 7 - 27
src/main/java/com/izouma/nineth/service/StatisticService.java

@@ -175,7 +175,7 @@ public class StatisticService {
         return JSONObject.toJSONString(maps);
     }
 
-    public Map<String, Map<String, BigDecimal>> orderPriceTrendV2(String yearMonth, Long userId) {
+    public Map<String, BigDecimal> orderPriceTrendV2(String yearMonth, Long userId) {
         YearMonth month = YearMonth.parse(yearMonth);
         LocalDateTime end = month.atEndOfMonth().atTime(LocalTime.MAX);
         LocalDateTime start = month.atDay(1).atStartOfDay();
@@ -189,31 +189,11 @@ public class StatisticService {
             orders = orderRepo.findAllByCreatedAtBetweenAndMinterIdAndStatusIn(start, end, userId,
                     Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
         }
-
-        Map<CollectionSource, List<Order>> orderMap = orders.stream().collect(Collectors.groupingBy(Order::getSource));
-        Map<String, BigDecimal> official = null;
-        if (CollUtil.isNotEmpty(orderMap.get(CollectionSource.OFFICIAL))) {
-            official = orderMap.get(CollectionSource.OFFICIAL)
-                    .stream()
-                    .collect(Collectors.groupingBy(
-                            item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
-                                    .format(item.getCreatedAt()), Collectors.mapping(Order::getTotalPrice,
-                                    Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
-        }
-
-        Map<String, BigDecimal> transfer = null;
-        if (CollUtil.isNotEmpty(orderMap.get(CollectionSource.TRANSFER))) {
-            transfer = orderMap.get(CollectionSource.TRANSFER)
-                    .stream()
-                    .collect(Collectors.groupingBy(
-                            item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
-                                    .format(item.getCreatedAt()), Collectors.mapping(Order::getTotalPrice,
-                                    Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
-        }
-
-        Map<String, Map<String, BigDecimal>> trend = new HashMap<>();
-        trend.put("official", official);
-        trend.put("transfer", transfer);
-        return trend;
+        Map<String, BigDecimal> map = new HashMap<>();
+        map.put("official", orders.stream().filter(order -> order.getSource().equals(CollectionSource.OFFICIAL))
+                .map(Order::getPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
+        map.put("transfer", orders.stream().filter(order -> order.getSource().equals(CollectionSource.TRANSFER))
+                .map(Order::getPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
+        return map;
     }
 }

+ 1 - 1
src/main/java/com/izouma/nineth/web/StatisticController.java

@@ -64,7 +64,7 @@ public class StatisticController {
     @GetMapping("/orderPriceTrendV2")
     @Cacheable(value = "orderPriceTrendV2", key = "#yearMonth")
     @PreAuthorize("hasAnyRole('ADMIN','COMPANY')")
-    public Map<String, Map<String, BigDecimal>> orderPriceTrend(String yearMonth) {
+    public Map<String, BigDecimal> orderPriceTrendV2(String yearMonth) {
         return statisticService.orderPriceTrendV2(yearMonth, SecurityUtils.getAuthenticatedUser().getId());
     }