Fix Bug #506: AI修复
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.openhis.web.outpatient.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 门诊挂号退号核心数据操作 Mapper
|
||||
* 修复 Bug #506:确保退号后多表状态变更严格对齐 PRD 定义
|
||||
*/
|
||||
@Mapper
|
||||
public interface RegistrationCancelMapper {
|
||||
|
||||
/**
|
||||
* 更新订单主表状态
|
||||
* 修复点:status=0(已取消), pay_status=3(已退费), cancel_time使用DB 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 id = #{slotId}")
|
||||
int rollbackSlotStatus(@Param("slotId") Long slotId);
|
||||
|
||||
/**
|
||||
* 更新号源池统计与版本
|
||||
* 修复点:booked_num = booked_num - 1, version = version + 1 (修正历史版本中字段赋值颠倒及version未累加问题)
|
||||
*/
|
||||
@Update("UPDATE adm_schedule_pool SET booked_num = booked_num - 1, version = version + 1 WHERE id = #{poolId}")
|
||||
int updatePoolVersionAndBookedNum(@Param("poolId") Long poolId);
|
||||
|
||||
/**
|
||||
* 插入退费流水日志
|
||||
* 修复点:order_id 严格取值于 order_main.id,保障后台财务对账链路完整
|
||||
*/
|
||||
@Insert("INSERT INTO refund_log (order_id, refund_amount, refund_time, operator, status) " +
|
||||
"VALUES (#{orderId}, #{refundAmount}, NOW(), #{operator}, 1)")
|
||||
int insertRefundLog(@Param("orderId") Long orderId,
|
||||
@Param("refundAmount") BigDecimal refundAmount,
|
||||
@Param("operator") String operator);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.openhis.web.outpatient.service;
|
||||
|
||||
import com.openhis.web.outpatient.mapper.RegistrationCancelMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 门诊挂号退号服务实现
|
||||
* 修复 Bug #506:重构退号事务逻辑,确保多表状态原子性变更与 PRD 定义完全一致
|
||||
*/
|
||||
@Service
|
||||
public class RegistrationCancelServiceImpl implements RegistrationCancelService {
|
||||
|
||||
private final RegistrationCancelMapper cancelMapper;
|
||||
|
||||
public RegistrationCancelServiceImpl(RegistrationCancelMapper cancelMapper) {
|
||||
this.cancelMapper = cancelMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelRegistration(Long orderId, Long slotId, Long poolId, BigDecimal refundAmount, String operator) {
|
||||
if (orderId == null || slotId == null || poolId == null) {
|
||||
throw new IllegalArgumentException("退号核心参数缺失:orderId, slotId, poolId 均不可为空");
|
||||
}
|
||||
|
||||
// 1. 更新订单主表:状态置为已取消,支付状态置为已退费,记录精准取消时间与标准原因
|
||||
cancelMapper.updateOrderStatus(orderId);
|
||||
|
||||
// 2. 记录退费日志:强制关联 order_main.id,打通财务对账数据链
|
||||
cancelMapper.insertRefundLog(orderId, refundAmount, operator);
|
||||
|
||||
// 3. 释放号源:状态回滚至待约,清空关联订单ID,允许号源重新进入预约池
|
||||
cancelMapper.rollbackSlotStatus(slotId);
|
||||
|
||||
// 4. 更新号源池:已约数减1,乐观锁版本号加1,防止并发超卖并修正历史版本字段错位问题
|
||||
cancelMapper.updatePoolVersionAndBookedNum(poolId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user