From f04c3d112cd87fd716dd3158e7e817bf08a56db4 Mon Sep 17 00:00:00 2001 From: chenqi Date: Thu, 26 Mar 2026 15:36:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E8=A7=A3=E5=86=B3ID=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=B2=BE=E5=BA=A6=E4=B8=A2=E5=A4=B1=E5=92=8C=E8=B4=A6?= =?UTF-8?q?=E6=88=B7ID=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在前端请求处理中添加convertIdsToString函数,将超过安全范围的数字转换为字符串 - 使用json-bigint库处理大数字序列化,防止精度丢失 - 在医嘱保存逻辑中确保accountId不为null,自动创建自费账户 - 添加IAccountService依赖注入支持账户操作 - 在产品转移详情DTO中添加@TableField注解标识非数据库字段 --- .../DoctorStationAdviceAppServiceImpl.java | 22 +++++++++ ...orStationChineseMedicalAppServiceImpl.java | 27 +++++++++++ .../web/doctorstation/utils/AdviceUtils.java | 27 +++++++++++ .../dto/ProductTransferDetailDto.java | 4 +- openhis-ui-vue3/src/utils/request.js | 48 +++++++++++++++++-- 5 files changed, 123 insertions(+), 5 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java index 98a72edd..e5d13deb 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java @@ -1104,6 +1104,28 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp log.info("BugFix#219: ========== handDevice END =========="); for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) { + // 🔧 Bug Fix: 确保accountId不为null + if (adviceSaveDto.getAccountId() == null) { + // 尝试从患者就诊中获取默认账户ID(自费账户) + Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId()); + if (selfAccount != null) { + adviceSaveDto.setAccountId(selfAccount.getId()); + } else { + // 自动创建自费账户 + Account newAccount = new Account(); + newAccount.setPatientId(adviceSaveDto.getPatientId()); + newAccount.setEncounterId(adviceSaveDto.getEncounterId()); + newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO); + newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode()); + newAccount.setBalanceAmount(BigDecimal.ZERO); + newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); + newAccount.setEncounterFlag(Whether.YES.getValue()); + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); + Long newAccountId = iAccountService.saveAccountByRegister(newAccount); + adviceSaveDto.setAccountId(newAccountId); + } + } + deviceRequest = new DeviceRequest(); deviceRequest.setId(adviceSaveDto.getRequestId()); // 主键id deviceRequest.setStatusEnum(is_save ? RequestStatus.DRAFT.getValue() : RequestStatus.ACTIVE.getValue()); // 请求状态 diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java index 1481fbd2..59ce1151 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationChineseMedicalAppServiceImpl.java @@ -10,8 +10,10 @@ import com.core.common.utils.AssignSeqUtil; import com.core.common.utils.MessageUtils; import com.core.common.utils.SecurityUtils; import com.core.common.utils.StringUtils; +import com.openhis.administration.domain.Account; import com.openhis.administration.domain.ChargeItem; import com.openhis.administration.domain.EncounterDiagnosis; +import com.openhis.administration.service.IAccountService; import com.openhis.administration.service.IChargeItemService; import com.openhis.administration.service.IEncounterDiagnosisService; import com.openhis.clinical.domain.Condition; @@ -80,6 +82,9 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation @Resource AdviceUtils adviceUtils; + @Resource + IAccountService iAccountService; + /** * 查询中医诊断数据 * @@ -475,6 +480,28 @@ public class DoctorStationChineseMedicalAppServiceImpl implements IDoctorStation // 医嘱签发编码 String signCode = assignSeqUtil.getSeq(AssignSeqEnum.ADVICE_SIGN.getPrefix(), 10); for (AdviceSaveDto adviceSaveDto : insertOrUpdateList) { + // 🔧 Bug Fix: 确保accountId不为null + if (adviceSaveDto.getAccountId() == null) { + // 尝试从患者就诊中获取默认账户ID(自费账户) + Account selfAccount = iAccountService.getSelfAccount(adviceSaveDto.getEncounterId()); + if (selfAccount != null) { + adviceSaveDto.setAccountId(selfAccount.getId()); + } else { + // 自动创建自费账户 + Account newAccount = new Account(); + newAccount.setPatientId(adviceSaveDto.getPatientId()); + newAccount.setEncounterId(adviceSaveDto.getEncounterId()); + newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO); + newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode()); + newAccount.setBalanceAmount(BigDecimal.ZERO); + newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); + newAccount.setEncounterFlag(Whether.YES.getValue()); + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); + Long newAccountId = iAccountService.saveAccountByRegister(newAccount); + adviceSaveDto.setAccountId(newAccountId); + } + } + // 中药付数 BigDecimal chineseHerbsDoseQuantity = adviceSaveDto.getChineseHerbsDoseQuantity(); medicationRequest = new MedicationRequest(); diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java index aec86d15..1b8eab18 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java @@ -11,6 +11,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.openhis.administration.domain.ChargeItem; +import com.openhis.administration.domain.Account; +import com.openhis.administration.service.IAccountService; import com.openhis.administration.service.IChargeItemService; import com.openhis.common.constant.CommonConstants; import com.openhis.common.enums.*; @@ -71,6 +73,9 @@ public class AdviceUtils { @Resource IDoctorStationAdviceAppService iDoctorStationAdviceAppService; + @Resource + IAccountService iAccountService; + /** * 校验库存 * @@ -305,6 +310,28 @@ public class AdviceUtils { */ public void handleActivityChild(String childrenJson, Long organizationId, ActivityChildrenJsonParams activityChildrenJsonParams) { + // 🔧 Bug Fix: 确保accountId不为null + if (activityChildrenJsonParams.getAccountId() == null) { + // 尝试从患者就诊中获取默认账户ID(自费账户) + Account selfAccount = iAccountService.getSelfAccount(activityChildrenJsonParams.getEncounterId()); + if (selfAccount != null) { + activityChildrenJsonParams.setAccountId(selfAccount.getId()); + } else { + // 自动创建自费账户 + Account newAccount = new Account(); + newAccount.setPatientId(activityChildrenJsonParams.getPatientId()); + newAccount.setEncounterId(activityChildrenJsonParams.getEncounterId()); + newAccount.setContractNo(CommonConstants.BusinessName.DEFAULT_CONTRACT_NO); + newAccount.setTypeCode(AccountType.PERSONAL_CASH_ACCOUNT.getCode()); + newAccount.setBalanceAmount(BigDecimal.ZERO); + newAccount.setStatusEnum(AccountStatus.ACTIVE.getValue()); + newAccount.setEncounterFlag(Whether.YES.getValue()); + newAccount.setName(AccountType.PERSONAL_CASH_ACCOUNT.getInfo()); + Long newAccountId = iAccountService.saveAccountByRegister(newAccount); + activityChildrenJsonParams.setAccountId(newAccountId); + } + } + // 治疗类型 (长期/临时) Integer therapyEnum = activityChildrenJsonParams.getTherapyEnum(); // 当前登录账号的科室id diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/dto/ProductTransferDetailDto.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/dto/ProductTransferDetailDto.java index 40306bee..f42b86f1 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/dto/ProductTransferDetailDto.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/dto/ProductTransferDetailDto.java @@ -4,6 +4,7 @@ package com.openhis.web.inventorymanage.dto; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.core.common.annotation.Excel; import com.core.common.annotation.ExcelExtra; @@ -248,7 +249,8 @@ public class ProductTransferDetailDto { private Date occurrenceTime; /** - * 单位列表 + * 单位列表(非数据库字段,业务逻辑填充) */ + @TableField(exist = false) private List unitList; } diff --git a/openhis-ui-vue3/src/utils/request.js b/openhis-ui-vue3/src/utils/request.js index 3ab0121c..65edb4ff 100644 --- a/openhis-ui-vue3/src/utils/request.js +++ b/openhis-ui-vue3/src/utils/request.js @@ -11,6 +11,38 @@ import JSONBig from 'json-bigint' // 初始化json-bigint,配置大数字转字符串(关键:storeAsString: true) const jsonBig = JSONBig({ storeAsString: true }) +// 🔧 Bug Fix #281: 转换所有ID字段为字符串,防止BigInt精度丢失 +const convertIdsToString = (obj) => { + if (obj === null || obj === undefined) return obj + + if (typeof obj === 'number' && obj > 9007199254740991) { + // 如果是超过安全范围的数字,转为字符串 + return String(obj) + } + + if (typeof obj === 'object') { + if (Array.isArray(obj)) { + return obj.map(item => convertIdsToString(item)) + } else { + const newObj = {} + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + const value = obj[key] + // 如果key以Id结尾或者是id,且值是数字,转为字符串 + if ((key === 'id' || key.endsWith('Id') || key.endsWith('ID')) && typeof value === 'number') { + newObj[key] = String(value) + } else { + newObj[key] = convertIdsToString(value) + } + } + } + return newObj + } + } + + return obj +} + let downloadLoadingInstance; // 是否显示重新登录 export let isRelogin = { show: false }; @@ -35,16 +67,23 @@ const service = axios.create({ } } ], - // 可选:请求体序列化,无需额外处理,默认即可(保留也不影响) + // 可选:请求体序列化,使用json-bigint处理大数字 transformRequest: [ function (data) { - return JSON.stringify(data) + if (!data) return data + // 🔧 Bug Fix #281: 使用json-bigint序列化,保留大数字精度 + return jsonBig.stringify(data) } ] }) // request拦截器 service.interceptors.request.use(config => { + // 🔧 Bug Fix #281: 转换请求数据中的ID字段为字符串 + if (config.data && typeof config.data === 'object') { + config.data = convertIdsToString(config.data) + } + // 是否需要设置 token const isToken = (config.headers || {}).isToken === false // 是否需要防止数据重复提交 @@ -62,10 +101,11 @@ service.interceptors.request.use(config => { if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) { const requestObj = { url: config.url, - data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data, + data: typeof config.data === 'object' ? jsonBig.stringify(config.data) : config.data, time: new Date().getTime() } - const requestSize = Object.keys(JSON.stringify(requestObj)).length; // 请求数据大小 + // 🔧 Bug Fix #281: 使用json-bigint计算大小 + const requestSize = Object.keys(jsonBig.stringify(requestObj)).length; // 请求数据大小 const limitSize = 5 * 1024 * 1024; // 限制存放数据5M if (requestSize >= limitSize) { console.warn(`[${config.url}]: ` + '请求数据大小超出允许的5M限制,无法进行防重复提交验证。')