You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-cpt-java/src/main/java/com/glxp/api/task/AsyncDiDlTask.java

64 lines
2.2 KiB
Java

package com.glxp.api.task;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.req.system.ScheduledRequest;
import com.glxp.api.util.DateUtil;
import com.glxp.api.util.RedisUtil;
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 javax.annotation.Resource;
import java.util.Date;
@Component
@EnableScheduling
public class AsyncDiDlTask implements SchedulingConfigurer {
final Logger logger = LoggerFactory.getLogger(AsyncDiDlTask.class);
@Resource
RedisUtil redisUtil;
@Resource
private ScheduledDao scheduledDao;
@Resource
AsyncDiDlService asyncDiDlService;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.addTriggerTask(() -> process(),
triggerContext -> {
ScheduledRequest scheduledRequest = new ScheduledRequest();
scheduledRequest.setCronName("syncDi");
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
if (scheduledEntity == null) {
return null;
}
String cron = scheduledEntity.getCron();//"0 55 5 * * ?";
if (cron.isEmpty()) {
logger.error("cron is null");
}
return new CronTrigger(cron).nextExecutionTime(triggerContext);
});
}
private void process() {
String day = DateUtil.getLastDayFormat(-1);
asyncDiDlService.asyncDiByTime(day);
String lastUpDiTime = (String) redisUtil.get("lastDiUpTime");
if (lastUpDiTime == null) {
lastUpDiTime = DateUtil.getLastDayFormat(-10);
}
asyncDiDlService.asyncDiByTime(lastUpDiTime);
redisUtil.set("lastDiUpTime", DateUtil.formatDate(new Date()));
}
}