diff --git a/HikariCP连接池问题分析.md b/HikariCP连接池问题分析.md index 2c9d922..16daa92 100644 --- a/HikariCP连接池问题分析.md +++ b/HikariCP连接池问题分析.md @@ -146,5 +146,6 @@ hikari: + diff --git a/src/main/java/com/rj/controller/CustomerManagementStatisticsController.java b/src/main/java/com/rj/controller/CustomerManagementStatisticsController.java index 7dfaeb5..de27f67 100644 --- a/src/main/java/com/rj/controller/CustomerManagementStatisticsController.java +++ b/src/main/java/com/rj/controller/CustomerManagementStatisticsController.java @@ -92,19 +92,47 @@ public class CustomerManagementStatisticsController { } /** - * 查询指定销售的统计数据 + * 查询指定销售人员的统计数据 */ - @Operation(summary = "查询指定销售的统计数据", description = "查询指定销售在指定日期范围内的客户统计数据") - @GetMapping("/sales/{salesId}") + @Operation(summary = "查询指定销售人员的统计数据", description = "根据销售人员ID或电话号码查询指定日期范围内的客户统计数据") + @PostMapping("/sales") public Result getStatisticsBySales( - @Parameter(description = "销售ID") - @PathVariable String salesId, - @Parameter(description = "开始日期,格式:yyyy-MM-dd") - @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, - @Parameter(description = "结束日期,格式:yyyy-MM-dd") - @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) { + @Parameter(description = "销售人员ID") + @RequestParam(required = false) String salesId, + @Parameter(description = "销售人员电话号码") + @RequestParam(required = false) String salesPhone, + @Parameter(description = "日期范围类型:1=1个月,2=3个月,3=6个月") + @RequestParam Integer dateRangeType) { try { - List statistics = customerStatisticsService.getStatisticsBySales(salesId, startDate, endDate); + // 验证参数:至少提供一个查询条件 + if ((salesId == null || salesId.trim().isEmpty()) && + (salesPhone == null || salesPhone.trim().isEmpty())) { + return Result.error("销售人员ID和电话号码至少需要提供一个"); + } + + // 验证日期范围类型 + if (dateRangeType == null || (dateRangeType != 1 && dateRangeType != 2 && dateRangeType != 3)) { + return Result.error("日期范围类型必须为1(1个月)、2(3个月)或3(6个月)"); + } + + // 根据日期范围类型计算开始和结束日期 + LocalDate endDate = LocalDate.now().minusDays(1); // 昨天 + LocalDate startDate; + switch (dateRangeType) { + case 1: + startDate = endDate.minusMonths(1); // 1个月前 + break; + case 2: + startDate = endDate.minusMonths(3); // 3个月前 + break; + case 3: + startDate = endDate.minusMonths(6); // 6个月前 + break; + default: + return Result.error("日期范围类型无效"); + } + + List statistics = customerStatisticsService.getStatisticsBySales(salesId, salesPhone, startDate, endDate); Result result = Result.ok(statistics); result.setMsg("查询成功"); return result; diff --git a/src/main/java/com/rj/service/ICustomerManagementStatisticsService.java b/src/main/java/com/rj/service/ICustomerManagementStatisticsService.java index 8dbb1ab..10f3bfc 100644 --- a/src/main/java/com/rj/service/ICustomerManagementStatisticsService.java +++ b/src/main/java/com/rj/service/ICustomerManagementStatisticsService.java @@ -54,5 +54,15 @@ public interface ICustomerManagementStatisticsService extends IService getStatisticsBySales(String salesId, LocalDate startDate, LocalDate endDate); + + /** + * 查询指定销售的统计数据(支持根据ID或电话号码查询) + * @param salesId 销售ID(可选) + * @param salesPhone 销售电话号码(可选) + * @param startDate 开始日期 + * @param endDate 结束日期 + * @return 统计记录列表 + */ + List getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate); } diff --git a/src/main/java/com/rj/service/impl/CustomerManagementStatisticsServiceImpl.java b/src/main/java/com/rj/service/impl/CustomerManagementStatisticsServiceImpl.java index 341aad9..2eaeb45 100644 --- a/src/main/java/com/rj/service/impl/CustomerManagementStatisticsServiceImpl.java +++ b/src/main/java/com/rj/service/impl/CustomerManagementStatisticsServiceImpl.java @@ -1,10 +1,13 @@ package com.rj.service.impl; import com.rj.entity.CustomerManagementStatistics; +import com.rj.entity.SalesManagement; import com.rj.mapper.CustomerManagementStatisticsMapper; import com.rj.service.ICustomerManagementStatisticsService; +import com.rj.service.ISalesManagementService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,6 +27,9 @@ import java.util.Map; @Service public class CustomerManagementStatisticsServiceImpl extends ServiceImpl implements ICustomerManagementStatisticsService { + @Autowired + private ISalesManagementService salesManagementService; + @Override @Transactional(rollbackFor = Exception.class) public int generateStatisticsByDate(LocalDate date) { @@ -123,5 +129,40 @@ public class CustomerManagementStatisticsServiceImpl extends ServiceImpl getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 如果提供了电话号码,先通过电话号码查询到salesId + String finalSalesId = salesId; + if ((finalSalesId == null || finalSalesId.trim().isEmpty()) && + salesPhone != null && !salesPhone.trim().isEmpty()) { + // 通过电话号码查询销售人员 + LambdaQueryWrapper salesQueryWrapper = new LambdaQueryWrapper<>(); + salesQueryWrapper.eq(SalesManagement::getLoginAccount, salesPhone); + List salesList = salesManagementService.list(salesQueryWrapper); + + if (salesList == null || salesList.isEmpty()) { + // 如果没有找到对应的销售人员,返回空列表 + return List.of(); + } + + // 如果找到多个销售人员,使用第一个的ID + // 或者可以根据业务需求处理多个销售人员的情况 + finalSalesId = salesList.get(0).getId(); + } + + // 如果最终没有salesId,返回空列表 + if (finalSalesId == null || finalSalesId.trim().isEmpty()) { + return List.of(); + } + + // 根据salesId查询统计数据 + queryWrapper.eq(CustomerManagementStatistics::getSalesId, finalSalesId) + .between(CustomerManagementStatistics::getStatisticsDate, startDate, endDate) + .orderByAsc(CustomerManagementStatistics::getStatisticsDate); + return list(queryWrapper); + } }