客户统计的代码框架

This commit is contained in:
2026-02-08 17:10:25 +08:00
parent 6350261a55
commit c003cbb11c
9 changed files with 584 additions and 2 deletions

View File

@@ -86,11 +86,11 @@ public class CustomerManagementController {
queryWrapper.eq(AudioManagement::getSalesPhone, salesPhone.trim())
.eq(AudioManagement::getServiceStatus, AudioManagementConstants.SERVICE_STATUS_IN_SERVICE);
long count = audioManagementService.count(queryWrapper);
if (count > 0) {
if (count > 0) { //如果正在服务,就直接返回,不能新增记录
result.put("success", true);
result.put("message", isUpdate ? "客户信息更新成功" : "客户添加成功");
result.put("message", "该销售人员正在服务其他客户,无法创建新的服务记录");
return ResponseEntity.badRequest().body(result);
return ResponseEntity.badRequest().body(result); //如果正在服务,就直接返回,不能新增记录
}
}
AudioManagement audioRecord = buildAudioRecordFromCustomer(customerManagement, now);

View File

@@ -0,0 +1,148 @@
package com.rj.controller;
import com.rj.common.Result;
import com.rj.entity.CustomerManagementStatistics;
import com.rj.service.ICustomerManagementStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.List;
/**
* 客户统计控制器
*
* @author 李中华 ,spllzh
* @since 2025-08-07
*/
@Tag(name = "客户统计", description = "客户统计相关接口")
@RestController
@RequestMapping("/api/customer-statistics")
public class CustomerManagementStatisticsController {
@Autowired
private ICustomerManagementStatisticsService customerStatisticsService;
/**
* 手动生成指定日期的统计数据
*/
@Operation(summary = "手动生成指定日期的统计数据", description = "手动触发指定日期的客户统计")
@PostMapping("/generate")
public Result<?> generateStatistics(
@Parameter(description = "统计日期格式yyyy-MM-dd")
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
try {
int count = customerStatisticsService.generateStatisticsByDate(date);
Result<?> result = Result.ok(count);
result.setMsg("统计生成成功");
return result;
} catch (Exception e) {
return Result.error("统计生成失败:" + e.getMessage());
}
}
/**
* 查询指定日期范围的统计数据
*/
@Operation(summary = "查询指定日期范围的统计数据", description = "查询指定日期范围内的客户统计数据")
@GetMapping("/range")
public Result<?> getStatisticsByDateRange(
@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) {
try {
List<CustomerManagementStatistics> statistics = customerStatisticsService.getStatisticsByDateRange(startDate, endDate);
Result<?> result = Result.ok(statistics);
result.setMsg("查询成功");
return result;
} catch (Exception e) {
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 查询指定经销商的统计数据
*/
@Operation(summary = "查询指定经销商的统计数据", description = "查询指定经销商在指定日期范围内的客户统计数据")
@GetMapping("/dealership/{dealershipId}")
public Result<?> getStatisticsByDealership(
@Parameter(description = "经销商ID")
@PathVariable String dealershipId,
@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) {
try {
List<CustomerManagementStatistics> statistics = customerStatisticsService.getStatisticsByDealership(dealershipId, startDate, endDate);
Result<?> result = Result.ok(statistics);
result.setMsg("查询成功");
return result;
} catch (Exception e) {
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 查询指定销售的统计数据
*/
@Operation(summary = "查询指定销售的统计数据", description = "查询指定销售在指定日期范围内的客户统计数据")
@GetMapping("/sales/{salesId}")
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) {
try {
List<CustomerManagementStatistics> statistics = customerStatisticsService.getStatisticsBySales(salesId, startDate, endDate);
Result<?> result = Result.ok(statistics);
result.setMsg("查询成功");
return result;
} catch (Exception e) {
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 查询指定日期的统计数据
*/
@Operation(summary = "查询指定日期的统计数据", description = "查询指定日期的所有客户统计数据")
@GetMapping("/date/{date}")
public Result<?> getStatisticsByDate(
@Parameter(description = "统计日期格式yyyy-MM-dd")
@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
try {
List<CustomerManagementStatistics> statistics = customerStatisticsService.getStatisticsByDateRange(date, date);
Result<?> result = Result.ok(statistics);
result.setMsg("查询成功");
return result;
} catch (Exception e) {
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 获取统计概览最近7天
*/
@Operation(summary = "获取统计概览", description = "获取最近7天的客户统计概览")
@GetMapping("/overview")
public Result<?> getStatisticsOverview() {
try {
LocalDate endDate = LocalDate.now().minusDays(1); // 昨天
LocalDate startDate = endDate.minusDays(6); // 7天前
List<CustomerManagementStatistics> statistics = customerStatisticsService.getStatisticsByDateRange(startDate, endDate);
Result<?> result = Result.ok(statistics);
result.setMsg("查询成功");
return result;
} catch (Exception e) {
return Result.error("查询失败:" + e.getMessage());
}
}
}