feat: add maintenance scheduler for preventive maintenance
This commit is contained in:
parent
ab777c748e
commit
8b5a002f3f
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.ether.pms.mdm.scheduler;
|
||||||
|
|
||||||
|
import com.ether.pms.mdm.entity.MaintenancePlan;
|
||||||
|
import com.ether.pms.mdm.service.MaintenancePlanService;
|
||||||
|
import com.ether.pms.mdm.service.MaintenanceTaskService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MaintenanceScheduler {
|
||||||
|
|
||||||
|
private final MaintenancePlanService maintenancePlanService;
|
||||||
|
private final MaintenanceTaskService maintenanceTaskService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查时间触发的维保计划 - 每天凌晨1点执行
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 1 * * ?")
|
||||||
|
public void checkTimeBasedMaintenance() {
|
||||||
|
log.info("开始检查时间触发的维保计划...");
|
||||||
|
try {
|
||||||
|
List<MaintenancePlan> plans = maintenancePlanService.getPlansByTriggerType(MaintenancePlan.TriggerType.TIME_BASED);
|
||||||
|
for (MaintenancePlan plan : plans) {
|
||||||
|
try {
|
||||||
|
maintenanceTaskService.generateTasksFromPlan(plan);
|
||||||
|
log.info("为计划[{}]生成维保任务完成", plan.getPlanCode());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("为计划[{}]生成维保任务失败: {}", plan.getPlanCode(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("时间触发维保计划检查完成,共处理 {} 个计划", plans.size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("检查时间触发维保计划失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查逾期任务 - 每小时执行
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 * * * ?")
|
||||||
|
public void checkOverdueTasks() {
|
||||||
|
log.info("开始检查逾期维保任务...");
|
||||||
|
try {
|
||||||
|
List<?> overdueTasks = maintenanceTaskService.getOverdueTasks();
|
||||||
|
if (!overdueTasks.isEmpty()) {
|
||||||
|
log.warn("发现 {} 个逾期维保任务", overdueTasks.size());
|
||||||
|
// 可以发送通知等后续处理
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("检查逾期维保任务失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,9 +3,11 @@ package com.ether.pms;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ComponentScan(basePackages = {"com.ether.pms"})
|
@ComponentScan(basePackages = {"com.ether.pms"})
|
||||||
|
@EnableScheduling
|
||||||
public class PmsApplication {
|
public class PmsApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue