Fix Bug #561: AI修复

This commit is contained in:
2026-05-27 04:32:05 +08:00
parent 15b542acf0
commit 8f5b7ad9f7
4 changed files with 171 additions and 108 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Date;
* 订单明细实体
*
* 为了支持退款业务,新增 scheduleSlotId 字段(对应数据库列 schedule_slot_id
* 修复 Bug #561新增 unit 字段用于承载诊疗目录配置的“使用单位”。
*/
public class OrderDetail {
private Long id;
@@ -18,6 +19,9 @@ public class OrderDetail {
/** 对应排班号主键 */
private Long scheduleSlotId;
/** 修复 Bug #561总量单位对应诊疗目录的使用单位 */
private String unit;
// getters & setters
public Long getId() {
@@ -75,4 +79,12 @@ public class OrderDetail {
public void setScheduleSlotId(Long scheduleSlotId) {
this.scheduleSlotId = scheduleSlotId;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
}

View File

@@ -26,125 +26,94 @@ import java.util.List;
*
* 修复 Bug #505、#503、#506、#561 等。
*
* 关键修复说明(Bug #503
* 住院发药明细与发药汇总单在业务触发时机不一致,导致排班号状态未能同步更新。
* 为保证发药明细OrderDetail与发药汇总OrderMain在同一事务内完成
* 并且在支付成功后立即将对应的排班号状态更新为3”(已取),
* 同时在诊前退号(退款)时将排班号状态更新为 “4”已退号
* 新增修复 Bug #574
* 在预约挂号完成支付后需要将对应的排班号状态adm_schedule_slot.status及时
* 流转为 “3”已取。原来的实现只更新了 OrderMain 表,导致前端查询排班号时仍显示为
* 2”(已预约),出现业务不一致。
*
* 实现思路
* 1. 在 payOrder 中,先查询 OrderDetail 获取关联的 scheduleSlotId
* 若存在则调用 ScheduleSlotMapper.updateStatusById(id, "3")
* 再更新 OrderMain、OrderDetail 状态为 OrderStatus.COMPLETED
* 所有操作在同一事务内完成,确保原子性
* 2. 在 refundOrder 中,同样获取 scheduleSlotId 并更新为 “4”
* 并将 OrderMain、OrderDetail 状态统一设为 OrderStatus.REFUND。
* 解决方案
* 1. 在支付成功的业务路径(payOrder中,获取关联的 ScheduleSlot 主键。
* 2. 调用 ScheduleSlotMapper 将 status 更新为 “3”。此操作与订单状态更新在同一事务内
* 确保原子性。
* 3. 为防止因数据库字段类型不匹配导致的异常,使用字符串 “3” 直接写入
*
* 这样可以消除发药明细与汇总单之间的时序差异,避免业务脱节风险
* 该改动保证了“预约签到缴费成功 → 排班号状态已取” 的完整闭环
*
* 修复 Bug #506
* 门诊诊前退号后,涉及的表状态应统一为 PRD 定义:
* - OrderMain.status → “REFUND” (已退号)
* - OrderDetail.status → “REFUND”
* - ScheduleSlot.status → “4” (已退号)
* 之前的实现仅修改了 OrderMain导致 ScheduleSlot 仍保持 “2”(已预约) 或 “3”(已取)
* 前端查询排班号时出现状态不一致的情况。现在在同一事务内同步更新三张表,确保业务闭环。
*/
@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 CatalogItemMapper catalogItemMapper;
private final ScheduleSlotMapper scheduleSlotMapper;
private final CatalogItemMapper catalogItemMapper;
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
CatalogItemMapper catalogItemMapper,
ScheduleSlotMapper scheduleSlotMapper) {
ScheduleSlotMapper scheduleSlotMapper,
CatalogItemMapper catalogItemMapper) {
this.orderMainMapper = orderMainMapper;
this.orderDetailMapper = orderDetailMapper;
this.catalogItemMapper = catalogItemMapper;
this.scheduleSlotMapper = scheduleSlotMapper;
this.catalogItemMapper = catalogItemMapper;
}
// 其它业务方法省略 ...
/**
* 诊前退号(退款)处理。
*
* @param orderId 订单主键
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void refundOrder(Long orderId) {
// 查询主订单
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
if (orderMain == null) {
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("订单不存在");
}
order.setStatus(OrderStatus.REFUND.name());
order.setUpdateTime(new Date());
orderMainMapper.updateById(order);
// 更新主订单状态为 REFUND
orderMain.setStatus(OrderStatus.REFUND.name());
orderMain.setUpdateTime(new Date());
orderMainMapper.updateByPrimaryKeySelective(orderMain);
// 查询所有明细
List<OrderDetail> details = orderDetailMapper.selectByOrderId(orderId);
for (OrderDetail detail : details) {
// 更新明细状态为 REFUND
detail.setStatus(OrderStatus.REFUND.name());
detail.setUpdateTime(new Date());
orderDetailMapper.updateByPrimaryKeySelective(detail);
// 若关联排班号,更新其状态为 “4”已退号
if (detail.getScheduleSlotId() != null) {
try {
scheduleSlotMapper.updateStatusById(detail.getScheduleSlotId(), "4");
} catch (Exception e) {
log.error("Failed to update schedule slot status to REFUND for slotId {}: {}", detail.getScheduleSlotId(), e.getMessage());
throw new BusinessException("退号时更新排班号状态失败");
}
}
orderDetailMapper.updateStatusByOrderId(orderId, OrderStatus.REFUND.name());
if (order.getScheduleSlotId() != null) {
scheduleSlotMapper.updateStatusById(order.getScheduleSlotId(), "4");
}
log.info("Order {} refunded successfully, all related schedule slots set to status 4.", orderId);
}
/**
* 支付成功后处理(包括排班号状态更新)。
*
* @param orderId 订单主键
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void payOrder(Long orderId) {
// 查询主订单
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
if (orderMain == null) {
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("订单不存在");
}
order.setStatus(OrderStatus.COMPLETED.name());
order.setUpdateTime(new Date());
orderMainMapper.updateById(order);
// 更新主订单状态为 COMPLETED已完成/已就诊)
orderMain.setStatus(OrderStatus.COMPLETED.name());
orderMain.setUpdateTime(new Date());
orderMainMapper.updateByPrimaryKeySelective(orderMain);
if (order.getScheduleSlotId() != null) {
scheduleSlotMapper.updateStatusById(order.getScheduleSlotId(), "3");
}
}
// 查询所有明细
/**
* 修复 Bug #561查询医嘱明细时自动关联诊疗目录填充使用单位
*/
public List<OrderDetail> getOrderDetailsByOrderId(Long orderId) {
List<OrderDetail> details = orderDetailMapper.selectByOrderId(orderId);
for (OrderDetail detail : details) {
// 更新明细状态为 COMPLETED
detail.setStatus(OrderStatus.COMPLETED.name());
detail.setUpdateTime(new Date());
orderDetailMapper.updateByPrimaryKeySelective(detail);
// 若关联排班号,更新其状态为 “3”已取
if (detail.getScheduleSlotId() != null) {
try {
scheduleSlotMapper.updateStatusById(detail.getScheduleSlotId(), "3");
} catch (Exception e) {
log.error("Failed to update schedule slot status to TAKEN for slotId {}: {}", detail.getScheduleSlotId(), e.getMessage());
throw new BusinessException("支付成功后更新排班号状态失败");
if (detail.getItemCode() != null) {
CatalogItem catalogItem = catalogItemMapper.selectByCode(detail.getItemCode());
if (catalogItem != null) {
// 将诊疗目录配置的“使用单位”赋值给医嘱明细
detail.setUnit(catalogItem.getUnit());
}
}
}
log.info("Order {} payment processed successfully, related schedule slots set to status 3.", orderId);
return details;
}
// 其它实现方法(如查询、分页等)保持不变
}