|
|
|
package com.glxp.api.task;
|
|
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
import com.glxp.api.constant.BasicExportTypeEnum;
|
|
|
|
import com.glxp.api.dao.system.SyncDataSetDao;
|
|
|
|
import com.glxp.api.entity.system.SyncDataSetEntity;
|
|
|
|
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.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
public class SyncHeartService {
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
@Resource
|
|
|
|
HeartService heartService;
|
|
|
|
@Resource
|
|
|
|
private SyncDataSetDao syncDataSetDao;
|
|
|
|
|
|
|
|
public void syncProcess() {
|
|
|
|
//查询数据同步设置
|
|
|
|
pushData();
|
|
|
|
pushOrder();
|
|
|
|
pullData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pushData() {
|
|
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
|
|
if (!syncDataSetEntity.isDownstreamEnable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//定时上传最近更新基础数据至上游轮询时间
|
|
|
|
long timeInterval1 = syncDataSetEntity.getSyncTime() * 6 * 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) {
|
|
|
|
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
|
|
|
|
try {
|
|
|
|
heartService.pushData(syncDataSetEntity, null, i);
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
redisUtil.set("SPS_SYNC_UPLOAD_DATA", curTime1);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void customPushData(BasicExportTypeEnum basicExportTypeEnum) {
|
|
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
|
|
ThreadUtil.execAsync(() -> {
|
|
|
|
try {
|
|
|
|
heartService.pushData(syncDataSetEntity, null, basicExportTypeEnum);
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pushOrder() {
|
|
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
|
|
if (!syncDataSetEntity.isDownstreamEnable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//定时上传最近更新单据数据至上游轮询时间
|
|
|
|
long timeInterval2 = syncDataSetEntity.getOrderSyncTime() * 6 * 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);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (curTime2 - lastTime2 > timeInterval2) {
|
|
|
|
heartService.uploadAllOrder(null);
|
|
|
|
heartService.uploadAllBusOrder(null);
|
|
|
|
redisUtil.set("SPS_SYNC_UPLOAD_ORDER", curTime2);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pullData() {
|
|
|
|
try {
|
|
|
|
heartService.dlAllOrder();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
heartService.dlAllDiProducts();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
}
|
|
|
|
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
|
|
|
|
heartService.pullData(i);
|
|
|
|
});
|
|
|
|
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|