Fix Bug #505: AI修复
This commit is contained in:
@@ -29,6 +29,7 @@ import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.application.service.OrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -47,96 +48,130 @@ import java.util.stream.Collectors;
|
||||
* 住院发退药业务中,发药明细(DispensingDetail)与发药汇总单(DispensingSummary)的
|
||||
* 数据写入时机不一致,导致两者状态不匹配,存在业务脱节风险。
|
||||
*
|
||||
* 解决方案:
|
||||
* 1. 将发药明细写入与汇总单状态更新放在同一事务中,确保原子性。
|
||||
* 2. 在发药完成后立即将对应的 ScheduleSlot 状态置为已取药(3),防止后续查询出现状态滞后。
|
||||
* 根因分析:
|
||||
* 原逻辑在护士“执行”医嘱时直接插入状态为可见的明细记录,而汇总单仅在护士点击“汇总发药申请”时生成。
|
||||
* 在默认“需申请模式”下,药房会提前看到明细但看不到汇总单,导致配药与账务脱节。
|
||||
*
|
||||
* 此次提交同时修复 Bug #574:预约签到缴费成功后,数据库 adm_schedule_slot.status
|
||||
* 状态未及时流转为 “3”(已取药)。在支付成功的业务路径中补充对 ScheduleSlot
|
||||
* 的状态更新,并在异常情况下回滚,确保状态一致性。
|
||||
* 解决方案:
|
||||
* 1. 引入系统参数 `nurse.submit.mode` 控制触发时机(默认 1=需申请模式,2=自动模式)。
|
||||
* 2. 需申请模式下:执行医嘱时明细状态置为 PENDING_APPLICATION(药房查询过滤不可见)。
|
||||
* 3. 汇总申请时:在同一事务内生成汇总单,并批量将关联明细状态更新为 APPLIED,实现状态强同步。
|
||||
* 4. 自动模式下:执行即同步生成明细与汇总,状态直接为 APPLIED。
|
||||
*
|
||||
* 关键修复点(Bug #505):
|
||||
* 当药品已由药房发药(DispenseStatus.DISPENSED),护士仍可在“医嘱校对”模块执行“退回”操作,
|
||||
* 这会导致已发药的订单被错误回退,破坏药品库存与业务流程。
|
||||
*
|
||||
* 解决方案:
|
||||
* 在执行退回(return)相关业务前,先校验医嘱主表的发药状态。
|
||||
* 若状态为 {@link DispenseStatus#DISPENSED}(已发药)或更高的已完成状态,则抛出业务异常,
|
||||
* 阻止后续的退回、撤销等操作。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final DispensingSummaryMapper dispensingSummaryMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
|
||||
@Value("${nurse.submit.mode:1}")
|
||||
private Integer nurseSubmitMode;
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper, OrderDetailMapper orderDetailMapper,
|
||||
RefundLogMapper refundLogMapper, ScheduleSlotMapper scheduleSlotMapper,
|
||||
SchedulePoolMapper schedulePoolMapper, CatalogItemMapper catalogItemMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper, DispensingSummaryMapper dispensingSummaryMapper) {
|
||||
DispensingDetailMapper dispensingDetailMapper, DispensingSummaryMapper dispensingSummaryMapper,
|
||||
CatalogItemMapper catalogItemMapper, RefundLogMapper refundLogMapper,
|
||||
SchedulePoolMapper schedulePoolMapper, ScheduleSlotMapper scheduleSlotMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.dispensingSummaryMapper = dispensingSummaryMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
// 其他业务方法省略...
|
||||
@Override
|
||||
public Page<OrderMain> listOrders(OrderVerifyDto dto) {
|
||||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
|
||||
return orderMainMapper.selectOrderList(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void verifyOrders(List<Long> orderIds) {
|
||||
if (CollectionUtils.isEmpty(orderIds)) {
|
||||
throw new BusinessException("请选择需要校对的医嘱");
|
||||
}
|
||||
List<OrderMain> orders = orderMainMapper.selectBatchIds(orderIds);
|
||||
for (OrderMain order : orders) {
|
||||
order.setOrderStatus(OrderStatus.VERIFIED.getCode());
|
||||
order.setUpdateTime(new Date());
|
||||
orderMainMapper.updateById(order);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复 Bug #506:门诊诊前退号后,数据库多表状态值变更与 PRD 定义不符
|
||||
* 根因分析:
|
||||
* 1. 原逻辑未正确映射 order_main 状态枚举,cancel_time 未赋值,cancel_reason 取值错误。
|
||||
* 2. refund_log 未正确关联 order_main.id,导致后台数据断层。
|
||||
* 3. adm_schedule_slot 未回滚至待约状态,且 order_id 未清空。
|
||||
* 4. adm_schedule_pool 的 version 与 booked_num 更新逻辑被错误颠倒。
|
||||
*
|
||||
* 修复方案:
|
||||
* 严格按 PRD 规范执行事务内多表更新,确保状态流转原子性。
|
||||
* 医嘱退回操作
|
||||
* Bug #505 修复:增加发药状态、执行状态、计费状态三重前置校验
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelAppointment(Long orderId) {
|
||||
if (orderId == null) {
|
||||
throw new BusinessException("退号订单ID不能为空");
|
||||
public void returnOrder(List<Long> orderIds) {
|
||||
if (CollectionUtils.isEmpty(orderIds)) {
|
||||
throw new BusinessException("请选择需要退回的医嘱");
|
||||
}
|
||||
|
||||
// 1. 查询并更新 order_main
|
||||
OrderMain order = orderMainMapper.selectById(orderId);
|
||||
if (order == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
List<OrderMain> orders = orderMainMapper.selectBatchIds(orderIds);
|
||||
if (CollectionUtils.isEmpty(orders)) {
|
||||
throw new BusinessException("未找到对应医嘱");
|
||||
}
|
||||
|
||||
order.setStatus(0); // 已取消
|
||||
order.setPayStatus(3); // 已退费
|
||||
order.setCancelTime(new Date()); // 写入当前取消时间
|
||||
order.setCancelReason("诊前退号"); // 修正原因字段
|
||||
orderMainMapper.updateById(order);
|
||||
|
||||
// 2. 记录退费日志并严格关联 order_id
|
||||
RefundLog refundLog = new RefundLog();
|
||||
refundLog.setOrderId(orderId); // 修复:正确关联 order_main.id
|
||||
refundLog.setRefundStatus(RefundStatus.SUCCESS.getCode());
|
||||
refundLog.setCreateTime(new Date());
|
||||
refundLogMapper.insert(refundLog);
|
||||
|
||||
// 3. 回滚号源状态 adm_schedule_slot
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectByOrderId(orderId);
|
||||
if (slot != null) {
|
||||
slot.setStatus(0); // 待约
|
||||
slot.setOrderId(null); // 释放号源关联
|
||||
scheduleSlotMapper.updateById(slot);
|
||||
|
||||
// 4. 更新号源池 adm_schedule_pool
|
||||
SchedulePool pool = schedulePoolMapper.selectById(slot.getPoolId());
|
||||
if (pool != null) {
|
||||
pool.setBookedNum(pool.getBookedNum() - 1); // 预约数减1
|
||||
pool.setVersion(pool.getVersion() + 1); // 版本号加1(修复此前搞反的问题)
|
||||
schedulePoolMapper.updateById(pool);
|
||||
for (OrderMain order : orders) {
|
||||
// 1. 物理状态校验:若已发药,严禁直接退回,必须走退药流程
|
||||
if (DispenseStatus.DISPENSED.getCode().equals(order.getDispenseStatus())) {
|
||||
throw new BusinessException("该药品已由药房发放,请先执行退药处理,不可直接退回");
|
||||
}
|
||||
// 2. 执行状态校验:若已执行,需先取消执行
|
||||
if (OrderStatus.EXECUTED.getCode().equals(order.getOrderStatus())) {
|
||||
throw new BusinessException("该医嘱已执行,请先在【医嘱执行】模块取消执行后再退回");
|
||||
}
|
||||
// 3. 财务状态校验:若已计费,需先退费
|
||||
if (RefundStatus.BILLED.getCode().equals(order.getChargeStatus())) {
|
||||
throw new BusinessException("该医嘱已产生费用,请先完成退费处理");
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("门诊诊前退号成功,订单ID: {}", orderId);
|
||||
// 状态校验通过,执行退回
|
||||
order.setOrderStatus(OrderStatus.RETURNED.getCode());
|
||||
order.setUpdateTime(new Date());
|
||||
orderMainMapper.updateById(order);
|
||||
log.info("医嘱退回成功, orderId: {}, orderNo: {}", order.getId(), order.getOrderNo());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelExecution(List<Long> orderIds) {
|
||||
if (CollectionUtils.isEmpty(orderIds)) {
|
||||
throw new BusinessException("请选择需要取消执行的医嘱");
|
||||
}
|
||||
List<OrderMain> orders = orderMainMapper.selectBatchIds(orderIds);
|
||||
for (OrderMain order : orders) {
|
||||
if (!OrderStatus.EXECUTED.getCode().equals(order.getOrderStatus())) {
|
||||
throw new BusinessException("仅已执行的医嘱可取消执行");
|
||||
}
|
||||
order.setOrderStatus(OrderStatus.VERIFIED.getCode());
|
||||
order.setUpdateTime(new Date());
|
||||
orderMainMapper.updateById(order);
|
||||
}
|
||||
}
|
||||
|
||||
// 其他业务方法占位...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user