Commit 1466aa02 authored by 麻笑宇's avatar 麻笑宇

sql优化

parent 6844858f
......@@ -1126,95 +1126,105 @@
SELECT code, name FROM tz_equipment_category
),
filtered_data AS (
SELECT
tjur.sequence_nbr AS sequenceNbr,
'使用登记' AS businessType,
tjur.apply_no AS applyNo,
ec_equ_list.name AS equList,
ec_equ_category.name AS equCategory,
tjur.use_unit_name AS unitName,
tjur.receive_org_name AS receiveOrgName,
tjur.create_date AS createDate,
tjur.audit_pass_date AS handleDate,
CASE
WHEN tjur.status = '已完成' THEN '已完成'
ELSE '进行中'
END AS status
FROM tzs_jg_use_registration tjur
LEFT JOIN tzs_jg_use_registration_eq tne ON tjur.sequence_nbr = tne.equip_transfer_id
LEFT JOIN idx_biz_jg_register_info ri ON tne.equ_id = ri.RECORD
LEFT JOIN equipment_category ec_equ_list ON ec_equ_list.code = ri.EQU_LIST
LEFT JOIN equipment_category ec_equ_category ON ec_equ_category.code = ri.EQU_CATEGORY
WHERE
receive_company_org_code LIKE CONCAT(#{orgCode}, '%')
AND tjur.status != '已作废'
AND tjur.is_delete = 0
<if test="dto.beginDate != null and dto.beginDate != ''">
and date_ge(CAST(audit_pass_date as date),#{dto.beginDate})
</if>
<if test="dto.endDate != null and dto.endDate != ''">
and date_le(CAST(audit_pass_date as date),#{dto.endDate})
</if>
<if test="dto.companyName != null and dto.companyName != ''">
AND tjur.use_unit_name LIKE CONCAT('%', #{dto.companyName}, '%')
</if>
<if test="dto.superviseUnitName != null and dto.superviseUnitName != ''">
AND tjur.receive_org_name LIKE CONCAT('%', #{dto.superviseUnitName}, '%')
</if>
<if test="dto.equListCode != null and dto.equListCode != ''">
AND ri.EQU_LIST = #{dto.equListCode}
</if>
<if test="dto.equCategoryCode != null and dto.equCategoryCode != ''">
AND ri.EQU_CATEGORY = #{dto.equCategoryCode}
</if>
<if test="dto.status != null and dto.status != ''">
AND tjur.status = #{dto.status}
</if>
UNION ALL
SELECT DISTINCT
tjvi.sequence_nbr AS sequenceNbr,
'车用气瓶登记' AS businessType,
tjvi.apply_no AS applyNo,
ec_equ_list.name AS equList,
ec_equ_category.name AS equCategory,
tjvi.install_unit_name AS unitName,
tjvi.receive_org_name AS receiveOrgName,
tjvi.create_date AS createDate,
tjvi.audit_pass_date AS handleDate,
CASE
WHEN tjvi.status = '已完成' THEN '已完成'
ELSE '进行中'
END AS status
FROM tzs_jg_vehicle_information tjvi
LEFT JOIN tzs_jg_vehicle_information_eq tjvie ON tjvi.sequence_nbr = tjvie.vehicle_id
LEFT JOIN idx_biz_jg_register_info ri ON tjvie.equ_id = ri.RECORD
LEFT JOIN equipment_category ec_equ_list ON ec_equ_list.code = ri.EQU_LIST
LEFT JOIN equipment_category ec_equ_category ON ec_equ_category.code = ri.EQU_CATEGORY
WHERE
tjvi.org_branch_code LIKE CONCAT(#{orgCode}, '%')
AND tjvi.status != '已作废'
<if test="dto.beginDate != null and dto.beginDate != ''">
and date_ge(CAST(audit_pass_date as date),#{dto.beginDate})
</if>
<if test="dto.endDate != null and dto.endDate != ''">
and date_le(CAST(audit_pass_date as date),#{dto.endDate})
</if>
<if test="dto.companyName != null and dto.companyName != ''">
AND tjvi.use_unit_name LIKE CONCAT('%', #{dto.companyName}, '%')
</if>
<if test="dto.superviseUnitName != null and dto.superviseUnitName != ''">
AND tjvi.receive_org_name LIKE CONCAT('%', #{dto.superviseUnitName}, '%')
</if>
<if test="dto.equListCode != null and dto.equListCode != ''">
AND ri.EQU_LIST = #{dto.equListCode}
<if test="treeValue != null or dto.businessTypeCode == 'sy_dj'">
SELECT
tjur.sequence_nbr AS sequenceNbr,
'使用登记' AS businessType,
tjur.apply_no AS applyNo,
ec_equ_list.name AS equList,
ec_equ_category.name AS equCategory,
tjur.use_unit_name AS unitName,
tjur.receive_org_name AS receiveOrgName,
tjur.create_date AS createDate,
tjur.audit_pass_date AS handleDate,
CASE
WHEN tjur.status = '已完成' THEN '已完成'
ELSE '进行中'
END AS status
FROM tzs_jg_use_registration tjur
LEFT JOIN tzs_jg_use_registration_eq tne ON tjur.sequence_nbr = tne.equip_transfer_id
LEFT JOIN idx_biz_jg_register_info ri ON tne.equ_id = ri.RECORD
LEFT JOIN equipment_category ec_equ_list ON ec_equ_list.code = ri.EQU_LIST
LEFT JOIN equipment_category ec_equ_category ON ec_equ_category.code = ri.EQU_CATEGORY
WHERE
receive_company_org_code LIKE CONCAT(#{orgCode}, '%')
AND tjur.status != '已作废'
AND tjur.is_delete = 0
<if test="dto.beginDate != null and dto.beginDate != ''">
and date_ge(CAST(audit_pass_date as date),#{dto.beginDate})
</if>
<if test="dto.endDate != null and dto.endDate != ''">
and date_le(CAST(audit_pass_date as date),#{dto.endDate})
</if>
<if test="dto.companyName != null and dto.companyName != ''">
AND tjur.use_unit_name LIKE CONCAT('%', #{dto.companyName}, '%')
</if>
<if test="dto.superviseUnitName != null and dto.superviseUnitName != ''">
AND tjur.receive_org_name LIKE CONCAT('%', #{dto.superviseUnitName}, '%')
</if>
<if test="dto.equListCode != null and dto.equListCode != ''">
AND ri.EQU_LIST = #{dto.equListCode}
</if>
<if test="dto.equCategoryCode != null and dto.equCategoryCode != ''">
AND ri.EQU_CATEGORY = #{dto.equCategoryCode}
</if>
<if test="dto.status != null and dto.status != '' and dto.status != '6616'">
and tjur.status != '已完成'
</if>
<if test="dto.status != null and dto.status != '' and dto.status == '6616'">
and tjur.status = '已完成'
</if>
</if>
<if test="dto.equCategoryCode != null and dto.equCategoryCode != ''">
AND ri.EQU_CATEGORY = #{dto.equCategoryCode}
<if test="treeValue != null">
UNION ALL
</if>
<if test="dto.status != null and dto.status != ''">
AND tjvi.status = #{dto.status}
<if test="treeValue != null or dto.businessTypeCode == 'car_cyl_dj'">
SELECT DISTINCT
tjvi.sequence_nbr AS sequenceNbr,
'车用气瓶登记' AS businessType,
tjvi.apply_no AS applyNo,
ec_equ_list.name AS equList,
ec_equ_category.name AS equCategory,
tjvi.install_unit_name AS unitName,
tjvi.receive_org_name AS receiveOrgName,
tjvi.create_date AS createDate,
tjvi.audit_pass_date AS handleDate,
CASE
WHEN tjvi.status = '已完成' THEN '已完成'
ELSE '进行中'
END AS status
FROM tzs_jg_vehicle_information tjvi
LEFT JOIN tzs_jg_vehicle_information_eq tjvie ON tjvi.sequence_nbr = tjvie.vehicle_id
LEFT JOIN idx_biz_jg_register_info ri ON tjvie.equ_id = ri.RECORD
LEFT JOIN equipment_category ec_equ_list ON ec_equ_list.code = ri.EQU_LIST
LEFT JOIN equipment_category ec_equ_category ON ec_equ_category.code = ri.EQU_CATEGORY
WHERE
tjvi.org_branch_code LIKE CONCAT(#{orgCode}, '%')
AND tjvi.status != '已作废'
<if test="dto.beginDate != null and dto.beginDate != ''">
and date_ge(CAST(audit_pass_date as date),#{dto.beginDate})
</if>
<if test="dto.endDate != null and dto.endDate != ''">
and date_le(CAST(audit_pass_date as date),#{dto.endDate})
</if>
<if test="dto.companyName != null and dto.companyName != ''">
AND tjvi.use_unit_name LIKE CONCAT('%', #{dto.companyName}, '%')
</if>
<if test="dto.superviseUnitName != null and dto.superviseUnitName != ''">
AND tjvi.receive_org_name LIKE CONCAT('%', #{dto.superviseUnitName}, '%')
</if>
<if test="dto.equListCode != null and dto.equListCode != ''">
AND ri.EQU_LIST = #{dto.equListCode}
</if>
<if test="dto.equCategoryCode != null and dto.equCategoryCode != ''">
AND ri.EQU_CATEGORY = #{dto.equCategoryCode}
</if>
<if test="dto.status != null and dto.status != '' and dto.status != '6616'">
and tjvi.status != '已完成'
</if>
<if test="dto.status != null and dto.status != '' and dto.status == '6616'">
and tjvi.status = '已完成'
</if>
</if>
)
SELECT * FROM filtered_data ORDER BY createDate DESC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment