Commit e5b054f5 by 范富荣

修改查询督导门店列表逻辑/统计督导总产值逻辑

1 parent aaba1fd0
......@@ -6,6 +6,7 @@ import lombok.ToString;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Data
@ToString
......@@ -39,6 +40,9 @@ public class SupervisorTaskQueryDTO implements Serializable {
@ApiModelProperty(notes = "督导管理的门店id列表")
private List<Integer> merchantIdList;
@ApiModelProperty(notes = "按督导类型分组的门店id列表,key=督导类型(directorType), value=门店id列表")
private Map<Integer, List<Integer>> directorTypeMerchantMap;
@ApiModelProperty(notes = "督导管理的员工手机号列表")
private List<String> staffPhoneList;
......
......@@ -91,7 +91,7 @@ public class SupervisorAudioReviewTaskJob implements SimpleJob {
// 2.1 查询督导管理的门店列表,参考CommonUtil.getFlightSupervisionMerchantList方法
ShopMerchantDirectorConfigDTO dto = new ShopMerchantDirectorConfigDTO();
dto.setDirectorUserId(supervisor.getUuid());
dto.setDirectorTypes(Arrays.asList(DirectorTypeEnum.FLIGHT_SUPERVISION.getValue()));
dto.setDirectorTypes(Arrays.asList(DirectorTypeEnum.FLIGHT_SUPERVISION.getValue(), DirectorTypeEnum.FLIGHT_SUPERVISION_2_1.getValue()));
RpcResponse<List<ShopMerchantDirectorConfigDTO>> merchantResponse = shopMerchantDirectorConfigRemote.list(dto);
log.info("请求参数:directorUserId:{},directorTypes:{}", dto.getDirectorUserId(), dto.getDirectorTypes());
List<Integer> merchantIdList = new ArrayList<>();
......@@ -100,6 +100,7 @@ public class SupervisorAudioReviewTaskJob implements SimpleJob {
if (CollectionUtils.isNotEmpty(merchantList)) {
merchantIdList = merchantList.stream()
.map(ShopMerchantDirectorConfigDTO::getMerchantId)
.distinct()
.collect(Collectors.toList());
}
}
......
......@@ -4,6 +4,7 @@ import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.SceneOutputResponse;
import cn.com.glsx.dj.peanalysis.remote.BusinessSceneAnalysisRemote;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.StaffBaseInfoDTO;
import cn.com.glsx.dj.smartcarlife.enums.DirectorTypeEnum;
import cn.com.glsx.dj.smartcarlife.remote.StaffBaseInfoRemote;
import cn.com.glsx.dj.supervisor.dto.*;
import cn.com.glsx.dj.supervisor.enums.ReviewStatusEnum;
......@@ -679,7 +680,7 @@ public class SupervisorTaskInfoService {
/**
* 查询督导团队概况信息
* @param request 督导管理的门店id列表
* @param request 督导管理的门店id列表(含按督导类型分组的门店数据)
* @return 督导团队概况信息
*/
public SupervisorTeamOverviewDTO getTeamOverview(SupervisorTaskQueryDTO request) {
......@@ -687,40 +688,64 @@ public class SupervisorTaskInfoService {
SupervisorTeamOverviewDTO overviewDTO = new SupervisorTeamOverviewDTO();
List<Integer> merchantIdList = request.getMerchantIdList();
// 计算团队员工个数
// 计算团队员工个数(使用所有门店去重)
StaffBaseInfoDTO param = new StaffBaseInfoDTO();
param.setMerchantIdList(merchantIdList);
RpcResponse<List<StaffBaseInfoDTO>> response = staffBaseInfoRemote.listShopStaffInfoGroupByUUid(param);
if (response.hasError()) {
log.error("查询团队员工个数失败,merchantIdList={}, error={}, message={}", merchantIdList, response.getError(), response.getMessage());
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, response.getMessage());
} else {
List<StaffBaseInfoDTO> staffList = response.getResult();
if (CollectionUtils.isNotEmpty(staffList)) {
//根据员工手机号去重计算员工个数
Set<String> phoneSet = staffList.stream().filter(x -> StringUtils.isNotBlank(x.getStaffPhone())).map(StaffBaseInfoDTO::getStaffPhone).collect(Collectors.toSet());
overviewDTO.setStaffCount(phoneSet.size());
//查询产值
}
List<StaffBaseInfoDTO> staffList = response.getResult();
if (CollectionUtils.isNotEmpty(staffList)) {
Set<String> phoneSet = staffList.stream()
.filter(x -> StringUtils.isNotBlank(x.getStaffPhone()))
.map(StaffBaseInfoDTO::getStaffPhone)
.collect(Collectors.toSet());
overviewDTO.setStaffCount(phoneSet.size());
}
// 按督导类型分别查询产值并求和
Map<Integer, List<Integer>> directorTypeMerchantMap = request.getDirectorTypeMerchantMap();
BigDecimal totalOutput = BigDecimal.ZERO;
String startTime = env.getProperty("supervisor.output.startTime", String.class, "2021-01-01");
String endTime = DateUtils.formatDate(new Date());
if (directorTypeMerchantMap != null && !directorTypeMerchantMap.isEmpty()) {
for (Map.Entry<Integer, List<Integer>> entry : directorTypeMerchantMap.entrySet()) {
Integer directorType = entry.getKey();
List<Integer> merchantIds = entry.getValue();
if (CollectionUtils.isEmpty(merchantIds)) {
continue;
}
SceneBaseReq req = new SceneBaseReq();
req.setMerchantIds(merchantIdList);
req.setMerchantIds(merchantIds);
req.setCycleType(4);
//req.setStaffUuids(staffList.stream().map(StaffBaseInfoDTO::getLoginUuid).collect(Collectors.toList()));
//设置指标开始时间,从配置文件中取值
req.setStartTime(env.getProperty("supervisor.output.startTime", String.class, "2021-01-01"));
//设置指标结束时间,固定当前日期
req.setEndTime(DateUtils.formatDate(new Date()));
req.setStartTime(startTime);
req.setEndTime(endTime);
// 1.1飞行督导(type=6)对应轻改,2.1飞行督导(type=13)对应延保+权益
if (Integer.valueOf(DirectorTypeEnum.FLIGHT_SUPERVISION.getValue()).equals(directorType)) {
req.setBizs(2);
} else if (Integer.valueOf(DirectorTypeEnum.FLIGHT_SUPERVISION_2_1.getValue()).equals(directorType)) {
req.setBizsMulti("1,3");
}
RpcResponse<SceneOutputResponse> outputResponse = businessSceneAnalysisRemote.querySupervisorOutput(req);
if (outputResponse.hasError()) {
log.error("查询督导团队产值失败,SceneBaseReq={}, error={}, message={}", JSON.toJSONString(req), outputResponse.getError(), outputResponse.getMessage());
log.error("查询督导团队产值失败,directorType={}, merchantIds={}, error={}, message={}",
directorType, merchantIds, outputResponse.getError(), outputResponse.getMessage());
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, outputResponse.getMessage());
} else {
SceneOutputResponse outputResp = outputResponse.getResult();
if (outputResp != null) {
overviewDTO.setTotalValue(outputResp.getOutputValue());
}
}
SceneOutputResponse outputResp = outputResponse.getResult();
if (outputResp != null && outputResp.getOutputValue() != null) {
totalOutput = totalOutput.add(outputResp.getOutputValue());
}
}
}
overviewDTO.setTotalValue(totalOutput);
return overviewDTO;
}
/**
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(Top 3)

    1. 性能与资源利用:在 for 循环中进行 RPC 远程调用(最重要)

    • 问题描述:在 SupervisorTaskInfoService.java 的 getTeamOverview 方法中,遍历 directorTypeMerchantMap 时,在 for 循环内部调用了 Dubbo 远程服务 businessSceneAnalysisRemote.querySupervisorOutput(req)。
    • 影响分析:这是典型的性能反模式(RPC in loop)。虽然按照业务逻辑,督导类型(directorType)的数量可能不多(如当前只有 6 和 13),但随着业务扩展或传入非预期数据,循环次数增加会导致网络 I/O 开销成倍增加,严重影响接口响应时间,甚至可能耗尽连接池资源。
    • 优化建议: 方案 A(推荐):推动 BusinessSceneAnalysisRemote 服务提供方提供批量查询接口,将不同类型的参数打包一次性发起 RPC 调用,由服务端进行聚合计算后返回。 方案 B(妥协):如果服务端接口暂时无法改造,且预估循环次数极少,建议使用 CompletableFuture 将串行 RPC 调用改为并行调用,并在设置超时时间后统一等待结果,以降低整体响应延迟。

    2. 健壮性与边界情况:缺少对入参 request 及核心列表的判空保护

    • 问题描述:在 SupervisorTaskInfoService.java 的 getTeamOverview 方法开头,直接调用了 List<Integer> merchantIdList = request.getMerchantIdList();,且后续将 merchantIdList 直接传递给 staffBaseInfoRemote。
    • 影响分析:
      1. 若上游调用方传入的 request 为 null,将直接引发 NullPointerException。
      2. 若 request.getMerchantIdList() 为 null,虽然当前代码不会立即报错,但将其直接传入 staffBaseInfoRemote.listShopStaffInfoGroupByUUid(param),若被调用的远端服务没有做好容错,可能会引发远端异常。
    • 优化建议:在方法入口处增加防御性编程逻辑。 java public SupervisorTeamOverviewDTO getTeamOverview(SupervisorTaskQueryDTO request) { if (request == null) { throw new RpcServiceException(DefaultErrorEnum.INVALID_PARAMETER, "请求参数不能为空"); } SupervisorTeamOverviewDTO overviewDTO = new SupervisorTeamOverviewDTO(); List<Integer> merchantIdList = request.getMerchantIdList(); if (CollectionUtils.isEmpty(merchantIdList)) { // 如果没有门店数据,可直接返回空概况,避免发起无效的 RPC 调用 return overviewDTO; } // ... 后续逻辑 }

    3. 最佳实践与可维护性:硬编码(Magic String)与冗余的类型转换

    • 问题描述:
      1. req.setBizsMulti("1,3"); 中使用了硬编码的字符串 "1,3"。
      2. Integer.valueOf(DirectorTypeEnum.FLIGHT_SUPERVISION.getValue()).equals(directorType) 存在冗余的装箱操作(假设 getValue() 返回 int),且写法较为臃肿。
    • 影响分析:硬编码降低了代码的可读性和可维护性,后续若业务类型发生变更,难以全局追踪和修改。冗余的类型转换虽然对性能影响微乎其微,但不够优雅。
    • 优化建议:
      1. 将 "1,3" 提取为常量,或者通过枚举类的方法动态拼接生成。
      2. 简化枚举值的比对逻辑,推荐使用 Objects.equals() 以增强可读性并防范潜在的空指针。 java // 优化示例 if (Objects.equals(directorType, DirectorTypeEnum.FLIGHT_SUPERVISION.getValue())) { req.setBizs(2); } else if (Objects.equals(directorType, DirectorTypeEnum.FLIGHT_SUPERVISION_2_1.getValue())) { req.setBizsMulti(BizTypeEnum.EXTENDED_WARRANTY_AND_RIGHTS.getBizsMultiStr()); // 假设提取了常量或枚举 }

    二、评分明细

    1. 功能实现的正确性与健壮性(35/40分)
      • 理由:业务逻辑调整基本正确,正确处理了新增字段 directorTypeMerchantMap 的映射与产值累加。DUBBO 请求参数 DTO 新增字段属于向下兼容的安全操作(未变更已有字段类型)。扣分点在于方法入口缺乏对 request 及其核心集合属性的判空保护,存在 NPE 隐患。
    2. 安全性与潜在风险(30/30分)
      • 理由:代码中未见 SQL 注入、越权、敏感日志泄露等常见的安全漏洞。
    3. 最佳实践与可维护性(16/20分)
      • 理由:代码整体结构清晰,引入了 Stream API 的 distinct() 等良好实践。扣分点在于存在硬编码(Magic String)以及部分条件判断语句略显臃肿。
    4. 性能与资源利用(2/5分)
      • 理由:在 for 循环中执行 RPC 调用是比较严重的性能反模式。即使当前循环次数可控,也为未来的系统扩展埋下了性能瓶颈的隐患。
    5. 提交信息质量(4/5分)
      • 理由:Commit 信息(修改查询督导门店列表逻辑/统计督导总产值逻辑)清晰地说明了“做了什么”,但缺乏对“为什么做”(业务背景或目的)的简要说明。

    总分:87分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!