refactor(doctorstation): 优化医生站医嘱查询SQL逻辑
- 将原有的条件判断逻辑重构为更清晰的choose/when/otherwise结构 - 修复了adviceTypes参数为空或未指定时的SQL执行问题 - 通过trim标签处理UNION ALL连接避免多余关键字 - 添加otherwise分支确保无adviceTypes时返回正确空结果集 - 保持了原有的所有功能逻辑和数据映射关系不变 - 提高了SQL查询的可读性和维护性
This commit is contained in:
@@ -43,8 +43,11 @@
|
||||
abi.restricted_scope,
|
||||
abi.dosage_instruction,
|
||||
abi.chrgitm_lv
|
||||
from (
|
||||
<if test="adviceTypes == null or adviceTypes.contains(1)">
|
||||
FROM (
|
||||
<choose>
|
||||
<when test="adviceTypes != null and !adviceTypes.isEmpty()">
|
||||
<trim prefixOverrides="UNION ALL">
|
||||
<if test="adviceTypes.contains(1)">
|
||||
(SELECT
|
||||
DISTINCT ON (T1.ID)
|
||||
T1.tenant_id,
|
||||
@@ -112,12 +115,8 @@
|
||||
)
|
||||
</if>
|
||||
|
||||
|
||||
<if test="adviceTypes == null or adviceTypes.contains(1)">
|
||||
<if test="adviceTypes == null or adviceTypes.contains(2) or adviceTypes.contains(3)">UNION ALL</if>
|
||||
</if>
|
||||
|
||||
<if test="adviceTypes == null or adviceTypes.contains(2)">
|
||||
<if test="adviceTypes.contains(2)">
|
||||
UNION ALL
|
||||
(SELECT
|
||||
DISTINCT ON (T1.ID)
|
||||
T1.tenant_id,
|
||||
@@ -179,12 +178,8 @@
|
||||
)
|
||||
</if>
|
||||
|
||||
|
||||
<if test="adviceTypes == null or adviceTypes.contains(2)">
|
||||
<if test="adviceTypes == null or adviceTypes.contains(3)">UNION ALL</if>
|
||||
</if>
|
||||
|
||||
<if test="adviceTypes == null or adviceTypes.contains(3)">
|
||||
<if test="adviceTypes.contains(3)">
|
||||
UNION ALL
|
||||
(SELECT
|
||||
DISTINCT ON (T1.ID)
|
||||
T1.tenant_id,
|
||||
@@ -245,6 +240,52 @@
|
||||
AND T1.status_enum = #{statusEnum}
|
||||
)
|
||||
</if>
|
||||
</trim>
|
||||
</when>
|
||||
<otherwise>
|
||||
-- 当没有指定adviceTypes或adviceTypes为空时,返回空结果集但保持正确的SQL语法
|
||||
SELECT
|
||||
NULL::varchar AS tenant_id,
|
||||
NULL::integer AS advice_type,
|
||||
NULL::varchar AS bus_no,
|
||||
NULL::varchar AS category_code,
|
||||
NULL::varchar AS pharmacology_category_code,
|
||||
NULL::numeric AS part_percent,
|
||||
NULL::numeric AS unit_conversion_ratio,
|
||||
NULL::integer AS part_attribute_enum,
|
||||
NULL::integer AS tho_part_attribute_enum,
|
||||
NULL::integer AS skin_test_flag,
|
||||
NULL::integer AS inject_flag,
|
||||
NULL::bigint AS advice_definition_id,
|
||||
NULL::varchar AS advice_name,
|
||||
NULL::varchar AS advice_bus_no,
|
||||
NULL::varchar AS py_str,
|
||||
NULL::varchar AS wb_str,
|
||||
NULL::varchar AS yb_no,
|
||||
NULL::varchar AS product_name,
|
||||
NULL::integer AS activity_type,
|
||||
NULL::varchar AS unit_code,
|
||||
NULL::varchar AS min_unit_code,
|
||||
NULL::numeric AS volume,
|
||||
NULL::varchar AS method_code,
|
||||
NULL::varchar AS rate_code,
|
||||
NULL::bigint AS org_id,
|
||||
NULL::bigint AS location_id,
|
||||
NULL::varchar AS dose,
|
||||
NULL::varchar AS dose_unit_code,
|
||||
NULL::varchar AS supplier,
|
||||
NULL::bigint AS supplier_id,
|
||||
NULL::varchar AS manufacturer,
|
||||
NULL::bigint AS charge_item_definition_id,
|
||||
NULL::varchar AS advice_table_name,
|
||||
NULL::bigint AS position_id,
|
||||
NULL::integer AS restricted_flag,
|
||||
NULL::varchar AS restricted_scope,
|
||||
NULL::varchar AS dosage_instruction,
|
||||
NULL::integer AS chrgitm_lv
|
||||
WHERE 1 = 0 -- 确保不返回任何行
|
||||
</otherwise>
|
||||
</choose>
|
||||
) AS abi
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user