diff --git a/openhis-server-new/openhis-domain/src/main/java/com/openhis/clinical/service/impl/TicketServiceImpl.java b/openhis-server-new/openhis-domain/src/main/java/com/openhis/clinical/service/impl/TicketServiceImpl.java index 01fb025e..b1ffbfbe 100644 --- a/openhis-server-new/openhis-domain/src/main/java/com/openhis/clinical/service/impl/TicketServiceImpl.java +++ b/openhis-server-new/openhis-domain/src/main/java/com/openhis/clinical/service/impl/TicketServiceImpl.java @@ -146,7 +146,25 @@ public class TicketServiceImpl extends ServiceImpl impleme logger.debug("开始执行纯净打单路线,slotId: {}, patientName: {}", slotId, dto.getPatientName()); - // 1. 直查物理大底座! + // 1. 检查患者取消预约次数限制(应在预约挂号时限制,而非取消预约时) + Integer tenantId = dto.getTenant_id(); + Long patientId = dto.getPatientId(); + if (tenantId != null && patientId != null) { + AppointmentConfig config = appointmentConfigService.getConfigByTenantId(tenantId); + if (config != null && config.getCancelAppointmentCount() != null + && config.getCancelAppointmentCount() > 0) { + // 计算当前周期的起始时间 + LocalDateTime startTime = calculatePeriodStartTime(config.getCancelAppointmentType()); + // 统计已取消次数 + long cancelledCount = orderService.countPatientCancellations(patientId, tenantId, startTime); + if (cancelledCount >= config.getCancelAppointmentCount()) { + String periodName = getPeriodName(config.getCancelAppointmentType()); + throw new RuntimeException("由于您在" + periodName + "内累计取消预约已达" + cancelledCount + "次,触发系统限制,暂时无法在线预约,请联系分诊台或咨询客服。"); + } + } + } + + // 2. 直查物理大底座! TicketSlotDTO slot = scheduleSlotMapper.selectTicketSlotById(slotId); if (slot == null) { @@ -242,26 +260,11 @@ public class TicketServiceImpl extends ServiceImpl impleme throw new RuntimeException("当前号源没有可取消的预约订单"); } - // 核心逻辑:获取订单信息并检查机构取消限制 + // 获取订单信息 Order latestOrder = orders.get(0); - Integer tenantId = latestOrder.getTenantId(); - Long patientId = latestOrder.getPatientId(); - - if (tenantId != null && patientId != null) { - AppointmentConfig config = appointmentConfigService.getConfigByTenantId(tenantId); - if (config != null && config.getCancelAppointmentCount() != null - && config.getCancelAppointmentCount() > 0) { - // 计算当前周期的起始时间 - LocalDateTime startTime = calculatePeriodStartTime(config.getCancelAppointmentType()); - // 统计已取消次数 - long cancelledCount = orderService.countPatientCancellations(patientId, tenantId, startTime); - if (cancelledCount >= config.getCancelAppointmentCount()) { - String periodName = getPeriodName(config.getCancelAppointmentType()); - throw new RuntimeException("您在" + periodName + "内已达到该机构取消预约次数上限(" + config.getCancelAppointmentCount() + "次),禁止取消"); - } - } - } + // 直接执行取消,不再检查取消限制 + // 根据需求,取消限制应在预约挂号时检查,而非取消预约时 for (Order order : orders) { orderService.cancelAppointmentOrder(order.getId(), "患者取消预约"); }