Commit 77928f19 by 谢海旭

飞行督导:web端 督导管理总产值查询逻辑调整

1 parent 72decf86
...@@ -221,7 +221,7 @@ public class SupervisorTaskInfoService { ...@@ -221,7 +221,7 @@ public class SupervisorTaskInfoService {
return summary; return summary;
} }
// 3. 查询 director_config 表,统计所有督导负责的门店(director_type=6,平台中飞行督导) // 3. 查询 director_config 表,统计所有督导负责的门店(director_type=6、13,平台中飞行督导)
List<SupervisorDirectorConfigDTO> supervisorDirectorConfigDTOS = supervisorTaskInfoMapper.queryDirectorConfigBySupervisorPhone(phoneList); List<SupervisorDirectorConfigDTO> supervisorDirectorConfigDTOS = supervisorTaskInfoMapper.queryDirectorConfigBySupervisorPhone(phoneList);
List<Integer> merchantIdList = supervisorDirectorConfigDTOS.stream() List<Integer> merchantIdList = supervisorDirectorConfigDTOS.stream()
.map(SupervisorDirectorConfigDTO::getMerchantId) .map(SupervisorDirectorConfigDTO::getMerchantId)
...@@ -229,9 +229,26 @@ public class SupervisorTaskInfoService { ...@@ -229,9 +229,26 @@ public class SupervisorTaskInfoService {
.collect(Collectors.toList()); .collect(Collectors.toList());
summary.setManagedStoreCount(merchantIdList.size()); summary.setManagedStoreCount(merchantIdList.size());
// supervisorDirectorConfigDTOS按director_type分组、1.1类型一组、2.1一组
Map<Integer, List<SupervisorDirectorConfigDTO>> configByType = supervisorDirectorConfigDTOS.stream()
.collect(Collectors.groupingBy(SupervisorDirectorConfigDTO::getDirectorType));
List<Integer> type6MerchantIds = configByType.getOrDefault(6, Collections.emptyList()).stream()
.map(SupervisorDirectorConfigDTO::getMerchantId).distinct().collect(Collectors.toList());
List<Integer> type13MerchantIds = configByType.getOrDefault(13, Collections.emptyList()).stream()
.map(SupervisorDirectorConfigDTO::getMerchantId).distinct().collect(Collectors.toList());
// 查询统计本月内总产值,保留2位小数 // 查询统计本月内总产值,保留2位小数
BigDecimal monthlyOutput = getMerchantListMonthlyOutput(merchantIdList); // 1.1:轻改(bizs=2) 2.1:延保(bizs=1) + 权益(bizs=3) 分三次查询产值,最后汇总为一个值作为总产值
summary.setMonthlyOutput(monthlyOutput != null ? monthlyOutput.setScale(2, java.math.RoundingMode.HALF_UP) : BigDecimal.ZERO); BigDecimal totalOutput = BigDecimal.ZERO;
if (!type6MerchantIds.isEmpty()) {
totalOutput = totalOutput.add(getMerchantListMonthlyOutput(type6MerchantIds, 2));
}
if (!type13MerchantIds.isEmpty()) {
totalOutput = totalOutput.add(getMerchantListMonthlyOutput(type13MerchantIds, 1));
totalOutput = totalOutput.add(getMerchantListMonthlyOutput(type13MerchantIds, 3));
}
summary.setMonthlyOutput(totalOutput.setScale(2, java.math.RoundingMode.HALF_UP));
return summary; return summary;
} }
...@@ -239,10 +256,12 @@ public class SupervisorTaskInfoService { ...@@ -239,10 +256,12 @@ public class SupervisorTaskInfoService {
* 查询门店列表本月内总产值 * 查询门店列表本月内总产值
* *
* @param merchantIdList 门店ID列表 * @param merchantIdList 门店ID列表
* @param bizs 业务类型,延保=1、轻改=2、权益=3
* @return 本月内总产值 * @return 本月内总产值
*/ */
private BigDecimal getMerchantListMonthlyOutput(List<Integer> merchantIdList) { private BigDecimal getMerchantListMonthlyOutput(List<Integer> merchantIdList, Integer bizs) {
DashboardQueryReq req = new DashboardQueryReq(); DashboardQueryReq req = new DashboardQueryReq();
req.setBizs(bizs);
req.setDateType(4); req.setDateType(4);
req.setStartDate(DateUtil.beginOfMonth(new Date()).toDateStr()); req.setStartDate(DateUtil.beginOfMonth(new Date()).toDateStr());
req.setEndDate(DateUtil.endOfMonth(new Date()).toDateStr()); req.setEndDate(DateUtil.endOfMonth(new Date()).toDateStr());
......
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
SELECT merchant_id, director_type, director_user_id, director_name, director_phone SELECT merchant_id, director_type, director_user_id, director_name, director_phone
FROM dj_car_life_shop_merchant_director_config FROM dj_car_life_shop_merchant_director_config
WHERE deleted_flag = 'N' WHERE deleted_flag = 'N'
AND director_type = 6 AND director_type in (6, 13)
AND director_phone in AND director_phone in
<foreach collection="supervisorPhoneList" open="(" item="i" close=")" separator=","> <foreach collection="supervisorPhoneList" open="(" item="i" close=")" separator=",">
#{i} #{i}
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的空指针异常(NPE)风险(严重)

    • 问题描述:在原代码中,对 getMerchantListMonthlyOutput 的返回值进行了显式的 null 判断(monthlyOutput != null ? ...),这表明该方法可能返回 null。但在修改后的代码中,直接使用了 totalOutput.add(getMerchantListMonthlyOutput(...))。如果该方法返回 null,BigDecimal.add(null) 将直接抛出 NullPointerException。
    • 影响分析:一旦某个业务类型的产值查询返回 null,整个统计接口将直接崩溃报错,导致前端页面无法正常展示数据,属于高危功能性缺陷。
    • 优化建议:在执行 add 操作前进行防空处理,或者在 getMerchantListMonthlyOutput 方法内部保证永远不返回 null(默认返回 BigDecimal.ZERO)。 代码示例: java // 建议封装一个安全的累加方法,或在原处修改: BigDecimal outputType6 = getMerchantListMonthlyOutput(type6MerchantIds, 2); if (outputType6 != null) { totalOutput = totalOutput.add(outputType6); } // 或者修改 getMerchantListMonthlyOutput 方法的最后一行,确保返回非空: // return result != null ? result : BigDecimal.ZERO;

    2. 魔法值泛滥与注释不符(可维护性)

    • 问题描述:代码中大量引入了魔法值(6, 13, 1, 2, 3),且新增的注释“1.1类型一组、2.1一组”与实际代码中使用的 6 和 13 存在认知割裂,未解释 6 和 13 与 1.1/2.1 的映射关系。
    • 影响分析:严重降低代码的可读性与可维护性。后续接手开发的人员难以理解这些数字代表的具体业务含义,极易在后续迭代中改错。
    • 优化建议:将督导类型(DirectorType)和业务类型(BizType)抽取为枚举类或常量,并修正注释以匹配代码逻辑。 代码示例: java // 替换魔法值 public static final int DIRECTOR_TYPE_FLIGHT_1 = 6; public static final int DIRECTOR_TYPE_FLIGHT_2 = 13; public static final int BIZ_TYPE_EXTENDED_WARRANTY = 1; public static final int BIZ_TYPE_LIGHT_MODIFICATION = 2; public static final int BIZ_TYPE_EQUITY = 3;

    3. 循环/多次调用下游接口的性能隐患(性能)

    • 问题描述:为了获取不同业务类型的产值,代码由原来的一次查询变为了最多三次串行调用 getMerchantListMonthlyOutput。
    • 影响分析:如果该方法内部涉及复杂的数据库聚合查询或远程 RPC 调用,三次串行执行将显著增加该接口的响应时间(RT),降低系统吞吐量。
    • 优化建议:评估底层 DashboardQueryReq 和下游接口是否支持传入业务类型集合(如 List<Integer> bizs)。如果支持,应改为一次性查询后在内存中按业务类型分组汇总;如果不支持且该接口耗时较长,可考虑使用 CompletableFuture 进行并发查询。

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分):扣分主要因为移除了原有的 null 值判断,引入了高风险的 NullPointerException 隐患。特别验证项中,无 MyBatis 子查询,也未修改 Dubbo 暴露的 Remote 接口参数,符合红线要求。
    • 安全性与潜在风险(30/30分):未发现 SQL 注入、XSS、越权等安全漏洞。MyBatis 的 XML 修改使用了 in 语法且原有参数传递方式安全。
    • 最佳实践与可维护性(15/20分):扣分因为代码中硬编码了较多业务魔法数字,且注释说明与代码实际使用的常量值存在割裂感,不符合编码规范。
    • 性能与资源利用(3/5分):扣分因为将原有的一次查询拆分成了三次串行查询,存在一定的性能劣化风险。
    • 提交信息质量(5/5分):Commit 信息“飞行督导:web端 督导管理总产值查询逻辑调整”清晰指出了修改的业务模块、端侧及修改目的,具备良好的可追溯性。

    总分:78分

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