优化,增加定时任务自动失效
parent
85018312e6
commit
c103d319ce
@ -0,0 +1,40 @@
|
|||||||
|
package com.supervision.knowsub.task;
|
||||||
|
|
||||||
|
import com.supervision.knowsub.dto.knowledge.CheckInvalidDTO;
|
||||||
|
import com.supervision.knowsub.enums.StatusEnum;
|
||||||
|
import com.supervision.knowsub.model.Knowledge;
|
||||||
|
import com.supervision.knowsub.service.KnowledgeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class InvalidCheckTask {
|
||||||
|
|
||||||
|
private final KnowledgeService knowledgeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务,每5分钟一次
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0/5 * * * ?")
|
||||||
|
public void checkInvalidKnowledge() {
|
||||||
|
log.info("定时任务,检查是否存在过期任务");
|
||||||
|
List<CheckInvalidDTO> checkInvalidDTOS = knowledgeService.queryKnowledgeInvalidList();
|
||||||
|
for (CheckInvalidDTO checkInvalidDTO : checkInvalidDTOS) {
|
||||||
|
// 校验当前时间是否超过了最大时间
|
||||||
|
if (LocalDateTime.now().isAfter(checkInvalidDTO.getExecTimeEnd())) {
|
||||||
|
log.info("标题:{},过期时间:{},目前已过期,标记为过期", checkInvalidDTO.getTitle(), checkInvalidDTO.getExecTimeEnd());
|
||||||
|
// 如果超过了当前时间,说明过期了
|
||||||
|
knowledgeService.lambdaUpdate().set(Knowledge::getStatus, StatusEnum.INVALID.getStatus())
|
||||||
|
.eq(Knowledge::getId, checkInvalidDTO.getKnowledgeId()).update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.supervision.knowsub.dto.knowledge;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CheckInvalidDTO {
|
||||||
|
|
||||||
|
private String knowledgeId;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
private Integer timeliness;
|
||||||
|
|
||||||
|
private Integer autoLoseEffect;
|
||||||
|
|
||||||
|
private LocalDateTime execTimeBegin;
|
||||||
|
|
||||||
|
private LocalDateTime execTimeEnd;
|
||||||
|
}
|
Loading…
Reference in New Issue