package zbooksoft.fams.job; import com.ruili.wcp.common.SpringContextUtil; import com.ruili.wcp.data.entity.config.TaskLog; import com.ruili.wcp.service.config.TaskLogService; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import zbooksoft.fams.service.RemindService; import java.time.LocalDate; import java.util.Date; import java.util.Map; /** * 资产到期提醒定时任务:每天扫描质保、维保、检定/年检、借用到期,生成提醒并发系统消息。 * 由平台按「程序集.类名」反射装载,不是Spring Bean,依赖须用 SpringContextUtil 获取 * @author ycq * @date 2026-10-16 */ public class AssetRemindJob implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap map = context.getJobDetail().getJobDataMap(); Long taskId = map.containsKey("id") ? map.getLong("id") : null; String taskName = map.getString("taskName"); TaskLogService taskLogService = (TaskLogService) SpringContextUtil.getBean(TaskLogService.class); try { RemindService remindService = (RemindService) SpringContextUtil.getBean(RemindService.class); int daysAhead = remindService.daysAhead(); Map result = remindService.scan(LocalDate.now(), daysAhead); writeLog(taskLogService, taskId, taskName, "成功:提前" + daysAhead + "天,新增提醒" + result.get("created") + "条,刷新" + result.get("updated") + "条,失效" + result.get("expired") + "条,发送消息" + result.get("notified") + "条"); } catch (Exception e) { writeLog(taskLogService, taskId, taskName, "失败:" + e.getMessage()); throw new JobExecutionException(e); } } private static void writeLog(TaskLogService service, Long taskId, String taskName, String message) { TaskLog log = new TaskLog(); log.setTaskId(taskId); log.setTaskName(taskName); log.setAction("任务调度运行"); log.setOperateType("运行"); log.setMessage(message); log.setOperateTime(new Date()); service.saveOrUpdate(log); } }