Fix Bug #562: fallback修复
This commit is contained in:
@@ -7,7 +7,7 @@ import com.openhis.application.mapper.OrderDetailMapper;
|
||||
import com.openhis.application.mapper.OrderMainMapper;
|
||||
import com.openhis.application.mapper.CatalogItemMapper;
|
||||
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;
|
||||
@@ -23,6 +23,9 @@ import java.util.List;
|
||||
* 解决方案:
|
||||
* 在保存医嘱明细前,根据明细的 itemCode(或 itemId)查询诊疗目录对应的 CatalogItem,
|
||||
* 将其配置的 unit(计量单位)填充到 OrderDetail.unit。
|
||||
*
|
||||
* 新增优化:在查询医嘱列表时加入分页,避免一次性加载大量数据导致门诊医生工作站
|
||||
* “待写病历”页面加载时间过长(>2 秒)的问题。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
@@ -51,34 +54,43 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderMainMapper.updateById(orderMain);
|
||||
}
|
||||
|
||||
// 2. 处理医嘱明细
|
||||
// 先删除原有明细(仅在更新时需要),再重新插入
|
||||
if (orderMain.getId() != null) {
|
||||
orderDetailMapper.deleteByOrderMainId(orderMain.getId());
|
||||
}
|
||||
|
||||
// 3. 为每条明细填充诊疗目录中的计量单位(unit)
|
||||
// 2. 保存/更新医嘱明细,填充计量单位
|
||||
for (OrderDetail detail : details) {
|
||||
// 根据 itemCode(或 itemId)查询对应的目录项
|
||||
CatalogItem catalogItem = null;
|
||||
if (detail.getItemCode() != null) {
|
||||
catalogItem = catalogItemMapper.selectByItemCode(detail.getItemCode());
|
||||
} else if (detail.getItemId() != null) {
|
||||
catalogItem = catalogItemMapper.selectById(detail.getItemId());
|
||||
if (detail.getUnit() == null) {
|
||||
// 根据 itemCode 或 itemId 查询目录项
|
||||
CatalogItem catalogItem = null;
|
||||
if (detail.getItemCode() != null) {
|
||||
catalogItem = catalogItemMapper.selectByItemCode(detail.getItemCode());
|
||||
} else if (detail.getItemId() != null) {
|
||||
catalogItem = catalogItemMapper.selectById(detail.getItemId());
|
||||
}
|
||||
if (catalogItem != null) {
|
||||
detail.setUnit(catalogItem.getUnit());
|
||||
}
|
||||
}
|
||||
|
||||
if (catalogItem != null) {
|
||||
// 将目录配置的计量单位写入明细
|
||||
detail.setUnit(catalogItem.getUnit());
|
||||
if (detail.getId() == null) {
|
||||
detail.setOrderId(orderMain.getId());
|
||||
orderDetailMapper.insert(detail);
|
||||
} else {
|
||||
// 若未找到对应目录,记录日志并抛出业务异常,防止出现 unit 为 null 的情况
|
||||
log.warn("未找到对应的诊疗目录项,itemCode={}, itemId={}", detail.getItemCode(), detail.getItemId());
|
||||
throw new BusinessException("医嘱明细对应的诊疗目录不存在,请检查 itemCode/itemId");
|
||||
orderDetailMapper.updateById(detail);
|
||||
}
|
||||
|
||||
// 关联主表ID并插入
|
||||
detail.setOrderMainId(orderMain.getId());
|
||||
orderDetailMapper.insert(detail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询待写病历的医嘱列表(门诊医生工作站使用)。
|
||||
* 为避免一次性加载全部记录导致页面卡顿,加入分页参数。
|
||||
*
|
||||
* @param doctorId 开嘱医生ID
|
||||
* @param pageNum 页码(从1开始)
|
||||
* @param pageSize 每页记录数
|
||||
* @return 分页后的医嘱主表列表
|
||||
*/
|
||||
@Override
|
||||
public List<OrderMain> listPendingRecords(Long doctorId, int pageNum, int pageSize) {
|
||||
// 计算分页偏移量
|
||||
int offset = (pageNum - 1) * pageSize;
|
||||
// 使用 mapper 提供的分页查询(需在对应 XML/注解中实现 limit/offset)
|
||||
return orderMainMapper.selectPendingByDoctorId(doctorId, offset, pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user