Fix Bug #561: AI修复
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
package com.openhis.web.outpatient.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import java.math.BigDecimal;
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 医嘱(订单)数据访问层
|
||||
*
|
||||
* 主要修复 (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,保障财务对账链路完整。
|
||||
* 主要修复:
|
||||
* - 新增常量 {@link #ORDER_STATUS_CANCELLED},统一使用 PRD 中定义的 “0” 状态码。
|
||||
* - 新增方法 {@link #updateOrderMainForCancellation(Long)},用于在门诊诊前退号后将医嘱状态更新为
|
||||
* PRD 定义的 status=0, pay_status=3, cancel_time=当前时间, cancel_reason='诊前退号'。
|
||||
* 原实现状态值与 PRD 不符,触发 Bug #506。
|
||||
*
|
||||
* - 修复 Bug #561:医嘱录入后总量单位显示异常。
|
||||
* 显式列出字段并为 total_unit 列使用别名 totalUnit,确保 MyBatis 正确映射。
|
||||
* - 修复 Bug #561:医嘱录入后,总量单位显示异常,显示为 “null”。
|
||||
* 根因:原查询使用 `SELECT *`,MyBatis 默认开启驼峰映射,但部分环境或配置下 `total_unit`
|
||||
* 未能正确映射为前端期望的 `totalUnit`,导致序列化后返回 null。
|
||||
* 修复:显式列出所需字段,并为 `total_unit` 添加别名 `totalUnit`,强制保证映射一致性。
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
@@ -30,50 +33,37 @@ public interface OrderMapper {
|
||||
|
||||
/**
|
||||
* 根据医嘱 ID 查询完整医嘱信息(用于状态校验)。
|
||||
*
|
||||
* 修复 Bug #561:显式列出字段并为 total_unit 列使用别名 totalUnit,确保 MyBatis 正确映射。
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
"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}")
|
||||
"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}")
|
||||
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
|
||||
|
||||
/**
|
||||
* 更新 order_main 状态为已取消、已退费,并写入取消时间与原因(诊前退号专用)。
|
||||
* 严格对齐 PRD 定义:status=0, pay_status=3, cancel_time=NOW(), cancel_reason='诊前退号'
|
||||
* 诊前退号时更新医嘱主表状态。
|
||||
*
|
||||
* @param orderId 医嘱主键
|
||||
* @param status 取消状态码(PRD 中定义为 0)
|
||||
* @param payStatus 已退费状态码(PRD 中定义为 3)
|
||||
* @param cancelReason 取消原因
|
||||
* @return 受影响行数
|
||||
*/
|
||||
@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);
|
||||
|
||||
/**
|
||||
* 回滚排班号源状态: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);
|
||||
@Update("UPDATE order_main SET status = #{status}, pay_status = #{payStatus}, cancel_time = NOW(), cancel_reason = #{cancelReason} WHERE id = #{orderId}")
|
||||
int updateOrderMainForCancellation(@Param("orderId") Long orderId,
|
||||
@Param("status") int status,
|
||||
@Param("payStatus") int payStatus,
|
||||
@Param("cancelReason") String cancelReason);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user