| New file |
| | |
| | | package org.springblade.scheduled; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.modules.assessment.entity.AssessmentTaskEntity; |
| | | import org.springblade.modules.assessment.service.IAssessmentTaskService; |
| | | import org.springblade.modules.evaluate.entity.EvaluateTaskEntity; |
| | | import org.springblade.modules.evaluate.service.IEvaluateTaskService; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: zttj-java-boot |
| | | * @DESCRIPTION: 定时器模块 |
| | | * @USER: aix |
| | | * @DATE: 2024/1/5 14:39 |
| | | */ |
| | | @Component |
| | | @AllArgsConstructor |
| | | @Slf4j |
| | | public class ScheduledTasks { |
| | | |
| | | private final IAssessmentTaskService assessmentTaskService; |
| | | private final IEvaluateTaskService evaluateTaskService; |
| | | |
| | | |
| | | /** |
| | | * 第一个字段(秒):0 |
| | | * 第二个字段(分):0 |
| | | * 第三个字段(小时):0 |
| | | * 第四个字段(日期):*(任意日期) |
| | | * 第五个字段(月):*(任意月份) |
| | | * 第六个字段(星期):?(无指定) |
| | | */ |
| | | // @Scheduled(cron = "0 0 0 * * ?") // 每天的凌晨0点0分0秒执行任务 |
| | | @Scheduled(fixedRate = 1000*60*10) |
| | | public void doSomething() { |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("is_assessment_ok", 0); |
| | | queryWrapper.lt("end_time", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | List<AssessmentTaskEntity> assessmentTaskEntityList = assessmentTaskService.list(queryWrapper); |
| | | if (assessmentTaskEntityList.size() > 0) { |
| | | List<AssessmentTaskEntity> editList = assessmentTaskEntityList.stream() |
| | | .map(ate -> { |
| | | ate.setIsAssessmentOk(1); // 给每个Person对象的name属性设置新值 |
| | | return ate; // 返回修改后的对象 |
| | | }) |
| | | .collect(Collectors.toList()); // 收集流中的对象到一个新的列表中 |
| | | |
| | | assessmentTaskService.updateBatchById(editList); |
| | | |
| | | log.info("考核任务状态修改,修改数量为:" + assessmentTaskEntityList.size()); |
| | | } else |
| | | log.info("考核任务状态修改,修改数量为:0"); |
| | | } |
| | | |
| | | // @Scheduled(cron = "0 10 0 * * ?") // 每天的凌晨0点10分0秒执行任务 |
| | | @Scheduled(fixedRate = 1000*60*10) |
| | | public void evaluateDoSomething() { |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("candidate_state", 1); |
| | | queryWrapper.lt("candidate_cutoff_time_end", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | List<EvaluateTaskEntity> entities = evaluateTaskService.list(queryWrapper); |
| | | if (entities.size() > 0) { |
| | | List<EvaluateTaskEntity> editList = entities.stream() |
| | | .map(ate -> { |
| | | ate.setCandidateState(2); // 给每个Person对象的name属性设置新值 |
| | | return ate; // 返回修改后的对象 |
| | | }) |
| | | .collect(Collectors.toList()); // 收集流中的对象到一个新的列表中 |
| | | |
| | | evaluateTaskService.updateBatchById(editList); |
| | | |
| | | log.info("考核任务状态修改,修改数量为:" + entities.size()); |
| | | } else |
| | | log.info("考核任务状态修改,修改数量为:0"); |
| | | } |
| | | |
| | | } |