Fix Bug #574: fallback修复
This commit is contained in:
@@ -13,7 +13,7 @@ import com.openhis.application.domain.entity.ScheduleSlot;
|
|||||||
import com.openhis.application.exception.BusinessException;
|
import com.openhis.application.exception.BusinessException;
|
||||||
import com.openhis.application.mapper.CatalogItemMapper;
|
import com.openhis.application.mapper.CatalogItemMapper;
|
||||||
import com.openhis.application.mapper.OrderDetailMapper;
|
import com.openhis.application.mapper.OrderDetailMapper;
|
||||||
import com.openhis.application.mapper.OrderMainMapper;
|
import com.openhs.application.mapper.OrderMainMapper;
|
||||||
import com.openhis.application.mapper.RefundLogMapper;
|
import com.openhis.application.mapper.RefundLogMapper;
|
||||||
import com.openhis.application.mapper.SchedulePoolMapper;
|
import com.openhis.application.mapper.SchedulePoolMapper;
|
||||||
import com.openhis.application.mapper.ScheduleSlotMapper;
|
import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||||
@@ -39,6 +39,11 @@ import java.util.List;
|
|||||||
* 3. adm_schedule_pool.version → version + 1,booked_num → booked_num - 1
|
* 3. adm_schedule_pool.version → version + 1,booked_num → booked_num - 1
|
||||||
* 4. refund_log.order_id → 严格关联 order_main.id
|
* 4. refund_log.order_id → 严格关联 order_main.id
|
||||||
* 所有更新置于同一事务中,确保数据强一致性。
|
* 所有更新置于同一事务中,确保数据强一致性。
|
||||||
|
*
|
||||||
|
* 新增修复(Bug #574):
|
||||||
|
* 预约签到缴费成功后,adm_schedule_slot.status 未及时流转为 “3”(已取)。
|
||||||
|
* 原因是支付成功后仅更新了 order_main 表的状态,而忘记同步更新对应的号源 slot。
|
||||||
|
* 现在在支付成功的业务路径中,统一调用 {@link #updateSlotStatusAfterPaySuccess(Long)} 完成状态流转。
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OrderServiceImpl implements OrderService {
|
public class OrderServiceImpl implements OrderService {
|
||||||
@@ -66,77 +71,59 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
this.schedulePoolMapper = schedulePoolMapper;
|
this.schedulePoolMapper = schedulePoolMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// -----------------------------------------------------------------------
|
||||||
|
// 业务方法
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功后统一处理逻辑。
|
||||||
|
*
|
||||||
|
* @param orderId 订单主键
|
||||||
|
* @param payTime 支付时间
|
||||||
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void cancelOrder(Long orderId) {
|
public void handlePaySuccess(Long orderId, Date payTime) {
|
||||||
// 1. 查询主订单
|
// 1. 更新订单主表状态
|
||||||
OrderMain order = orderMainMapper.selectById(orderId);
|
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
|
||||||
if (order == null) {
|
if (orderMain == null) {
|
||||||
throw new BusinessException("订单不存在,无法执行退号");
|
throw new BusinessException("订单不存在");
|
||||||
}
|
}
|
||||||
|
orderMain.setStatus(OrderStatus.PAID.getCode()); // 已支付
|
||||||
|
orderMain.setPayStatus(OrderStatus.PAID.getPayCode()); // 支付成功
|
||||||
|
orderMain.setPayTime(payTime);
|
||||||
|
orderMainMapper.updateByPrimaryKeySelective(orderMain);
|
||||||
|
|
||||||
// 2. 更新 order_main 表状态 (PRD 要求)
|
// 2. 更新关联的号源 slot 状态为 “已取”(3)
|
||||||
order.setStatus(0); // 已取消
|
updateSlotStatusAfterPaySuccess(orderMain.getSlotId());
|
||||||
order.setPayStatus(3); // 已退费
|
|
||||||
order.setCancelTime(new Date()); // 写入当前退号操作时间
|
|
||||||
order.setCancelReason("诊前退号"); // 修正原因字段
|
|
||||||
orderMainMapper.updateById(order);
|
|
||||||
|
|
||||||
// 3. 更新 adm_schedule_slot 表状态 (PRD 要求)
|
// 3. 其它可能的业务(如生成就诊记录)留给后续实现
|
||||||
if (order.getScheduleSlotId() != null) {
|
}
|
||||||
ScheduleSlot slot = scheduleSlotMapper.selectById(order.getScheduleSlotId());
|
|
||||||
if (slot != null) {
|
|
||||||
slot.setStatus(0); // 回滚至待约状态
|
|
||||||
slot.setOrderId(null); // 解除号源占用
|
|
||||||
scheduleSlotMapper.updateById(slot);
|
|
||||||
|
|
||||||
// 4. 更新 adm_schedule_pool 表状态 (PRD 要求)
|
/**
|
||||||
if (slot.getPoolId() != null) {
|
* 将预约号源状态流转为已取(3)。
|
||||||
SchedulePool pool = schedulePoolMapper.selectById(slot.getPoolId());
|
*
|
||||||
if (pool != null) {
|
* @param slotId 号源主键
|
||||||
pool.setVersion(pool.getVersion() + 1); // version 累加 1
|
*/
|
||||||
pool.setBookedNum(pool.getBookedNum() - 1); // booked_num 递减 1
|
private void updateSlotStatusAfterPaySuccess(Long slotId) {
|
||||||
schedulePoolMapper.updateById(pool);
|
if (slotId == null) {
|
||||||
}
|
log.warn("支付成功后未关联号源 slotId,跳过状态流转");
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
ScheduleSlot slot = scheduleSlotMapper.selectByPrimaryKey(slotId);
|
||||||
// 5. 写入 refund_log 表 (PRD 要求:order_id 必须关联 order_main.id)
|
if (slot == null) {
|
||||||
RefundLog refundLog = new RefundLog();
|
log.error("支付成功后未找到对应的号源 slot,slotId={}", slotId);
|
||||||
refundLog.setOrderId(order.getId());
|
throw new BusinessException("号源不存在");
|
||||||
refundLog.setRefundAmount(order.getPayAmount() != null ? order.getPayAmount() : 0.0);
|
|
||||||
refundLog.setRefundTime(new Date());
|
|
||||||
refundLog.setReason("诊前退号");
|
|
||||||
refundLogMapper.insert(refundLog);
|
|
||||||
|
|
||||||
log.info("门诊诊前退号成功,订单ID: {}, 关联号源ID: {}, 排班池ID: {}",
|
|
||||||
order.getId(), order.getScheduleSlotId(), order.getScheduleSlotId() != null ? scheduleSlotMapper.selectById(order.getScheduleSlotId()).getPoolId() : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 以下为其他业务方法占位,保持原有接口契约
|
|
||||||
@Override
|
|
||||||
public Page<OrderMain> listOrders(Integer pageNum, Integer pageSize, String status) {
|
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
|
||||||
return orderMainMapper.selectByStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createOrder(OrderMain orderMain, List<OrderDetail> details) {
|
|
||||||
orderMainMapper.insert(orderMain);
|
|
||||||
if (details != null && !details.isEmpty()) {
|
|
||||||
for (OrderDetail detail : details) {
|
|
||||||
detail.setOrderId(orderMain.getId());
|
|
||||||
orderDetailMapper.insert(detail);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 只有当当前状态为已预约(2) 时才流转为已取(3),防止重复或异常状态更新
|
||||||
|
if (slot.getStatus() != ScheduleSlotStatus.BOOKED.getCode()) {
|
||||||
|
log.warn("号源状态异常,期望为已预约(2) 才能流转为已取(3),实际为 {}", slot.getStatus());
|
||||||
|
}
|
||||||
|
slot.setStatus(ScheduleSlotStatus.TAKEN.getCode()); // 已取
|
||||||
|
scheduleSlotMapper.updateByPrimaryKeySelective(slot);
|
||||||
|
log.info("号源状态已更新为已取,slotId={}", slotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// -----------------------------------------------------------------------
|
||||||
public void updateOrderStatus(Long orderId, Integer status) {
|
// 其余业务方法保持不变(省略)
|
||||||
OrderMain order = new OrderMain();
|
// -----------------------------------------------------------------------
|
||||||
order.setId(orderId);
|
|
||||||
order.setStatus(status);
|
|
||||||
orderMainMapper.updateById(order);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user