70 lines
2.4 KiB
Java
70 lines
2.4 KiB
Java
package com.openhis.web.outpatient.mapper;
|
||
|
||
import org.apache.ibatis.annotations.Insert;
|
||
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.math.BigDecimal;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 门诊退号数据访问层
|
||
* 修复 Bug #506:修正退号流程中多表状态更新 SQL,对齐 PRD 定义
|
||
*
|
||
* 新增:
|
||
* 1. updatePoolAfterCancel – 退号后更新排班池的 version 与 booked_num。
|
||
* 2. insertRefundLog – 记录退费日志,确保 refund_log 表状态与 PRD 定义保持一致。
|
||
*/
|
||
@Mapper
|
||
public interface RegistrationCancelMapper {
|
||
|
||
/**
|
||
* 查询号源关联的排班池ID
|
||
*/
|
||
@Select("SELECT id, pool_id, status, order_id FROM adm_schedule_slot WHERE order_id = #{orderId} LIMIT 1")
|
||
Map<String, Object> selectSlotByOrderId(@Param("orderId") Long orderId);
|
||
|
||
/**
|
||
* 更新订单主表状态
|
||
* 修复点:status=0, pay_status=3, cancel_time=NOW(), cancel_reason='诊前退号'
|
||
*/
|
||
@Update("UPDATE order_main " +
|
||
"SET status = 0, " +
|
||
" pay_status = 3, " +
|
||
" cancel_time = NOW(), " +
|
||
" cancel_reason = '诊前退号' " +
|
||
"WHERE id = #{orderId}")
|
||
int updateOrderStatus(@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 rollbackSlotStatus(@Param("orderId") Long orderId);
|
||
|
||
/**
|
||
* 更新排班池版本与已约数
|
||
* 修复点:version=version+1, booked_num=booked_num-1
|
||
*/
|
||
@Update("UPDATE adm_schedule_pool " +
|
||
"SET version = version + 1, " +
|
||
" booked_num = booked_num - 1 " +
|
||
"WHERE id = #{poolId}")
|
||
int updatePoolAfterCancel(@Param("poolId") Long poolId);
|
||
|
||
/**
|
||
* 插入退费日志
|
||
*/
|
||
@Insert("INSERT INTO refund_log (order_id, refund_amount, refund_time, remark) " +
|
||
"VALUES (#{orderId}, #{refundAmount}, NOW(), #{remark})")
|
||
int insertRefundLog(@Param("orderId") Long orderId,
|
||
@Param("refundAmount") BigDecimal refundAmount,
|
||
@Param("remark") String remark);
|
||
}
|