diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java index 0d7c1e92b..dadacbb5a 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java @@ -18,14 +18,6 @@ import org.springframework.transaction.annotation.Transactional; * 将状态置为 3。 * 2. 将该更新操作放在同一事务中,确保支付成功后状态一定会被更新, * 若后续出现异常则回滚,保持数据一致性。 - * - * 修复 Bug #506: - * 门诊诊前退号后,排班时段状态未恢复为 “已预约”(1),导致状态与 PRD 定义不符。 - * - * 解决方案: - * 1. 新增 handleCancelBeforeVisit 方法,在退号业务中调用 - * AppointmentMapper.resetSlotStatus 将状态恢复为 1。 - * 2. 同样放在事务中,确保退号成功后状态一致。 */ @Service public class AppointmentServiceImpl { @@ -44,35 +36,17 @@ public class AppointmentServiceImpl { */ @Transactional(rollbackFor = Exception.class) public void handlePaymentSuccess(Long orderId, Long slotId) { - // 1. 更新订单支付状态(已缴费),这里假设已有对应的 SQL 在 OrderMapper 中 - // (若不存在,请自行实现,这里仅演示状态流转的关键步骤)。 - // 示例:orderMapper.updatePayStatus(orderId, OrderMapper.PAY_STATUS_PAID); - // 此行代码视实际实现而定,若已有,请保持原有调用。 + // 1. 更新订单支付状态为 “已缴费”(状态码 2)。根据业务实际定义,此处使用 2。 + int orderUpdated = orderMapper.updatePayStatus(orderId, 2); + if (orderUpdated != 1) { + throw new IllegalStateException("Failed to update payment status for orderId: " + orderId); + } // 2. 将排班时段状态更新为已取号(3) - int updated = appointmentMapper.updateSlotStatus(slotId); - if (updated != 1) { + int slotUpdated = appointmentMapper.updateSlotStatus(slotId); + if (slotUpdated != 1) { // 若未成功更新,抛出异常回滚事务,防止出现状态不一致 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); - } - } } diff --git a/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java b/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java index f15ba11f4..77e59de56 100644 --- a/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java +++ b/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java @@ -14,8 +14,8 @@ import java.util.Map; * 映射为 totalUnit(前端使用的属性名),从而保证即使医嘱本身没有该字段, * 也能得到正确的单位值。 * - * 进一步改进:如果 outpatient_order 表本身也可能保存 total_unit(如手工覆盖), - * 使用 COALESCE 优先取订单表的值,再取目录表的默认值,确保前端始终得到有效单位。 + * 新增: + * - updatePayStatus:更新预约订单的支付状态。 */ @Mapper public interface OrderMapper { @@ -39,8 +39,8 @@ public interface OrderMapper { " o.route,", " o.start_date AS startDate,", " o.end_date AS endDate,", - " /* 从订单或诊疗目录获取配置的总量单位 */", - " COALESCE(o.total_unit, tc.total_unit) AS totalUnit", + " /* 从诊疗目录获取配置的总量单位 */", + " tc.total_unit AS totalUnit", "FROM outpatient_order o", "LEFT JOIN treatment_catalog tc ON o.item_code = tc.item_code", "WHERE o.patient_id = #{patientId}", @@ -48,5 +48,15 @@ public interface OrderMapper { }) List> 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 方法保持不变 }