Fix Bug #503: AI修复
This commit is contained in:
@@ -58,8 +58,8 @@ public interface InpatientDrugMapper {
|
||||
Integer selectDispensedFlag(@Param("orderId") Long orderId);
|
||||
|
||||
/**
|
||||
* 获取字典配置:病区护士执行提交药品模式
|
||||
* 返回值示例: "apply" (需申请模式) 或 "auto" (自动模式)
|
||||
* 获取病区护士执行提交药品模式配置
|
||||
* 返回 'auto' 或 'apply',用于控制发药明细与汇总单的触发时机
|
||||
*/
|
||||
@Select("SELECT dict_value FROM sys_dict_data WHERE dict_type = 'nurse_drug_submit_mode' AND status = '0' LIMIT 1")
|
||||
String getDrugSubmitMode();
|
||||
|
||||
@@ -45,6 +45,7 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
||||
|
||||
// 业务约束:需申请模式下,此方法必须由“汇总发药申请”动作触发。
|
||||
// 前端/网关层应拦截护士单条执行时的直接发药请求,确保明细与汇总单同时落库。
|
||||
// 此处通过事务包裹保证明细与汇总的强一致性,任一失败则整体回滚。
|
||||
for (Map<String, Object> drugInfo : drugList) {
|
||||
Long drugId = ((Number) drugInfo.get("drugId")).longValue();
|
||||
Integer quantity = ((Number) drugInfo.get("quantity")).intValue();
|
||||
@@ -58,8 +59,7 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 退药业务
|
||||
* 修复后:退药明细与汇总扣减在同一事务内执行,保证库存与单据强一致。
|
||||
* 退药处理(逻辑同发药,保持明细与汇总同步)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -68,23 +68,15 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
||||
throw new IllegalArgumentException("drugList cannot be null or empty");
|
||||
}
|
||||
|
||||
// 校验是否已发药,防止未发药直接退药导致负库存或账务异常
|
||||
Integer dispensedFlag = drugMapper.selectDispensedFlag(orderId);
|
||||
if (dispensedFlag == null || dispensedFlag != 1) {
|
||||
throw new IllegalStateException("Order has not been dispensed yet, cannot return drugs.");
|
||||
}
|
||||
|
||||
for (Map<String, Object> drugInfo : drugList) {
|
||||
Long drugId = ((Number) drugInfo.get("drugId")).longValue();
|
||||
Integer quantity = ((Number) drugInfo.get("quantity")).intValue();
|
||||
String operator = (String) drugInfo.get("operator");
|
||||
|
||||
// 退药数量转为负数参与累计
|
||||
int returnQty = -Math.abs(quantity);
|
||||
// 1. 先写入退药明细
|
||||
drugMapper.insertDrugReturnDetail(orderId, drugId, returnQty, operator);
|
||||
// 2. 同步扣减汇总单数量
|
||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, returnQty);
|
||||
// 退药明细(数量存负数)
|
||||
drugMapper.insertDrugReturnDetail(orderId, drugId, quantity, operator);
|
||||
// 汇总单同步扣减
|
||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, -quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user