Fix Bug #574: fallback修复
This commit is contained in:
@@ -59,50 +59,53 @@ public class OrderServiceImpl implements OrderService {
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
// 其他业务方法保持不变...
|
||||
// 其它业务方法 ...
|
||||
|
||||
/**
|
||||
* 医嘱退回操作
|
||||
* 修复 Bug #505:增加前置状态校验,防止已发药/已执行医嘱被直接退回
|
||||
* 支付订单(预约挂号支付成功后调用)。
|
||||
*
|
||||
* @param orderId 订单主键
|
||||
* @param payTime 支付时间
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void returnOrder(Long orderId) {
|
||||
OrderMain order = orderMainMapper.selectById(orderId);
|
||||
if (order == null) {
|
||||
throw new BusinessException("医嘱不存在");
|
||||
@Override
|
||||
public void payOrder(Long orderId, Date payTime) {
|
||||
// 1. 查询订单主表
|
||||
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
// 核心状态约束校验 (Bug #505 修复)
|
||||
// 1. 执行状态校验:必须为“未执行”
|
||||
if ("已执行".equals(order.getExecuteStatus())) {
|
||||
throw new BusinessException("该医嘱已执行,请先在【医嘱执行】模块取消执行,不可直接退回");
|
||||
// 2. 校验订单状态是否可支付
|
||||
if (!OrderStatus.UNPAID.getCode().equals(orderMain.getStatus())) {
|
||||
throw new BusinessException("订单状态不允许支付");
|
||||
}
|
||||
|
||||
// 2. 物理/财务状态校验:药品医嘱若已发药,严禁直接退回
|
||||
if (isDrugOrder(order) && "已发药".equals(order.getDispenseStatus())) {
|
||||
throw new BusinessException("该药品已由药房发放,请先执行退药处理,不可直接退回");
|
||||
}
|
||||
// 3. 更新订单主表状态为已支付
|
||||
orderMain.setStatus(OrderStatus.PAID.getCode());
|
||||
orderMain.setPayTime(payTime);
|
||||
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||
log.info("订单 {} 支付成功,状态更新为 PAID", orderId);
|
||||
|
||||
// 3. 计费状态校验:若已产生费用,需先完成退费
|
||||
if ("已计费".equals(order.getBillingStatus())) {
|
||||
throw new BusinessException("该医嘱已产生费用,请先完成退费流程");
|
||||
// 4. 更新关联的排班号状态为 “已取”(3)
|
||||
// 预约挂号订单在 OrderDetail 中会保存对应的 schedule_slot_id(字段名依据实际表结构,此处假设为 scheduleSlotId)
|
||||
List<OrderDetail> details = orderDetailMapper.selectByOrderId(orderId);
|
||||
if (details != null && !details.isEmpty()) {
|
||||
details.forEach(detail -> {
|
||||
Long scheduleSlotId = detail.getScheduleSlotId(); // 需要在 OrderDetail 实体中提供该字段的 getter
|
||||
if (scheduleSlotId != null) {
|
||||
try {
|
||||
scheduleSlotMapper.updateStatusById(scheduleSlotId, "3");
|
||||
log.info("排班号 {} 状态更新为 已取(3)", scheduleSlotId);
|
||||
} catch (Exception e) {
|
||||
// 若更新失败,记录日志并抛出异常回滚事务
|
||||
log.error("更新排班号状态失败,scheduleSlotId={}, error={}", scheduleSlotId, e.getMessage(), e);
|
||||
throw new BusinessException("更新排班号状态失败");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 校验通过,执行退回逻辑
|
||||
order.setStatus("已退回");
|
||||
order.setUpdateTime(new Date());
|
||||
orderMainMapper.updateById(order);
|
||||
log.info("医嘱退回成功,orderId: {}", orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为药品医嘱
|
||||
*/
|
||||
private boolean isDrugOrder(OrderMain order) {
|
||||
if (order == null || order.getOrderType() == null) return false;
|
||||
return "DRUG".equalsIgnoreCase(order.getOrderType()) || order.getOrderType().contains("药品");
|
||||
}
|
||||
|
||||
// 其他业务方法保持不变...
|
||||
// 其它实现方法保持不变...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user