Commit 274d7f6a by zhouhaibao

新增督导分页查询处理

1 parent 7bea1e42
package cn.com.glsx.dj.supervisor.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 督导业绩分页响应DTO
* <p>
* 包含分页信息和督导业绩列表
* </p>
*/
@ApiModel(description = "督导业绩分页响应DTO")
@Data
public class SupervisorPerformanceResponse implements Serializable {
@ApiModelProperty(notes = "总条数")
private Integer totalCount;
@ApiModelProperty(notes = "总页数")
private Integer totalPages;
@ApiModelProperty(notes = "当前页码(从0开始)")
private Integer currentPage;
@ApiModelProperty(notes = "每页大小(固定为3)")
private Integer pageSize;
@ApiModelProperty(notes = "督导业绩列表")
private List<SupervisorPerformanceDTO> supervisorList;
}
\ No newline at end of file
......@@ -195,10 +195,11 @@ public interface SupervisorDashboardRemote {
@ApiOperation("业绩概览 -- 督导业绩接口")
@ApiMethod("业绩概览 -- 督导业绩接口")
@ApiParams({
@ApiParam(name = "req", notes = "查询参数(总部运营视角,不需要指定督导ID)", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiParam(name = "req", notes = "查询参数(总部运营视角,不需要指定督导ID)", dataType = ApiParam.DataTypeEnum.OBJECT, required = true),
@ApiParam(name = "page", notes = "页码(从0开始,固定每页3条)", dataType = ApiParam.DataTypeEnum.INTEGER, required = false)
})
@ApiResponse("督导业绩列表")
RpcResponse<List<SupervisorPerformanceDTO>> getSupervisorPerformance(SupervisorManagementQueryReq req);
@ApiResponse("督导业绩分页响应(包含总页数、总条数和当前页数据)")
RpcResponse<SupervisorPerformanceResponse> getSupervisorPerformance(SupervisorManagementQueryReq req, Integer page);
/**
* 业绩概览 -- 门店业绩接口(总部运营视角)
......
......@@ -209,15 +209,18 @@ public class SupervisorDashboardRemoteImpl implements SupervisorDashboardRemote
* </p>
*
* @param req 查询参数
* @param page 页码(从0开始,固定每页3条)
* @return RPC响应,包含督导业绩列表
*/
@Override
public RpcResponse<List<SupervisorPerformanceDTO>> getSupervisorPerformance(SupervisorManagementQueryReq req) {
public RpcResponse<SupervisorPerformanceResponse> getSupervisorPerformance(SupervisorManagementQueryReq req, Integer page) {
try {
log.info("开始远程调用获取督导业绩(总部运营视角),请求参数:统计维度={},时间范围={}~{}",
req.getStatDimension(), req.getStartDate(), req.getEndDate());
List<SupervisorPerformanceDTO> result = supervisorDashboardService.getSupervisorPerformance(req);
log.info("远程调用获取督导业绩成功,共 {} 条记录", result != null ? result.size() : 0);
log.info("开始远程调用获取督导业绩(总部运营视角),请求参数:统计维度={},时间范围={}~{},页码={}",
req.getStatDimension(), req.getStartDate(), req.getEndDate(), page);
SupervisorPerformanceResponse result = supervisorDashboardService.getSupervisorPerformance(req, page);
log.info("远程调用获取督导业绩成功,总条数={},总页数={}",
result != null && result.getTotalCount() != null ? result.getTotalCount() : 0,
result != null && result.getTotalPages() != null ? result.getTotalPages() : 0);
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("cn.com.glsx.dj.supervisor.remote.SupervisorDashboardRemoteImpl.getSupervisorPerformance error {}", e);
......
......@@ -34,6 +34,7 @@ import cn.com.glsx.dj.supervisor.dto.SupervisionQueryReq;
import cn.com.glsx.dj.supervisor.dto.SupervisorDashboardVO;
import cn.com.glsx.dj.supervisor.dto.SupervisorManagementQueryReq;
import cn.com.glsx.dj.supervisor.dto.SupervisorPerformanceDTO;
import cn.com.glsx.dj.supervisor.dto.SupervisorPerformanceResponse;
import cn.com.glsx.dj.supervisor.mapper.RecordingStatsMapper;
import cn.com.glsx.dj.supervisor.model.BehaviorDataDTO;
import cn.com.glsx.dj.supervisor.model.DataBusinessDTO;
......@@ -3176,62 +3177,123 @@ public class SupervisorDashboardService {
*
* 触发场景:运营在"督导业绩" Tab页查看
* 数据复用:界面及统计逻辑复用"驻店销售业绩列表",但统计对象变为"区域督导"
* 分页策略:固定每页3条,查询前分页,按分页缓存
*
* @param req 查询参数
* @return 督导业绩列表
* @param page 页码(从0开始)
* @return 督导业绩分页响应(包含总页数、总条数和当前页数据)
*/
public List<SupervisorPerformanceDTO> getSupervisorPerformance(SupervisorManagementQueryReq req) {
public SupervisorPerformanceResponse getSupervisorPerformance(SupervisorManagementQueryReq req, Integer page) {
long totalStartTime = System.currentTimeMillis();
String requestId = String.valueOf(System.nanoTime());
// 总部运营视角:查询所有督导业绩,不需要指定督导
log.info("[督导业绩查询] [{}] 开始查询督导业绩(总部运营视角),请求参数:统计维度={},时间范围={}~{}",
requestId, req.getStatDimension(), req.getStartDate(), req.getEndDate());
// 1. 尝试从缓存获取
String cacheKey = generateCacheKey(req);
List<SupervisorPerformanceDTO> cachedResult = getFromCache(cacheKey);
if (cachedResult != null) {
log.info("[督导业绩查询] [{}] 从缓存获取数据成功,总耗时 {}ms",
requestId, System.currentTimeMillis() - totalStartTime);
return cachedResult;
}
// 默认页码为0,固定每页3条
int currentPage = page != null && page >= 0 ? page : 0;
int pageSize = 3;
List<SupervisorPerformanceDTO> result = new ArrayList<>();
// 总部运营视角:查询所有督导业绩,不需要指定督导
log.info("[督导业绩查询] [{}] 开始查询督导业绩(总部运营视角),请求参数:统计维度={},时间范围={}~{},页码={}",
requestId, req.getStatDimension(), req.getStartDate(), req.getEndDate(), currentPage);
// 2. 获取所有区域督导列表(总部运营视角不限制特定督导)
// 1. 获取所有区域督导列表(总部运营视角不限制特定督导)
long stepStartTime = System.currentTimeMillis();
List<MerchantStaffResponse> allSupervisorIds = getAllSupervisorIds();
int totalCount = allSupervisorIds.size();
int totalPages = totalCount > 0 ? (int) Math.ceil((double) totalCount / pageSize) : 0;
// 构建分页响应
SupervisorPerformanceResponse response = new SupervisorPerformanceResponse();
response.setTotalCount(totalCount);
response.setTotalPages(totalPages);
response.setCurrentPage(currentPage);
response.setPageSize(pageSize);
if (allSupervisorIds.isEmpty()) {
log.warn("[督导业绩查询] [{}] 没有找到区域督导", requestId);
return result;
response.setSupervisorList(new ArrayList<>());
return response;
}
log.info("[督导业绩查询] [{}] 步骤2:获取督导列表完成,耗时 {}ms,督导数量:{}",
requestId, System.currentTimeMillis() - stepStartTime, allSupervisorIds.size());
log.info("[督导业绩查询] [{}] 步骤1:获取督导列表完成,耗时 {}ms,督导数量:{},总页数:{}",
requestId, System.currentTimeMillis() - stepStartTime, totalCount, totalPages);
// 3. 查询预警门店ID集合
// 2. 查询预警门店ID集合
Map<String, Set<Integer>> warningStoreIds = getWarningStoreIds(req.getStartDate(), req.getEndDate());
Set<Integer> redWarningStoreIds = warningStoreIds.get("red");
Set<Integer> yellowWarningStoreIds = warningStoreIds.get("yellow");
// 4. 使用多线程并行查询每个督导的业绩数据
// 3. 先计算所有督导的红黄绿店数量用于排序(只计算管理维度数据,不查询详细业绩)
stepStartTime = System.currentTimeMillis();
List<SupervisorPerformanceDTO> allSupervisors = allSupervisorIds.parallelStream()
.map(merchantStaffResponse -> {
SupervisorPerformanceDTO supervisor = new SupervisorPerformanceDTO();
supervisor.setSupervisorId(merchantStaffResponse.getUuid());
supervisor.setSupervisorName(merchantStaffResponse.getStaffName());
// 只填充管理维度数据用于排序
fillSupervisorManagementData(supervisor, redWarningStoreIds, yellowWarningStoreIds);
return supervisor;
})
.collect(java.util.stream.Collectors.toList());
log.info("[督导业绩查询] [{}] 步骤3:计算督导红黄绿店数量完成,耗时 {}ms",
requestId, System.currentTimeMillis() - stepStartTime);
// 4. 按红店数量排序:有红店排前面,没有红店排黄店,只有绿店排最后
stepStartTime = System.currentTimeMillis();
allSupervisors.sort((a, b) -> {
int redA = a.getRedStoreCount() != null ? a.getRedStoreCount() : 0;
int redB = b.getRedStoreCount() != null ? b.getRedStoreCount() : 0;
// 优先按红店数量降序排序
if (redA != redB) {
return Integer.compare(redB, redA);
}
// 红店数量相同时,按黄店数量降序排序
int yellowA = a.getYellowStoreCount() != null ? a.getYellowStoreCount() : 0;
int yellowB = b.getYellowStoreCount() != null ? b.getYellowStoreCount() : 0;
if (yellowA != yellowB) {
return Integer.compare(yellowB, yellowA);
}
// 最后按姓名升序排序
String nameA = a.getSupervisorName() != null ? a.getSupervisorName() : "";
String nameB = b.getSupervisorName() != null ? b.getSupervisorName() : "";
return nameA.compareTo(nameB);
});
log.info("[督导业绩查询] [{}] 步骤4:排序完成,耗时 {}ms",
requestId, System.currentTimeMillis() - stepStartTime);
// 5. 分页处理(查询前分页,控制线程使用量)
stepStartTime = System.currentTimeMillis();
int fromIndex = currentPage * pageSize;
if (fromIndex >= allSupervisors.size()) {
log.info("[督导业绩查询] [{}] 当前页没有数据,页码={},总督导数={}",
requestId, currentPage, totalCount);
response.setSupervisorList(new ArrayList<>());
return response;
}
int toIndex = Math.min(fromIndex + pageSize, allSupervisors.size());
List<SupervisorPerformanceDTO> paginatedSupervisors = allSupervisors.subList(fromIndex, toIndex);
log.info("[督导业绩查询] [{}] 步骤5:分页处理完成,当前页督导数量:{}",
requestId, paginatedSupervisors.size());
// 6. 尝试从缓存获取当前页数据
String cacheKey = generateCacheKey(req) + ":page:" + currentPage;
List<SupervisorPerformanceDTO> cachedResult = getFromCache(cacheKey);
if (cachedResult != null) {
log.info("[督导业绩查询] [{}] 从缓存获取当前页数据成功,总耗时 {}ms",
requestId, System.currentTimeMillis() - totalStartTime);
response.setSupervisorList(cachedResult);
return response;
}
// 7. 使用多线程并行查询当前页督导的业绩数据(只查询当前页,控制线程数)
stepStartTime = System.currentTimeMillis();
List<CompletableFuture<SupervisorPerformanceDTO>> futures = new ArrayList<>();
for (MerchantStaffResponse merchantStaffResponse : allSupervisorIds) {
for (SupervisorPerformanceDTO supervisor : paginatedSupervisors) {
CompletableFuture<SupervisorPerformanceDTO> future = CompletableFuture.supplyAsync(() -> {
SupervisorPerformanceDTO supervisor = new SupervisorPerformanceDTO();
supervisor.setSupervisorId(merchantStaffResponse.getUuid());
// 获取督导基础信息
supervisor.setSupervisorName(merchantStaffResponse.getStaffName());
// 获取管理维度数据(辖区门店、预警门店、需关注门店、管理驻店)
fillSupervisorManagementData(supervisor, redWarningStoreIds, yellowWarningStoreIds);
// 获取业绩指标(复用驻店销售业绩逻辑,按督导维度聚合)
fillSupervisorPerformanceData(supervisor, req);
return supervisor;
}, taskExecutor);
......@@ -3239,6 +3301,7 @@ public class SupervisorDashboardService {
}
// 等待所有任务完成
List<SupervisorPerformanceDTO> currentPageResult = new ArrayList<>();
try {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
......@@ -3247,7 +3310,7 @@ public class SupervisorDashboardService {
try {
SupervisorPerformanceDTO supervisor = future.get();
if (supervisor != null) {
result.add(supervisor);
currentPageResult.add(supervisor);
}
} catch (Exception e) {
log.error("[督导业绩查询] [{}] 获取督导数据异常:{}", requestId, e.getMessage(), e);
......@@ -3259,44 +3322,21 @@ public class SupervisorDashboardService {
}
// 格式化显示值
for (SupervisorPerformanceDTO supervisorPerformanceDTO : result) {
for (SupervisorPerformanceDTO supervisorPerformanceDTO : currentPageResult) {
formatDisplayValues(supervisorPerformanceDTO);
}
log.info("[督导业绩查询] [{}] 步骤4:并行查询督导数据完成,耗时 {}ms",
log.info("[督导业绩查询] [{}] 步骤7:并行查询当前页督导数据完成,耗时 {}ms",
requestId, System.currentTimeMillis() - stepStartTime);
// 5. 按红店数量排序:有红店排前面,没有红店排黄店,只有绿店排最后
stepStartTime = System.currentTimeMillis();
result.sort((a, b) -> {
int redA = a.getRedStoreCount() != null ? a.getRedStoreCount() : 0;
int redB = b.getRedStoreCount() != null ? b.getRedStoreCount() : 0;
// 优先按红店数量降序排序
if (redA != redB) {
return Integer.compare(redB, redA);
}
// 红店数量相同时,按黄店数量降序排序
int yellowA = a.getYellowStoreCount() != null ? a.getYellowStoreCount() : 0;
int yellowB = b.getYellowStoreCount() != null ? b.getYellowStoreCount() : 0;
if (yellowA != yellowB) {
return Integer.compare(yellowB, yellowA);
}
// 最后按姓名升序排序
String nameA = a.getSupervisorName() != null ? a.getSupervisorName() : "";
String nameB = b.getSupervisorName() != null ? b.getSupervisorName() : "";
return nameA.compareTo(nameB);
});
log.info("[督导业绩查询] [{}] 步骤5:排序完成,耗时 {}ms",
requestId, System.currentTimeMillis() - stepStartTime);
// 8. 存入缓存(按分页缓存)
putToCache(cacheKey, currentPageResult);
// 6. 存入缓存
putToCache(cacheKey, result);
response.setSupervisorList(currentPageResult);
log.info("[督导业绩查询] [{}] 查询完成,总耗时 {}ms,共 {} 条记录",
requestId, System.currentTimeMillis() - totalStartTime, result.size());
return result;
log.info("[督导业绩查询] [{}] 查询完成,总耗时 {}ms,总条数={},总页数={},当前页条数={}",
requestId, System.currentTimeMillis() - totalStartTime, totalCount, totalPages, currentPageResult.size());
return response;
}
/**
......
......@@ -8,6 +8,7 @@ import cn.com.glsx.dj.supervisor.dto.SupervisorPerformanceDTO;
import cn.com.glsx.dj.supervisor.dto.SupervisionQueryReq;
import cn.com.glsx.dj.supervisor.dto.SupervisorManagementQueryReq;
import cn.com.glsx.dj.supervisor.dto.MerchantQueryReq;
import cn.com.glsx.dj.supervisor.dto.SupervisorPerformanceResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
......@@ -117,25 +118,11 @@ public class SupervisorDashboardServiceTest extends BaseServiceTest {
req.setEndDate("2026-05-31");
req.setDateType(2); // 月
req.setStatDimension(2); // 通用品牌
List<SupervisorPerformanceDTO> result = supervisorDashboardService.getSupervisorPerformance(req);
log.info("通用品牌督导业绩查询成功,{}",JSONObject.toJSONString( result));
}
SupervisorPerformanceResponse supervisorPerformance = supervisorDashboardService.getSupervisorPerformance(
req, 0);
log.info("通用品牌督导业绩查询成功,{}",JSONObject.toJSONString( supervisorPerformance));
/**
* 测试督导业绩查询 - 问界鸿蒙品牌
*/
@Test
public void testGetSupervisorPerformanceHarmony() {
SupervisorManagementQueryReq req = new SupervisorManagementQueryReq();
req.setStartDate("2026-05-01");
req.setEndDate("2026-05-31");
req.setDateType(2); // 月
req.setStatDimension(1); // 问界鸿蒙
List<SupervisorPerformanceDTO> result = supervisorDashboardService.getSupervisorPerformance(req);
System.out.println("问界鸿蒙督导业绩查询成功,数量:" + (result != null ? result.size() : 0));
}
// ==================== 门店业绩测试用例(总部运营视角) ====================
......@@ -176,20 +163,6 @@ public class SupervisorDashboardServiceTest extends BaseServiceTest {
}
/**
* 测试管理维度数据计算
*/
@Test
public void testManagementDataCalculation() {
SupervisorManagementQueryReq req = new SupervisorManagementQueryReq();
req.setStartDate("2026-05-01");
req.setEndDate("2026-05-31");
req.setDateType(2); // 月
req.setStatDimension(2); // 通用品牌
List<SupervisorPerformanceDTO> result = supervisorDashboardService.getSupervisorPerformance(req);
}
// ==================== 门店维度业绩测试用例 ====================
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!