Commit d82b7f6e by zhouhaibao

[+]驻店员工逻辑调整

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

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

    1. 命名名不副实与注释过期(违反阿里巴巴开发规范)

    • 问题描述:在 ExcellentCaseReviewMapper 中,方法名 countByRecordingId 原本用于统计数量,但本次修改将其返回值改为了实体对象 ExcellentCaseReview。同时,Service 层中接收该对象的变量名依然叫 existingCount。这导致方法名、变量名与实际业务逻辑严重不符,且接口的 JavaDoc 注释(“返回存在数量”)未同步更新,极大地降低了代码的可读性和可维护性。
    • 优化建议:
      • 将 Mapper 方法重命名为 selectByRecordingId 或 findByRecordingId。
      • 将 Service 中的变量名 existingCount 更改为 existingRecord 或 existingCase。
      • 同步更新 Mapper 接口中的 JavaDoc 注释。

    2. 魔法值硬编码与潜在的空指针异常(NPE)风险

    • 问题描述:在 ExcellentCaseReviewService 中,判断审核状态时使用了魔法值(intValue()==0 和 intValue()==1),这违反了阿里巴巴规范中“不允许任何魔法值直接出现在代码中”的规定。且代码下文已经使用了 ExcellentCaseReviewStatusEnum.PENDING.getCode(),上下文标准不一致。此外,如果数据库中 reviewStatus 为 null,调用 .intValue() 会直接触发 NullPointerException。
    • 优化建议:使用枚举类进行安全的判等比较。 java // 假设 0 为 PENDING,1 为 APPROVED,请替换为实际枚举 if (Objects.equals(existingRecord.getReviewStatus(), ExcellentCaseReviewStatusEnum.PENDING.getCode())) { throw new RpcServiceException("录音审核中,请勿重复提交"); } else if (Objects.equals(existingRecord.getReviewStatus(), ExcellentCaseReviewStatusEnum.APPROVED.getCode())) { throw new RpcServiceException("录音已经通过,请勿重复提交"); }

    3. SQL 规范问题与多条记录报错风险(MyBatis 异常)

    • 问题描述:在 ExcellentCaseReviewMapper.xml 中,查询语句被改为了 select * from ...。阿里巴巴开发手册明确规定:禁止使用 select *,必须明确指定列名。此外,该 SQL 原本是查 count,现在改为查单条记录,如果数据库中存在多条相同 recording_id 且 deleted_flag = 'N' 的脏数据,MyBatis 会抛出 TooManyResultsException 导致接口崩溃。
    • 优化建议:
      • 将 select * 替换为具体的字段名(如 <include refid="Base_Column_List" />)。
      • 为保证健壮性,建议在 SQL 末尾增加 LIMIT 1,确保无论数据情况如何,最多只返回一条记录。

    二、评分明细

    • 1. 功能实现的正确性与健壮性(40分):28分
      • 扣分项:状态字段存在 NPE 风险(-6分);Mapper 查询单条数据未加 LIMIT 1 存在 TooManyResultsException 隐患(-6分)。
    • 2. 安全性与潜在风险(30分):30分
      • 无明显 SQL 注入、越权等严重安全漏洞。
    • 3. 最佳实践与可维护性(20分):10分
      • 扣分项:方法名与返回类型严重不符(-4分);使用魔法值进行状态判断(-4分);If-else 分支中存在重复的装配逻辑代码,结构不够精简(-2分)。
    • 4. 性能与资源利用(5分):3分
      • 扣分项:使用了 select * 增加数据库解析和网络传输开销(-2分)。
    • 5. 提交信息质量(5分):3分
      • 扣分项:提交信息 "驻店员工逻辑调整" 过于宽泛,未能准确描述本次将“仅限制提交”改为“支持退回后重新提交/更新”的业务意图(-2分)。

    总分:74分

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