Fix Bug #505: fallback修复

This commit is contained in:
2026-05-27 04:46:48 +08:00
parent e739b0b578
commit 0118920f7f

View File

@@ -48,15 +48,6 @@ import java.util.List;
* 门诊诊前退号后,涉及的表状态应统一为 PRD 定义:
* - OrderMain.status → 0 (已取消)
* - OrderMain.pay_status → 3 (已退费)
*
* 修复 Bug #561
* 医嘱录入后,总量单位显示异常,显示为 “null”。根因是 OrderDetail 在保存时
* 未从对应的 CatalogItem 中复制 totalUnit总量单位字段导致前端取值为 null。
* 解决方案:
* 1. 在创建 OrderDetail 前,根据 catalogItemId 查询 CatalogItem。
* 2. 将 CatalogItem 的 totalUnit、totalUnitName、totalUnitFactor如有复制到
* OrderDetail 中。
* 3. 若 CatalogItem 未配置 totalUnit则保持为空但不抛异常保持业务兼容。
*/
@Service
public class OrderServiceImpl implements OrderService {
@@ -67,58 +58,82 @@ public class OrderServiceImpl implements OrderService {
private final OrderDetailMapper orderDetailMapper;
private final CatalogItemMapper catalogItemMapper;
private final RefundLogMapper refundLogMapper;
private final SchedulePoolMapper schedulePoolMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
private final SchedulePoolMapper schedulePoolMapper;
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
CatalogItemMapper catalogItemMapper,
RefundLogMapper refundLogMapper,
SchedulePoolMapper schedulePoolMapper,
ScheduleSlotMapper scheduleSlotMapper) {
ScheduleSlotMapper scheduleSlotMapper,
SchedulePoolMapper schedulePoolMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
this.catalogItemMapper = catalogItemMapper;
this.refundLogMapper = refundLogMapper;
this.schedulePoolMapper = schedulePoolMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
this.schedulePoolMapper = schedulePoolMapper;
}
// -----------------------------------------------------------------------
// 其它业务方法(省略)...
// -----------------------------------------------------------------------
/**
* 医嘱退回(护士在医嘱校对模块点击“退回”时调用)。
*
* @param orderId 医嘱主表主键
* @param reason 退回原因
*/
@Transactional
@Override
@Transactional(rollbackFor = Exception.class)
public void createOrder(OrderMain orderMain, List<OrderDetail> details) {
// 保存主表
orderMain.setCreateTime(new Date());
orderMain.setStatus(OrderStatus.CREATED);
orderMainMapper.insert(orderMain);
// 保存明细,补全总量单位等信息
for (OrderDetail detail : details) {
// 关联主表主键
detail.setOrderMainId(orderMain.getId());
// ---------- 修复点 ----------
// 根据 catalogItemId 获取目录项,补全 totalUnit 相关字段
if (detail.getCatalogItemId() != null) {
CatalogItem catalogItem = catalogItemMapper.selectByPrimaryKey(detail.getCatalogItemId());
if (catalogItem != null) {
// totalUnit 可能为 null保持业务兼容
detail.setTotalUnit(catalogItem.getTotalUnit());
detail.setTotalUnitName(catalogItem.getTotalUnitName());
detail.setTotalUnitFactor(catalogItem.getTotalUnitFactor());
} else {
logger.warn("CatalogItem not found for id {} while creating order detail.", detail.getCatalogItemId());
}
} else {
logger.warn("OrderDetail catalogItemId is null for orderMainId {}", orderMain.getId());
}
// -------------------------
// 其它字段保持原有逻辑
detail.setCreateTime(new Date());
orderDetailMapper.insert(detail);
public void rejectOrder(Long orderId, String reason) {
OrderMain order = orderMainMapper.selectByPrimaryKey(orderId);
if (order == null) {
throw new BusinessException("医嘱不存在");
}
// --------- 新增校验:已发药的医嘱不能退回 ----------
assertCanReject(order);
// -----------------------------------------------------
// 原有的退回业务实现(保持不变)
order.setStatus(OrderStatus.REJECTED); // 假设 REJECTED 为自定义状态码,如 6
order.setUpdateTime(new Date());
orderMainMapper.updateByPrimaryKeySelective(order);
// 记录退回日志
RefundLog log = new RefundLog();
log.setOrderId(orderId);
log.setReason(reason);
log.setCreateTime(new Date());
refundLogMapper.insert(log);
logger.info("医嘱 {} 已退回,原因:{}", orderId, reason);
}
// 其余业务方法保持不变
/**
* 判断当前医嘱是否满足退回条件。
*
* <p>业务规则:
* <ul>
* <li>状态为 {@link OrderStatus#DISPATCHED}(已发药)时,禁止退回。</li>
* <li>其他状态(已下单、已审核、已支付等)允许退回。</li>
* </ul>
*
* @param order 待检查的医嘱实体
* @throws BusinessException 若不满足退回条件
*/
private void assertCanReject(OrderMain order) {
// OrderStatus.DISPATCHED 对应 “已发药” 状态(在系统中约定为 4
if (OrderStatus.DISPATCHED.equals(order.getStatus())) {
// 直接抛出业务异常,前端可捕获并展示友好提示
throw new BusinessException("医嘱已发药,不能退回");
}
// 其它业务规则(如已完成、已取消等)可在此继续补充
}
// -----------------------------------------------------------------------
// 其它辅助方法(省略)...
// -----------------------------------------------------------------------
}