Commit d9230835 by 谢海旭

学习中心:课程培训计划-刷新培训人员完成状态定时任务、课程培训计划-监听完成等级考试的人员的mq消息,并推送培训计划

1 parent 49469ba7
...@@ -18,10 +18,10 @@ public class LevelExamDataOverviewDTO implements Serializable { ...@@ -18,10 +18,10 @@ public class LevelExamDataOverviewDTO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "已提交人数") @ApiModelProperty(notes = "已提交人数")
private int submitted = 0; private Integer submitted;
@ApiModelProperty(notes = "已提交人均得分") @ApiModelProperty(notes = "已提交人均得分")
private BigDecimal avg = BigDecimal.valueOf(0.00); private BigDecimal avg;
@ApiModelProperty(notes = "得分TOP10") @ApiModelProperty(notes = "得分TOP10")
private List<TopPersonDTO> topPersons; private List<TopPersonDTO> topPersons;
...@@ -53,13 +53,13 @@ public class LevelExamDataOverviewDTO implements Serializable { ...@@ -53,13 +53,13 @@ public class LevelExamDataOverviewDTO implements Serializable {
private String levelName; private String levelName;
@ApiModelProperty(notes = "最小分数") @ApiModelProperty(notes = "最小分数")
private int minScore; private Integer minScore;
@ApiModelProperty(notes = "最大分数") @ApiModelProperty(notes = "最大分数")
private int maxScore; private Integer maxScore;
@ApiModelProperty(notes = "人数") @ApiModelProperty(notes = "人数")
private int num; private Integer num;
@ApiModelProperty(notes = "占比百分比值") @ApiModelProperty(notes = "占比百分比值")
private BigDecimal proportion; private BigDecimal proportion;
......
package cn.com.glsx.dj.riskmanage.enums.learningcenter;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2025/12/3
**/
public enum TrainingPlanPersonOpenOrderStatusEnum {
LOCKED((byte)0, "已锁定"),
UNLOCKED((byte)1, "已解锁");
private Byte value;
private String desc;
TrainingPlanPersonOpenOrderStatusEnum(Byte value, String desc) {
this.value = value;
this.desc = desc;
}
public Byte getValue() {
return value;
}
public String getDesc() {
return desc;
}
public static TrainingPlanPersonOpenOrderStatusEnum getByValue(Byte value) {
for (TrainingPlanPersonOpenOrderStatusEnum item : values()) {
if (item.getValue().equals(value)) {
return item;
}
}
return null;
}
public static TrainingPlanPersonOpenOrderStatusEnum getByDesc(String desc) {
for (TrainingPlanPersonOpenOrderStatusEnum item : values()) {
if (item.getDesc().equals(desc)) {
return item;
}
}
return null;
}
}
package cn.com.glsx.dj.riskmanage.enums.learningcenter;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2025/12/3
**/
public enum TrainingPlanPersonOrderPermissionTypeEnum {
LOCK_PERMISSION((byte) 1, "锁定开单权限, 完成培训计划后开放"),
OPEN_PERMISSION((byte) 2, "开单权限已开放, 限时锁定");
private Byte value;
private String desc;
TrainingPlanPersonOrderPermissionTypeEnum(Byte value, String desc) {
this.value = value;
this.desc = desc;
}
public Byte getValue() {
return value;
}
public String getDesc() {
return desc;
}
public static TrainingPlanPersonOrderPermissionTypeEnum getByValue(Byte value) {
for (TrainingPlanPersonOrderPermissionTypeEnum item : values()) {
if (item.getValue().equals(value)) {
return item;
}
}
return null;
}
public static TrainingPlanPersonOrderPermissionTypeEnum getByDesc(String desc) {
for (TrainingPlanPersonOrderPermissionTypeEnum item : values()) {
if (item.getDesc().equals(desc)) {
return item;
}
}
return null;
}
}
...@@ -34,6 +34,12 @@ public class LearningCenterTrainingPlanPerson { ...@@ -34,6 +34,12 @@ public class LearningCenterTrainingPlanPerson {
private String personName; private String personName;
/** /**
* 等级考试-等级id
*/
@Column(name = "exam_level_id")
private Integer examLevelId;
/**
* 开单权限 (0:已锁定, 1:已解锁) * 开单权限 (0:已锁定, 1:已解锁)
*/ */
@Column(name = "open_order_status") @Column(name = "open_order_status")
......
package cn.com.glsx.dj.riskmanage.job.learningcenter;
import cn.com.glsx.dj.riskmanage.service.learningcenter.LearningCenterTrainingPlanPersonService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Title:
* @Description: 课程培训计划-刷新培训人员完成状态定时任务
* @Author xiehx
* @Date 2025/12/3
**/
@Service
@Slf4j
@ElasticJobConf(name = "RefreshTrainingPlanPersonCompletedJob", cron = "0 0/10 * * * ?", description = "课程培训计划-刷新培训人员完成状态定时任务", overwrite = false)
public class RefreshTrainingPlanPersonCompletedJob implements SimpleJob {
@Autowired
private LearningCenterTrainingPlanPersonService trainingPlanPersonService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("课程培训计划-刷新培训人员完成状态定时任务开始");
try {
trainingPlanPersonService.refreshCompleted();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("课程培训计划-刷新培训人员完成状态定时任务结束");
}
}
...@@ -8,4 +8,9 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper; ...@@ -8,4 +8,9 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper;
@Mapper @Mapper
public interface LearningCenterTrainingPlanPersonMapper extends OreMapper<LearningCenterTrainingPlanPerson> { public interface LearningCenterTrainingPlanPersonMapper extends OreMapper<LearningCenterTrainingPlanPerson> {
void invalidTrainingPlan(@Param("trainingPlanId") Integer trainingPlanId, @Param("updatedBy") String updatedBy); void invalidTrainingPlan(@Param("trainingPlanId") Integer trainingPlanId, @Param("updatedBy") String updatedBy);
/**
* 刷新培训计划人员完成状态
*/
void refreshCompleted();
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.riskmanage.mqlistener;
import cn.com.glsx.dj.riskmanage.config.KafkaTopicConfig;
import cn.com.glsx.dj.riskmanage.service.learningcenter.LearningCenterTrainingPlanService;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.jms.kafka.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Title:
* @Description: 完成等级考试 kafka消息消费
* @Author xiehx
* @Date 2025/12/3
**/
@Slf4j
@Component
public class LearningCenterLevelExamCompletionConsumer extends KafkaConsumer {
@Autowired
private LearningCenterTrainingPlanService trainingPlanService;
public LearningCenterLevelExamCompletionConsumer(@Autowired KafkaTopicConfig kafkaTopicConfig) {
super(kafkaTopicConfig.getLevelExamCompletionTopic(), false);
}
@Override
public void processMessage(Object o) {
String msg = new String(getMessage());
log.info("完成等级考试 kafka消息消费,处理开始,msg:{}", msg);
int levelExamPersonId = Integer.parseInt(msg);
try {
trainingPlanService.pushPlanToEmployees(levelExamPersonId);
} catch (Exception e) {
log.error("培训计划推送员工失败 levelExamPersonId:{}", levelExamPersonId, e);
}
log.info("完成等级考试 kafka消息消费,处理结束,msg:{}", msg);
}
}
...@@ -592,8 +592,6 @@ public class LearningCenterLevelExamService { ...@@ -592,8 +592,6 @@ public class LearningCenterLevelExamService {
scoreDistribution.setLevelName(level.getLevelName()); scoreDistribution.setLevelName(level.getLevelName());
scoreDistribution.setMinScore(level.getMinScore()); scoreDistribution.setMinScore(level.getMinScore());
scoreDistribution.setMaxScore(level.getMaxScore()); scoreDistribution.setMaxScore(level.getMaxScore());
scoreDistribution.setNum(0);
scoreDistribution.setProportion(BigDecimal.valueOf(0.00));
List<LearningCenterLevelExamPerson> levelPersons = levelPersonsMap.get(level.getId()); List<LearningCenterLevelExamPerson> levelPersons = levelPersonsMap.get(level.getId());
if (CollectionUtils.isNotEmpty(levelPersons)) { if (CollectionUtils.isNotEmpty(levelPersons)) {
...@@ -611,8 +609,6 @@ public class LearningCenterLevelExamService { ...@@ -611,8 +609,6 @@ public class LearningCenterLevelExamService {
scoreDistribution.setLevelName(level.getLevelName()); scoreDistribution.setLevelName(level.getLevelName());
scoreDistribution.setMinScore(level.getMinScore()); scoreDistribution.setMinScore(level.getMinScore());
scoreDistribution.setMaxScore(level.getMaxScore()); scoreDistribution.setMaxScore(level.getMaxScore());
scoreDistribution.setNum(0);
scoreDistribution.setProportion(BigDecimal.valueOf(0.00));
scoreDistributions.add(scoreDistribution); scoreDistributions.add(scoreDistribution);
} }
dto.setScoreDistributions(scoreDistributions); dto.setScoreDistributions(scoreDistributions);
......
...@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor; ...@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.util.*; import java.util.*;
...@@ -201,4 +202,12 @@ public class LearningCenterTrainingPlanPersonService { ...@@ -201,4 +202,12 @@ public class LearningCenterTrainingPlanPersonService {
criteria.andEqualTo("deletedFlag", DeleteFlagEnum.N.getValue()); criteria.andEqualTo("deletedFlag", DeleteFlagEnum.N.getValue());
return learningCenterTrainingPlanPersonMapper.selectByExample(example); return learningCenterTrainingPlanPersonMapper.selectByExample(example);
} }
/**
* 刷新培训计划人员完成状态
*/
@Transactional
public void refreshCompleted() {
learningCenterTrainingPlanPersonMapper.refreshCompleted();
}
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<result column="plan_id" property="planId" jdbcType="INTEGER" /> <result column="plan_id" property="planId" jdbcType="INTEGER" />
<result column="person_id" property="personId" jdbcType="INTEGER" /> <result column="person_id" property="personId" jdbcType="INTEGER" />
<result column="person_name" property="personName" jdbcType="VARCHAR" /> <result column="person_name" property="personName" jdbcType="VARCHAR" />
<result column="exam_level_id" property="examLevelId" jdbcType="INTEGER" />
<result column="open_order_status" property="openOrderStatus" jdbcType="TINYINT" /> <result column="open_order_status" property="openOrderStatus" jdbcType="TINYINT" />
<result column="is_completed" property="isCompleted" jdbcType="TINYINT" /> <result column="is_completed" property="isCompleted" jdbcType="TINYINT" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" /> <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
...@@ -21,11 +22,23 @@ ...@@ -21,11 +22,23 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, plan_id, person_id, person_name, open_order_status, is_completed, created_by, created_date, id, plan_id, person_id, person_name, exam_level_id, open_order_status, is_completed, created_by, created_date,
updated_by, updated_date, deleted_flag updated_by, updated_date, deleted_flag
</sql> </sql>
<update id="invalidTrainingPlan"> <update id="invalidTrainingPlan">
update dj_car_life_learning_center_training_plan_person set is_completed = 1, open_order_status = 1, updated_by = #{updatedBy}, updated_date = now() update dj_car_life_learning_center_training_plan_person set is_completed = 1, open_order_status = 1, updated_by = #{updatedBy}, updated_date = now()
where deleted_flag = 'N' and is_completed = 0 and plan_id = #{trainingPlanId} where deleted_flag = 'N' and is_completed = 0 and plan_id = #{trainingPlanId}
</update> </update>
<update id="refreshCompleted">
update dj_car_life_learning_center_training_plan_person tpp
inner join dj_car_life_learning_center_training_plan tp on tpp.plan_id = tp.id and tp.deleted_flag = 'N'
set tpp.is_completed = 1, tpp.open_order_status = 1, tpp.updated_by = 'Job', tpp.updated_date = now()
where tpp.deleted_flag = 'N' and tpp.is_completed = 0 and tp.status = 1
and not exists (
select 1 from dj_car_life_learning_center_training_plan_course tpc
left join dj_beisen_course_staff bcs on tpc.course_id = bcs.course_id and bcs.deleted_flag = 'N'
where tpc.deleted_flag = 'N' and tpc.plan_id = tp.id and tpc.exam_level_id = tpp.exam_level_id and tpc.type = 1
and bcs.learn_status != '50' and (bcs.user_id = tpp.person_id or bcs.user_id is null)
)
</update>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. LevelExamDataOverviewDTO 类

      • 问题:submitted 和 avg 字段由基本类型 int 和 BigDecimal 改为了包装类型 Integer 和 BigDecimal,但没有初始化,可能导致空指针异常。
      • 优化建议:建议在声明字段时进行初始化,或者在构造函数中进行初始化。 java private Integer submitted = 0; private BigDecimal avg = BigDecimal.ZERO;
    2. TrainingPlanPersonOpenOrderStatusEnum 和 TrainingPlanPersonOrderPermissionTypeEnum 枚举

      • 问题:getByValue 和 getByDesc 方法在找不到匹配项时返回 null,这可能导致调用者在使用返回值时需要额外的空值检查。
      • 优化建议:考虑抛出异常而不是返回 null,或者提供默认值。 java public static TrainingPlanPersonOpenOrderStatusEnum getByValue(Byte value) { for (TrainingPlanPersonOpenOrderStatusEnum item : values()) { if (item.getValue().equals(value)) { return item; } } throw new IllegalArgumentException("Unknown value: " + value); }
    3. LearningCenterLevelExamCompletionConsumer 类

      • 问题:processMessage 方法中将 getMessage() 转换为字符串,但未处理可能的 NumberFormatException。
      • 优化建议:增加异常处理,确保程序的健壮性。 java try { int levelExamPersonId = Integer.parseInt(msg); trainingPlanService.pushPlanToEmployees(levelExamPersonId); } catch (NumberFormatException e) { log.error("Invalid message format: {}", msg, e); } catch (Exception e) { log.error("Failed to process message: {}", msg, e); }
    4. LearningCenterTrainingPlanService 类

      • 问题:pushPlanToEmployees 方法中的 whiteListStr.split(",") 可能导致 NullPointerException 如果 whiteListStr 为空。
      • 优化建议:增加对 whiteListStr 的空值检查。 java if (StringUtils.isNotEmpty(whiteListStr)) { List<String> whiteList = Arrays.asList(whiteListStr.split(",")); List<Integer> whiteIdList = whiteList.stream().map(Integer::parseInt).collect(Collectors.toList()); if (whiteIdList.contains(examPerson.getPersonId())) { planPerson.setOpenOrderStatus(TrainingPlanPersonOpenOrderStatusEnum.UNLOCKED.getValue()); } }

    评分明细

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

      • LevelExamDataOverviewDTO 字段初始化问题扣 5 分。
      • getByValue 和 getByDesc 返回 null 问题扣 5 分。
      • processMessage 中缺少异常处理扣 5 分。
      • pushPlanToEmployees 中缺少空值检查扣 5 分。
      • 得分:20 分
    2. 安全性与潜在风险(30分)

      • 没有明显的安全漏洞,但 processMessage 中的 Integer.parseInt 可能抛出异常,需注意。
      • 得分:25 分
    3. 是否符合最佳实践(20分)

      • 注释和文档不足,部分方法缺少详细的注释。
      • 得分:15 分
    4. 性能与资源利用效率(5分)

      • 代码中没有明显的性能问题,但 pushPlanToEmployees 中的 whiteListStr.split(",") 可能会导致性能问题如果 whiteListStr 非常长。
      • 得分:4 分
    5. Commits信息的清晰性与准确性(5分)

      • 提交信息清晰,能够反映更改内容。
      • 得分:5 分

    总分:69分


    以上是针对提交代码的详细审查报告,希望对改进有所帮助。

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