Commit 980204b2 authored by 刘林's avatar 刘林

fix(jg):监管业务查询性能优化

parent 69205719
......@@ -4,72 +4,96 @@
<select id="queryForSafetyProblemTracingPage"
resultType="com.yeejoin.amos.boot.module.jg.api.dto.SafetyProblemTracingDto">
select
SELECT
spt.*,
case when spt."problem_status_code" = '0' then '红'
else '绿' end hiddenDangersLevel,
(select extend::json->>'pic' from cb_data_dictionary where type = 'ISSUE_TYPE' and code = spt.problem_type_code) problemTypePic
from tzs_safety_problem_tracing spt
CASE
WHEN spt.problem_status_code = '0' THEN '红'
ELSE '绿'
END AS hiddenDangersLevel,
cdd.extend::json ->> 'pic' AS problemTypePic
FROM tzs_safety_problem_tracing spt
LEFT JOIN cb_data_dictionary cdd
ON cdd.type = 'ISSUE_TYPE'
AND cdd.code = spt.problem_type_code
<where>
spt.is_delete = false
spt.is_delete = FALSE
<if test="problemModel.problemNum != null and problemModel.problemNum != ''">
and spt.problem_num = LIKE CONCAT('%', #{problemModel.problemNum}, '%')
AND spt.problem_num LIKE CONCAT('%', #{problemModel.problemNum}, '%')
</if>
<if test="problemModel.problemStatus != null and problemModel.problemStatus != ''">
and spt.problem_status = #{problemModel.problemStatus}
AND spt.problem_status = #{problemModel.problemStatus}
</if>
<if test="problemModel.equipListCode != null and problemModel.equipListCode != ''">
and spt.equip_list_code = #{problemModel.equipListCode}
AND spt.equip_list_code = #{problemModel.equipListCode}
</if>
<if test="problemModel.equCategoryCode != null and problemModel.equCategoryCode != ''">
and spt.equ_category_code = #{problemModel.equCategoryCode}
AND spt.equ_category_code = #{problemModel.equCategoryCode}
</if>
<if test="problemModel.sourceTypeCode != null and problemModel.sourceTypeCode != ''">
and spt.source_type_code = #{problemModel.sourceTypeCode}
AND spt.source_type_code = #{problemModel.sourceTypeCode}
</if>
<if test="problemModel.problemLevelCode != null and problemModel.problemLevelCode != ''">
and spt.problem_level_code = #{problemModel.problemLevelCode}
AND spt.problem_level_code = #{problemModel.problemLevelCode}
</if>
<if test="problemModel.problemTypeCode != null and problemModel.problemTypeCode != ''">
and spt.problem_type_code = #{problemModel.problemTypeCode}
AND spt.problem_type_code = #{problemModel.problemTypeCode}
</if>
<if test="problemModel.problemTimeRange != null and problemModel.problemTimeRange.beginDate != null">
and to_char(spt.problem_time, 'YYYY-MM-DD') <![CDATA[>=]]>
AND to_char(spt.problem_time, 'YYYY-MM-DD') <![CDATA[>=]]>
to_char(#{problemModel.problemTimeRange.beginDate}::timestamp, 'YYYY-MM-DD')
</if>
<if test="problemModel.problemTimeRange != null and problemModel.problemTimeRange.endDate != null">
and to_char(spt.problem_time, 'YYYY-MM-DD') <![CDATA[<=]]>
AND to_char(spt.problem_time, 'YYYY-MM-DD') <![CDATA[<=]]>
to_char(#{problemModel.problemTimeRange.endDate}::timestamp, 'YYYY-MM-DD')
</if>
<if test="problemModel.problemDesc != null and problemModel.problemDesc != ''">
and spt.problem_desc like CONCAT('%', #{problemModel.problemDesc}, '%')
AND spt.problem_desc LIKE CONCAT('%', #{problemModel.problemDesc}, '%')
</if>
<if test="problemModel.sourceId != null and problemModel.sourceId != ''">
and spt.source_id = #{problemModel.sourceId}
AND spt.source_id = #{problemModel.sourceId}
</if>
<if test="problemModel.governingBodyOrgCode != null and problemModel.governingBodyOrgCode != ''">
and spt.governing_body_org_code like CONCAT(#{problemModel.governingBodyOrgCode}, '%')
AND spt.governing_body_org_code LIKE CONCAT(#{problemModel.governingBodyOrgCode}, '%')
</if>
<if test="problemModel.governingBodyCode != null and problemModel.governingBodyCode != ''">
and spt.governing_body_code = #{problemModel.governingBodyCode}
AND spt.governing_body_code = #{problemModel.governingBodyCode}
</if>
<if test="problemModel.principalUnit != null and problemModel.principalUnit != ''">
and spt.principal_unit like CONCAT('%', #{problemModel.principalUnit}, '%')
AND spt.principal_unit LIKE CONCAT('%', #{problemModel.principalUnit}, '%')
</if>
<if test="problemModel.principalUnitType != null and problemModel.principalUnitType != ''">
and spt.principal_unit_type like CONCAT('%', #{problemModel.principalUnitType}, '%')
AND spt.principal_unit_type LIKE CONCAT('%', #{problemModel.principalUnitType}, '%')
</if>
<if test="problemModel.hiddenDangersLevel != null and problemModel.hiddenDangersLevel != ''">
and spt.problem_status_code = #{problemModel.hiddenDangersLevel}
AND spt.problem_status_code = #{problemModel.hiddenDangersLevel}
</if>
<if test="problemModel.regionCode != null and problemModel.regionCode != ''">
and spt.region_code like CONCAT('%',#{problemModel.regionCode}, '%')
AND spt.region_code LIKE CONCAT('%', #{problemModel.regionCode}, '%')
</if>
<if test="problemModel.problemStatusCode != null and problemModel.problemStatusCode != ''">
and spt.problem_status_code = #{problemModel.problemStatusCode}
AND spt.problem_status_code = #{problemModel.problemStatusCode}
</if>
</where>
order by spt.create_date desc
ORDER BY spt.create_date DESC
</select>
<select id="queryEquipListByProblemId" resultType="java.util.Map">
......
......@@ -90,40 +90,28 @@
</resultMap>
<select id="countContraptionInUseTimesForEdit" resultMap="projectContraptionResultMap">
SELECT
project_contraption_id,
SUM(inUseNumber) inUseNumber
FROM (
SELECT
a.project_contraption_id,
COUNT(1) as inUseNumber
pl.project_contraption_id,
COALESCE(SUM(CASE WHEN ur.project_contraption_id IS NOT NULL THEN 1 ELSE 0 END), 0)
+ COALESCE(SUM(CASE WHEN ins.project_contraption_id IS NOT NULL THEN 1 ELSE 0 END), 0) AS inUseNumber
FROM
tzs_jg_use_registration a
WHERE a.project_contraption_id in
<foreach collection ='projectContraptionIdList' item='id' index='index' open="(" close= ")" separator=",">
#{id}
</foreach>
AND a.is_delete = 0
AND (a.status <![CDATA[ <> ]]> '使用单位待提交' and a.status <![CDATA[ <> ]]> '一级受理已驳回' and a.status <![CDATA[ <> ]]> '使用单位已撤回' and a.status <![CDATA[ <> ]]> '已作废')
group by a.project_contraption_id
UNION
SELECT
a.project_contraption_id,
COUNT(1) as inUseNumber
FROM
tzs_jg_installation_notice a
WHERE a.project_contraption_id in
<foreach collection ='projectContraptionIdList' item='id' index='index' open="(" close= ")" separator=",">
UNNEST(
ARRAY[
<foreach collection="projectContraptionIdList" item="id" separator=",">
#{id}
</foreach>
AND a.notice_status <![CDATA[ <> ]]> '6610'
AND a.notice_status <![CDATA[ <> ]]> '6615'
AND a.notice_status <![CDATA[ <> ]]> '6614'
group by a.project_contraption_id
)
GROUP BY project_contraption_id
]
) AS pl(project_contraption_id)
LEFT JOIN tzs_jg_use_registration ur
ON ur.project_contraption_id = pl.project_contraption_id
AND ur.is_delete = 0
AND ur.project_contraption_id != null
AND ur.status NOT IN ('使用单位待提交','一级受理已驳回','使用单位已撤回','已作废')
LEFT JOIN tzs_jg_installation_notice ins
ON ins.project_contraption_id = pl.project_contraption_id
AND ins.notice_status NOT IN ('6610','6614','6615')
GROUP BY pl.project_contraption_id
</select>
<select id="countContraptionInUseTimesForDelete" resultMap="projectContraptionResultMap">
SELECT
project_contraption_id,
......@@ -263,7 +251,8 @@
FROM (
SELECT "RECORD", project_contraption_id
FROM idx_biz_jg_use_info
WHERE project_contraption_id = ANY(
WHERE project_contraption_id != null
AND project_contraption_id = ANY(
ARRAY[
<foreach collection="projectContraptionIdList" item="id" index="index" separator=",">
#{id}
......@@ -271,6 +260,7 @@
])) tu
GROUP BY tu.project_contraption_id
</select>
<select id="queryJgProjectContraptionPage"
resultType="com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgProjectContraption">
select
......@@ -473,172 +463,130 @@
<select id="countContraptionInUseTimesForDeleteByIntoManagementBatch" resultMap="projectContraptionResultMap">
SELECT
project_contraption_id,
SUM(inUseNumber) inUseNumber
FROM (
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
FROM tzs_jg_equip_transfer a
LEFT JOIN tzs_jg_equip_transfer_eq b ON b.equip_transfer_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.apply_status != '6617')
GROUP BY c.project_contraption_id
UNION
SELECT
a.project_contraption_id,
COUNT(1) AS inUseNumber
pc.project_contraption_id,
COALESCE(et.cnt,0) +
COALESCE(ur.cnt,0) +
COALESCE(cru.cnt,0) +
COALESCE(ed.cnt,0) +
COALESCE(sc.cnt,0) +
COALESCE(crt.cnt,0) +
COALESCE(crn.cnt,0) +
COALESCE(ins.cnt,0) +
COALESCE(mnt.cnt,0) +
COALESCE(ref.cnt,0) +
COALESCE(trf.cnt,0) +
COALESCE(inspec.cnt,0) AS inUseNumber
FROM
tzs_jg_use_registration a
WHERE a.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
(VALUES
<foreach collection="projectContraptionIdList" item="projectContraptionId" separator=",">
(#{projectContraptionId})
</foreach>
AND a.is_delete = 0
AND ( a.status != '已作废')
) AS pc(project_contraption_id)
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_equip_transfer a
JOIN tzs_jg_equip_transfer_eq b ON b.equip_transfer_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.apply_status != '6617'
GROUP BY c.project_contraption_id
) et ON et.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT a.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_use_registration a
WHERE a.is_delete = 0 AND a.status != '已作废'
GROUP BY a.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) ur ON ur.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_change_registration_unit a
LEFT JOIN tzs_jg_change_registration_unit_eq b ON b.unit_change_registration_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.status != '已作废')
JOIN tzs_jg_change_registration_unit_eq b ON b.unit_change_registration_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.status != '已作废'
GROUP BY c.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) cru ON cru.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_enable_disable a
LEFT JOIN tzs_jg_enable_disable_eq b ON b.enable_disable_apply_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.audit_status != '已作废')
JOIN tzs_jg_enable_disable_eq b ON b.enable_disable_apply_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.audit_status != '已作废'
GROUP BY c.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) ed ON ed.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_scrap_cancel a
LEFT JOIN tzs_jg_scrap_cancel_eq b ON b.equip_transfer_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.audit_status != '使用单位已撤回')
JOIN tzs_jg_scrap_cancel_eq b ON b.equip_transfer_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.audit_status != '使用单位已撤回'
GROUP BY c.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) sc ON sc.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_change_registration_transfer a
LEFT JOIN tzs_jg_change_registration_transfer_eq b ON b.equip_transfer_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.audit_status != '使用单位已撤回')
JOIN tzs_jg_change_registration_transfer_eq b ON b.equip_transfer_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.audit_status != '使用单位已撤回'
GROUP BY c.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) crt ON crt.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_change_registration_name a
LEFT JOIN tzs_jg_change_registration_name_eq b ON b.name_change_registration_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.audit_status != '使用单位已撤回')
JOIN tzs_jg_change_registration_name_eq b ON b.name_change_registration_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.audit_status != '使用单位已撤回'
GROUP BY c.project_contraption_id
UNION
SELECT
a.project_contraption_id,
COUNT(1) AS inUseNumber
FROM
tzs_jg_installation_notice a
WHERE a.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND (a.notice_status != '6617')
) crn ON crn.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT a.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_installation_notice a
WHERE a.notice_status != '6617'
GROUP BY a.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) ins ON ins.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_maintain_notice a
LEFT JOIN tzs_jg_maintain_notice_eq b ON b.equip_transfer_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.notice_status != '6617')
JOIN tzs_jg_maintain_notice_eq b ON b.equip_transfer_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.notice_status != '6617'
GROUP BY c.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) mnt ON mnt.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_reform_notice a
LEFT JOIN tzs_jg_reform_notice_eq b ON b.equip_transfer_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.notice_status != '6617')
JOIN tzs_jg_reform_notice_eq b ON b.equip_transfer_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.notice_status != '6617'
GROUP BY c.project_contraption_id
UNION
SELECT
c.project_contraption_id,
COUNT(1) AS inUseNumber
) ref ON ref.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT c.project_contraption_id, COUNT(1) AS cnt
FROM tzs_jg_transfer_notice a
LEFT JOIN tzs_jg_transfer_notice_eq b ON b.equip_transfer_id=a.sequence_nbr
LEFT JOIN idx_biz_jg_use_info c ON b.equ_id=c.record
WHERE c.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND a.is_delete = 0
AND ( a.notice_status != '6617')
JOIN tzs_jg_transfer_notice_eq b ON b.equip_transfer_id = a.sequence_nbr
JOIN idx_biz_jg_use_info c ON b.equ_id = c.record
WHERE a.is_delete = 0 AND a.notice_status != '6617'
GROUP BY c.project_contraption_id
UNION
SELECT
a.project_contraption_id,
COUNT(1) AS inUseNumber
) trf ON trf.project_contraption_id = pc.project_contraption_id
LEFT JOIN (
SELECT a.project_contraption_id, COUNT(1) AS cnt
FROM tz_jyjc_inspection_application a
WHERE a.project_contraption_id in
<foreach collection="projectContraptionIdList" item="projectContraptionId" index='index' open="(" close= ")" separator=",">
#{projectContraptionId}
</foreach>
AND ( a.status != '6617')
WHERE a.status != '6617'
GROUP BY a.project_contraption_id
) GROUP BY project_contraption_id
) inspec ON inspec.project_contraption_id = pc.project_contraption_id
</select>
<select id="selectPipelineListByProjectContraptionId"
resultType="com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgTechParamsPipeline">
SELECT
......
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