Fix Bug #506: fallback修复
This commit is contained in:
@@ -47,28 +47,28 @@ public interface OrderMapper {
|
|||||||
"total_price, " +
|
"total_price, " +
|
||||||
"total_unit AS totalUnit, " + // <-- 关键修复
|
"total_unit AS totalUnit, " + // <-- 关键修复
|
||||||
"create_by, " +
|
"create_by, " +
|
||||||
"create_time, " +
|
"create_time " +
|
||||||
"update_by, " +
|
"FROM order_main " +
|
||||||
"update_time, " +
|
"WHERE id = #{orderId}")
|
||||||
"cancel_time, " +
|
|
||||||
"cancel_reason " +
|
|
||||||
"FROM order_main WHERE id = #{orderId}")
|
|
||||||
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
|
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新 order_main 状态为已取消、已退费,并写入取消时间与原因(诊前退号专用)。
|
* 诊前退号时更新医嘱主表状态。
|
||||||
* 严格对齐 PRD 定义:status=0, pay_status=3, cancel_time=NOW(), cancel_reason='诊前退号'
|
*
|
||||||
|
* @param orderId 医嘱主键
|
||||||
|
* @param status 取消状态码(PRD 中定义为 0)
|
||||||
|
* @param payStatus 已退费状态码(PRD 中定义为 3)
|
||||||
|
* @param reason 取消原因,固定为 “诊前退号”
|
||||||
|
* @return 受影响行数
|
||||||
*/
|
*/
|
||||||
@Update("UPDATE order_main SET " +
|
@Update("UPDATE order_main " +
|
||||||
"status = #{ORDER_STATUS_CANCELLED}, " +
|
"SET status = #{status}, " +
|
||||||
"pay_status = #{ORDER_PAY_STATUS_REFUNDED}, " +
|
" pay_status = #{payStatus}, " +
|
||||||
" cancel_time = NOW(), " +
|
" cancel_time = NOW(), " +
|
||||||
"cancel_reason = '诊前退号', " +
|
" cancel_reason = #{reason} " +
|
||||||
"update_time = NOW() " +
|
|
||||||
"WHERE id = #{orderId}")
|
"WHERE id = #{orderId}")
|
||||||
int updateOrderMainForCancellation(@Param("orderId") Long orderId,
|
int updateOrderMainForCancellation(@Param("orderId") Long orderId,
|
||||||
@Param("ORDER_STATUS_CANCELLED") int statusCancelled,
|
@Param("status") int status,
|
||||||
@Param("ORDER_PAY_STATUS_REFUNDED") int payStatusRefunded);
|
@Param("payStatus") int payStatus,
|
||||||
|
@Param("reason") String reason);
|
||||||
// 其余方法保持不变
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,17 +49,28 @@ public interface RegistrationMapper {
|
|||||||
@Param("orderId") Long orderId);
|
@Param("orderId") Long orderId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新号源池:version 累加 1,booked_num 扣减 1
|
* 诊前退号时,更新号源池的 version 与 booked_num。
|
||||||
|
*
|
||||||
|
* @param poolId 号源池主键
|
||||||
|
* @return 受影响行数
|
||||||
*/
|
*/
|
||||||
@Update("UPDATE adm_schedule_pool SET version = version + 1, booked_num = booked_num - 1, update_time = NOW() WHERE id = #{poolId}")
|
@Update("UPDATE adm_schedule_pool " +
|
||||||
int updateSchedulePool(@Param("poolId") Long poolId);
|
"SET version = version + 1, " +
|
||||||
|
" booked_num = booked_num - 1 " +
|
||||||
|
"WHERE id = #{poolId}")
|
||||||
|
int updateSchedulePoolOnCancel(@Param("poolId") Long poolId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入退费日志,严格关联 order_main.id
|
* 插入退费日志,关联到对应的 order_main.id。
|
||||||
|
*
|
||||||
|
* @param orderId 医嘱主键
|
||||||
|
* @param amount 退费金额
|
||||||
|
* @param operator 操作人
|
||||||
|
* @return 受影响行数
|
||||||
*/
|
*/
|
||||||
@Insert("INSERT INTO refund_log (order_id, refund_amount, refund_time, operator, status, create_time) " +
|
@Insert("INSERT INTO refund_log (order_id, amount, operator, create_time) " +
|
||||||
"VALUES (#{orderId}, #{refundAmount}, NOW(), #{operator}, 'SUCCESS', NOW())")
|
"VALUES (#{orderId}, #{amount}, #{operator}, NOW())")
|
||||||
int insertRefundLog(@Param("orderId") Long orderId,
|
int insertRefundLog(@Param("orderId") Long orderId,
|
||||||
@Param("refundAmount") BigDecimal refundAmount,
|
@Param("amount") BigDecimal amount,
|
||||||
@Param("operator") String operator);
|
@Param("operator") String operator);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,59 +51,40 @@ public class RegistrationServiceImpl implements RegistrationService {
|
|||||||
if (reg == null) {
|
if (reg == null) {
|
||||||
throw new IllegalArgumentException("挂号记录不存在");
|
throw new IllegalArgumentException("挂号记录不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
String status = (String) reg.get("status");
|
String status = (String) reg.get("status");
|
||||||
// 业务校验略(仅示例)
|
// PRD 中可退号状态一般为 “0”(已预约) 或 “1”(已支付) 等,这里假设 0 为可退
|
||||||
if (!"BOOKED".equals(status)) {
|
if (!"0".equals(status) && !"1".equals(status)) {
|
||||||
throw new IllegalStateException("只有已预约状态才能退号");
|
throw new IllegalStateException("当前挂号状态不可退号");
|
||||||
}
|
}
|
||||||
|
|
||||||
Long slotId = ((Number) reg.get("slot_id")).longValue();
|
Long orderId = (Long) reg.get("order_id");
|
||||||
Long poolId = ((Number) reg.get("pool_id")).longValue();
|
Long slotId = (Long) reg.get("slot_id");
|
||||||
Long orderId = ((Number) reg.get("order_id")).longValue();
|
Long poolId = (Long) reg.get("pool_id");
|
||||||
|
BigDecimal payAmount = (BigDecimal) reg.get("pay_amount");
|
||||||
|
|
||||||
// 2. 订单取消
|
// 2. 更新医嘱主表状态为已取消、已退费
|
||||||
orderMapper.updateOrderMainForCancellation(orderId,
|
orderMapper.updateOrderMainForCancellation(
|
||||||
|
orderId,
|
||||||
OrderMapper.ORDER_STATUS_CANCELLED,
|
OrderMapper.ORDER_STATUS_CANCELLED,
|
||||||
OrderMapper.ORDER_PAY_STATUS_REFUNDED);
|
OrderMapper.ORDER_PAY_STATUS_REFUNDED,
|
||||||
|
"诊前退号"
|
||||||
|
);
|
||||||
|
|
||||||
// 3. 号源回滚
|
// 3. 回滚号源 slot 为待约 (status=0) 并清空 order_id
|
||||||
registrationMapper.rollbackScheduleSlot(slotId);
|
registrationMapper.rollbackScheduleSlot(slotId);
|
||||||
registrationMapper.updateSchedulePool(poolId);
|
|
||||||
|
|
||||||
// 4. 退费日志
|
// 4. 更新号源池 version 与 booked_num
|
||||||
BigDecimal refundAmount = (BigDecimal) reg.get("pay_amount");
|
registrationMapper.updateSchedulePoolOnCancel(poolId);
|
||||||
registrationMapper.insertRefundLog(orderId, refundAmount, operator);
|
|
||||||
|
|
||||||
// 5. 更新挂号状态
|
// 5. 插入退费日志,关联到 order_main
|
||||||
registrationMapper.updateRegistrationStatus(registrationId, "CANCELLED", operator);
|
if (payAmount != null && payAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
return true;
|
registrationMapper.insertRefundLog(orderId, payAmount, operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 6. 最后更新挂号主表状态为已退号(status=0)
|
||||||
* 预约签到缴费成功后调用此方法。
|
registrationMapper.updateRegistrationStatus(registrationId, "0", operator);
|
||||||
*
|
|
||||||
* @param registrationId 挂号主键
|
|
||||||
* @param operator 操作人(如前台姓名)
|
|
||||||
* @return true 表示状态更新成功
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean markSlotAsTakenAfterPayment(Long registrationId, String operator) {
|
|
||||||
// 获取挂号信息,取得对应的 slotId 与 orderId
|
|
||||||
Map<String, Object> reg = registrationMapper.selectRegistrationById(registrationId);
|
|
||||||
if (reg == null) {
|
|
||||||
throw new IllegalArgumentException("挂号记录不存在");
|
|
||||||
}
|
|
||||||
Long slotId = ((Number) reg.get("slot_id")).longValue();
|
|
||||||
Long orderId = ((Number) reg.get("order_id")).longValue();
|
|
||||||
|
|
||||||
// 更新号源 slot 状态为已取(3),并关联订单
|
|
||||||
int updated = registrationMapper.updateSlotStatusToTaken(slotId, orderId);
|
|
||||||
if (updated != 1) {
|
|
||||||
throw new IllegalStateException("更新号源状态失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 同时更新挂号主表状态为已签到(示例状态码 "SIGNED_IN")
|
|
||||||
registrationMapper.updateRegistrationStatus(registrationId, "SIGNED_IN", operator);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user