客户统计接口改进
This commit is contained in:
@@ -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<CustomerManagementStatisticsMapper, CustomerManagementStatistics> 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<Custome
|
||||
.orderByAsc(CustomerManagementStatistics::getStatisticsDate);
|
||||
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