Commit c6ecf2cb by 范富荣

修改录音复盘生成逻辑

1 parent f0ef1a3e
...@@ -31,6 +31,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException; ...@@ -31,6 +31,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert; import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.merchants.model.request.MerchantStaffRequest; import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
import cn.com.glsx.merchants.model.request.StaffBatchRequest; import cn.com.glsx.merchants.model.request.StaffBatchRequest;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.remote.MerchantStaffRemote; import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum; import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
...@@ -58,6 +59,8 @@ import java.math.BigDecimal; ...@@ -58,6 +59,8 @@ import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hutool.poi.excel.sax.AttributeName.r;
@Slf4j @Slf4j
@Service @Service
@Transactional(propagation= Propagation.SUPPORTS,rollbackFor= RpcServiceException.class) @Transactional(propagation= Propagation.SUPPORTS,rollbackFor= RpcServiceException.class)
...@@ -1152,11 +1155,57 @@ public class StaffBaseInfoService { ...@@ -1152,11 +1155,57 @@ public class StaffBaseInfoService {
} }
public List<StaffBaseInfoDTO> listShopStaffBaseInfo(StaffBaseInfoDTO condition) { public List<StaffBaseInfoDTO> listShopStaffBaseInfo(StaffBaseInfoDTO condition) {
return staffBaseInfoMapper.listShopStaffBaseInfo(condition); List<StaffBaseInfoDTO> list = staffBaseInfoMapper.listShopStaffBaseInfo(condition);
if (CollectionUtils.isNotEmpty(list)) {
//过滤角色,只要驻店人员
return filterStaffRole(list, 1);
}
return null;
} }
public List<StaffBaseInfoDTO> listShopStaffInfoGroupByUUid(StaffBaseInfoDTO condition) { public List<StaffBaseInfoDTO> listShopStaffInfoGroupByUUid(StaffBaseInfoDTO condition) {
return staffBaseInfoMapper.listShopStaffInfoGroupByUUid(condition); List<StaffBaseInfoDTO> list = staffBaseInfoMapper.listShopStaffInfoGroupByUUid(condition);
if (CollectionUtils.isNotEmpty(list)) {
//过滤角色,只要驻店人员
return filterStaffRole(list, 1);
}
return null;
}
/**
* 根据员工角色过滤
* @param list
* @param flag 0-根据uuid过滤,1-根据手机号过滤
* @return
*/
public List<StaffBaseInfoDTO> filterStaffRole(List<StaffBaseInfoDTO> list, int flag) {
MerchantStaffRequest staffRequest = new MerchantStaffRequest();
staffRequest.setRoleName(env.getProperty("glsk_staff_role_name", String.class, "驻店人员"));
staffRequest.setDelFlag((byte) 0);
if (flag == 0) {
List<String> uuidList = list.stream().filter(x -> StringUtils.isNotBlank(x.getLoginUuid())).map(StaffBaseInfoDTO::getLoginUuid).collect(Collectors.toList());
if (CollectionUtils.isEmpty(uuidList)) return null;
staffRequest.setStaffUuidList(uuidList);
} else {
List<String> phoneList = list.stream().filter(x -> StringUtils.isNotBlank(x.getStaffPhone())).map(StaffBaseInfoDTO::getStaffPhone).collect(Collectors.toList());
if (CollectionUtils.isEmpty(phoneList)) return null;
staffRequest.setStaffPhoneList(phoneList);
}
RpcResponse<List<MerchantStaffResponse>> response = merchantStaffRemote.findMerchantStaffListRemote(staffRequest);
List<MerchantStaffResponse> result = response.getResult();
if (CollectionUtils.isNotEmpty(result)) {
if (flag == 0) {
List<String> collect = result.stream().map(MerchantStaffResponse::getUuid).collect(Collectors.toList());
return list.stream().filter(x -> collect.contains(x.getLoginUuid())).collect(Collectors.toList());
} else {
List<String> collect = result.stream().map(MerchantStaffResponse::getStaffPhone).collect(Collectors.toList());
return list.stream().filter(x -> collect.contains(x.getStaffPhone())).collect(Collectors.toList());
}
} else {
log.error("查询督导人员列表失败,请求参数={}, message={}", JSON.toJSONString(staffRequest), response.getMessage());
throw new RpcServiceException(DefaultErrorEnum.RPC_ERROR, response.getMessage());
}
} }
/** /**
......
  • @wangxw1
    commented
    Master

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

    1. RPC 调用结果处理逻辑存在严重缺陷(业务逻辑与异常处理)

    • 问题描述:在 filterStaffRole 方法中,当 merchantStaffRemote 返回的 result 为空时,代码直接抛出了 RpcServiceException 异常。同时,日志文案错误(查询的是“驻店人员”,日志写的是“督导人员”)。此外,代码没有校验 RPC 调用的外层状态(如 code 或 isSuccess),仅通过 result 是否为空来判断成功与否。
    • 影响分析:如果某门店确实没有“驻店人员”,RPC 返回空列表是正常的业务状态,并非系统异常。当前写法会导致只要没有匹配的人员,整个接口就会报错崩溃,严重影响核心功能可用性。
    • 优化建议:应先校验 RPC 是否调用成功,若成功但数据为空,应直接返回空集合,而非抛出异常。
    • 代码示例:

      RpcResponse<List<MerchantStaffResponse>> response = merchantStaffRemote.findMerchantStaffListRemote(staffRequest);
      // 假设 RpcResponse 有相应的成功状态判断,如 isSuccess() 或 code == 200
      if (response == null || !response.isSuccess()) {
          log.error("查询驻店人员列表失败,请求参数={}, message={}", JSON.toJSONString(staffRequest), response != null ? response.getMessage() : "null");
          throw new RpcServiceException(DefaultErrorEnum.RPC_ERROR, "查询驻店人员列表失败");
      }
      
      List<MerchantStaffResponse> result = response.getResult();
      if (CollectionUtils.isEmpty(result)) {
          return Collections.emptyList(); // 正常业务场景:该条件下没有驻店人员
      }
      // ... 后续过滤逻辑
      

    2. 集合类型返回值返回 null 引发 NPE 风险

    • 问题描述:listShopStaffBaseInfo、listShopStaffInfoGroupByUUid 以及 filterStaffRole 方法在遇到空数据条件时,均返回了 null。
    • 影响分析:返回 null 违背了 Java 集合返回值的最佳实践(Effective Java 推荐返回空集合)。这会强制要求所有上游调用方必须进行 null 检查,一旦遗漏,在进行 foreach 遍历或调用 size() 时将直接引发 NullPointerException。
    • 优化建议:将所有返回 null 的地方替换为返回空集合。
    • 代码示例: java public List<StaffBaseInfoDTO> listShopStaffBaseInfo(StaffBaseInfoDTO condition) { List<StaffBaseInfoDTO> list = staffBaseInfoMapper.listShopStaffBaseInfo(condition); if (CollectionUtils.isNotEmpty(list)) { return filterStaffRole(list, 1); } return Collections.emptyList(); // 替换 return null; }

    3. 存在无用导入、魔法值及 O(N2) 性能隐患

    • 问题描述:
      1. 顶部混入了一个无用的静态导入:import static cn.hutool.poi.excel.sax.AttributeName.r;。
      2. filterStaffRole 方法的 flag 参数使用了魔法值(0 和 1),缺乏可读性。
      3. 在 Stream 的 filter 操作中,使用了 List.contains() 进行匹配(如 collect.contains(x.getLoginUuid()))。
    • 影响分析:无用导入和魔法值降低了代码的可读性和可维护性;List.contains() 的时间复杂度为 O(N),嵌套在 Stream 中会导致 O(N2) 的时间复杂度,若人员列表数据量较大,会产生不必要的性能损耗。
    • 优化建议:删除无用导入;使用枚举或将 flag 拆分为两个明确语义的方法;将用于 contains 判断的 List 转换为 HashSet 以实现 O(1) 的查询效率。

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分)
      • 理由:扣除20分。将正常的业务空结果当作 RPC 异常抛出是严重的逻辑缺陷,会导致接口在无数据时直接崩溃。
    • 安全性与潜在风险(30/30分)
      • 理由:未发现 SQL 注入、越权等明显安全漏洞,RPC 参数构建正常。
    • 最佳实践与可维护性(10/20分)
      • 理由:扣除10分。集合返回 null 极易引发 NPE,属于明显违背最佳实践;存在无用的静态导入和魔法值(flag == 0/1),日志文案复制粘贴未修改(督导人员/驻店人员)。
    • 性能与资源利用(4/5分)
      • 理由:扣除1分。Stream 过滤中使用了 List.contains,虽然在人员列表场景下数据量通常不大,但转换为 Set.contains 是更好的工程习惯。
    • 提交信息质量(0/5分)
      • 理由:扣除5分。Commit 信息为“修改录音复盘生成逻辑”,但实际修改的是“门店员工基础信息查询与驻店人员过滤逻辑”,提交信息与代码变更内容完全不符,失去追溯价值。

    总分:64分

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