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.
77 lines
2.9 KiB
Java
77 lines
2.9 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.res.system.SyncDataSetResponse;
|
|
import com.glxp.api.service.basic.BasicBackUpdateProductService;
|
|
import com.glxp.api.service.sync.SpsSyncDownloadService;
|
|
import com.glxp.api.service.sync.SyncDataSetService;
|
|
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;
|
|
|
|
|
|
@Component
|
|
@EnableScheduling
|
|
public class AsyncHeartTask implements SchedulingConfigurer {
|
|
|
|
final Logger logger = LoggerFactory.getLogger(AsyncHeartTask.class);
|
|
@Resource
|
|
protected ScheduledDao scheduledDao;
|
|
@Resource
|
|
RedisUtil redisUtil;
|
|
@Resource
|
|
private SyncDataSetService syncDataSetService;
|
|
@Resource
|
|
SpsSyncDownloadService spsSyncDownloadService;
|
|
|
|
@Override
|
|
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
|
|
|
scheduledTaskRegistrar.addTriggerTask(() -> process(),
|
|
triggerContext -> {
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
scheduledRequest.setCronName("heartTask");
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
String cron = scheduledEntity.getCron();
|
|
if (cron.isEmpty()) {
|
|
logger.error("cron is null");
|
|
}
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
});
|
|
}
|
|
|
|
|
|
private void process() {
|
|
|
|
SyncDataSetResponse syncDataSetEntity = syncDataSetService.selectSet();
|
|
if (syncDataSetEntity.isDownstreamEnable()) {
|
|
|
|
//定时同步单据最近更新数据至任务表,等待下载
|
|
if (syncDataSetEntity.getOrderSyncTime() != null) {
|
|
long timeInterval = syncDataSetEntity.getOrderSyncTime() * 60 * 1000;
|
|
long curTime = System.currentTimeMillis();
|
|
Long lastTime = (Long) redisUtil.get("SPS_ORDER_SYNC_GEN_DATA");
|
|
if (lastTime == null) {
|
|
lastTime = System.currentTimeMillis();
|
|
redisUtil.set("SPS_ORDER_SYNC_GEN_DATA", lastTime);
|
|
}
|
|
if (curTime - lastTime > timeInterval) {
|
|
spsSyncDownloadService.syncOrderUpdateTime();
|
|
redisUtil.set("SPS_ORDER_SYNC_GEN_DATA", curTime);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|