Files
his/com/openhis/web/outpatient/mapper/RegistrationCancelMapper.java
2026-05-27 00:05:18 +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 定义
*
* 新增:支付成功后号源状态流转为“已取”(status=3)的更新方法。
*/
@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 = (SELECT pool_id FROM adm_schedule_slot WHERE order_id = #{orderId} LIMIT 1)")
int updatePoolAfterCancel(@Param("orderId") Long orderId);
/**
* 支付成功后,将号源状态置为“已取”(status=3)
*
* @param orderId 关联的挂号订单ID
* @return 更新行数
*/
@Update("UPDATE adm_schedule_slot " +
"SET status = 3 " + // 3 表示已取
"WHERE order_id = #{orderId}")
int updateSlotStatusToTaken(@Param("orderId") Long orderId);
}