IFNULL((SELECT CASE WHEN wesi.`value` = 'true' THEN wesi.equipment_index_name ELSE '关到位' END FROM wl_equipment_specific_index wesi
WHERE wesi.equipment_specific_id = temp.id AND wesi.equipment_index_key = 'CAFS_GunValve_OpenToPosition' ORDER BY wesi.update_date DESC LIMIT 1),'关到位') AS stateValue
FROM
(
SELECT wes.id,wes.name,wes.code,
CASE WHEN (SELECT is_alarm FROM wl_equipment_specific_index wesi WHERE wesi.equipment_specific_id = wes.id AND wesi.equipment_index_key = wes.realtime_iot_index_key ) = 1
AND wes.realtime_iot_index_value = 'true' THEN
1 ELSE 0
END AS alarm
FROM wl_equipment_specific wes
WHERE
wes.equipment_code LIKE concat( '920302', '%' )
AND wes.biz_org_code LIKE CONCAT( #{bizOrgCode}, '%' )