89 lines
3.6 KiB
Java
89 lines
3.6 KiB
Java
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 java.util.Map;
|
||
|
||
/**
|
||
* 医嘱(订单)数据访问层
|
||
*
|
||
* 主要修复:
|
||
* - 新增常量 {@link #ORDER_STATUS_CANCELLED},统一使用 PRD 中定义的 “CANCELLED” 状态码。
|
||
* - 新增方法 {@link #updateOrderStatusToCancelled(Long, String)},用于在门诊诊前退号后将医嘱状态更新为
|
||
* PRD 定义的 “CANCELLED”。原实现使用硬编码的 'RETURNED',导致状态不一致,触发 Bug #506。
|
||
* - **新增方法 {@link #selectOrderDetailById(Long)}**,显式返回诊疗目录配置的总量单位字段,
|
||
* 解决医嘱录入后总量单位显示为 “null” 的 Bug #561。
|
||
*
|
||
* 该接口的实现依赖 MyBatis 动态 SQL,保持与项目其他 Mapper 的风格一致。
|
||
*/
|
||
@Mapper
|
||
public interface OrderMapper {
|
||
|
||
/** PRD 中定义的医嘱取消状态 */
|
||
String ORDER_STATUS_CANCELLED = "CANCELLED";
|
||
|
||
/**
|
||
* 根据医嘱 ID 查询完整医嘱信息(用于状态校验)。
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @return 包含医嘱所有字段的 Map,若不存在返回 null
|
||
*/
|
||
@Select("SELECT * FROM his_order WHERE id = #{orderId}")
|
||
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
|
||
|
||
/**
|
||
* **新增**:查询医嘱详情并返回总量单位。
|
||
*
|
||
* <p>诊疗目录中配置的单位保存在列 {@code total_unit_name},前端 DTO 期望的属性名为 {@code totalUnit}
|
||
*(对应数据库列 {@code total_unit})。原始的 {@code SELECT *} 只能映射到 {@code total_unit},导致
|
||
* 前端得到 {@code null}。此查询通过别名把 {@code total_unit_name} 映射为 {@code total_unit},
|
||
* 从而保证前端能够正确显示。</p>
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @return 包含医嘱所有字段(包括别名后的 total_unit)的 Map,若不存在返回 null
|
||
*/
|
||
@Select("SELECT " +
|
||
"id, " +
|
||
"order_no, " +
|
||
"patient_id, " +
|
||
"doctor_id, " +
|
||
"dept_id, " +
|
||
"order_type, " +
|
||
"order_status, " +
|
||
"exec_status, " +
|
||
"dispense_status, " +
|
||
"billing_status, " +
|
||
"total_quantity, " +
|
||
// 将诊疗目录的单位列映射为前端需要的列名
|
||
"total_unit_name AS total_unit, " +
|
||
"price, " +
|
||
"create_time, " +
|
||
"update_time " +
|
||
"FROM his_order WHERE id = #{orderId}")
|
||
Map<String, Object> selectOrderDetailById(@Param("orderId") Long orderId);
|
||
|
||
/**
|
||
* 将医嘱状态更新为已支付(示例方法,业务中已有实现)。
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @return 受影响的行数
|
||
*/
|
||
@Update("UPDATE his_order SET status = 'PAID' WHERE id = #{orderId}")
|
||
int updateOrderStatusToPaid(@Param("orderId") Long orderId);
|
||
|
||
/**
|
||
* 将医嘱状态更新为已取消(PRD 定义的 CANCELLED)。
|
||
*
|
||
* 该方法在门诊诊前退号、检验申请撤回等场景统一调用,确保状态值始终与 PRD 保持一致。
|
||
*
|
||
* @param orderId 医嘱主键
|
||
* @param status 取消状态值,建议使用 {@link #ORDER_STATUS_CANCELLED}
|
||
*/
|
||
@Update("UPDATE his_order SET status = #{status} WHERE id = #{orderId}")
|
||
int updateOrderStatusToCancelled(@Param("orderId") Long orderId,
|
||
@Param("status") String status);
|
||
}
|