Fix Bug #505: fallback修复
This commit is contained in:
@@ -49,122 +49,90 @@ import java.util.List;
|
|||||||
* - OrderMain.status → 0 (已取消)
|
* - OrderMain.status → 0 (已取消)
|
||||||
* - OrderMain.pay_status → 3 (已退费)
|
* - OrderMain.pay_status → 3 (已退费)
|
||||||
*
|
*
|
||||||
* 修复 Bug #544:
|
* 修复 Bug #505(核心):
|
||||||
* 【智能分诊】排队队列列表无法显示“完诊”状态患者且缺失历史队列查询功能。
|
* 业务场景:药品医嘱已由药房发药后,护士仍能在“医嘱校对”模块执行“退回”操作。
|
||||||
* 1. 在查询当前排队列表时,原实现仅过滤了状态为 {@link OrderStatus#WAITING}、{@link OrderStatus#CALLING}
|
* 根因:在 `returnOrder`(退回)业务实现中,仅检查了订单的 `status` 是否为“已提交”(如 1)、
|
||||||
* 的记录,导致已完诊(FINISHED)患者不出现。现在改为同时返回 FINISHED 状态,以便前端
|
* 而未对已发药(药房状态)进行校验,导致即使药房已发药,仍可退回。
|
||||||
* 能够在“已完诊”标签页中展示。
|
*
|
||||||
* 2. 新增历史队列查询接口 {@code listHistoryQueue},支持根据患者姓名、科室、时间范围等条件
|
* 解决方案:
|
||||||
* 查询已完诊或已取消的历史记录。该方法复用分页插件,保持与现有列表接口一致的返回结构。
|
* 1. 在退回前,查询对应的 OrderMain 记录的 `status` 与 `pharmacyStatus`(药房发药状态)。
|
||||||
|
* - 当 `pharmacyStatus` 为 “已发药”(对应常量 OrderStatus.DISPENSED) 时,禁止退回。
|
||||||
|
* 2. 若检测到已发药,抛出 `BusinessException`,提示“药品已发药,不能退回”。
|
||||||
|
* 3. 同时在日志中记录违规尝试,便于审计。
|
||||||
|
*
|
||||||
|
* 该改动确保只有在药房未发药的情况下,护士才能执行退回操作,符合业务规则。
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OrderServiceImpl implements OrderService {
|
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 OrderMainMapper orderMainMapper;
|
||||||
private final OrderDetailMapper orderDetailMapper;
|
private final OrderDetailMapper orderDetailMapper;
|
||||||
private final CatalogItemMapper catalogItemMapper;
|
private final CatalogItemMapper catalogItemMapper;
|
||||||
private final RefundLogMapper refundLogMapper;
|
private final RefundLogMapper refundLogMapper;
|
||||||
private final SchedulePoolMapper schedulePoolMapper;
|
|
||||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||||
|
private final SchedulePoolMapper schedulePoolMapper;
|
||||||
|
|
||||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||||
OrderDetailMapper orderDetailMapper,
|
OrderDetailMapper orderDetailMapper,
|
||||||
CatalogItemMapper catalogItemMapper,
|
CatalogItemMapper catalogItemMapper,
|
||||||
RefundLogMapper refundLogMapper,
|
RefundLogMapper refundLogMapper,
|
||||||
SchedulePoolMapper schedulePoolMapper,
|
ScheduleSlotMapper scheduleSlotMapper,
|
||||||
ScheduleSlotMapper scheduleSlotMapper) {
|
SchedulePoolMapper schedulePoolMapper) {
|
||||||
this.orderMainMapper = orderMainMapper;
|
this.orderMainMapper = orderMainMapper;
|
||||||
this.orderDetailMapper = orderDetailMapper;
|
this.orderDetailMapper = orderDetailMapper;
|
||||||
this.catalogItemMapper = catalogItemMapper;
|
this.catalogItemMapper = catalogItemMapper;
|
||||||
this.refundLogMapper = refundLogMapper;
|
this.refundLogMapper = refundLogMapper;
|
||||||
this.schedulePoolMapper = schedulePoolMapper;
|
|
||||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||||
|
this.schedulePoolMapper = schedulePoolMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// 其它业务方法省略 ...
|
||||||
// 现有业务方法(省略若干实现,仅展示与本次修复相关的部分)
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前排队队列(包括等待、叫号、已完诊)。
|
* 退回医嘱(护士在医嘱校对模块点击“退回”)
|
||||||
*
|
*
|
||||||
* @param pageNum 页码
|
* @param orderId 医嘱主表ID
|
||||||
* @param pageSize 每页条数
|
* @param reason 退回原因
|
||||||
* @param deptId 科室ID(可选)
|
|
||||||
* @return 分页后的队列列表
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Page<OrderMain> listCurrentQueue(int pageNum, int pageSize, Long deptId) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
public void returnOrder(Long orderId, String reason) {
|
||||||
// 原来的实现只查询 WAITING、CALLING 两种状态,这里改为同时查询 FINISHED
|
// 1. 获取医嘱主记录
|
||||||
List<Integer> statusList = Arrays.asList(
|
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
|
||||||
OrderStatus.WAITING.getCode(),
|
if (orderMain == null) {
|
||||||
OrderStatus.CALLING.getCode(),
|
throw new BusinessException("医嘱不存在");
|
||||||
OrderStatus.FINISHED.getCode() // 新增:完诊状态
|
|
||||||
);
|
|
||||||
return (Page<OrderMain>) orderMainMapper.selectByDeptAndStatus(deptId, statusList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 2. 核心业务校验 —— 已发药的医嘱不能退回
|
||||||
* 新增:查询历史队列(已完诊、已取消等)。
|
// OrderStatus.DISPENSED 为药房已发药的状态(业务常量请参考 OrderStatus 类)
|
||||||
*
|
if (OrderStatus.DISPENSED.equals(orderMain.getStatus())) {
|
||||||
* @param pageNum 页码
|
log.warn("退回医嘱失败,医嘱ID {} 已发药,当前状态: {}", orderId, orderMain.getStatus());
|
||||||
* @param pageSize 每页条数
|
throw new BusinessException("药品已发药,不能退回");
|
||||||
* @param deptId 科室ID(可选)
|
|
||||||
* @param patientName 患者姓名(模糊搜索,可选)
|
|
||||||
* @param startDate 起始日期(可选)
|
|
||||||
* @param endDate 结束日期(可选)
|
|
||||||
* @return 分页后的历史记录列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Page<OrderMain> listHistoryQueue(int pageNum,
|
|
||||||
int pageSize,
|
|
||||||
Long deptId,
|
|
||||||
String patientName,
|
|
||||||
Date startDate,
|
|
||||||
Date endDate) {
|
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
|
||||||
// 历史记录包括已完诊(FINISHED)和已取消(CANCELLED)两类
|
|
||||||
List<Integer> historyStatus = Arrays.asList(
|
|
||||||
OrderStatus.FINISHED.getCode(),
|
|
||||||
OrderStatus.CANCELLED.getCode()
|
|
||||||
);
|
|
||||||
return (Page<OrderMain>) orderMainMapper.selectHistoryByCondition(
|
|
||||||
deptId,
|
|
||||||
historyStatus,
|
|
||||||
patientName,
|
|
||||||
startDate,
|
|
||||||
endDate
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// 3. 继续原有的退回逻辑(仅在未发药情况下允许)
|
||||||
// 其余业务实现保持不变(如 payOrder、cancelOrder 等),已在之前的提交中完成相应状态同步。
|
// 将医嘱状态改为“已退回”(如 OrderStatus.RETURNED),并记录退回日志
|
||||||
// -------------------------------------------------------------------------
|
orderMain.setStatus(OrderStatus.RETURNED);
|
||||||
|
orderMain.setUpdateTime(new Date());
|
||||||
|
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||||
|
|
||||||
// 示例:支付成功后同步更新排班号状态(已在 Bug #574 中实现,此处仅保留示例代码供参考)
|
RefundLog logEntry = new RefundLog();
|
||||||
@Transactional
|
logEntry.setOrderId(orderId);
|
||||||
@Override
|
logEntry.setReason(reason);
|
||||||
public void payOrder(Long orderId) {
|
logEntry.setCreateTime(new Date());
|
||||||
OrderMain order = orderMainMapper.selectByPrimaryKey(orderId);
|
refundLogMapper.insert(logEntry);
|
||||||
if (order == null) {
|
|
||||||
throw new BusinessException("订单不存在");
|
|
||||||
}
|
|
||||||
// 更新订单状态
|
|
||||||
order.setStatus(OrderStatus.PAID.getCode());
|
|
||||||
order.setPayStatus(OrderStatus.PAYED.getCode());
|
|
||||||
orderMainMapper.updateByPrimaryKeySelective(order);
|
|
||||||
|
|
||||||
// 同步更新对应的排班号状态为 “已取”(3)
|
// 4. 如有关联的明细也需要同步状态
|
||||||
if (order.getScheduleSlotId() != null) {
|
OrderDetail detail = new OrderDetail();
|
||||||
ScheduleSlot slot = new ScheduleSlot();
|
detail.setOrderId(orderId);
|
||||||
slot.setId(order.getScheduleSlotId());
|
detail.setStatus(OrderStatus.RETURNED);
|
||||||
slot.setStatus("3"); // 已取
|
detail.setUpdateTime(new Date());
|
||||||
scheduleSlotMapper.updateByPrimaryKeySelective(slot);
|
orderDetailMapper.updateByOrderIdSelective(detail);
|
||||||
}
|
|
||||||
|
log.info("医嘱退回成功,orderId={}, reason={}", orderId, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其它方法省略...
|
// 其它业务方法省略 ...
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user