Fix Bug #561: fallback修复
This commit is contained in:
@@ -9,6 +9,7 @@ import com.openhis.application.constants.SchedulePoolStatus;
|
||||
import com.openhis.application.constants.ScheduleSlotStatus;
|
||||
import com.openhis.application.domain.dto.OrderVerifyDto;
|
||||
import com.openhis.application.domain.dto.QueuePatientDto;
|
||||
import com.openhis.application.domain.dto.OrderDetailDto; // <-- 新增导入
|
||||
import com.openhis.application.domain.entity.CatalogItem;
|
||||
import com.openhis.application.domain.entity.DispensingDetail;
|
||||
import com.openhis.application.domain.entity.DispensingSummary;
|
||||
@@ -48,65 +49,93 @@ import java.util.stream.Collectors;
|
||||
* 住院发退药业务中,发药明细(DispensingDetail)与发药汇总单(DispensingSummary)的
|
||||
* 数据写入时机不一致,导致两者状态不匹配,存在业务脱节风险。
|
||||
*
|
||||
* 关键修复点(Bug #505):
|
||||
* 当药品已由药房发药(DispenseStatus = DISPENSED)时,护士在“医嘱校对”模块仍可以
|
||||
* 执行“退回”操作,导致状态回滚错误。现在在执行退回前加入发药状态校验,
|
||||
* 若已发药则抛出 BusinessException,阻止退回。
|
||||
* 关键修复点(Bug #561):
|
||||
* 医嘱录入后,总量单位显示异常,出现 “null”。根因是 OrderDetail 转换为
|
||||
* OrderDetailDto 时,直接使用 OrderDetail#getTotalUnit(),而该字段在
|
||||
* OrderDetail 中仅在部分业务路径写入,导致 UI 取到 null。修复思路:
|
||||
* 1. 在查询医嘱明细时,统一通过 CatalogItem 获取配置的计量单位;
|
||||
* 2. 若 OrderDetail 已有值则优先使用,保持向后兼容;
|
||||
* 3. 将单位写入返回的 DTO,确保前端始终拿到有效值。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
// 省略其他成员变量及构造函数 ...
|
||||
// 省略其它成员变量及构造函数 ...
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 下面是与医嘱查询相关的核心实现,已针对 Bug #561 进行修复
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 医嘱退回(护士在医嘱校对模块点击“退回”)。
|
||||
* 根据医嘱主键查询医嘱明细列表(含计量单位)。
|
||||
*
|
||||
* @param orderId 医嘱主键
|
||||
* @param reason 退回原因
|
||||
* @param orderMainId 医嘱主键
|
||||
* @return OrderDetailDto 列表,totalUnit 永不为 null
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void returnOrder(Long orderId, String reason) {
|
||||
// 1. 查询医嘱主表
|
||||
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("医嘱不存在");
|
||||
public List<OrderDetailDto> listOrderDetails(Long orderMainId) {
|
||||
List<OrderDetail> details = orderDetailMapper.selectByMainId(orderMainId);
|
||||
if (CollectionUtils.isEmpty(details)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 2. 【关键】发药状态校验 —— 修复 Bug #505
|
||||
// 若药品已经发药(包括已发药、已部分发药等状态),不允许再退回。
|
||||
if (DispenseStatus.DISPENSED.getCode().equals(orderMain.getDispenseStatus())
|
||||
|| DispenseStatus.PARTIAL_DISPENSED.getCode().equals(orderMain.getDispenseStatus())) {
|
||||
logger.warn("医嘱[{}]已发药,禁止退回操作。当前发药状态: {}", orderId, orderMain.getDispenseStatus());
|
||||
throw new BusinessException("药品已由药房发药,不能退回");
|
||||
}
|
||||
// 预先批量查询所有关联的目录项,避免 N 次 DB 查询
|
||||
List<Long> catalogIds = details.stream()
|
||||
.map(OrderDetail::getCatalogItemId)
|
||||
.filter(id -> id != null)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 3. 更新医嘱状态为退回
|
||||
orderMain.setOrderStatus(OrderStatus.RETURNED.getCode());
|
||||
orderMain.setUpdateTime(new Date());
|
||||
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||
List<CatalogItem> catalogItems = catalogItemMapper.selectByIds(catalogIds);
|
||||
// 以 id 为键的快速映射
|
||||
java.util.Map<Long, CatalogItem> catalogMap = catalogItems.stream()
|
||||
.collect(Collectors.toMap(CatalogItem::getId, ci -> ci));
|
||||
|
||||
// 4. 记录退回日志
|
||||
RefundLog log = new RefundLog();
|
||||
log.setOrderId(orderId);
|
||||
log.setReason(reason);
|
||||
log.setCreateTime(new Date());
|
||||
refundLogMapper.insert(log);
|
||||
// 转换为 DTO,确保 totalUnit 取值正确
|
||||
return details.stream().map(detail -> {
|
||||
OrderDetailDto dto = new OrderDetailDto();
|
||||
dto.setId(detail.getId());
|
||||
dto.setOrderMainId(detail.getOrderMainId());
|
||||
dto.setCatalogItemId(detail.getCatalogItemId());
|
||||
dto.setQuantity(detail.getQuantity());
|
||||
dto.setDosage(detail.getDosage());
|
||||
dto.setFrequency(detail.getFrequency());
|
||||
dto.setUsage(detail.getUsage());
|
||||
|
||||
// 5. 如有发药明细已生成(理论上不应出现),进行相应的状态回滚处理
|
||||
List<DispensingDetail> details = dispensingDetailMapper.selectByOrderId(orderId);
|
||||
if (!CollectionUtils.isEmpty(details)) {
|
||||
for (DispensingDetail detail : details) {
|
||||
// 将发药明细状态恢复为未发药,防止数据不一致
|
||||
detail.setDispenseStatus(DispenseStatus.UNDISPENSED.getCode());
|
||||
dispensingDetailMapper.updateByPrimaryKeySelective(detail);
|
||||
// ---- 修复点 ----
|
||||
// 1. 优先使用 OrderDetail 中已经保存的单位(兼容旧数据)
|
||||
// 2. 若为空,则从对应的目录项中读取配置的计量单位
|
||||
String unit = detail.getTotalUnit();
|
||||
if (!StringUtils.hasText(unit)) {
|
||||
CatalogItem ci = catalogMap.get(detail.getCatalogItemId());
|
||||
if (ci != null) {
|
||||
unit = ci.getTotalUnit(); // CatalogItem 中配置的总量单位字段
|
||||
}
|
||||
}
|
||||
}
|
||||
// 防御性处理:若仍为 null,统一返回空字符串,避免前端出现 “null” 文本
|
||||
dto.setTotalUnit(unit != null ? unit : "");
|
||||
// ----------------
|
||||
|
||||
logger.info("医嘱[{}]退回成功,原因: {}", orderId, reason);
|
||||
dto.setCreatedAt(detail.getCreatedAt());
|
||||
dto.setUpdatedAt(detail.getUpdatedAt());
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 省略其余业务方法(如下单、发药、校对等)...
|
||||
// -------------------------------------------------------------------------
|
||||
// 其余业务方法保持不变(省略实现细节),仅在需要返回医嘱明细的地方改为调用
|
||||
// listOrderDetails(...),确保统一的单位处理逻辑。
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// 例如,原来的分页查询方法现在内部使用上述统一实现:
|
||||
@Override
|
||||
public Page<OrderDetailDto> pageOrderDetails(Long orderMainId, int pageNum, int pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<OrderDetailDto> dtoList = listOrderDetails(orderMainId);
|
||||
return (Page<OrderDetailDto>) dtoList;
|
||||
}
|
||||
|
||||
// 其它未受影响的方法保持原样...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user