数据同步优化

master
wj 2 years ago
parent 16539645de
commit 0b840c9de4

@ -149,6 +149,34 @@ public class SpsSyncDownloadService {
@Value("${file_path}")
private String filePath;
/**
*
*
* @param info
* @param exportType
*/
public void syncData(SyncDataSetResponse info, BasicExportTypeEnum exportType) {
Date now = new Date();
switch (exportType) {
case BASIC_DATA:
if (needExec(info.getBasicProducts(), info.getBasicCorp(), info.getSupCert())) {
basicExportInfoCreate(exportType, now
, x -> x.generateBasicDataFile(info, now, false)
, x -> x.generateBasicDataFile(info, now, true));
}
break;
case OTHER_DATA:
if (needExec(info.getUdiCodeLost(), info.getUdiCodeRel())) {
basicExportInfoCreate(exportType, now
, x -> x.generateOtherDataFile(info, now, false)
, x -> x.generateOtherDataFile(info, now, true));
}
break;
case COUNTRY_DI_DATA:
}
}
/**
*
*
@ -163,7 +191,7 @@ public class SpsSyncDownloadService {
return;
}
try {
basicExportInfoCreate(BasicExportTypeEnum.BASIC_DATA, now, this.getClass()
basicExportInfoCreate(BasicExportTypeEnum.BASIC_DATA, now
, x -> x.generateBasicDataFile(info, now, false)
, x -> x.generateBasicDataFile(info, now, true));
} catch (Exception e) {
@ -173,7 +201,7 @@ public class SpsSyncDownloadService {
}
/**
* TODO
*
*
* @param info
*/
@ -186,7 +214,7 @@ public class SpsSyncDownloadService {
return;
}
try {
basicExportInfoCreate(BasicExportTypeEnum.OTHER_DATA, now, this.getClass()
basicExportInfoCreate(BasicExportTypeEnum.OTHER_DATA, now
, x -> x.generateOtherDataFile(info, now, false)
, x -> x.generateOtherDataFile(info, now, true));
} catch (Exception e) {
@ -195,6 +223,16 @@ public class SpsSyncDownloadService {
}
/**
*
*
* @param set
* @return
*/
private boolean needExec(int... set) {
return CollectionUtil.contains(Collections.singleton(set), 2);
}
/**
*
*
@ -202,15 +240,14 @@ public class SpsSyncDownloadService {
* @param hasDataMethod
* @param createFileMethod
*/
private void basicExportInfoCreate(BasicExportTypeEnum exportEnum, Date now
, Class<? extends SpsSyncDownloadService> clazz, Function<SpsSyncDownloadService, Boolean> hasDataMethod, Function<SpsSyncDownloadService, Boolean> createFileMethod) throws Exception {
private void basicExportInfoCreate(BasicExportTypeEnum exportEnum, Date now, Function<SpsSyncDownloadService, Boolean> hasDataMethod, Function<SpsSyncDownloadService, Boolean> createFileMethod) {
//防止出现同时调用问题
String redisKey = String.format("spsm-sync-create:%s", exportEnum.getKey());
boolean result = redisUtil.setIfAbsent(redisKey, 1, 10);
if (!result) {
String errorMsg = String.format("syncIdcSps----process------------同步[%s]重复进入", exportEnum.getRemark());
// logger.info(errorMsg);
throw new Exception(errorMsg);
throw new RuntimeException(errorMsg);
}
BasicExportStatusEntity exportStatus = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class)
.eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.BASIC_DATA.getRemark())

@ -1,5 +1,6 @@
package com.glxp.api.task;
import com.glxp.api.constant.BasicExportTypeEnum;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.req.system.ScheduledRequest;
@ -17,6 +18,7 @@ import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Arrays;
@Component
@ -65,8 +67,11 @@ public class AsyncHeartTask implements SchedulingConfigurer {
if (curTime - lastTime > timeInterval) {
spsSyncDownloadService.syncDiProductsTask();
// todo 生成任务都写在这
spsSyncDownloadService.syncBasicData(syncDataSetEntity);
spsSyncDownloadService.syncOtherData(syncDataSetEntity);
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
spsSyncDownloadService.syncData(syncDataSetEntity, i);
});
// spsSyncDownloadService.syncBasicData(syncDataSetEntity);
// spsSyncDownloadService.syncOtherData(syncDataSetEntity);
redisUtil.set("SPS_SYNC_GEN_DATA", curTime);
}
}

Loading…
Cancel
Save