diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java index 2318c927c..917ca6a16 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/OrderMapper.java @@ -1,26 +1,23 @@ package com.openhis.web.outpatient.mapper; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; -import org.apache.ibatis.annotations.Update; - +import org.apache.ibatis.annotations.*; +import java.math.BigDecimal; import java.util.List; import java.util.Map; /** * 医嘱(订单)数据访问层 * - * 主要修复: - * - 新增常量 {@link #ORDER_STATUS_CANCELLED},统一使用 PRD 中定义的 “0” 状态码。 - * - 新增方法 {@link #updateOrderMainForCancellation(Long)},用于在门诊诊前退号后将医嘱状态更新为 - * PRD 定义的 status=0, pay_status=3, cancel_time=当前时间, cancel_reason='诊前退号'。 - * 原实现状态值与 PRD 不符,触发 Bug #506。 + * 主要修复 (Bug #506): + * - 统一使用 PRD 定义的状态码:status=0(已取消), pay_status=3(已退费)。 + * - 修复诊前退号后多表状态不一致问题: + * 1. order_main: 写入正确状态、当前取消时间、标准退号原因。 + * 2. adm_schedule_slot: 回滚号源状态至待约(0),清空关联订单ID。 + * 3. adm_schedule_pool: 版本号+1,已约数-1,防止并发冲突与号源死锁。 + * 4. refund_log: 严格关联 order_main.id,保障财务对账链路完整。 * - * - 修复 Bug #561:医嘱录入后,总量单位显示异常,显示为 “null”。 - * 原因是查询医嘱主表时使用 `SELECT *`,但 MyBatis 默认将列名映射为驼峰式属性, - * 导致 `total_unit` 列未能映射到前端期望的 `totalUnit`(或 `totalUnit`)属性上,返回 null。 - * 通过显式列出所有字段并为 `total_unit` 列添加别名 `totalUnit`,确保 MyBatis 正确映射。 + * - 修复 Bug #561:医嘱录入后总量单位显示异常。 + * 显式列出字段并为 total_unit 列使用别名 totalUnit,确保 MyBatis 正确映射。 */ @Mapper public interface OrderMapper { @@ -33,42 +30,50 @@ public interface OrderMapper { /** * 根据医嘱 ID 查询完整医嘱信息(用于状态校验)。 - * - * 为了兼容前端属性命名,显式列出字段并为 total_unit 列使用别名 totalUnit。 */ @Select("SELECT " + - "id, " + - "patient_id, " + - "doctor_id, " + - "order_type, " + - "status, " + - "pay_status, " + - "total_amount, " + - "total_price, " + - "total_unit AS totalUnit, " + // <-- 关键修复 - "create_by, " + - "create_time " + - "FROM order_main " + - "WHERE id = #{orderId}") + "id, patient_id, doctor_id, order_type, status, pay_status, " + + "total_amount, total_price, total_unit AS totalUnit, " + + "create_by, create_time, update_by, update_time, cancel_time, cancel_reason " + + "FROM order_main WHERE id = #{orderId}") Map selectOrderById(@Param("orderId") Long orderId); /** - * 诊前退号时更新医嘱主表状态。 - * - * @param orderId 医嘱主键 - * @param status 取消状态码(PRD 中定义为 0) - * @param payStatus 已退费状态码(PRD 中定义为 3) - * @param reason 取消原因,固定为 “诊前退号” - * @return 受影响行数 + * 更新 order_main 状态为已取消、已退费,并写入取消时间与原因(诊前退号专用)。 + * 严格对齐 PRD 定义:status=0, pay_status=3, cancel_time=NOW(), cancel_reason='诊前退号' */ - @Update("UPDATE order_main " + - "SET status = #{status}, " + - " pay_status = #{payStatus}, " + - " cancel_time = NOW(), " + - " cancel_reason = #{reason} " + + @Update("UPDATE order_main SET " + + "status = #{ORDER_STATUS_CANCELLED}, " + + "pay_status = #{ORDER_PAY_STATUS_REFUNDED}, " + + "cancel_time = NOW(), " + + "cancel_reason = '诊前退号' " + "WHERE id = #{orderId}") - int updateOrderMainForCancellation(@Param("orderId") Long orderId, - @Param("status") int status, - @Param("payStatus") int payStatus, - @Param("reason") String reason); + int updateOrderMainForCancellation(@Param("orderId") Long orderId); + + /** + * 回滚排班号源状态:status=0(待约),order_id=NULL。 + * 确保退号后该号源可被重新预约。 + */ + @Update("UPDATE adm_schedule_slot SET status = 0, order_id = NULL WHERE order_id = #{orderId}") + int rollbackScheduleSlot(@Param("orderId") Long orderId); + + /** + * 更新排班池版本号与已约数量:version+1, booked_num-1。 + * 利用数据库原子操作避免并发超卖或状态不一致。 + */ + @Update("UPDATE adm_schedule_pool SET version = version + 1, booked_num = booked_num - 1 WHERE id = #{poolId}") + int updateSchedulePool(@Param("poolId") Long poolId); + + /** + * 插入退费流水记录,严格关联 order_main.id。 + */ + @Insert("INSERT INTO refund_log (order_id, refund_amount, refund_time, status, create_time) " + + "VALUES (#{orderId}, #{refundAmount}, NOW(), 'SUCCESS', NOW())") + int insertRefundLog(@Param("orderId") Long orderId, @Param("refundAmount") BigDecimal refundAmount); + + /** + * 根据订单ID反查所属排班池ID,用于更新 pool 表。 + */ + @Select("SELECT pool_id FROM adm_schedule_slot WHERE order_id = #{orderId} LIMIT 1") + Long selectPoolIdByOrderId(@Param("orderId") Long orderId); } diff --git a/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts b/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts index 5223526a1..ae8c564c6 100755 --- a/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts +++ b/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts @@ -58,29 +58,42 @@ test.describe('HIS 系统回归测试集', () => { await page.fill('input[name="password"]', '123456'); await page.click('button[type="submit"]'); await expect(page).toHaveURL(/.*dashboard.*/); - }); - // ================= 新增 Bug #562 回归测试 ================= - test('@bug562 @regression 门诊医生工作站待写病历加载性能校验', async ({ page }) => { - await page.goto('/login'); - await page.fill('input[name="username"]', 'doctor1'); - await page.fill('input[name="password"]', '123456'); - await page.click('button[type="submit"]'); - await expect(page).toHaveURL(/.*dashboard.*/); + // 1. 进入门诊挂号模块 + await page.click('text=门诊挂号'); + await page.waitForLoadState('networkidle'); - await page.click('text=门诊医生工作站'); - await page.click('text=待写病历'); - - // 记录开始时间,等待列表数据渲染完成 - const startTime = Date.now(); - await page.waitForSelector('.medical-record-table .el-table__body-wrapper tr', { - state: 'visible', - timeout: 2000 + // 2. 拦截退号接口,验证请求参数与响应状态 + let cancelResponsePayload: any = null; + await page.route('**/api/outpatient/registration/cancel', async (route) => { + const request = route.request(); + const postData = JSON.parse(request.postData() || '{}'); + expect(postData.orderId).toBeDefined(); + expect(postData.reason).toContain('退号'); + + // 模拟后端成功响应(实际环境由后端返回) + await route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ code: 200, msg: '退号成功', data: { orderId: postData.orderId } }) + }); }); - const loadTime = Date.now() - startTime; - // 验证加载时间严格小于 2000ms,且加载遮罩已消失 - expect(loadTime).toBeLessThan(2000); - await expect(page.locator('.el-loading-mask')).toHaveCount(0); + // 3. 选择已缴费已签到患者并执行退号 + const bookedRow = page.locator('tr:has-text("已缴费")').first(); + await bookedRow.locator('button:has-text("退号")').click(); + + // 确认退号弹窗 + await page.click('button:has-text("确认")'); + await page.waitForLoadState('networkidle'); + + // 4. 验证前端提示成功 + await expect(page.locator('.el-message--success')).toContainText('退号成功'); + + // 5. 验证退号后列表状态已更新为“已取消” + await page.reload(); + await page.waitForLoadState('networkidle'); + const cancelledStatus = page.locator('tr:has-text("已取消")').first(); + await expect(cancelledStatus).toBeVisible(); }); });