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.
126 lines
4.8 KiB
Java
126 lines
4.8 KiB
Java
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 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.Arrays;
|
|
|
|
|
|
@Component
|
|
@EnableScheduling
|
|
public class SyncHeartTask implements SchedulingConfigurer {
|
|
|
|
final Logger logger = LoggerFactory.getLogger(SyncHeartTask.class);
|
|
@Resource
|
|
protected ScheduledDao scheduledDao;
|
|
@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()) {
|
|
logger.error("cron is null");
|
|
}
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
});
|
|
}
|
|
|
|
|
|
private void process() {
|
|
|
|
logger.info("数据同步心跳");
|
|
//查询数据同步设置
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
if (syncDataSetEntity.isDownstreamEnable()) {
|
|
|
|
|
|
//定时上传最近更新基础数据至上游轮询时间
|
|
long timeInterval1 = syncDataSetEntity.getSyncTime() * 60 * 1000L;
|
|
long curTime1 = System.currentTimeMillis();
|
|
Long lastTime1 = (Long) redisUtil.get("SPS_SYNC_UPLOAD_DATA");
|
|
if (lastTime1 == null) {
|
|
lastTime1 = System.currentTimeMillis();
|
|
redisUtil.set("SPS_SYNC_UPLOAD_DATA", lastTime1);
|
|
}
|
|
try {
|
|
if (curTime1 - lastTime1 > timeInterval1) {
|
|
heartService.uploadAllBus(null);
|
|
heartService.uploadAllUserData(null);
|
|
// heartService.uploadScheduleList();
|
|
heartService.uploadThrData(null);
|
|
heartService.uploadThrProducts(null);
|
|
heartService.uploadSysSetting(null);
|
|
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
|
|
heartService.chooseData(syncDataSetEntity, null, i);
|
|
});
|
|
redisUtil.set("SPS_SYNC_UPLOAD_DATA", curTime1);
|
|
}
|
|
} catch (Exception e) {
|
|
}
|
|
|
|
|
|
//定时上传最近更新单据数据至上游轮询时间
|
|
long timeInterval2 = syncDataSetEntity.getOrderSyncTime() * 60 * 1000L;
|
|
long curTime2 = System.currentTimeMillis();
|
|
Long lastTime2 = (Long) redisUtil.get("SPS_SYNC_UPLOAD_ORDER");
|
|
if (lastTime2 == null) {
|
|
lastTime2 = System.currentTimeMillis();
|
|
redisUtil.set("SPS_SYNC_UPLOAD_ORDER", lastTime2);
|
|
}
|
|
if (curTime2 - lastTime2 > timeInterval2) {
|
|
heartService.uploadAllOrder(null);
|
|
heartService.uploadAllBusOrder(null);
|
|
redisUtil.set("SPS_SYNC_UPLOAD_ORDER", curTime2);
|
|
}
|
|
|
|
|
|
//定时下载上游最近更新数据轮询时间
|
|
long timeInterval = syncDataSetEntity.getSyncDownloadTime() * 60 * 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) {
|
|
heartService.dlAllOrder();
|
|
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
|
|
heartService.pullData(i);
|
|
});
|
|
// heartService.pullBasicData();
|
|
// heartService.pullOtherData();
|
|
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", curTime);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|