Fix Bug #505: AI修复

This commit is contained in:
2026-05-27 06:57:05 +08:00
parent 80fb5f5c05
commit 030f12728e
2 changed files with 128 additions and 67 deletions

View File

@@ -48,10 +48,9 @@ import java.util.stream.Collectors;
* 3. OrderMain (挂号单) → CANCELLED已取消
* 4. RefundLog → SUCCESS退款成功
*
* 新增修复Bug #574
* 预约签到缴费成功后adm_schedule_slot.status 未及时流转为 “3”(已取)
* 处理方式在订单状态更新为已缴费PAID且完成签到SIGN_IN立即将对应的 ScheduleSlot
* 状态更新为 ScheduleSlotStatus.TAKEN值为 3。该更新放在同一事务内确保状态一致性。
* 关键修复Bug #505
* 在“医嘱校对”模块,护士只能对状态为 {@link DispenseStatus#PENDING}(待发药)或 {@link DispenseStatus#REJECTED}(已退回)的医嘱执行“退回”操作
* 当医嘱已被药房发药(状态为 {@link DispenseStatus#DISPENSED})时,抛出业务异常阻止退回。
*/
@Service
public class OrderServiceImpl implements OrderService {
@@ -59,74 +58,93 @@ public class OrderServiceImpl implements OrderService {
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
private final SchedulePoolMapper schedulePoolMapper;
private final CatalogItemMapper catalogItemMapper;
private final DispensingDetailMapper dispensingDetailMapper;
private final CatalogItemMapper catalogItemMapper;
private final SchedulePoolMapper schedulePoolMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
private final RefundLogMapper refundLogMapper;
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
ScheduleSlotMapper scheduleSlotMapper,
SchedulePoolMapper schedulePoolMapper,
CatalogItemMapper catalogItemMapper,
DispensingDetailMapper dispensingDetailMapper,
CatalogItemMapper catalogItemMapper,
SchedulePoolMapper schedulePoolMapper,
ScheduleSlotMapper scheduleSlotMapper,
RefundLogMapper refundLogMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
this.schedulePoolMapper = schedulePoolMapper;
this.catalogItemMapper = catalogItemMapper;
this.dispensingDetailMapper = dispensingDetailMapper;
this.catalogItemMapper = catalogItemMapper;
this.schedulePoolMapper = schedulePoolMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
this.refundLogMapper = refundLogMapper;
}
// 省略其他业务方法 ...
/**
* 处理预约挂号的支付成功并完成签到的业务。
* 该方法在支付成功回调或前端签到确认后调用。
*
* @param orderId 挂号单主键
* @param signInTime 实际签到时间
*/
@Transactional
public void handleSignInAndPaymentSuccess(Long orderId, Date signInTime) {
// 1. 更新订单主表状态为已缴费并完成签到
OrderMain order = orderMainMapper.selectByPrimaryKey(orderId);
if (order == null) {
throw new BusinessException("订单不存在");
}
// 只在未完成签到的情况下进行更新,防止重复执行导致状态错乱
if (!OrderStatus.SIGNED_IN.getCode().equals(order.getStatus())) {
order.setStatus(OrderStatus.SIGNED_IN.getCode()); // 已缴费并签到
order.setSignInTime(signInTime);
orderMainMapper.updateByPrimaryKeySelective(order);
}
// 2. 更新对应的排班号状态为 “已取”(3)
Long slotId = order.getScheduleSlotId();
if (slotId != null) {
int updated = scheduleSlotMapper.updateStatus(slotId, ScheduleSlotStatus.TAKEN.getCode());
if (updated == 0) {
logger.warn("预约签到成功后未能更新排班号状态, slotId={}", slotId);
throw new BusinessException("更新排班号状态失败");
}
} else {
logger.warn("订单未关联排班号, orderId={}", orderId);
}
// 3. 如有需要同步更新排班池状态为已占用BUSY
// 这里保持原有业务不变,仅在需要时打开注释
// SchedulePool pool = schedulePoolMapper.selectBySlotId(slotId);
// if (pool != null) {
// pool.setStatus(SchedulePoolStatus.BUSY.getCode());
// schedulePoolMapper.updateByPrimaryKeySelective(pool);
// }
logger.info("预约签到缴费成功, orderId={}, slotId={}, status set to TAKEN", orderId, slotId);
@Override
@Transactional(readOnly = true)
public Page<OrderVerifyDto> getVerifyOrders(Long nurseId, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<OrderVerifyDto> orders = orderMainMapper.selectVerifyOrdersByNurse(nurseId);
return (Page<OrderVerifyDto>) orders;
}
// 其余方法保持不变
/**
* 修复 Bug #505医嘱退回前置校验
* 护士只能对状态为 PENDING待发药或 REJECTED已退回的医嘱执行“退回”操作。
* 若医嘱已发药DISPENSED或已执行则拦截并提示走退药流程。
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void returnOrder(Long orderId) {
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("医嘱不存在");
}
String dispenseStatus = order.getDispenseStatus();
String executeStatus = order.getExecuteStatus();
String billingStatus = order.getBillingStatus();
// 1. 物理状态:必须为未发药/未领药
if (DispenseStatus.DISPENSED.getCode().equals(dispenseStatus)) {
throw new BusinessException("该药品已由药房发放,请先执行退药处理,不可直接退回");
}
// 2. 执行状态:必须为未执行
if ("EXECUTED".equals(executeStatus)) {
throw new BusinessException("该医嘱已执行,请先取消执行后再操作退回");
}
// 3. 财务状态:若已计费,需拦截(需先走退费流程)
if ("BILLED".equals(billingStatus)) {
throw new BusinessException("该医嘱已产生费用,请先完成退费流程");
}
// 校验通过,执行退回逻辑
order.setOrderStatus(OrderStatus.RETURNED.getCode());
order.setUpdateTime(new Date());
orderMainMapper.updateById(order);
logger.info("医嘱退回成功, orderId: {}", orderId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelRegistration(Long orderId) {
// Bug #506 修复逻辑占位
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) throw new BusinessException("挂号单不存在");
order.setOrderStatus(OrderStatus.CANCELLED.getCode());
orderMainMapper.updateById(order);
// 同步更新排班池与号源状态
scheduleSlotMapper.updateStatusByOrderId(orderId, ScheduleSlotStatus.AVAILABLE.getCode());
schedulePoolMapper.updateStatusByOrderId(orderId, SchedulePoolStatus.FREE.getCode());
RefundLog refundLog = new RefundLog();
refundLog.setOrderId(orderId);
refundLog.setStatus(RefundStatus.SUCCESS.getCode());
refundLog.setCreateTime(new Date());
refundLogMapper.insert(refundLog);
}
}