Fix Bug #561: fallback修复

This commit is contained in:
2026-05-27 03:25:15 +08:00
parent a7afeaf200
commit 2566a3d12b

View File

@@ -3,13 +3,13 @@ package com.openhis.application.service.impl;
import com.openhis.application.domain.entity.OrderDetail;
import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.domain.entity.CatalogItem;
import com.openhis.application.domain.entity.ScheduleSlot; // <-- 新增导入
import com.openhis.application.mapper.OrderDetailMapper;
import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.mapper.CatalogItemMapper;
import com.openhis.application.mapper.ScheduleSlotMapper; // 新增导入
import com.openhis.application.domain.entity.ScheduleSlot; // 新增导入
import com.openhis.application.mapper.ScheduleSlotMapper; // <-- 新增导入
import com.openhis.application.exception.BusinessException;
import com.openhis.application.service.OrderService; // 修正错误的包名
import com.openhs.application.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -40,18 +40,79 @@ public class OrderServiceImpl implements OrderService {
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
private final CatalogItemMapper catalogItemMapper;
private final ScheduleSlotMapper scheduleSlotMapper; // 新增成员
private final ScheduleSlotMapper scheduleSlotMapper; // <-- 新增成员
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
CatalogItemMapper catalogItemMapper,
ScheduleSlotMapper scheduleSlotMapper) { // 注入
ScheduleSlotMapper scheduleSlotMapper) { // <-- 注入
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
this.catalogItemMapper = catalogItemMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
}
// 其余业务方法保持不变,确保在保存 OrderDetail 时填充 unit
// 并在支付成功后更新对应的 ScheduleSlot 状态为 3。
/**
* 保存医嘱(包括主表和明细表)。
*
* @param orderMain 医嘱主表数据
* @param orderDetails 医嘱明细列表
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void saveOrder(OrderMain orderMain, List<OrderDetail> orderDetails) {
// 1. 保存主表
orderMainMapper.insert(orderMain);
Long orderId = orderMain.getId();
// 2. 保存明细,关键是把诊疗目录的计量单位写入明细的 unit 字段
for (OrderDetail detail : orderDetails) {
// 关联主表主键
detail.setOrderId(orderId);
// ---- 修复 Bug #561 开始 ----
// 根据明细的 itemCode若为空则使用 itemId查询对应的目录项
CatalogItem catalogItem = null;
if (detail.getItemCode() != null && !detail.getItemCode().trim().isEmpty()) {
catalogItem = catalogItemMapper.selectByItemCode(detail.getItemCode());
} else if (detail.getItemId() != null) {
catalogItem = catalogItemMapper.selectById(detail.getItemId());
}
// 若找到目录项且其 unit 不为空,则填充到明细的 unit 字段
if (catalogItem != null && catalogItem.getUnit() != null) {
detail.setUnit(catalogItem.getUnit());
} else {
// 没有找到对应目录或目录未配置单位时,记录日志并使用空字符串防止出现 “null”
log.warn("未能为医嘱明细 (orderId={}, itemId={}, itemCode={}) 获取计量单位,"
+ "将使用默认空字符串", orderId, detail.getItemId(), detail.getItemCode());
detail.setUnit("");
}
// ---- 修复 Bug #561 结束 ----
orderDetailMapper.insert(detail);
}
}
/**
* 订单支付成功后更新对应的号源状态为已取号status = 3
*
* @param scheduleSlotId 号源主键
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void handlePaymentSuccess(Long scheduleSlotId) {
if (scheduleSlotId == null) {
throw new BusinessException("号源ID不能为空");
}
ScheduleSlot slot = scheduleSlotMapper.selectById(scheduleSlotId);
if (slot == null) {
throw new BusinessException("号源不存在");
}
// 将状态更新为 “已取号”(3)
slot.setStatus(3);
scheduleSlotMapper.updateById(slot);
}
// 其它业务方法保持不变...
}