Commit b5c20a7a by 春觉晓

优化北森考试列表查询,员工考试结果分页查询逻辑

1 parent 46b5fb6c
......@@ -4,12 +4,13 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Data
public class TrainingPlanDetailDTO {
public class TrainingPlanDetailDTO implements Serializable {
/**
* 主键id
......
......@@ -481,7 +481,8 @@ public class LearningCenterCourseService {
//将学习时长 从单位秒转为小时,四舍五入,保留2位小时
studyDurationDetail.setDuration(studyDurationDetail.getDuration().divide(new BigDecimal(3600), 2, RoundingMode.HALF_UP));
if (employeeMap.containsKey(rowUserId)) {
studyDurationDetail.setUserName(employeeMap.get(rowUserId).getName());
//设置用户名称,只展示第一个字符,后续字符全部使用*代替
studyDurationDetail.setUserName(desensitizeUserName(employeeMap.get(rowUserId).getName()));
}
if (i < rankLimit) {
rankList.add(studyDurationDetail);
......@@ -497,4 +498,27 @@ public class LearningCenterCourseService {
return res;
}
/**
* 用户名脱敏:保留第一个字符,后续全部替换为*
* @param userName 原始用户名(支持空值、单字符、多字符)
* @return 脱敏后的用户名
*/
public String desensitizeUserName(String userName) {
// 1. 空值/空白处理:直接返回空字符串
if (StringUtils.isBlank(userName)) {
return "";
}
int len = userName.length();
if (len == 1) {
return userName;
}
// 用 StringBuilder 拼接,杜绝 null
StringBuilder sb = new StringBuilder();
sb.append(userName.charAt(0)); // 首字符
for (int i = 1; i < len; i++) {
sb.append("*"); // 逐个添加*
}
return sb.toString();
}
}
......@@ -25,6 +25,7 @@ import cn.com.glsx.dj.riskmanage.service.beisen.BeiSenOrganizationService;
import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListRequestDTO;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListResonseDTO;
......@@ -38,6 +39,7 @@ import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.oreframework.jms.kafka.producer.KafkaProducer;
import org.springframework.beans.BeanUtils;
......@@ -587,7 +589,9 @@ public class LearningCenterLevelExamService {
public LevelExamDataOverviewDTO levelExamDataOverview(Integer id) {
LevelExamDataOverviewDTO dto = new LevelExamDataOverviewDTO();
LevelExamDetailResponseDTO levelExamDetail = this.getLevelExamDetail(id);
if (levelExamDetail == null) {
throw new RpcServiceException(DefaultErrorEnum.DATA_NOT_EXIST, "等级考试不存在");
}
Example personQueryExample = new Example(LearningCenterLevelExamPerson.class);
personQueryExample.createCriteria()
.andEqualTo("examId", id)
......@@ -598,7 +602,9 @@ public class LearningCenterLevelExamService {
List<LevelExamLevelDTO> examLevel = levelExamDetail.getExamLevel();
if (CollectionUtils.isNotEmpty(persons)) {
dto.setSubmitted(persons.size());
BigDecimal avg = persons.stream().map(person -> person.getScore()).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(persons.size()), 2, RoundingMode.HALF_UP);
BigDecimal avg = persons.stream()
.filter(person -> person.getScore() != null)
.map(person -> person.getScore()).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(persons.size()), 2, RoundingMode.HALF_UP);
dto.setAvg(avg);
ArrayList<LevelExamDataOverviewDTO.TopPersonDTO> topPersons = new ArrayList<>();
......@@ -665,38 +671,56 @@ public class LearningCenterLevelExamService {
employeePageQuery.setCondition(employeePageCondition);
RpcResponse<RpcPagination<BeiSenEmployeeListResonseDTO>> beisenUserResp = merchantStaffRemote.getBeisenUserWithConditions(employeePageQuery);
if (beisenUserResp.hasError()) {
log.error("查询等级考试人员得分信息失败:{}", beisenUserResp.getMessage());
throw new RpcServiceException(beisenUserResp.getError(), beisenUserResp.getMessage());
}
if (beisenUserResp.getResult() == null || CollectionUtils.isEmpty(beisenUserResp.getResult().getList())) {
return new Page<>();
}
List<BeiSenEmployeeListResonseDTO> employeeList = beisenUserResp.getResult().getList();
Map<Integer, BeiSenEmployeeListResonseDTO> employeeInfoMap = employeeList.stream().collect(Collectors.toMap(BeiSenEmployeeListResonseDTO::getUserID, employee -> employee, (employee1, employee2) -> employee1));
// 查询部门信息
List<Integer> departmentIds = employeeList.stream().map(BeiSenEmployeeListResonseDTO::getOIdDepartmentId).distinct().collect(Collectors.toList());
Example orgExample = new Example(BeiSenOrganization.class);
orgExample.createCriteria().andIn("oId", departmentIds).andEqualTo("stdIsDeleted", false);
List<BeiSenOrganization> departmentList = beiSenOrganizationMapper.selectByExample(orgExample);
Map<Integer, BeiSenOrganization> orgMap = departmentList.stream().collect(Collectors.toMap(BeiSenOrganization::getOId, department -> department, (department1, department2) -> department1));
Map<Integer, BeiSenOrganization> orgMap = new HashMap<>();
List<Integer> departmentIds = employeeList.stream().filter(employee -> employee.getOIdDepartmentId() != null)
.map(BeiSenEmployeeListResonseDTO::getOIdDepartmentId).distinct().collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(departmentIds)) {
Example orgExample = new Example(BeiSenOrganization.class);
orgExample.createCriteria().andIn("oId", departmentIds).andEqualTo("stdIsDeleted", false);
List<BeiSenOrganization> departmentList = beiSenOrganizationMapper.selectByExample(orgExample);
if (CollectionUtil.isNotEmpty(departmentList)) {
orgMap = departmentList.stream().collect(Collectors.toMap(BeiSenOrganization::getOId, department -> department, (department1, department2) -> department1));
}
}
Map<String, BeiSenJobPost> jpMap = new HashMap<>();
// 查询职务信息
List<String> jobPostIds = employeeList.stream().map(BeiSenEmployeeListResonseDTO::getOIdJobPostId).distinct().collect(Collectors.toList());
Example jpExample = new Example(BeiSenJobPost.class);
jpExample.createCriteria().andIn("id", jobPostIds).andEqualTo("stdIsDeleted", false);
List<BeiSenJobPost> jpList = beiSenJobPostMapper.selectByExample(jpExample);
Map<String, BeiSenJobPost> jpMap = jpList.stream().collect(Collectors.toMap(BeiSenJobPost::getId, jobPost -> jobPost, (jobPost1, jobPost2) -> jobPost1));
List<String> jobPostIds = employeeList.stream().filter(employee -> StringUtils.isNotBlank(employee.getOIdJobPostId()))
.map(BeiSenEmployeeListResonseDTO::getOIdJobPostId).distinct().collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(jobPostIds)) {
List<BeiSenJobPost> jpList = beiSenJobPostMapper.selectJobPostByOId(jobPostIds);
if (CollectionUtil.isNotEmpty(jpList)) {
jpMap = jpList.stream().collect(Collectors.toMap(BeiSenJobPost::getOId, jobPost -> jobPost, (jobPost1, jobPost2) -> jobPost1));
}
}
// 结合人员标识再次查询考试人员
List<Integer> employeeIds = employeeList.stream().map(employee -> employee.getUserID()).collect(Collectors.toList());
condition.setPersonIds(employeeIds);
Page<LevelExamPersonDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(),pagination.isNeedCount());
levelExamPersonMapper.levelExamDataPersonPage(condition);
List<LevelExamPersonDTO> result = page.getResult();
for (LevelExamPersonDTO person : result) {
Integer personId = person.getPersonId();
BeiSenEmployeeListResonseDTO employee = employeeInfoMap.get(personId);
person.setDepartmentName(orgMap.get(employee.getOIdDepartmentId()).getName());
person.setJobPostName(jpMap.get(employee.getOIdJobPostId()).getName());
person.setZzStatus(employee.getZzStatus());
if (CollectionUtil.isNotEmpty(result)) {
for (LevelExamPersonDTO person : result) {
Integer personId = person.getPersonId();
BeiSenEmployeeListResonseDTO employee = employeeInfoMap.get(personId);
if (orgMap.containsKey(employee.getOIdDepartmentId())) {
person.setDepartmentName(orgMap.get(employee.getOIdDepartmentId()).getName());
}
if (jpMap.containsKey(employee.getOIdJobPostId())) {
person.setJobPostName(jpMap.get(employee.getOIdJobPostId()).getName());
}
person.setZzStatus(employee.getZzStatus());
}
}
return page;
}
......
......@@ -167,7 +167,6 @@
and bc.total_star &gt;= #{totalStar}
</if>
</where>
group by bc.id
<if test="sortType != null">
<choose>
<when test="sortType == 0">
......
......@@ -74,6 +74,7 @@
left join dj_beisen_organization o on e.organization = o.o_id and o.std_is_deleted = 0
where e.deleted_flag = 'N'
and e.exam_status = '20'
and e.source ='30'
and not exists (
select 1 from dj_car_life_learning_center_level_exam le where le.beisen_exam_id = e.id and le.status = 2 and
le.deleted_flag = 'N'
......
package cn.com.glsx.dj.riskmanage.service.learningcenter;
import cn.com.glsx.dj.riskmanage.dto.beisen.BeiSenExaminationDTO;
import cn.com.glsx.dj.riskmanage.dto.beisen.BeiSenJobPostDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamDataOverviewDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamDetailDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamPersonDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.TrainingPlanDetailDTO;
import cn.com.glsx.dj.riskmanage.service.BaseServiceTest;
import cn.com.glsx.dj.riskmanage.service.beisen.BeiSenJobPostService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class BeiSenExaminationServiceTest extends BaseServiceTest {
@Autowired
private BeiSenExaminationService beiSenExaminationService;
@Autowired
private BeiSenJobPostService beiSenJobPostService;
@Autowired
private LearningCenterLevelExamService learningCenterLevelExamService;
@Autowired
private LearningCenterTrainingPlanService learningCenterTrainingPlanService;
@Test
public void testBeiSenExaminationPage() {
RpcPagination<BeiSenExaminationDTO> pagination = new RpcPagination<>();
pagination.setPageNum(1);
pagination.setPageSize(10);
BeiSenExaminationDTO request = new BeiSenExaminationDTO();
pagination.setCondition(request);
//request.setTitle("小组考试");
Page<BeiSenExaminationDTO> res = beiSenExaminationService.beiSenExaminationPage(pagination);
log.info("res:{}", JSON.toJSONString(res));
}
@Test
public void testBeiSenJobPostPage() {
RpcPagination<BeiSenJobPostDTO> pagination = new RpcPagination<>();
pagination.setPageNum(1);
pagination.setPageSize(10);
BeiSenJobPostDTO request = new BeiSenJobPostDTO();
pagination.setCondition(request);
request.setName("高级Java工程师");
Page<BeiSenJobPostDTO> res = beiSenJobPostService.beiSenJobPostPage(pagination);
log.info("res:{}", JSON.toJSONString(res));
}
@Test
public void testDeleteLevelExam() {
LevelExamDetailDTO request = new LevelExamDetailDTO();
request.setId(1);
learningCenterLevelExamService.deleteLevelExam(request);
}
@Test
public void testLevelExamDataOverview() {
LevelExamDetailDTO request = new LevelExamDetailDTO();
request.setId(1);
LevelExamDataOverviewDTO overview = learningCenterLevelExamService.levelExamDataOverview(request.getId());
log.info("overview:{}", JSON.toJSONString(overview));
}
@Test
public void testLevelExamDataPersonPage() {
LevelExamPersonDTO request = new LevelExamPersonDTO();
request.setExamId(3);
RpcPagination<LevelExamPersonDTO> pagination = new RpcPagination<>();
pagination.setPageNum(1);
pagination.setPageSize(10);
pagination.setCondition(request);
Page<LevelExamPersonDTO> res = learningCenterLevelExamService.levelExamDataPersonPage(pagination);
log.info("res:{}", JSON.toJSONString(res));
}
@Test
public void testTrainingPlanDetail() {
TrainingPlanDetailDTO detail = learningCenterTrainingPlanService.trainingPlanDetail(7);
log.info("detail:{}", JSON.toJSONString(detail));
}
}
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. TrainingPlanDetailDTO 类的修改

    问题描述:

    • 在 TrainingPlanDetailDTO 类中增加了 Serializable 接口的实现。 优化建议:
    • 这是一个合理的修改,如果该类需要通过网络传输或者持久化存储,实现 Serializable 是必要的。但是,需要确保所有的字段都是可序列化的,否则在序列化过程中可能会抛出异常。
    • 如果没有明确的需求需要序列化,可以考虑不实现该接口,以减少不必要的依赖和潜在的问题。

    2. LearningCenterCourseService 类的修改

    问题描述:

    • 新增了 desensitizeUserName 方法,用于对用户名进行脱敏处理。 优化建议:
    • 该方法的实现是合理的,但可以进一步优化。例如,使用 StringBuilder 的 append 方法可以在循环外构造好 * 字符串,避免多次调用 append 方法。
    • 可以考虑将 StringUtils 的导入改为静态导入,这样可以减少代码量并提高可读性。
    • 建议添加单元测试来验证该方法的行为。

    3. LearningCenterLevelExamService 类的修改

    问题描述:

    • 新增了对 levelExamDetail 和 beisenUserResp 的空值检查,并添加了相应的异常处理。 优化建议:
    • 这些空值检查和异常处理是必要的,可以有效防止空指针异常和其他运行时错误。
    • 对于数据库查询的结果,应该考虑是否有可能返回 null 或者空集合,并根据实际情况进行处理。
    • 在日志记录中,建议添加更多的上下文信息,以便更好地调试和监控系统。

    4. 新增测试类 BeiSenExaminationServiceTest

    问题描述:

    • 新增了测试类 BeiSenExaminationServiceTest,其中包含了多个测试方法。 优化建议:
    • 测试类的创建是一个很好的做法,可以帮助保证代码的质量和稳定性。
    • 每个测试方法应该只测试一个功能点,以提高测试的可读性和可维护性。
    • 建议为每个测试方法添加详细的注释,说明测试的目的和预期结果。

    评分明细

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

      • 修改合理,实现了必要的空值检查和异常处理。
      • 新增的测试类有助于提高代码的健壮性。
      • 评分: 38分
    2. 安全性与潜在风险 (30分):

      • 没有明显的安全漏洞,但需要确保所有字段都是可序列化的。
      • 增加了用户名脱敏处理,提高了数据的安全性。
      • 评分: 28分
    3. 是否符合最佳实践 (20分):

      • 实现了 Serializable 接口,但需要确保所有字段都是可序列化的。
      • 使用了 Lombok 的 @Data 注解,减少了样板代码。
      • 添加了详细的注释,但可以进一步优化。
      • 评分: 18分
    4. 性能与资源利用效率 (5分):

      • 代码中没有明显的性能问题,但可以进一步优化字符串拼接和数据库查询。
      • 评分: 4分
    5. Commits信息的清晰性与准确性 (5分):

      • 提交信息不够详细,建议添加具体的修改内容和目的。
      • 评分: 3分

    总分: 91分


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

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