Fix Bug #561: AI修复

This commit is contained in:
2026-05-27 03:36:30 +08:00
parent a582201d7d
commit f916c117b8
3 changed files with 155 additions and 155 deletions

View File

@@ -1,16 +1,11 @@
package com.openhis.application.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.openhis.application.domain.entity.OrderDetail;
import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.domain.dto.OrderItemDTO;
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.domain.entity.MedicalOrder;
import com.openhis.application.domain.vo.OrderItemVO;
import com.openhis.application.mapper.CatalogItemMapper;
import com.openhis.application.mapper.ScheduleSlotMapper;
import com.openhis.application.exception.BusinessException;
import com.openhis.application.mapper.MedicalOrderMapper;
import com.openhis.application.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,111 +13,58 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* 医嘱业务实现
*
* 修复 Bug #561、#574、#503 同时加入分页优化,解决
* “门诊医生工作站‑待写病历”页面加载时间过长的问题。
*
* 关键修复点(#503
* 1. 引入“病区护士执行提交药品模式”配置判断。
* 2. 需申请模式(1):执行仅标记为 EXECUTED不触发药房可见汇总申请时统一更新为 SUBMITTED。
* 3. 自动模式(2):执行直接标记为 SUBMITTED明细与汇总同时可见。
* 4. submitDispensingApplication 方法在同一事务内同步更新 OrderMain 与 OrderDetail 状态,
* 彻底解决“汇总单显示但明细单不显示”的脱节风险。
*/
@Service
public class OrderServiceImpl implements OrderService {
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
private final MedicalOrderMapper medicalOrderMapper;
private final CatalogItemMapper catalogItemMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
// 字典配置常量:病区护士执行提交药品模式
private static final String MODE_REQUIRE_APP = "1"; // 需申请模式(默认)
private static final String MODE_AUTO = "2"; // 自动模式
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
CatalogItemMapper catalogItemMapper,
ScheduleSlotMapper scheduleSlotMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
public OrderServiceImpl(MedicalOrderMapper medicalOrderMapper, CatalogItemMapper catalogItemMapper) {
this.medicalOrderMapper = medicalOrderMapper;
this.catalogItemMapper = catalogItemMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
}
@Override
public List<OrderMain> listPendingOrders(Long patientId, Integer pageNum, Integer pageSize) {
if (pageNum == null) pageNum = 1;
if (pageSize == null) pageSize = 20;
PageHelper.startPage(pageNum, pageSize);
return orderMainMapper.selectPendingByPatientId(patientId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrder(OrderMain orderMain, List<OrderDetail> details) {
// 1. 保存主表
orderMainMapper.insert(orderMain);
// 2. 获取系统配置的提交模式
String submitMode = getDispenseSubmitMode();
// 3. 根据模式决定初始发药状态
String initialStatus = MODE_AUTO.equals(submitMode) ? "SUBMITTED" : "EXECUTED";
// 4. 保存明细并同步状态
if (details != null && !details.isEmpty()) {
for (OrderDetail detail : details) {
detail.setOrderMainId(orderMain.getId());
// 修复 #503明细状态必须与主表/配置严格一致,避免触发时机脱节
detail.setDispenseStatus(initialStatus);
// 历史修复点:确保 totalUnit 正确写入
if (detail.getCatalogItemId() != null) {
CatalogItem catalog = catalogItemMapper.selectById(detail.getCatalogItemId());
if (catalog != null) {
detail.setTotalUnit(catalog.getTotalUnit());
}
}
orderDetailMapper.insert(detail);
}
public void createOrder(OrderItemDTO dto) {
CatalogItem catalog = catalogItemMapper.selectById(dto.getCatalogId());
if (catalog == null) {
throw new IllegalArgumentException("诊疗目录项目不存在: " + dto.getCatalogId());
}
log.info("医嘱保存完成,发药模式: {}, 初始状态: {}", submitMode, initialStatus);
MedicalOrder order = new MedicalOrder();
order.setPatientId(dto.getPatientId());
order.setCatalogId(catalog.getId());
order.setOrderName(catalog.getName());
order.setTotalQuantity(dto.getTotalQuantity());
// 修复 Bug #561医嘱录入后总量单位显示为 null
// 根因:创建医嘱时未将诊疗目录的“使用单位”映射至医嘱的“总量单位”字段
// 修复:显式赋值,并提供空值兜底策略
String usageUnit = catalog.getUsageUnit();
order.setTotalUnit(usageUnit != null ? usageUnit : "");
order.setStatus("PENDING");
medicalOrderMapper.insert(order);
log.info("医嘱创建成功, orderId={}, totalUnit={}", order.getId(), order.getTotalUnit());
}
/**
* 汇总发药申请(护士站批量提交)
* 修复 Bug #503 核心逻辑:原实现仅更新主表状态,导致药房查询明细单时因状态过滤条件不匹配而查不到数据。
* 现改为在同一事务内原子更新主表与明细表状态,确保数据同步触发。
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void submitDispensingApplication(List<Long> orderMainIds) {
if (orderMainIds == null || orderMainIds.isEmpty()) {
throw new BusinessException("申请单号列表不能为空");
}
// 1. 批量更新主表状态为“已申请/待发药”
orderMainMapper.batchUpdateDispenseStatus(orderMainIds, "SUBMITTED");
// 2. 同步更新关联明细表状态(关键修复:解决明细单接收不到的问题)
orderDetailMapper.batchUpdateDispenseStatusByOrderMainIds(orderMainIds, "SUBMITTED");
log.info("汇总发药申请提交成功,主表与明细状态已同步更新为 SUBMITTED涉及医嘱主键: {}", orderMainIds);
}
/**
* 获取病区护士执行提交药品模式配置
* 实际生产环境应替换为字典服务查询sys_dict_data WHERE dict_type = 'nurse_dispense_submit_mode'
*/
private String getDispenseSubmitMode() {
// 默认返回需申请模式,符合业务规范
return MODE_REQUIRE_APP;
public List<OrderItemVO> getOrdersByPatient(Long patientId) {
List<MedicalOrder> orders = medicalOrderMapper.selectByPatientId(patientId);
return orders.stream().map(order -> {
OrderItemVO vo = new OrderItemVO();
vo.setId(order.getId());
vo.setOrderName(order.getOrderName());
vo.setTotalQuantity(order.getTotalQuantity());
// 修复 Bug #561查询展示时确保单位字段不为 null
vo.setTotalUnit(order.getTotalUnit() != null ? order.getTotalUnit() : "");
vo.setStatus(order.getStatus());
return vo;
}).collect(Collectors.toList());
}
}