Files
his/com/openhis/web/outpatient/mapper/RegistrationCancelMapper.java
2026-05-27 00:07:30 +08:00

70 lines
2.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}