zss
9 小时以前 fddb7b7951238b5c70cee251459f6effb3b42c26
销售看板统计的新增客户趋势分析
已添加2个文件
已修改3个文件
161 ■■■■■ 文件已修改
src/main/java/com/ruoyi/home/controller/HomeController.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/home/dto/SalesDeliveryDto.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/home/dto/SalesTotalDto.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/home/service/HomeService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/home/controller/HomeController.java
@@ -336,4 +336,34 @@
        return AjaxResult.success(homeService.total());
    }
    @GetMapping("/salesAnalysis")
    @ApiOperation("销售统计看板---销量分析趋势图")
    public AjaxResult salesAnalysis(SalesDeliveryDto salesDeliveryDto) {
        return AjaxResult.success(homeService.salesAnalysis(salesDeliveryDto));
    }
    @GetMapping("/salesRanking")
    @ApiOperation("销售统计看板---销量数据-排名分析")
    public AjaxResult salesRanking(SalesDeliveryDto salesDeliveryDto) {
        return AjaxResult.success(homeService.salesRanking(salesDeliveryDto));
    }
    @GetMapping("/salesAmount")
    @ApiOperation("销售统计看板---销售金额分析")
    public AjaxResult salesAmount(SalesDeliveryDto salesDeliveryDto) {
        return AjaxResult.success(homeService.salesAmount(salesDeliveryDto));
    }
    @GetMapping("/salesDataRanking")
    @ApiOperation("销售统计看板---销售额数据-排名分析")
    public AjaxResult salesDataRanking(SalesDeliveryDto salesDeliveryDto) {
        return AjaxResult.success(homeService.salesDataRanking(salesDeliveryDto));
    }
    @GetMapping("/customerTrends")
    @ApiOperation("销售统计看板---新增客户趋势分析")
    public AjaxResult customerTrends(SalesDeliveryDto salesDeliveryDto) {
        return AjaxResult.success(homeService.customerTrends(salesDeliveryDto));
    }
}
src/main/java/com/ruoyi/home/dto/SalesDeliveryDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,14 @@
package com.ruoyi.home.dto;
import lombok.Data;
@Data
//销售统计看板的传参
public class SalesDeliveryDto {
    //å¹´/月
    private String days;
    //产品类型(砌块/板材)
    private String type;
}
src/main/java/com/ruoyi/home/dto/SalesTotalDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,21 @@
package com.ruoyi.home.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
//销售区统计
@Data
public class SalesTotalDto {
    //时间坐标
    private List<LocalDate> dates;
    //客户区域分析
    private List<Map<String,Long>> customerTrends;
}
src/main/java/com/ruoyi/home/service/HomeService.java
@@ -97,4 +97,14 @@
    List<processDataProductionStatisticsDto> processDataProductionStatistics(Integer type, List<Long> processIds);
    Map<String,Long> total();
    String salesAnalysis(SalesDeliveryDto salesDeliveryDto);
    String salesRanking(SalesDeliveryDto salesDeliveryDto);
    String salesAmount(SalesDeliveryDto salesDeliveryDto);
    String salesDataRanking(SalesDeliveryDto salesDeliveryDto);
    SalesTotalDto customerTrends(SalesDeliveryDto salesDeliveryDto);
}
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, // åŒºåŸŸåä½œä¸ºkey
                            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;
    }
    /**
     * æ ¹æ®å‰ç«¯ä¼ å‚ å¹´/月 è½¬æ¢ä¸ºå¯¹åº”LocalDate列表
     * @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;
    }
}