客户统计接口改进
This commit is contained in:
@@ -146,5 +146,6 @@ hikari:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,19 +92,47 @@ public class CustomerManagementStatisticsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询指定销售的统计数据
|
* 查询指定销售人员的统计数据
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "查询指定销售的统计数据", description = "查询指定销售在指定日期范围内的客户统计数据")
|
@Operation(summary = "查询指定销售人员的统计数据", description = "根据销售人员ID或电话号码查询指定日期范围内的客户统计数据")
|
||||||
@GetMapping("/sales/{salesId}")
|
@PostMapping("/sales")
|
||||||
public Result<?> getStatisticsBySales(
|
public Result<?> getStatisticsBySales(
|
||||||
@Parameter(description = "销售ID")
|
@Parameter(description = "销售人员ID")
|
||||||
@PathVariable String salesId,
|
@RequestParam(required = false) String salesId,
|
||||||
@Parameter(description = "开始日期,格式:yyyy-MM-dd")
|
@Parameter(description = "销售人员电话号码")
|
||||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
|
@RequestParam(required = false) String salesPhone,
|
||||||
@Parameter(description = "结束日期,格式:yyyy-MM-dd")
|
@Parameter(description = "日期范围类型:1=1个月,2=3个月,3=6个月")
|
||||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
|
@RequestParam Integer dateRangeType) {
|
||||||
try {
|
try {
|
||||||
List<CustomerManagementStatistics> 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<CustomerManagementStatistics> statistics = customerStatisticsService.getStatisticsBySales(salesId, salesPhone, startDate, endDate);
|
||||||
Result<?> result = Result.ok(statistics);
|
Result<?> result = Result.ok(statistics);
|
||||||
result.setMsg("查询成功");
|
result.setMsg("查询成功");
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -54,5 +54,15 @@ public interface ICustomerManagementStatisticsService extends IService<CustomerM
|
|||||||
* @return 统计记录列表
|
* @return 统计记录列表
|
||||||
*/
|
*/
|
||||||
List<CustomerManagementStatistics> getStatisticsBySales(String salesId, LocalDate startDate, LocalDate endDate);
|
List<CustomerManagementStatistics> getStatisticsBySales(String salesId, LocalDate startDate, LocalDate endDate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询指定销售的统计数据(支持根据ID或电话号码查询)
|
||||||
|
* @param salesId 销售ID(可选)
|
||||||
|
* @param salesPhone 销售电话号码(可选)
|
||||||
|
* @param startDate 开始日期
|
||||||
|
* @param endDate 结束日期
|
||||||
|
* @return 统计记录列表
|
||||||
|
*/
|
||||||
|
List<CustomerManagementStatistics> getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.rj.service.impl;
|
package com.rj.service.impl;
|
||||||
|
|
||||||
import com.rj.entity.CustomerManagementStatistics;
|
import com.rj.entity.CustomerManagementStatistics;
|
||||||
|
import com.rj.entity.SalesManagement;
|
||||||
import com.rj.mapper.CustomerManagementStatisticsMapper;
|
import com.rj.mapper.CustomerManagementStatisticsMapper;
|
||||||
import com.rj.service.ICustomerManagementStatisticsService;
|
import com.rj.service.ICustomerManagementStatisticsService;
|
||||||
|
import com.rj.service.ISalesManagementService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -24,6 +27,9 @@ import java.util.Map;
|
|||||||
@Service
|
@Service
|
||||||
public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<CustomerManagementStatisticsMapper, CustomerManagementStatistics> implements ICustomerManagementStatisticsService {
|
public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<CustomerManagementStatisticsMapper, CustomerManagementStatistics> implements ICustomerManagementStatisticsService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISalesManagementService salesManagementService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public int generateStatisticsByDate(LocalDate date) {
|
public int generateStatisticsByDate(LocalDate date) {
|
||||||
@@ -123,5 +129,40 @@ public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<Custome
|
|||||||
.orderByAsc(CustomerManagementStatistics::getStatisticsDate);
|
.orderByAsc(CustomerManagementStatistics::getStatisticsDate);
|
||||||
return list(queryWrapper);
|
return list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CustomerManagementStatistics> getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate) {
|
||||||
|
LambdaQueryWrapper<CustomerManagementStatistics> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
// 如果提供了电话号码,先通过电话号码查询到salesId
|
||||||
|
String finalSalesId = salesId;
|
||||||
|
if ((finalSalesId == null || finalSalesId.trim().isEmpty()) &&
|
||||||
|
salesPhone != null && !salesPhone.trim().isEmpty()) {
|
||||||
|
// 通过电话号码查询销售人员
|
||||||
|
LambdaQueryWrapper<SalesManagement> salesQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
salesQueryWrapper.eq(SalesManagement::getLoginAccount, salesPhone);
|
||||||
|
List<SalesManagement> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user