From fddb7b7951238b5c70cee251459f6effb3b42c26 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 30 三月 2026 16:06:13 +0800
Subject: [PATCH] 销售看板统计的新增客户趋势分析

---
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java |   86 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index 988804f..e496507 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -2535,4 +2535,90 @@
         map.put("customer",count);
         return map;
     }
+
+    @Override
+    public String salesAnalysis(SalesDeliveryDto salesDeliveryDto) {
+        List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+        return null;
+    }
+
+    @Override
+    public String salesRanking(SalesDeliveryDto salesDeliveryDto) {
+        List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+        return null;
+    }
+
+    @Override
+    public String salesAmount(SalesDeliveryDto salesDeliveryDto) {
+        List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+        return null;
+    }
+
+    @Override
+    public String salesDataRanking(SalesDeliveryDto salesDeliveryDto) {
+        List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+        return null;
+    }
+
+    @Override
+    public SalesTotalDto customerTrends(SalesDeliveryDto salesDeliveryDto) {
+        SalesTotalDto salesTotalDto = new SalesTotalDto();
+        List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+        List<Map<String, Long>> maps = new ArrayList<>();
+        for (LocalDate date : dates) {
+            LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
+            LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+            Date startDate = Date.from(firstDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
+            Date endDate = Date.from(lastDay.atTime(23, 59, 59).atZone(ZoneId.systemDefault()).toInstant());
+            List<Customer> customers = customerMapper.selectList(Wrappers.<Customer>lambdaQuery()
+                    .between(Customer::getMaintenanceTime, startDate, endDate));
+            Map<String, Long> regionCountMap = Arrays.stream(AddressRegionEnum.values())
+                    .filter(addressRegionEnum -> addressRegionEnum.getRegionName().equals("SELF_PICKUP"))
+                    .collect(Collectors.toMap(
+                            AddressRegionEnum::getRegionName, // 鍖哄煙鍚嶄綔涓簁ey
+                            enumItem -> 0L                    // 鍒濆鍊煎叏閮ㄤ负0
+                    ));
+            if (!CollectionUtils.isEmpty(customers)) {
+                regionCountMap = customers.stream()
+                        // 璋冪敤鏂规硶灏嗗師濮嬪湴鍧�杞崲涓虹洰鏍囧尯鍩�
+                        .map(customer -> AddressRegionEnum.matchRegion(customer.getCompanyAddress()).getRegionName())
+                        // 杩囨护鎺夎浆鎹㈠け璐�/绌虹殑鍖哄煙锛堝彲閫夛紝鏍规嵁涓氬姟闇�姹傦級
+                        .filter(region -> region != null && !region.isEmpty())
+                        // 鎸夊尯鍩熷垎缁勶紝缁熻姣忎釜鍖哄煙鐨勬暟閲�
+                        .collect(Collectors.groupingBy(
+                                region -> region,       // 鍒嗙粍渚濇嵁锛氳浆鎹㈠悗鐨勫尯鍩�
+                                Collectors.counting()   // 璁℃暟
+                        ));
+            }
+            regionCountMap.put("ALLIN",customers.stream().count());
+            maps.add(regionCountMap);
+        }
+        salesTotalDto.setDates(dates);
+        salesTotalDto.setCustomerTrends(maps);
+        return salesTotalDto;
+    }
+
+    /**
+     * 鏍规嵁鍓嶇浼犲弬 骞�/鏈� 杞崲涓哄搴擫ocalDate鍒楄〃
+     * @param days 鍓嶇鍙傛暟锛�"骞�" / "鏈�"
+     * @return List<LocalDate>
+     */
+    public static List<LocalDate> convertDateList(String days) {
+        List<LocalDate> resultList = new ArrayList<>();
+        LocalDate now = LocalDate.now();
+        int currentYear = now.getYear();
+
+        if ("骞�".equals(days)) {
+            // 闇�姹傦細杩�5骞� 鈫� 姣忓勾鐨� 1鏈�1鏃�
+            for (int i = 0; i < 5; i++) {
+                resultList.add(LocalDate.of(currentYear - i, 1, 1));
+            }
+        } else if ("鏈�".equals(days)) {
+            // 闇�姹傦細褰撳勾12涓湀 鈫� 姣忔湀1鏃�
+            for (int month = 1; month <= 12; month++) {
+                resultList.add(LocalDate.of(currentYear, month, 1));
+            }
+        }
+        return resultList;
+    }
 }

--
Gitblit v1.9.3