diff --git a/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java b/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java index b6f47f4a..53d68e06 100644 --- a/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java +++ b/src/main/java/com/glxp/api/constant/BasicExportStatusTimeEnum.java @@ -140,6 +140,7 @@ public enum BasicExportStatusTimeEnum { PRODUCE_BUSINESS_DATA("thr_manufacturer", "生产企业数据"), DRUG_DATA_TASK("drug_data_task", "药品关联信息"), + UNIFY_DATA_TASK("unify_data_task", "医共体信息"), ; @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 05e3e644..e95d12c6 100644 --- a/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java +++ b/src/main/java/com/glxp/api/constant/BasicExportTypeEnum.java @@ -78,6 +78,11 @@ public enum BasicExportTypeEnum { * 药品关联信息任务同步 */ DRUG_DATA_TASK("drug_data_task", "药品关联关系"), + + /** + * 医共体数据 + */ + UNIFY_DATA("unify_data", "医共体数据"), ; @EnumValue private String key; diff --git a/src/main/java/com/glxp/api/service/auth/AuthWarehouseUnifyService.java b/src/main/java/com/glxp/api/service/auth/AuthWarehouseUnifyService.java index e90bde7e..4e6455fa 100644 --- a/src/main/java/com/glxp/api/service/auth/AuthWarehouseUnifyService.java +++ b/src/main/java/com/glxp/api/service/auth/AuthWarehouseUnifyService.java @@ -1,7 +1,13 @@ package com.glxp.api.service.auth; +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.glxp.api.dao.auth.AuthAliUserDao; +import com.glxp.api.dao.auth.AuthWarehouseUnifyMapper; +import com.glxp.api.entity.auth.AuthAliUser; import com.glxp.api.entity.auth.AuthWarehouseUnify; +import com.glxp.api.entity.auth.InvBusUserEntity; -public interface AuthWarehouseUnifyService { +public interface AuthWarehouseUnifyService extends IService { void deleteWarehouseCustomer(AuthWarehouseUnify authWarehouseUnify); } diff --git a/src/main/java/com/glxp/api/service/auth/impl/AuthWarehouseUnifyServiceImpl.java b/src/main/java/com/glxp/api/service/auth/impl/AuthWarehouseUnifyServiceImpl.java index 85c987c4..5fcddc2d 100644 --- a/src/main/java/com/glxp/api/service/auth/impl/AuthWarehouseUnifyServiceImpl.java +++ b/src/main/java/com/glxp/api/service/auth/impl/AuthWarehouseUnifyServiceImpl.java @@ -1,8 +1,12 @@ package com.glxp.api.service.auth.impl; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.glxp.api.dao.auth.AuthWarehouseUnifyMapper; +import com.glxp.api.dao.auth.InvBusUserDao; import com.glxp.api.entity.auth.AuthWarehouseUnify; +import com.glxp.api.entity.auth.InvBusUserEntity; import com.glxp.api.service.auth.AuthWarehouseUnifyService; +import com.glxp.api.service.auth.InvBusUserService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -10,7 +14,7 @@ import javax.annotation.Resource; @Service @Transactional(rollbackFor = Exception.class) -public class AuthWarehouseUnifyServiceImpl implements AuthWarehouseUnifyService { +public class AuthWarehouseUnifyServiceImpl extends ServiceImpl implements AuthWarehouseUnifyService { @Resource AuthWarehouseUnifyMapper authWarehouseUnifyMapper; 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 cca138e5..17ae56cb 100644 --- a/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java +++ b/src/main/java/com/glxp/api/service/sync/SpsSyncDownloadService.java @@ -13,7 +13,9 @@ import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.*; import com.glxp.api.controller.sync.SpsSyncWebSocket; import com.glxp.api.constant.Constant; +import com.glxp.api.dao.auth.AuthWarehouseUnifyMapper; import com.glxp.api.dao.basic.BasicProductsDao; +import com.glxp.api.entity.auth.AuthWarehouseUnify; import com.glxp.api.entity.basic.*; import com.glxp.api.entity.collect.RelCodeBatch; import com.glxp.api.entity.collect.RelCodeDetail; @@ -37,6 +39,7 @@ import com.glxp.api.res.sync.SpsSyncDeviceTaskResponse; import com.glxp.api.res.sync.SpsSyncDrugDataTaskResponse; import com.glxp.api.res.sync.SpsSyncOrderResponse; import com.glxp.api.res.system.SyncDataSetResponse; +import com.glxp.api.service.auth.AuthWarehouseUnifyService; import com.glxp.api.service.basic.*; import com.glxp.api.service.collect.RelCodeBatchService; import com.glxp.api.service.collect.RelCodeDetailService; @@ -104,6 +107,8 @@ public class SpsSyncDownloadService { @Resource IoOrderInvoiceService orderInvoiceService; + @Resource + AuthWarehouseUnifyService authWarehouseUnifyService; // 创建单据同步任务 @@ -286,6 +291,77 @@ public class SpsSyncDownloadService { , x -> x.generateDrugDataFile(info, now, false, syncTime) , x -> x.generateDrugDataFile(info, now, true, syncTime)); break; + case UNIFY_DATA: + basicExportInfoCreate(exportType, syncTime, now + , x -> x.generateUnifyDataFile(info, now, false, syncTime) + , x -> x.generateUnifyDataFile(info, now, true, syncTime)); + break; + } + } + + private Boolean generateUnifyDataFile(SyncDataSetResponse info, Date now, boolean createFile, Date syncTime) { + BasicExportTypeEnum exportType = BasicExportTypeEnum.UNIFY_DATA; + //文件数据 + Map jsonMap = new WeakHashMap<>(4); + List syncFiles = new ArrayList<>(); + Map> totalTimeMap = new WeakHashMap<>(10); + StringBuffer remark = new StringBuffer(); + Map syncTimeMap = new WeakHashMap<>(3); + syncTimeMap.put("isNew", true); + boolean ge = false; + if (syncTime != null) { + ge = true; + } + try { + //确认有开启设备信息由外向内同步 +// if (needExec(info.getDeviceInfo())) + { + Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.UNIFY_DATA_TASK, createFile); + totalTimeMap.put(BasicExportStatusTimeEnum.UNIFY_DATA_TASK, map); + + List list = authWarehouseUnifyService.list(Wrappers.lambdaQuery(AuthWarehouseUnify.class) + .le(!ge && (boolean) map.get("isNew"), AuthWarehouseUnify::getUpdateTime, now) + .between(ge, AuthWarehouseUnify::getUpdateTime, syncTime, now) + .between(!ge && !(boolean) map.get("isNew"), AuthWarehouseUnify::getUpdateTime + , map.get("oldDate"), now) + ); + + if (CollectionUtil.isNotEmpty(list)) { + jsonMap.put(AuthWarehouseUnify.class.getSimpleName(), list); + remark.append("医共体信息:").append(list.size()).append("条\n"); + } + + } + + if (jsonMap.size() > 0) { + jsonMap.put(SYNC_REMARK, remark.toString()); + if (!createFile) { + return true; + } + try { + String fileFullPath = writeFile(filePath, exportType.getRemark(), JsonUtils.toJsonString(jsonMap)); + try { + //修改任务数据 + boolean update = updateExportStatus(exportType, fileFullPath, remark.toString()); + } catch (Exception e) { + // 异常回滚 + this.exportTimeRollback(totalTimeMap, exportType, fileFullPath); + } + SocketMsgEntity socketMsgEntity = SocketMsgEntity.builder().type(SocketMsgType.DL_ALL_DATA).remark("下载医共体信息").build(); + spsSyncWebSocket.sendMessage(socketMsgEntity, "1:" + socketToken); + + 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; } }