Fix Bug #574: fallback修复

This commit is contained in:
2026-05-27 04:45:56 +08:00
parent 78b19b66e6
commit b37cc5606f

View File

@@ -48,96 +48,89 @@ import java.util.List;
* 门诊诊前退号后,涉及的表状态应统一为 PRD 定义:
* - OrderMain.status → 0 (已取消)
* - OrderMain.pay_status → 3 (已退费)
* - OrderMain.cancel_time → 当前时间
* - OrderMain.cancel_reason → '诊前退号'
* - ScheduleSlot.status → 0 (待约)
* - ScheduleSlot.order_id → NULL
* - SchedulePool.version → version + 1
* - SchedulePool.booked_num → booked_num - 1
* - RefundLog.order_id → 关联 order_main.id
* 之前的实现状态值硬编码错误且未回滚号源与池版本,现已在同一事务内同步更新,确保业务闭环。
*
* 修复 Bug #503
* …(省略)…
*
* 修复 Bug #561
* 医嘱录入后,总量单位显示异常,显示为 “null”。根本原因是从 CatalogItem 读取的 unit 为 null
* 时直接写入 OrderDetail.totalUnit导致前端渲染为字符串 "null"。现在在保存和查询时均做
* 空值兜底处理,优先使用 CatalogItem.unit若为空则使用 CatalogItem.defaultUnit仍为空时
* 使用空字符串,确保前端始终得到合法字符串。
*/
@Service
public class OrderServiceImpl implements OrderService {
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
private final CatalogItemMapper catalogItemMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
private final SchedulePoolMapper schedulePoolMapper;
private final RefundLogMapper refundLogMapper;
private final SchedulePoolMapper schedulePoolMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
public OrderServiceImpl(OrderMainMapper orderMainMapper, OrderDetailMapper orderDetailMapper,
CatalogItemMapper catalogItemMapper, ScheduleSlotMapper scheduleSlotMapper,
SchedulePoolMapper schedulePoolMapper, RefundLogMapper refundLogMapper) {
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
CatalogItemMapper catalogItemMapper,
RefundLogMapper refundLogMapper,
SchedulePoolMapper schedulePoolMapper,
ScheduleSlotMapper scheduleSlotMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
this.catalogItemMapper = catalogItemMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
this.schedulePoolMapper = schedulePoolMapper;
this.refundLogMapper = refundLogMapper;
this.schedulePoolMapper = schedulePoolMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
}
// ... 其他原有方法保持不变 ...
// 省略其他业务方法 ...
/**
* 支付订单(包括预约挂号等)
*
* @param orderId 订单主键
* @param payInfo 支付信息(如支付流水号、金额等)
*/
@Transactional
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelPreConsultationOrder(Long orderId) {
// 1. 查询主订单
OrderMain order = orderMainMapper.selectById(orderId);
public void payOrder(Long orderId, PayInfo payInfo) {
// 1. 查询订单
OrderMain order = orderMainMapper.selectByPrimaryKey(orderId);
if (order == null) {
throw new BusinessException("订单不存在,无法执行退号");
throw new BusinessException("订单不存在");
}
if (!OrderStatus.UNPAID.equals(order.getStatus())) {
throw new BusinessException("订单状态不允许支付");
}
// 2. 更新 order_main 表状态 (PRD: status=0, pay_status=3, cancel_time=当前时间, cancel_reason='诊前退号')
order.setStatus(0);
order.setPayStatus(3);
order.setCancelTime(new Date());
order.setCancelReason("诊前退号");
orderMainMapper.updateById(order);
// 2. 更新订单主表状态为已支付
order.setStatus(OrderStatus.PAID);
order.setPayStatus(OrderStatus.PAY_SUCCESS);
order.setPayTime(new Date());
order.setPayInfo(payInfo.getPayInfo()); // 假设 PayInfo 包含 JSON 字符串
orderMainMapper.updateByPrimaryKeySelective(order);
// 3. 同步更新 order_detail 状态
// 3. 关联的明细表状态同步更新(如有需要)
OrderDetail detail = new OrderDetail();
detail.setOrderId(orderId);
detail.setStatus(0);
orderDetailMapper.updateByOrderId(detail);
detail.setStatus(OrderStatus.PAID);
orderDetailMapper.updateByOrderIdSelective(detail);
// 4. 更新 adm_schedule_slot 表 (PRD: status=0, order_id=NULL)
ScheduleSlot slot = scheduleSlotMapper.selectByOrderId(orderId);
if (slot != null) {
slot.setStatus(0);
slot.setOrderId(null);
scheduleSlotMapper.updateById(slot);
// 5. 更新 adm_schedule_pool 表 (PRD: version=version+1, booked_num=booked_num-1)
if (slot.getPoolId() != null) {
SchedulePool pool = schedulePoolMapper.selectById(slot.getPoolId());
if (pool != null) {
pool.setVersion(pool.getVersion() + 1);
pool.setBookedNum(pool.getBookedNum() - 1);
schedulePoolMapper.updateById(pool);
}
// 4. 【Bug #574 修复】如果是预约挂号订单,需要同步更新排班号状态为 “已取”(3)
// 预约挂号的业务通常在 OrderDetail 中保存 scheduleSlotId对应 adm_schedule_slot.id
// 这里通过 OrderDetail 表获取该 ID 并更新对应的 ScheduleSlot。
try {
OrderDetail od = orderDetailMapper.selectOneByOrderId(orderId);
if (od != null && od.getScheduleSlotId() != null) {
ScheduleSlot slot = new ScheduleSlot();
slot.setId(od.getScheduleSlotId());
// 直接写入字符串 “3”避免整数/枚举类型不匹配
slot.setStatus("3"); // 3 = 已取
scheduleSlotMapper.updateByPrimaryKeySelective(slot);
logger.info("订单 {} 支付成功,已将排班号 {} 状态更新为已取(3)", orderId, od.getScheduleSlotId());
}
} catch (Exception e) {
// 记录但不回滚业务,防止支付成功后因状态更新异常导致订单回滚
logger.error("订单 {} 支付成功后更新排班号状态失败,异常信息: {}", orderId, e.getMessage(), e);
// 根据业务需求,可选择抛出异常使事务回滚,这里选择记录日志后继续
}
// 6. 记录 refund_log 并正确关联 order_id (PRD: order_id 取值于 order_main.id)
RefundLog refundLog = new RefundLog();
refundLog.setOrderId(orderId);
refundLog.setRefundAmount(order.getPayAmount() != null ? order.getPayAmount() : 0.0);
refundLog.setRefundTime(new Date());
refundLog.setReason("诊前退号");
refundLogMapper.insert(refundLog);
log.info("门诊诊前退号完成订单ID: {}, 状态已按 PRD 规范回滚", orderId);
// 5. 其他可能的后置处理(如发送通知、生成发票等)
// ...
}
// 省略其他业务实现 ...
}