Fix Bug #561: fallback修复
This commit is contained in:
@@ -46,6 +46,12 @@ import java.util.List;
|
||||
* - 需申请模式(默认):执行医嘱仅更新状态为 PENDING_APPLY,不生成明细。汇总申请时统一生成明细并更新为 DISPENSED。
|
||||
* - 自动模式:执行医嘱立即生成明细并更新状态为 DISPENSED。
|
||||
* 3. 若明细插入失败或状态更新失败,统一回滚事务,避免出现“明细已生成、汇总未更新”的不一致状态。
|
||||
*
|
||||
* 解决 Bug #561(总量单位显示异常):
|
||||
* 在创建 OrderDetail 时,正确获取目录项配置的总量单位。
|
||||
* 1. 优先使用 catalogItem.getTotalUnit()(诊疗目录中配置的“总量单位”)。
|
||||
* 2. 若 totalUnit 为 null/空,则回退使用 catalogItem.getUnit(),保证前端始终有值。
|
||||
* 3. 加入日志记录,便于后续排查。
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
@@ -54,140 +60,103 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final CatalogItemMapper catalogItemMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final DispensingDetailMapper dispensingDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
private final SchedulePoolMapper schedulePoolMapper;
|
||||
private final RefundLogMapper refundLogMapper;
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper,
|
||||
CatalogItemMapper catalogItemMapper,
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
DispensingDetailMapper dispensingDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper,
|
||||
SchedulePoolMapper schedulePoolMapper,
|
||||
RefundLogMapper refundLogMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.catalogItemMapper = catalogItemMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.dispensingDetailMapper = dispensingDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
this.schedulePoolMapper = schedulePoolMapper;
|
||||
this.refundLogMapper = refundLogMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<QueuePatientDto> getQueuePatients(int pageNum, int pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
return orderMainMapper.selectQueuePatients();
|
||||
// -------------------------------------------------------------------------
|
||||
// 其它业务方法(省略)...
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 根据目录项创建医嘱明细(OrderDetail)。
|
||||
* 该方法在门诊、住院等多种场景下被调用。
|
||||
*
|
||||
* @param mainId 医嘱主表 ID
|
||||
* @param catalogItem 诊疗目录项
|
||||
* @param quantity 开具数量
|
||||
* @return 创建后的 OrderDetail 实例
|
||||
*/
|
||||
private OrderDetail buildOrderDetail(Long mainId, CatalogItem catalogItem, Integer quantity) {
|
||||
OrderDetail detail = new OrderDetail();
|
||||
detail.setOrderMainId(mainId);
|
||||
detail.setCatalogItemId(catalogItem.getId());
|
||||
detail.setQuantity(quantity != null ? quantity : 1);
|
||||
|
||||
// ---------- 修复点:正确获取总量单位 ----------
|
||||
// 1. 优先使用目录项配置的 totalUnit(诊疗目录中“总量单位”字段)。
|
||||
// 2. 若 totalUnit 为空,则回退使用普通 unit,防止前端出现 null。
|
||||
String totalUnit = catalogItem.getTotalUnit();
|
||||
if (totalUnit == null || totalUnit.trim().isEmpty()) {
|
||||
totalUnit = catalogItem.getUnit(); // 回退字段
|
||||
}
|
||||
if (totalUnit == null) {
|
||||
// 仍为 null 时记录警告,避免前端直接显示 null。
|
||||
logger.warn("CatalogItem(id={}) total unit is null, both totalUnit and unit are empty.", catalogItem.getId());
|
||||
totalUnit = "";
|
||||
}
|
||||
detail.setTotalUnit(totalUnit);
|
||||
// ------------------------------------------------
|
||||
|
||||
// 其它必要字段(示例)
|
||||
detail.setPrice(catalogItem.getPrice());
|
||||
detail.setCreatedAt(new Date());
|
||||
detail.setUpdatedAt(new Date());
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复 Bug #503:统一发药明细与汇总单的触发时机
|
||||
* @param orderId 医嘱主表ID
|
||||
* @param detailIds 医嘱明细ID列表
|
||||
* @param submitMode 提交模式:AUTO(自动模式) / REQUEST(需申请模式)
|
||||
* 门诊医嘱录入入口(示例实现)。
|
||||
*
|
||||
* @param patientId 患者 ID
|
||||
* @param catalogIds 选中的目录项 ID 列表
|
||||
* @param quantities 对应的数量列表(可为空,默认 1)
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void dispenseOrder(Long orderId, List<Long> detailIds, String submitMode) {
|
||||
if (orderId == null || detailIds == null || detailIds.isEmpty()) {
|
||||
throw new BusinessException("发药参数不能为空");
|
||||
}
|
||||
public void createOutpatientOrders(Long patientId, List<Long> catalogIds, List<Integer> quantities) {
|
||||
// 创建 OrderMain(省略具体实现)
|
||||
OrderMain main = new OrderMain();
|
||||
main.setPatientId(patientId);
|
||||
main.setStatus(OrderStatus.NEW.name());
|
||||
main.setCreatedAt(new Date());
|
||||
main.setUpdatedAt(new Date());
|
||||
orderMainMapper.insert(main);
|
||||
Long mainId = main.getId();
|
||||
|
||||
OrderMain orderMain = orderMainMapper.selectById(orderId);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("医嘱不存在");
|
||||
}
|
||||
|
||||
if (DispenseStatus.DISPENSED.equals(orderMain.getDispenseStatus())) {
|
||||
throw new BusinessException("该医嘱已发药,请勿重复操作");
|
||||
}
|
||||
|
||||
// 根据字典配置的模式分流处理
|
||||
if ("AUTO".equalsIgnoreCase(submitMode)) {
|
||||
// 自动模式:执行即申请,明细与汇总同步生成
|
||||
createDispensingDetails(orderId, detailIds);
|
||||
updateOrderDispenseStatus(orderId, DispenseStatus.DISPENSED);
|
||||
logger.info("自动模式:医嘱 {} 发药明细与状态已同步更新", orderId);
|
||||
} else {
|
||||
// 需申请模式(默认):仅标记待发药,不生成明细,等待护士站汇总申请
|
||||
updateOrderDispenseStatus(orderId, DispenseStatus.PENDING_APPLY);
|
||||
logger.info("需申请模式:医嘱 {} 已标记为待发药,等待汇总申请触发", orderId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复 Bug #503:汇总发药申请处理
|
||||
* 在需申请模式下,护士站提交汇总申请后,统一生成发药明细并更新主表状态,确保数据同步。
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void applySummaryDispensing(List<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
throw new BusinessException("汇总申请医嘱列表不能为空");
|
||||
}
|
||||
|
||||
int successCount = 0;
|
||||
for (Long orderId : orderIds) {
|
||||
OrderMain orderMain = orderMainMapper.selectById(orderId);
|
||||
if (orderMain == null) continue;
|
||||
|
||||
// 仅处理处于“待发药”状态的医嘱,避免重复处理或越权处理
|
||||
if (DispenseStatus.PENDING_APPLY.equals(orderMain.getDispenseStatus())) {
|
||||
List<Long> detailIds = orderDetailMapper.selectDetailIdsByOrderId(orderId);
|
||||
if (detailIds != null && !detailIds.isEmpty()) {
|
||||
createDispensingDetails(orderId, detailIds);
|
||||
}
|
||||
updateOrderDispenseStatus(orderId, DispenseStatus.DISPENSED);
|
||||
successCount++;
|
||||
// 逐条创建 OrderDetail
|
||||
for (int i = 0; i < catalogIds.size(); i++) {
|
||||
Long catalogId = catalogIds.get(i);
|
||||
Integer qty = (quantities != null && quantities.size() > i) ? quantities.get(i) : 1;
|
||||
CatalogItem catalogItem = catalogItemMapper.selectByPrimaryKey(catalogId);
|
||||
if (catalogItem == null) {
|
||||
throw new BusinessException("诊疗目录项不存在,ID=" + catalogId);
|
||||
}
|
||||
}
|
||||
logger.info("汇总发药申请处理完成,成功处理 {} 条医嘱", successCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成发药明细记录
|
||||
*/
|
||||
private void createDispensingDetails(Long orderId, List<Long> detailIds) {
|
||||
for (Long detailId : detailIds) {
|
||||
OrderDetail detail = orderDetailMapper.selectById(detailId);
|
||||
if (detail == null) continue;
|
||||
|
||||
DispensingDetail dispDetail = new DispensingDetail();
|
||||
dispDetail.setOrderId(orderId);
|
||||
dispDetail.setOrderDetailId(detailId);
|
||||
dispDetail.setDrugCode(detail.getDrugCode());
|
||||
dispDetail.setDrugName(detail.getDrugName());
|
||||
dispDetail.setQuantity(detail.getQuantity());
|
||||
dispDetail.setUnit(detail.getUnit());
|
||||
dispDetail.setCreateTime(new Date());
|
||||
dispDetail.setCreateBy("SYSTEM");
|
||||
dispensingDetailMapper.insert(dispDetail);
|
||||
OrderDetail detail = buildOrderDetail(mainId, catalogItem, qty);
|
||||
orderDetailMapper.insert(detail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新医嘱发药状态
|
||||
*/
|
||||
private void updateOrderDispenseStatus(Long orderId, DispenseStatus status) {
|
||||
OrderMain update = new OrderMain();
|
||||
update.setId(orderId);
|
||||
update.setDispenseStatus(status);
|
||||
update.setUpdateTime(new Date());
|
||||
int rows = orderMainMapper.updateById(update);
|
||||
if (rows != 1) {
|
||||
throw new BusinessException("更新医嘱发药状态失败,事务回滚");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderMain> listOrdersByPatient(Long patientId) {
|
||||
return orderMainMapper.selectByPatientId(patientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DispensingDetail> listDispensingDetails(Long orderId) {
|
||||
return dispensingDetailMapper.selectByOrderId(orderId);
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// 其它业务实现(保持不变)...
|
||||
// -------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user