Commit f86e14ad by 章家宝

feat:审批的时候添加北森课程id与名称,返回的时候也做返回

1 parent 26998c48
...@@ -102,6 +102,20 @@ public class SupervisorSpecialCoachApprovalController { ...@@ -102,6 +102,20 @@ public class SupervisorSpecialCoachApprovalController {
} }
} }
// 转换课程列表:List<CourseItem> -> 逗号分隔的字符串
if (request.getCourseList() != null && !request.getCourseList().isEmpty()) {
String bcCourseIds = request.getCourseList().stream()
.map(ApprovalSubmitRequest.CourseItem::getBcCourseId)
.filter(StrUtil::isNotBlank)
.collect(java.util.stream.Collectors.joining(","));
String bcCourseNames = request.getCourseList().stream()
.map(ApprovalSubmitRequest.CourseItem::getBcCourseName)
.filter(StrUtil::isNotBlank)
.collect(java.util.stream.Collectors.joining(","));
dto.setBcCourseIds(bcCourseIds);
dto.setBcCourseNames(bcCourseNames);
}
RpcResponse<ApprovalResultDTO> response = approvalRemote.approveSpecialTask(dto); RpcResponse<ApprovalResultDTO> response = approvalRemote.approveSpecialTask(dto);
if (response.hasError()) { if (response.hasError()) {
return RopResponse.error(response.getError(), response.getMessage()); return RopResponse.error(response.getError(), response.getMessage());
......
...@@ -66,4 +66,6 @@ public class TaskCenterExecuteRequest extends AbstractRopRequest { ...@@ -66,4 +66,6 @@ public class TaskCenterExecuteRequest extends AbstractRopRequest {
@ApiModelProperty(notes = "北森课程id列表") @ApiModelProperty(notes = "北森课程id列表")
private List<String> bcCourseIdList; private List<String> bcCourseIdList;
@ApiModelProperty(notes = "北森课程名称列表")
private List<String> bcCourseNameList;
} }
...@@ -188,6 +188,18 @@ public class SupervisorSpecialCoachTaskService { ...@@ -188,6 +188,18 @@ public class SupervisorSpecialCoachTaskService {
String teachingStaffNames = String.valueOf(fieldMap.get("teachingStaffNames")); String teachingStaffNames = String.valueOf(fieldMap.get("teachingStaffNames"));
dto.setTaskStaffList(Arrays.asList(teachingStaffNames.split(","))); dto.setTaskStaffList(Arrays.asList(teachingStaffNames.split(",")));
} }
// 北森课程ID(逗号分隔)
if (fieldMap.containsKey("bcCourseIds")) {
String bcCourseIds = String.valueOf(fieldMap.get("bcCourseIds"));
dto.setBcCourseIdList(Arrays.asList(bcCourseIds.split(",")));
}
// 北森课程名称(逗号分隔)
if (fieldMap.containsKey("bcCourseNames")) {
String bcCourseNames = String.valueOf(fieldMap.get("bcCourseNames"));
dto.setBcCourseNameList(Arrays.asList(bcCourseNames.split(",")));
}
} catch (Exception e) { } catch (Exception e) {
log.error("解析bizDisplayInfo失败,bizDisplayInfo={}", bizDisplayInfo, e); log.error("解析bizDisplayInfo失败,bizDisplayInfo={}", bizDisplayInfo, e);
} }
......
  • @wangxw1
    commented
    Master

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

    1. 数据一致性风险与性能问题(Controller层)

    • 问题描述:在 SupervisorSpecialCoachApprovalController 中,对 CourseList 进行了两次 Stream 遍历。更严重的是,分别独立使用 filter(StrUtil::isNotBlank) 进行过滤。如果某个 CourseItem 存在 bcCourseId 但 bcCourseName 为空(或相反),会导致最终生成的 bcCourseIds 和 bcCourseNames 逗号分隔字符串长度不一致、元素错位,下游解析时将无法正确匹配 ID 和名称。此外,未防范 CourseItem 对象本身为 null 导致的 NPE。
    • 优化建议:建议使用单次循环处理,保证 ID 和名称的严格对齐,并提升性能。 java // 优化示例 if (CollUtil.isNotEmpty(request.getCourseList())) { List<String> ids = new ArrayList<>(); List<String> names = new ArrayList<>(); for (ApprovalSubmitRequest.CourseItem item : request.getCourseList()) { if (item != null && StrUtil.isNotBlank(item.getBcCourseId()) && StrUtil.isNotBlank(item.getBcCourseName())) { ids.add(item.getBcCourseId()); names.add(item.getBcCourseName()); } } dto.setBcCourseIds(CollUtil.join(ids, ",")); dto.setBcCourseNames(CollUtil.join(names, ",")); }

    2. String.valueOf(null) 导致的隐藏 Bug(Service层)

    • 问题描述:在 SupervisorSpecialCoachTaskService 中,fieldMap.get("bcCourseIds") 如果返回 null(尽管外层有 containsKey 判断,但 Map 的 value 仍可能为 null),String.valueOf(null) 会返回字面量字符串 "null"。随后 "null".split(",") 会生成一个包含 "null" 字符串的 List ["null"],而不是空列表,这会导致极其隐蔽的业务 Bug。
    • 优化建议:在转换前进行严格的 null 检查,建议使用 MapUtils.getString()(如果引入了 Apache Commons Collections)或手动判断。 java // 优化示例 Object idsObj = fieldMap.get("bcCourseIds"); if (idsObj != null) { String bcCourseIds = String.valueOf(idsObj); // 见问题3,还需判断空字符串 }

    3. 空字符串 split 导致产生空元素数组(Service层)

    • 问题描述:在 SupervisorSpecialCoachTaskService 中,直接调用 bcCourseIds.split(",")。如果 bcCourseIds 是一个空字符串 "",Java 的 split 方法会返回一个长度为 1 的数组 [""],从而导致 dto.setBcCourseIdList 得到一个包含空字符串的列表,而不是预期中的空列表。
    • 优化建议:在执行 split 之前,必须使用 StringUtils.isNotBlank() 判断字符串是否有实际内容。 java // 优化示例 if (idsObj != null && StrUtil.isNotBlank(String.valueOf(idsObj))) { dto.setBcCourseIdList(Arrays.asList(String.valueOf(idsObj).split(","))); } else { dto.setBcCourseIdList(Collections.emptyList()); }

    二、评分明细

    • 功能实现的正确性与健壮性(40分):20分
      • 扣分原因:独立过滤导致 ID 与名称错位(严重逻辑缺陷);String.valueOf(null) 陷阱;空字符串 split 产生脏数据。这些问题在极端边界条件下极易引发线上 Bug。
    • 安全性与潜在风险(30分):30分
      • 得分原因:代码变更主要集中在数据结构的转换与解析,未引入明显的 SQL 注入、XSS、越权等安全漏洞。
    • 最佳实践与可维护性(20分):15分
      • 扣分原因:Controller 中使用两次 Stream 遍历不仅降低了可读性,也违背了《阿里巴巴 Java 开发手册》中关于集合处理高效与严谨的原则。
    • 性能与资源利用(5分):3分
      • 扣分原因:O(2N) 的两次 Stream 遍历存在不必要的性能损耗,一次遍历即可完成组装。
    • 提交信息质量(5分):4分
      • 得分原因:提交信息包含了 feat: 前缀,说明了业务意图(添加北森课程id与名称),格式基本符合规范,但略显口语化。

    总分:72分

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