LEFT JOIN (SELECT SUM(c1.csl) AS totalCsl, (CASE WHEN SUM(c1.csl) <![CDATA[<]]> 4000 THEN '0' ELSE '1' END) AS eligibility, c1.bizOrgName FROM (
select
*,
(
CASE
WHEN nowLevel IS NOT NULL
AND maxLevel IS NOT NULL
AND nowLevel - maxLevel > 0 THEN
'1'
WHEN nowLevel IS NOT NULL
AND minLevel IS NOT NULL
AND nowLevel != '--'
AND nowLevel - minLevel >= 0 THEN
'0'
WHEN nowLevel IS NOT NULL
AND minLevel IS NOT NULL AND nowLevel != '--'
AND minLevel - nowLevel > 0 THEN
'1' ELSE '0'
END
) AS `status`,
IFNULL(nowLevel/maxlevel, 0) * volume AS csl
from (
(SELECT
r.sequence_nbr AS id,
r.`name`,
wes.id as equipmentSpecificId,
IFNULL( rp.min_water_level, 0 ) AS minLevel,
IFNULL( rp.max_water_level, 0 ) AS maxLevel,
IFNULL( rp.output_flow_rate, 0 ) AS outputFlowRate,
IFNULL((select
avg(IFNULL(ei.`value`, 0))
from
wl_equipment_specific_index ei
where
(ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel')
AND FIND_IN_SET( ei.equipment_specific_id, rp.level_device_id) > 0), '--') AS nowLevel,
IFNULL(CASE WHEN (ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel') THEN ei.`unit` END,'--') AS 'unit',
IFNULL( rp.volume, 0 ) AS volume,
ec.image,
r.resource_type,
r.sequence_nbr,
wes.code,
ifnull(rp.pump_device_id, '') as pumpDeviceId,
r.biz_org_name AS bizOrgName
FROM
cb_water_resource r
LEFT JOIN cb_water_resource_pool rp ON rp.resource_id = r.sequence_nbr
LEFT JOIN wl_equipment_specific_index ei ON ei.equipment_specific_id = rp.level_device_id
LEFT JOIN wl_equipment_category ec ON ec.id = r.equip_category_id
LEFT JOIN f_fire_fighting_system fs ON fs.id = r.belong_fighting_system_id
LEFT JOIN wl_equipment_specific wes ON wes.id = rp.level_device_id
WHERE
r.resource_type = 'industryPool'
AND r.is_delete = 1
AND r.`biz_org_code` IS NOT NULL
<iftest="bizOrgCode!=null and bizOrgCode!=''">
AND r.biz_org_code like concat(#{bizOrgCode}, '%')
</if>
GROUP BY
r.sequence_nbr) union all
(
SELECT
a1.id,
a1.`name`,
a1.equipmentSpecificId,
a1.minLevel,
a1.maxLevel,
a1.outputFlowRate,
IFNULL( a1.nowLevel, '--' ) nowLevel,
a1.`unit`,
a1.volume,
a1.image,
a1.resource_type,
a1.sequence_nbr,
a1.code,
a1.pumpDeviceId,
a1.bizOrgName
FROM
(
SELECT
r.sequence_nbr AS id,
r.`name`,
wes.id as equipmentSpecificId,
IFNULL( rp.min_water_level, 0 ) AS minLevel,
IFNULL( rp.max_water_level, 0 ) AS maxLevel,
IFNULL( rp.output_flow_rate, 0 ) AS outputFlowRate,
(select
avg(IFNULL(ei.`value`,0))
from
wl_equipment_specific_index ei
where
(ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel')
and FIND_IN_SET( ei.equipment_specific_id, rp.level_device_id) > 0) AS nowLevel,
(select
ei.unit
from
wl_equipment_specific_index ei
where
(ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel')
and FIND_IN_SET( ei.equipment_specific_id, rp.level_device_id) > 0 limit 1) AS 'unit',
IFNULL( rp.volume, 0 ) AS volume,
ec.image,
r.resource_type,
r.sequence_nbr,
rp.level_device_id,
wes.code,
ifnull(rp.pump_device_id, '') as pumpDeviceId,
r.biz_org_name AS bizOrgName
FROM
cb_water_resource r
LEFT JOIN cb_water_resource_pool rp ON rp.resource_id = r.sequence_nbr
LEFT JOIN wl_equipment_category ec ON ec.id = r.equip_category_id
LEFT JOIN f_fire_fighting_system fs ON fs.id = r.belong_fighting_system_id
LEFT JOIN wl_equipment_specific wes ON wes.id = rp.level_device_id
WHERE
r.resource_type = 'pool'
AND r.is_delete = 1
AND r.`biz_org_code` IS NOT NULL
<iftest="bizOrgCode!=null and bizOrgCode!=''">
AND r.biz_org_code like concat(#{bizOrgCode}, '%')
</if>
GROUP BY
r.sequence_nbr
) a1
)) b1
) c1 GROUP BY bizOrgName) d ON d.bizOrgName = c.bizOrgName
<where>
<iftest="status != null and status != ''">
c.`status` = #{status}
...
...
@@ -5163,6 +5289,16 @@
</otherwise>
</choose>
</if>
<iftest="sortFlag != null and sortFlag != '' and sortFlag = '2'">
(SELECT count( 1 ) AS indexNum FROM wl_equipment_specific_index a LEFT JOIN wl_equipment_index b ON a.equipment_index_id = b.id WHERE b.is_iot = 1) AS indexNum,
(SELECT count( 1 ) AS equipNum FROM wl_equipment_specific es LEFT JOIN wl_equipment e ON e.`code` = es.equipment_code WHERE e.is_iot = 1
(SELECT
sum( n.num )
FROM
(
SELECT
a.id,
count( 1 ) AS num
FROM
wl_equipment_specific a
LEFT JOIN (select m.* from wl_equipment_specific_index m left join wl_equipment_index e on e.id = m.equipment_index_id where e.is_iot = 1) b ON a.id = b.equipment_specific_id
<where>
<iftest="bizOrgCode!=null and bizOrgCode!=''">
AND es.biz_org_code LIKE CONCAT(#{bizOrgCode},'%')
AND a.biz_org_code LIKE CONCAT(#{bizOrgCode},'%')
</if>
) AS equipNum,
(SELECT count(1) AS indexMonitorNum FROM wl_equipment_specific_index wesi LEFT JOIN wl_equipment_specific wes on wesi.equipment_specific_id = wes.id WHERE DATE_FORMAT(wesi.update_date, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
</where>
GROUP BY
a.id
) n
)
) AS indexNum,
(SELECT count( 1 ) AS equipNum FROM wl_equipment_specific es LEFT JOIN wl_equipment e ON e.`code` = es.equipment_code WHERE e.is_iot = 1
<iftest="bizOrgCode!=null and bizOrgCode!=''">
AND wes.biz_org_code LIKE CONCAT(#{bizOrgCode},'%')
AND es.biz_org_code LIKE CONCAT(#{bizOrgCode},'%')