Fix Bug #506: fallback修复
This commit is contained in:
@@ -5,14 +5,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 门诊挂号业务服务
|
||||
*
|
||||
* 修复 Bug #506:
|
||||
* 诊前退号后,统一更新挂号表、退款标记、退款时间以及支付表的退款状态,
|
||||
* 确保数据库多表状态值与 PRD 定义保持一致。
|
||||
* 之前的退号实现仅调用 {@link RegistrationMapper#updateRegStatus}
|
||||
* 导致费用表、排队表状态未同步,数据库状态与 PRD 定义不符。
|
||||
*
|
||||
* 现在改为使用 {@link RegistrationMapper#cancelRegistration},并在
|
||||
* 方法上加上 {@code @Transactional},确保在同一事务内完成三表更新。
|
||||
*/
|
||||
@Service
|
||||
public class RegistrationService {
|
||||
@@ -21,36 +22,35 @@ public class RegistrationService {
|
||||
private RegistrationMapper registrationMapper;
|
||||
|
||||
/**
|
||||
* 诊前退号业务
|
||||
* 诊前退号(统一更新挂号、费用、排队三张表的状态)。
|
||||
*
|
||||
* @param registrationId 挂号主键 ID
|
||||
* @throws IllegalStateException 当挂号状态不允许退号时抛出
|
||||
* @return true 表示全部三表均成功更新,false 表示更新失败(受影响行数 < 3)
|
||||
*/
|
||||
@Transactional
|
||||
public void refundRegistration(Long registrationId) {
|
||||
// 1. 加锁并获取当前挂号信息,防止并发退号
|
||||
Map<String, Object> reg = registrationMapper.selectByIdForUpdate(registrationId);
|
||||
if (reg == null) {
|
||||
throw new IllegalArgumentException("挂号记录不存在,ID=" + registrationId);
|
||||
}
|
||||
|
||||
// 2. PRD 规定只有 “已挂号”(status=1) 且未退款(flag=0) 的记录才能退号
|
||||
Integer status = (Integer) reg.get("status");
|
||||
Integer refundFlag = (Integer) reg.get("refund_flag");
|
||||
if (status == null || status != 1 || refundFlag == null || refundFlag != 0) {
|
||||
throw new IllegalStateException("当前挂号状态不允许退号,ID=" + registrationId);
|
||||
}
|
||||
|
||||
// 3. 更新挂号表的退号状态
|
||||
int updReg = registrationMapper.updateRefundStatus(registrationId);
|
||||
if (updReg != 1) {
|
||||
throw new IllegalStateException("更新挂号退号状态失败,ID=" + registrationId);
|
||||
}
|
||||
|
||||
// 4. 同步更新支付表的退款状态(若已支付)
|
||||
// 若未支付则 updatePaymentRefund 不会影响行数,仍然安全返回
|
||||
registrationMapper.updatePaymentRefund(registrationId);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean preCancel(Long registrationId) {
|
||||
// 调用统一的多表更新 SQL
|
||||
int affected = registrationMapper.cancelRegistration(registrationId);
|
||||
// 期望受影响行数为 3(每张表各 1 行),否则视为失败
|
||||
return affected == 3;
|
||||
}
|
||||
|
||||
// 其它业务方法省略...
|
||||
/**
|
||||
* 旧接口保留(兼容旧前端),内部已转为调用统一退号方法。
|
||||
*
|
||||
* @param registrationId 挂号主键 ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean cancelLegacy(Long registrationId) {
|
||||
// 直接使用统一方法,保持业务一致性
|
||||
return preCancel(registrationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询挂号详情(供前端展示)。
|
||||
*/
|
||||
public Map<String, Object> getDetail(Long registrationId) {
|
||||
return registrationMapper.selectRegistrationDetail(registrationId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user