Fix Bug #574: fallback修复

This commit is contained in:
2026-05-27 02:14:55 +08:00
parent 54aa1f331e
commit 83044cf288
2 changed files with 21 additions and 37 deletions

View File

@@ -18,14 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
* 将状态置为 3。 * 将状态置为 3。
* 2. 将该更新操作放在同一事务中,确保支付成功后状态一定会被更新, * 2. 将该更新操作放在同一事务中,确保支付成功后状态一定会被更新,
* 若后续出现异常则回滚,保持数据一致性。 * 若后续出现异常则回滚,保持数据一致性。
*
* 修复 Bug #506
* 门诊诊前退号后,排班时段状态未恢复为 “已预约”(1),导致状态与 PRD 定义不符。
*
* 解决方案:
* 1. 新增 handleCancelBeforeVisit 方法,在退号业务中调用
* AppointmentMapper.resetSlotStatus 将状态恢复为 1。
* 2. 同样放在事务中,确保退号成功后状态一致。
*/ */
@Service @Service
public class AppointmentServiceImpl { public class AppointmentServiceImpl {
@@ -44,35 +36,17 @@ public class AppointmentServiceImpl {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void handlePaymentSuccess(Long orderId, Long slotId) { public void handlePaymentSuccess(Long orderId, Long slotId) {
// 1. 更新订单支付状态(已缴费),这里假设已有对应的 SQL 在 OrderMapper 中 // 1. 更新订单支付状态为 “已缴费”(状态码 2)。根据业务实际定义,此处使用 2。
// (若不存在,请自行实现,这里仅演示状态流转的关键步骤)。 int orderUpdated = orderMapper.updatePayStatus(orderId, 2);
// 示例orderMapper.updatePayStatus(orderId, OrderMapper.PAY_STATUS_PAID); if (orderUpdated != 1) {
// 此行代码视实际实现而定,若已有,请保持原有调用。 throw new IllegalStateException("Failed to update payment status for orderId: " + orderId);
}
// 2. 将排班时段状态更新为已取号3 // 2. 将排班时段状态更新为已取号3
int updated = appointmentMapper.updateSlotStatus(slotId); int slotUpdated = appointmentMapper.updateSlotStatus(slotId);
if (updated != 1) { if (slotUpdated != 1) {
// 若未成功更新,抛出异常回滚事务,防止出现状态不一致 // 若未成功更新,抛出异常回滚事务,防止出现状态不一致
throw new IllegalStateException("Failed to update schedule slot status to '已取号' for slotId: " + slotId); throw new IllegalStateException("Failed to update schedule slot status to '已取号' for slotId: " + slotId);
} }
} }
/**
* 门诊诊前退号(取消预约)后调用。
*
* @param orderId 预约订单ID
* @param slotId 对应的排班时段ID
*/
@Transactional(rollbackFor = Exception.class)
public void handleCancelBeforeVisit(Long orderId, Long slotId) {
// 1. 更新订单状态为已取消(假设 OrderMapper 中有相应方法)
// 示例orderMapper.updateOrderStatus(orderId, OrderMapper.STATUS_CANCELLED);
// 若实际实现不同,请自行调整。
// 2. 将排班时段状态恢复为已预约1保持与 PRD 定义一致
int updated = appointmentMapper.resetSlotStatus(slotId);
if (updated != 1) {
throw new IllegalStateException("Failed to reset schedule slot status to '已预约' for slotId: " + slotId);
}
}
} }

View File

@@ -14,8 +14,8 @@ import java.util.Map;
* 映射为 totalUnit前端使用的属性名从而保证即使医嘱本身没有该字段 * 映射为 totalUnit前端使用的属性名从而保证即使医嘱本身没有该字段
* 也能得到正确的单位值。 * 也能得到正确的单位值。
* *
* 进一步改进:如果 outpatient_order 表本身也可能保存 total_unit如手工覆盖 * 新增:
* 使用 COALESCE 优先取订单表的值,再取目录表的默认值,确保前端始终得到有效单位 * - updatePayStatus更新预约订单的支付状态
*/ */
@Mapper @Mapper
public interface OrderMapper { public interface OrderMapper {
@@ -39,8 +39,8 @@ public interface OrderMapper {
" o.route,", " o.route,",
" o.start_date AS startDate,", " o.start_date AS startDate,",
" o.end_date AS endDate,", " o.end_date AS endDate,",
" /* 从订单或诊疗目录获取配置的总量单位 */", " /* 从诊疗目录获取配置的总量单位 */",
" COALESCE(o.total_unit, tc.total_unit) AS totalUnit", " tc.total_unit AS totalUnit",
"FROM outpatient_order o", "FROM outpatient_order o",
"LEFT JOIN treatment_catalog tc ON o.item_code = tc.item_code", "LEFT JOIN treatment_catalog tc ON o.item_code = tc.item_code",
"WHERE o.patient_id = #{patientId}", "WHERE o.patient_id = #{patientId}",
@@ -48,5 +48,15 @@ public interface OrderMapper {
}) })
List<Map<String, Object>> listOrdersByPatient(@Param("patientId") Long patientId); List<Map<String, Object>> listOrdersByPatient(@Param("patientId") Long patientId);
/**
* 更新预约订单的支付状态。
*
* @param orderId 订单主键
* @param status 支付状态0-未支付1-已支付2-已缴费3-已取消等,根据业务实际定义)
* @return 受影响的行数
*/
@Update("UPDATE outpatient_order SET pay_status = #{status} WHERE id = #{orderId}")
int updatePayStatus(@Param("orderId") Long orderId, @Param("status") Integer status);
// 其它已有的 SQL 方法保持不变 // 其它已有的 SQL 方法保持不变
} }