Fix Bug #503: fallback修复
This commit is contained in:
@@ -1,39 +1,57 @@
|
||||
package com.openhis.web.inpatient.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 住院发药相关数据访问层
|
||||
* 住院发退药数据访问层
|
||||
*
|
||||
* 新增:
|
||||
* 1. {@code updateDispenseSummaryStatus(Long)}:在发药明细完成后,将对应的发药汇总单状态
|
||||
* 更新为 “已完成”。该方法用于解决 Bug #503 中发药明细与发药汇总单状态不同步的问题。
|
||||
*
|
||||
* 说明:
|
||||
* - 发药汇总单表名为 {@code inpatient_dispense_summary},状态字段为 {@code status}。
|
||||
* - 状态值 {@code COMPLETED} 与 PRD 中定义保持一致。
|
||||
* 为了解决 Bug #503,新增两条 SQL:
|
||||
* 1. {@link #insertDetail(Long, Integer)} – 写入发/退药明细。
|
||||
* 2. {@link #updateSummaryAfterDetail(Long, Integer)} – 在同一事务内同步更新
|
||||
* 汇总单的累计数量、状态等字段,确保明细与汇总单的触发时机保持一致。
|
||||
*/
|
||||
@Mapper
|
||||
public interface DispenseMapper {
|
||||
|
||||
/** 发药汇总单已完成状态(与 PRD 保持一致) */
|
||||
String SUMMARY_STATUS_COMPLETED = "COMPLETED";
|
||||
/**
|
||||
* 插入发药(或退药)明细记录。
|
||||
*
|
||||
* @param dispenseId 发药单主键
|
||||
* @param quantity 本次(正数为发药,负数为退药)数量
|
||||
*/
|
||||
@Insert("INSERT INTO his_inpatient_dispense_detail (dispense_id, quantity, create_time) " +
|
||||
"VALUES (#{dispenseId}, #{quantity}, NOW())")
|
||||
void insertDetail(@Param("dispenseId") Long dispenseId,
|
||||
@Param("quantity") Integer quantity);
|
||||
|
||||
/**
|
||||
* 将对应住院订单的发药汇总单状态更新为已完成。
|
||||
* 同步更新汇总单统计信息。
|
||||
*
|
||||
* @param orderId 住院医嘱主键
|
||||
* @return 更新记录数,通常为 1
|
||||
* 业务说明:
|
||||
* - 汇总单表 his_inpatient_dispense_summary 中维护累计发药数量 total_quantity
|
||||
* 以及发药状态 status(PARTIAL、COMPLETED)。
|
||||
* - 本方法在同事务内执行,使用传入的 quantity(正数/负数)直接累加到 total_quantity,
|
||||
* 并根据累计值与订单需求量进行状态判定,避免原来通过异步任务或触发器延迟更新导致的时机不一致。
|
||||
*
|
||||
* @param dispenseId 发药单主键
|
||||
* @param quantity 本次(正数为发药,负数为退药)数量
|
||||
*/
|
||||
@Update({
|
||||
"<script>",
|
||||
"UPDATE inpatient_dispense_summary",
|
||||
"SET status = #{status}",
|
||||
"WHERE order_id = #{orderId}",
|
||||
"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 id = #{dispenseId}",
|
||||
"</script>"
|
||||
})
|
||||
int updateDispenseSummaryStatus(@Param("orderId") Long orderId,
|
||||
@Param("status") String status);
|
||||
void updateSummaryAfterDetail(@Param("dispenseId") Long dispenseId,
|
||||
@Param("quantity") Integer quantity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user