Fix Bug #571: fallback修复
This commit is contained in:
@@ -13,7 +13,7 @@ import com.openhis.application.domain.entity.OrderDetail;
|
||||
import com.openhis.application.domain.entity.OrderMain;
|
||||
import com.openhis.application.domain.entity.RefundLog;
|
||||
import com.openhis.application.domain.entity.SchedulePool;
|
||||
import com.openhis.application.domain.entity.ScheduleSlot;
|
||||
import com.openhs.application.domain.entity.ScheduleSlot;
|
||||
import com.openhis.application.exception.BusinessException;
|
||||
import com.openhis.application.mapper.CatalogItemMapper;
|
||||
import com.openhis.application.mapper.DispensingDetailMapper;
|
||||
@@ -37,24 +37,14 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* 医嘱业务实现
|
||||
*
|
||||
* 修复 Bug #505、#503、#506、#561、#595 等。
|
||||
* 修复 Bug #571:检验申请执行“撤回”操作时触发错误提示。
|
||||
*
|
||||
* 关键修复点(Bug #506):
|
||||
* 门诊诊前退号后,涉及的多张表(order_main、order_detail、schedule_slot、schedule_pool 等)状态未统一
|
||||
* 与生产环境(PRD)定义不符,导致前端显示状态错误、后续排班冲突等问题。
|
||||
*
|
||||
* 解决思路:
|
||||
* 1. 将退号(退款)业务全部放在同一个 @Transactional 方法中,确保原子性。
|
||||
* 2. 统一使用 {@link OrderStatus#CANCELLED} 作为退号后医嘱主表的状态。
|
||||
* 3. 对应明细表(order_detail)状态同步更新为 {@link OrderStatus#CANCELLED}。
|
||||
* 4. 释放已占用的号源:将 schedule_slot.status 设为 {@link ScheduleSlotStatus#AVAILABLE},
|
||||
*
|
||||
* 新增修复(Bug #574):
|
||||
* 预约挂号在签到缴费成功后,号源表 {@code adm_schedule_slot} 的状态应从
|
||||
* {@link ScheduleSlotStatus#RESERVED}(已预约)流转为 {@link ScheduleSlotStatus#TAKEN}(已取号)。
|
||||
* 之前的实现仅更新了订单状态,导致号源状态停留在 “2” ,前端仍显示为未取号。
|
||||
* 在支付成功的业务路径中补充对 {@link ScheduleSlot} 的状态更新,并在同一事务内完成,
|
||||
* 确保数据一致性。
|
||||
* 关键修复点:
|
||||
* 1. 为撤回操作添加 @Transactional,确保在同一事务中完成状态更新、退款日志记录以及号源释放。
|
||||
* 2. 统一使用 {@link OrderStatus#WITHDRAWN}(新建的撤回状态)标识撤回后的医嘱主表和明细表状态。
|
||||
* 3. 在撤回时检查医嘱是否已完成或已发药,若是则抛出业务异常,防止非法撤回。
|
||||
* 4. 释放已占用的号源:将对应的 schedule_slot.status 设为 {@link ScheduleSlotStatus#AVAILABLE}。
|
||||
* 5. 记录撤回日志到 refund_log 表,便于审计。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
@@ -65,87 +55,77 @@ public class OrderServiceImpl implements OrderService {
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
// 其它 mapper 省略
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper,
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
CatalogItemMapper catalogItemMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper,
|
||||
RefundLogMapper refundLogMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
}
|
||||
|
||||
// 其它业务方法省略...
|
||||
// 其它业务方法省略
|
||||
|
||||
/**
|
||||
* 预约挂号签到缴费成功后调用。
|
||||
* 撤回检验申请(医嘱)。
|
||||
*
|
||||
* @param orderMainId 订单主键
|
||||
* @param payAmount 实际支付金额
|
||||
* @throws BusinessException 支付或状态更新异常
|
||||
*
|
||||
* 该方法在原有的 {@code payOrder} 基础上新增了对 {@link ScheduleSlot}
|
||||
* 状态的更新:将 {@code status} 从 {@link ScheduleSlotStatus#RESERVED}
|
||||
* 改为 {@link ScheduleSlotStatus#TAKEN}(值 3),以满足 Bug #574 的需求。
|
||||
* 所有更新均在同一事务中完成,保证原子性。
|
||||
* @param orderMainId 主医嘱 ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void payOrder(Long orderMainId, Double payAmount) {
|
||||
// 1. 查询订单主表
|
||||
public void withdrawOrder(Long orderMainId) {
|
||||
// 1. 查询主医嘱
|
||||
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderMainId);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
if (!OrderStatus.PENDING_PAYMENT.getCode().equals(orderMain.getStatus())) {
|
||||
throw new BusinessException("订单状态不允许支付");
|
||||
throw new BusinessException("医嘱不存在,撤回失败");
|
||||
}
|
||||
|
||||
// 2. 更新订单主表状态为已支付
|
||||
orderMain.setStatus(OrderStatus.PAID.getCode());
|
||||
orderMain.setPayAmount(payAmount);
|
||||
orderMain.setPayTime(new Date());
|
||||
// 2. 已完成、已发药、已执行的医嘱不允许撤回
|
||||
if (OrderStatus.COMPLETED.equals(orderMain.getStatus())
|
||||
|| DispenseStatus.DISPENSED.equals(orderMain.getDispenseStatus())) {
|
||||
throw new BusinessException("已完成或已发药的医嘱不能撤回");
|
||||
}
|
||||
|
||||
// 3. 更新主医嘱状态为撤回
|
||||
orderMain.setStatus(OrderStatus.WITHDRAWN);
|
||||
orderMain.setUpdateTime(new Date());
|
||||
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||
|
||||
// 3. 更新订单明细状态为已支付(保持与主表一致)
|
||||
OrderDetail detail = new OrderDetail();
|
||||
detail.setOrderMainId(orderMainId);
|
||||
detail.setStatus(OrderStatus.PAID.getCode());
|
||||
orderDetailMapper.updateByOrderMainIdSelective(detail);
|
||||
|
||||
// 4. 关键修复:更新对应的号源状态为“已取号”(3)
|
||||
// 号源 ID 存在于 order_main 表的 schedule_slot_id 字段(假设如此)。
|
||||
Long scheduleSlotId = orderMain.getScheduleSlotId();
|
||||
if (scheduleSlotId != null) {
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectByPrimaryKey(scheduleSlotId);
|
||||
if (slot != null) {
|
||||
// 仅在原状态为已预约(2)时进行流转,防止重复更新导致状态错误
|
||||
if (ScheduleSlotStatus.RESERVED.getCode().equals(slot.getStatus())) {
|
||||
slot.setStatus(ScheduleSlotStatus.TAKEN.getCode());
|
||||
scheduleSlotMapper.updateByPrimaryKeySelective(slot);
|
||||
logger.info("订单 {} 支付成功,号源 {} 状态由 RESERVED 转为 TAKEN", orderMainId, scheduleSlotId);
|
||||
} else {
|
||||
logger.warn("订单 {} 支付成功,但号源 {} 当前状态为 {},未进行状态流转",
|
||||
orderMainId, scheduleSlotId, slot.getStatus());
|
||||
}
|
||||
} else {
|
||||
logger.warn("订单 {} 支付成功,但未找到对应的号源记录,slotId={}", orderMainId, scheduleSlotId);
|
||||
}
|
||||
} else {
|
||||
logger.warn("订单 {} 支付成功,但未关联号源(scheduleSlotId 为 null)", orderMainId);
|
||||
// 4. 更新所有明细状态为撤回
|
||||
List<OrderDetail> details = orderDetailMapper.selectByOrderMainId(orderMainId);
|
||||
if (details != null && !details.isEmpty()) {
|
||||
details.forEach(d -> {
|
||||
d.setStatus(OrderStatus.WITHDRAWN);
|
||||
d.setUpdateTime(new Date());
|
||||
orderDetailMapper.updateByPrimaryKeySelective(d);
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 其他可能的业务(如发券、打印等)保持不变
|
||||
}
|
||||
// 5. 释放已占用的号源(如果有预约号源)
|
||||
details.forEach(d -> {
|
||||
if (d.getScheduleSlotId() != null) {
|
||||
scheduleSlotMapper.updateStatusById(d.getScheduleSlotId(), ScheduleSlotStatus.AVAILABLE);
|
||||
// 同时释放对应的 pool 记录
|
||||
schedulePoolMapper.updateStatusBySlotId(d.getScheduleSlotId(), ScheduleSlotStatus.AVAILABLE);
|
||||
}
|
||||
});
|
||||
|
||||
// 其它业务实现...
|
||||
// 6. 记录撤回日志(使用 refund_log 表,保持与退款日志结构一致)
|
||||
RefundLog log = new RefundLog();
|
||||
log.setOrderMainId(orderMainId);
|
||||
log.setOperation("WITHDRAW");
|
||||
log.setOperatorId(/* 获取当前操作员 ID,示例写死 */ 0L);
|
||||
log.setOperateTime(new Date());
|
||||
log.setRemark("检验申请撤回");
|
||||
refundLogMapper.insert(log);
|
||||
|
||||
logger.info("医嘱撤回成功,orderMainId={}, detailsCount={}", orderMainId,
|
||||
details != null ? details.size() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user