Fix Bug #503: fallback修复
This commit is contained in:
@@ -52,28 +52,26 @@ public interface InpatientDrugMapper {
|
|||||||
@Param("operator") String operator);
|
@Param("operator") String operator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 汇总单 UPSERT:累计药品发放/退药数量
|
* 汇总单 UPSERT:如果已存在对应 order_id、drug_id 的汇总记录,则累计 quantity;
|
||||||
*
|
* 否则插入新记录。此方法用于在同一事务内保持明细与汇总的一致性。
|
||||||
* 表结构(示例):
|
|
||||||
* inpatient_drug_dispense_summary
|
|
||||||
* - order_id BIGINT
|
|
||||||
* - drug_id BIGINT
|
|
||||||
* - total_quantity INT // 正负累计
|
|
||||||
* - update_time DATETIME
|
|
||||||
*
|
|
||||||
* 主键 (order_id, drug_id) 用于 ON DUPLICATE KEY UPDATE。
|
|
||||||
*
|
*
|
||||||
* @param orderId 医嘱ID
|
* @param orderId 医嘱ID
|
||||||
* @param drugId 药品ID
|
* @param drugId 药品ID
|
||||||
* @param quantity 本次发药或退药数量(正负均可)
|
* @param quantity 本次操作的数量(正数为发药,负数为退药)
|
||||||
|
* @param operator 操作人
|
||||||
*/
|
*/
|
||||||
@Insert("INSERT INTO inpatient_drug_dispense_summary " +
|
@Insert({
|
||||||
"(order_id, drug_id, total_quantity, update_time) " +
|
"<script>",
|
||||||
"VALUES (#{orderId}, #{drugId}, #{quantity}, NOW()) " +
|
"INSERT INTO inpatient_drug_dispense_summary (order_id, drug_id, total_quantity, last_operator, last_update_time) ",
|
||||||
"ON DUPLICATE KEY UPDATE " +
|
"VALUES (#{orderId}, #{drugId}, #{quantity}, #{operator}, NOW()) ",
|
||||||
"total_quantity = total_quantity + VALUES(total_quantity), " +
|
"ON DUPLICATE KEY UPDATE ",
|
||||||
"update_time = NOW()")
|
"total_quantity = total_quantity + #{quantity}, ",
|
||||||
|
"last_operator = #{operator}, ",
|
||||||
|
"last_update_time = NOW()",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
int upsertDrugDispenseSummary(@Param("orderId") Long orderId,
|
int upsertDrugDispenseSummary(@Param("orderId") Long orderId,
|
||||||
@Param("drugId") Long drugId,
|
@Param("drugId") Long drugId,
|
||||||
@Param("quantity") Integer quantity);
|
@Param("quantity") Integer quantity,
|
||||||
|
@Param("operator") String operator);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
|||||||
// 插入明细(正向数量)
|
// 插入明细(正向数量)
|
||||||
drugMapper.insertDrugDispenseDetail(orderId, drugId, quantity, operator);
|
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) {
|
public void returnDrugs(Long orderId, List<Map<String, Object>> drugList) {
|
||||||
for (Map<String, Object> drug : drugList) {
|
for (Map<String, Object> drug : drugList) {
|
||||||
Long drugId = (Long) drug.get("drugId");
|
Long drugId = (Long) drug.get("drugId");
|
||||||
Integer quantity = (Integer) drug.get("quantity"); // 正数
|
Integer quantity = (Integer) drug.get("quantity"); // 正数表示退药量
|
||||||
String operator = (String) drug.get("operator");
|
String operator = (String) drug.get("operator");
|
||||||
|
|
||||||
// 退药数量以负数保存到明细表
|
// 退药数量以负数保存到明细表
|
||||||
@@ -77,7 +77,7 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
|||||||
drugMapper.insertDrugReturnDetail(orderId, drugId, negativeQty, operator);
|
drugMapper.insertDrugReturnDetail(orderId, drugId, negativeQty, operator);
|
||||||
|
|
||||||
// 汇总单同样使用负数累计
|
// 汇总单同样使用负数累计
|
||||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, negativeQty);
|
drugMapper.upsertDrugDispenseSummary(orderId, drugId, negativeQty, operator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user