Fix Bug #503: fallback修复
This commit is contained in:
@@ -52,31 +52,27 @@ public interface InpatientDrugMapper {
|
||||
@Param("operator") String operator);
|
||||
|
||||
/**
|
||||
* 汇总发药/退药数量(UPSERT)。
|
||||
* 汇总单 UPSERT:累计药品发放/退药数量
|
||||
*
|
||||
* 表结构示例(仅供参考):
|
||||
* 表结构(示例):
|
||||
* inpatient_drug_dispense_summary
|
||||
* - id (PK, 自增)
|
||||
* - order_id
|
||||
* - drug_id
|
||||
* - total_quantity (累计正负数量)
|
||||
* - last_update_time
|
||||
* - order_id BIGINT
|
||||
* - drug_id BIGINT
|
||||
* - total_quantity INT // 正负累计
|
||||
* - update_time DATETIME
|
||||
*
|
||||
* 该 SQL 在不存在对应汇总记录时 INSERT,存在时 UPDATE total_quantity。
|
||||
* 主键 (order_id, drug_id) 用于 ON DUPLICATE KEY UPDATE。
|
||||
*
|
||||
* @param orderId 医嘱ID
|
||||
* @param drugId 药品ID
|
||||
* @param quantity 本次操作的数量(正数为发药,负数为退药)
|
||||
* @param quantity 本次发药或退药数量(正负均可)
|
||||
*/
|
||||
@Insert({
|
||||
"<script>",
|
||||
"INSERT INTO inpatient_drug_dispense_summary (order_id, drug_id, total_quantity, last_update_time) ",
|
||||
"VALUES (#{orderId}, #{drugId}, #{quantity}, NOW()) ",
|
||||
"ON DUPLICATE KEY UPDATE ",
|
||||
"total_quantity = total_quantity + #{quantity}, ",
|
||||
"last_update_time = NOW()",
|
||||
"</script>"
|
||||
})
|
||||
@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()")
|
||||
int upsertDrugDispenseSummary(@Param("orderId") Long orderId,
|
||||
@Param("drugId") Long drugId,
|
||||
@Param("quantity") Integer quantity);
|
||||
|
||||
@@ -50,16 +50,16 @@ public class InpatientDrugServiceImpl implements InpatientDrugService {
|
||||
Integer quantity = (Integer) drug.get("quantity");
|
||||
String operator = (String) drug.get("operator");
|
||||
|
||||
// 明细记录(正向数量)
|
||||
// 插入明细(正向数量)
|
||||
drugMapper.insertDrugDispenseDetail(orderId, drugId, quantity, operator);
|
||||
|
||||
// 汇总单累计(正向数量)
|
||||
// 更新/插入汇总单(正向累计)
|
||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退药(数量为负数,业务同样先写明细后更新汇总)
|
||||
* 退药(数量为负数)
|
||||
*
|
||||
* @param orderId 医嘱主键
|
||||
* @param drugList 每种药品的退药信息,键包括 drugId、quantity(正数表示退药量)、operator 等
|
||||
@@ -69,14 +69,14 @@ 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");
|
||||
|
||||
// 退药明细使用负数保存
|
||||
// 退药数量以负数保存到明细表
|
||||
int negativeQty = -Math.abs(quantity);
|
||||
drugMapper.insertDrugReturnDetail(orderId, drugId, negativeQty, operator);
|
||||
|
||||
// 汇总单累计负数
|
||||
// 汇总单同样使用负数累计
|
||||
drugMapper.upsertDrugDispenseSummary(orderId, drugId, negativeQty);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user