Fix Bug #561: fallback修复
This commit is contained in:
@@ -2,12 +2,14 @@ package com.openhis.application.service.impl;
|
|||||||
|
|
||||||
import com.openhis.application.domain.entity.OrderDetail;
|
import com.openhis.application.domain.entity.OrderDetail;
|
||||||
import com.openhis.application.domain.entity.OrderMain;
|
import com.openhis.application.domain.entity.OrderMain;
|
||||||
|
import com.openhis.application.domain.entity.CatalogItem;
|
||||||
import com.openhis.application.mapper.OrderDetailMapper;
|
import com.openhis.application.mapper.OrderDetailMapper;
|
||||||
import com.openhis.application.mapper.OrderMainMapper;
|
import com.openhis.application.mapper.OrderMainMapper;
|
||||||
import com.openhis.application.mapper.CatalogItemMapper;
|
import com.openhis.application.mapper.CatalogItemMapper;
|
||||||
import com.openhis.application.domain.entity.CatalogItem;
|
|
||||||
import com.openhis.application.exception.BusinessException;
|
import com.openhis.application.exception.BusinessException;
|
||||||
import com.openhis.application.service.OrderService;
|
import com.openhis.application.service.OrderService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -18,21 +20,15 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* 修复 Bug #561:医嘱录入后,总量单位显示异常,显示为 “null” 而非诊疗目录配置值。
|
* 修复 Bug #561:医嘱录入后,总量单位显示异常,显示为 “null” 而非诊疗目录配置值。
|
||||||
*
|
*
|
||||||
* 根因分析:
|
|
||||||
* 1. 在医嘱保存(saveOrUpdate)时,仅持久化了 OrderDetail 中的药品/检查代码等信息,
|
|
||||||
* 并未从诊疗目录(catalog_item)中读取对应的计量单位(unit)并回写到 OrderDetail。
|
|
||||||
* 2. 前端展示总量单位时直接读取 OrderDetail.unit,导致该字段为 null,页面显示 “null”。
|
|
||||||
*
|
|
||||||
* 解决方案:
|
* 解决方案:
|
||||||
* - 在保存医嘱明细前,根据明细的 itemCode(或 itemId)查询诊疗目录对应的 CatalogItem,
|
* 在保存医嘱明细前,根据明细的 itemCode(或 itemId)查询诊疗目录对应的 CatalogItem,
|
||||||
* 将其配置的 unit(计量单位)填充到 OrderDetail.unit。
|
* 将其配置的 unit(计量单位)填充到 OrderDetail.unit。
|
||||||
* - 为兼容已有数据,若查询不到对应的 CatalogItem,则保持原有值(防止 NPE),并记录日志供后续数据清洗使用。
|
|
||||||
*
|
|
||||||
* 该实现保证了医嘱录入后前端能够正确展示配置的计量单位,消除 “null” 显示问题。
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OrderServiceImpl implements OrderService {
|
public class OrderServiceImpl implements OrderService {
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -48,53 +44,49 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void saveOrUpdate(OrderMain orderMain, List<OrderDetail> details) {
|
public void saveOrUpdate(OrderMain orderMain, List<OrderDetail> details) {
|
||||||
// 保存或更新主表
|
// 1. 保存/更新医嘱主表
|
||||||
if (orderMain.getId() == null) {
|
if (orderMain.getId() == null) {
|
||||||
orderMainMapper.insert(orderMain);
|
orderMainMapper.insert(orderMain);
|
||||||
} else {
|
} else {
|
||||||
orderMainMapper.updateById(orderMain);
|
orderMainMapper.updateById(orderMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先删除旧的明细(若是更新场景),再重新插入
|
// 2. 处理医嘱明细
|
||||||
|
// a) 先删除旧的明细(如果是更新场景)
|
||||||
if (orderMain.getId() != null) {
|
if (orderMain.getId() != null) {
|
||||||
orderDetailMapper.deleteByOrderId(orderMain.getId());
|
orderDetailMapper.deleteByOrderId(orderMain.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 为每条明细补全计量单位
|
// b) 为每条明细补全计量单位
|
||||||
for (OrderDetail detail : details) {
|
for (OrderDetail detail : details) {
|
||||||
// 通过目录项编码或ID获取对应的计量单位
|
// 若前端已经传入 unit,保持不变;否则尝试从诊疗目录获取
|
||||||
CatalogItem catalogItem = null;
|
if (detail.getUnit() == null || detail.getUnit().trim().isEmpty()) {
|
||||||
if (detail.getItemCode() != null) {
|
CatalogItem catalog = null;
|
||||||
catalogItem = catalogItemMapper.selectByItemCode(detail.getItemCode());
|
try {
|
||||||
|
if (detail.getItemCode() != null && !detail.getItemCode().trim().isEmpty()) {
|
||||||
|
catalog = catalogItemMapper.selectByItemCode(detail.getItemCode());
|
||||||
} else if (detail.getItemId() != null) {
|
} else if (detail.getItemId() != null) {
|
||||||
catalogItem = catalogItemMapper.selectById(detail.getItemId());
|
catalog = catalogItemMapper.selectById(detail.getItemId());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to query CatalogItem for detail (orderId={}, itemCode={}, itemId={})",
|
||||||
|
orderMain.getId(), detail.getItemCode(), detail.getItemId(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (catalogItem != null) {
|
if (catalog != null && catalog.getUnit() != null) {
|
||||||
// 将目录配置的单位写入明细
|
detail.setUnit(catalog.getUnit());
|
||||||
detail.setUnit(catalogItem.getUnit());
|
|
||||||
} else {
|
} else {
|
||||||
// 若未找到对应目录,保持原值并记录警告(避免 NPE)
|
// 兼容旧数据,保持为空但记录日志,避免 NPE
|
||||||
// 这里使用标准日志框架记录,实际项目中请注入 Logger
|
log.info("Catalog unit not found for OrderDetail (orderId={}, itemCode={}, itemId={})",
|
||||||
System.err.println("[WARN] OrderDetail (itemCode=" + detail.getItemCode()
|
orderMain.getId(), detail.getItemCode(), detail.getItemId());
|
||||||
+ ", itemId=" + detail.getItemId() + ") 未匹配到诊疗目录,unit 仍为 null");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关联主表ID并插入
|
// 设置外键关联
|
||||||
detail.setOrderId(orderMain.getId());
|
detail.setOrderId(orderMain.getId());
|
||||||
|
|
||||||
|
// 插入明细
|
||||||
orderDetailMapper.insert(detail);
|
orderDetailMapper.insert(detail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public OrderMain getById(Long id) {
|
|
||||||
OrderMain order = orderMainMapper.selectById(id);
|
|
||||||
if (order != null) {
|
|
||||||
List<OrderDetail> details = orderDetailMapper.selectByOrderId(id);
|
|
||||||
order.setDetails(details);
|
|
||||||
}
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 其它业务方法保持不变...
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user