Commit 633e594b by zhouhaibao

[+]新增空权限处理

1 parent a89ff913
...@@ -172,6 +172,10 @@ public class SupervisorDashboardService { ...@@ -172,6 +172,10 @@ public class SupervisorDashboardService {
allMerchantIds.addAll(flightSupervision21Merchants); allMerchantIds.addAll(flightSupervision21Merchants);
} }
if (CollectionUtils.isEmpty(allMerchantIds)){
return vo;
}
// 获取所有门店的员工列表 // 获取所有门店的员工列表
storeAndEmployeePhoneList = getSupervisorStoreAndEmployeePhoneList(req.getSupervisorId(), allMerchantIds); storeAndEmployeePhoneList = getSupervisorStoreAndEmployeePhoneList(req.getSupervisorId(), allMerchantIds);
if (storeAndEmployeePhoneList.isEmpty()) { if (storeAndEmployeePhoneList.isEmpty()) {
...@@ -188,6 +192,9 @@ public class SupervisorDashboardService { ...@@ -188,6 +192,9 @@ public class SupervisorDashboardService {
} else { } else {
// biz不为空时,使用原有逻辑 // biz不为空时,使用原有逻辑
List<Integer> merchantIds = getSupervisorMerchants(req.getSupervisorId(), bizs); List<Integer> merchantIds = getSupervisorMerchants(req.getSupervisorId(), bizs);
if(CollectionUtils.isEmpty(merchantIds)){
return vo;
}
// 获取督导的管理门店以及门店的员工的手机号列表 // 获取督导的管理门店以及门店的员工的手机号列表
storeAndEmployeePhoneList = getSupervisorStoreAndEmployeePhoneList(req.getSupervisorId(), merchantIds); storeAndEmployeePhoneList = getSupervisorStoreAndEmployeePhoneList(req.getSupervisorId(), merchantIds);
...@@ -362,7 +369,9 @@ public class SupervisorDashboardService { ...@@ -362,7 +369,9 @@ public class SupervisorDashboardService {
dataLists.add(fetchBehaviorDataByBiz(req, flightSupervision21Merchants, 3)); // 权益 dataLists.add(fetchBehaviorDataByBiz(req, flightSupervision21Merchants, 3)); // 权益
allMerchantIds.addAll(flightSupervision21Merchants); allMerchantIds.addAll(flightSupervision21Merchants);
} }
if (CollectionUtils.isEmpty(allMerchantIds)){
return vo;
}
// 获取所有门店的员工列表 // 获取所有门店的员工列表
storePhoneMap = getSupervisorStoreAndEmployeePhoneList(req.getSupervisorId(), allMerchantIds); storePhoneMap = getSupervisorStoreAndEmployeePhoneList(req.getSupervisorId(), allMerchantIds);
if (storePhoneMap.isEmpty()) return vo; if (storePhoneMap.isEmpty()) return vo;
...@@ -377,6 +386,10 @@ public class SupervisorDashboardService { ...@@ -377,6 +386,10 @@ public class SupervisorDashboardService {
} else { } else {
// biz不为空时,使用原有逻辑 // biz不为空时,使用原有逻辑
List<Integer> merchantIds = getSupervisorMerchants(req.getSupervisorId(), bizs); List<Integer> merchantIds = getSupervisorMerchants(req.getSupervisorId(), bizs);
if (CollectionUtils.isEmpty(merchantIds)){
return vo;
}
req.setMerchantIds(merchantIds); req.setMerchantIds(merchantIds);
// 获取管辖员工 // 获取管辖员工
......
  • @wangxw1
    commented
    Master

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

    1. 业务短路返回缺少日志记录(可维护性)

    • 问题描述:在 allMerchantIds 或 merchantIds 为空时直接短路返回 vo,逻辑上拦截了无效查询,但未记录任何日志。
    • 影响分析:当线上发生“督导看板数据为空”的客诉时,排查人员很难通过日志快速确认是因为督导没有关联门店权限,还是下游服务或数据库出现异常,增加了排查成本。
    • 优化建议:建议在返回前增加一条业务日志,提升系统的可观测性。 java if (CollectionUtils.isEmpty(merchantIds)) { log.info("Supervisor dashboard: supervisorId={} has no merchant permissions, return empty.", req.getSupervisorId()); return vo; }

    2. 需确保提前返回的 vo 对象结构完整(健壮性)

    • 问题描述:增加空判断后直接 return vo;,跳过了后续的数据组装逻辑。
    • 影响分析:需确保在触发这些 return vo; 分支之前,vo 对象内部的关键属性(如前端需要的各种数据 List)已经初始化为默认的空集合([])而非 null。如果前端没有做严格的判空兼容,返回 null 可能会导致前端渲染报错或白屏。
    • 优化建议:检查 vo 实例化的代码,确保使用了默认值初始化(如 private List<XXX> dataList = new ArrayList<>();),保障接口契约的一致性。

    3. 代码格式与规范一致性(最佳实践)

    • 问题描述:新增的部分代码中,if 关键字与括号之间、右括号与大括号之间缺少空格,例如 if(CollectionUtils.isEmpty(merchantIds)){。
    • 影响分析:虽然不影响功能,但不符合主流的 Java 编码规范(如 Alibaba Java 规范或 Google Style),不利于团队代码风格的统一。
    • 优化建议:建议在提交代码前使用 IDE 的自动格式化功能。 java // 修改前 if(CollectionUtils.isEmpty(merchantIds)){ // 修改后 if (CollectionUtils.isEmpty(merchantIds)) {

    二、评分明细

    • 功能实现的正确性与健壮性(40/40分): 逻辑完全正确。本次修改有效避免了将空集合传递给下游方法(如引发 SQL 中的 IN () 语法错误),增强了系统的健壮性。
    • 安全性与潜在风险(30/30分): 未引入任何安全漏洞(如 SQL 注入、越权等),属于正向防御性编程。
    • 最佳实践与可维护性(18/20分): 短路逻辑是很好的实践,但在代码格式细节(空格缺失)以及关键分支的可观测性(缺少日志)上还有微调空间。
    • 性能与资源利用(5/5分): 通过前置校验拦截了无意义的数据查询和 RPC 调用,有效节约了数据库和服务器资源,对性能有正向提升。
    • 提交信息质量(5/5分): commit 描述 [+]新增空权限处理 简洁明了,准确反映了代码变更的目的。

    总分:98分

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