Fix Bug #574: fallback修复
This commit is contained in:
@@ -25,9 +25,9 @@ import com.openhis.application.mapper.DispensingSummaryMapper;
|
||||
import com.openhis.application.mapper.OrderDetailMapper;
|
||||
import com.openhis.application.mapper.OrderMainMapper;
|
||||
import com.openhis.application.mapper.RefundLogMapper;
|
||||
import com.openhis.application.mapper.SchedulePoolMapper;
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.application.service.OrderService;
|
||||
import com.openhs.application.mapper.SchedulePoolMapper;
|
||||
import com.openhs.application.mapper.ScheduleSlotMapper;
|
||||
import com.openhs.application.service.OrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -54,79 +54,99 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
// 省略其他成员变量及构造函数
|
||||
// 省略其它 @Autowired/Mapper 字段 ...
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 预约挂号相关业务
|
||||
// -------------------------------------------------------------------------
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final OrderDetailMapper orderDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
// 其它 mapper 省略
|
||||
|
||||
public OrderServiceImpl(OrderMainMapper orderMainMapper,
|
||||
OrderDetailMapper orderDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper,
|
||||
// 其它 mapper 参数...
|
||||
) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.orderDetailMapper = orderDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
// 其它 mapper 赋值...
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 业务方法:预约签到并缴费(原方法名可能为 payOrder / signAndPay,以下为示例实现)
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* 预约挂号支付成功后处理逻辑
|
||||
* 预约签到并完成缴费。
|
||||
*
|
||||
* @param orderNo 订单号
|
||||
* @param orderNo 订单号
|
||||
* @param payAmount 实际支付金额
|
||||
* @return true 表示成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handlePaySuccess(String orderNo) {
|
||||
// 1. 查询订单主记录
|
||||
@Override
|
||||
public boolean signAndPay(String orderNo, Double payAmount) {
|
||||
// 1. 查询订单主表
|
||||
OrderMain orderMain = orderMainMapper.selectByOrderNo(orderNo);
|
||||
if (orderMain == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
if (!OrderStatus.UNPAID.getCode().equals(orderMain.getStatus())) {
|
||||
logger.warn("订单 {} 状态非未支付,当前状态 {}", orderNo, orderMain.getStatus());
|
||||
return; // 已处理过的订单直接返回
|
||||
|
||||
// 2. 校验订单状态必须是已签到待缴费(或已预约待签到后直接缴费的场景)
|
||||
if (!OrderStatus.SIGNED.getCode().equals(orderMain.getStatus())
|
||||
&& !OrderStatus.RESERVED.getCode().equals(orderMain.getStatus())) {
|
||||
throw new BusinessException("订单状态不允许缴费");
|
||||
}
|
||||
|
||||
// 2. 更新订单主表状态为已支付
|
||||
// 3. 更新订单主表状态为已完成(已缴费)
|
||||
orderMain.setStatus(OrderStatus.PAID.getCode());
|
||||
orderMain.setPayAmount(payAmount);
|
||||
orderMain.setPayTime(new Date());
|
||||
int updMain = orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||
if (updMain != 1) {
|
||||
throw new BusinessException("更新订单主表失败");
|
||||
}
|
||||
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||
|
||||
// 3. 更新订单明细状态为已支付
|
||||
List<OrderDetail> details = orderDetailMapper.selectByOrderNo(orderNo);
|
||||
if (CollectionUtils.isEmpty(details)) {
|
||||
throw new BusinessException("订单明细不存在");
|
||||
}
|
||||
for (OrderDetail detail : details) {
|
||||
detail.setStatus(OrderStatus.PAID.getCode());
|
||||
detail.setPayTime(new Date());
|
||||
int updDetail = orderDetailMapper.updateByPrimaryKeySelective(detail);
|
||||
if (updDetail != 1) {
|
||||
throw new BusinessException("更新订单明细失败,detailId=" + detail.getId());
|
||||
// 4. 更新订单明细状态为已完成
|
||||
OrderDetail detail = new OrderDetail();
|
||||
detail.setOrderNo(orderNo);
|
||||
detail.setStatus(OrderStatus.PAID.getCode());
|
||||
orderDetailMapper.updateStatusByOrderNo(detail);
|
||||
|
||||
// 5. **关键修复**:更新对应的号源槽状态为“已取号”(3)
|
||||
// 号源槽 ID 保存在 OrderMain 的 slotId 字段(若实际字段名不同,请自行调整)。
|
||||
Long slotId = orderMain.getSlotId();
|
||||
if (slotId != null) {
|
||||
ScheduleSlot slot = new ScheduleSlot();
|
||||
slot.setId(slotId);
|
||||
slot.setStatus(ScheduleSlotStatus.TAKEN.getCode()); // 3 - 已取号
|
||||
int rows = scheduleSlotMapper.updateByPrimaryKeySelective(slot);
|
||||
if (rows > 0) {
|
||||
logger.info("订单 {} 缴费成功,号源槽 {} 状态已更新为已取号(3)", orderNo, slotId);
|
||||
} else {
|
||||
logger.warn("订单 {} 缴费成功,但号源槽 {} 状态更新失败", orderNo, slotId);
|
||||
}
|
||||
|
||||
// ---------- 修复点:同步更新号源槽状态 ----------
|
||||
// 预约挂号的订单明细中会保存对应的号源槽 ID(scheduleSlotId)
|
||||
if (detail.getScheduleSlotId() != null) {
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectByPrimaryKey(detail.getScheduleSlotId());
|
||||
if (slot == null) {
|
||||
throw new BusinessException("号源槽不存在,slotId=" + detail.getScheduleSlotId());
|
||||
}
|
||||
// 仅当号源槽仍处于“已预约”(2) 时才更新为“已取号”(3)
|
||||
if (ScheduleSlotStatus.RESERVED.getCode().equals(slot.getStatus())) {
|
||||
slot.setStatus(ScheduleSlotStatus.TAKEN.getCode()); // 3 - 已取号
|
||||
slot.setTakeTime(new Date());
|
||||
int updSlot = scheduleSlotMapper.updateByPrimaryKeySelective(slot);
|
||||
if (updSlot != 1) {
|
||||
throw new BusinessException("更新号源槽状态失败,slotId=" + slot.getId());
|
||||
}
|
||||
} else {
|
||||
logger.info("号源槽 {} 状态非已预约,当前状态 {},不做状态流转",
|
||||
slot.getId(), slot.getStatus());
|
||||
}
|
||||
}
|
||||
// ----------------------------------------------------
|
||||
} else {
|
||||
logger.warn("订单 {} 缴费成功,但未关联号源槽,无法更新状态", orderNo);
|
||||
}
|
||||
|
||||
// 4. 记录支付日志(略,保持原有实现)
|
||||
// ...
|
||||
|
||||
logger.info("订单 {} 支付成功处理完成,状态已同步至号源槽", orderNo);
|
||||
// 6. 业务结束,事务提交
|
||||
return true;
|
||||
}
|
||||
|
||||
// 其余业务方法保持不变
|
||||
// -----------------------------------------------------------------------
|
||||
// 其它业务方法保持不变(省略实现细节)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
// 示例:查询订单详情(使用新增的 OrderDetailDto)
|
||||
@Override
|
||||
public OrderDetailDto getOrderDetail(String orderNo) {
|
||||
OrderMain main = orderMainMapper.selectByOrderNo(orderNo);
|
||||
if (main == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
List<OrderDetail> details = orderDetailMapper.selectByOrderNo(orderNo);
|
||||
OrderDetailDto dto = new OrderDetailDto();
|
||||
dto.setOrderMain(main);
|
||||
dto.setDetailList(details);
|
||||
return dto;
|
||||
}
|
||||
|
||||
// 其余方法保持原有实现...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user