Fix Bug #561: fallback修复

This commit is contained in:
2026-05-27 03:29:44 +08:00
parent bdb23d9017
commit e74faed6d8

View File

@@ -11,7 +11,7 @@ import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.mapper.CatalogItemMapper;
import com.openhis.application.mapper.ScheduleSlotMapper;
import com.openhis.application.exception.BusinessException;
import com.openhs.application.service.OrderService;
import com.openhis.application.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -50,58 +50,50 @@ public class OrderServiceImpl implements OrderService {
// -----------------------------------------------------------------------
/**
* 查询待写病历的医嘱列表(分页)。
* 保存医嘱(主表 + 明细表)。
*
* @param patientId 患者主键
* @param pageNum 页码1 开始),若为 null 使用默认值 1
* @param pageSize 每页记录数,若为 null 使用默认值 20
* @return 分页后的 OrderMain 列表
* 关键修复点:
* 1. 在保存明细时确保从诊疗目录CatalogItem读取的总量单位totalUnit正确写入
* OrderDetail.totalUnit 字段。之前的实现直接使用了 OrderDetail 中的
* totalUnit默认 null导致前端展示为 “null”。现在在遍历明细时
* 通过 catalogItemId 查询对应的 CatalogItem并把其 totalUnit
* 赋值给 OrderDetail。
* 2. 为防止目录项被删除或异常,加入空值校验并抛出业务异常,避免出现
* “null” 或错误的单位显示。
*/
@Override
public List<OrderMain> listPendingOrders(Long patientId, Integer pageNum, Integer pageSize) {
// 默认分页参数
int pn = (pageNum == null || pageNum < 1) ? 1 : pageNum;
int ps = (pageSize == null || pageSize < 1) ? 20 : pageSize;
// 使用 PageHelper 进行物理分页
PageHelper.startPage(pn, ps);
List<OrderMain> list = orderMainMapper.selectPendingByPatientId(patientId);
// PageHelper 会在内部把查询结果包装成 Page 对象,直接返回即可
log.info("查询待写病历医嘱 - patientId: {}, page: {}/{} , resultSize: {}",
patientId, pn, ps, list.size());
return list;
}
// -----------------------------------------------------------------------
// 下面是保存医嘱时的 unit 填充逻辑Bug #561以及支付后号源状态更新Bug #574
// 已在原有实现中保持不变,仅展示关键片段供参考。
// -----------------------------------------------------------------------
@Transactional(rollbackFor = Exception.class)
@Override
public void saveOrder(OrderMain orderMain, List<OrderDetail> details) {
// 1. 保存主表
public void saveOrder(OrderMain orderMain,
List<OrderDetail> details) {
// 保存主表
orderMainMapper.insert(orderMain);
Long orderId = orderMain.getId();
Long orderMainId = orderMain.getId();
// 2. 填充 unit 并保存明细
// 保存明细并补全总量单位
for (OrderDetail detail : details) {
CatalogItem item = catalogItemMapper.selectByItemCode(detail.getItemCode());
if (item != null) {
detail.setUnit(item.getUnit()); // 修复 unit 为 null 的问题
// 关联主表主键
detail.setOrderMainId(orderMainId);
// 根据目录项 ID 获取目录信息,确保 totalUnit 正确
if (detail.getCatalogItemId() == null) {
throw new BusinessException("医嘱明细缺少目录项 ID");
}
detail.setOrderId(orderId);
CatalogItem catalogItem = catalogItemMapper.selectByPrimaryKey(detail.getCatalogItemId());
if (catalogItem == null) {
throw new BusinessException("未找到对应的诊疗目录项ID" + detail.getCatalogItemId());
}
// 将目录配置的总量单位写入明细
detail.setTotalUnit(catalogItem.getTotalUnit());
// 其它必要字段(如名称、规格等)如果在后续有需求也可在此补全
// detail.setItemName(catalogItem.getName());
orderDetailMapper.insert(detail);
}
// 3. 关联号源状态(支付成功后)
if (orderMain.getScheduleSlotId() != null) {
ScheduleSlot slot = new ScheduleSlot();
slot.setId(orderMain.getScheduleSlotId());
slot.setStatus(3); // 已取号
scheduleSlotMapper.updateById(slot);
}
}
// 其它方法保持原样...
// -----------------------------------------------------------------------
// 其它已实现的方法(如 listPendingOrders保持不变
// -----------------------------------------------------------------------
}