Files
his/com/openhis/web/outpatient/service/impl/RegistrationServiceImpl.java
2026-05-27 00:45:22 +08:00

76 lines
3.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.openhis.web.outpatient.service.impl;
import com.openhis.web.outpatient.mapper.RegistrationMapper;
import com.openhis.web.outpatient.mapper.OrderMapper;
import com.openhis.web.outpatient.service.RegistrationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
/**
* 门诊挂号业务实现
*
* 修复 Bug #574在预约签到缴费成功后调用 {@link RegistrationMapper#updateSlotStatusToPaid}
* 将对应的 adm_schedule_slot.status 状态及时流转为 “3”(已取号)。
*
* 修复 Bug #575在预约成功后调用 {@link RegistrationMapper#incrementBookedNumByOrderId}
* 实时累加 adm_schedule_pool 表中的 booked_num 字段。
*
* 该方法假设在支付成功的业务流程中被调用,确保状态同步。
*/
@Service
public class RegistrationServiceImpl implements RegistrationService {
private final RegistrationMapper registrationMapper;
private final OrderMapper orderMapper;
public RegistrationServiceImpl(RegistrationMapper registrationMapper,
OrderMapper orderMapper) {
this.registrationMapper = registrationMapper;
this.orderMapper = orderMapper;
}
/**
* 预约签到缴费成功后处理逻辑
*
* @param orderId 订单ID
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void handlePaymentSuccess(Long orderId) {
if (orderId == null) {
throw new IllegalArgumentException("订单ID不能为空");
}
// 1. 更新订单状态为已支付(使用 OrderMapper 中新增的常量)
int orderUpdated = orderMapper.updateOrderStatusToPaid(orderId, OrderMapper.ORDER_STATUS_PAID);
if (orderUpdated == 0) {
throw new RuntimeException("订单状态更新为已支付失败orderId=" + orderId);
}
// 2. 获取订单关联的号源 slot_id
Map<String, Object> order = orderMapper.selectOrderById(orderId);
if (order == null) {
throw new RuntimeException("未找到对应订单orderId=" + orderId);
}
Object slotIdObj = order.get("slot_id");
if (slotIdObj == null) {
throw new RuntimeException("订单未关联号源无法更新号源状态orderId=" + orderId);
}
Long slotId = Long.valueOf(String.valueOf(slotIdObj));
// 3. 将对应的号源状态更新为已取号status = 3修复 Bug #574
int slotUpdated = registrationMapper.updateSlotStatusToPaid(slotId);
if (slotUpdated == 0) {
throw new RuntimeException("号源状态更新为已取号失败slotId=" + slotId);
}
// 4. 同步累加排班池已预约数量,修复 Bug #575
int poolUpdated = registrationMapper.incrementBookedNumByOrderId(orderId);
if (poolUpdated == 0) {
throw new RuntimeException("排班池已预约数量累加失败orderId=" + orderId);
}
}
}