Commit 416561e6 by 谢海旭

Merge remote-tracking branch 'origin/main'

2 parents 005e736b d82b7f6e
......@@ -70,7 +70,7 @@ public interface ExcellentCaseReviewMapper extends OreMapper<ExcellentCaseReview
* @param recordingId 录音ID
* @return 存在数量(0表示未提交,大于0表示已提交)
*/
Integer countByRecordingId(@Param("recordingId") Long recordingId);
ExcellentCaseReview countByRecordingId(@Param("recordingId") Long recordingId);
/**
* 查询所有客户类型
......
......@@ -59,34 +59,53 @@ public class ExcellentCaseReviewService {
log.info("开始提交优秀案例,请求参数:{}", request);
// 检查录音ID是否已经提交过
Integer existingCount = excellentCaseReviewMapper.countByRecordingId(request.getRecordingId());
if (existingCount != null && existingCount > 0) {
log.error("录音ID已提交过,录音ID:{}", request.getRecordingId());
throw new RpcServiceException("录音ID已提交过");
ExcellentCaseReview existingCount = excellentCaseReviewMapper.countByRecordingId(request.getRecordingId());
if (existingCount != null) {
if(existingCount.getReviewStatus().intValue()==0) {
log.error("录音ID已提交过,录音ID:{}", request.getRecordingId());
throw new RpcServiceException("录音审核中,请勿重复提交");
}else if(existingCount.getReviewStatus().intValue()==1) {
log.error("录音ID已提交过,录音ID:{}", request.getRecordingId());
throw new RpcServiceException("录音已经通过,请勿重复提交");
}
}
ExcellentCaseReview excellentCase = new ExcellentCaseReview();
BeanUtils.copyProperties(request, excellentCase);
// 设置初始状态为待审核
excellentCase.setReviewStatus(ExcellentCaseReviewStatusEnum.PENDING.getCode());
// 设置提交人信息
excellentCase.setSubmitterId(currentUserId);
excellentCase.setSubmitterName(currentUser);
// 设置创建信息
excellentCase.setCreatedBy(currentUser);
excellentCase.setCreateTime(new Date());
excellentCase.setUpdatedBy(currentUser);
excellentCase.setUpdatedDate(new Date());
excellentCase.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
int count = excellentCaseReviewMapper.insertSelective(excellentCase);
if (count <= 0) {
log.error("插入优秀案例失败,请求参数:{}", request);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, "插入优秀案例失败");
if (existingCount==null) {
ExcellentCaseReview excellentCase = new ExcellentCaseReview();
BeanUtils.copyProperties(request, excellentCase);
// 设置初始状态为待审核
excellentCase.setReviewStatus(ExcellentCaseReviewStatusEnum.PENDING.getCode());
// 设置提交人信息
excellentCase.setSubmitterId(currentUserId);
excellentCase.setSubmitterName(currentUser);
// 设置创建信息
excellentCase.setCreatedBy(currentUser);
excellentCase.setCreateTime(new Date());
excellentCase.setUpdatedBy(currentUser);
excellentCase.setUpdatedDate(new Date());
excellentCase.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
int count = excellentCaseReviewMapper.insertSelective(excellentCase);
if (count <= 0) {
log.error("插入优秀案例失败,请求参数:{}", request);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, "插入优秀案例失败");
}
log.info("提交优秀案例成功,案例ID:{}", excellentCase.getId());
}else{
existingCount.setReviewStatus(ExcellentCaseReviewStatusEnum.PENDING.getCode());
// 设置提交人信息
existingCount.setSubmitterId(currentUserId);
existingCount.setSubmitterName(currentUser);
existingCount.setUpdatedBy(currentUser);
existingCount.setUpdatedDate(new Date());
int count = excellentCaseReviewMapper.updateByPrimaryKeySelective(existingCount);
if (count <= 0) {
log.error("更新优秀案例失败,请求参数:{}", request);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, "更新优秀案例失败");
}
log.info("提交优秀案例成功,案例ID:{}", existingCount.getId());
}
log.info("提交优秀案例成功,案例ID:{}", excellentCase.getId());
return true;
}
......
......@@ -133,10 +133,10 @@ public class SupervisorAudioReviewInfoService {
throw new RpcServiceException(DefaultErrorEnum.DATA_NOT_EXIST, "录音复盘记录不存在");
}
//判断是否已复盘
if (ReviewStatusEnum.COMPLETED.getCode().equals(info.getReviewStatus()) && StringUtils.isBlank(request.getReviewTarget())) {
log.error("提交录音复盘记录,录音复盘记录已复盘,id={}", request.getId());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "录音复盘记录已复盘,不能重复提交");
}
// if (ReviewStatusEnum.COMPLETED.getCode().equals(info.getReviewStatus()) && StringUtils.isBlank(request.getReviewTarget())) {
// log.error("提交录音复盘记录,录音复盘记录已复盘,id={}", request.getId());
// throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "录音复盘记录已复盘,不能重复提交");
// }
request.setUpdatedDate(new Date());
request.setReviewStatus(ReviewStatusEnum.COMPLETED.getCode());
supervisorAudioReviewInfoMapper.updateByPrimaryKeySelective(request);
......
......@@ -204,8 +204,8 @@
order by t5.customer_type
</select>
<select id="countByRecordingId" parameterType="java.lang.Long" resultType="java.lang.Integer">
select count(1)
<select id="countByRecordingId" parameterType="java.lang.Long" resultMap="BaseResultMap">
select *
from excellent_case_review
where deleted_flag = 'N' and recording_id = #{recordingId}
</select>
......
......@@ -27,7 +27,7 @@ public class ExcellentCaseReviewRemoteImplTest extends BaseServiceTest {
@Test
public void testSubmitExcellentCase() {
ExcellentCaseSubmitDTO request = new ExcellentCaseSubmitDTO();
request.setRecordingId(915L);
request.setRecordingId(917L);
String currentUser = "谢海旭";
String currentUserId = "584fdb460afa4dad835cbe8d73cfa923";
RpcResponse<Boolean> response = excellentCaseReviewRemote.submitExcellentCase(request, currentUser, currentUserId);
......
  • @wangxw1
    commented
    Master

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

    1. 【健壮性/致命】存在严重的 NullPointerException (NPE) 风险

    • 问题描述:代码中直接调用了 o1.getStudyHours().compareTo(...) 等方法。如果 o1、o2 本身为 null,或者它们的属性(如 StudyHours、CompletedCourses)为 null,将直接抛出 NullPointerException 导致系统异常。此外,如果 request 或 request.getSortField() 为 null(假设是包装类 Integer),也会在条件判断时触发 NPE。
    • 规范依据:《阿里巴巴 Java 开发手册》- 异常处理:防止 NPE,是程序员的基本修养,注意包装类拆箱、级联调用时的空指针问题。
    • 优化建议:使用 Java 8 提供的安全比较器,如 Comparator.nullsLast(),并在排序前校验 request 及其参数。

    2. 【可维护性/规范】滥用魔法值与陈旧的排序实现方式

    • 问题描述:代码中充斥着 1、2、3 这样的魔法数字(Magic Number),缺乏业务语义说明(例如 1 代表什么字段?sortOrder == 1 是升序还是降序?)。此外,使用传统的匿名内部类/Lambda 返回 1, -1, 0 的方式过于冗长,不符合现代 Java 编码风格。
    • 规范依据:《阿里巴巴 Java 开发手册》- 编程规约:不允许任何魔法值(即未经预先定义的常量)直接出现在代码中。
    • 优化建议:将排序字段和排序规则定义为 Enum 或常量。建议使用 Java 8 的 Comparator.comparing() 配合 reversed() 来重构,代码更简洁易读。例如: java // 伪代码示例 Comparator<EmployeeTrainingInfo> comparator = Comparator.comparing( EmployeeTrainingInfo::getStudyHours, Comparator.nullsLast(Integer::compareTo) ); if (request.getSortOrder() == SortOrderEnum.DESC.getCode()) { comparator = comparator.reversed(); }

    3. 【提交规范】提交信息(Commit Message)缺失变更原因

    • 问题描述:本次代码修改的核心逻辑是完全反转了原有的排序规则(将 o1.compareTo(o2) 与 o2.compareTo(o1) 的条件对调了)。但提交信息仅描述了“v5.7.0版本 飞行督导”,未说明为什么要反转排序规则。
    • 规范依据:良好的 Git 提交规范要求不仅要说明“做了什么”,更要说明“为什么这么做”,以便于后续问题排查和代码回溯。
    • 优化建议:在 Commit Message 中补充具体的业务背景,例如:“fix: 修复由于前端传参定义变更导致的排序结果相反问题(将 sortOrder=1 调整为降序)”。

    二、评分明细

    审查维度 满分 得分 扣分说明
    1. 功能正确性与健壮性 40 25 扣15分。未处理对象及属性的 null 值,在实际业务中极易触发 NPE 导致接口崩溃;未校验 request 及其参数的合法性。
    2. 安全性与潜在风险 30 28 扣2分。对于大数据量的列表,在内存中直接使用 list.sort 会占用较多 CPU 和内存资源,存在轻微的性能耗尽风险(建议尽量在 DB 层用 SQL 进行 Order By)。
    3. 最佳实践与可维护性 20 12 扣8分。严重依赖魔法值(1,2,3),代码可读性差;未利用 Java 8+ 的 Comparator 现代写法,代码显得冗余。
    4. 性能与资源利用 5 4 扣1分。嵌套的 if-else 判断在每次元素比较时都会执行,虽然对小列表影响不大,但并非最优的 Comparator 实现方式。
    5. 提交信息质量 5 2 扣3分。Commit 信息过于笼统,掩盖了“反转排序逻辑”这一核心且高风险的变更行为,不利于团队协作。

    总分:71分

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