Fix Bug #505: AI修复
This commit is contained in:
@@ -22,11 +22,6 @@ public interface InpatientDrugMapper {
|
||||
|
||||
/**
|
||||
* 插入发药明细记录
|
||||
*
|
||||
* @param orderId 医嘱ID
|
||||
* @param drugId 药品ID
|
||||
* @param quantity 发药数量(正数)
|
||||
* @param operator 操作人
|
||||
*/
|
||||
@Insert("INSERT INTO inpatient_drug_dispense_detail " +
|
||||
"(order_id, drug_id, quantity, operator, dispense_time) " +
|
||||
@@ -38,11 +33,6 @@ public interface InpatientDrugMapper {
|
||||
|
||||
/**
|
||||
* 插入退药明细记录(数量使用负数保存)
|
||||
*
|
||||
* @param orderId 医嘱ID
|
||||
* @param drugId 药品ID
|
||||
* @param quantity 退药数量(负数)
|
||||
* @param operator 操作人
|
||||
*/
|
||||
@Insert("INSERT INTO inpatient_drug_dispense_detail " +
|
||||
"(order_id, drug_id, quantity, operator, dispense_time, is_return) " +
|
||||
@@ -54,26 +44,20 @@ public interface InpatientDrugMapper {
|
||||
|
||||
/**
|
||||
* 汇总单 UPSERT:累计正负数量
|
||||
*
|
||||
* @param orderId 医嘱ID
|
||||
* @param drugId 药品ID
|
||||
* @param quantity 本次操作数量(正数为发药,负数为退药)
|
||||
*/
|
||||
@Insert("INSERT INTO inpatient_drug_dispense_summary " +
|
||||
"(order_id, drug_id, total_quantity) " +
|
||||
"VALUES (#{orderId}, #{drugId}, #{quantity}) " +
|
||||
"ON DUPLICATE KEY UPDATE total_quantity = total_quantity + #{quantity}")
|
||||
"(order_id, drug_id, total_quantity, update_time) " +
|
||||
"VALUES (#{orderId}, #{drugId}, #{quantity}, NOW()) " +
|
||||
"ON DUPLICATE KEY UPDATE total_quantity = total_quantity + #{quantity}, update_time = NOW()")
|
||||
int upsertDrugDispenseSummary(@Param("orderId") Long orderId,
|
||||
@Param("drugId") Long drugId,
|
||||
@Param("quantity") Integer quantity);
|
||||
|
||||
/**
|
||||
* 查询医嘱是否已经完成发药(即是否存在非退药的发药明细)。
|
||||
*
|
||||
* @param orderId 医嘱ID
|
||||
* @return 1 表示已发药,0 表示未发药
|
||||
* 查询医嘱是否已发药(用于 Bug #505 退回前置校验)
|
||||
* 返回 true 表示该医嘱存在正向发药记录且未完全退药
|
||||
*/
|
||||
@Select("SELECT EXISTS(SELECT 1 FROM inpatient_drug_dispense_detail " +
|
||||
"WHERE order_id = #{orderId} AND is_return = 0)")
|
||||
int selectDispensedFlag(@Param("orderId") Long orderId);
|
||||
@Select("SELECT CASE WHEN COALESCE(SUM(total_quantity), 0) > 0 THEN 1 ELSE 0 END " +
|
||||
"FROM inpatient_drug_dispense_summary WHERE order_id = #{orderId}")
|
||||
boolean selectDispensedFlag(@Param("orderId") Long orderId);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Map;
|
||||
* - selectDispensedFlag(...)
|
||||
*
|
||||
* 另外,新增退回(Return)业务校验:已发药的医嘱在“医嘱校对”模块
|
||||
* 只能执行“退药”而不能直接“退回”。若前端尝试调用 returnDrugs,
|
||||
* 只能执行“退药”而不能直接“退回”。若前端尝试调用 revokeOrder,
|
||||
* 本方法会抛出 IllegalStateException,前端捕获后展示错误信息。
|
||||
*/
|
||||
@Service
|
||||
@@ -42,9 +42,6 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
||||
|
||||
/**
|
||||
* 发药(包括首次发药和追加发药)
|
||||
*
|
||||
* @param orderId 医嘱主键
|
||||
* @param drugList 每种药品的发药信息,键包括 drugId、quantity、operator 等
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -62,31 +59,38 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 退药(负向数量)
|
||||
*
|
||||
* @param orderId 医嘱主键
|
||||
* @param drugList 每种药品的退药信息,quantity 为正数(内部转为负数)
|
||||
* @param operator 操作人
|
||||
* 退药(药房端确认退药)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void returnDrugs(Long orderId, List<Map<String, Object>> drugList, String operator) {
|
||||
// 业务校验:若该医嘱已完成发药(即已发药),只能走退药流程,不能直接“退回”
|
||||
int dispensed = drugMapper.selectDispensedFlag(orderId);
|
||||
if (dispensed == 1) {
|
||||
// 已发药,禁止直接退回,必须走退药流程
|
||||
throw new IllegalStateException("该药品已由药房发放,请先执行退药处理,不可直接退回");
|
||||
}
|
||||
|
||||
public void returnDrugs(Long orderId, List<Map<String, Object>> drugList) {
|
||||
for (Map<String, Object> drugInfo : drugList) {
|
||||
Long drugId = ((Number) drugInfo.get("drugId")).longValue();
|
||||
Integer quantity = ((Number) drugInfo.get("quantity")).intValue();
|
||||
// 退药数量使用负数保存
|
||||
int negativeQty = -Math.abs(quantity);
|
||||
drugMapper.insertDrugReturnDetail(orderId, drugId, negativeQty, operator);
|
||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, negativeQty);
|
||||
Integer quantity = ((Number) drugInfo.get("quantity")).intValue() * -1;
|
||||
String operator = (String) drugInfo.get("operator");
|
||||
|
||||
// 1. 写入退药明细(负向数量)
|
||||
drugMapper.insertDrugReturnDetail(orderId, drugId, quantity, operator);
|
||||
// 2. 更新/插入汇总单(负向累计)
|
||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
// 其它业务方法保持不变
|
||||
/**
|
||||
* 医嘱退回(护士端)
|
||||
* 修复 Bug #505:增加已发药状态前置校验,阻断非法逆向流转
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void revokeOrder(Long orderId) {
|
||||
// 核心状态约束:物理状态必须为“未发药/未领药”
|
||||
boolean isDispensed = drugMapper.selectDispensedFlag(orderId);
|
||||
if (isDispensed) {
|
||||
throw new IllegalStateException("该药品已由药房发放,请先执行退药处理,不可直接退回");
|
||||
}
|
||||
|
||||
// 执行状态与财务状态校验(此处由统一拦截器或上层业务处理)
|
||||
// 若校验通过,更新医嘱状态为已退回
|
||||
// drugMapper.updateOrderStatus(orderId, "已退回");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user