From 0b840c9de40794d01a7d7e28eac752aa902814c2 Mon Sep 17 00:00:00 2001 From: wj <1285151836@qq.com> Date: Fri, 21 Apr 2023 11:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/sync/SpsSyncDownloadService.java | 49 ++++++++++++++++--- .../com/glxp/api/task/AsyncHeartTask.java | 9 +++- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java index eec9d793..45ef8a49 100644 --- a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java +++ b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java @@ -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 clazz, Function hasDataMethod, Function createFileMethod) throws Exception { + private void basicExportInfoCreate(BasicExportTypeEnum exportEnum, Date now, Function hasDataMethod, Function 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()) diff --git a/src/main/java/com/glxp/api/task/AsyncHeartTask.java b/src/main/java/com/glxp/api/task/AsyncHeartTask.java index bd25cc5f..12c59512 100644 --- a/src/main/java/com/glxp/api/task/AsyncHeartTask.java +++ b/src/main/java/com/glxp/api/task/AsyncHeartTask.java @@ -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); } }