添加客户或录音时,经销商信息。
This commit is contained in:
@@ -6,8 +6,10 @@ import com.rj.common.AudioManagementConstants;
|
|||||||
import com.rj.common.DataEnrichmentUtil;
|
import com.rj.common.DataEnrichmentUtil;
|
||||||
import com.rj.entity.AudioManagement;
|
import com.rj.entity.AudioManagement;
|
||||||
import com.rj.entity.CustomerManagement;
|
import com.rj.entity.CustomerManagement;
|
||||||
|
import com.rj.entity.SalesManagement;
|
||||||
import com.rj.service.IAudioManagementService;
|
import com.rj.service.IAudioManagementService;
|
||||||
import com.rj.service.ICustomerManagementService;
|
import com.rj.service.ICustomerManagementService;
|
||||||
|
import com.rj.service.ISalesManagementService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -17,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -42,6 +43,9 @@ public class CustomerManagementController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IAudioManagementService audioManagementService;
|
private IAudioManagementService audioManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISalesManagementService salesManagementService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增客户
|
* 新增客户
|
||||||
*/
|
*/
|
||||||
@@ -56,7 +60,7 @@ public class CustomerManagementController {
|
|||||||
boolean isUpdate = customerManagement.getId() != null && !customerManagement.getId().trim().isEmpty();
|
boolean isUpdate = customerManagement.getId() != null && !customerManagement.getId().trim().isEmpty();
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
String operationType = customerManagement.getOperationType();
|
String operationType = customerManagement.getOperationType();
|
||||||
|
String salesPhone = customerManagement.getSalesPhone();
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
CustomerManagement existing = customerManagementService.getById(customerManagement.getId());
|
CustomerManagement existing = customerManagementService.getById(customerManagement.getId());
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
@@ -68,6 +72,24 @@ public class CustomerManagementController {
|
|||||||
customerManagement.setUpdateTime(now);
|
customerManagement.setUpdateTime(now);
|
||||||
customerManagement.setRecordingCount(customerManagement.getRecordingCount()+1);
|
customerManagement.setRecordingCount(customerManagement.getRecordingCount()+1);
|
||||||
} else {
|
} else {
|
||||||
|
// 根据salesPhone查询销售管理表,获取经销商信息
|
||||||
|
if (salesPhone != null && !salesPhone.trim().isEmpty()) {
|
||||||
|
LambdaQueryWrapper<SalesManagement> salesQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
salesQueryWrapper.eq(SalesManagement::getLoginAccount, salesPhone.trim());
|
||||||
|
List<SalesManagement> salesList = salesManagementService.list(salesQueryWrapper);
|
||||||
|
if (salesList != null && !salesList.isEmpty()) {
|
||||||
|
SalesManagement sales = salesList.get(0);
|
||||||
|
customerManagement.setDealershipId(sales.getDealershipId());
|
||||||
|
customerManagement.setDealershipName(sales.getDealershipName());
|
||||||
|
// 同时设置销售ID和销售名称
|
||||||
|
if (customerManagement.getSalesId() == null || customerManagement.getSalesId().trim().isEmpty()) {
|
||||||
|
customerManagement.setSalesId(sales.getId());
|
||||||
|
}
|
||||||
|
if (customerManagement.getSalesName() == null || customerManagement.getSalesName().trim().isEmpty()) {
|
||||||
|
customerManagement.setSalesName(sales.getSalesName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
customerManagement.setCreateTime(now);
|
customerManagement.setCreateTime(now);
|
||||||
customerManagement.setUpdateTime(now);
|
customerManagement.setUpdateTime(now);
|
||||||
customerManagement.setRecordingCount(1);
|
customerManagement.setRecordingCount(1);
|
||||||
@@ -80,7 +102,6 @@ public class CustomerManagementController {
|
|||||||
throw new IllegalStateException("客户ID为空,无法同步录音记录");
|
throw new IllegalStateException("客户ID为空,无法同步录音记录");
|
||||||
}
|
}
|
||||||
// 检查销售人员是否正在服务其他客户
|
// 检查销售人员是否正在服务其他客户
|
||||||
String salesPhone = customerManagement.getSalesPhone();
|
|
||||||
if (salesPhone != null && !salesPhone.trim().isEmpty()) {
|
if (salesPhone != null && !salesPhone.trim().isEmpty()) {
|
||||||
LambdaQueryWrapper<AudioManagement> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AudioManagement> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(AudioManagement::getSalesPhone, salesPhone.trim())
|
queryWrapper.eq(AudioManagement::getSalesPhone, salesPhone.trim())
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.rj.controller;
|
|||||||
|
|
||||||
import com.rj.common.Result;
|
import com.rj.common.Result;
|
||||||
import com.rj.entity.CustomerManagementStatistics;
|
import com.rj.entity.CustomerManagementStatistics;
|
||||||
|
import com.rj.scheduler.CustomerStatisticsScheduler;
|
||||||
import com.rj.service.ICustomerManagementStatisticsService;
|
import com.rj.service.ICustomerManagementStatisticsService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -27,6 +28,9 @@ public class CustomerManagementStatisticsController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ICustomerManagementStatisticsService customerStatisticsService;
|
private ICustomerManagementStatisticsService customerStatisticsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CustomerStatisticsScheduler customerStatisticsScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手动生成指定日期的统计数据
|
* 手动生成指定日期的统计数据
|
||||||
*/
|
*/
|
||||||
@@ -36,7 +40,7 @@ public class CustomerManagementStatisticsController {
|
|||||||
@Parameter(description = "统计日期,格式:yyyy-MM-dd")
|
@Parameter(description = "统计日期,格式:yyyy-MM-dd")
|
||||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
|
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
|
||||||
try {
|
try {
|
||||||
int count = customerStatisticsService.generateStatisticsByDate(date);
|
int count = customerStatisticsScheduler.manualGenerateStatistics(date);
|
||||||
Result<?> result = Result.ok(count);
|
Result<?> result = Result.ok(count);
|
||||||
result.setMsg("统计生成成功");
|
result.setMsg("统计生成成功");
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -22,53 +22,44 @@ import java.util.Map;
|
|||||||
public interface CustomerManagementStatisticsMapper extends BaseMapper<CustomerManagementStatistics> {
|
public interface CustomerManagementStatisticsMapper extends BaseMapper<CustomerManagementStatistics> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按经销商统计指定日期的客户数据
|
* 按租户、经销商、项目、销售统计指定日期的客户数据
|
||||||
|
* 每天生成一条记录(按租户、经销商、项目、销售分组)
|
||||||
* @param date 统计日期
|
* @param date 统计日期
|
||||||
* @return 经销商统计结果列表
|
* @return 统计结果列表,包含tenant_id, dealership_id, dealership_name, project_id, project_name, sales_id, sales_name, count_by_dealership, count_by_sales, count_by_project
|
||||||
*/
|
*/
|
||||||
@Select("SELECT " +
|
@Select("SELECT " +
|
||||||
"dealership_id, " +
|
"cm.tenant_id, " +
|
||||||
"dealership_name, " +
|
"cm.dealership_id, " +
|
||||||
"COUNT(*) as count_by_dealership " +
|
"cm.dealership_name, " +
|
||||||
"FROM customer_management " +
|
"COALESCE(sm.project_id, '') as project_id, " +
|
||||||
"WHERE DATE(create_time) = #{date} " +
|
"COALESCE(sm.project_name, '') as project_name, " +
|
||||||
"AND dealership_id IS NOT NULL " +
|
"cm.sales_id, " +
|
||||||
"AND dealership_id != '' " +
|
"cm.sales_name, " +
|
||||||
"GROUP BY dealership_id, dealership_name")
|
"(SELECT COUNT(*) FROM customer_management cm2 " +
|
||||||
List<Map<String, Object>> getDealershipStatisticsByDate(@Param("date") LocalDate date);
|
" WHERE cm2.dealership_id = cm.dealership_id " +
|
||||||
|
" AND DATE(cm2.create_time) = #{date} " +
|
||||||
/**
|
" AND cm2.tenant_id = cm.tenant_id) as count_by_dealership, " +
|
||||||
* 按销售统计指定日期的客户数据
|
"(SELECT COUNT(*) FROM customer_management cm3 " +
|
||||||
* @param date 统计日期
|
" WHERE cm3.sales_id = cm.sales_id " +
|
||||||
* @return 销售统计结果列表
|
" AND DATE(cm3.create_time) = #{date} " +
|
||||||
*/
|
" AND cm3.tenant_id = cm.tenant_id) as count_by_sales, " +
|
||||||
@Select("SELECT " +
|
"(SELECT COUNT(*) FROM customer_management cm4 " +
|
||||||
"sales_id, " +
|
" LEFT JOIN sales_management sm4 ON cm4.sales_id = sm4.id " +
|
||||||
"COUNT(*) as count_by_sales " +
|
" WHERE sm4.project_id = COALESCE(sm.project_id, '') " +
|
||||||
"FROM customer_management " +
|
" AND DATE(cm4.create_time) = #{date} " +
|
||||||
"WHERE DATE(create_time) = #{date} " +
|
" AND cm4.tenant_id = cm.tenant_id " +
|
||||||
"AND sales_id IS NOT NULL " +
|
" AND COALESCE(sm.project_id, '') != '') as count_by_project " +
|
||||||
"AND sales_id != '' " +
|
"FROM customer_management cm " +
|
||||||
"GROUP BY sales_id")
|
"LEFT JOIN sales_management sm ON cm.sales_id = sm.id " +
|
||||||
List<Map<String, Object>> getSalesStatisticsByDate(@Param("date") LocalDate date);
|
"WHERE DATE(cm.create_time) = #{date} " +
|
||||||
|
"AND cm.tenant_id IS NOT NULL " +
|
||||||
/**
|
"AND cm.tenant_id != '' " +
|
||||||
* 按项目统计指定日期的客户数据
|
"AND cm.dealership_id IS NOT NULL " +
|
||||||
* @param date 统计日期
|
"AND cm.dealership_id != '' " +
|
||||||
* @return 项目统计结果列表
|
"AND cm.sales_id IS NOT NULL " +
|
||||||
*/
|
"AND cm.sales_id != '' " +
|
||||||
@Select("SELECT " +
|
"GROUP BY cm.tenant_id, cm.dealership_id, cm.dealership_name, sm.project_id, sm.project_name, cm.sales_id, cm.sales_name")
|
||||||
"dealership_id, " +
|
List<Map<String, Object>> getStatisticsByDate(@Param("date") LocalDate date);
|
||||||
"sales_id, " +
|
|
||||||
"COUNT(*) as count_by_project " +
|
|
||||||
"FROM customer_management " +
|
|
||||||
"WHERE DATE(create_time) = #{date} " +
|
|
||||||
"AND dealership_id IS NOT NULL " +
|
|
||||||
"AND dealership_id != '' " +
|
|
||||||
"AND sales_id IS NOT NULL " +
|
|
||||||
"AND sales_id != '' " +
|
|
||||||
"GROUP BY dealership_id, sales_id")
|
|
||||||
List<Map<String, Object>> getProjectStatisticsByDate(@Param("date") LocalDate date);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查指定日期的统计数据是否已存在
|
* 检查指定日期的统计数据是否已存在
|
||||||
|
|||||||
@@ -30,21 +30,19 @@ public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<Custome
|
|||||||
// 先删除该日期的统计数据(如果存在)
|
// 先删除该日期的统计数据(如果存在)
|
||||||
baseMapper.deleteByStatisticsDate(date);
|
baseMapper.deleteByStatisticsDate(date);
|
||||||
|
|
||||||
// 查询该日期的经销商客户统计数据
|
// 查询该日期的统计数据(按租户、经销商、项目、销售分组)
|
||||||
List<Map<String, Object>> dealershipStatsList = baseMapper.getDealershipStatisticsByDate(date);
|
List<Map<String, Object>> statsList = baseMapper.getStatisticsByDate(date);
|
||||||
|
|
||||||
// 查询该日期的销售客户统计数据
|
|
||||||
List<Map<String, Object>> salesStatsList = baseMapper.getSalesStatisticsByDate(date);
|
|
||||||
|
|
||||||
// 查询该日期的项目客户统计数据
|
|
||||||
List<Map<String, Object>> projectStatsList = baseMapper.getProjectStatisticsByDate(date);
|
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
// 处理经销商统计数据
|
// 处理统计数据,每个组合生成一条记录
|
||||||
for (Map<String, Object> stat : dealershipStatsList) {
|
for (Map<String, Object> stat : statsList) {
|
||||||
CustomerManagementStatistics statistics = new CustomerManagementStatistics();
|
CustomerManagementStatistics statistics = new CustomerManagementStatistics();
|
||||||
|
|
||||||
|
// 设置租户ID
|
||||||
|
Object tenantIdObj = stat.get("tenant_id");
|
||||||
|
statistics.setTenantId(tenantIdObj != null ? tenantIdObj.toString() : "");
|
||||||
|
|
||||||
// 设置经销商信息
|
// 设置经销商信息
|
||||||
Object dealershipIdObj = stat.get("dealership_id");
|
Object dealershipIdObj = stat.get("dealership_id");
|
||||||
statistics.setDealershipId(dealershipIdObj != null ? dealershipIdObj.toString() : "");
|
statistics.setDealershipId(dealershipIdObj != null ? dealershipIdObj.toString() : "");
|
||||||
@@ -52,7 +50,11 @@ public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<Custome
|
|||||||
Object dealershipNameObj = stat.get("dealership_name");
|
Object dealershipNameObj = stat.get("dealership_name");
|
||||||
statistics.setDealershipName(dealershipNameObj != null ? dealershipNameObj.toString() : "未知经销商");
|
statistics.setDealershipName(dealershipNameObj != null ? dealershipNameObj.toString() : "未知经销商");
|
||||||
|
|
||||||
// 设置经销商统计数量
|
// 设置销售信息
|
||||||
|
Object salesIdObj = stat.get("sales_id");
|
||||||
|
statistics.setSalesId(salesIdObj != null ? salesIdObj.toString() : "");
|
||||||
|
|
||||||
|
// 设置经销商统计数量(该经销商当天的客户总数)
|
||||||
Object countByDealershipObj = stat.get("count_by_dealership");
|
Object countByDealershipObj = stat.get("count_by_dealership");
|
||||||
if (countByDealershipObj != null) {
|
if (countByDealershipObj != null) {
|
||||||
statistics.setCountByDealership(Integer.valueOf(countByDealershipObj.toString()));
|
statistics.setCountByDealership(Integer.valueOf(countByDealershipObj.toString()));
|
||||||
@@ -60,42 +62,21 @@ public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<Custome
|
|||||||
statistics.setCountByDealership(0);
|
statistics.setCountByDealership(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找该经销商对应的销售统计数据
|
// 设置销售统计数量(该销售当天的客户总数)
|
||||||
String dealershipId = dealershipIdObj != null ? dealershipIdObj.toString() : "";
|
Object countBySalesObj = stat.get("count_by_sales");
|
||||||
Map<String, Object> salesStat = findSalesStatByDealership(salesStatsList, dealershipId);
|
|
||||||
|
|
||||||
if (salesStat != null) {
|
|
||||||
// 设置销售信息
|
|
||||||
Object salesIdObj = salesStat.get("sales_id");
|
|
||||||
statistics.setSalesId(salesIdObj != null ? salesIdObj.toString() : "");
|
|
||||||
|
|
||||||
// 设置销售统计数量
|
|
||||||
Object countBySalesObj = salesStat.get("count_by_sales");
|
|
||||||
if (countBySalesObj != null) {
|
if (countBySalesObj != null) {
|
||||||
statistics.setCountBySales(Integer.valueOf(countBySalesObj.toString()));
|
statistics.setCountBySales(Integer.valueOf(countBySalesObj.toString()));
|
||||||
} else {
|
} else {
|
||||||
statistics.setCountBySales(0);
|
statistics.setCountBySales(0);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 如果没有找到对应的销售数据,设置为空
|
|
||||||
statistics.setSalesId("");
|
|
||||||
statistics.setCountBySales(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查找该经销商和销售对应的项目统计数据
|
// 设置项目统计数量(该项目当天的客户总数)
|
||||||
Map<String, Object> projectStat = findProjectStat(projectStatsList, dealershipId, statistics.getSalesId());
|
Object countByProjectObj = stat.get("count_by_project");
|
||||||
|
|
||||||
if (projectStat != null) {
|
|
||||||
// 设置项目统计数量
|
|
||||||
Object countByProjectObj = projectStat.get("count_by_project");
|
|
||||||
if (countByProjectObj != null) {
|
if (countByProjectObj != null) {
|
||||||
statistics.setCountByProject(Integer.valueOf(countByProjectObj.toString()));
|
statistics.setCountByProject(Integer.valueOf(countByProjectObj.toString()));
|
||||||
} else {
|
} else {
|
||||||
statistics.setCountByProject(0);
|
statistics.setCountByProject(0);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
statistics.setCountByProject(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置统计日期和时间
|
// 设置统计日期和时间
|
||||||
statistics.setStatisticsDate(date);
|
statistics.setStatisticsDate(date);
|
||||||
@@ -110,42 +91,6 @@ public class CustomerManagementStatisticsServiceImpl extends ServiceImpl<Custome
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据经销商ID查找对应的销售统计数据
|
|
||||||
* @param salesStatsList 销售统计列表
|
|
||||||
* @param dealershipId 经销商ID
|
|
||||||
* @return 销售统计数据
|
|
||||||
*/
|
|
||||||
private Map<String, Object> findSalesStatByDealership(List<Map<String, Object>> salesStatsList, String dealershipId) {
|
|
||||||
// 这里需要根据业务逻辑来确定经销商和销售的对应关系
|
|
||||||
// 由于原始数据中可能没有直接的关联关系,这里返回第一个销售数据作为示例
|
|
||||||
// 实际使用时需要根据具体的业务逻辑来调整
|
|
||||||
if (!salesStatsList.isEmpty()) {
|
|
||||||
return salesStatsList.get(0);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据经销商ID和销售ID查找对应的项目统计数据
|
|
||||||
* @param projectStatsList 项目统计列表
|
|
||||||
* @param dealershipId 经销商ID
|
|
||||||
* @param salesId 销售ID
|
|
||||||
* @return 项目统计数据
|
|
||||||
*/
|
|
||||||
private Map<String, Object> findProjectStat(List<Map<String, Object>> projectStatsList, String dealershipId, String salesId) {
|
|
||||||
for (Map<String, Object> projectStat : projectStatsList) {
|
|
||||||
Object projectDealershipId = projectStat.get("dealership_id");
|
|
||||||
Object projectSalesId = projectStat.get("sales_id");
|
|
||||||
|
|
||||||
if (dealershipId != null && dealershipId.equals(projectDealershipId != null ? projectDealershipId.toString() : "") &&
|
|
||||||
salesId != null && salesId.equals(projectSalesId != null ? projectSalesId.toString() : "")) {
|
|
||||||
return projectStat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int generateYesterdayStatistics() {
|
public int generateYesterdayStatistics() {
|
||||||
LocalDate yesterday = LocalDate.now().minusDays(1);
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user