258 预约管理-》医生排班管理:点【预约设置】界面编辑内容【确定】提示”保存成功“但是刷新重新进入未显示最后一次更新的数据

This commit is contained in:
HuangXinQuan
2026-03-27 15:42:26 +08:00
parent 112ec2e4a3
commit e2e5999276
15 changed files with 419 additions and 38 deletions

View File

@@ -33,4 +33,14 @@ public interface IOrderService extends IService<Order> {
Order createAppointmentOrder(Map<String, Object> params);
int cancelAppointmentOrder(Long orderId, String cancelReason);
/**
* 统计患者在指定机构、指定起始时间后的取消预约次数
*
* @param patientId 患者ID
* @param tenantId 机构ID
* @param startTime 起始时间
* @return 取消次数
*/
long countPatientCancellations(Long patientId, Integer tenantId, java.time.LocalDateTime startTime);
}

View File

@@ -178,4 +178,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
Date cancelTime = new Date();
return orderMapper.updateOrderCancelInfoById(orderId, cancelTime, cancelReason);
}
@Override
public long countPatientCancellations(Long patientId, Integer tenantId, java.time.LocalDateTime startTime) {
if (patientId == null || tenantId == null || startTime == null) {
return 0;
}
return this.count(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Order>()
.eq(Order::getPatientId, patientId)
.eq(Order::getTenantId, tenantId)
.ge(Order::getCancelTime, startTime)
.eq(Order::getStatus, AppointmentOrderStatus.CANCELLED));
}
}

View File

@@ -2,6 +2,8 @@ package com.openhis.clinical.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.openhis.appointmentmanage.domain.AppointmentConfig;
import com.openhis.appointmentmanage.service.IAppointmentConfigService;
import com.openhis.appointmentmanage.domain.TicketSlotDTO;
import com.openhis.appointmentmanage.mapper.SchedulePoolMapper;
import com.openhis.appointmentmanage.mapper.ScheduleSlotMapper;
@@ -23,6 +25,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -49,6 +52,9 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
@Resource
private SchedulePoolMapper schedulePoolMapper;
@Resource
private IAppointmentConfigService appointmentConfigService;
/**
* 查询号源列表
*
@@ -235,6 +241,27 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
if (orders == null || orders.isEmpty()) {
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(), "患者取消预约");
}
@@ -309,4 +336,35 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
throw new RuntimeException("挂号费格式错误: " + fee);
}
}
/**
* 根据类型获取周期名称
*/
private String getPeriodName(String type) {
if ("YEAR".equalsIgnoreCase(type)) {
return "年度";
} else if ("MONTH".equalsIgnoreCase(type)) {
return "月度";
} else {
return "当日";
}
}
/**
* 根据取消预约时间类型计算本周期的起始时间
*
* @param type YEAR/MONTH/DAY
* @return 起始时间
*/
private LocalDateTime calculatePeriodStartTime(String type) {
LocalDateTime now = LocalDateTime.now();
if ("YEAR".equalsIgnoreCase(type)) {
return now.with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN);
} else if ("MONTH".equalsIgnoreCase(type)) {
return now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
} else {
// 默认为 DAY
return now.with(LocalTime.MIN);
}
}
}