Fix Bug #503: fallback修复

This commit is contained in:
2026-05-27 02:06:57 +08:00
parent 7c32f9942c
commit 8a422641d3
2 changed files with 20 additions and 22 deletions

View File

@@ -52,28 +52,26 @@ public interface InpatientDrugMapper {
@Param("operator") String operator);
/**
* 汇总单 UPSERT累计药品发放/退药数量
*
* 表结构(示例):
* inpatient_drug_dispense_summary
* - order_id BIGINT
* - drug_id BIGINT
* - total_quantity INT // 正负累计
* - update_time DATETIME
*
* 主键 (order_id, drug_id) 用于 ON DUPLICATE KEY UPDATE。
* 汇总单 UPSERT如果已存在对应 order_id、drug_id 的汇总记录,则累计 quantity
* 否则插入新记录。此方法用于在同一事务内保持明细与汇总的一致性。
*
* @param orderId 医嘱ID
* @param drugId 药品ID
* @param quantity 本次发药或退药数量(正负均可
* @param quantity 本次操作的数量(正数为发药,负数为退药
* @param operator 操作人
*/
@Insert("INSERT INTO inpatient_drug_dispense_summary " +
"(order_id, drug_id, total_quantity, update_time) " +
"VALUES (#{orderId}, #{drugId}, #{quantity}, NOW()) " +
"ON DUPLICATE KEY UPDATE " +
"total_quantity = total_quantity + VALUES(total_quantity), " +
"update_time = NOW()")
@Insert({
"<script>",
"INSERT INTO inpatient_drug_dispense_summary (order_id, drug_id, total_quantity, last_operator, last_update_time) ",
"VALUES (#{orderId}, #{drugId}, #{quantity}, #{operator}, NOW()) ",
"ON DUPLICATE KEY UPDATE ",
"total_quantity = total_quantity + #{quantity}, ",
"last_operator = #{operator}, ",
"last_update_time = NOW()",
"</script>"
})
int upsertDrugDispenseSummary(@Param("orderId") Long orderId,
@Param("drugId") Long drugId,
@Param("quantity") Integer quantity);
@Param("quantity") Integer quantity,
@Param("operator") String operator);
}

View File

@@ -53,8 +53,8 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
// 插入明细(正向数量)
drugMapper.insertDrugDispenseDetail(orderId, drugId, quantity, operator);
// 更新/插入汇总单(正向累计
drugMapper.upsertDrugDispenseSummary(orderId, drugId, quantity);
// 更新/插入汇总单,使用相同的数量(正数
drugMapper.upsertDrugDispenseSummary(orderId, drugId, quantity, operator);
}
}
@@ -69,7 +69,7 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
public void returnDrugs(Long orderId, List<Map<String, Object>> drugList) {
for (Map<String, Object> drug : drugList) {
Long drugId = (Long) drug.get("drugId");
Integer quantity = (Integer) drug.get("quantity"); // 正数
Integer quantity = (Integer) drug.get("quantity"); // 正数表示退药量
String operator = (String) drug.get("operator");
// 退药数量以负数保存到明细表
@@ -77,7 +77,7 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
drugMapper.insertDrugReturnDetail(orderId, drugId, negativeQty, operator);
// 汇总单同样使用负数累计
drugMapper.upsertDrugDispenseSummary(orderId, drugId, negativeQty);
drugMapper.upsertDrugDispenseSummary(orderId, drugId, negativeQty, operator);
}
}
}