From bf4c254cd3aa55831faf923ce7acc06bed897e60 Mon Sep 17 00:00:00 2001 From: wj <1285151836@qq.com> Date: Wed, 19 Apr 2023 16:05:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=AE=BE=E7=BD=AE--=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/BasicExportStatusTimeEnum.java | 10 ++ .../api/constant/BasicExportTypeEnum.java | 5 + .../sync/SpsSyncDownloadController.java | 56 ++++++++- .../api/entity/sync/SyncDataSetEntity.java | 4 + .../res/sync/SpsSyncOtherDataResponse.java | 20 ++++ .../api/res/system/SyncDataSetResponse.java | 4 + .../api/service/inout/IoCodeLostService.java | 3 +- .../api/service/inout/IoCodeRelService.java | 3 +- .../inout/impl/IoCodeLostServiceImpl.java | 3 +- .../inout/impl/IoCodeRelServiceImpl.java | 38 +++--- .../service/sync/SpsSyncDownloadService.java | 112 +++++++++++++++++- .../com/glxp/api/task/AsyncHeartTask.java | 1 + 12 files changed, 235 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/glxp/api/res/sync/SpsSyncOtherDataResponse.java diff --git a/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java b/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java index a4117719..489e176c 100644 --- a/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java +++ b/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java @@ -28,6 +28,16 @@ public enum BasicExportStatusTimeEnum { * 首营资质 */ SUP_CERT("sup_cert", "首营资质"), + + /** + * UDI码补齐 + */ + IO_CODE_LOST("io_code_lost", "UDI码补齐"), + + /** + * UDI码关联关系 + */ + IO_CODE_REL("io_code_rel", "UDI码关联关系"), ; @EnumValue private String key; diff --git a/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java b/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java index b5cd25c4..8a158260 100644 --- a/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java +++ b/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java @@ -17,6 +17,11 @@ public enum BasicExportTypeEnum { * 国家库DI数据 */ COUNTRY_DI_DATA("country_di_data", "国家库DI数据"), + + /** + * 其他数据 + */ + OTHER_DATA("other_data", "其他数据"), ; @EnumValue private String key; diff --git a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java index 30f7c98b..f2acae98 100644 --- a/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java +++ b/src/main/java/com/glxp/api/controller/sync/SpsSyncDownloadController.java @@ -175,7 +175,7 @@ public class SpsSyncDownloadController { StringBuilder str = new StringBuilder(); int data; while ((data = reader.read()) != -1) { - str.append((char)data); + str.append((char) data); } reader.close(); Dict map = JsonUtils.parseMap(str.toString()); @@ -210,6 +210,60 @@ public class SpsSyncDownloadController { return baseResponse; } + + // 下发基础数据 ,供给中继服务,UDI管理系统下载 + @AuthRuleAnnotation("") + @GetMapping("sps/sync/otherData") + public BaseResponse getOtherData() { + BaseResponse baseResponse = new BaseResponse<>(); + SpsSyncOtherDataResponse spsSyncOtherDataResponse = new SpsSyncOtherDataResponse(); + BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class) + .eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.OTHER_DATA.getRemark()) + .orderByDesc(BasicExportStatusEntity::getStartTime) + .last("limit 1") + ); + if (one != null) { + if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) { + basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) + .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode()) + .set(BasicExportStatusEntity::getUpdateTime, new Date()) + .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_TRIGGERED.getCode()) + .eq(BasicExportStatusEntity::getId, one.getId()) + ); + } else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) { + // 读取文件数据 + try { + FileReader reader = new FileReader(one.getCacheFilePath()); + StringBuilder str = new StringBuilder(); + int data; + while ((data = reader.read()) != -1) { + str.append((char) data); + } + reader.close(); + Dict map = JsonUtils.parseMap(str.toString()); + // 组装返回数据 + spsSyncOtherDataResponse.setTaskId(one.getId()); + spsSyncOtherDataResponse.setIoCodeLostList((List) map.get(IoCodeLostEntity.class.getSimpleName())); + spsSyncOtherDataResponse.setIoCodeRelList((List) map.get(IoCodeRelEntity.class.getSimpleName())); + } catch (FileNotFoundException e) { + throw new RuntimeException("系统异常,未找到对应数据文件"); + } catch (IOException e) { + throw new RuntimeException(e); + } + // 修改任务状态 +// basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) +// .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.COMPLETED.getCode()) +// .set(BasicExportStatusEntity::getUpdateTime, new Date()) +// .set(BasicExportStatusEntity::getEndTime, new Date()) +// .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) +// .eq(BasicExportStatusEntity::getId, one.getId()) +// ); + } + } + baseResponse.setData(spsSyncOtherDataResponse); + return baseResponse; + } + //接收中继服务、UDI管理系统上传单据 @AuthRuleAnnotation("sps/sync/order/upload") @PostMapping("/sps/sync/order/upload") diff --git a/src/main/java/com/glxp/api/entity/sync/SyncDataSetEntity.java b/src/main/java/com/glxp/api/entity/sync/SyncDataSetEntity.java index 432c979c..adefc82b 100644 --- a/src/main/java/com/glxp/api/entity/sync/SyncDataSetEntity.java +++ b/src/main/java/com/glxp/api/entity/sync/SyncDataSetEntity.java @@ -20,6 +20,10 @@ public class SyncDataSetEntity { private int basicThirdInv; //第三方仓库信息 private int basicThirdBusOrder; //第三方业务单据 private int dbDiProducts; //DI产品信息 + + private int udiCodeLost; // UDI码补齐 + private int udiCodeRel; //UDI码关联关系 + private boolean downstreamEnable; //上游是否联通 private Integer syncTime; //数据上传间隔时间 private Integer syncDownloadTime; //数据下载间隔时间 diff --git a/src/main/java/com/glxp/api/res/sync/SpsSyncOtherDataResponse.java b/src/main/java/com/glxp/api/res/sync/SpsSyncOtherDataResponse.java new file mode 100644 index 00000000..b5ee4f12 --- /dev/null +++ b/src/main/java/com/glxp/api/res/sync/SpsSyncOtherDataResponse.java @@ -0,0 +1,20 @@ +package com.glxp.api.res.sync; + +import com.glxp.api.entity.basic.*; +import com.glxp.api.entity.inout.IoCodeLostEntity; +import com.glxp.api.entity.inout.IoCodeRelEntity; +import com.glxp.api.entity.purchase.*; +import lombok.Data; + +import java.util.List; + +/** + * 同步设置--其他数据 + */ +@Data +public class SpsSyncOtherDataResponse extends BaseSyncResponse { + + + List ioCodeLostList; + List ioCodeRelList; +} diff --git a/src/main/java/com/glxp/api/res/system/SyncDataSetResponse.java b/src/main/java/com/glxp/api/res/system/SyncDataSetResponse.java index 97281a91..14ef7bbe 100644 --- a/src/main/java/com/glxp/api/res/system/SyncDataSetResponse.java +++ b/src/main/java/com/glxp/api/res/system/SyncDataSetResponse.java @@ -21,6 +21,10 @@ public class SyncDataSetResponse { private int basicThirdInv; private int basicThirdBusOrder; private int dbDiProducts; + + private int udiCodeLost; // UDI码补齐 + private int udiCodeRel; //UDI码关联关系 + private boolean downstreamEnable; private int orderScanFinish; private int orderUnReceive; diff --git a/src/main/java/com/glxp/api/service/inout/IoCodeLostService.java b/src/main/java/com/glxp/api/service/inout/IoCodeLostService.java index aafe62e7..e68ccfcb 100644 --- a/src/main/java/com/glxp/api/service/inout/IoCodeLostService.java +++ b/src/main/java/com/glxp/api/service/inout/IoCodeLostService.java @@ -1,11 +1,12 @@ package com.glxp.api.service.inout; +import com.baomidou.mybatisplus.extension.service.IService; import com.glxp.api.entity.inout.IoCodeLostEntity; import com.glxp.api.res.inout.IoCodeLostResponse; import java.util.List; -public interface IoCodeLostService { +public interface IoCodeLostService extends IService { List selectLost(IoCodeLostEntity ioCodeLostEntity); diff --git a/src/main/java/com/glxp/api/service/inout/IoCodeRelService.java b/src/main/java/com/glxp/api/service/inout/IoCodeRelService.java index 9c04993f..61b0aedd 100644 --- a/src/main/java/com/glxp/api/service/inout/IoCodeRelService.java +++ b/src/main/java/com/glxp/api/service/inout/IoCodeRelService.java @@ -1,12 +1,13 @@ package com.glxp.api.service.inout; +import com.baomidou.mybatisplus.extension.service.IService; import com.glxp.api.entity.inout.IoCodeRelEntity; import com.glxp.api.req.inout.IoOrderRelRequest; import com.glxp.api.res.inout.IoCodeRelResponse; import java.util.List; -public interface IoCodeRelService { +public interface IoCodeRelService extends IService { List selectIoCodeRelList(IoOrderRelRequest ioOrderRelRequest); diff --git a/src/main/java/com/glxp/api/service/inout/impl/IoCodeLostServiceImpl.java b/src/main/java/com/glxp/api/service/inout/impl/IoCodeLostServiceImpl.java index 74839923..507a42c9 100644 --- a/src/main/java/com/glxp/api/service/inout/impl/IoCodeLostServiceImpl.java +++ b/src/main/java/com/glxp/api/service/inout/impl/IoCodeLostServiceImpl.java @@ -1,6 +1,7 @@ package com.glxp.api.service.inout.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.glxp.api.res.inout.IoCodeLostResponse; import org.springframework.stereotype.Service; @@ -15,7 +16,7 @@ import java.util.List; @Service @Transactional(rollbackFor = Exception.class) -public class IoCodeLostServiceImpl implements IoCodeLostService { +public class IoCodeLostServiceImpl extends ServiceImpl implements IoCodeLostService { @Resource IoCodeLostMapper codeLostEntityMapper; diff --git a/src/main/java/com/glxp/api/service/inout/impl/IoCodeRelServiceImpl.java b/src/main/java/com/glxp/api/service/inout/impl/IoCodeRelServiceImpl.java index 014d0578..505688b4 100644 --- a/src/main/java/com/glxp/api/service/inout/impl/IoCodeRelServiceImpl.java +++ b/src/main/java/com/glxp/api/service/inout/impl/IoCodeRelServiceImpl.java @@ -2,6 +2,7 @@ package com.glxp.api.service.inout.impl; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.glxp.api.dao.inout.IoCodeRelMapper; import com.glxp.api.entity.inout.IoCodeRelEntity; @@ -17,7 +18,7 @@ import java.util.List; @Service @Transactional(rollbackFor = Exception.class) -public class IoCodeRelServiceImpl implements IoCodeRelService { +public class IoCodeRelServiceImpl extends ServiceImpl implements IoCodeRelService { @Resource IoCodeRelMapper ioCodeRelMapper; @@ -42,41 +43,42 @@ public class IoCodeRelServiceImpl implements IoCodeRelService { @Override public List selectIoCodeRelByCode(String code, String parentCode) { - QueryWrapper ew=new QueryWrapper<>(); - if(StrUtil.isNotEmpty(code)){ - ew.eq("code",code); + QueryWrapper ew = new QueryWrapper<>(); + if (StrUtil.isNotEmpty(code)) { + ew.eq("code", code); } - if(StrUtil.isNotEmpty(parentCode)){ - ew.eq("parentCode",parentCode); + if (StrUtil.isNotEmpty(parentCode)) { + ew.eq("parentCode", parentCode); } - List list=ioCodeRelMapper.selectList(ew); + List list = ioCodeRelMapper.selectList(ew); return list; } @Override public Long selectIoCodeRelCount(String parentCode) { - QueryWrapper ew=new QueryWrapper<>(); - if(StrUtil.isNotEmpty(parentCode)){ - ew.eq("parentCode",parentCode); + QueryWrapper ew = new QueryWrapper<>(); + if (StrUtil.isNotEmpty(parentCode)) { + ew.eq("parentCode", parentCode); } - Long count=ioCodeRelMapper.selectCount(ew); + Long count = ioCodeRelMapper.selectCount(ew); return count; } @Override public int delIoCodeRel(String code, String parentCode) { - QueryWrapper ew=new QueryWrapper<>(); - if(StrUtil.isNotEmpty(code)){ - ew.eq("code",code); + QueryWrapper ew = new QueryWrapper<>(); + if (StrUtil.isNotEmpty(code)) { + ew.eq("code", code); } - if(StrUtil.isNotEmpty(parentCode)){ - ew.eq("parentCode",parentCode); + if (StrUtil.isNotEmpty(parentCode)) { + ew.eq("parentCode", parentCode); } - int count=ioCodeRelMapper.delete(ew); - return count; + int count = ioCodeRelMapper.delete(ew); + return count; } + @Override public List selectIoCodeRelDetailList(IoOrderRelRequest ioOrderRelRequest) { if (ioOrderRelRequest == null) { 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 df13a83b..6fbf2b84 100644 --- a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java +++ b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java @@ -172,14 +172,35 @@ public class SpsSyncDownloadService { } + /** + * TODO 同步其他模块 + * + * @param info 同步设置 + */ + public void syncOtherData(SyncDataSetResponse info) { + + Date now = new Date(); + //是否需要执行 + boolean needExec = info.getUdiCodeLost() == 2 || info.getUdiCodeRel() == 2; + if (!needExec) { + return; + } + try { + basicExportInfoCreate(BasicExportTypeEnum.OTHER_DATA, now, this.getClass() + , x -> x.generateOtherDataFile(info, now, false) + , x -> x.generateOtherDataFile(info, now, true)); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + /** * 创建一个同步任务 * * @param exportEnum 任务类型枚举 * @param hasDataMethod 判断时候有无数据方法 * @param createFileMethod 执行文件生成方法 - * @return - * @throws Exception */ private void basicExportInfoCreate(BasicExportTypeEnum exportEnum, Date now , Class clazz, Function hasDataMethod, Function createFileMethod) throws Exception { @@ -371,6 +392,93 @@ public class SpsSyncDownloadService { } } + + private final IoCodeLostService ioCodeLostService; + + private final IoCodeRelService ioCodeRelService; + + /** + * 读取其他数据,创建文件 + * + * @param info 同步设置信息 + * @param now 当前时间 + * @param createFile 是否创建文件 + * @return 是否有数据 true/false 有新数据/无新数据 + */ + protected boolean generateOtherDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + //文件数据 + Map jsonMap = new WeakHashMap<>(4); + Map> totalTimeMap = new WeakHashMap<>(10); + try { + //确认有开启物资字典由外向内同步 + if (info.getUdiCodeLost() == 2) { + Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_LOST, createFile); + totalTimeMap.put(BasicExportStatusTimeEnum.IO_CODE_LOST, map); + List ioCodeLostList = ioCodeLostService.list(Wrappers.lambdaQuery(IoCodeLostEntity.class) + .le((boolean) map.get("isNew"), IoCodeLostEntity::getUpdateTime, now) + .between(!(boolean) map.get("isNew"), IoCodeLostEntity::getUpdateTime + , map.get("oldDate"), now) + ); + if (CollectionUtil.isNotEmpty(ioCodeLostList)) { + jsonMap.put(BasicExportStatusTimeEntity.class.getSimpleName(), ioCodeLostList); + } + } + //确认有开启udi关联关系同步 + if (info.getUdiCodeRel() == 2) { + Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL, createFile); + totalTimeMap.put(BasicExportStatusTimeEnum.IO_CODE_REL, map); + List ioCodeRelList = ioCodeRelService.list(Wrappers.lambdaQuery(IoCodeRelEntity.class) + .le((boolean) map.get("isNew"), IoCodeRelEntity::getUpdateTime, now) + .between(!(boolean) map.get("isNew"), IoCodeRelEntity::getUpdateTime + , map.get("oldDate"), now) + ); + if (CollectionUtil.isNotEmpty(ioCodeRelList)) { + jsonMap.put(IoCodeRelEntity.class.getSimpleName(), ioCodeRelList); + } + } + + + if (jsonMap.size() > 0) { + if (!createFile) { + return true; + } + try { + String fileFullPath = writeFile(filePath, BasicExportTypeEnum.BASIC_DATA.getRemark(), JsonUtils.toJsonString(jsonMap)); + //计算总数 + int total = 0; + for (List l : jsonMap.values()) { + total += l.size(); + } + try { + //插入一条任务数据 + boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) + .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) + .set(BasicExportStatusEntity::getUpdateTime, new Date()) + .set(BasicExportStatusEntity::getCacheFilePath, fileFullPath) + .set(BasicExportStatusEntity::getRemark, String.format("%s: %s条", BasicExportTypeEnum.BASIC_DATA.getRemark(), total)) + .eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.BASIC_DATA.getRemark()) + .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode()) + .isNull(BasicExportStatusEntity::getCacheFilePath) + ); + } catch (Exception e) { + // 异常回滚 + this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.BASIC_DATA, fileFullPath); + } + return true; + } catch (IOException e) { + logger.error(String.format("syncIdcSps----process------------生成[%s]文件及更改库操作异常,异常信息<%s>" + , BasicExportTypeEnum.BASIC_DATA.getRemark(), e.getMessage())); + // 异常回滚 + this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.BASIC_DATA, null); + } + } + return false; + } catch (Exception e) { + logger.error(e.getMessage()); + return false; + } + } + /** * 插入 basicExportStatusTime表 * diff --git a/src/main/java/com/glxp/api/task/AsyncHeartTask.java b/src/main/java/com/glxp/api/task/AsyncHeartTask.java index a97f21f8..e5efb909 100644 --- a/src/main/java/com/glxp/api/task/AsyncHeartTask.java +++ b/src/main/java/com/glxp/api/task/AsyncHeartTask.java @@ -68,6 +68,7 @@ public class AsyncHeartTask implements SchedulingConfigurer { spsSyncDownloadService.syncDiProductsTask(); // todo 生成任务都写在这 spsSyncDownloadService.syncBasicData(syncDataSetEntity); + spsSyncDownloadService.syncOtherData(syncDataSetEntity); redisUtil.set("SPS_SYNC_GEN_DATA", curTime); } }