From 8d5501c7c1753aeeead9934308f143c0cdce67f5 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 30 Mar 2023 11:13:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BAUDI=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/glxp/api/task/AsyncUdiTask.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/com/glxp/api/task/AsyncUdiTask.java diff --git a/src/main/java/com/glxp/api/task/AsyncUdiTask.java b/src/main/java/com/glxp/api/task/AsyncUdiTask.java new file mode 100644 index 000000000..4742af9f3 --- /dev/null +++ b/src/main/java/com/glxp/api/task/AsyncUdiTask.java @@ -0,0 +1,56 @@ +package com.glxp.api.task; + +import javax.annotation.Resource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Component; + +import com.glxp.api.dao.schedule.ScheduledDao; +import com.glxp.api.entity.system.ScheduledEntity; +import com.glxp.api.idc.service.IdcService; +import com.glxp.api.req.system.ScheduledRequest; + + + +@Component +@EnableScheduling +public class AsyncUdiTask implements SchedulingConfigurer { + + final Logger logger = LoggerFactory.getLogger(AsyncUdiTask.class); + + @Resource + private ScheduledDao scheduledDao; + + @Resource + private IdcService idcService; + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + scheduledTaskRegistrar.addTriggerTask(() -> process(), + triggerContext -> { + ScheduledRequest scheduledRequest = new ScheduledRequest(); + scheduledRequest.setCronName("syncIdcUdi"); + logger.info("syncIdcUdi----------------"); + ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); + String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "* 0/30 * * * ?"; + + if (cron.isEmpty()) { + logger.error("cron is null"); + } + logger.info("syncIdcUdi----------------"); + return new CronTrigger(cron).nextExecutionTime(triggerContext); + }); + } + + private void process() { + logger.info("syncIdcUdi----process------------"); + + idcService.asyncUdiTask(); + } + +}