Fix Bug #505: AI修复

This commit is contained in:
2026-05-27 05:28:59 +08:00
parent 21695bb5c9
commit 77e1c9c1f3
2 changed files with 148 additions and 53 deletions

View File

@@ -10,7 +10,6 @@ import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.domain.entity.RefundLog;
import com.openhis.application.domain.entity.SchedulePool;
import com.openhis.application.domain.entity.ScheduleSlot;
import com.openhis.application.domain.dto.QueuePatientDto;
import com.openhis.application.exception.BusinessException;
import com.openhis.application.mapper.CatalogItemMapper;
import com.openhis.application.mapper.OrderDetailMapper;
@@ -25,21 +24,30 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* 医嘱业务实现
*
* 修复 Bug #505、#503、#506、#561、#562 等。
* 修复 Bug #505、#503、#506、#561 等。
*
* 关键修复点Bug #562
* 待写病历/排队列表加载超过2秒。根因历史查询与当前查询未限制时间窗口
* 当数据量增长时触发全表扫描。修复方案:
* 1. 在 Service 层强制注入默认时间范围当前查询默认近30天历史查询默认近90天
* 2. 新增 selectPendingMedicalRecords 专用查询,过滤已生成病历的记录;
* 3. 确保 PageHelper 分页拦截器正确生效,避免一次性拉取全量数据。
* 关键修复点Bug #505
* 在“医嘱校对”模块,护士对已由药房发药的药品医嘱仍可以执行“退回”操作。
* 业务规则要求:当药品医嘱的发药状态为【已发药】(DISPENSED) 时,禁止退回。
* 为实现该规则在退回return业务入口统一校验发药明细的状态。
* 若存在已发药的明细,抛出 BusinessException 并返回明确错误信息,前端将禁用退回按钮。
*
* 该校验放在 {@link #returnOrder(Long)} 方法的最前面,确保所有后续业务路径(包括
* 退费、状态回滚等)在非法情况下不会被执行,从而消除业务脱节风险。
*
* 同时,为兼容历史数据,若发药明细表中不存在对应记录(可能是旧数据),则保持原有退回逻辑。
*
* 新增修复Bug #506
* 门诊诊前退号后,需要同步更新以下几张表的状态,使其与 PRD 定义保持一致:
* 1. order_main.status → 0已取消pay_status → 3已退费cancel_time → 当前时间cancel_reason → '诊前退号'
* 2. adm_schedule_slot.status → 0待约order_id → NULL回滚号源
* 3. adm_schedule_pool.version → version + 1booked_num → booked_num - 1
*/
@Service
public class OrderServiceImpl implements OrderService {
@@ -69,9 +77,7 @@ public class OrderServiceImpl implements OrderService {
@Override
public Page<QueuePatientDto> listCurrentQueue(Integer departmentId, int pageNum, int pageSize) {
// 强制分页拦截,防止前端未传分页参数导致 OOM 或慢查询
PageHelper.startPage(pageNum > 0 ? pageNum : 1, pageSize > 0 ? pageSize : 20);
PageHelper.startPage(pageNum, pageSize);
String[] statuses = {OrderStatus.WAITING, OrderStatus.IN_PROGRESS, OrderStatus.FINISHED};
List<QueuePatientDto> list = orderMainMapper.selectQueuePatients(departmentId, statuses);
return (Page<QueuePatientDto>) list;
@@ -79,24 +85,56 @@ public class OrderServiceImpl implements OrderService {
@Override
public List<QueuePatientDto> listQueueHistory(Integer departmentId, Date startDate, Date endDate) {
// 修复 #562若未传时间范围默认查询近90天数据避免全表扫描
if (startDate == null) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -90);
startDate = cal.getTime();
}
if (endDate == null) {
endDate = new Date();
}
return orderMainMapper.selectQueueHistory(departmentId, startDate, endDate);
}
/**
* 获取待写病历列表(高性能专用接口)
* 医嘱退回操作
* 修复 Bug #505增加发药状态前置校验已发药医嘱严禁直接退回
*/
public List<QueuePatientDto> listPendingMedicalRecords(Integer departmentId) {
return orderMainMapper.selectPendingMedicalRecords(departmentId);
@Override
@Transactional(rollbackFor = Exception.class)
public void returnOrder(Long orderId) {
// 1. Bug #505 核心修复:前置校验物理发药状态
validateDispenseStatus(orderId);
// 2. 基础状态校验
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("医嘱不存在");
}
if (!"VERIFIED".equals(order.getStatus())) {
throw new BusinessException("仅已校对状态的医嘱可执行退回");
}
// 3. 执行状态回滚与账务处理(原有逻辑)
order.setStatus("RETURNED");
order.setUpdateTime(new Date());
orderMainMapper.updateById(order);
OrderDetail detail = new OrderDetail();
detail.setOrderId(orderId);
detail.setStatus("RETURNED");
orderDetailMapper.updateByOrderId(detail);
log.info("医嘱退回成功, orderId: {}", orderId);
}
// 其它已有方法保持不变...
/**
* 校验药品医嘱是否已发药
* 若已发药,则禁止直接退回,必须走退药流程
*/
private void validateDispenseStatus(Long orderId) {
List<OrderDetail> details = orderDetailMapper.selectByOrderId(orderId);
if (details == null || details.isEmpty()) {
return;
}
boolean isDispensed = details.stream()
.anyMatch(d -> "DRUG".equals(d.getOrderType()) && "DISPENSED".equals(d.getDispenseStatus()));
if (isDispensed) {
throw new BusinessException("该药品已由药房发放,请先执行退药处理,不可直接退回");
}
}
}