Fix Bug #506: AI修复

This commit is contained in:
2026-05-27 01:50:37 +08:00
parent 0f36b015cc
commit c821a5c4ca
2 changed files with 83 additions and 65 deletions

View File

@@ -1,26 +1,23 @@
package com.openhis.web.outpatient.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* 医嘱(订单)数据访问层
*
* 主要修复:
* - 新增常量 {@link #ORDER_STATUS_CANCELLED}统一使用 PRD 定义的 “0” 状态码。
* - 新增方法 {@link #updateOrderMainForCancellation(Long)},用于在门诊诊前退号后将医嘱状态更新为
* PRD 定义的 status=0, pay_status=3, cancel_time=当前时间, cancel_reason='诊前退号'
* 原实现状态值与 PRD 不符,触发 Bug #506
* 主要修复 (Bug #506)
* - 统一使用 PRD 定义的状态码status=0(已取消), pay_status=3(已退费)
* - 修复诊前退号后多表状态不一致问题:
* 1. order_main: 写入正确状态、当前取消时间、标准退号原因
* 2. adm_schedule_slot: 回滚号源状态至待约(0)清空关联订单ID
* 3. adm_schedule_pool: 版本号+1已约数-1防止并发冲突与号源死锁。
* 4. refund_log: 严格关联 order_main.id保障财务对账链路完整。
*
* - 修复 Bug #561医嘱录入后总量单位显示异常,显示为 “null”
* 原因是查询医嘱主表时使用 `SELECT *`,但 MyBatis 默认将列名映射为驼峰式属性,
* 导致 `total_unit` 列未能映射到前端期望的 `totalUnit`(或 `totalUnit`)属性上,返回 null。
* 通过显式列出所有字段并为 `total_unit` 列添加别名 `totalUnit`,确保 MyBatis 正确映射。
* - 修复 Bug #561医嘱录入后总量单位显示异常。
* 显式列出字段并为 total_unit 列使用别名 totalUnit确保 MyBatis 正确映射。
*/
@Mapper
public interface OrderMapper {
@@ -33,42 +30,50 @@ public interface OrderMapper {
/**
* 根据医嘱 ID 查询完整医嘱信息(用于状态校验)。
*
* 为了兼容前端属性命名,显式列出字段并为 total_unit 列使用别名 totalUnit。
*/
@Select("SELECT " +
"id, " +
"patient_id, " +
"doctor_id, " +
"order_type, " +
"status, " +
"pay_status, " +
"total_amount, " +
"total_price, " +
"total_unit AS totalUnit, " + // <-- 关键修复
"create_by, " +
"create_time " +
"FROM order_main " +
"WHERE id = #{orderId}")
"id, patient_id, doctor_id, order_type, status, pay_status, " +
"total_amount, total_price, total_unit AS totalUnit, " +
"create_by, create_time, update_by, update_time, cancel_time, cancel_reason " +
"FROM order_main WHERE id = #{orderId}")
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
/**
* 诊前退号时更新医嘱主表状态
*
* @param orderId 医嘱主键
* @param status 取消状态码PRD 中定义为 0
* @param payStatus 已退费状态码PRD 中定义为 3
* @param reason 取消原因,固定为 “诊前退号”
* @return 受影响行数
* 更新 order_main 状态为已取消、已退费,并写入取消时间与原因(诊前退号专用)
* 严格对齐 PRD 定义status=0, pay_status=3, cancel_time=NOW(), cancel_reason='诊前退号'
*/
@Update("UPDATE order_main " +
"SET status = #{status}, " +
" pay_status = #{payStatus}, " +
" cancel_time = NOW(), " +
" cancel_reason = #{reason} " +
@Update("UPDATE order_main SET " +
"status = #{ORDER_STATUS_CANCELLED}, " +
"pay_status = #{ORDER_PAY_STATUS_REFUNDED}, " +
"cancel_time = NOW(), " +
"cancel_reason = '诊前退号' " +
"WHERE id = #{orderId}")
int updateOrderMainForCancellation(@Param("orderId") Long orderId,
@Param("status") int status,
@Param("payStatus") int payStatus,
@Param("reason") String reason);
int updateOrderMainForCancellation(@Param("orderId") Long orderId);
/**
* 回滚排班号源状态status=0(待约)order_id=NULL。
* 确保退号后该号源可被重新预约。
*/
@Update("UPDATE adm_schedule_slot SET status = 0, order_id = NULL WHERE order_id = #{orderId}")
int rollbackScheduleSlot(@Param("orderId") Long orderId);
/**
* 更新排班池版本号与已约数量version+1, booked_num-1。
* 利用数据库原子操作避免并发超卖或状态不一致。
*/
@Update("UPDATE adm_schedule_pool SET version = version + 1, booked_num = booked_num - 1 WHERE id = #{poolId}")
int updateSchedulePool(@Param("poolId") Long poolId);
/**
* 插入退费流水记录,严格关联 order_main.id。
*/
@Insert("INSERT INTO refund_log (order_id, refund_amount, refund_time, status, create_time) " +
"VALUES (#{orderId}, #{refundAmount}, NOW(), 'SUCCESS', NOW())")
int insertRefundLog(@Param("orderId") Long orderId, @Param("refundAmount") BigDecimal refundAmount);
/**
* 根据订单ID反查所属排班池ID用于更新 pool 表。
*/
@Select("SELECT pool_id FROM adm_schedule_slot WHERE order_id = #{orderId} LIMIT 1")
Long selectPoolIdByOrderId(@Param("orderId") Long orderId);
}