瑞利声电固定资产管理系统
ycq
2026-10-16 dbbadb021c2fc171466cc82bd9a7a82cc47165f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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<String, Integer> 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);
    }
}