Commit 10ff3aab by 章家宝

fix:名称分隔用逗号而不是分号

1 parent 2e2be2d4
...@@ -77,16 +77,16 @@ public class SupervisorSpecialTaskService { ...@@ -77,16 +77,16 @@ public class SupervisorSpecialTaskService {
if (CollectionUtils.isNotEmpty(request.getRegionOperatorList())) { if (CollectionUtils.isNotEmpty(request.getRegionOperatorList())) {
List<String> nameList = request.getRegionOperatorList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getName).collect(Collectors.toList()); List<String> nameList = request.getRegionOperatorList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getName).collect(Collectors.toList());
List<String> phoneList = request.getRegionOperatorList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getPhone).collect(Collectors.toList()); List<String> phoneList = request.getRegionOperatorList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getPhone).collect(Collectors.toList());
regionOperatorName = String.join(";", nameList); regionOperatorName = String.join(",", nameList);
regionOperatorPhone = String.join(";", phoneList); regionOperatorPhone = String.join(",", phoneList);
} }
String problemStaffName = ""; String problemStaffName = "";
String problemStaffPhones = ""; String problemStaffPhones = "";
if (CollectionUtils.isNotEmpty(request.getProblemStaffList())) { if (CollectionUtils.isNotEmpty(request.getProblemStaffList())) {
List<String> nameList = request.getProblemStaffList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getName).collect(Collectors.toList()); List<String> nameList = request.getProblemStaffList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getName).collect(Collectors.toList());
List<String> phoneList = request.getProblemStaffList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getPhone).collect(Collectors.toList()); List<String> phoneList = request.getProblemStaffList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getPhone).collect(Collectors.toList());
problemStaffName = String.join(";", nameList); problemStaffName = String.join(",", nameList);
problemStaffPhones = String.join(";", phoneList); problemStaffPhones = String.join(",", phoneList);
} }
task.setRegionOperatorName(regionOperatorName); task.setRegionOperatorName(regionOperatorName);
task.setRegionOperatorPhone(regionOperatorPhone); task.setRegionOperatorPhone(regionOperatorPhone);
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的 "null" 字符串拼接风险(健壮性问题)

    • 问题描述:当 request.getRegionOperatorList() 或 request.getProblemStaffList() 列表中的 StaffInfo 对象的 name 或 phone 属性为 null 时,String.join() 方法会默认将其转换为字符串字面量 "null" 进行拼接(例如生成 "张三,null,李四")。
    • 影响分析:会导致脏数据落库,进而可能引起前端展示异常或下游业务解析错误。
    • 优化建议:在 Stream 处理中增加对空值或空字符串的过滤逻辑。
    • 代码示例: java List<String> nameList = request.getRegionOperatorList().stream() .map(SubmitSpecialTaskDTO.StaffInfo::getName) .filter(StringUtils::isNotBlank) // 增加过滤逻辑 .collect(Collectors.toList());

    2. 分隔符变更带来的数据兼容性风险(功能正确性)

    • 问题描述:将原本的分号 ; 变更为逗号 , 作为分隔符。
    • 影响分析:如果数据库中已经存在大量以分号 ; 分隔的历史数据,或者下游系统、前端页面、报表导出等解析该字段时强依赖于分号 ;,该变更会导致读取历史数据或下游解析时发生异常。
    • 优化建议:请全局确认读取和解析该字段的相关逻辑是否已同步修改,并确保解析逻辑(如 split 操作)能够同时兼容历史的 ; 和新增的 , 两种分隔符。

    3. 集合的重复遍历与冗余(最佳实践)

    • 问题描述:对 request.getRegionOperatorList() 和 request.getProblemStaffList() 均进行了两次完整的 Stream 遍历,分别用于提取 name 和 phone 并生成两个新的 List。
    • 影响分析:虽然在小数据量下性能损耗可忽略不计,但产生了不必要的多次遍历和中间集合对象,不符合代码编写的最佳实践。
    • 优化建议:建议使用单次 for 循环配合 StringJoiner,在一次遍历中同时完成 name 和 phone 的提取与拼接,使代码更高效、紧凑。
    • 代码示例: java StringJoiner nameJoiner = new StringJoiner(","); StringJoiner phoneJoiner = new StringJoiner(","); for (SubmitSpecialTaskDTO.StaffInfo staff : request.getRegionOperatorList()) { if (StringUtils.isNotBlank(staff.getName())) nameJoiner.add(staff.getName()); if (StringUtils.isNotBlank(staff.getPhone())) phoneJoiner.add(staff.getPhone()); } regionOperatorName = nameJoiner.toString(); regionOperatorPhone = phoneJoiner.toString();

    二、评分明细

    1. 功能实现的正确性与健壮性(35/40分)

      • 理由:修改逻辑简单且符合预期目的。但缺乏对对象属性可能为 null 的防御性编程,且变更分隔符可能引发历史数据兼容性问题,酌情扣 5 分。
    2. 安全性与潜在风险(30/30分)

      • 理由:仅涉及字符串拼接符的修改,未涉及 SQL 操作及 Dubbo 接口参数变更,不存在 SQL 注入、XSS、越权等安全隐患。
    3. 最佳实践与可维护性(17/20分)

      • 理由:通过 Stream 两次遍历同一集合提取不同属性略显冗余,未采用更优雅的单次遍历或 StringJoiner,扣 3 分。
    4. 性能与资源利用(4/5分)

      • 理由:重复遍历和创建多余的 List 集合造成了微小的性能与内存开销,但在当前业务场景下影响极小,扣 1 分。
    5. 提交信息质量(4/5分)

      • 理由:提交信息(fix:名称分隔用逗号而不是分号)清晰描述了做了“什么”,但未说明“为什么”要做此修改(即业务背景或触发原因),扣 1 分。

    总分:90分

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