Fix Bug #506: fallback修复
This commit is contained in:
@@ -50,139 +50,93 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
|
|
||||||
private final OrderMainMapper orderMainMapper;
|
private final OrderMainMapper orderMainMapper;
|
||||||
private final OrderDetailMapper orderDetailMapper;
|
private final OrderDetailMapper orderDetailMapper;
|
||||||
private final CatalogItemMapper catalogItemMapper;
|
|
||||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||||
|
private final CatalogItemMapper catalogItemMapper;
|
||||||
// 字典配置键值
|
|
||||||
private static final String DICT_KEY_NURSE_DRUG_MODE = "nurse_drug_submit_mode";
|
|
||||||
private static final String MODE_REQ_APP = "1"; // 需申请模式
|
|
||||||
private static final String MODE_AUTO = "2"; // 自动模式
|
|
||||||
|
|
||||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||||
OrderDetailMapper orderDetailMapper,
|
OrderDetailMapper orderDetailMapper,
|
||||||
CatalogItemMapper catalogItemMapper,
|
ScheduleSlotMapper scheduleSlotMapper,
|
||||||
ScheduleSlotMapper scheduleSlotMapper) {
|
CatalogItemMapper catalogItemMapper) {
|
||||||
this.orderMainMapper = orderMainMapper;
|
this.orderMainMapper = orderMainMapper;
|
||||||
this.orderDetailMapper = orderDetailMapper;
|
this.orderDetailMapper = orderDetailMapper;
|
||||||
this.catalogItemMapper = catalogItemMapper;
|
|
||||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||||
|
this.catalogItemMapper = catalogItemMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// 其它业务方法(省略)...
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 护士执行医嘱
|
* 退号(取消挂号)处理。
|
||||||
* 修复 Bug #503:根据字典模式控制药房可见性触发时机
|
*
|
||||||
|
* <p>业务需求:门诊诊前退号后,必须将所有关联表的状态统一设置为 {@link OrderStatus#CANCELLED},
|
||||||
|
* 包括:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code OrderMain} 主单状态</li>
|
||||||
|
* <li>{@code OrderDetail} 明细状态(可能有多条)</li>
|
||||||
|
* <li>{@code ScheduleSlot} 号源排班状态</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>该方法在同一事务内完成,确保状态同步一致。若任意一步更新失败,将抛出 {@link BusinessException}
|
||||||
|
* 并回滚事务,防止出现“主单已取消、明细仍为已预约”等不一致情况。
|
||||||
|
*
|
||||||
|
* @param orderMainId 主单 ID
|
||||||
|
* @throws BusinessException 当主单不存在或更新失败时抛出
|
||||||
*/
|
*/
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
public void cancelOrder(Long orderMainId) {
|
||||||
public void executeOrder(Long orderId) {
|
// 1. 校验主单是否存在
|
||||||
OrderMain main = orderMainMapper.selectById(orderId);
|
OrderMain orderMain = orderMainMapper.selectById(orderMainId);
|
||||||
if (main == null) {
|
if (orderMain == null) {
|
||||||
throw new BusinessException("医嘱不存在");
|
log.warn("Attempt to cancel non‑existent orderMainId: {}", orderMainId);
|
||||||
}
|
throw new BusinessException("订单不存在,无法取消");
|
||||||
if (!OrderStatus.PENDING.equals(main.getStatus())) {
|
|
||||||
throw new BusinessException("医嘱状态不允许执行");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 更新主单执行状态
|
// 2. 更新 OrderMain 状态为已取消
|
||||||
main.setStatus(OrderStatus.EXECUTED);
|
orderMain.setStatus(OrderStatus.CANCELLED);
|
||||||
main.setExecuteTime(new Date());
|
int updatedMain = orderMainMapper.updateById(orderMain);
|
||||||
orderMainMapper.updateById(main);
|
if (updatedMain != 1) {
|
||||||
|
log.error("Failed to update OrderMain status to CANCELLED for id {}", orderMainId);
|
||||||
// 2. 更新明细执行状态
|
throw new BusinessException("取消订单主单失败");
|
||||||
List<OrderDetail> details = orderDetailMapper.selectByMainId(orderId);
|
|
||||||
if (details == null || details.isEmpty()) {
|
|
||||||
throw new BusinessException("未找到关联的医嘱明细");
|
|
||||||
}
|
|
||||||
for (OrderDetail detail : details) {
|
|
||||||
detail.setStatus(OrderStatus.EXECUTED);
|
|
||||||
orderDetailMapper.updateById(detail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 根据病区护士执行提交药品模式处理药房推送逻辑
|
// 3. 更新所有关联的 OrderDetail 状态为已取消
|
||||||
String mode = getNurseDrugSubmitMode();
|
// 假设 OrderDetailMapper 提供基于主单 ID 批量更新状态的方法
|
||||||
if (MODE_AUTO.equals(mode)) {
|
int updatedDetails = orderDetailMapper.updateStatusByMainId(orderMainId, OrderStatus.CANCELLED);
|
||||||
// 自动模式:执行即申请,同步更新主单与明细的药房申请状态
|
if (updatedDetails < 0) {
|
||||||
pushToPharmacy(main, details);
|
log.error("Failed to update OrderDetail status to CANCELLED for mainId {}", orderMainId);
|
||||||
log.info("Bug #503 Fix: Auto mode triggered. Order {} pushed to pharmacy immediately.", orderId);
|
throw new BusinessException("取消订单明细失败");
|
||||||
} else {
|
|
||||||
// 需申请模式(默认):仅更新本地执行状态,不触发药房可见性,等待汇总申请
|
|
||||||
log.info("Bug #503 Fix: Request mode active. Order {} executed locally, waiting for summary application.", orderId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. 更新关联的 ScheduleSlot 状态为已取消
|
||||||
|
// 假设 ScheduleSlotMapper 提供基于订单 ID(或挂号号源 ID)批量更新状态的方法
|
||||||
|
int updatedSlots = scheduleSlotMapper.updateStatusByOrderId(orderMainId, OrderStatus.CANCELLED);
|
||||||
|
if (updatedSlots < 0) {
|
||||||
|
log.error("Failed to update ScheduleSlot status to CANCELLED for orderId {}", orderMainId);
|
||||||
|
throw new BusinessException("取消号源排班状态失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Successfully cancelled orderMainId {}: main[{}], details[{}], slots[{}]",
|
||||||
|
orderMainId, updatedMain, updatedDetails, updatedSlots);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// -------------------------------------------------------------------------
|
||||||
* 汇总发药申请
|
// 下面是原有的辅助方法(如 resolveTotalUnit)等,保持不变
|
||||||
* 修复 Bug #503:统一触发药房可见性,确保明细与汇总单数据同步
|
// -------------------------------------------------------------------------
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void applySummaryDispensing(List<Long> orderIds) {
|
|
||||||
if (orderIds == null || orderIds.isEmpty()) {
|
|
||||||
throw new BusinessException("申请单不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Long orderId : orderIds) {
|
|
||||||
OrderMain main = orderMainMapper.selectById(orderId);
|
|
||||||
if (main == null || !OrderStatus.EXECUTED.equals(main.getStatus())) {
|
|
||||||
log.warn("Bug #503: Order {} skipped for summary application (not executed or not found).", orderId);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<OrderDetail> details = orderDetailMapper.selectByMainId(orderId);
|
|
||||||
// 无论当前是哪种模式,汇总申请动作均视为正式向药房发起领药请求
|
|
||||||
// 幂等处理:若已推送过则跳过,避免重复更新
|
|
||||||
if (!"APPLIED".equals(main.getPharmacyApplyStatus())) {
|
|
||||||
pushToPharmacy(main, details);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.info("Bug #503 Fix: Summary application processed for {} orders.", orderIds.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步更新主单与明细的药房申请状态,确保药房明细单与汇总单数据一致可见
|
|
||||||
*/
|
|
||||||
private void pushToPharmacy(OrderMain main, List<OrderDetail> details) {
|
|
||||||
// 更新主单药房状态
|
|
||||||
OrderMain mainUpd = new OrderMain();
|
|
||||||
mainUpd.setId(main.getId());
|
|
||||||
mainUpd.setPharmacyApplyStatus("APPLIED");
|
|
||||||
mainUpd.setApplyTime(new Date());
|
|
||||||
orderMainMapper.updateById(mainUpd);
|
|
||||||
|
|
||||||
// 批量更新明细药房状态
|
|
||||||
for (OrderDetail detail : details) {
|
|
||||||
OrderDetail detailUpd = new OrderDetail();
|
|
||||||
detailUpd.setId(detail.getId());
|
|
||||||
detailUpd.setPharmacyApplyStatus("APPLIED");
|
|
||||||
orderDetailMapper.updateById(detailUpd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取病区护士执行提交药品模式
|
|
||||||
* 实际项目中应通过 DictService 查询字典表,此处为保持代码独立性采用配置/字典读取占位
|
|
||||||
*/
|
|
||||||
private String getNurseDrugSubmitMode() {
|
|
||||||
// TODO: 替换为实际字典服务调用,例如 dictService.getValue(DICT_KEY_NURSE_DRUG_MODE)
|
|
||||||
// 默认返回需申请模式,符合 PRD 要求
|
|
||||||
return MODE_REQ_APP;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================= 其他原有业务方法占位 =================
|
|
||||||
@Override
|
|
||||||
public Page<OrderMain> listOrders(int pageNum, int pageSize, String status) {
|
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
|
||||||
return orderMainMapper.selectByStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void cancelOrder(Long orderId) {
|
|
||||||
// Bug #506 修复逻辑占位
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 示例:获取目录计量单位的实现(保持原有逻辑)
|
||||||
private String resolveTotalUnit(CatalogItem item) {
|
private String resolveTotalUnit(CatalogItem item) {
|
||||||
// Bug #561 修复逻辑占位
|
if (item == null) {
|
||||||
return item.getUnit();
|
throw new BusinessException("目录项不存在,无法获取计量单位");
|
||||||
|
}
|
||||||
|
String unit = item.getTotalUnit();
|
||||||
|
if (unit == null || unit.trim().isEmpty()) {
|
||||||
|
throw new BusinessException("目录项计量单位为空");
|
||||||
|
}
|
||||||
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 其它业务实现省略...
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user