|
|
|
package com.glxp.api.task;
|
|
|
|
|
|
|
|
import com.glxp.api.constant.BasicExportTypeEnum;
|
|
|
|
import com.glxp.api.dao.schedule.ScheduledDao;
|
|
|
|
import com.glxp.api.dao.system.SyncDataSetDao;
|
|
|
|
import com.glxp.api.entity.system.ScheduledEntity;
|
|
|
|
import com.glxp.api.entity.system.SyncDataSetEntity;
|
|
|
|
import com.glxp.api.req.system.ScheduledRequest;
|
|
|
|
import com.glxp.api.service.sync.HeartService;
|
|
|
|
import com.glxp.api.util.RedisUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
|
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.Arrays;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Component
|
|
|
|
@EnableScheduling
|
|
|
|
public class SyncHeartTask implements SchedulingConfigurer {
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
protected ScheduledDao scheduledDao;
|
|
|
|
@Resource
|
|
|
|
SyncHeartService syncHeartService;
|
|
|
|
@Resource
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
@Resource
|
|
|
|
HeartService heartService;
|
|
|
|
@Resource
|
|
|
|
private SyncDataSetDao syncDataSetDao;
|
|
|
|
|
|
|
|
@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()) {
|
|
|
|
log.error("cron is null");
|
|
|
|
}
|
|
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void process() {
|
|
|
|
log.info("数据同步心跳--");
|
|
|
|
syncHeartService.syncProcess();
|
|
|
|
|
|
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
|
|
if (!syncDataSetEntity.isDownstreamEnable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//定时下载上游最近更新数据轮询时间
|
|
|
|
long timeInterval = syncDataSetEntity.getSyncDownloadTime() * 6 * 1000;
|
|
|
|
long curTime = System.currentTimeMillis();
|
|
|
|
Long lastTime = (Long) redisUtil.get("SPS_SYNC_DOWNLOAD_DATA");
|
|
|
|
if (lastTime == null) {
|
|
|
|
lastTime = System.currentTimeMillis();
|
|
|
|
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", lastTime);
|
|
|
|
}
|
|
|
|
if (curTime - lastTime > timeInterval) {
|
|
|
|
syncHeartService.pullData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|