新建UDI同步任务
parent
e4721ef5b0
commit
8d5501c7c1
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue