Commit 051409b7 by 叶立庆

增强非空校验

1 parent ff19095a
package cn.com.glsx.dj.riskmanage.service.learningcenter; package cn.com.glsx.dj.riskmanage.service.learningcenter;
import cn.com.glsx.dj.riskmanage.config.KafkaTopicConfig; import cn.com.glsx.dj.riskmanage.config.KafkaTopicConfig;
import cn.com.glsx.dj.riskmanage.dto.beisen.BeisenEmployeeInfoDTO;
import cn.com.glsx.dj.riskmanage.dto.beisen.OrganizationListResponseDTO; import cn.com.glsx.dj.riskmanage.dto.beisen.OrganizationListResponseDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.*; import cn.com.glsx.dj.riskmanage.dto.learningcenter.*;
import cn.com.glsx.dj.riskmanage.enums.RiskmanageErrorEnum; import cn.com.glsx.dj.riskmanage.enums.RiskmanageErrorEnum;
...@@ -36,7 +35,6 @@ import cn.hutool.core.date.DateUtil; ...@@ -36,7 +35,6 @@ import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -96,7 +94,7 @@ public class LearningCenterLevelExamService { ...@@ -96,7 +94,7 @@ public class LearningCenterLevelExamService {
LevelExamPageListRequestDTO condition = pagination.getCondition(); LevelExamPageListRequestDTO condition = pagination.getCondition();
//递归查询组织机构树,填充查询条件DepartmentIds //递归查询组织机构树,填充查询条件DepartmentIds
fillConditionDepartmentIds(condition); fillConditionDepartmentIds(condition);
Page<LevelExamPageListResponseDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(),pagination.isNeedCount()); Page<LevelExamPageListResponseDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(), pagination.isNeedCount());
List<LevelExamPageListResponseDTO> responseDTOS = levelExamMapper.levelExamListPage(condition); List<LevelExamPageListResponseDTO> responseDTOS = levelExamMapper.levelExamListPage(condition);
//填充考试等级 //填充考试等级
fillExamLevel(responseDTOS); fillExamLevel(responseDTOS);
...@@ -145,7 +143,7 @@ public class LearningCenterLevelExamService { ...@@ -145,7 +143,7 @@ public class LearningCenterLevelExamService {
} }
public LevelExamDetailResponseDTO getLevelExamDetail(Integer id) { public LevelExamDetailResponseDTO getLevelExamDetail(Integer id) {
if(id == null) { if (id == null) {
return null; return null;
} }
LearningCenterLevelExam learningCenterLevelExam = levelExamMapper.selectByPrimaryKey(id); LearningCenterLevelExam learningCenterLevelExam = levelExamMapper.selectByPrimaryKey(id);
...@@ -291,7 +289,7 @@ public class LearningCenterLevelExamService { ...@@ -291,7 +289,7 @@ public class LearningCenterLevelExamService {
levelExamLevelMapper.updateLevelExamTakeEffect(); levelExamLevelMapper.updateLevelExamTakeEffect();
} }
@GlsxDistributeLockable(name="'LearningCenterLevelExamService_levelExamStatusToggle_' + #request.id", timeoutException=RpcServiceException.class) @GlsxDistributeLockable(name = "'LearningCenterLevelExamService_levelExamStatusToggle_' + #request.id", timeoutException = RpcServiceException.class)
@Transactional @Transactional
public void levelExamStatusToggle(LevelExamDetailDTO request) { public void levelExamStatusToggle(LevelExamDetailDTO request) {
Integer id = request.getId(); Integer id = request.getId();
...@@ -348,7 +346,7 @@ public class LearningCenterLevelExamService { ...@@ -348,7 +346,7 @@ public class LearningCenterLevelExamService {
* *
* @param levelExamId * @param levelExamId
*/ */
@GlsxDistributeLockable(name="'LearningCenterLevelExamService_pushExamToEmployees_' + #levelExamId", timeoutException=RpcServiceException.class) @GlsxDistributeLockable(name = "'LearningCenterLevelExamService_pushExamToEmployees_' + #levelExamId", timeoutException = RpcServiceException.class)
@Transactional @Transactional
public void pushExamToEmployees(int levelExamId) { public void pushExamToEmployees(int levelExamId) {
LearningCenterLevelExam levelExam = levelExamMapper.selectByPrimaryKey(levelExamId); LearningCenterLevelExam levelExam = levelExamMapper.selectByPrimaryKey(levelExamId);
...@@ -398,7 +396,8 @@ public class LearningCenterLevelExamService { ...@@ -398,7 +396,8 @@ public class LearningCenterLevelExamService {
Date entryDate = employee.getEntryDate(); Date entryDate = employee.getEntryDate();
return DateUtil.betweenDay(entryDate, new Date(), true) == examTime.longValue(); return DateUtil.betweenDay(entryDate, new Date(), true) == examTime.longValue();
}).collect(Collectors.toList()); }).collect(Collectors.toList());
List<LearningCenterLevelExamPerson> existPersonList = new ArrayList<>();
if (!employees.isEmpty()) {
Set<Integer> userIds = employees.stream().map(BeiSenEmployeeListResonseDTO::getUserID).collect(Collectors.toSet()); Set<Integer> userIds = employees.stream().map(BeiSenEmployeeListResonseDTO::getUserID).collect(Collectors.toSet());
Example pushedQueryExample = new Example(LearningCenterLevelExamPerson.class); Example pushedQueryExample = new Example(LearningCenterLevelExamPerson.class);
Example.Criteria pushedQueryCriteria = pushedQueryExample.createCriteria(); Example.Criteria pushedQueryCriteria = pushedQueryExample.createCriteria();
...@@ -406,7 +405,8 @@ public class LearningCenterLevelExamService { ...@@ -406,7 +405,8 @@ public class LearningCenterLevelExamService {
.andEqualTo("examId", levelExamId) .andEqualTo("examId", levelExamId)
.andIn("personId", userIds) .andIn("personId", userIds)
.andEqualTo("deletedFlag", BaseModel.DeletedFlagEnum.N.name()); .andEqualTo("deletedFlag", BaseModel.DeletedFlagEnum.N.name());
List<LearningCenterLevelExamPerson> existPersonList = levelExamPersonMapper.selectByExample(pushedQueryExample); existPersonList = levelExamPersonMapper.selectByExample(pushedQueryExample);
}
if (CollectionUtils.isNotEmpty(existPersonList)) { if (CollectionUtils.isNotEmpty(existPersonList)) {
Set<Integer> existPersonIds = existPersonList.stream().map(LearningCenterLevelExamPerson::getPersonId).collect(Collectors.toSet()); Set<Integer> existPersonIds = existPersonList.stream().map(LearningCenterLevelExamPerson::getPersonId).collect(Collectors.toSet());
employees = employees.stream() employees = employees.stream()
...@@ -416,7 +416,9 @@ public class LearningCenterLevelExamService { ...@@ -416,7 +416,9 @@ public class LearningCenterLevelExamService {
String created_by = "system"; String created_by = "system";
Date createdDate = new Date(); Date createdDate = new Date();
List<LearningCenterLevelExamPerson> personInsertList = employees.stream() List<LearningCenterLevelExamPerson> personInsertList = new ArrayList<>();
if (!employees.isEmpty()) {
personInsertList = employees.stream()
.map(employee -> { .map(employee -> {
LearningCenterLevelExamPerson person = new LearningCenterLevelExamPerson(); LearningCenterLevelExamPerson person = new LearningCenterLevelExamPerson();
person.setExamId(levelExamId); person.setExamId(levelExamId);
...@@ -430,6 +432,7 @@ public class LearningCenterLevelExamService { ...@@ -430,6 +432,7 @@ public class LearningCenterLevelExamService {
person.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name()); person.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
return person; return person;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
}
if (CollectionUtils.isNotEmpty(personInsertList)) { if (CollectionUtils.isNotEmpty(personInsertList)) {
levelExamPersonMapper.insertList(personInsertList); levelExamPersonMapper.insertList(personInsertList);
...@@ -708,7 +711,7 @@ public class LearningCenterLevelExamService { ...@@ -708,7 +711,7 @@ public class LearningCenterLevelExamService {
// 结合人员标识再次查询考试人员 // 结合人员标识再次查询考试人员
List<Integer> employeeIds = employeeList.stream().map(employee -> employee.getUserID()).collect(Collectors.toList()); List<Integer> employeeIds = employeeList.stream().map(employee -> employee.getUserID()).collect(Collectors.toList());
condition.setPersonIds(employeeIds); condition.setPersonIds(employeeIds);
Page<LevelExamPersonDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(),pagination.isNeedCount()); Page<LevelExamPersonDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(), pagination.isNeedCount());
levelExamPersonMapper.levelExamDataPersonPage(condition); levelExamPersonMapper.levelExamDataPersonPage(condition);
List<LevelExamPersonDTO> result = page.getResult(); List<LevelExamPersonDTO> result = page.getResult();
if (CollectionUtil.isNotEmpty(result)) { if (CollectionUtil.isNotEmpty(result)) {
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 代码格式与一致性

      • 问题:部分代码缩进不一致,影响可读性。
      • 优化建议:统一代码缩进格式,推荐使用4个空格或一个Tab键。
    2. 异常处理

      • 问题:getLevelExamDetail 方法中,如果传入的 id 为 null,直接返回 null,没有抛出异常或日志记录。
      • 优化建议:建议在 id 为 null 时抛出自定义异常,或者至少记录一条日志,以便于调试和维护。
    3. 潜在的安全风险

      • 问题:未看到明显的SQL注入风险,但repeatCheck方法中使用了Example对象进行条件构造,如果参数构造不当,存在SQL注入的风险。
      • 优化建议:确保所有参数通过ORM框架提供的方法进行安全绑定,避免手动拼接SQL语句。
    4. 代码重复

      • 问题:pushExamToEmployees方法中,existPersonList 和 personInsertList 的构建逻辑存在重复。
      • 优化建议:可以将这部分逻辑提取到一个单独的方法中,减少代码重复,提高代码复用性。
    5. 提交信息

      • 问题:提交信息“增强非空校验”过于简单,无法明确了解具体的修改内容。
      • 优化建议:提交信息应更详细,描述具体修改的内容和原因,例如:“增加对员工ID的非空校验,优化pushExamToEmployees方法中的逻辑”。

    评分明细

    1. 功能实现的正确性与健壮性(40分):35分。代码逻辑基本正确,但在异常处理和日志记录方面需要改进。
    2. 安全性与潜在风险(30分):25分。未发现明显的安全漏洞,但需要注意Example对象的使用。
    3. 是否符合最佳实践(20分):15分。代码格式和结构需要改进,存在代码重复。
    4. 性能与资源利用效率(5分):5分。未发现明显的性能问题。
    5. Commits信息的清晰性与准确性(5分):2分。提交信息不够详细。

    总分: 82分


    希望以上建议能帮助改进代码质量。如有任何疑问或需要进一步讨论,请随时联系。

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