diff --git a/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java b/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java index ed199d85..f04e94d7 100644 --- a/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java +++ b/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java @@ -41,6 +41,21 @@ public enum BasicExportStatusTimeEnum { * UDI码关联关系 */ IO_CODE_REL("io_code_rel", "UDI码关联关系"), + + /** + * 业务单据类型 + */ + BASIC_BUSSINESS_TYPE("basic_bussiness_type","扫码单据类型"), + + /** + * 扫码单据类型 + */ + BASIC_BUSTYPE_CHANGE("basic_bustype_change","业务单据类型"), + + /** + * 业务单据类型 + */ + THR_BUSTYPE_ORIGIN("thr_bustype_origin","第三方单据类型"), ; @EnumValue private String key; diff --git a/src/main/java/com/glxp/api/service/basic/IBasicBusTypeChangeService.java b/src/main/java/com/glxp/api/service/basic/IBasicBusTypeChangeService.java index f629ab7d..c5d9e32c 100644 --- a/src/main/java/com/glxp/api/service/basic/IBasicBusTypeChangeService.java +++ b/src/main/java/com/glxp/api/service/basic/IBasicBusTypeChangeService.java @@ -1,6 +1,8 @@ package com.glxp.api.service.basic; +import com.baomidou.mybatisplus.extension.service.IService; import com.glxp.api.entity.basic.BasicBusTypeChangeEntity; +import com.glxp.api.entity.basic.BasicBussinessTypeEntity; import com.glxp.api.req.basic.FilterBusTypeChangeRequest; import com.glxp.api.res.basic.BasicBusTypeChangeResponse; @@ -9,7 +11,7 @@ import java.util.List; /** * 单据生成设置Service */ -public interface IBasicBusTypeChangeService { +public interface IBasicBusTypeChangeService extends IService { BasicBusTypeChangeEntity selectByOriginAction(String action); diff --git a/src/main/java/com/glxp/api/service/basic/impl/BasicBusTypeChangeServiceImpl.java b/src/main/java/com/glxp/api/service/basic/impl/BasicBusTypeChangeServiceImpl.java index 80f3f22c..66235c43 100644 --- a/src/main/java/com/glxp/api/service/basic/impl/BasicBusTypeChangeServiceImpl.java +++ b/src/main/java/com/glxp/api/service/basic/impl/BasicBusTypeChangeServiceImpl.java @@ -2,9 +2,12 @@ package com.glxp.api.service.basic.impl; import cn.hutool.core.collection.CollUtil; 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.basic.BasicBusTypeChangeDao; +import com.glxp.api.dao.basic.BasicBussinessTypeDao; import com.glxp.api.entity.basic.BasicBusTypeChangeEntity; +import com.glxp.api.entity.basic.BasicBussinessTypeEntity; import com.glxp.api.req.basic.FilterBusTypeChangeRequest; import com.glxp.api.res.basic.BasicBusTypeChangeResponse; import com.glxp.api.service.auth.CustomerService; @@ -21,7 +24,7 @@ import java.util.List; @Slf4j @Service @Transactional(rollbackFor = Exception.class) -public class BasicBusTypeChangeServiceImpl implements IBasicBusTypeChangeService { +public class BasicBusTypeChangeServiceImpl extends ServiceImpl implements IBasicBusTypeChangeService { @Resource private CustomerService customerService; 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 27bc15f0..43b0b916 100644 --- a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java +++ b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java @@ -15,6 +15,7 @@ import com.glxp.api.entity.purchase.*; import com.glxp.api.entity.sync.BasicExportStatusEntity; import com.glxp.api.entity.sync.BasicExportStatusTimeEntity; import com.glxp.api.entity.sync.SyncDataBustypeEntity; +import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity; import com.glxp.api.req.basic.ProductInfoFilterRequest; import com.glxp.api.req.basic.UdiCompanyRequest; import com.glxp.api.req.inout.FilterOrderRequest; @@ -25,6 +26,7 @@ import com.glxp.api.res.system.SyncDataSetResponse; import com.glxp.api.service.basic.*; import com.glxp.api.service.inout.*; import com.glxp.api.service.purchase.*; +import com.glxp.api.service.thrsys.IThrBusTypeOriginService; import com.glxp.api.util.CustomUtil; import com.glxp.api.util.DateUtil; import com.glxp.api.util.JsonUtils; @@ -174,6 +176,13 @@ public class SpsSyncDownloadService { , x -> x.generateOtherDataFile(info, now, true)); } break; + case DOCUMENT_TYPE_DATA: + if (needExec(info.getTypeBus(), info.getTypeScan(), info.getTypeThird())) { + basicExportInfoCreate(exportType, now + , x -> x.generateDocumentTypeDataFile(info, now, false) + , x -> x.generateDocumentTypeDataFile(info, now, true)); + } + break; case COUNTRY_DI_DATA: } } @@ -291,6 +300,7 @@ public class SpsSyncDownloadService { * @return 是否有数据 true/false 有新数据/无新数据 */ protected boolean generateBasicDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + BasicExportTypeEnum exportType = BasicExportTypeEnum.BASIC_DATA; //文件数据 Map jsonMap = new WeakHashMap<>(4); Map> totalTimeMap = new WeakHashMap<>(10); @@ -398,7 +408,7 @@ public class SpsSyncDownloadService { return true; } try { - String fileFullPath = writeFile(filePath, BasicExportTypeEnum.BASIC_DATA.getRemark(), JsonUtils.toJsonString(jsonMap)); + String fileFullPath = writeFile(filePath, exportType.getRemark(), JsonUtils.toJsonString(jsonMap)); //计算总数 int total = 0; for (List l : jsonMap.values()) { @@ -406,25 +416,17 @@ public class SpsSyncDownloadService { } 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) - ); + boolean update = updateExportStatus(exportType, fileFullPath, total); } catch (Exception e) { // 异常回滚 - this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.BASIC_DATA, fileFullPath); + this.exportTimeRollback(totalTimeMap, exportType, fileFullPath); } return true; } catch (IOException e) { logger.error(String.format("syncIdcSps----process------------生成[%s]文件及更改库操作异常,异常信息<%s>" - , BasicExportTypeEnum.BASIC_DATA.getRemark(), e.getMessage())); + , exportType.getRemark(), e.getMessage())); // 异常回滚 - this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.BASIC_DATA, null); + this.exportTimeRollback(totalTimeMap, exportType, null); } } return false; @@ -448,6 +450,7 @@ public class SpsSyncDownloadService { * @return 是否有数据 true/false 有新数据/无新数据 */ protected boolean generateOtherDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + BasicExportTypeEnum exportType = BasicExportTypeEnum.OTHER_DATA; //文件数据 Map jsonMap = new WeakHashMap<>(4); Map> totalTimeMap = new WeakHashMap<>(10); @@ -485,7 +488,100 @@ public class SpsSyncDownloadService { return true; } try { - String fileFullPath = writeFile(filePath, BasicExportTypeEnum.OTHER_DATA.getRemark(), JsonUtils.toJsonString(jsonMap)); + String fileFullPath = writeFile(filePath, exportType.getRemark(), JsonUtils.toJsonString(jsonMap)); + //计算总数 + int total = 0; + for (List l : jsonMap.values()) { + total += l.size(); + } + try { + //修改任务数据 + boolean update = updateExportStatus(exportType, fileFullPath, total); + } catch (Exception e) { + // 异常回滚 + this.exportTimeRollback(totalTimeMap, exportType, fileFullPath); + } + return true; + } catch (IOException e) { + logger.error(String.format("syncIdcSps----process------------生成[%s]文件及更改库操作异常,异常信息<%s>" + , exportType.getRemark(), e.getMessage())); + // 异常回滚 + this.exportTimeRollback(totalTimeMap, exportType, null); + } + } + return false; + } catch (Exception e) { + logger.error(e.getMessage()); + return false; + } + } + + + private final IBasicBussinessTypeService bussinessTypeService; + private final IBasicBusTypeChangeService busTypeChangeService; + private final IThrBusTypeOriginService thrBusTypeOriginService; + + /** + * 读取单据类型数据,创建文件 + * + * @param info 同步设置信息 + * @param now 当前时间 + * @param createFile 是否创建文件 + * @return 是否有数据 true/false 有新数据/无新数据 + */ + protected boolean generateDocumentTypeDataFile(SyncDataSetResponse info, Date now, boolean createFile) { + BasicExportTypeEnum exportType = BasicExportTypeEnum.DOCUMENT_TYPE_DATA; + //文件数据 + Map jsonMap = new WeakHashMap<>(4); + Map> totalTimeMap = new WeakHashMap<>(10); + try { + //确认有开启业务单据类型同步 + if (needExec(info.getTypeBus())) { + Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE, createFile); + totalTimeMap.put(BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE, map); + List ioCodeLostList = bussinessTypeService.list(Wrappers.lambdaQuery(BasicBussinessTypeEntity.class) + .le((boolean) map.get("isNew"), BasicBussinessTypeEntity::getUpdateTime, now) + .between(!(boolean) map.get("isNew"), BasicBussinessTypeEntity::getUpdateTime + , map.get("oldDate"), now) + ); + if (CollectionUtil.isNotEmpty(ioCodeLostList)) { + jsonMap.put(BasicBussinessTypeEntity.class.getSimpleName(), ioCodeLostList); + } + } + //确认有开启扫码单据类型同步 + if (needExec(info.getTypeScan())) { + Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE, createFile); + totalTimeMap.put(BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE, map); + List ioCodeRelList = busTypeChangeService.list(Wrappers.lambdaQuery(BasicBusTypeChangeEntity.class) + .le((boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime, now) + .between(!(boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime + , map.get("oldDate"), now) + ); + if (CollectionUtil.isNotEmpty(ioCodeRelList)) { + jsonMap.put(BasicBusTypeChangeEntity.class.getSimpleName(), ioCodeRelList); + } + } + //确认有开启第三方单据类型同步 + if (needExec(info.getTypeThird())) { + Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN, createFile); + totalTimeMap.put(BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN, map); + List ioCodeRelList = thrBusTypeOriginService.list(Wrappers.lambdaQuery(ThrBusTypeOriginEntity.class) + .le((boolean) map.get("isNew"), ThrBusTypeOriginEntity::getUpdateTime, now) + .between(!(boolean) map.get("isNew"), ThrBusTypeOriginEntity::getUpdateTime + , map.get("oldDate"), now) + ); + if (CollectionUtil.isNotEmpty(ioCodeRelList)) { + jsonMap.put(ThrBusTypeOriginEntity.class.getSimpleName(), ioCodeRelList); + } + } + + + if (jsonMap.size() > 0) { + if (!createFile) { + return true; + } + try { + String fileFullPath = writeFile(filePath, exportType.getRemark(), JsonUtils.toJsonString(jsonMap)); //计算总数 int total = 0; for (List l : jsonMap.values()) { @@ -493,25 +589,17 @@ public class SpsSyncDownloadService { } 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.OTHER_DATA.getRemark(), total)) - .eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.OTHER_DATA.getRemark()) - .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode()) - .isNull(BasicExportStatusEntity::getCacheFilePath) - ); + boolean update = updateExportStatus(exportType, fileFullPath, total); } catch (Exception e) { // 异常回滚 - this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.OTHER_DATA, fileFullPath); + this.exportTimeRollback(totalTimeMap, exportType, fileFullPath); } return true; } catch (IOException e) { logger.error(String.format("syncIdcSps----process------------生成[%s]文件及更改库操作异常,异常信息<%s>" - , BasicExportTypeEnum.OTHER_DATA.getRemark(), e.getMessage())); + , exportType.getRemark(), e.getMessage())); // 异常回滚 - this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.OTHER_DATA, null); + this.exportTimeRollback(totalTimeMap, exportType, null); } } return false; @@ -571,6 +659,27 @@ public class SpsSyncDownloadService { return returnMap; } + + /** + * 修改任务数据 + * @param exportType 任务类型 + * @param fileFullPath 文件地址 + * @param total 总条数 + * @return 更新结果 true/false + */ + private boolean updateExportStatus(BasicExportTypeEnum exportType, String fileFullPath, Integer total) { + return basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class) + .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode()) + .set(BasicExportStatusEntity::getUpdateTime, new Date()) + .set(BasicExportStatusEntity::getCacheFilePath, fileFullPath) + .set(total != null, BasicExportStatusEntity::getRemark, String.format("%s: %s条", exportType.getRemark(), total)) + .eq(BasicExportStatusEntity::getType, exportType.getRemark()) + .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode()) + .isNull(BasicExportStatusEntity::getCacheFilePath) + ); + + } + /** * 异常回滚操作 * diff --git a/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java b/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java index e847dbcd..245ac674 100644 --- a/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java +++ b/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java @@ -1,5 +1,6 @@ package com.glxp.api.service.thrsys; +import com.baomidou.mybatisplus.extension.service.IService; import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.thrsys.FilterThrBusTypeOriginRequest; @@ -10,7 +11,7 @@ import java.util.List; /** * 第三方单据类型Service */ -public interface IThrBusTypeOriginService { +public interface IThrBusTypeOriginService extends IService { /** * 查询启用的第三方单据类型列表 diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java index ebb61b9c..d08724dd 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java @@ -3,6 +3,7 @@ package com.glxp.api.service.thrsys.impl; import cn.hutool.core.collection.CollUtil; 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.thrsys.ThrBusTypeOriginDao; import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity; @@ -25,7 +26,7 @@ import java.util.List; @Slf4j @Service @Transactional(rollbackFor = Exception.class) -public class ThrBusTypeOriginServiceImpl implements IThrBusTypeOriginService { +public class ThrBusTypeOriginServiceImpl extends ServiceImpl implements IThrBusTypeOriginService { @Resource private CustomerService customerService;