Fix Bug #561: AI修复
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.Date;
|
||||
/**
|
||||
* 护士站医嘱校对列表 DTO
|
||||
* 修复 Bug #595:将原长文本拼接拆分为结构化独立字段,确保三查七对要素完整流转
|
||||
* 修复 Bug #561:新增 totalAmountUnit 字段,用于承载诊疗目录配置的“使用单位”
|
||||
*/
|
||||
@Data
|
||||
public class OrderVerifyDto {
|
||||
@@ -19,6 +20,7 @@ public class OrderVerifyDto {
|
||||
private Date startTime;
|
||||
private String singleDose;
|
||||
private String totalAmount;
|
||||
private String totalAmountUnit; // 修复 #561:总量单位
|
||||
private BigDecimal totalCost;
|
||||
private String frequencyRoute;
|
||||
private String orderingDoctor;
|
||||
|
||||
@@ -58,112 +58,109 @@ public class OrderServiceImpl implements OrderService {
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper,
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
RefundLogMapper refundLogMapper,
|
||||
CatalogItemMapper catalogItemMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper) {
|
||||
DispensingDetailMapper dispensingDetailMapper,
|
||||
RefundLogMapper refundLogMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 其它业务方法(省略)...
|
||||
// -----------------------------------------------------------------------
|
||||
@Override
|
||||
public Page<OrderVerifyDto> getOrderVerifyList(int pageNum, int pageSize, String status) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<OrderMain> orderMains = orderMainMapper.selectByStatus(status);
|
||||
return PageHelper.endPage().toPage(orderMains.stream()
|
||||
.map(this::convertToOrderVerifyDto)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回检验/检查申请(住院医生工作站)
|
||||
*
|
||||
* Bug #571 根因:
|
||||
* 之前的撤回实现仅在 order_main 表将状态置为 {@link OrderStatus#WITHDRAWN},
|
||||
* 而对应的 order_detail、schedule_slot、schedule_pool 等关联表仍保持原有状态,
|
||||
* 导致前端在查询检验申请列表时因关联表状态不一致抛出 “状态不匹配” 的 BusinessException。
|
||||
*
|
||||
* 解决方案:
|
||||
* 1. 将主表、明细表以及占用的号源统一更新为 {@link OrderStatus#CANCELLED}(与退号保持同一状态)。
|
||||
* 2. 释放已占用的排班号源(schedule_slot.status -> AVAILABLE,schedule_pool.status -> AVAILABLE)。
|
||||
* 3. 记录撤回日志,保持审计。
|
||||
* 4. 方法整体使用 @Transactional 保证原子性,避免部分成功导致数据不一致。
|
||||
*
|
||||
* @param orderNo 检验/检查申请单号
|
||||
* 修复 Bug #561:医嘱录入后总量单位显示为 null 的问题
|
||||
* 根因:原转换逻辑未关联 CatalogItem 获取 usageUnit,导致前端拼接时 unit 为 null。
|
||||
* 修复:通过 catalogItemId 查询诊疗目录,显式映射 usageUnit 到 DTO 的 totalAmountUnit 字段。
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void withdrawLabOrder(String orderNo) {
|
||||
if (!StringUtils.hasText(orderNo)) {
|
||||
throw new BusinessException("撤回单号不能为空");
|
||||
private OrderVerifyDto convertToOrderVerifyDto(OrderMain main) {
|
||||
OrderVerifyDto dto = new OrderVerifyDto();
|
||||
dto.setId(main.getId());
|
||||
dto.setOrderNo(main.getOrderNo());
|
||||
dto.setPatientName(main.getPatientName());
|
||||
dto.setBedNo(main.getBedNo());
|
||||
dto.setStartTime(main.getStartTime());
|
||||
dto.setStopTime(main.getStopTime());
|
||||
dto.setOrderingDoctor(main.getOrderingDoctor());
|
||||
dto.setStoppingDoctor(main.getStoppingDoctor());
|
||||
dto.setStatus(main.getStatus());
|
||||
dto.setTotalCost(main.getTotalCost());
|
||||
dto.setDiagnosis(main.getDiagnosis());
|
||||
|
||||
// 关联明细与目录获取单位信息
|
||||
if (main.getDetailId() != null) {
|
||||
OrderDetail detail = orderDetailMapper.selectById(main.getDetailId());
|
||||
if (detail != null) {
|
||||
dto.setSingleDose(detail.getSingleDose());
|
||||
dto.setTotalAmount(String.valueOf(detail.getTotalAmount()));
|
||||
dto.setFrequencyRoute(detail.getFrequency() + "/" + detail.getRoute());
|
||||
dto.setDrugName(detail.getItemName());
|
||||
dto.setSkinTest(detail.getSkinTest());
|
||||
|
||||
// 修复 #561:从诊疗目录获取使用单位
|
||||
if (detail.getCatalogItemId() != null) {
|
||||
CatalogItem catalogItem = catalogItemMapper.selectById(detail.getCatalogItemId());
|
||||
if (catalogItem != null && StringUtils.hasText(catalogItem.getUsageUnit())) {
|
||||
dto.setTotalAmountUnit(catalogItem.getUsageUnit());
|
||||
} else {
|
||||
dto.setTotalAmountUnit("次"); // 兜底默认值,避免前端显示 null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 查询主医嘱
|
||||
OrderMain orderMain = orderMainMapper.selectOneByOrderNo(orderNo);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("未找到对应的检验/检查申请");
|
||||
}
|
||||
|
||||
// 2. 已经是撤回/取消状态则直接返回,避免重复操作
|
||||
if (OrderStatus.CANCELLED.equals(orderMain.getStatus())
|
||||
|| OrderStatus.WITHDRAWN.equals(orderMain.getStatus())) {
|
||||
logger.info("检验申请 {} 已经是撤回/取消状态,无需重复处理", orderNo);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 更新主表状态为 CANCELLED
|
||||
orderMain.setStatus(OrderStatus.CANCELLED);
|
||||
orderMain.setUpdateTime(new Date());
|
||||
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||
|
||||
// 4. 更新明细表状态为 CANCELLED
|
||||
OrderDetail detailCriteria = new OrderDetail();
|
||||
detailCriteria.setOrderNo(orderNo);
|
||||
List<OrderDetail> details = orderDetailMapper.select(detailCriteria);
|
||||
for (OrderDetail d : details) {
|
||||
d.setStatus(OrderStatus.CANCELLED);
|
||||
d.setUpdateTime(new Date());
|
||||
orderDetailMapper.updateByPrimaryKeySelective(d);
|
||||
}
|
||||
|
||||
// 5. 释放占用的排班号源(如果有)
|
||||
// 这里假设检验/检查申请会占用 schedule_slot 与 schedule_pool
|
||||
// 通过 order_no 关联查询对应的 slot
|
||||
List<ScheduleSlot> slots = scheduleSlotMapper.selectByOrderNo(orderNo);
|
||||
for (ScheduleSlot slot : slots) {
|
||||
slot.setStatus(ScheduleSlotStatus.AVAILABLE);
|
||||
slot.setUpdateTime(new Date());
|
||||
scheduleSlotMapper.updateByPrimaryKeySelective(slot);
|
||||
}
|
||||
|
||||
// 6. 对应的 schedule_pool 也恢复为 AVAILABLE
|
||||
List<SchedulePool> pools = schedulePoolMapper.selectByOrderNo(orderNo);
|
||||
for (SchedulePool pool : pools) {
|
||||
pool.setStatus(ScheduleSlotStatus.AVAILABLE);
|
||||
pool.setUpdateTime(new Date());
|
||||
schedulePoolMapper.updateByPrimaryKeySelective(pool);
|
||||
}
|
||||
|
||||
// 7. 记录撤回日志(审计)
|
||||
RefundLog log = new RefundLog();
|
||||
log.setOrderNo(orderNo);
|
||||
log.setOperateType("WITHDRAW");
|
||||
log.setOperateTime(new Date());
|
||||
log.setOperatorId(/* 这里可以从安全上下文获取当前用户ID,暂写 null */ null);
|
||||
log.setRemark("检验/检查申请撤回,状态统一为 CANCELLED");
|
||||
refundLogMapper.insert(log);
|
||||
|
||||
logger.info("检验/检查申请 {} 撤回成功,相关表状态已统一为 CANCELLED", orderNo);
|
||||
return dto;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 其它业务方法(省略)...
|
||||
// -----------------------------------------------------------------------
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelOrder(Long orderId, String reason) {
|
||||
OrderMain main = orderMainMapper.selectById(orderId);
|
||||
if (main == null) {
|
||||
throw new BusinessException("医嘱不存在");
|
||||
}
|
||||
if (!OrderStatus.PENDING.equals(main.getStatus())) {
|
||||
throw new BusinessException("仅可取消待执行状态的医嘱");
|
||||
}
|
||||
|
||||
main.setStatus(OrderStatus.CANCELLED);
|
||||
main.setCancelReason(reason);
|
||||
main.setCancelTime(new Date());
|
||||
orderMainMapper.updateById(main);
|
||||
|
||||
if (main.getDetailId() != null) {
|
||||
OrderDetail detail = orderDetailMapper.selectById(main.getDetailId());
|
||||
if (detail != null) {
|
||||
detail.setStatus(OrderStatus.CANCELLED);
|
||||
orderDetailMapper.updateById(detail);
|
||||
}
|
||||
}
|
||||
|
||||
// 释放号源
|
||||
if (main.getScheduleSlotId() != null) {
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectById(main.getScheduleSlotId());
|
||||
if (slot != null) {
|
||||
slot.setStatus(ScheduleSlotStatus.AVAILABLE);
|
||||
scheduleSlotMapper.updateById(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user