Commit b900e817 by 谢海旭

学习中心 优化代码,方法提取

1 parent cf6dbb78
...@@ -231,10 +231,10 @@ public class LearningCenterLevelExamService { ...@@ -231,10 +231,10 @@ public class LearningCenterLevelExamService {
/** /**
* 检查是否存在重复记录 * 检查是否存在重复记录
* *
* @param beisenExamId * @param beisenExamId 北森考试标识
* @param departmentId * @param departmentId 北森部门标识
* @param positionCode * @param positionCode 北森职务标识
* @param examTime * @param examTime 等级考试-考试时间
*/ */
private void repeatCheck(String beisenExamId, Integer departmentId, String positionCode, Integer examTime) { private void repeatCheck(String beisenExamId, Integer departmentId, String positionCode, Integer examTime) {
Example repeatQueryExample = new Example(LearningCenterLevelExam.class); Example repeatQueryExample = new Example(LearningCenterLevelExam.class);
...@@ -413,7 +413,65 @@ public class LearningCenterLevelExamService { ...@@ -413,7 +413,65 @@ public class LearningCenterLevelExamService {
Byte newStatus = request.getStatus(); Byte newStatus = request.getStatus();
String updatedBy = request.getUpdatedBy(); String updatedBy = request.getUpdatedBy();
// 原始状态与请求数据状态比较判断:原状态是草稿,则可以更新为 草稿、未生效;原始状态是未生效,则只能更新为未生效;原始状态是生效,则只能更新为生效;原始状态是失效,则只能更新为失效、生效 // 原始状态与请求数据状态比较判断:原状态是草稿,则可以更新为 草稿、未生效;原始状态是未生效,则只能更新为未生效;原始状态是生效,则只能更新为生效;原始状态是失效,则只能更新为失效、生效
if (LevelExamStatusEnum.DRAFT.getValue().compareTo(oldStatus) == 0) { if (LevelExamStatusEnum.DRAFT.getValue().compareTo(oldStatus) == 0
|| LevelExamStatusEnum.NOT_EFFECTIVE.getValue().compareTo(oldStatus) == 0) {
draftOrNotEffectiveUpdate(request, oldLevelExam);
} else if (LevelExamStatusEnum.EFFECTIVE.getValue().compareTo(oldStatus) == 0) {
if (LevelExamStatusEnum.EFFECTIVE.getValue().compareTo(newStatus) != 0) {
log.info("等级考试状态错误 id:{}", levelExamId);
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级考试状态错误");
}
Integer examTime = request.getExamTime();
Integer oldExamTime = oldLevelExam.getExamTime();
if (examTime.compareTo(oldExamTime) != 0) {
repeatCheck(oldLevelExam.getBeisenExamId(), oldLevelExam.getDepartmentId(), oldLevelExam.getPositionCode(), examTime);
}
LearningCenterLevelExam updateExam = new LearningCenterLevelExam();
updateExam.setId(levelExamId);
updateExam.setExamTime(examTime);
updateExam.setUpdatedBy(updatedBy);
updateExam.setUpdatedDate(new Date());
levelExamMapper.updateByPrimaryKeySelective(updateExam);
} else if (LevelExamStatusEnum.INVALID.getValue().compareTo(oldStatus) == 0) {
if (LevelExamStatusEnum.INVALID.getValue().compareTo(newStatus) != 0
&& LevelExamStatusEnum.EFFECTIVE.getValue().compareTo(newStatus) != 0) {
log.info("等级考试状态错误 id:{}", levelExamId);
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级考试状态错误");
}
Integer examTime = request.getExamTime();
Integer oldExamTime = oldLevelExam.getExamTime();
if (examTime.compareTo(oldExamTime) != 0) {
repeatCheck(oldLevelExam.getBeisenExamId(), oldLevelExam.getDepartmentId(), oldLevelExam.getPositionCode(), request.getExamTime());
}
LearningCenterLevelExam updateExam = new LearningCenterLevelExam();
updateExam.setId(levelExamId);
updateExam.setExamTime(examTime);
updateExam.setStatus(newStatus);
updateExam.setUpdatedBy(updatedBy);
updateExam.setUpdatedDate(new Date());
levelExamMapper.updateByPrimaryKeySelective(updateExam);
} else {
log.info("等级考试原始状态错误 id:{}", levelExamId);
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级考试原始状态错误");
}
}
/**
* 更新草稿、未生效 状态的等级考试
*
* @param request 更新信息
* @param oldLevelExam 原等级考试信息
*/
private void draftOrNotEffectiveUpdate(LevelExamDetailDTO request, LearningCenterLevelExam oldLevelExam) {
Integer levelExamId = request.getId();
Byte oldStatus = oldLevelExam.getStatus();
Byte newStatus = request.getStatus();
String updatedBy = request.getUpdatedBy();
if (LevelExamStatusEnum.DRAFT.getValue().compareTo(oldStatus) == 0 if (LevelExamStatusEnum.DRAFT.getValue().compareTo(oldStatus) == 0
&& LevelExamStatusEnum.DRAFT.getValue().compareTo(newStatus) != 0 && LevelExamStatusEnum.DRAFT.getValue().compareTo(newStatus) != 0
&& LevelExamStatusEnum.NOT_EFFECTIVE.getValue().compareTo(newStatus) != 0) { && LevelExamStatusEnum.NOT_EFFECTIVE.getValue().compareTo(newStatus) != 0) {
...@@ -484,48 +542,6 @@ public class LearningCenterLevelExamService { ...@@ -484,48 +542,6 @@ public class LearningCenterLevelExamService {
return temp; return temp;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
levelExamLevelMapper.insertList(examLevelInsertList); levelExamLevelMapper.insertList(examLevelInsertList);
} else if (LevelExamStatusEnum.EFFECTIVE.getValue().compareTo(oldStatus) == 0) {
if (LevelExamStatusEnum.EFFECTIVE.getValue().compareTo(newStatus) != 0) {
log.info("等级考试状态错误 id:{}", levelExamId);
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级考试状态错误");
}
Integer examTime = request.getExamTime();
Integer oldExamTime = oldLevelExam.getExamTime();
if (examTime.compareTo(oldExamTime) != 0) {
repeatCheck(oldLevelExam.getBeisenExamId(), oldLevelExam.getDepartmentId(), oldLevelExam.getPositionCode(), examTime);
}
LearningCenterLevelExam updateExam = new LearningCenterLevelExam();
updateExam.setId(levelExamId);
updateExam.setExamTime(examTime);
updateExam.setUpdatedBy(updatedBy);
updateExam.setUpdatedDate(new Date());
levelExamMapper.updateByPrimaryKeySelective(updateExam);
} else if (LevelExamStatusEnum.INVALID.getValue().compareTo(oldStatus) == 0) {
if (LevelExamStatusEnum.INVALID.getValue().compareTo(newStatus) != 0
&& LevelExamStatusEnum.EFFECTIVE.getValue().compareTo(newStatus) != 0) {
log.info("等级考试状态错误 id:{}", levelExamId);
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级考试状态错误");
}
Integer examTime = request.getExamTime();
Integer oldExamTime = oldLevelExam.getExamTime();
if (examTime.compareTo(oldExamTime) != 0) {
repeatCheck(oldLevelExam.getBeisenExamId(), oldLevelExam.getDepartmentId(), oldLevelExam.getPositionCode(), request.getExamTime());
}
LearningCenterLevelExam updateExam = new LearningCenterLevelExam();
updateExam.setId(levelExamId);
updateExam.setExamTime(examTime);
updateExam.setStatus(newStatus);
updateExam.setUpdatedBy(updatedBy);
updateExam.setUpdatedDate(new Date());
levelExamMapper.updateByPrimaryKeySelective(updateExam);
} else {
log.info("等级考试原始状态错误 id:{}", levelExamId);
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级考试原始状态错误");
}
} }
public LevelExamDataOverviewDTO levelExamDataOverview(Integer id) { public LevelExamDataOverviewDTO levelExamDataOverview(Integer id) {
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

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

    问题描述: 在repeatCheck方法中,examTime参数的类型是Integer,但实际传入的值应该是Date或其他时间类型,这可能会导致比较逻辑不正确。此外,repeatCheck方法中的examTime比较逻辑存在问题,应该使用日期类型的比较而非整数比较。

    优化建议:

    • 将examTime参数的类型改为Date,并在调用repeatCheck方法的地方传入正确的日期对象。
    • 使用Date类型的比较方法来替代整数比较。

    问题描述: 在draftOrNotEffectiveUpdate方法中,存在重复的逻辑,特别是关于状态验证的部分。

    优化建议:

    • 提取重复的状态验证逻辑到一个单独的方法中,以提高代码的可读性和可维护性。

    2. 安全性与潜在风险(30分)

    问题描述: 代码中没有明显的SQL注入或XSS攻击的风险,但是需要确保beiSenOrganizationMapper.selectByPrimaryKey和levelExamMapper.updateByPrimaryKeySelective等数据库操作是安全的,即防止SQL注入。

    优化建议:

    • 确认所有数据库操作都使用了ORM框架提供的安全API,避免直接拼接SQL语句。

    3. 是否符合最佳实践(20分)

    问题描述:

    • 方法draftOrNotEffectiveUpdate的命名不够明确,虽然功能已经分离,但是方法名可以更具描述性。
    • repeatCheck方法的注释中,参数描述不够详细,应进一步说明参数的具体含义。

    优化建议:

    • 将方法draftOrNotEffectiveUpdate重命名为更具描述性的名称,例如updateDraftOrNotEffectiveLevelExam。
    • 增加对repeatCheck方法参数的详细描述。

    4. 性能与资源利用效率(5分)

    问题描述: 代码中没有明显的性能问题,但是多次调用BeanUtil.copyProperties和数据库操作可能会影响性能。

    优化建议:

    • 如果BeanUtil.copyProperties频繁调用,考虑使用更高效的工具或方法。
    • 对于数据库操作,可以考虑批量操作以减少数据库连接次数。

    5. Commits信息的清晰性与准确性(5分)

    问题描述: 提交信息“学习中心 优化代码,方法提取”较为笼统,无法明确知道具体优化的内容和方法提取的目的。

    优化建议:

    • 提交信息应更加具体,例如:“优化LearningCenterLevelExamService中的状态更新逻辑,提取重复代码至新方法draftOrNotEffectiveUpdate”。

    评分明细

    • 功能实现的正确性与健壮性:30/40 分
    • 安全性与潜在风险:28/30 分
    • 是否符合最佳实践:16/20 分
    • 性能与资源利用效率:4/5 分
    • Commits信息的清晰性与准确性:3/5 分

    总分

    总分:81分


    以上是对该代码变更的审查结果,希望上述建议能够帮助改进代码质量。如有任何疑问或需要进一步讨论的地方,请随时联系。

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