CASE WHEN COUNT(*) = 0 THEN 0 ELSE ROUND((COUNT(CASE WHEN ci.next_inspection_date <![CDATA[<=]]> now() THEN 1 END) * 100.0 / COUNT(*)), 2) END AS expiredRate
FROM
"tz_cylinder_inspection" ci
LEFT JOIN tz_base_enterprise_info cu on ci.app_id = cu.app_id
<where>
cu.data_sources = '陕西省内企业'
AND cu.unit_type LIKE '%充装单位%'
<iftest="regionCode != null and regionCode != ''">
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate} and alarm_type_code = '960' and father_alert is null)
and org_type_code = 'levelOneUnit') as levelOne,
(select count(1)
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate} and alarm_type_code = '960' and father_alert is null)
and org_type_code = 'levelTwoUnit') as levelTwo,
(select count(1)
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate} and alarm_type_code = '960' and father_alert is null)
and org_type_code = '953') as levelThree,
(select count(DISTINCT (response_org_id))
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate} and alarm_type_code = '960' and father_alert is null)
and org_type_code = 'levelOneUnit') as maintenanceUnit,
( SELECT count(1) from (
SELECT
t1.sequence_nbr,
(SELECT min(arrive_time) from tz_dispatch_task where alert_id = t1.sequence_nbr and arrive_time is not null) as arr,
(SELECT min(dispatch_time) from tz_dispatch_task where alert_id = t1.sequence_nbr and dispatch_time is not null ) as dis
from tz_alert_called t1 where t1.biz_org_code like concat(#{orgCode}, '%') and t1.alarm_type_code = '960' and call_time BETWEEN #{startDate} and #{endDate} and father_alert is null
) where extract(epoch from arr - dis ) < 1800
) as lessNum,
(SELECT count(1) from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and alarm_type_code = '960' and call_time BETWEEN #{startDate} and #{endDate} and father_alert is null) as greaterNum,
(
SELECT sum(extract(epoch from arr - dis )) from
( SELECT
t1.sequence_nbr,
(SELECT min(arrive_time) from tz_dispatch_task where alert_id = t1.sequence_nbr and arrive_time is not null) as arr,
(SELECT min(dispatch_time) from tz_dispatch_task where alert_id = t1.sequence_nbr and dispatch_time is not null ) as dis
from tz_alert_called t1 where t1.biz_org_code like concat(#{orgCode}, '%') and t1.alarm_type_code = '960' and t1.call_time BETWEEN #{startDate} and #{endDate} and t1.father_alert is null
CASE WHEN COUNT(*) = 0 THEN 0 ELSE ROUND((COUNT(CASE WHEN ci.next_inspection_date <![CDATA[<=]]> now() THEN 1 END) * 100.0 / COUNT(*)), 2) END AS expiredRate
FROM
"tz_cylinder_inspection" ci
LEFT JOIN tz_base_enterprise_info cu on ci.app_id = cu.app_id
<where>
cu.data_sources = '陕西省内企业'
AND cu.unit_type LIKE '%充装单位%'
<iftest="regionCode != null and regionCode != ''">
and ((supervise_org_code != '50' and supervise_org_code LIKE CONCAT (#{orgCode}, '%')) or (supervise_org_code = '50' and office_region LIKE CONCAT ('%', #{cityCode}, '%')))
and ((supervise_org_code != '50' and supervise_org_code LIKE CONCAT (#{orgCode}, '%')) or (supervise_org_code = '50' and office_region LIKE CONCAT ('%', #{cityCode}, '%')))