Fix Bug #503: AI修复
This commit is contained in:
@@ -32,7 +32,7 @@ public interface DispenseMapper {
|
||||
*
|
||||
* 业务说明:
|
||||
* - 汇总单表 his_inpatient_dispense_summary 中维护累计发药数量 total_quantity
|
||||
* 以及发药状态 status(NONE、PARTIAL、COMPLETED)。
|
||||
* 以及发药状态 status(PARTIAL、COMPLETED)。
|
||||
* - 本方法在同事务内执行,使用传入的 quantity(正数/负数)直接累加到 total_quantity,
|
||||
* 并根据累计值与订单需求量进行状态判定,避免原来通过异步任务或触发器延迟更新导致的时机不一致。
|
||||
*
|
||||
@@ -43,12 +43,13 @@ public interface DispenseMapper {
|
||||
"<script>",
|
||||
"UPDATE his_inpatient_dispense_summary",
|
||||
"SET total_quantity = total_quantity + #{quantity},",
|
||||
// 根据累计数量判断状态
|
||||
" status = CASE",
|
||||
" WHEN total_quantity + #{quantity} = 0 THEN 'NONE'",
|
||||
" WHEN total_quantity + #{quantity} < required_quantity THEN 'PARTIAL'",
|
||||
" ELSE 'COMPLETED'",
|
||||
" END",
|
||||
"WHERE dispense_id = #{dispenseId}",
|
||||
" END",
|
||||
"WHERE id = #{dispenseId}",
|
||||
"</script>"
|
||||
})
|
||||
void updateSummaryAfterDetail(@Param("dispenseId") Long dispenseId,
|
||||
|
||||
@@ -58,11 +58,13 @@ public class DispenseServiceImpl {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, Object> returnDrug(Long dispenseId, Integer quantity) {
|
||||
// 1. 写入退药明细(负数表示退药)
|
||||
dispenseMapper.insertDetail(dispenseId, -quantity);
|
||||
int returnQty = -Math.abs(quantity);
|
||||
dispenseMapper.insertDetail(dispenseId, returnQty);
|
||||
|
||||
// 2. 同步更新汇总单统计
|
||||
dispenseMapper.updateSummaryAfterDetail(dispenseId, -quantity);
|
||||
// 2. 同步更新汇总单统计(在同事务内完成,确保时机一致)
|
||||
dispenseMapper.updateSummaryAfterDetail(dispenseId, returnQty);
|
||||
|
||||
// 3. 返回统一结构
|
||||
return Map.of("code", 0, "msg", "退药成功");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user