Commit eb97f252 by 春觉晓

优化课程培训计划查询逻辑

1 parent f9257f59
package cn.com.glsx.dj.riskmanage.dto.learningcenter; package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamLevel;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -110,4 +111,6 @@ public class TrainingPlanDetailDTO implements Serializable { ...@@ -110,4 +111,6 @@ public class TrainingPlanDetailDTO implements Serializable {
@ApiModelProperty(notes = "白名单名称列表") @ApiModelProperty(notes = "白名单名称列表")
private List<String> whiteNameList; private List<String> whiteNameList;
@ApiModelProperty(notes = "等级考试信息")
List<LearningCenterLevelExamLevel> levelExamLevels;
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.riskmanage.model.learningcenter; package cn.com.glsx.dj.riskmanage.model.learningcenter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.persistence.*; import javax.persistence.*;
...@@ -11,6 +12,7 @@ public class LearningCenterLevelExamLevel { ...@@ -11,6 +12,7 @@ public class LearningCenterLevelExamLevel {
/** /**
* 主键id * 主键id
*/ */
@ApiModelProperty(notes = "等级id")
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id; private Integer id;
...@@ -24,6 +26,7 @@ public class LearningCenterLevelExamLevel { ...@@ -24,6 +26,7 @@ public class LearningCenterLevelExamLevel {
/** /**
* 等级名称 * 等级名称
*/ */
@ApiModelProperty(notes = "等级名称")
@Column(name = "level_name") @Column(name = "level_name")
private String levelName; private String levelName;
......
...@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param; ...@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
@Mapper @Mapper
public interface LearningCenterLevelExamLevelMapper extends OreMapper<LearningCenterLevelExamLevel> { public interface LearningCenterLevelExamLevelMapper extends OreMapper<LearningCenterLevelExamLevel> {
...@@ -22,4 +23,6 @@ public interface LearningCenterLevelExamLevelMapper extends OreMapper<LearningCe ...@@ -22,4 +23,6 @@ public interface LearningCenterLevelExamLevelMapper extends OreMapper<LearningCe
* @return * @return
*/ */
LearningCenterLevelExamLevel getScoreLevel(@Param("examId") Integer examId, @Param("score") BigDecimal score); LearningCenterLevelExamLevel getScoreLevel(@Param("examId") Integer examId, @Param("score") BigDecimal score);
List<LearningCenterLevelExamLevel> listLevelExamLevel(@Param("list") List<Integer> examIdList);
} }
\ No newline at end of file \ No newline at end of file
...@@ -112,10 +112,13 @@ public class LearningCenterTrainingPlanService { ...@@ -112,10 +112,13 @@ public class LearningCenterTrainingPlanService {
BeiSenEmployeeListRequestDTO employeePageCondition = new BeiSenEmployeeListRequestDTO(); BeiSenEmployeeListRequestDTO employeePageCondition = new BeiSenEmployeeListRequestDTO();
employeePageCondition.setEmployeeName(condition.getName()); employeePageCondition.setEmployeeName(condition.getName());
employeePageCondition.setMobilePhone(condition.getMobilePhone()); employeePageCondition.setMobilePhone(condition.getMobilePhone());
if (condition.getOldDepartmentId() != null) {
employeePageCondition.setOIdDepartmentIds(Lists.newArrayList(condition.getOldDepartmentId())); employeePageCondition.setOIdDepartmentIds(Lists.newArrayList(condition.getOldDepartmentId()));
}
if (StringUtils.isNotBlank(condition.getOIdJobPostId())) {
employeePageCondition.setOIdJobPostIds(Lists.newArrayList(condition.getOIdJobPostId())); employeePageCondition.setOIdJobPostIds(Lists.newArrayList(condition.getOIdJobPostId()));
}
employeePageCondition.setStatus(condition.getZzStatus()); employeePageCondition.setStatus(condition.getZzStatus());
employeePageQuery.setCondition(employeePageCondition); employeePageQuery.setCondition(employeePageCondition);
RpcResponse<RpcPagination<BeiSenEmployeeListResonseDTO>> beisenUserResp = merchantStaffRemote.getBeisenUserWithConditions(employeePageQuery); RpcResponse<RpcPagination<BeiSenEmployeeListResonseDTO>> beisenUserResp = merchantStaffRemote.getBeisenUserWithConditions(employeePageQuery);
if (!beisenUserResp.hasResult()) { if (!beisenUserResp.hasResult()) {
...@@ -126,20 +129,28 @@ public class LearningCenterTrainingPlanService { ...@@ -126,20 +129,28 @@ public class LearningCenterTrainingPlanService {
List<BeiSenEmployeeDTO> beiSenEmployeeDTOS = result.getList().stream().map(item -> BeanUtil.copyProperties(item, BeiSenEmployeeDTO.class)).collect(Collectors.toList()); List<BeiSenEmployeeDTO> beiSenEmployeeDTOS = result.getList().stream().map(item -> BeanUtil.copyProperties(item, BeiSenEmployeeDTO.class)).collect(Collectors.toList());
// 查询部门信息 // 查询部门信息
List<Integer> departmentIds = beiSenEmployeeDTOS.stream().map(BeiSenEmployeeDTO::getOldDepartmentId).distinct().collect(Collectors.toList()); Map<Integer, BeiSenOrganization> orgMap = new HashMap<>();
List<Integer> departmentIds = beiSenEmployeeDTOS.stream().filter(x -> x.getOldDepartmentId() != null).map(BeiSenEmployeeDTO::getOldDepartmentId).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(departmentIds)) {
Example orgExample = new Example(BeiSenOrganization.class); Example orgExample = new Example(BeiSenOrganization.class);
orgExample.createCriteria().andIn("oId", departmentIds).andEqualTo("stdIsDeleted", false); orgExample.createCriteria().andIn("oId", departmentIds).andEqualTo("stdIsDeleted", false);
List<BeiSenOrganization> departmentList = beiSenOrganizationMapper.selectByExample(orgExample); List<BeiSenOrganization> departmentList = beiSenOrganizationMapper.selectByExample(orgExample);
Map<Integer, BeiSenOrganization> orgMap = departmentList.stream().collect(Collectors.toMap(BeiSenOrganization::getOId, department -> department, (department1, department2) -> department1)); if (CollectionUtils.isNotEmpty(departmentList)) {
orgMap = departmentList.stream().collect(Collectors.toMap(BeiSenOrganization::getOId, department -> department, (department1, department2) -> department1));
}
}
// 查询职务信息 // 查询职务信息
List<String> jobPostIds = beiSenEmployeeDTOS.stream().map(BeiSenEmployeeDTO::getOIdJobPostId).distinct().collect(Collectors.toList()); Map<String, BeiSenJobPost> jpMap = new HashMap<>();
List<String> jobPostIds = beiSenEmployeeDTOS.stream().filter(x -> StringUtils.isNotBlank(x.getOIdJobPostId())).map(BeiSenEmployeeDTO::getOIdJobPostId).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(jobPostIds)) {
Example jpExample = new Example(BeiSenJobPost.class); Example jpExample = new Example(BeiSenJobPost.class);
jpExample.createCriteria().andIn("id", jobPostIds).andEqualTo("stdIsDeleted", false); jpExample.createCriteria().andIn("id", jobPostIds).andEqualTo("stdIsDeleted", false);
List<BeiSenJobPost> jpList = beiSenJobPostMapper.selectByExample(jpExample); List<BeiSenJobPost> jpList = beiSenJobPostMapper.selectByExample(jpExample);
Map<String, BeiSenJobPost> jpMap = jpList.stream().collect(Collectors.toMap(BeiSenJobPost::getId, jobPost -> jobPost, (jobPost1, jobPost2) -> jobPost1)); if (CollectionUtils.isNotEmpty(jpList)) {
jpMap = jpList.stream().collect(Collectors.toMap(BeiSenJobPost::getId, jobPost -> jobPost, (jobPost1, jobPost2) -> jobPost1));
beiSenEmployeeDTOS.forEach(beiSenEmployeeDTO -> { }
}
for (BeiSenEmployeeDTO beiSenEmployeeDTO : beiSenEmployeeDTOS) {
BeiSenOrganization department = orgMap.get(beiSenEmployeeDTO.getOldDepartmentId()); BeiSenOrganization department = orgMap.get(beiSenEmployeeDTO.getOldDepartmentId());
if (department != null) { if (department != null) {
beiSenEmployeeDTO.setOldDepartmentName(department.getName()); beiSenEmployeeDTO.setOldDepartmentName(department.getName());
...@@ -148,7 +159,7 @@ public class LearningCenterTrainingPlanService { ...@@ -148,7 +159,7 @@ public class LearningCenterTrainingPlanService {
if (jobPost != null) { if (jobPost != null) {
beiSenEmployeeDTO.setOIdJobPostName(jobPost.getName()); beiSenEmployeeDTO.setOIdJobPostName(jobPost.getName());
} }
}); }
page.addAll(beiSenEmployeeDTOS); page.addAll(beiSenEmployeeDTOS);
return page; return page;
} }
...@@ -341,6 +352,10 @@ public class LearningCenterTrainingPlanService { ...@@ -341,6 +352,10 @@ public class LearningCenterTrainingPlanService {
detailDTO.setCourseMap(dtoCourseMap); detailDTO.setCourseMap(dtoCourseMap);
Map<Integer, List<LearningCenterTrainingPlanCourse>> levelMap = courses.stream().collect(Collectors.groupingBy(LearningCenterTrainingPlanCourse::getExamLevelId)); Map<Integer, List<LearningCenterTrainingPlanCourse>> levelMap = courses.stream().collect(Collectors.groupingBy(LearningCenterTrainingPlanCourse::getExamLevelId));
//根据等级id 查询等级列表
List<Integer> levelIds = levelMap.keySet().stream().collect(Collectors.toList());
List<LearningCenterLevelExamLevel> levelExamLevels = levelExamLevelMapper.listLevelExamLevel(levelIds);
detailDTO.setLevelExamLevels(levelExamLevels);
for (Map.Entry<Integer, List<LearningCenterTrainingPlanCourse>> levelEntry : levelMap.entrySet()) { for (Map.Entry<Integer, List<LearningCenterTrainingPlanCourse>> levelEntry : levelMap.entrySet()) {
Integer levelKey = levelEntry.getKey(); Integer levelKey = levelEntry.getKey();
HashMap<Byte, List<TrainingPlanCourseDetailDTO>> dtoTypeMap = new HashMap<>(); HashMap<Byte, List<TrainingPlanCourseDetailDTO>> dtoTypeMap = new HashMap<>();
......
...@@ -34,4 +34,14 @@ ...@@ -34,4 +34,14 @@
FROM dj_car_life_learning_center_level_exam_level FROM dj_car_life_learning_center_level_exam_level
where deleted_flag = 'N' and exam_id = #{examId} and min_score &lt;= #{score} and max_score >= #{score} where deleted_flag = 'N' and exam_id = #{examId} and min_score &lt;= #{score} and max_score >= #{score}
</select> </select>
<select id="listLevelExamLevel" resultMap="BaseResultMap">
SELECT
*
FROM dj_car_life_learning_center_level_exam_level
where deleted_flag = 'N' and id in
<foreach collection="list" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性:

      • 问题:在LearningCenterTrainingPlanService中,对condition.getOldDepartmentId()和condition.getOIdJobPostId()的空值检查是正确的,但可以进一步优化以提高代码可读性和健壮性。
      • 优化建议:使用Optional来处理可能为空的对象,这可以使代码更加简洁和易于理解。
    2. 安全性与潜在风险:

      • 问题:目前没有明显的安全漏洞,但是LearningCenterTrainingPlanService中的数据库查询存在潜在的风险,如果beiSenEmployeeDTOS列表很大,可能会导致大量的数据库查询。
      • 优化建议:考虑使用批量查询来减少数据库操作次数,或者使用缓存机制来减少重复查询。
    3. 是否符合最佳实践:

      • 问题:新增的@ApiModelProperty注解提升了API文档的可用性,但是部分变量命名可以更具有描述性。
      • 优化建议:确保所有变量名都具有明确的含义,避免使用缩写,除非它是广泛认可的。
    4. 性能与资源利用效率:

      • 问题:在LearningCenterTrainingPlanService中,多次调用stream().collect()可能会导致性能下降,特别是在数据量较大的情况下。
      • 优化建议:考虑使用中间集合来存储中间结果,或者使用更高效的流操作方式来减少不必要的计算。
    5. Commits信息的清晰性与准确性:

      • 问题:提交信息“优化课程培训计划查询逻辑”虽然简明,但不够详细,无法清楚地传达具体的更改内容。
      • 优化建议:提供更详细的提交信息,例如:“增加对部门ID和职位ID的空值检查,优化部门和职位信息查询逻辑”。

    评分明细

    1. 功能实现的正确性与健壮性(40分):35分
    2. 安全性与潜在风险(30分):25分
    3. 是否符合最佳实践(20分):18分
    4. 性能与资源利用效率(5分):3分
    5. Commits信息的清晰性与准确性(5分):3分

    总分

    总分:84分


    通过以上审查,可以看到该代码整体质量良好,但在功能健壮性、性能优化以及提交信息的详细程度上还有提升空间。希望这些建议能够帮助改进代码质量。

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