<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.equipmanage.mapper.FireFightingSystemMapper">
    <resultMap id="EquiplistBySystemId" type="com.yeejoin.equipmanage.common.entity.vo.EquiplistSpecificBySystemVO">
        <result property="id" column="id"></result>
        <result property="equipmentName" column="equipment_name"></result>
        <result property="code" column="code"></result>
        <result property="categoryName" column="category_name"></result>
        <result property="isBound" column="is_bound"></result>
    </resultMap>

    <resultMap id="EquipCountBySystemId" type="com.yeejoin.equipmanage.common.entity.vo.EquipCountBySystemVO">
        <result property="equipmentId" column="equipment_id"></result>
        <result property="equipmentName" column="equipment_name"></result>
        <result property="equipmentNum" column="num"></result>
        <result property="unitName" column="unit_name"></result>
    </resultMap>
    <resultMap id="CategoryAmountList" type="com.yeejoin.equipmanage.common.entity.vo.EquipTypeImgAmountVO">
        <result column="id" property="id"></result>
        <result column="fullqrCode" property="fullqrCode"></result>
        <result column="amount" property="amount"></result>
        <result column="equipmentName" property="equipmentName"></result>
        <result column="unitName" property="unitName"></result>
        <result property="qrCode" column="qr_code"></result>
        <result property="standard" column="standard"></result>
        <result property="img" column="img"></result>
        <result property="warehouseStructureName" column="full_name"></result>
        <result property="systemName" column="systemName"></result>
        <result property="amount" column="amount"></result>
        <result property="manufacturerName" column="manufacturerName"></result>
        <result property="status" column="status"></result>
        <result property="type" column="type"></result>
        <result property="code" column="code"></result>
        <result property="systemType" column="systemType"></result>
        <result property="iotCode" column="iotCode"></result>
        <result property="eqtype" column="eqtype"></result>
        <result property="bizOrgCode" column="bizOrgCode"></result>
        <result property="equipStatus" column="equipStatus"></result>
        <result property="bizOrgName" column="bizOrgName"></result>
        <result property="belongBuildName" column="belongBuildName"></result>

    </resultMap>
    <select id="getEquiplistBySystemId" resultMap="EquiplistBySystemId">
       SELECT
            spe.id,
            det.`name` equipment_name,
            spe.`code`,
            spe.`iot_code` iotCode,
            wle.`name` AS category_name,
            find_in_set(spe.id,(select  point_in_scene from  wl_source_scene  where source_id=#{systemId}))	 is_bound

        FROM
            wl_equipment_specific AS spe
            LEFT JOIN wl_equipment_detail AS det ON spe.equipment_detail_id = det.id
            LEFT JOIN wl_equipment AS wle ON wle.id = det.equipment_id
            LEFT JOIN wl_stock_detail AS wlsd on  wlsd.equipment_detail_id = det.id
       WHERE
           find_in_set(#{systemId},spe.system_id) and spe.single = true  and 	wlsd.`status` = 1
    </select>

    <select id="getEquiplistBySystemIdList" resultType="com.yeejoin.equipmanage.common.entity.vo.EquiplistSpecificBySystemVO">
       SELECT
            det.`name` equipmentName,
            spe.`iot_code` iotCode,
            ein.equipment_index_name indexName,
			ein.equipment_index_key indexKey,
			ein.is_alarm  isAlarm

        FROM
            wl_equipment_specific AS spe
            LEFT JOIN wl_equipment_detail AS det ON spe.equipment_detail_id = det.id
            LEFT JOIN wl_stock_detail AS wlsd on  wlsd.equipment_detail_id = det.id
			LEFT JOIN wl_equipment_specific_index  ein on ein.equipment_specific_id =spe.id
			WHERE
           find_in_set(#{systemId},spe.system_id) and spe.single = true  and 	wlsd.`status` = 1
            and spe.`iot_code` is not null and ein.is_alarm =0
    </select>






    <!--   任务 3711 by litw 2021年9月17日  新增装备分类名称-->
    <select id="getEquipCountBySystemId" resultMap="EquipCountBySystemId">
        SELECT
            wle.id equipment_id,
            det.NAME equipment_name,
            count(spe.id) num,
			unit.name unit_name,
			cate.NAME AS equipmentCateGoryName
        FROM
            wl_equipment_specific AS spe
            LEFT JOIN wl_equipment_detail AS det ON spe.equipment_detail_id = det.id
            LEFT JOIN wl_equipment AS wle ON wle.id = det.equipment_id
            LEFT JOIN wl_equipment_category cate ON cate.id = wle.category_id
            LEFT JOIN wl_unit as unit ON wle.unit_id = unit.id
            where
            find_in_set(#{systemId},spe.system_id) and spe.single = true
        group by wle.id
    </select>
    <insert id="save">
             INSERT INTO
                f_fire_fighting_system
                (id,
                name,
                code,
                system_type,
                form_group_id,
                install_date,
                charge_person,
                charge_person_name,
                construction_unit,
                maintenance_unit,
                maintenance_frequency,
                first_maintenance_date,
                rec_user_id,
                rec_date,
                sort,
                charge_person_phone,
                maintenance_phone,
                org_code,
                contro_box_build,
                pro_object,
                instance_id,
                pro_code,
                factory,
                contro_box_address,
                biz_org_code,
                biz_org_name,
                design_org,
                design_org_telephone,
                lead_designer
                )
                VALUES(
                #{id},
                #{name},
                #{code},
                #{systemType},
                #{formGroupId},
                STR_TO_DATE(#{installDate},'%Y-%m-%d'),
                #{chargePerson},
                #{chargePersonName},
                #{constructionUnit},
                #{maintenanceUnit},
                #{maintenanceFrequency},
                STR_TO_DATE(#{firstMaintenanceDate},'%Y-%m-%d'),
                #{recUserId},
                now(),
                #{sort},
                #{chargePersonPhone},
                #{maintenancePhone},
                #{orgCode},
                #{controBoxBuild},
                #{proObject},
                #{instanceId},
                #{proCode},
                #{factory},
                #{controBoxAddress},
                #{bizOrgCode},
                #{bizOrgName},
                #{designOrg},
                #{designOrgTelephone},
                #{leadDesigner}
                )
    </insert>
    <insert id="insertFile">
        insert into wl_upload_file
             (id,
             url,
             name,
             user_id,
             file_type,
             object_id,
             create_date)
             VALUES(
             #{id},
             #{url},
             #{name},
             #{userId},
             #{fileType},
             #{objectId},
             now())
    </insert>
    <!--  BUG 2938 更新系统没有更新系统编号 by kongfm 2021-09-17  -->
    <!--  BUG 2938 更新系统类型 by chenzhao 2021-09-26  -->
    <update id="update">
         UPDATE
              f_fire_fighting_system
              SET
              name = #{name},
              install_date =STR_TO_DATE(#{installDate},'%Y-%m-%d'),
              charge_person =#{chargePerson},
              charge_person_name=#{chargePersonName},
              construction_unit =#{constructionUnit},
              maintenance_unit =#{maintenanceUnit},
              maintenance_frequency =#{maintenanceFrequency},
              first_maintenance_date =STR_TO_DATE(#{firstMaintenanceDate},'%Y-%m-%d'),
              rec_user_id =#{recUserId},
              rec_date = now(),
              charge_person_phone=#{chargePersonPhone},
              maintenance_phone =#{maintenancePhone},
              contro_box_build=#{controBoxBuild},
              pro_object=#{proObject},
              pro_code=#{proCode},
              factory=#{factory},
              code=#{code},
              form_group_id =#{formGroupId},
              contro_box_address = #{controBoxAddress},
              biz_org_code=#{bizOrgCode},
              biz_org_name=#{bizOrgName},
              design_org = #{designOrg},
              lead_designer = #{leadDesigner},
              design_org_telephone = #{designOrgTelephone}
              where id = #{id}
    </update>
    <delete id="deleteFilre">
        delete from wl_upload_file WHERE object_id = #{id}
    </delete>
    <update id="setSceneId">
        UPDATE
              f_fire_fighting_system
              SET scene_id=#{sceneId}
              where id =#{id}
    </update>

<!--    全部建筑下不应该存在装备-->
    <select id="getPointDataNum" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        SELECT b.* from (
        select
        '正在加载中...' as displayName,
        da.parentId,
        da.sequenceNbr
        from (
        select
        stru.source_id as parentId,
        spe.id as sequenceNbr
        from wl_stock_detail as det
        join wl_warehouse_structure as stru on det.warehouse_structure_id = stru.id
        join wl_equipment_specific as spe on det.qr_code = spe.qr_code
        join wl_equipment_detail as eqdet on det.equipment_detail_id = eqdet.id
        join wl_equipment as equ on eqdet.equipment_id = equ.id
        join wl_equipment_category as cat on equ.category_id = cat.id
        where det.amount > 0
        and spe.single = true and stru.source_id != '0'
        ) as da
        GROUP BY da.parentId
        <if test="id != null  and  id !=''">
            where find_in_set(#{id}, da.equipSyetemId)
        </if>
        <if test="id == null">
            union all
            SELECT
            '正在加载中...' as displayName,
            vis.source_id AS parentId,
            vid.id AS sequenceNbr
            FROM
            wl_video AS vid
            JOIN wl_video_source AS vis ON vid.id = vis.video_id
            JOIN wl_warehouse_structure AS stru ON stru.id = vis.source_id
            GROUP BY parentId ) as b
            GROUP BY b.parentId
        </if>
    </select>

    <select id="getPointData" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        select * from (
        select
        'component' as template,
        true as openStatus,
        if(spe.code is null,eqdet.name,concat(eqdet.name,'(',spe.code,')')) as displayName,
        '{\"width\": 20, \"height\": 20}'as initStyle,
        'CommonEquip' as componentName,
        spe.id as sequenceNbr,
        'equipment' as componentKey,
        'equipment' as `key`,
        equ.img as imgPath,
        spe.qr_code as equipCode,
--         spe.code as equipCode,
        spe.code  AS code,
        stru.source_id as parentId,
        cat.id as equipId,
        cat.code as categoryCode,
        cat.name as equipName,
        spe.system_id as equipSyetemId,
        spe.iot_code as iotCode,
        equ.id as groupId,
        equ.name as groupName,
        '' as ip,
        '' as token,
        '' as address
        from wl_stock_detail as det
        join wl_warehouse_structure as stru on det.warehouse_structure_id = stru.id
        join wl_equipment_specific as spe on det.qr_code = spe.qr_code
        join wl_equipment_detail as eqdet on det.equipment_detail_id = eqdet.id
        join wl_equipment as equ on eqdet.equipment_id = equ.id
        join wl_equipment_category as cat on equ.category_id = cat.id
        where det.amount > 0
        and spe.single = true
        <if test="instanceId != null and instanceId !=''">
        and  stru.id IN
         (  select id from wl_warehouse_structure where parent_id in(
            select id from wl_warehouse_structure where parent_id = #{instanceId})
            union
            select id from wl_warehouse_structure where parent_id = #{instanceId} or
            id = #{instanceId} )
        </if>
            ) as da
        <if test="id != null  and  id !=''">
            where find_in_set(#{id}, da.equipSyetemId)
        </if>
        <if test="id == null">
            union all
            SELECT
            'component' AS template,
            TRUE AS openStatus,
            IF
            ( vid.CODE IS NULL, vid.NAME, concat( vid.NAME, '(', vid.CODE, ')' ) ) AS displayName,
            '{\"width\": 20, \"height\": 20}' AS initStyle,
            'CommonEquip' AS componentName,
            vid.id AS sequenceNbr,
            'equipment' AS componentKey,
            'video' AS `key`,
            img AS imgPath,
            vid.code AS equipCode,
            vid.code AS code,
            vis.source_id AS parentId,
            vid.id AS equipId,
            vid.CODE AS categoryCode,
            vid.NAME AS equipName,
            '' AS equipSyetemId,
            '' AS iotCode,
            '1000000000000000' AS groupId,
            '监控摄像' AS groupName,
            url AS ip,
            token,
            stru.full_name AS address
            FROM
            wl_video AS vid
            JOIN wl_video_source AS vis ON vid.id = vis.video_id
            JOIN wl_warehouse_structure AS stru ON stru.id = vis.source_id
            WHERE
            stru.id IN
            (
            select id from wl_warehouse_structure where parent_id in(
            select id from wl_warehouse_structure where parent_id = #{instanceId})
            union
            select id from wl_warehouse_structure where parent_id = #{instanceId} or
            id = #{instanceId}
            )
        </if>
    </select>

    <select id="getPointDataNew" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        select * from (
        select
        'component' as template,
        true as openStatus,
        if(spe.code is null,eqdet.name,concat(eqdet.name,'(',spe.code,')')) as displayName,
        '{\"width\": 20, \"height\": 20}'as initStyle,
        'CommonEquip' as componentName,
        spe.id as sequenceNbr,
        'equipment' as componentKey,
        'equipment' as `key`,
        equ.img as imgPath,
        spe.qr_code as equipCode,
        --         spe.code as equipCode,
        spe.code  AS code,
        stru.source_id as parentId,
        cat.id as equipId,
        cat.code as categoryCode,
        cat.name as equipName,
        spe.system_id as equipSyetemId,
        spe.iot_code as iotCode,
        equ.id as groupId,
        equ.name as groupName,
        '' as ip,
        '' as token,
        '' as address
        from wl_stock_detail as det
        join wl_warehouse_structure as stru on det.warehouse_structure_id = stru.id
        join wl_equipment_specific as spe on det.qr_code = spe.qr_code
        join wl_equipment_detail as eqdet on det.equipment_detail_id = eqdet.id
        join wl_equipment as equ on eqdet.equipment_id = equ.id
        join wl_equipment_category as cat on equ.category_id = cat.id
        where det.amount > 0
        and spe.single = true
        <if test="instanceId != null and instanceId !=''">
            and  stru.id IN
            (  select id from wl_warehouse_structure where parent_id in(
            select id from wl_warehouse_structure where parent_id = #{instanceId})
            union
            select id from wl_warehouse_structure where parent_id = #{instanceId}or
            id = #{instanceId} )
        </if>
        ) as da
        <where>
        <if test="displayName != null and displayName != '' ">
            da.displayName like concat ('%',#{displayName},'%')
        </if>
            <choose>
                <when test="id != null  and  id !=''">
                    find_in_set(#{id}, da.equipSyetemId)
                </when>
                <when test="id == null">
                    union all
                    SELECT * from (
                    SELECT
                    'component' AS template,
                    TRUE AS openStatus,
                    IF
                    ( vid.CODE IS NULL, vid.NAME, concat( vid.NAME, '(', vid.CODE, ')' ) ) AS displayName,
                    '{\"width\": 20, \"height\": 20}' AS initStyle,
                    'CommonEquip' AS componentName,
                    vid.id AS sequenceNbr,
                    'equipment' AS componentKey,
                    'video' AS `key`,
                    img AS imgPath,
                    vid.code AS equipCode,
                    vid.code AS code,
                    vis.source_id AS parentId,
                    vid.id AS equipId,
                    vid.CODE AS categoryCode,
                    vid.NAME AS equipName,
                    '' AS equipSyetemId,
                    '' AS iotCode,
                    '1000000000000000' AS groupId,
                    '监控摄像' AS groupName,
                    url AS ip,
                    token,
                    stru.full_name AS address
                    FROM
                    wl_video AS vid
                    JOIN wl_video_source AS vis ON vid.id = vis.video_id
                    JOIN wl_warehouse_structure AS stru ON stru.id = vis.source_id
                    <if test="instanceId != null and instanceId !=''">
                        and  stru.id IN
                        (  select id from wl_warehouse_structure where parent_id in(
                        select id from wl_warehouse_structure where parent_id = #{instanceId})
                        union
                        select id from wl_warehouse_structure where parent_id = #{instanceId}or
                        id = #{instanceId} )
                    </if>
                    ) as video
                    <where>
                        <if test="displayName != null and displayName != '' ">
                            video.displayName like concat ('%',#{displayName},'%')
                        </if>
                    </where>
                </when>
            </choose>
        </where>
    </select>
    <select id="get3dPointData" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        SELECT
            *
        FROM
            (
            SELECT
            IF
                ( spe.CODE IS NULL, eqdet.NAME, concat( eqdet.NAME, '(', spe.CODE, ')' ) ) AS displayName,
                spe.id AS sequenceNbr,
                'equipment' AS componentKey,
                'equipment' AS `key`,
                spe.CODE AS equipCode,
                stru.source_id AS parentId,
                cat.id AS equipId,
                cat.CODE AS categoryCode,
                cat.NAME AS equipName,
                spe.system_id AS equipSyetemId,
                spe.iot_code AS iotCode,
                equ.id AS groupId,
                equ.NAME AS groupName
            FROM
                wl_stock_detail AS det
                LEFT JOIN wl_warehouse_structure AS stru ON det.warehouse_structure_id = stru.id
                LEFT JOIN wl_equipment_specific AS spe ON det.qr_code = spe.qr_code
                LEFT JOIN wl_equipment_detail AS eqdet ON det.equipment_detail_id = eqdet.id
                LEFT JOIN wl_equipment AS equ ON eqdet.equipment_id = equ.id
                LEFT JOIN wl_equipment_category AS cat ON equ.category_id = cat.id
            WHERE
                det.amount > 0
                AND spe.single = TRUE
                AND stru.source_id IS NOT NULL
            ) AS da UNION ALL
        SELECT
        IF
            ( vid.CODE IS NULL, vid.NAME, concat( vid.NAME, '(', vid.CODE, ')' ) ) AS displayName,
            vid.id AS sequenceNbr,
            'video' AS componentKey,
            'video' AS `key`,
            vid.CODE AS equipCode,
            vis.source_id AS parentId,
            vid.id AS equipId,
            vid.type_code AS categoryCode,
            vid.NAME AS equipName,
            '' AS equipSyetemId,
            '' AS iotCode,
            vid.type_code AS groupId,
            vid.type AS groupName
        FROM
            wl_video AS vid
            LEFT JOIN wl_video_source AS vis ON vid.id = vis.video_id
            LEFT JOIN wl_source_scene AS sou ON sou.video_in_scene LIKE CONCAT( '%', vid.id, '%' )
            LEFT JOIN wl_warehouse_structure AS stru ON stru.id = sou.source_id UNION ALL
        SELECT
        IF
            ( p.point_no IS NULL, p.NAME, concat( p.NAME, '(', p.point_no, ')' ) ) AS displayName,
            p.id AS sequenceNbr,
            'patrol' AS componentKey,
            'patrol' AS `key`,
            p.point_no AS equipCode,
            p.risk_source_id AS parentId,
            p.id AS equipId,
            '99999999' AS categoryCode,
            p.NAME AS equipName,
            '' AS equipSyetemId,
            '' AS iotCode,
            '99999999' AS groupId,
            '巡检点' AS groupName
        FROM
            p_point p
    </select>
    <select id="getSpeIndex" resultType="com.yeejoin.equipmanage.common.vo.SpeIndexVo">
    	SELECT
			*
		FROM
			(
				SELECT
					eqin.name_key AS `key`,
					eqin.`name` AS `name`,
					eqin.type_code,
					spein.update_date AS updateDate,
					spein.equipment_specific_id as equipmentSpecificId,
				IF (
					eqin.unit IS NULL,
				IF (
					(
						ISNULL(spein.value_label)
						OR spein.value_label = ''
					),
					spein.`value`,
					spein.value_label
				),
				concat(
					IF (
						(
							ISNULL(spein.value_label)
							OR spein.value_label = ''
						),
						spein.`value`,
						spein.value_label
					),
					' ',
					eqin.unit
				)
				) AS `value`,
				spein.emergency_level_color AS color,
				spein.is_alarm AS isAlarm,
				spein.emergency_level AS emergencyLevel,
				spein.emergency_level_describe AS emergencyLevelDescribe,
				spein.`value` AS indexValue,
				spein.equipment_index_name AS indexName,
				wes.qr_code AS qrCode
				FROM
					wl_equipment_specific_index AS spein
				LEFT JOIN wl_equipment_index AS eqin ON spein.equipment_index_id = eqin.id
				LEFT JOIN wl_equipment_specific AS wes ON wes.id = spein.equipment_specific_id
				WHERE
					spein.equipment_specific_id = #{id}
				ORDER BY
					eqin.sort_num
			) AS dat
		WHERE
			`key` IS NOT NULL
		AND `key` != ''
		ORDER BY
			dat.updateDate DESC
    </select>
    <select id="getSpeIndexIn" resultType="com.yeejoin.equipmanage.common.vo.SpeIndexVo">
		select * from (
         select
             eqin.name_key as `key`,
             eqin.name as name,
             eqin.type_code,
             spein.update_date as updateDate,
             if (eqin.unit is null, spein.value,concat(spein.value,eqin.unit)) as value,
            spein.equipment_specific_id
             from
             wl_equipment_specific_index as spein
             left join wl_equipment_index as eqin on spein.equipment_index_id = eqin.id
             <where>
                 <if test="list != null and list.size() >0">
                     AND spein.equipment_specific_id IN
                     <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                         #{item}
                     </foreach>
                 </if>
             </where>
            order by eqin.sort_num) as dat
            where `key` <![CDATA[<>]]> ''
            ORDER BY dat.updateDate DESC
    </select>
    <select id="getSystemById" resultType="com.yeejoin.equipmanage.common.vo.AlarmDataVO">

        select a.key,a.value,a.isHref from(SELECT
        fffs.id,
                        '系统名称' AS 'key',
                        IFNULL(fffs.name,'') AS
                    VALUE,
                    true as isHref,
                    1 as sort
        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
            union all
            SELECT
        fffs.id,
                        '系统编号' AS 'key',
                        IFNULL(fffs.CODE,'') AS
                    VALUE,
                    false as isHref,
                    2 as sort

        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
                union all
            SELECT
        fffs.id,
                        '系统类别' AS 'key',
                        IFNULL(wlec.NAME,'') AS
                    VALUE,
                    false as isHref,
                    3 as sort
        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
            union all
            SELECT
        fffs.id,
                        '安装日期' AS 'key',
                        IFNULL(DATE_FORMAT(fffs.install_date,'%Y年%m月%d日'),'') AS
                    VALUE,
                    false as isHref,
                    4 as sort
        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
            union all
            SELECT
        fffs.id,
                        '责任人电话' AS 'key',
                        IFNULL(fffs.charge_person_phone,'')  AS
                    VALUE,
                    false as isHref,
                    5 as sort
        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
            union all
            SELECT
        fffs.id,
                        '维保单位' AS 'key',
                        IFNULL(wlmi.name,'') AS VALUE,
                        false as isHref,
                    6 as sort
        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
                union all
            SELECT
        fffs.id,
                        '施工单位' AS 'key',
                        IFNULL(wlmi1.name,'') AS
                    VALUE,
                    false as isHref,
                    7 as sort
        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit
                union all
            SELECT
        fffs.id,
                        '维保周期' AS 'key',
                        IFNULL(fffs.maintenance_frequency,'') AS
                    VALUE,
                    false as isHref,
                    8 as sort

        FROM
            f_fire_fighting_system fffs
            LEFT JOIN wl_equipment_category wlec ON fffs.system_type = wlec.id
            left join wl_manufacturer_info wlmi on wlmi.id=fffs.maintenance_unit
            left join wl_manufacturer_info wlmi1 on wlmi1.id=fffs.construction_unit) a where a.id=#{id} order by sort
   </select>
    <select id="getEquipmentAlarmBySystemIdOrSourceIdVO"
            resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentAlarmBySystemIdOrSourceIdVO">
        SELECT
            d.id,d.fireEquipmentCode,
            d.equipmentSpecificId,
            d.fireEquipmentName,
            d.warehouseStructureName,
            d.fireEquipmentSpecificIndexName,
            d.createDate,
            d.confirmType,
            d.type,
            d.cleanStatus
        FROM
        (
        SELECT
            wlesal.id,
            wlesal.equipment_specific_id AS equipmentSpecificId,
            IFNULL(wlesal.equipment_specific_code,'') AS fireEquipmentCode,
            (SELECT name from wl_equipment_specific where id = wlesal.equipment_specific_id) AS fireEquipmentName,
            wlesal.equipment_index_id AS fireEquipmentIndexId,
            wlesal.equipment_specific_index_key AS fireEquipmentSpecificIndexKey,
            (
            SELECT
            type_name
            FROM
            wl_signal_classify sc
            WHERE
            sc.type_code = wlesal.type
            LIMIT 1
            ) AS fireEquipmentSpecificIndexName,
            if(wlesal.confirm_type IS NULL, 0, 1) AS confirmType,
            if(wlesal.clean_time IS NULL, 0, 1) AS cleanStatus,
            CASE
            wlesal.equipment_specific_index_value
            WHEN 'true' THEN
            '是'
            WHEN 'false' THEN
            '否' ELSE wlesal.equipment_specific_index_value
            END AS fireEquipmentPointValue,
            wlesa.frequency AS frequency,
            wlesa.STATUS AS STATUS,
            wlesal.type AS type,
            wlesal.create_date AS createDate,
            wlesa.recovery_date AS recoveryDate,
            wlesal.location AS warehouseStructureName,
            (select
            group_concat(fet.`name`)
            from f_equipment_fire_equipment as fefe
            left join f_equipment as fet on fet.id = fefe.equipment_id
            where fefe.fire_equipment_id = wlesal.equipment_specific_id
            ) as equipmentName
        FROM
            wl_equipment_specific_alarm_log wlesal
            LEFT JOIN wl_equipment_specific_alarm wlesa ON wlesa.id = wlesal.equipment_specific_alarm_id
        <where>
            <if test="systemId!=null">
                and 0 <![CDATA[<>]]> find_in_set(#{systemId},wlesal.system_ids)
            </if>
            <if test="sourceId!=null">
                and (wlesal.build_id=#{sourceId}
                or find_in_set(wlesal.equipment_specific_id,(SELECT s.point_in_scene FROM `wl_source_scene` s where s.source_id = #{sourceId})))
            </if>
            <if test='createDate != null and createDate == "1"'>
                AND wlesal.create_date LIKE CONCAT( DATE_FORMAT( NOW( ), '%Y-%m-%d' ), '%' )
            </if>
            <if test='createDate != null and createDate == "7"'>
                AND wlesal.create_date > CONCAT( DATE_ADD( DATE_FORMAT( NOW( ), '%Y-%m-%d ' ), INTERVAL - 7 DAY ), ' 23:59:59' )
            </if>
            <if test='createDate != null and createDate == "30"'>
                 AND wlesal.create_date > CONCAT( DATE_ADD( DATE_FORMAT( NOW( ), '%Y-%m-%d ' ), INTERVAL - 30 DAY ),' 23:59:59' )
            </if>
            <if test='confirmType != null and confirmType == 0'>
                and wlesal.confirm_type IS NULL
            </if>
            <if test='confirmType != null and confirmType == 1'>
                and wlesal.confirm_type IS NOT NULL
            </if>
            <if test='confirmType != null and confirmType == 2'>
                and wlesal.clean_time IS NULL
            </if>
            <if test='confirmType != null and confirmType == 3'>
                and wlesal.clean_time IS NOT NULL
            </if>
            <if test='equipmentId != null'>
                and wlesal.equipment_id=#{equipmentId}
            </if>
        </where>
        ) d
        <where>
            d.fireEquipmentName IS NOT NULL
            <choose>
                <when test="type != null and type != ''">
                    AND d.type = #{type}
                </when>
            </choose>
        </where>
        ORDER BY d.createDate DESC
    </select>
    <select id="getColaCategoryAmountList" resultMap="CategoryAmountList">
        <if test="equipTypeAmountPage.type == 'equipment' or codeHead==null or codeHead=='' or codeHead==' '">
             select * from (
            SELECT
            wles.id,
            wles.qr_code,
            CONCAT('01#',wles.qr_code) fullqrCode,
            wled.standard,
            wle.img,
            wled.NAME equipmentName,
            concat_ws('-',wlws.full_name,wled.area) as full_name,
            wlun.NAME unitName,
            (SELECT GROUP_CONCAT(fem.name) FROM `f_fire_fighting_system` fem WHERE find_in_set(fem.id,wles.system_id))
            as systemName,
            wlsd.amount,
            wlsd.id as stockDetailId,
            'equipment' as type,
            wlai.`name` manufacturerName,
            wles.code,
            wles.iot_code as iotCode,
            case wlsd.`status`
            when '1' then '在位'
            when '2' then '执勤'
            when '3' then '维修'
            when '6' then '退役'
            when '7' then '报废'
            when '10' then '车载'
            when '11' then '损耗'
            when '12' then '配装'
            else '未入库' END as status,
            wles.create_date as createDate,
            wled.code as eqtype,
            wles.biz_org_code as bizOrgCode,
            wles.biz_org_name as bizOrgName
            FROM
            (select id,qr_code,code ,iot_code ,biz_org_code ,team_id,biz_org_name,create_date ,equipment_detail_id ,system_id from wl_equipment_specific) wles
            LEFT JOIN (select id,amount,status,equipment_specific_id,warehouse_structure_id from wl_stock_detail ) wlsd on wlsd.equipment_specific_id = wles.id
            LEFT JOIN wl_warehouse_structure wlws on wlsd.warehouse_structure_id = wlws.id
            LEFT JOIN (select id,standard ,name ,area ,code, equipment_id ,manufacturer_id,is_import from wl_equipment_detail) wled on wles.equipment_detail_id = wled.id
            LEFT JOIN wl_equipment wle ON wle.id = wled.equipment_id
            LEFT JOIN wl_unit wlun ON wle.unit_id = wlun.id
            LEFT JOIN wl_manufacturer_info wlai on wled.manufacturer_id=wlai.id
            LEFT JOIN wl_equipment_category wec ON wle.category_id = wec.id
            WHERE 1=1
            <if test="codeHead!=null and codeHead!='' and codeHead!=' '">
                and LEFT (wle.CODE, #{hierarchy}) = #{codeHead}
            </if>

            <if test="equipTypeAmountPage.isIot!=null">
                and wle.is_iot=1
            </if>

            <if test="equipTypeAmountPage.industryCode!=null">
                and wec.industry_code = #{equipTypeAmountPage.industryCode}
            </if>

            <if test="equipTypeAmountPage.teamId!=null">
                and wles.team_id = #{equipTypeAmountPage.teamId}
            </if>
            <if test="equipTypeAmountPage.systemId!=null">
                and wles.system_id = #{equipTypeAmountPage.systemId}
            </if>
            <if test="equipTypeAmountPage.manufacturerId!=null">
                and wled.manufacturer_id = #{equipTypeAmountPage.manufacturerId}
            </if>
            <if test="equipTypeAmountPage.isImport!=null">
                and wled.is_import = #{equipTypeAmountPage.isImport}
            </if>
            <if test="equipTypeAmountPage.warehouseStructureId!=null">
                and wlsd.warehouse_structure_id in (
                select id from wl_warehouse_structure where parent_id in(
                select id from wl_warehouse_structure where parent_id = #{equipTypeAmountPage.warehouseStructureId})
                union
                select id from wl_warehouse_structure where parent_id = #{equipTypeAmountPage.warehouseStructureId} or
                id = #{equipTypeAmountPage.warehouseStructureId}
                )
            </if>
            <if test="equipTypeAmountPage.status == 1">
                and wlsd.warehouse_structure_id is null
            </if>
            <if test="equipTypeAmountPage.status == 0">
                and wlsd.warehouse_structure_id is not null
            </if>
            <if test="equipTypeAmountPage.equipmentName!=null and equipTypeAmountPage.equipmentName!=''">
                AND wled.name LIKE CONCAT('%',#{equipTypeAmountPage.equipmentName},'%')
            </if>
            <if test="equipTypeAmountPage.code!=null and equipTypeAmountPage.code!=''">
                AND wles.code LIKE CONCAT('%',#{equipTypeAmountPage.code},'%')
            </if>
            <if test="equipTypeAmountPage.iotCode!=null and equipTypeAmountPage.iotCode!=''">
                AND wles.iot_code LIKE CONCAT('%',#{equipTypeAmountPage.iotCode},'%')
            </if>
               )s1  WHERE 1=1
              <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
                  AND   s1.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
            </if>

            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                AND  s1.bizOrgCode LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
            </if>



        </if>
        <if test="(codeHead==null or codeHead=='' or codeHead==' ') and equipTypeAmountPage.status == null and equipTypeAmountPage.warehouseStructureId==null and equipTypeAmountPage.systemId==null">
            union all
        </if>
        <if test="(equipTypeAmountPage.type == 'car' or codeHead==null or codeHead=='' or codeHead==' ') and equipTypeAmountPage.status == null and equipTypeAmountPage.warehouseStructureId==null and equipTypeAmountPage.systemId==null">
             select * from (  SELECT
            wlc.id,
            wlc.qr_code,
            CONCAT('03#',wlc.qr_code) fullqrCode,
            wlc.standard,
            wle.img,
            wlc.`NAME` equipmentName,
            NULL AS full_name,
            wlun.NAME unitName,
            NULL AS systemName,
            1 AS amount,
            '' as stockDetailId,
            'car' as type,
            wlai.`name` manufacturerName,
            wlc.car_num as code,
            wlc.iot_code as iotCode,
            CASE
            wlc.car_state
            WHEN '1' THEN
            '在位'
            WHEN '2' THEN
            '执勤'
            WHEN '3' THEN
            '维修'
            WHEN '6' THEN
            '退役'
            WHEN '7' THEN
            '报废' ELSE '未入库'
            END AS STATUS,
            wlc.create_date as createDate,
            '2' as eqtype,
            wlc.biz_org_code as bizOrgCode,
            wlc.biz_org_name as bizOrgName
            FROM
            wl_car wlc
            LEFT JOIN wl_equipment wle ON wle.id = wlc.equipment_id
            LEFT JOIN wl_unit wlun ON wle.unit_id = wlun.id
            LEFT JOIN wl_manufacturer_info wlai ON wlc.manufacturer_id = wlai.id
            LEFT JOIN wl_equipment_category wec ON wle.category_id = wec.id
            WHERE 1=1
            <if test="codeHead!=null and codeHead!='' and codeHead!=' '">
                and LEFT (wec.CODE, #{hierarchy}) = #{codeHead}
            </if>
            <if test="equipTypeAmountPage.industryCode!=null">
                and wec.industry_code = #{equipTypeAmountPage.industryCode}
            </if>
            <if test="equipTypeAmountPage.isIot!=null">
                and wle.is_iot=1
            </if>
            <if test="equipTypeAmountPage.equipmentName!=null and equipTypeAmountPage.equipmentName!=''">
                And wlc.`NAME` LIKE CONCAT('%',#{equipTypeAmountPage.equipmentName},'%')
            </if>
            <if test="equipTypeAmountPage.manufacturerId!=null">
                and wlc.manufacturer_id = #{equipTypeAmountPage.manufacturerId}
            </if>
            <if test="equipTypeAmountPage.isImport!=null">
                and wlc.is_import = #{equipTypeAmountPage.isImport}
            </if>
            <if test="equipTypeAmountPage.code!=null and equipTypeAmountPage.code!=''">
                AND wlc.car_num LIKE CONCAT('%',#{equipTypeAmountPage.code},'%')
            </if>
            <if test="equipTypeAmountPage.iotCode!=null and equipTypeAmountPage.iotCode!=''">
                AND wlc.iot_code LIKE CONCAT('%',#{equipTypeAmountPage.iotCode},'%')
            </if>
              )s2
              <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
                  AND  s2.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
            </if>
            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                where  s2.bizOrgCode LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
            </if>

        </if>
        order by createDate DESC
    </select>







    <select id="getFireFightingSystemDetail"
            resultType="com.yeejoin.equipmanage.common.datasync.entity.FireFightingSystem">
        SELECT

        fs.id,
        f.`name` AS stationname,
        f.`code` AS stationcode,
        fs.`name`,
        fs.`name` AS aliasname,
        fs.`code`,
        fg.group_name AS systemtype,
        IFNULL(fs.install_date, CURRENT_TIMESTAMP) AS installdate,
        IFNULL(p.`name`,'') AS chargeperson,
        IFNULL(fs.charge_person_phone,'') AS chargepersonphone,
        IFNULL(mi.`name`,'') AS constructionunit,
        mi1.`name` AS maintenanceunit,
        fs.first_maintenance_date AS firstmaintenancedate,
        fs.maintenance_frequency AS maintenancefrequency,
        fs.maintenance_phone AS maintenancephone,
        fs.rec_date AS createdate,
        NOW() AS updatedate,
        fs.`code` AS mrid,
        fs.remark AS description
        FROM
        f_fire_fighting_system fs
        LEFT JOIN wl_dynamic_form_group fg ON fg.relation_id = fs.system_type
        LEFT JOIN wl_manufacturer_info mi ON mi.id = fs.construction_unit
        LEFT JOIN wl_manufacturer_info mi1 ON mi1.id = fs.maintenance_unit
        LEFT JOIN rpm_person p ON p.id = fs.charge_person,
        f_station_info f
        <where>
            <if test="fireFightingSystemVo != null and fireFightingSystemVo.id != null and fireFightingSystemVo.id !=''">
                fs.id = #{fireFightingSystemVo.id}
            </if>
        </where>
    </select>
    <select id="getFightingSysByCodes" resultType="com.yeejoin.equipmanage.common.entity.FireFightingSystemEntity">
        SELECT
        *
        FROM
        `f_fire_fighting_system`a
        <where>
            <if test="ids != null and ids.length > 0">
                a.code IN
                <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="getFightingSysByIds" resultType="com.yeejoin.equipmanage.common.entity.FireFightingSystemEntity">
        SELECT
        *
        FROM
        `f_fire_fighting_system`fffs
        <where>
            <if test="ids != null and ids.length > 0">
                fffs.id IN
                <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="get3dFightingSystemList" resultType="com.yeejoin.equipmanage.common.vo.FireFightingSystem3dVo">
        SELECT
            fs.id,
            fs.`name`,
            fs.code AS mRid,
            fs.core_component_ids,
        IF
            (
                SUM(
                IF
                    (
                        a.equipment_specific_index_value = 'true'
                        <if test="list != null and list.size() >0">
                            AND
                            <foreach collection="list" item="item" index="index" open="(" close=")" separator=" OR ">
                                ei.type_code = #{item}
                            </foreach>
                        </if>
                        ,
                        1,
                        0
                    )
                ) > 0,
                0,
                1
            ) AS `status`,
            fs.charge_person_phone,
            fs.charge_person_name
        FROM
            f_fire_fighting_system fs
            LEFT JOIN wl_equipment_specific es ON FIND_IN_SET( fs.id, es.system_id )
            LEFT JOIN wl_equipment_specific_index esi ON esi.equipment_specific_id = es.id
            LEFT JOIN wl_equipment_index ei ON ei.id = esi.equipment_index_id
            LEFT JOIN wl_equipment_specific_alarm a ON a.equipment_specific_id = es.id
        GROUP BY
            fs.id;
    </select>

    <select id="getFireSystemState" resultType="Map">
    	select * from v_fire_system_state
    </select>

    <select id="getFireOnlSystem" resultType="Map">
    	select * from v_fire_onl_num
    </select>

	 <select id="getFireCafsSystem" resultType="Map">
    	select * from v_fire_cafs_num
    </select>

	 <select id="getFireFfsSystem" resultType="Map">
    	select * from v_fire_ffs_num
    </select>


	 <select id="getFireFasSystem" resultType="Map">
    	select * from v_fire_fas_num
    </select>


	 <select id="getFireAcsSystem" resultType="Map">
    	select * from v_fire_acs_num
    </select>

	 <select id="getFireFhsSystem" resultType="Map">
    	select * from v_fire_fhs_num
    </select>

    <select id="getTodayConfirmAlarmInfo" resultType="Map">
    	select * from v_equip_alarm_today_statistics
    </select>

    <select id="getPoolInfo" resultType="Map">
    	select * from v_fire_fhs_yl_num
    </select>

    <select id="getFightingSysInfo" resultType="com.yeejoin.equipmanage.common.vo.FireFightingSystemVo">
    	select * from v_fire_system_info fs
    	<where>
    		<if test="id != null and id !=''">
              and fs.id = #{id}
            </if>
            <if test="code != null and code !=''">
              and fs.code = #{code}
            </if>
    	</where>
    </select>

    <select id="getFireOnlSystemThreeSmall" resultType="Map">
     		select * from v_fire_onl_three_small
	</select>
    <select id="fireAlarmSysEquipmentNumber" resultType="java.util.Map">
        select
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key  = 'FAS_SmokeAlarm_FireAlarm') as ywtcqnum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_SoundLightAlarm_FireAlarm') as sgbjqnum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_InfraredLight_FireAlarm') as hwdsnum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_ManualAlarm_FireAlarm') as sdbjanum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_TemperatureCable_FireAlarm') as gwdlnum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_TemperatureFireDetector_FireAlarm') as fbwgnum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_AirSampler_FireAlarm') as kqcynum,
	        (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_UltravioletLight_FireAlarm') as zwhynum,
	        (
                SELECT
                    count(1)
                FROM
                    `wl_equipment_specific_index` si
                WHERE
                    si.equipment_index_key = 'SCS_FireDamper_FireAlarm'
		    ) AS fhznum,
		    (SELECT
	            count(1)
	        from
	        `wl_equipment_specific_index` si
	        where
	        si.equipment_index_key = 'FAS_VESDA_SignalMAction') as vesdanum
	    </select>
    <select id="fireAlarmSysIndexNumber" resultType="java.util.Map">
        SELECT * FROM v_fire_fas_index_num
    </select>
    <select id="fireWaterSysHydrant" resultType="java.util.Map">
        SELECT
			xhsanhj,
			xhsangz,
			xhsanpb,
			(xhszc - noZcTotal) AS xhszc,
			xhsan
		FROM
			(
				SELECT
					(
						SELECT
							count(1)
						FROM
							`wl_equipment_specific_index` s
						WHERE
							s.equipment_index_key = 'FAS_FireHydrantButton_FireAlarm'
						AND s.`value` = 'true'
					) AS xhsanhj,
					(
						SELECT
							count(1)
						FROM
							`wl_equipment_specific_index` s
						WHERE
							s.equipment_index_key = 'FAS_FireHydrantButton_Fault'
						AND s.`value` = 'true'
					) AS xhsangz,
					(
						SELECT
							count(1)
						FROM
							`wl_equipment_specific_index` s
						WHERE
							s.equipment_index_key = 'FAS_FireHydrantButton_Shield'
						AND s.`value` = 'true'
					) AS xhsanpb,
					(
						SELECT
							count(1)
						FROM
							`wl_equipment_specific_index` si
						WHERE
							si.equipment_index_key = 'FAS_FireHydrantButton_FireAlarm'
					) AS xhsan,
					(
						SELECT
							count(
								DISTINCT equipment_specific_id
							)
						FROM
							`wl_equipment_specific_index` s
						WHERE
							(
								s.`value` = 'false'
								OR s.`value` IS NULL
							)
						AND (
							s.equipment_index_key = 'FAS_FireHydrantButton_FireAlarm'
							OR s.equipment_index_key = 'FAS_FireHydrantButton_Fault'
							OR s.equipment_index_key = 'FAS_FireHydrantButton_Shield'
						)
					) AS xhszc,
					(
						SELECT
							count(
								DISTINCT equipment_specific_id
							)
						FROM
							`wl_equipment_specific_index` s
						WHERE
							(
								s.`value` = 'true'
							)
						AND (
							s.equipment_index_key = 'FAS_FireHydrantButton_FireAlarm'
							OR s.equipment_index_key = 'FAS_FireHydrantButton_Fault'
							OR s.equipment_index_key = 'FAS_FireHydrantButton_Shield'
						)
					) AS noZcTotal
			) AS hydrant
    </select>
    <select id="fireWaterSysCollectingDevice" resultType="java.util.Map">
        SELECT
            sbfcjzzyc,
            sbfcjzzbs,
            ( sbfcjzzzc - noZcTotal ) AS sbfcjzzzc,
            sbfcjzz
        FROM
            (
            SELECT
                ( SELECT count( 1 ) FROM `wl_equipment_specific_index` s WHERE s.equipment_index_key = 'FHS_CollectingDevice_DeviceAbnormal' AND s.`value` = 'true' ) AS sbfcjzzyc,
                ( SELECT count( 1 ) FROM `wl_equipment_specific_index` s WHERE s.equipment_index_key = 'FHS_CollectingDevice_DeviceLock' AND s.`value` = 'true' ) AS sbfcjzzbs,
                (
                SELECT
                    count( DISTINCT equipment_specific_id )
                FROM
                    `wl_equipment_specific_index` s
                WHERE
                    ( s.`value` = 'false' OR s.`value` IS NULL )
                    AND ( s.equipment_index_key = 'FHS_CollectingDevice_DeviceAbnormal' )
                ) AS sbfcjzz,
                (
                SELECT
                    count( DISTINCT equipment_specific_id )
                FROM
                    `wl_equipment_specific_index` s
                WHERE
                    ( s.`value` = 'false' OR s.`value` IS NULL )
                    AND s.equipment_index_key = 'FHS_CollectingDevice_DeviceAbnormal'
                ) AS sbfcjzzzc,
            ( SELECT count( DISTINCT equipment_specific_id ) FROM `wl_equipment_specific_index` s WHERE ( s.`value` = 'true' ) AND s.equipment_index_key = 'FHS_CollectingDevice_DeviceAbnormal' ) AS noZcTotal
            ) AS collectingDevice
    </select>
    <select id="fireWaterSysWaterPump" resultType="java.util.Map">
         select
        -- 总数
        (SELECT
            count(1)
        from
        `wl_equipment_specific_index` si
        where
        si.equipment_index_key  = 'FHS_FirePump_RunStatus') as xfsbzs,
        -- 消防水泵指标
        (SELECT
            count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_FirePump_RunStatus'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as xfsbjt,
        (SELECT
            count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_FirePump_Stop'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as xfsbqd,
        (SELECT
            count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_FirePump_RunShield'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as xfsbpb,
        (SELECT
             count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_FirePump_Fault'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as xfsbgz,
        -- 稳压泵
        -- 总数
        (SELECT
            count(1)
        from
        `wl_equipment_specific_index` si
        where
        si.equipment_index_key  = 'FHS_PressurePump_RunStatus') as wybzs,
        -- 稳压泵指标
        (SELECT
            count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_PressurePump_RunStatus'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as wybjt,
        (SELECT
             count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_PressurePump_Stop'
				and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as wybqd,
        (SELECT
             count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_PressurePump_Fault'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as wybgz,
        (SELECT
            count(1)
        FROM
        `wl_equipment_specific_index` si,
        `wl_equipment_specific` s
        where
        si.equipment_index_key = 'FHS_PressurePump_RunShield'
        and si.`value` = 'true'
        and si.equipment_specific_id = s.id ) as wybpb
    </select>
    <select id="fireWaterSysPool" resultType="java.util.Map">
        select * from v_fire_pool_water_level
    </select>

    <select id="fireWaterSysPipeNetwork" resultType="java.util.Map">
        SELECT
	        IFNULL(MAX(wesi.`value`), 0) AS xfgwyl
        FROM
            wl_equipment_specific_index wesi
            LEFT JOIN wl_equipment_specific wes ON wes.id = wesi.equipment_specific_id
        WHERE
            wes.equipment_code = '92011000T5Q44'
            AND wesi.equipment_index_key = 'FHS_PipePressureDetector_PipePressure'
        ORDER BY
            abs( wesi.`value` ) DESC
	        LIMIT 1
    </select>

    <select id="fireWaterSysPipeStatus" resultType="java.util.Map">
        SELECT
         esi.`value`,
        esi.equipment_index_key
        FROM
            `wl_equipment_specific_index` esi
        LEFT JOIN wl_equipment_specific es ON es.id = esi.equipment_specific_id
        WHERE
            -- 此处为水喷雾系统code，水系统实现消息实时刷新
            es.`code` = "011023306003020000010509"
    </select>

    <select id="fireFoamSysEquipmentIndexNumber" resultType="java.util.Map">
        select * from v_fire_equip_ffs_num
    </select>
    <select id="otherSysIndexNumAndTotal" resultType="java.util.Map">
         SELECT
				`d`.`sffjnum` AS `sffjnum`,
				`d`.`sffjqd` AS `sffjqd`,
				`d`.`sffjgz` AS `sffjgz`,
				`d`.`sffjpb` AS `sffjpb`,
				`d`.`pffjnum` AS `pffjnum`,
				`d`.`pffjqd` AS `pffjqd`,
				`d`.`pffjgz` AS `pffjgz`,
				`d`.`pffjpb` AS `pffjpb`,
				`d`.`dtnum` AS `dtnum`,
				`d`.`dtqd` AS `dtqd`,
				`d`.`dtgz` AS `dtgz`,
				`d`.`dtpb` AS `dtpb`,
				`d`.`ktnum` AS `ktnum`,
				`d`.`ktqd` AS `ktqd`,
				`d`.`ktgz` AS `ktgz`,
				`d`.`ktpb` AS `ktpb`,
				`d`.`ntnum` AS `ntnum`,
				`d`.`ntqd` AS `ntqd`,
				`d`.`ntgz` AS `ntgz`,
				`d`.`ntpb` AS `ntpb`,
				`d`.`mjnum` AS `mjnum`,
				`d`.`mjqd` AS `mjqd`,
				`d`.`mjgz` AS `mjgz`,
				`d`.`mjpb` AS `mjpb`,
				`d`.fhzpb AS fhzpb,
				`d`.fhzgz AS fhzgz,
				`d`.fhzhj AS fhzhj
			FROM
				(
					SELECT
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_Blower_Start'
						) AS `sffjnum`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_Blower_Start'
			                and si.`value` = 'true'
						) AS `sffjqd`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_Blower_Fault'
			            and si.`value` = 'true'
						) AS `sffjgz`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_Blower_Shield'
						) AS `sffjpb`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_SmokeExhaust_Start'
						) AS `pffjnum`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_SmokeExhaust_Start'
			                and si.`value` = 'true'
						) AS `pffjqd`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_SmokeExhaust_Fault'
			                and si.`value` = 'true'
						) AS `pffjgz`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'SCS_SmokeExhaust_Shield'
			                and si.`value` = 'true'
						) AS `pffjpb`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ES_Elevator_Start'
						) AS `dtnum`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ES_Elevator_Start'
							and si.`value` = 'true'
						) AS `dtqd`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ES_Elevator_Fault'
							and si.`value` = 'true'
						) AS `dtgz`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ES_Elevator_Shield'
							and si.`value` = 'true'

						) AS `dtpb`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_AirCondition_Start'
						) AS `ktnum`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_AirCondition_Start'
							and si.`value` = 'true'
						) AS `ktqd`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_AirCondition_Fault'
							and si.`value` = 'true'
						) AS `ktgz`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_AirCondition_Shield'
							and si.`value` = 'true'
						) AS `ktpb`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_HVAC_Start'
						) AS `ntnum`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_HVAC_Start'
							and si.`value` = 'true'
						) AS `ntqd`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_HVAC_Fault'
							and si.`value` = 'true'
						) AS `ntgz`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'AIRCS_HVAC_Shield'
							and si.`value` = 'true'
						) AS `ntpb`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ACS_AccessControl_Start'
						) AS `mjnum`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ACS_AccessControl_Start'
							and si.`value` = 'true'
						) AS `mjqd`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ACS_AccessControl_Fault'
							and si.`value` = 'true'
						) AS `mjgz`,
						(
							select
								count(1)
							from
							`wl_equipment_specific_index` si
							where
							si.equipment_index_key  = 'ACS_AccessControl_Shield'
							and si.`value` = 'true'
						) AS `mjpb`,
						(
                            SELECT
                                count(1)
                            FROM
                                `wl_equipment_specific_index` s
                            WHERE
                                s.equipment_index_key = 'SCS_FireDamper_Shield'
                            AND s.`value` = 'true'
                        ) AS fhzpb,
                        (
                            SELECT
                                count(1)
                            FROM
                                `wl_equipment_specific_index` s
                            WHERE
                                s.equipment_index_key = 'SCS_FireDamper_Fault'
                            AND s.`value` = 'true'
                        ) AS fhzgz,
                        (
                            SELECT
                                count(1)
                            FROM
                                `wl_equipment_specific_index` s
                            WHERE
                                s.equipment_index_key = 'SCS_FireDamper_FireAlarm'
                            AND s.`value` = 'true'
                        ) AS fhzhj
				) `d`
     </select>
    <select id="fireFoamSysEquipmentNumber" resultType="java.util.Map">
        SELECT
            d.dcfzs,
            d.dcfqd,
            d.dcfgz,
            d.dcfpb,
            d.qdpzs,
            d.qdpqd,
            d.qdpgz,
            d.qdppb,
            d.dlqzs,
            d.dlqqd,
            ABS (d.dlqzs - d.dlqqd) AS dlqjt,
            d.dlqgz,
            d.dlqpb
        FROM
        (

            SELECT
                (
                    SELECT
                 count(1)
                    FROM
                wl_equipment_specific_index si
              WHERE
                        si.equipment_index_key  = 'FFS_SolenoidValve_Start'
                ) AS dcfzs,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_SolenoidValve_Start'
              AND s.`value` = 'true'
                ) AS dcfqd,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_SolenoidValve_Fault'
              AND s.`value` = 'true'
                ) AS dcfgz,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_SolenoidValve_Shield'
              AND s.`value` = 'true'
                ) AS dcfpb,
                (
                    SELECT
                 count(1)
                    FROM
                wl_equipment_specific_index si
              WHERE
                        si.equipment_index_key  = 'FFS_Startbottle_Start'
                ) AS qdpzs,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_Startbottle_Start'
              AND s.`value` = 'true'
                ) AS qdpqd,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_Startbottle_StartupModuleFault'
              AND s.`value` = 'true'
                ) AS qdpgz,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_Startbottle_StartupModuleShield'
              AND s.`value` = 'true'
                ) AS qdppb,
                (
                    SELECT
                 count(1)
                    FROM
                wl_equipment_specific_index si
              WHERE
                        si.equipment_index_key  = 'FFS_Breaker_State'
                ) AS dlqzs,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_Breaker_State'
              AND s.`value` = 'true'
                ) AS dlqqd,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_Breaker_Fault'
              AND s.`value` = 'true'
                ) AS dlqgz,
                (
                    SELECT
                count(1)
              FROM
                        wl_equipment_specific_index s
              WHERE
                        s.equipment_index_key = 'FFS_Breaker_Shield'
              AND s.`value` = 'true'
                ) AS dlqpb

        )d
    </select>





    <select id="getColaCategoryAmountCarList" resultMap="CategoryAmountList">
        select * from (  SELECT
        wlc.id,
        wlc.qr_code,
        CONCAT('03#',wlc.qr_code) fullqrCode,
        wlc.standard,
        wle.img,
        wlc.`NAME` equipmentName,
        wec.name as systemType,
        NULL AS full_name,
        wlun.NAME unitName,
        NULL AS systemName,
        1 AS amount,
        '' as stockDetailId,
        'car' as type,
        wlai.`name` manufacturerName,
        wlc.car_num as code,
        wlc.iot_code as iotCode,
        wlc.car_num as carNum,
        CASE
        wlc.car_state
        WHEN '1' THEN
        '在位'
        WHEN '2' THEN
        '执勤'
        WHEN '3' THEN
        '维修'
        WHEN '6' THEN
        '退役'
        WHEN '7' THEN
        '报废' ELSE '未入库'
        END AS STATUS,
        wlc.create_date as createDate,
        '2' as eqtype,
        wlc.biz_org_code as bizOrgCode,
        wlc.biz_org_name as bizOrgName,
        wlc.longitude,
        wlc.equip_status as equipStatus,
        wlc.latitude
        FROM
        wl_car wlc
        LEFT JOIN wl_equipment wle ON wle.id = wlc.equipment_id
        LEFT JOIN wl_unit wlun ON wle.unit_id = wlun.id
        LEFT JOIN wl_manufacturer_info wlai ON wlc.manufacturer_id = wlai.id
        LEFT JOIN wl_equipment_category wec ON wle.category_id = wec.id
        WHERE 1=1
        <if test="codeHead!=null and codeHead!='' and codeHead!=' '">
            and LEFT (wec.CODE, #{hierarchy}) = #{codeHead}
        </if>
        <if test="equipTypeAmountPage.industryCode!=null">
            and wec.industry_code = #{equipTypeAmountPage.industryCode}
        </if>
        <if test="equipTypeAmountPage.teamId!=null">
            and wlc.team_id = #{equipTypeAmountPage.teamId}
        </if>
        <if test="equipTypeAmountPage.equipmentName!=null and equipTypeAmountPage.equipmentName!=''">
            And wlc.`NAME` LIKE CONCAT('%',#{equipTypeAmountPage.equipmentName},'%')
        </if>
        <if test="equipTypeAmountPage.manufacturerId!=null">
            and wlc.manufacturer_id = #{equipTypeAmountPage.manufacturerId}
        </if>
        <if test="equipTypeAmountPage.isImport!=null">
            and wlc.is_import = #{equipTypeAmountPage.isImport}
        </if>
        <if test="equipTypeAmountPage.code!=null and equipTypeAmountPage.code!=''">
            AND wlc.car_num LIKE CONCAT('%',#{equipTypeAmountPage.code},'%')
        </if>
        <if test="equipTypeAmountPage.iotCode!=null and equipTypeAmountPage.iotCode!=''">
            AND wlc.iot_code LIKE CONCAT('%',#{equipTypeAmountPage.iotCode},'%')
        </if>
        <if test="equipTypeAmountPage.carNum!=null and equipTypeAmountPage.carNum!=''">
            And wlc.car_num LIKE CONCAT('%',#{equipTypeAmountPage.carNum},'%')
        </if>
        <if test="equipTypeAmountPage.equipStatus!=null and equipTypeAmountPage.equipStatus!=''">
            And wlc.equip_status = #{equipTypeAmountPage.equipStatus}
        </if>
        <if test="equipTypeAmountPage.keyword!=null and equipTypeAmountPage.keyword!=''">
            And (wlc.`NAME` LIKE CONCAT('%',#{equipTypeAmountPage.keyword},'%') OR wlc.car_num LIKE CONCAT('%',#{equipTypeAmountPage.keyword},'%'))
        </if>
        )s2
        <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
            where  s2.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
        </if>
        <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
            where  s2.bizOrgCode LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
        </if>
        order by createDate DESC

    </select>






    <select id="getColaCategoryAmountEquList" resultMap="CategoryAmountList">
            select * from (
            SELECT
            wles.id,
            wles.qr_code,
            CONCAT('01#',wles.qr_code) fullqrCode,
            wled.standard,
            wle.img,
            wles.name equipmentName,
            wec.name as systemType,
            concat_ws('-',wlws.full_name,wled.area) as full_name,
            wlws.name as belongBuildName,
            wlun.NAME unitName,
            (SELECT GROUP_CONCAT(fem.name) FROM `f_fire_fighting_system` fem WHERE find_in_set(fem.id,wles.system_id))
            as systemName,
            wlsd.amount,
            wlsd.id as stockDetailId,
            'equipment' as type,
            wlai.`name` manufacturerName,
            wles.code,
            wles.iot_code as iotCode,
            case wlsd.`status`
            when '1' then '在位'
            when '2' then '执勤'
            when '3' then '维修'
            when '6' then '退役'
            when '7' then '报废'
            when '10' then '车载'
            when '11' then '损耗'
            when '12' then '配装'
            else '未入库' END as status,
            wles.create_date as createDate,
            wled.code as eqtype,
            wles.biz_org_code as bizOrgCode,
            wles.biz_org_name as bizOrgName,
            wles.equip_status as equipStatus
            FROM
            (select id,name,qr_code,code ,iot_code ,biz_org_code,team_id ,biz_org_name,create_date ,equipment_detail_id ,system_id,equip_status from wl_equipment_specific) wles
            LEFT JOIN (select id,amount,status,equipment_specific_id,warehouse_structure_id from wl_stock_detail ) wlsd on wlsd.equipment_specific_id = wles.id
            LEFT JOIN wl_warehouse_structure wlws on wlsd.warehouse_structure_id = wlws.id
            LEFT JOIN (select id,standard ,name ,area ,code, equipment_id ,manufacturer_id,is_import from wl_equipment_detail) wled on wles.equipment_detail_id = wled.id
            LEFT JOIN wl_equipment wle ON wle.id = wled.equipment_id
            LEFT JOIN wl_unit wlun ON wle.unit_id = wlun.id
            LEFT JOIN wl_manufacturer_info wlai on wled.manufacturer_id=wlai.id
            LEFT JOIN wl_equipment_category wec ON wle.category_id = wec.id
            WHERE 1=1
            <if test="codeHead!=null and codeHead!='' and codeHead!=' '">
                and wec.`code` like concat(LEFT(#{codeHead}, #{hierarchy}), '%')
            </if>
            <if test="equipTypeAmountPage.industryCode!=null">
                and wec.industry_code = #{equipTypeAmountPage.industryCode}
            </if>
            <if test="equipTypeAmountPage.teamId!=null">
                and wles.team_id = #{equipTypeAmountPage.teamId}
            </if>
            <if test="equipTypeAmountPage.systemId!=null">
                and wles.system_id = #{equipTypeAmountPage.systemId}
            </if>
            <if test="equipTypeAmountPage.manufacturerId!=null">
                and wled.manufacturer_id = #{equipTypeAmountPage.manufacturerId}
            </if>
            <if test="equipTypeAmountPage.isImport!=null">
                and wled.is_import = #{equipTypeAmountPage.isImport}
            </if>
            <if test="equipTypeAmountPage.warehouseStructureId!=null">
                and wlsd.warehouse_structure_id in (
                select id from wl_warehouse_structure where parent_id in(
                select id from wl_warehouse_structure where parent_id = #{equipTypeAmountPage.warehouseStructureId})
                union
                select id from wl_warehouse_structure where parent_id = #{equipTypeAmountPage.warehouseStructureId} or
                id = #{equipTypeAmountPage.warehouseStructureId}
                )
            </if>
            <if test="equipTypeAmountPage.status == 1">
                and wlsd.warehouse_structure_id is null
            </if>
            <if test="equipTypeAmountPage.isIot!=null">
                and wle.is_iot=#{equipTypeAmountPage.isIot}
            </if>
            <if test="equipTypeAmountPage.status == 0">
                and wlsd.warehouse_structure_id is not null
            </if>
            <if test="equipTypeAmountPage.equipStatus!=null and equipTypeAmountPage.equipStatus!=''">
                and wles.equip_status = #{equipTypeAmountPage.equipStatus}
            </if>
            <if test="equipTypeAmountPage.equipmentName!=null and equipTypeAmountPage.equipmentName!=''">
                AND wled.name LIKE CONCAT('%',#{equipTypeAmountPage.equipmentName},'%')
            </if>
            <if test="equipTypeAmountPage.nameOrCode!=null and equipTypeAmountPage.nameOrCode!=''">
                AND (wled.name LIKE CONCAT('%',#{equipTypeAmountPage.nameOrCode},'%') or wles.code LIKE CONCAT('%',#{equipTypeAmountPage.nameOrCode},'%'))
            </if>
            <if test="equipTypeAmountPage.code!=null and equipTypeAmountPage.code!=''">
                AND wles.code LIKE CONCAT('%',#{equipTypeAmountPage.code},'%')
            </if>
            <if test="equipTypeAmountPage.iotCode!=null and equipTypeAmountPage.iotCode!=''">
                AND wles.iot_code LIKE CONCAT('%',#{equipTypeAmountPage.iotCode},'%')
            </if>
            )s1  WHERE 1=1
            <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
                AND  s1.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
            </if>

            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                AND  s1.bizOrgCode LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
            </if>
        order by  CONVERT(bizOrgName USING gbk) ASC, equipStatus DESC ,createDate DESC
    </select>

    <select id="listByBizOrgCode" resultType="java.util.Map">
        SELECT
            form_group_id typeId,
            COUNT(form_group_id) total
        FROM
            f_fire_fighting_system
        WHERE
            biz_org_code LIKE CONCAT(#{bizOrgCode}, '%' )
         GROUP BY 	form_group_id
    </select>



    <select id="getColaCategoryAmountListIot" resultMap="CategoryAmountList">
        <if test="equipTypeAmountPage.type == 'equipment' or codeHead==null or codeHead=='' or codeHead==' '">
            select * from (
            SELECT
            wles.id,
            wles.qr_code,
            CONCAT('01#',wles.qr_code) fullqrCode,
            wled.standard,
            wle.img,
            wled.NAME equipmentName,
            concat_ws('-',wlws.full_name,wled.area) as full_name,
            wlun.NAME unitName,
            (SELECT GROUP_CONCAT(fem.name) FROM `f_fire_fighting_system` fem WHERE find_in_set(fem.id,wles.system_id))
            as systemName,
            wlsd.amount,
            wlsd.id as stockDetailId,
            'equipment' as type,
            wlai.`name` manufacturerName,
            wles.code,
            wles.iot_code as iotCode,
            case wlsd.`status`
            when '1' then '在位'
            when '2' then '执勤'
            when '3' then '维修'
            when '6' then '退役'
            when '7' then '报废'
            when '10' then '车载'
            when '11' then '损耗'
            when '12' then '配装'
            else '未入库' END as status,
            wles.create_date as createDate,
            wled.code as eqtype,
            wles.biz_org_code as bizOrgCode,
            wles.biz_org_name as bizOrgName,
            wles.equip_status as equipStatus
            FROM
            (select id,qr_code,code ,iot_code ,biz_org_code ,team_id,biz_org_name,create_date ,equipment_detail_id ,system_id ,equip_status from wl_equipment_specific) wles
            LEFT JOIN (select id,amount,status,equipment_specific_id,warehouse_structure_id from wl_stock_detail ) wlsd on wlsd.equipment_specific_id = wles.id
            LEFT JOIN wl_warehouse_structure wlws on wlsd.warehouse_structure_id = wlws.id
            LEFT JOIN (select id,standard ,name ,area ,code, equipment_id ,manufacturer_id,is_import from wl_equipment_detail) wled on wles.equipment_detail_id = wled.id
            LEFT JOIN wl_equipment wle ON wle.id = wled.equipment_id
            LEFT JOIN wl_unit wlun ON wle.unit_id = wlun.id
            LEFT JOIN wl_manufacturer_info wlai on wled.manufacturer_id=wlai.id
            LEFT JOIN wl_equipment_category wec ON wle.category_id = wec.id
            WHERE 1=1
            <if test="codeHead!=null and codeHead!='' and codeHead!=' '">
                and LEFT (wle.CODE, #{hierarchy}) = #{codeHead}
            </if>

            <if test="equipTypeAmountPage.isIot!=null">
                and wle.is_iot=1
            </if>

            <if test="equipTypeAmountPage.industryCode!=null">
                and wec.industry_code = #{equipTypeAmountPage.industryCode}
            </if>

            <if test="equipTypeAmountPage.teamId!=null">
                and wles.team_id = #{equipTypeAmountPage.teamId}
            </if>
            <if test="equipTypeAmountPage.systemId!=null">
                and wles.system_id = #{equipTypeAmountPage.systemId}
            </if>
            <if test="equipTypeAmountPage.manufacturerId!=null">
                and wled.manufacturer_id = #{equipTypeAmountPage.manufacturerId}
            </if>
            <if test="equipTypeAmountPage.isImport!=null">
                and wled.is_import = #{equipTypeAmountPage.isImport}
            </if>
            <if test="equipTypeAmountPage.warehouseStructureId!=null">
                and wlsd.warehouse_structure_id in (
                select id from wl_warehouse_structure where parent_id in(
                select id from wl_warehouse_structure where parent_id = #{equipTypeAmountPage.warehouseStructureId})
                union
                select id from wl_warehouse_structure where parent_id = #{equipTypeAmountPage.warehouseStructureId} or
                id = #{equipTypeAmountPage.warehouseStructureId}
                )
            </if>
            <if test="equipTypeAmountPage.status == 1">
                and wlsd.warehouse_structure_id is null
            </if>
            <if test="equipTypeAmountPage.status == 0">
                and wlsd.warehouse_structure_id is not null
            </if>
            <if test="equipTypeAmountPage.equipmentName!=null and equipTypeAmountPage.equipmentName!=''">
                AND wled.name LIKE CONCAT('%',#{equipTypeAmountPage.equipmentName},'%')
            </if>
            <if test="equipTypeAmountPage.code!=null and equipTypeAmountPage.code!=''">
                AND wles.code LIKE CONCAT('%',#{equipTypeAmountPage.code},'%')
            </if>
            <if test="equipTypeAmountPage.iotCode!=null and equipTypeAmountPage.iotCode!=''">
                AND wles.iot_code LIKE CONCAT('%',#{equipTypeAmountPage.iotCode},'%')
            </if>
            )s1 WHERE 1=1
            <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
                and  s1.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
            </if>

            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                and  s1.bizOrgCode LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
            </if>



        </if>
         order by createDate DESC
    </select>

    <select id="getSystemAlarmInfo" resultType="java.util.Map">
        SELECT
			`fs`.`id` AS `id`,
			`fs`.`name` AS `name`,
			`fs`.`code`,
			(
				SELECT
					count(1)
				FROM
					`wl_equipment_specific` `wes`
                LEFT JOIN wl_equipment_detail wed on wed.id = wes.equipment_detail_id
                LEFT JOIN wl_equipment e ON wed.`equipment_id` = e.`id`
                WHERE
                    e.is_iot = 1
                    and
                    0 != find_in_set(
						`fs`.`id`,
						`wes`.`system_id`
					)
			) AS `totalEquipNum`,
			(
				SELECT
					count(
						DISTINCT `eqlog`.`equipment_specific_id`
					)
				FROM
					`wl_equipment_specific_alarm` `eqlog`
				WHERE
					(
						(
							0 != find_in_set(
								`fs`.`id`,
								`eqlog`.`system_ids`
							)
						)
						AND (
							`eqlog`.`create_date` LIKE concat(
								date_format(curdate(), '%Y-%m-%d'),
								'%'
							)
						)
					)
			) AS `todayAlarmNum`,

		IF (
			(
				(
					SELECT
						count(
							`esa`.`equipment_specific_id`
						)
					FROM
						`wl_equipment_specific_alarm` `esa`
					WHERE
						(
							(
								0 != find_in_set(
									`fs`.`id`,
									`esa`.`system_ids`
								)
							)
							AND (`esa`.`status` = 1)
						)
				) > 0
			),
			'异常',
			'正常'
		) AS `stateDesc`,
		 IFNULL(ec.image, "") AS image
		FROM
			`f_fire_fighting_system` `fs`
		LEFT JOIN wl_equipment_category ec ON ec.id = fs.system_type
            <where>
                <if test="bizOrgCode!=null and bizOrgCode!=''">
                    and fs.biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
        ORDER BY stateDesc, `fs`.`id`
    </select>

    <select id="getEquipAlarmInfoNum" resultType="java.util.Map">
        SELECT
            (
                SELECT
                    count( log.id )
                FROM
                    `wl_equipment_specific_alarm_log` log
                        LEFT JOIN wl_equipment_specific es ON log.equipment_specific_id = es.id
        <where>
            log.`status` = 1
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                and es.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
            <if test="systemCode!=null and systemCode!=''">
                and FIND_IN_SET( #{systemCode,jdbcType=VARCHAR}, log.system_codes )
            </if>
        </where>
            ) AS unclearInfoNum,
            (
                SELECT
                    count( log.id )
                FROM
                    `wl_equipment_specific_alarm_log` log
                        LEFT JOIN wl_equipment_specific es ON log.equipment_specific_id = es.id
        <where>
            log.`confirm_date` IS NULL
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                and es.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
            <if test="systemCode!=null and systemCode!=''">
                and FIND_IN_SET( #{systemCode,jdbcType=VARCHAR}, log.system_codes )
            </if>
        </where>
            ) AS unConfirmInfoNum
    </select>


    <select id="getStationBizOrgCode" resultType="java.util.Map">
        select
            org.biz_org_name as bizOrgName,
            org.biz_org_code as bizOrgCode,
            org.sequence_nbr as id
        from cb_org_usr org
                 right JOIN idx_biz_station_info ibi on ibi.code = org.code
        where
            org.is_delete = 0 and org.biz_org_type = 'COMPANY'

    </select>

    <select id="getFireTeamInfoBy117" resultType="java.util.Map">
        SELECT
            ifnull( count( 0 ), 0 ) AS `total`,
            ifnull( sum(( SELECT count( 0 ) FROM `d_duty_details` `duty` WHERE ( `duty`.`user_id` = `cou`.`amos_org_id` and duty.duty_date like concat(DATE_FORMAT(NOW(),'%Y-%m-%d'), '%') ))), 0 ) AS `on_duty`,
            '志愿消防队' as typeName
        FROM
            ( SELECT * FROM `cb_org_usr` WHERE `cb_org_usr`.`is_firefighters` = 1 AND `cb_org_usr`.`type_code` = 117
                <if test="bizOrgCode!=null and bizOrgCode!=''">
                    AND biz_org_code like concat(#{bizOrgCode}, '%')
                </if> ) `cou`
    </select>

    <select id="getFireTeamInfoBy116" resultType="java.util.Map">
        SELECT
        ifnull( count( 0 ), 0 ) AS `total`,
        ifnull( sum(( SELECT count( 0 ) FROM `d_duty_details` `duty` WHERE ( `duty`.`user_id` = `cou`.`amos_org_id` and duty.duty_date like concat(DATE_FORMAT(NOW(),'%Y-%m-%d'), '%') ))), 0 ) AS `on_duty`,
        '专职驻站消防队' as typeName
        FROM
        ( SELECT * FROM `cb_org_usr` WHERE `cb_org_usr`.`is_firefighters` = 1 AND `cb_org_usr`.`type_code` = 116
        <if test="bizOrgCode!=null and bizOrgCode!=''">
            AND biz_org_code like concat(#{bizOrgCode}, '%')
        </if> ) `cou`
    </select>

    <select id="getFireCarInfo" resultType="java.util.Map">
        SELECT
        COUNT( 1 ) AS total,
        IFNULL( sum( a.carStartState ), 0 ) AS carStartNum,
        IFNULL( sum( a.carCloseState ), 0 ) AS carCloseNum
        FROM
        (
        SELECT
        `wc`.`id` AS `id`,
        `wc`.`name` AS `name`,
        max(
        CASE

        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'true' ) THEN
        1
        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'false' ) THEN
        0
        END
        ) AS `carStartState`,
        max(
        CASE

        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'true' ) THEN
        0
        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'false' ) THEN
        1
        END
        ) AS `carCloseState`
        FROM
        `wl_car` `wc`
        LEFT JOIN `wl_car_property` `wcp` ON `wcp`.`car_id` = `wc`.`id`
        <where>
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                wc.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
        GROUP BY
        wc.id
        ) a
    </select>

    <select id="getFireCarInfoByWL" resultType="java.util.Map">
        SELECT
        a.*
        FROM
        (
        SELECT
        `wc`.`id` AS `id`,
        `wc`.`iot_code` AS `iot_code`,
        `wc`.`name` AS `name`,
        IFNULL( max( CASE WHEN ( `wcp`.`equipment_index_key` = 'FireCar_WaterCapacity' ) THEN `wcp`.`value` END ), 0 ) AS `waterCapacity`,
        IFNULL( max( CASE WHEN ( `wcp`.`equipment_index_key` = 'FireCar_FoamCapacity' ) THEN `wcp`.`value` END ), 0 ) AS `foamCapacity`,
        IFNULL(
        max(
        CASE

        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'true' ) THEN
        '启动'
        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'false' ) THEN
        '熄火'
        END
        ),
        '--'
        ) AS `carState`,
        IFNULL(
        max(
        CASE

        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'true' ) THEN
        `wcp`.`update_date`
        WHEN ( `wcp`.`equipment_index_key` = 'FireCar_Start' AND `wcp`.`value` = 'false' ) THEN
        `wcp`.`update_date`
        END
        ),
        ''
        ) AS `carStateDate`
        FROM
        `wl_car` `wc`
        LEFT JOIN `wl_car_property` `wcp` ON `wcp`.`car_id` = `wc`.`id`
        <where>
            1=1
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                AND wc.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
        GROUP BY
        `wc`.`id`
        ) a
    </select>

    <select id="getWaterInfo" resultType="java.util.Map">

        select *  from (
        select * from (
        (SELECT
        r.`name`,
        ou.`code`,
        IFNULL( rp.min_water_level, 0 ) AS minLevel,
        IFNULL( rp.max_water_level, 0 ) AS maxLevel,
        IF((
        CASE
        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) IS NULL THEN
        '--'
        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) >= IFNULL( rp.min_water_level, 0 )
        AND rp.max_water_level IS NULL THEN
        '100'
        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) &lt; IFNULL( rp.min_water_level, 0 )
        AND rp.max_water_level IS NULL THEN
        '--' ELSE IFNULL((

        abs(
        IFNULL(
        max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ),
        IFNULL( rp.min_water_level, 0 )) /
        IF
        (
        IFNULL( rp.max_water_level, 0 ) = 0,
        1,
        IFNULL( rp.max_water_level, 0 ))) * 100
        ),
        0
        )
        END
        ) = '--', '--', ROUND((
        CASE

        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) IS NULL THEN
        '--'
        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) >= IFNULL( rp.min_water_level, 0 )
        AND rp.max_water_level IS NULL THEN
        '100'
        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) &lt; IFNULL( rp.min_water_level, 0 )
        AND rp.max_water_level IS NULL THEN
        '--' ELSE IFNULL((

        abs(
        IFNULL(
        max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ),
        IFNULL( rp.min_water_level, 0 )) /
        IF
        (
        IFNULL( rp.max_water_level, 0 ) = 0,
        1,
        IFNULL( rp.max_water_level, 0 ))) * 100
        ),
        0
        )
        END
        ), 2)) AS levelAbs,
        IFNULL(max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ),'--')  AS nowLevel,
        (
        CASE

        WHEN max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ) IS NULL
        OR rp.min_water_level IS NULL THEN
        '--'
        WHEN IFNULL(
        max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN ei.`value` END ),
        IFNULL( rp.min_water_level, 0 )) &lt; IFNULL( rp.min_water_level, 0 ) THEN
        '缺水' ELSE '正常'
        END
        ) AS levelStatus,
        IFNULL( rp.volume, 0 ) AS volume,
        ec.image,
        r.resource_type,
        r.sequence_nbr,
        rp.level_device_id,
        fs.`code` AS systemCode
        FROM
        cb_water_resource r
        LEFT JOIN cb_org_usr ou ON ou.biz_org_code = r.biz_org_code
        AND ou.is_delete = 0
        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
        WHERE
        r.resource_type = 'industryPool'
        AND r.is_delete = 1
        AND ou.`code` IS NOT NULL
        <if test="bizOrgCode!=null and bizOrgCode!=''">
            AND r.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        <if test="systemCode!=null and systemCode!=''">
            AND fs.code = #{systemCode,jdbcType=VARCHAR}
        </if>
        GROUP BY
        r.sequence_nbr) union all
        (
        SELECT
        a.`name`,
        a.`code`,
        a.minLevel,
        a.maxLevel,

        IF((
        CASE

        WHEN a.nowLevel IS NULL THEN
        '--'
        WHEN a.nowLevel >= IFNULL( a.minLevel, 0 )
        AND a.maxLevel IS NULL THEN
        '100'
        WHEN IFNULL( a.minLevel, 0 ) > a.nowLevel
        AND a.maxLevel IS NULL THEN
        '--' ELSE IFNULL((

        abs(
        IFNULL(
        a.nowLevel,
        IFNULL( a.minLevel, 0 )) /
        IF
        (
        IFNULL( a.maxLevel, 0 ) = 0,
        1,
        IFNULL( a.maxLevel, 0 ))) * 100
        ),
        0
        )
        END
        ) = '--', '--', ROUND((
        CASE

        WHEN a.nowLevel IS NULL THEN
        '--'
        WHEN a.nowLevel >= IFNULL( a.minLevel, 0 )
        AND a.maxLevel IS NULL THEN
        '100'
        WHEN IFNULL( a.minLevel, 0 ) > a.nowLevel
        AND a.maxLevel IS NULL THEN
        '--' ELSE IFNULL((

        abs(
        IFNULL(
        a.nowLevel,
        IFNULL( a.minLevel, 0 )) /
        IF
        (
        IFNULL( a.maxLevel, 0 ) = 0,
        1,
        IFNULL( a.maxLevel, 0 ))) * 100
        ),
        0
        )
        END
        ), 2)) AS levelAbs,
        a.nowLevel,
        (
        CASE

        WHEN a.nowLevel IS NULL
        OR a.minLevel IS NULL THEN
        '--'
        WHEN IFNULL( a.minLevel, 0 ) > IFNULL(
        a.nowLevel,
        IFNULL( a.minLevel, 0 )) THEN
        '缺水' ELSE '正常'
        END
        ) AS levelStatus,
        a.volume,
        a.image,
        a.resource_type,
        a.sequence_nbr,
        a.level_device_id,
        a.`code` AS systemCode
        FROM
        (
        SELECT
        r.`name`,
        ou.`code`,
        IFNULL( rp.min_water_level, 0 ) AS minLevel,
        IFNULL( rp.max_water_level, 0 ) AS maxLevel,
        (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( rp.volume, 0 ) AS volume,
        ec.image,
        r.resource_type,
        r.sequence_nbr,
        rp.level_device_id,
        fs.`code` AS systemCode
        FROM
        cb_water_resource r
        LEFT JOIN cb_org_usr ou ON ou.biz_org_code = r.biz_org_code
        AND ou.is_delete = 0
        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
        WHERE
        r.resource_type = 'pool'
        AND r.is_delete = 1
        AND ou.`code` IS NOT NULL
        <if test="bizOrgCode!=null and bizOrgCode!=''">
            AND r.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        <if test="systemCode!=null and systemCode!=''">
            AND fs.code = #{systemCode,jdbcType=VARCHAR}
        </if>
        GROUP BY
        r.sequence_nbr
        ) a
        )) b
        ORDER BY
        levelStatus DESC,sequence_nbr DESC ) as a
    </select>

    <select id="getFireSystemInfo"  resultType="java.util.Map">
      select `nz`.name,`nz`.status from ( SELECT
        `fs`.`id` AS `id`,
        `fs`.`code` AS `code`,
        `fs`.`biz_org_code` AS `biz_org_code`,
        `fs`.`name` AS `name`,
        `fs`.`install_date` AS `installdate`,
        `fs`.`charge_person_name` AS `chargeperson`,
        `fs`.`charge_person_phone` AS `chargepersonphone`,
        `mim`.`name` AS `maintenanceunit`,
        `mic`.`name` AS `constructionunit`,(
        CASE

        WHEN ((
        SELECT
        count( 1 )
        FROM
        `wl_equipment_specific_alarm`
        WHERE
        ((
        `wl_equipment_specific_alarm`.`status` = 1
        )
        AND (
        0 != find_in_set( `fs`.`id`, `wl_equipment_specific_alarm`.`system_ids` )))) > 0
        ) THEN
        '异常' ELSE '正常'
        END
        ) AS `status`
        FROM
        ((
        `f_fire_fighting_system` `fs`
        LEFT JOIN `wl_manufacturer_info` `mic` ON ((
        `mic`.`id` = `fs`.`maintenance_unit`
        )))
        LEFT JOIN `wl_manufacturer_info` `mim` ON ((
        `mim`.`id` = `fs`.`construction_unit`
        )))) `nz`
        <where>
            <if test="systemCode!=null and systemCode!=''">
               and `nz`.code = #{systemCode}
            </if>
            <if test="bizOrgCode!=null and bizOrgCode!=''">
               and `nz`.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
    </select>

    <select id="equipAlarmTOP"  resultType="java.util.Map">
<!--        SELECT-->
<!--        ifnull( `a`.`fightSysName`, NULL ) AS `fightSysName`,-->
<!--        ifnull( `a`.`fightSysCode`, NULL ) AS `fightSysCode`,-->
<!--        ifnull( `a`.`fightSysId`, NULL ) AS `fightSysId`,-->
<!--        ifnull( `a`.`report_date`, NULL ) AS `reportDate`,-->
<!--        `a`.`equipName` AS `equipName`,-->
<!--        sum( `a`.`total` ) AS `total`-->
<!--        FROM-->
<!--        (-->
<!--        SELECT-->
<!--        `rd`.`index_type` AS `indxKey`,-->
<!--        `rd`.`index_name` AS `index_name`,-->
<!--        `rd`.`equipment_specific_name` AS `equipName`,-->
<!--        count( DISTINCT `rd`.`equipment_specific_id` ) AS `total`,-->
<!--        `rd`.`report_date` AS `report_date`,-->
<!--        `fs`.`name` AS `fightSysName`,-->
<!--        `fs`.`code` AS `fightSysCode`,-->
<!--        `fs`.`id` AS `fightSysId`,-->
<!--        `rd`.`equipment_specific_id` AS `equipId`-->
<!--        FROM-->
<!--        (-->
<!--        `wl_equipment_alarm_report_day` `rd`-->
<!--        LEFT JOIN `f_fire_fighting_system` `fs` ON ((-->
<!--        0 != find_in_set( `fs`.`id`, `rd`.`system_ids` ))))-->
<!--        WHERE-->
<!--        (((-->
<!--        curdate() - INTERVAL 30 DAY-->
<!--        ) &lt;= cast( `rd`.`report_date` AS date ))-->
<!--        AND ( `fs`.`code` = #{systemCode} )-->
<!--        AND ( `fs`.`biz_org_code` like concat(#{bizOrgCode}, '%') )-->
<!--        AND ((-->
<!--        `rd`.`index_type` LIKE '%Fault'-->
<!--        )-->
<!--        OR ( `rd`.`index_type` LIKE '%FireAlarm' )-->
<!--        OR ( `rd`.`index_type` LIKE '%Shield' ))-->
<!--        AND ( `rd`.`value` = 'true' ))-->
<!--        GROUP BY-->
<!--        `rd`.`equipment_specific_id`,-->
<!--        `rd`.`report_date`-->
<!--        ) `a`-->
<!--        GROUP BY-->
<!--        `a`.`equipId`-->
<!--        ORDER BY-->
<!--        `total` DESC-->
<!--        LIMIT 5-->

        SELECT
            d.*
        FROM
        (
            SELECT
            a.equipName,
            count( DISTINCT wesa.equipment_specific_id ) AS total
            FROM
            (
            SELECT
            eq.`name` AS equipName,
            eq.id AS equipmentId,
            eq.`code` AS `code`
            FROM
            wl_equipment eq
            LEFT JOIN wl_equipment_detail wed ON eq.id = wed.equipment_id
            LEFT JOIN wl_equipment_specific wes ON wed.id = wes.equipment_detail_id
            WHERE
            FIND_IN_SET( #{systemId}, wes.system_id ) > 0
            ) a
            LEFT JOIN wl_equipment_specific_alarm wesa ON wesa.equipment_id = a.equipmentId
            AND FIND_IN_SET( #{systemId}, wesa.system_ids ) > 0
            AND `wesa`.`create_date` >= ( curdate() - INTERVAL 30 DAY )
            GROUP BY
            a.equipmentId
            ORDER BY
            total DESC
            LIMIT 5
        ) d
        ORDER BY d.total ASC
    </select>

    <select id="equipmentId" resultType="String">
        select
            id
        from
            f_fire_fighting_system
        where
            code = #{systemCode}
    </select>

    <select id="equipmentIdBySuper" resultType="String">
        select
            id
        from
            f_fire_fighting_system
        where
            code = #{systemCode}
          and
            biz_org_code like concat(#{bizOrgCode}, '%')
    </select>

    <select id="equipmentState" resultType="java.util.Map">
<!--        SELECT-->
<!--            b.equipName,-->
<!--            (CASE WHEN-->
<!--                      b.totalNum > 0 THEN-->
<!--                      '异常' ELSE '正常' END) `status`,-->
<!--            b.totalNum AS totalNum,-->
<!--            b.`code` AS equipDetailCode-->
<!--        FROM-->
<!--            (-->
<!--                SELECT-->
<!--                    a.equipName,-->
<!--                    count( wesl.id ) AS totalNum,-->
<!--                    a.`code`-->
<!--                FROM-->
<!--                    (-->
<!--                        SELECT-->
<!--                            wes.`name` AS equipName,-->
<!--                            wed.equipment_id AS equipmentId,-->
<!--                            wed.`code` AS code-->
<!--                        FROM-->
<!--                            wl_equipment_specific wes-->
<!--                                LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id-->
<!--                        WHERE-->
<!--                            FIND_IN_SET( #{id}, wes.system_id ) > 0-->
<!--                        GROUP BY-->
<!--                            wed.equipment_id-->
<!--                    ) a-->
<!--                        LEFT JOIN wl_equipment_specific_alarm_log wesl ON wesl.equipment_id = a.equipmentId-->
<!--                GROUP BY-->
<!--                    a.equipmentId-->
<!--            ) b-->

        SELECT
        b.equipName,
        ( CASE WHEN b.totalNum > 0 THEN '异常' ELSE '正常' END ) `status`,
        b.totalNum AS totalNum,
        b.`code` AS equipDetailCode
        FROM
        (
        SELECT
        a.equipName,
        count( DISTINCT wesa.equipment_specific_id ) AS totalNum,
        a.`code`
        FROM
        (
         SELECT
        eq.`name` AS equipName,
        eq.id AS equipmentId,
        eq.`code` AS `code`
        FROM
        wl_equipment eq
        LEFT JOIN wl_equipment_detail wed ON eq.id = wed.equipment_id
        LEFT JOIN wl_equipment_specific wes on wed.id = wes.equipment_detail_id
        WHERE
        FIND_IN_SET( #{id}, wes.system_id ) > 0
        ) a
        LEFT JOIN wl_equipment_specific_alarm wesa ON wesa.equipment_id = a.equipmentId
        AND wesa.`status` = 1 and FIND_IN_SET( #{id}, wesa.system_ids ) > 0
        GROUP BY
        a.equipmentId
        ) b
        ORDER BY
        b.totalNum DESC
    </select>

    <select id="equipmentStateBySuper" resultType="java.util.Map">
        SELECT
            b.equipName,
            ( CASE WHEN b.totalAlarmNum > 0 THEN '异常' ELSE '正常' END ) `status`,
            b.totalAlarmNum AS alarmNum,
            b.`code` AS equipDetailCode,
            b.totalNum
        FROM
            (
                SELECT
                    a.equipName,
                    count( DISTINCT wesi.equipment_specific_id ) AS totalAlarmNum,
                    a.`code`,
                    count( DISTINCT a.id ) AS totalNum
                FROM
                    (
                        SELECT
                            eq.`name` AS equipName,
                            eq.id AS equipmentId,
                            eq.`code` AS `code`,
                            wes.id
                        FROM
                            wl_equipment eq
                                LEFT JOIN wl_equipment_detail wed ON eq.id = wed.equipment_id
                                LEFT JOIN wl_equipment_specific wes ON wed.id = wes.equipment_detail_id
                        WHERE
                            FIND_IN_SET( #{id}, wes.system_id ) > 0
                    ) a
                        LEFT JOIN wl_equipment_specific_index wesi ON wesi.equipment_specific_id = a.id
                        AND ((wesi.`is_alarm` = 1 and wesi.`value` = 'true') or (wesi.`is_alarm` = 0 and wesi.`value` = 'false'))
                GROUP BY
                    a.equipmentId
            ) b
        ORDER BY
            b.totalNum DESC
    </select>

    <select id="getPressurePumpInfo" resultType="java.util.Map">
        SELECT
        ed.`name`,
        concat_ws( '-', ws.full_name, ed.area ) area,
        es.iot_code,
        es.id,
        es.code,
        IFNULL( sum( `status` ), 0 ) AS isAlarm
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = es.warehouse_structure_id
        LEFT JOIN wl_equipment_specific_alarm esa ON esa.equipment_specific_id = es.id
        WHERE
        ed.`code` LIKE '92010800%'
        AND es.iot_code IS NOT NULL
        <if test="bizOrgCode != null and bizOrgCode != ''" >
            AND es.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        GROUP BY
        es.id
    </select>

    <select id="queryPressureNowStateBySpecificId" resultType="java.util.Map">
        SELECT
            i.update_date,
            i.equipment_index_name,
            value
        FROM
            wl_equipment_specific_index i
        WHERE
            i.equipment_specific_id = #{id,jdbcType=VARCHAR}
            AND i.equipment_index_key in ('FHS_PressurePump_Start', 'FHS_PressurePump_Stop')
        ORDER BY
            i.update_date DESC
            LIMIT 1
    </select>

    <select id="queryPressureNowSignalBySpecificId" resultType="java.util.Map">
        SELECT
            DATE_FORMAT( i.update_date, '%Y-%m-%d %H:%i:%S' ) update_date,
            i.equipment_index_name,
            `value`
        FROM
            wl_equipment_specific_index i
        WHERE
            i.equipment_specific_id = #{id,jdbcType=VARCHAR}
          AND
            VALUE in ("true","false")
        ORDER BY
            i.update_date DESC
            LIMIT 1
    </select>

    <select id="getPressurePumpInfo3Small" resultType="java.util.Map">
        SELECT
        ed.`name`,
        concat_ws( '-', ws.full_name, ed.area ) area,
        es.iot_code,
        es.id,
        IFNULL( sum( `status` ), 0 ) AS isAlarm
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = es.warehouse_structure_id
        LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
        LEFT JOIN wl_equipment_specific_alarm esa ON esa.equipment_specific_id = es.id
        WHERE
        ed.`code` LIKE '92010800%'
        AND es.iot_code IS NOT NULL
        AND es.biz_org_code like concat(#{bizOrgCode}, '%')
        <if test="systemCode!=null and systemCode!=''">
            AND fs.code = #{systemCode,jdbcType=VARCHAR}
        </if>
        GROUP BY
        es.id
    </select>
    <select id="exportEquipmentList" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentExportVO">
              SELECT
          wesp.`code` ,
          wws.full_name location,
          wesp.`name`,
          ed.production_date,
          ed.maintenance_cycle AS maintenanceCycle,
          ed.expiry_date AS validityPeriod,
          mi.`name` AS manufacturer,
          ed.standard,
          ed.brand,
          eq.`name`AS classification,
          ed.delivery_date AS   operationTime,
          (
            SELECT
              GROUP_CONCAT(fem.`name`)
            FROM
              `f_fire_fighting_system` fem
            WHERE
              find_in_set(fem.id, wesp.system_id)
          ) AS system_name
        FROM
          wl_equipment_specific wesp
        LEFT JOIN wl_equipment_detail ed ON ed.id = wesp.equipment_detail_id
        LEFT JOIN wl_equipment eq ON eq.id = ed.equipment_id
        LEFT JOIN wl_manufacturer_info mi ON mi.id = ed.manufacturer_id
        LEFT JOIN wl_stock_detail wsd ON wsd.equipment_specific_id = wesp.id
        LEFT JOIN wl_warehouse_structure wws ON wsd.warehouse_structure_id = wws.id
        LEFT JOIN  wl_equipment_category wec on wec.id=eq.category_id
        <where>
            wec.industry_code = 2
        <if test="dto.code!=null and dto.code!=''">
            and wesp.code = #{dto.code}
        </if>

        <if test="dto.equipmentName!=null and dto.equipmentName!=''">
            and wesp.`name` LIKE CONCAT('%', #{dto.equipmentName},'%')
        </if>
        <if test="dto.iotCode!=null and dto.iotCode!=''">
            and  wesp.iot_code LIKE CONCAT('%', #{dto.iotCode},'%')
        </if>

        <if test="dto.warehouseStructureName!=null and dto.warehouseStructureName!=''">
            and  wws.full_name LIKE CONCAT('%', #{dto.warehouseStructureName},'%')
        </if>

        <if test="dto.isIot!=null and dto.isIot!=''">
            and eq.is_iot = #{dto.isIot}
        </if>

         <if test="dto.manufacturerId!=null and dto.manufacturerId!=''">
            and  mi.id = #{dto.manufacturerId}
        </if>

        <if test="dto.status == 1">
            and wsd.warehouse_structure_id is null
        </if>

        <if test="dto.status == 0">
            and wsd.warehouse_structure_id is not null
        </if>

        <if test="dto.teamId!=null and dto.teamId!=''">
            and wesp.team_id = #{dto.teamId}
        </if>

        <if test="dto.systemId!=null and dto.systemId!=''">
            and wesp.system_id = #{dto.systemId}
        </if>

        <if test="dto.warehouseStructureId!=null and dto.warehouseStructureId!=''">
            and wws.id  = #{dto.warehouseStructureId}
        </if>
        <if test="dto.isImport!=null">
            and wled.is_import = #{dto.isImport}
        </if>

        <if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''">
            and wesp.biz_org_code like concat(#{dto.bizOrgCode}, '%')
        </if>
     </where>
    </select>

    <select id="getSystemAlarmInfoNum" resultType="java.util.Map">
        SELECT
            count( a.alarmNum > 0 OR NULL ) AS exceptionNum,
            count( a.id ) AS totalSystemNum,
            (
                count( a.id ) - count( a.alarmNum &gt; 0 OR NULL )) AS normalNum,
            (
        FORMAT (
                            abs(((
                                     count( a.id ) - count( a.alarmNum > 0 OR NULL )) /
                                 IF
                                     (( count( a.id ) = 0 ), 1, count( a.id ) ))) * 100, 2)
                ) AS normalAbs
        FROM
            (
                SELECT
                    fs.id,
                    IFNULL( sum( esa.`status` ), 0 ) AS alarmNum
                FROM
                    f_fire_fighting_system fs
                        LEFT JOIN wl_equipment_specific_alarm esa ON FIND_IN_SET( fs.id, esa.system_ids )
                <where>
                    <if test="bizOrgCode != null and bizOrgCode != ''">
                        fs.`biz_org_code`  like concat(#{bizOrgCode}, '%')
                    </if>
                </where>
                GROUP BY
                    fs.id
            ) a
    </select>

    <select id="getWaterPoolInfoNum" resultType="java.util.Map">
        SELECT
        count( 1 ) AS totalNum,
        count( a.minLevel > a.nowLevel OR NULL ) AS abnomalNum,
        count( a.nowLevel >= a.minLevel OR NULL ) AS nomalNum,
        (
        FORMAT (
        abs(((
        count( a.nowLevel >= a.minLevel OR NULL )) /
        IF
        (( count( 1 ) = 0 ), 1, count( 1 ) ))) * 100,
        2
        )
        ) AS normalAbs
        FROM
        (
        SELECT
        ifnull( `rp`.`min_water_level`, 0 ) AS `minLevel`,
        ifnull( `rp`.`max_water_level`, 0 ) AS `maxLevel`,
        (select
        FORMAT(avg(IFNULL(ei.`value`,0)), 2)
        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
        FROM
        `cb_water_resource` `r`
        LEFT JOIN `cb_water_resource_pool` `rp` ON `rp`.`resource_id` = `r`.`sequence_nbr`
        WHERE
        `r`.`is_delete` = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            AND r.`biz_org_code` like concat(#{bizOrgCode}, '%')
        </if>
        AND `r`.`resource_type` = 'pool'
        GROUP BY
        `r`.`sequence_nbr`
        ) a
    </select>


    <select id="getWaterIndustryPoolInfoNum" resultType="java.util.Map">
        SELECT
        count( 1 ) AS totalNum,
        count( a.minLevel > a.nowLevel OR NULL ) AS abnomalNum,
        count( a.nowLevel >= a.minLevel OR NULL ) AS nomalNum,
        (
        FORMAT (
        abs(((
        count( a.nowLevel >= a.minLevel OR NULL )) /
        IF
        (( count( 1 ) = 0 ), 1, count( 1 ) ))) * 100,
        2
        )
        ) AS normalAbs
        FROM
        (
        SELECT
        ifnull( `rp`.`min_water_level`, 0 ) AS `minLevel`,
        ifnull( `rp`.`max_water_level`, 0 ) AS `maxLevel`,
        ifnull(MAX( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel'  THEN IFNULL( ei.`value`, 0 ) END ), 0) AS nowLevel
        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`
        WHERE
        `r`.`is_delete` = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            AND r.`biz_org_code` like concat(#{bizOrgCode}, '%')
        </if>
        AND `r`.`resource_type` = 'industryPool'
        GROUP BY
        `r`.`sequence_nbr`
        ) a
    </select>


<!--    <select id="getWaterPoolVolumeInfo" resultType="java.util.Map">-->
<!--        SELECT-->
<!--            IFNULL( sum( a.margin ), 0 ) AS margin,-->
<!--            IFNULL( sum( volume ), 0 ) AS volume-->
<!--        FROM-->
<!--            (-->
<!--                SELECT-->
<!--                    `ou`.`code` AS `code`,-->
<!--                    ifnull((-->
<!--                                   abs((-->
<!--                                           ifnull(-->
<!--                                                   max((-->
<!--                                                       CASE-->

<!--                                                           WHEN ( `ei`.`name_key` = 'FHS_WirelessliquidDetector_WaterLevel' ) THEN-->
<!--                                                               `ei`.`perf_value`-->
<!--                                                           END-->
<!--                                                       )),-->
<!--                                                   ifnull( `rp`.`min_water_level`, 0 )) /-->
<!--                                           IF-->
<!--                                               ((-->
<!--                                                    ifnull( `rp`.`max_water_level`, 0 ) = 0-->
<!--                                                    ),-->
<!--                                                1,-->
<!--                                                ifnull( `rp`.`max_water_level`, 0 )))) * ifnull( `rp`.`volume`, 0 )),-->
<!--                           0-->
<!--                        ) AS `margin`,-->
<!--                    ifnull( `rp`.`volume`, 0 ) AS `volume`-->
<!--                FROM-->
<!--                    `cb_water_resource` `r`-->
<!--                        LEFT JOIN `cb_org_usr` `ou` ON `ou`.`biz_org_code` = `r`.`biz_org_code`-->
<!--                        LEFT JOIN `cb_water_resource_pool` `rp` ON `rp`.`resource_id` = `r`.`sequence_nbr`-->
<!--                        LEFT JOIN `wl_equipment_specific` `es` ON `es`.`id` = `rp`.`level_device_id`-->
<!--                        LEFT JOIN `wl_equipment_detail` `ed` ON `ed`.`id` = `es`.`equipment_detail_id`-->
<!--                        LEFT JOIN `wl_equipment_index` `ei` ON `ei`.`equipment_id` = `ed`.`equipment_id`-->
<!--                WHERE-->
<!--                    `r`.`resource_type` IN ( 'pool', 'industryPool' )-->
<!--                  AND `r`.`is_delete` = 1-->
<!--                  AND `ou`.`code` IS NOT NULL-->
<!--                <if test="companyCode != null and companyCode != ''">-->
<!--                    AND ou.`code` = #{companyCode}-->
<!--                </if>-->
<!--                GROUP BY-->
<!--                    `r`.`sequence_nbr`-->
<!--            ) a-->
<!--    </select>-->

    <select id="getCarNum" resultType="java.lang.Integer">
        SELECT
            count( wc.id ) as carNum
        FROM
            wl_car wc
                LEFT JOIN cb_org_usr ou ON ou.amos_org_code = wc.org_code
        <where>
            <if test="companyCode != null and companyCode != ''">
                ou.`code` = #{companyCode}
            </if>
        </where>
    </select>

    <select id="getCarInfo" resultType="java.util.Map">
        select b.*,
        (FORMAT (
        abs((
        b.near7DaysStartNum) /
        IF
        (( b.totalCarNum = 0 ), 1, b.totalCarNum )) * 100 , 2)) as carAbs
        from
        (SELECT
        count(( a.carStateDate BETWEEN DATE_ADD( now(), INTERVAL - 7 DAY ) AND now()) OR NULL ) AS near7DaysStartNum,
        count( 1 ) AS totalCarNum
        FROM
        (
        SELECT
        `wc`.`id` AS `id`,
        `wc`.`name` AS `name`,
        max( CASE WHEN `wcp`.`equipment_index_key` = 'FireCar_Start' THEN `wcp`.`update_date` END ) AS `carStateDate`
        FROM
        `wl_car` `wc`
        LEFT JOIN `wl_car_property` `wcp` ON `wcp`.`car_id` = `wc`.`id`
        <where>
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                wc.`biz_org_code` like concat(#{bizOrgCode}, '%')
            </if>
        </where>
        GROUP BY
        wc.id
        ) a) b
    </select>

    <select id="getEquipInfo" resultType="java.util.Map">
        SELECT
            temp.total,
            temp.notReturned,
            temp.alarmEquipTotalNum,(
                temp.alarmEquipTotalNum - temp.notReturned
                ) AS returned,
            (
                    FORMAT ( abs(( temp.alarmEquipTotalNum ) / IF (( temp.total = 0 ), 1, temp.total )) * 100, 2 )
                ) AS equipAbs,
            (
                    FORMAT ( abs(( temp.alarmEquipTotalNum - temp.notReturned ) / IF (( temp.alarmEquipTotalNum = 0 ), 1, temp.alarmEquipTotalNum )) * 100 , 2 )
                ) AS returnAbs
        FROM
            (
                SELECT
                    (
                        SELECT
                            count( 1 )
                        FROM
                            wl_equipment_specific es
                                LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
                                LEFT JOIN wl_equipment e ON e.id = ed.equipment_id
                        WHERE
                            e.is_iot = 1
                        <if test="bizOrgCode != null and bizOrgCode != ''">
                           and es.`biz_org_code` like concat(#{bizOrgCode}, '%')
                        </if>
                    ) AS total,
                    (
                        SELECT
                            COUNT(
                                    DISTINCT ( esa.iot_code ))
                        FROM
                            wl_equipment_specific_alarm esa
                                LEFT JOIN cb_org_usr ou ON ou.amos_org_code = esa.org_code
                        WHERE
                            esa.create_date LIKE CONCAT( DATE_FORMAT( now(), '%Y-%m' ), '%' )
                        <if test="alarmType != null and alarmType != ''">
                            AND esa.type = #{alarmType}
                        </if>
                        <if test="bizOrgCode != null and bizOrgCode != ''">
                            and ou.`biz_org_code`  like concat(#{bizOrgCode}, '%')
                        </if>
                    ) AS alarmEquipTotalNum,
                    (
                        SELECT
                            COUNT(
                                    DISTINCT ( esa.iot_code ))
                        FROM
                            wl_equipment_specific_alarm esa
                                LEFT JOIN cb_org_usr ou ON ou.amos_org_code = esa.org_code
                        WHERE
                            esa.equipment_specific_index_value = "true"
                          AND esa.create_date LIKE CONCAT( DATE_FORMAT( now(), '%Y-%m' ), '%' )
                        <if test="alarmType != null and alarmType != ''">
                            AND esa.type = #{alarmType}
                        </if>
                        <if test="bizOrgCode != null and bizOrgCode != ''">
                            and ou.`biz_org_code`  like concat(#{bizOrgCode}, '%')
                        </if>
                    ) AS notReturned
            ) temp
    </select>
    <select id="statisticsByStation" resultType="java.util.Map">
        SELECT
        (
        SELECT COUNT(1) FROM wl_video v
        <where>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                v.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
        ) AS videoNum,
        (
        SELECT
            count( 1 )
        FROM
            wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
        LEFT JOIN wl_equipment e ON e.id = ed.equipment_id
        LEFT JOIN cb_org_usr ou ON ou.biz_org_code = es.biz_org_code
        <where>
            e.is_iot = 1
            <if test="bizOrgCode != null and bizOrgCode != ''">
             and  es.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
         )AS equipNum
    </select>
    <select id="todayAlarmEquipment" resultType="java.util.Map">
        SELECT
        `a`.`currentDateNum` AS `currentDateNum`,
        (
        abs(
        (
        ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) /
        IF
        ( ( `a`.`yesterdayNum` = 0 ), 1, `a`.`yesterdayNum` )
        )
        ) * 100
        ) AS `dayAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `dayStatus`,
        (
        abs(
        (
        ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) /
        IF
        ( ( `a`.`lastMonthNum` = 0 ), 1, `a`.`lastMonthNum` )
        )
        ) * 100
        ) AS `monthAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `monthStatus`
        FROM
        (
        SELECT
        ( SELECT count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` ) FROM `wl_equipment_specific_alarm_log`
        WHERE create_date LIKE concat( curdate( ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `currentDateNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE

        create_date LIKE concat( cast( ( curdate( ) + INTERVAL - ( 1 ) DAY ) AS date ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>


        ) AS `yesterdayNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        create_date LIKE concat( date_format( curdate( ), '%Y-%m' ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `currentMonthNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE

        `create_date` LIKE concat( date_format( cast( ( curdate( ) + INTERVAL - ( 1 ) MONTH ) AS date ), '%Y-%m' ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `lastMonthNum`
        ) `a`


    </select>
    <select id="todayAlarmMessage" resultType="java.util.Map">
        SELECT
        `a`.`currentDateNum` AS `currentDateNum`,
        (
        abs(
        (
        ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) /
        IF
        ( ( `a`.`yesterdayNum` = 0 ), 1, `a`.`yesterdayNum` )
        )
        ) * 100
        ) AS `dayAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `dayStatus`,
        (
        abs(
        (
        ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) /
        IF
        ( ( `a`.`lastMonthNum` = 0 ), 1, `a`.`lastMonthNum` )
        )
        ) * 100
        ) AS `monthAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `monthStatus`
        FROM
        (
        SELECT
        ( SELECT count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` ) FROM `wl_equipment_specific_alarm_log` WHERE
        create_date LIKE concat( curdate( ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `currentDateNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        create_date LIKE concat( cast( ( curdate( ) + INTERVAL - ( 1 ) DAY ) AS date ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `yesterdayNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        create_date LIKE concat( date_format( curdate( ), '%Y-%m' ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `currentMonthNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE

        create_date LIKE concat( date_format( cast( ( curdate( ) + INTERVAL - ( 1 ) MONTH ) AS date ), '%Y-%m' ), '%' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `lastMonthNum`
        ) `a`
    </select>
    <select id="todayAlarmUnEliminateEquipment" resultType="java.util.Map">
        SELECT
        `a`.`unclearTotalNum` AS `currentDateNum`,
        (
        abs(
        (
        ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) /
        IF
        ( ( `a`.`yesterdayNum` = 0 ), 1, `a`.`yesterdayNum` )
        )
        ) * 100
        ) AS `dayAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'

        END
        ) AS `dayStatus`,
        (
        abs(
        (
        ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) /
        IF
        ( ( `a`.`lastMonthNum` = 0 ), 1, `a`.`lastMonthNum` )
        )
        ) * 100
        ) AS `monthAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `monthStatus`
        FROM
        (
        SELECT
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        create_date LIKE concat( curdate( ), '%' )  AND status = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `currentDateNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        status = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `unclearTotalNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE


        create_date LIKE concat( cast( ( curdate( ) + INTERVAL - ( 1 ) DAY ) AS date ), '%' )

        AND status = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `yesterdayNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE

        create_date LIKE concat( date_format( curdate( ), '%Y-%m' ), '%' )
        AND  status = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `currentMonthNum`,
        (
        SELECT
        count( DISTINCT `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE


        create_date LIKE concat( date_format( cast( ( curdate( ) + INTERVAL - ( 1 ) MONTH ) AS date ), '%Y-%m' ), '%' )

        AND status = 1
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `lastMonthNum`
        ) `a`
    </select>
    <select id="todayAlarmUnEliminateMessage" resultType="java.util.Map">
        SELECT
        `a`.`unConfirmTotalNum` AS `currentDateNum`,
        (
        abs(
        (
        ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) /
        IF
        ( ( `a`.`yesterdayNum` = 0 ), 1, `a`.`yesterdayNum` )
        )
        ) * 100
        ) AS `dayAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) &lt;  0 ) THEN
        '0'
        WHEN ( ( `a`.`currentDateNum` - `a`.`yesterdayNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `dayStatus`,
        (
        abs(
        (
        ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) /
        IF
        ( ( `a`.`lastMonthNum` = 0 ), 1, `a`.`lastMonthNum` )
        )
        ) * 100
        ) AS `monthAbs`,
        (
        CASE

        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) &lt; 0 ) THEN
        '0'
        WHEN ( ( `a`.`currentMonthNum` - `a`.`lastMonthNum` ) > 0 ) THEN
        '1'
        ELSE
        '2'
        END
        ) AS `monthStatus`
        FROM
        (
        SELECT
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        create_date LIKE concat( curdate( ), '%' ) AND confirm_date IS NULL
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `currentDateNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        confirm_date IS NULL
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>
        ) AS `unConfirmTotalNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE


        create_date LIKE concat( cast( ( curdate( ) + INTERVAL - ( 1 ) DAY ) AS date ), '%' )

        AND confirm_date IS NULL
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `yesterdayNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE

        create_date LIKE concat( date_format( curdate( ), '%Y-%m' ), '%' )
        AND confirm_date IS NULL
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `currentMonthNum`,
        (
        SELECT
        count( `wl_equipment_specific_alarm_log`.`equipment_specific_id` )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE


        create_date LIKE concat( date_format( cast( ( curdate( ) + INTERVAL - ( 1 ) MONTH ) AS date ), '%Y-%m' ), '%' )

        AND confirm_date IS NULL
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code like concat(#{bizOrgCode}, '%'))
        </if>

        ) AS `lastMonthNum`
        ) `a`
    </select>
    <select id="monthAlarm" resultType="java.util.Map">
        SELECT
        `result`.`click_date` AS `click_date`,
        `a`.`fireAlarmNum` AS `fireAlarmNum`,
        `b`.`breakdownNum` AS `breakdownNum`,
        `c`.`shieldNum` AS `shieldNum`,
        `d`.`otherNum` AS `otherNum`
        FROM
        (
        (
        (
        (
        `v_monitor_event_utils_month` `result`
        LEFT JOIN (
        SELECT
        `monthUtil`.`click_date` AS `click_date`,
        ifnull( count( `fireAlarm`.`id` ), 0 ) AS `fireAlarmNum`
        FROM
        (
        `v_monitor_event_utils_month` `monthUtil`
        LEFT JOIN `wl_equipment_specific_alarm_log` `fireAlarm` ON date_format( `fireAlarm`.`create_date`, '%Y-%m-%d' )
        = `monthUtil`.`click_date`
        AND `fireAlarm`.`equipment_specific_index_name` = '火警'
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and fireAlarm.equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%') )
        </if>

        )
        GROUP BY
        `monthUtil`.`click_date`
        ORDER BY
        `monthUtil`.`click_date`
        ) `a` ON ( ( `a`.`click_date` = `result`.`click_date` ) )
        )
        LEFT JOIN (
        SELECT
        `monthUtil`.`click_date` AS `click_date`,
        ifnull( count( `breakdown`.`id` ), 0 ) AS `breakdownNum`
        FROM
        (
        `v_monitor_event_utils_month` `monthUtil`
        LEFT JOIN `wl_equipment_specific_alarm_log` `breakdown` ON `monthUtil`.`click_date` = date_format(
        `breakdown`.`create_date`, '%Y-%m-%d' ) AND `breakdown`.`equipment_specific_index_name` = '故障'
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and breakdown.equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%') )
        </if>

        )
        GROUP BY
        `monthUtil`.`click_date`
        ORDER BY
        `monthUtil`.`click_date`
        ) `b` ON ( ( `b`.`click_date` = `result`.`click_date` ) )
        )
        LEFT JOIN (
        SELECT
        `monthUtil`.`click_date` AS `click_date`,
        ifnull( count( `shield`.`id` ), 0 ) AS `shieldNum`
        FROM
        (
        `v_monitor_event_utils_month` `monthUtil`
        LEFT JOIN `wl_equipment_specific_alarm_log` `shield` ON date_format( `shield`.`create_date`, '%Y-%m-%d' ) =
        `monthUtil`.`click_date` AND `shield`.`equipment_specific_index_name` = '屏蔽'
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and shield.equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%')
            )
        </if>

        )
        GROUP BY
        `monthUtil`.`click_date`
        ORDER BY
        `monthUtil`.`click_date`
        ) `c` ON ( ( `c`.`click_date` = `result`.`click_date` ) )
        )
        LEFT JOIN (
        SELECT
        `monthUtil`.`click_date` AS `click_date`,
        ifnull( count( `other`.`id` ), 0 ) AS `otherNum`
        FROM
        (
        `v_monitor_event_utils_month` `monthUtil`
        LEFT JOIN `wl_equipment_specific_alarm_log` `other` ON

        date_format( `other`.`create_date`, '%Y-%m-%d' ) = `monthUtil`.`click_date`
        AND `other`.`equipment_specific_index_name` NOT IN ( '火警', '故障', '屏蔽' )
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and other.equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%') )
        </if>


        )
        GROUP BY
        `monthUtil`.`click_date`
        ORDER BY
        `monthUtil`.`click_date`
        ) `d` ON ( ( `d`.`click_date` = `result`.`click_date` ) )
        )
        ORDER BY
        `result`.`click_date`


    </select>
    <select id="yearsAlarm" resultType="java.util.Map">
                SELECT
            `result`.`date` AS `date`,
            `a`.`alarmEquipNum` AS `alarmEquipNum`,
            `b`.`alarmInfoNum` AS `alarmInfoNum`
        FROM
            (
            (
            `one_years_month_util_view` `result`
            LEFT JOIN (
        SELECT
            `monthUtil`.`date` AS `date`,
            ifnull( count( DISTINCT `wes1`.`equipment_specific_id` ), 0 ) AS `alarmEquipNum`
        FROM
            ( `one_years_month_util_view` `monthUtil` LEFT JOIN `wl_equipment_specific_alarm_log` `wes1` ON   date_format( `wes1`.`create_date`, '%Y-%m' ) = `monthUtil`.`date`
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and  wes1.equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%') )
        </if>

             )
        GROUP BY
            `monthUtil`.`date`
        ORDER BY
            `monthUtil`.`date`
            ) `a` ON  `a`.`date` = `result`.`date`
            )
            LEFT JOIN (
        SELECT
            `monthUtil`.`date` AS `date`,
            ifnull( count( `wes1`.`id` ), 0 ) AS `alarmInfoNum`
        FROM
            ( `one_years_month_util_view` `monthUtil` LEFT JOIN `wl_equipment_specific_alarm_log` `wes1` ON   date_format( `wes1`.`create_date`, '%Y-%m' ) = `monthUtil`.`date`
        <if test="bizOrgCode != null and bizOrgCode != ''">
            and  wes1.equipment_specific_id in(SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%') )
        </if>
            )
        GROUP BY
            `monthUtil`.`date`
        ORDER BY
            `monthUtil`.`date`
            ) `b` ON   `b`.`date` = `result`.`date`
            )
        ORDER BY
            `result`.`date`

    </select>
    <select id="alarmList" resultType="java.util.Map">
        SELECT * FROM alarm_all_list_view
        <where>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                specificId in (SELECT id FROM wl_equipment_specific WHERE biz_org_code  like concat(#{bizOrgCode}, '%'))
            </if>
        </where>
        ORDER BY createDate DESC
    </select>

    <select id="equipList" resultType="java.util.Map">
        SELECT wesp.name,
        wesp.`code` AS num,
        ifNull(ed.standard,"") AS type,
        ifNull(mi.`name`,"") as manufacturer,
        ifNull(concat(wws.full_name,'--',ed.area) ,"") as address,
        ifNull(eq.`name`,"") AS equType,
        wesp.biz_org_name AS bizOrgName,
        wesp.id,

        case wsd.status
        when '1' then '在位'
        when '2' then '执勤'
        when '3' then '维修'
        when '6' then '退役'
        when '7' then '报废'
        when '10' then '车载'
        when '11' then '损耗'
        when '12' then '配装'
        else '未入库' END as status
        ,
        ifNull( ed.delivery_date, "") AS putDate
        FROM wl_equipment_specific wesp
        LEFT JOIN wl_equipment_detail ed ON ed.id = wesp.equipment_detail_id
        LEFT JOIN wl_equipment eq ON eq.id = ed.equipment_id
        LEFT JOIN wl_manufacturer_info mi ON mi.id = ed.manufacturer_id
        LEFT JOIN wl_stock_detail wsd ON wsd.equipment_specific_id = wesp.id
        LEFT JOIN wl_warehouse_structure wws ON wsd.warehouse_structure_id = wws.id

        <where>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                wesp.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>

    </select>

    <select id="queryByCompanyCode" resultType="java.lang.String">
        SELECT biz_org_code
        FROM cb_org_usr
        WHERE is_delete = 0
        <if test="companyCode != null and companyCode != ''">
            AND code = #{companyCode}
        </if>
    </select>
    <select id="selectSystemByBizOrgCode" resultType="java.util.Map">
             SELECT ffs.id,ffs.`code`,ffs.system_type as type,ffs.biz_org_name  as stationName, ffs.name,wec.code AS typeCode
        FROM `f_fire_fighting_system` ffs
				LEFT JOIN wl_equipment_category wec
				on ffs.system_type = wec.id
             <where>
             <if test="bizOrgCode != null and bizOrgCode != ''">
                 biz_org_code like concat(#{bizOrgCode},'%')
             </if>
             </where>
        order by ffs.sort
    </select>
    <select id="selectAlarmList" resultType="java.util.Map">
        select
            a1.*,
            ABS(a1.num - a1.alarm_equip_num) as normalEquipNum,
            concat(FORMAT(  (abs( ( (a1.num - a1.alarm_equip_num) / IF ( a1.num = 0, 1, a1.num ) ) ) * 100
                                ),2), '%')  as normalEquipPercent,


            concat(FORMAT(      (
                                    abs( ( (a1.fault_equip_num) / IF ( a1.num = 0, 1, a1.num ) ) ) * 100
                                    ) ,2), '%') as faultEquipPercent,

            concat(FORMAT(      (
                                    abs( ( (a1.alarm_equip_num) / IF ( a1.num = 0, 1, a1.num ) ) ) * 100
                                    ) ,2), '%') as alarmEquipPercent
            from
            wl_analysis_report_month a1
            where
            a1.report_month = #{month}  and system_id = #{systemId}
    </select>
    <select id="selectMonthSummarize" resultType="java.util.Map">

				SELECT
            rs.system_id,
            rs.summary_info,
            rs.report_date,
            rs.report_type
             FROM
            `wl_analysis_report_summary` rs
            where
           rs.report_date like  concat(#{month},'%')
            and rs.report_type = 3
            and system_id = #{systemId}
    </select>
    <select id="selectMonthPieChart" resultType="java.util.Map">

        SELECT
        `name` as `type`,
        (SELECT count(distinct equipment_specific_id)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
        and report.index_type  LIKE  CONCAT('%','Fault')
        and report.index_true_num >0
        and report.report_date  BETWEEN #{startDate}
        and  #{endDate}
        )  as `value`
        FROM(
        SELECT
        s.id as system_id,
        equipment.code,
        equipment.name
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
        LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
        left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where spec.system_id is not null
        AND s.code = #{systemCode}
        GROUP BY code,s.id, name ORDER BY system_id, code ) a
    </select>
    <select id="selectMonthPieChartTwo" resultType="java.util.Map">
        	SELECT
        ss.alarm_type_name as type,
        	count(distinct(ss.equipment_specific_id)) as value
        from
        (
        SELECT
        rep.alarm_type,
        rep.alarm_type_name,
        rep.index_true_num,
        rep.equipment_specific_id
        FROM
        wl_equipment_alarm_report_day rep,
        (
        SELECT
          s.id as system_id,
          equipment.code,
          equipment.name
        FROM
          wl_equipment_specific spec
          LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
          LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
          left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where spec.system_id is not null
        and s.code = #{systemCode}
          GROUP BY s.id, code, name ORDER BY s.id, code
        ) a
        where rep.equipment_code = a.code and FIND_IN_SET(a.system_id,rep.system_ids)

        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            rep.index_type  like concat ('%', #{index})
        </foreach>
        and rep.index_true_num >0
        and rep.alarm_type is not null
        and rep.report_date BETWEEN #{startDate}
        and  #{endDate}
        ) ss
        GROUP BY ss.alarm_type_name
    </select>
    <select id="selectMonthPolyline" resultType="java.util.Map">

        SELECT * FROM (
        SELECT A.name as title, A.date as x, IFNULL(B.num,0) AS y  from
        (
        SELECT * from (
        SELECT
        DATE( DATE_ADD(#{startDate}, INTERVAL @s DAY ) ) AS date,
        '报警总条数' as name,
        @s := @s + 1 AS `index`
        FROM
        mysql.help_topic,
        ( SELECT @s := 0 ) temp ) s1
        WHERE
        s1.`index` &lt;= DATEDIFF(#{endDate},#{startDate})
        ) A
        LEFT JOIN (
        SELECT
        SUM( report.index_true_num ) AS num,
        report.report_date	AS reportDate
        FROM
        wl_equipment_alarm_report_day report
        LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids)
        WHERE  report.system_ids is not null


        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
             report.index_type  like concat ('%', #{index})
        </foreach>


        and s.code = #{systemCode}
        GROUP BY
        report.report_date,
        s.id
        ) B on B.reportDate =  A.date
        UNION  all
        SELECT A.name, A.date , IFNULL(B.num,0) AS num from
        (
        select * from (
        SELECT
        DATE( DATE_ADD( #{startDate}, INTERVAL @s2 DAY ) ) AS date,
        '报警设备总数' as name,
        @s2 := @s2 + 1 AS `index`
        FROM
        mysql.help_topic,
        ( SELECT @s2 := 0 ) temp ) s1
        WHERE
        s1.`index` &lt;= DATEDIFF(#{endDate},#{startDate})
        ) A
        LEFT JOIN (
        SELECT
        COUNT( distinct(report.equipment_specific_id)) AS num,
        report.report_date	AS reportDate
        FROM
        wl_equipment_alarm_report_day report
        LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids)
        WHERE
        report.system_ids is not null
        and s.code = #{systemCode}
        and report.index_true_num >0


        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>

        GROUP BY
        report.report_date,
        s.id
        ) B on B.reportDate =  A.date  ) C
        ORDER BY title,x
    </select>
    <select id="selectWeekReportList" resultType="java.util.Map">


        SELECT temp.name,temp.num,temp.normalNum,temp1.type_name ,   temp1.monitoringData,temp1.acquisition,temp1.normal,
        IFNULL(temp1.alarmEquipNum,0) AS alarmEquipNum, temp1.type_code,temp.code
        FROM
        (
            select
        a1.*,
        (a1.num - a1.exepctionNum) as normalNum
        from
        (SELECT
        system_id,
        num,
        name,
        code,
        (SELECT count(distinct equipment_specific_id)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        and( report.index_type  LIKE  CONCAT('%','FireAlarm','%')
                            or report.index_type  LIKE  CONCAT('%','Fault','%')
                            or report.index_type  LIKE  CONCAT('%','Shield','%')
                                  or report.index_type  LIKE  CONCAT('%','Open','%')
                          or report.index_type  LIKE  CONCAT('%','OilLeak','%')
                          or report.index_type  LIKE  CONCAT('%','Alarm','%')	)
        and report.index_true_num > 0 and report.report_date >=  #{startDate} and
         report.report_date &lt;=  #{endDate})  as exepctionNum
        FROM(
        SELECT
          s.id as system_id,
          equipment.code,
          equipment.name,
          count(1) AS num
        FROM
          wl_equipment_specific spec
          LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
          LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
          left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where  FIND_IN_SET( #{systemId},spec.system_id) AND equipment.is_iot = 1
          GROUP BY code,s.id, name ORDER BY system_id, code ) a) as  a1


            ) temp
            LEFT JOIN




            (



        SELECT temp.*,
        CASE
        WHEN wei.is_trend = 0 then "遥信"
        WHEN wei.is_trend = 1 then "遥测"
        ELSE "/"
        END AS monitoringData
         FROM
        (
        SELECT
        spec_index.equipment_index_id,
          s.id as systemId,
          spec.equipment_code as code,
            spec_index.equipment_index_name AS type_name,
            spec_index.equipment_index_key AS type_code,

	'自动获取' AS acquisition,
	CASE
	WHEN spec_index.equipment_index_key LIKE CONCAT('%', 'Fault') THEN
		'无故障'
	WHEN spec_index.equipment_index_key LIKE CONCAT('%', 'Shield') THEN
		'无屏蔽'
	ELSE
		'/'
	END AS normal,
	IFNULL(
		(
			SELECT
				sum(e.report_equip_num)
			FROM
				wl_equipment_alarm_equip_day e
			WHERE
				e.system_id is not null
        and  FIND_IN_SET( #{systemId},e.system_id)
          AND e.equipment_code = spec.equipment_code
          AND e.index_key = spec_index.equipment_index_key
          AND e.report_date >= DATE_FORMAT(#{startDate},'%y-%m-%d')
        AND e.report_date &lt;= DATE_FORMAT(#{endDate},'%y-%m-%d')
		),
		0
            ) AS alarmEquipNum
        FROM
            wl_equipment_specific_index spec_index
          JOIN wl_equipment_specific spec ON spec_index.equipment_specific_id = spec.id

          join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)

         WHERE FIND_IN_SET( #{systemId},spec.system_id)

        GROUP BY systemId,code,type_code
        )temp LEFT JOIN wl_equipment_index wei on temp.equipment_index_id = wei.id

        )temp1  on  temp.system_id = temp1.systemId and temp.code = temp1.code
        group by type_code
       ORDER BY temp.name
    </select>
    <select id="selectAlarms" resultType="java.lang.Integer">
        SELECT
            ifnull(SUM(index_true_num), 0)
        FROM
        wl_equipment_alarm_report_day report
        LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids )
        LEFT JOIN wl_equipment_specific spec on report.equipment_specific_id = spec.id
        where report.system_ids is not null  and report.index_true_num > 0

        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>

        and report.report_date BETWEEN #{startDate} and  #{endDate}
        and system_id = #{systemId}
        and  index_type = #{indexType}
        and   report.equipment_code = #{equipmentCode}
    </select>
    <select id="selectWeekSummarize" resultType="java.util.Map">
        SELECT
        fs.name, b.equipNum, b.normalNum,  b.normalRate, b.faultNum,  b.faultRate,
       b.exepctionNum, b.status1,exepctionWOW,
        b.alarmNum,b.status2,alarmWOW,
        fs.id as system_id
        FROM
        f_fire_fighting_system fs left join
        (
        select
        SUM(a1.num) AS equipNum,
        SUM( (a1.num - a1.exepctionNum))as normalNum,
        SUM(a1.faultNum) as faultNum,
        a1.systemName,
        a1.system_id,
        SUM(a1.exepctionNum) as exepctionNum,
        SUM(a1.lastExepctionNum) as lastExepctionNum,
        SUM(a1.alarmNum) as alarmNum,
        SUM(a1.lastAlarmNum) as lastAlarmNum,
        if (SUM(a1.lastExepctionNum)>0,IFNULL( convert( ABS(SUM(a1.exepctionNum)-SUM(a1.lastExepctionNum))/SUM(a1.lastExepctionNum),char(5)),'-'),ABS(SUM(a1.exepctionNum)-SUM(a1.lastExepctionNum)))*100 as exepctionWOW,
        if (SUM(a1.lastAlarmNum)>0,IFNULL( convert( ABS(SUM(a1.alarmNum)-SUM(a1.lastAlarmNum))/SUM(a1.lastAlarmNum),char(5)),'-'),ABS(SUM(a1.alarmNum)-SUM(a1.lastAlarmNum)))*100  as alarmWOW,
        (CASE WHEN (SUM(a1.exepctionNum)-SUM(a1.lastExepctionNum)) &lt;0 THEN '减少' else '增加' end )  as status1,
        (CASE WHEN (SUM(a1.alarmNum)-SUM(a1.lastAlarmNum)) &lt;0 THEN '减少' else '增加' end )  as status2,
        FORMAT(
        IF
        (
        SUM( a1.num ) > 0,
        (
        abs(
        (
        SUM( a1.num - a1.exepctionNum ) /
        IF
        ( SUM( a1.num ) = 0, 1, SUM( a1.num ) )
        )
        )
        ),
        SUM( a1.num - a1.exepctionNum )
        ) * 100,
        2
        ) AS normalRate,
        FORMAT(
        IF
        (
        SUM( a1.num ) > 0,
        (
        abs(
        (
        SUM( a1.faultNum ) /
        IF
        ( SUM( a1.num ) = 0, 1, SUM( a1.num ) )
        )
        )
        ),
        SUM( a1.faultNum )
        ) * 100,
        2
        ) AS faultRate,
        a1.create_date
        from
        (SELECT
        system_id,
        num,
        name,
        code,
        create_date,
        (SELECT IFNULL(count(distinct equipment_specific_id) ,0)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        and report.index_true_num >0
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and report.report_date >= #{startDate} and  report.report_date &lt;=#{endDate} )  as exepctionNum,
        (SELECT IFNULL(count(distinct equipment_specific_id) ,0)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        and report.index_true_num >0
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and  report.report_date >= DATE_SUB(#{startDate},INTERVAL 7 DAY)
        and report.report_date &lt;= DATE_SUB(#{endDate},INTERVAL 7 DAY)  )  as lastExepctionNum,
        (SELECT IFNULL(SUM(index_true_num ),0)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and report.report_date >= #{startDate} and  report.report_date &lt;=#{endDate}  )  as alarmNum,
        (SELECT IFNULL(count(distinct equipment_specific_id) ,0)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        and report.index_true_num >0
        and( report.index_type  LIKE  CONCAT('%','Fault','%'))
        and report.report_date >= #{startDate} and  report.report_date &lt;=#{endDate} )  as faultNum,
        (SELECT IFNULL(SUM(index_true_num ),0)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>

        and  report.report_date >= DATE_SUB(#{startDate},INTERVAL 7 DAY)
        and report.report_date &lt;= DATE_SUB(#{endDate},INTERVAL 7 DAY)  )  as lastAlarmNum,
        systemName
        FROM(
        SELECT
        s.id as system_id,
        equipment.code,
        equipment.name,
        count(1) AS num,
        s.name as systemName,
        spec.create_date
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
        LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
        left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where FIND_IN_SET(#{systemId} , spec.system_id)  and spec.create_date &lt; #{endDate}
        GROUP BY code,s.id, name ORDER BY system_id, code ) a) as  a1
        GROUP BY a1.system_id
        ) as b
        on fs.id = b.system_id

        WHERE fs.id = #{systemId}
    </select>
    <select id="selectWeekEquipEchart" resultType="java.util.Map">
        SELECT
        (
        select
        SUM(a1.num-a1.exepctionNum) AS num
        from
        (SELECT
        system_id,
        system_code,
        num,
        code,
        (SELECT count(distinct equipment_specific_id)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and report.index_true_num>0
        and report.report_date >= #{startDate}
        and report.report_date &lt;= #{endDate}  )  as exepctionNum,
        create_date
        FROM(
        SELECT
        s.id as system_id,
        s.code as system_code,
        equipment.code,
        count(1) AS num,
        spec.create_date
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
        LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
        left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where spec.system_id is not null  and spec.create_date &lt; #{endDate}
        GROUP BY code,s.id ORDER BY system_id, code ) a) as  a1
        WHERE system_code = #{systemCode}
        GROUP BY a1.system_id
        ) as value,
        '正常设备' as type
        union
        SELECT
        (
        select
        SUM(a1.exepctionNum)as exepctionNum
        from
        (SELECT
        system_id,
        system_code,
        num,
        code,
        (SELECT count(distinct equipment_specific_id)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and report.index_true_num>0
        and report.report_date between #{startDate}
        and #{endDate} )  as exepctionNum
        FROM(
        SELECT
        s.id as system_id,
        s.code as system_code,
        equipment.code,
        count(1) AS num,
        spec.create_date
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
        LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
        left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where spec.system_id is not null  and spec.create_date &lt; #{endDate}
        GROUP BY code,s.id ORDER BY system_id, code ) a) as  a1
        WHERE system_code = #{systemCode}
        GROUP BY a1.system_id
        ) as value,
        '异常设备' as type
    </select>
    <select id="selectWeekEchart" resultType="java.util.Map">
        SELECT
        count( DISTINCT(report.equipment_specific_id) ) AS `value`,
        equipment.NAME  AS `type`
        FROM
        wl_equipment_alarm_report_day report
        LEFT JOIN wl_equipment equipment ON equipment.CODE = report.equipment_code
        LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids )
        WHERE
        report.system_ids is not null
        and report.index_type  LIKE  CONCAT('%','Fault')
        and report.index_true_num >0
        AND s.code = #{systemCode}
        and report.report_date between #{startDate} and #{endDate}
        GROUP BY
        report.equipment_code,
        s.id
    </select>
    <select id="selectWeekLinesEchart" resultType="java.util.Map">

        SELECT * FROM (
        SELECT A.name as title, A.date as x, IFNULL(B.num,0) AS y from
        (
        select * from (SELECT
        @s := @s + 1 AS `index`,
        DATE( DATE_SUB( #{endDate}, INTERVAL @s-1 DAY ) ) AS date,
        '告警条数' as name
        FROM
        mysql.help_topic,
        ( SELECT @s := 0 ) temp ) s
        WHERE
        s.`index` &lt;= 7
        ) A
        LEFT JOIN (
        SELECT
        SUM( report.index_true_num ) AS num,
        report.report_date	AS reportDate
        FROM
        wl_equipment_alarm_report_day report
        LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids)
        WHERE  report.system_ids is not null
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and s.code = #{systemCode}
        GROUP BY
        report.report_date,
        s.id
        ) B on B.reportDate =  A.date
        UNION  all
        SELECT A.name, A.date , IFNULL(B.num,0) AS num from
        (
        select * from (SELECT
        @s1 := @s1 + 1 AS `index`,
        DATE( DATE_SUB( #{endDate}, INTERVAL @s1-1 DAY ) ) AS date,
        '告警设备' as name
        FROM
        mysql.help_topic,
        ( SELECT @s1 := 0 ) temp ) s
        WHERE
        s.`index` &lt;= 7
        ) A
        LEFT JOIN (
        SELECT
        COUNT(DISTINCT(report.equipment_specific_id) ) AS num,
        report.report_date	AS reportDate
        FROM
        wl_equipment_alarm_report_day report
        LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids)
        WHERE  report.system_ids is not null
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and report.index_true_num >0
        and s.code = #{systemCode}
        GROUP BY
        report.report_date,
        s.id
        ) B on B.reportDate =  A.date  ) C
        ORDER BY x
    </select>
    <select id="selectDaySummarize" resultType="java.util.Map">
        SELECT
         fs.name,  b.equipNum, ( b.equipNum - b.normalNum) as dayNum,ifnull(b.alarmNum, 0)  as alarmNum
         , b.normalNum, b.normalRate,
        fs.id as system_id
        FROM
        f_fire_fighting_system fs left join
        (
        select
        SUM(a1.num) AS equipNum,
        SUM( (a1.num - a1.exepctionNum))as normalNum,
        a1.systemName,
        a1.system_id,
        a1.alarmNum,
        FORMAT(if(  SUM(a1.num)>0,SUM(a1.num - a1.exepctionNum)/SUM(a1.num),SUM(a1.num - a1.exepctionNum))*100,2) as normalRate,
        a1.create_date
        from
        (SELECT
        system_id,
        num,
        name,
        code,
        create_date,
        (SELECT count(distinct equipment_specific_id)
        FROM wl_equipment_alarm_report_day report
        where report.equipment_code = a.code
        and FIND_IN_SET(a.system_id,report.system_ids)
        and  report.index_true_num >0
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>

        and report.report_date >= #{startDate} and report.report_date &lt;= #{endDate} )  as exepctionNum,
        (SELECT SUM(index_true_num)
        FROM wl_equipment_alarm_report_day report
        where FIND_IN_SET(a.system_id,report.system_ids)
        <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
            report.index_type  like concat ('%', #{index})
        </foreach>
        and report.report_date >= #{startDate}
        and report.report_date &lt;= #{endDate}
        )  as alarmNum,
        systemName
        FROM(
        SELECT
        s.id as system_id,
        equipment.code,
        equipment.name,
        count(1) AS num,
        s.name as systemName,
        spec.create_date
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
        LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
        left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where
        FIND_IN_SET(#{systemId},spec.system_id)
         AND equipment.is_iot = 1
        GROUP BY code,s.id, name ORDER BY system_id, code ) a) as  a1
        GROUP BY a1.system_id
        ) as b
        on fs.id = b.system_id
        WHERE fs.id = #{systemId}
    </select>
    <select id="selectDayEquipEchart" resultType="java.util.Map">
        SELECT

        num as `value`,
        name as `type`

        FROM(
        SELECT
        s.id as system_id,
        s.code as system_code,
        equipment.code,
        equipment.name,
        count(1) AS num,
        s.name as systemName
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
        LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
        left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
        where spec.system_id is not null AND equipment.is_iot = 1
        GROUP BY code,s.id, name ORDER BY system_id, code ) a WHERE system_code = #{systemCode}

    </select>
    <select id="selectDayEchart" resultType="java.util.Map">



        SELECT

        (SELECT COUNT(DISTINCT iot_code) FROM wl_equipment_specific WHERE  FIND_IN_SET(#{systemId},system_id)
         and iot_code is not null) AS value,'正常设备' AS type

        UNION
        (

        SELECT

        (SELECT COUNT(DISTINCT wesa.iot_code) AS exepctionNum FROM wl_equipment_specific_alarm wesa
        WHERE FIND_IN_SET(#{systemId},wesa.system_ids)

                <foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
                    wesa.equipment_specific_index_key  like concat ('%', #{index})
                </foreach>

        and wesa.create_date
        like CONCAT(#{date},'%'))AS value,'异常设备'as type

        )

    </select>
    <select id="getSystemInfo" resultType="java.util.Map">
        SELECT
        temp.*,
        CASE

        WHEN temp.notReturnd > 0 THEN
        '0' ELSE '1'
        END AS status
        FROM
        (
        SELECT
        fs.id,
        fs.name,
        fs.code,
        ( SELECT COUNT( DISTINCT(wesa.iot_code) ) FROM wl_equipment_specific_alarm wesa WHERE FIND_IN_SET( fs.id, wesa.system_ids ) AND wesa.create_date like concat(DATE_FORMAT(NOW(),'%Y-%m-%d')) ) AS total,
        ( SELECT COUNT( DISTINCT(wesa.iot_code) ) FROM wl_equipment_specific_alarm wesa WHERE FIND_IN_SET( fs.id, wesa.system_ids ) AND wesa.equipment_specific_index_value = 'true' AND wesa.create_date like concat(DATE_FORMAT(NOW(),'%Y-%m-%d'))) AS notReturnd
        FROM
        f_fire_fighting_system fs

        ) temp
        ORDER BY
        temp.notReturnd DESC

    </select>

    <select id="systemAndEquipment" resultType="java.util.Map">
        SELECT
            a.id,
            a.`name`,
            a.code,
            a.sort,
            substring_index(
                    substring_index(
                            a.parentId,
                            ',',
                            b.help_topic_id + 1
                        ),
                    ',' ,- 1
                ) AS parentId,
            a.bizOrgCode
        FROM
            (
                (
                    SELECT
                        ffs.`id`,
                        ffs.`name`,
                        ffs.`code`,
                        sort,
                        '' parentId,
                        ffs.biz_org_code bizOrgCode
                    FROM
                        f_fire_fighting_system ffs
                    WHERE
                        ffs.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%' )
                )  UNION
                (
                    SELECT
                        wes.id,
                        wes.`name`,
                        wes.`code`,
                        0,
                        wes.system_id parentId,
                        wes.biz_org_code bizOrgCode
                    FROM
                        f_fire_fighting_system ffs
                            LEFT JOIN wl_equipment_specific wes ON wes.system_id = ffs.id
                    WHERE
                        wes.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%' )
                )
            )a
                JOIN mysql.help_topic b ON b.help_topic_id &lt; (
                        length(a.parentId) - length(
                            REPLACE (a.parentId, ',', '')
                        ) + 1
                )
        ORDER BY parentId, sort
    </select>

    <select id="selectEquipCountBySystemId" resultType="java.lang.Long">
        SELECT
            count(1) num
        FROM
            wl_equipment_specific AS spe
        where
            spe.system_id = #{systemId}
    </select>

    <select id="selectEquipSystemType" resultType="java.lang.String">
        SELECT
            group_name
        FROM
            f_fire_fighting_system ffs
                LEFT JOIN wl_dynamic_form_group wdfg ON ffs.form_group_id = wdfg.id
        WHERE
            ffs.code = #{code}
    </select>

    <select id="getWaterInfoBySuper" resultType="java.util.Map">
        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
        '2'
        WHEN nowLevel IS NOT NULL
        AND minLevel IS NOT NULL AND nowLevel != '--'
        AND minLevel - nowLevel > 0 THEN
        '0' ELSE '4'
        END
        ) AS `status`
        from (
        (SELECT
        r.`name`,
        IFNULL( rp.min_water_level, 0 ) AS minLevel,
        IFNULL( rp.max_water_level, 0 ) AS maxLevel,
--         IFNULL(max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_WaterLevel' or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel' THEN ei.`value` END ),'--')  AS nowLevel,
        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' THEN ei.`unit` END,'--')  AS 'unit',
        IFNULL( rp.volume, 0 ) AS volume,
        ec.image,
        r.resource_type,
        r.sequence_nbr,
        wes.code
        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
        <if test="bizOrgCode!=null and bizOrgCode!=''">
            AND r.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        GROUP BY
        r.sequence_nbr) union all
        (
        SELECT
        a.`name`,
        a.minLevel,
        a.maxLevel,
        IFNULL( a.nowLevel, '--' ) nowLevel,
        a.`unit`,
        a.volume,
        a.image,
        a.resource_type,
        a.sequence_nbr,
        a.code
        FROM
        (
        SELECT
        r.`name`,
        IFNULL( rp.min_water_level, 0 ) AS minLevel,
        IFNULL( rp.max_water_level, 0 ) AS maxLevel,
        (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
            -- or ei.equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel' 此处由于单位会出现多个，所以无法确定选择哪一个，所以此处默认用一个指标的单位进行单位换算
        ei.equipment_index_key = 'FHS_FirePoolDevice_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
        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
        <if test="bizOrgCode!=null and bizOrgCode!=''">
            AND r.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        GROUP BY
        r.sequence_nbr
        ) a
        )) b
        ORDER BY
        status ASC
    </select>

    <select id="getFoamTankBySuper" resultType="java.util.Map">

        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 '2'
		WHEN nowLevel IS NOT NULL
		AND minLevel IS NOT NULL
		AND nowLevel != '--'
		AND minLevel - nowLevel > 0 THEN '0'
		ELSE '4'
	END ) AS `status`
        from
            (
                SELECT
                    a.`name`, IFNULL( a.nowLevel, '--' ) AS nowLevel, a.id, IFNULL( a.image, '' ) AS image, a.unit, a.minLevel AS minLevel, a.maxLevel AS maxLevel, (
                    CASE
                        WHEN a.nowLevel IS NULL
                            OR a.minLevel IS NULL THEN '--'
                        WHEN a.minLevel - a.nowLevel > 0 THEN '缺水'
                        ELSE '正常'
                        END ) AS levelStatus, 'foamTank' AS type
                FROM
                    (
                        SELECT
                            ed.`name`, es.iot_code, es.id, ec.image, ei.unit, max( CASE WHEN ei.equipment_index_key = 'CAFS_FoamTank_FoamTankLevel' THEN ei.`value` END ) AS nowLevel, max( CASE WHEN fi.field_name = 'minLevel' THEN fi.field_value END ) AS minLevel, max( CASE WHEN fi.field_name = 'maxLevel' THEN fi.field_value END ) AS maxLevel
                        FROM
                            wl_equipment_specific es
                                LEFT JOIN wl_equipment_detail ed ON
                                es.equipment_detail_id = ed.id
                                LEFT JOIN wl_equipment_specific_index ei ON
                                es.id = ei.equipment_specific_id
                                LEFT JOIN wl_equipment e ON
                                e.id = ed.equipment_id
                                LEFT JOIN wl_equipment_category ec ON
                                e.category_id = ec.id
                                LEFT JOIN wl_form_instance_equip fi ON
                                fi.instance_id = es.id
                        WHERE
                            ed.`code` LIKE '92031900%'
                          AND es.biz_org_code LIKE concat(#{bizOrgCode}, '%')
                          AND es.iot_code IS NOT NULL
                        GROUP BY
                            es.id ) a
                UNION ALL
                SELECT
                    a.`name`, IFNULL( a.nowLevel, '--' ) AS nowLevel, a.id, IFNULL( a.image, '' ) AS image, 'M' AS unit, a.minLevel AS minLevel, a.maxLevel AS maxLevel, (
                    CASE
                        WHEN a.nowLevel IS NULL
                            OR a.minLevel IS NULL THEN '--'
                        WHEN a.minLevel - a.nowLevel > 0 THEN '缺水'
                        ELSE '正常'
                        END ) AS levelStatus, a.type AS type
                FROM
                    (
                        SELECT
                            r.`name`, IFNULL( rp.min_water_level, 0 ) AS minLevel, IFNULL( rp.max_water_level, 0 ) AS maxLevel, (
                            SELECT
                                FORMAT( avg( IFNULL( ei.`value`, 0 ) ), 2 )
                            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, ec.image, r.resource_type AS type, r.sequence_nbr AS id
                        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
                        WHERE
                            r.resource_type = 'waterTank'
                          AND r.biz_org_code LIKE concat(#{bizOrgCode}, '%')
                          AND r.is_delete = 1
                        GROUP BY
                            r.sequence_nbr ) a
                ORDER BY
                    levelStatus DESC ) as b order by status asc
    </select>

    <select id="getPipeNetworkBySuper" resultType="java.util.Map">
        SELECT
            a.`name`,
            'FHS_PipePressureDetector_PipePressure' nameKey,
            (CASE WHEN
            LENGTH(trim(a.area)) = 0 THEN '--'
            ELSE
            IFNULL(a.area, '--') END) AS area,
            a.id,
            IFNULL(ROUND(a.nowPressure, 2 ), '--') AS nowPressure,
            a.nowPressureDate,
            (
                CASE
                    WHEN nowPressure IS NOT NULL
                        AND maxLevel IS NOT NULL
                        AND nowPressure - maxLevel > 0 THEN
                    '压力高'
                    WHEN nowPressure IS NOT NULL
                        AND minLevel IS NOT NULL
                        AND nowPressure -  minLevel >= 0 THEN
                        '正常'
                    WHEN nowPressure IS NOT NULL
                        AND minLevel IS NOT NULL
                        AND minLevel - nowPressure > 0 THEN
                        '压力低' ELSE '--'
                    END
                ) AS `status`
        FROM
            (
                SELECT
                    ed.`name`,
                    concat_ws( '-', es.position, es.`name` ) area,
                    es.id,
                    max( CASE WHEN ei.equipment_index_key = 'FHS_PipePressureDetector_PipePressure' THEN ei.`value` END ) AS nowPressure,
                    IF
                        ((
                             max( CASE WHEN ei.equipment_index_key = 'FHS_PipePressureDetector_PipePressure' THEN ei.`value` END ) IS NOT NULL
                             ),
                         max( CASE WHEN ei.equipment_index_key = 'FHS_PipePressureDetector_PipePressure' THEN DATE_FORMAT( ei.`update_date`, '%m-%d %H:%i:%S' ) END ),
                         '--'
                        ) AS nowPressureDate,
                    max( CASE WHEN fi.field_name = 'minPressure' THEN fi.field_value END ) AS minLevel,
                    max( CASE WHEN fi.field_name = 'maxPressure' THEN fi.field_value END ) AS maxLevel
                FROM
                    wl_equipment_specific es
                        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
                        LEFT JOIN wl_equipment_specific_index ei ON es.id = ei.equipment_specific_id
                        LEFT JOIN wl_form_instance_equip fi ON fi.instance_id = es.id
                WHERE
                    ed.`code` LIKE '92011000%'
<!--                  AND es.iot_code IS NOT NULL-->
                    <if test="bizOrgCode!=null and bizOrgCode!=''">
                        AND es.biz_org_code like concat(#{bizOrgCode}, '%')
                    </if>
                GROUP BY
                    es.id
            ) a ORDER BY FIELD(status,'压力低','正常','--')
    </select>

    <select id="getInfluentFlowBySuper" resultType="java.util.Map">
        SELECT
            ed.`name`,
            IFNULL(concat_ws( '-', ws.full_name, ed.area ), '') AS area,
            es.id,
            IF
                (
                        CONCAT(IFNULL( max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_InfluentFlow' THEN ei.`value` END ), '--' ), '')  = '--',
                        '--',
                        TRUNCATE (max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_InfluentFlow' THEN ei.`value` END ), 2)) AS nowInfluentFlow,
            IF
                ((
                     max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_InfluentFlow' THEN ei.`value` END ) IS NOT NULL
                     ),
                 max( CASE WHEN ei.equipment_index_key = 'FHS_FirePoolDevice_InfluentFlow' THEN DATE_FORMAT( ei.`update_date`, '%m-%d %H:%i:%S' ) END ),
                 '--'
                ) AS nowInfluentFlowDate
        FROM
            wl_equipment_specific es
                LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
                LEFT JOIN wl_warehouse_structure ws ON ws.id = es.warehouse_structure_id
                LEFT JOIN wl_equipment_specific_index ei ON es.id = ei.equipment_specific_id
                LEFT JOIN wl_form_instance_equip fi ON fi.instance_id = es.id
        WHERE
            ed.`code` LIKE '92010700%'
          AND es.iot_code IS NOT NULL
          AND es.biz_org_code LIKE concat(#{bizOrgCode}, '%')
        GROUP BY
            es.id
    </select>

    <select id="getSystemStatus" resultType="java.lang.Integer">
        SELECT
            count( DISTINCT equipment_specific_id ) AS isAlarm
        FROM
            wl_equipment_specific_index
        WHERE
                equipment_specific_id IN (
                SELECT
                    wl.id
                FROM
                    wl_equipment_specific wl
                WHERE
                        FIND_IN_SET( ( SELECT f.id FROM f_fire_fighting_system f WHERE `code` = #{systemCode} ), system_id ) > 0
                  AND biz_org_code LIKE concat(#{bizOrgCode}, '%')
            )
          AND ((
                           `is_alarm` = 1
                       AND `value` = 'true'
                   )
            OR ( `is_alarm` = 0 AND `value` = 'false' ))
    </select>
    <select id="queryStartAndStopBySpecificId" resultType="java.util.Map">
       ( SELECT
        i.equipment_specific_id,
        DATE_FORMAT(i.update_date,'%Y-%m-%d %H:%i:%S') update_date,
        i.equipment_index_name
        FROM
        wl_equipment_specific_index i
        WHERE
        <if test="ids != null and ids.size > 0">
            i.equipment_specific_id  IN
            <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
            AND
        </if>
        i.equipment_index_key in ('FHS_PressurePump_Start')
        and i.value = 'true'
        ORDER BY
        i.update_date DESC
           limit 1
        ) union
       (
        SELECT
        i.equipment_specific_id,
        DATE_FORMAT(i.update_date,'%Y-%m-%d %H:%i:%S') update_date,
        i.equipment_index_name
        FROM
        wl_equipment_specific_index i
        WHERE
        <if test="ids != null and ids.size > 0">
            i.equipment_specific_id  IN
            <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
            AND
        </if>
        i.equipment_index_key in ('FHS_PressurePump_Stop')
        and i.value = 'true'
        ORDER BY
        i.update_date DESC
        limit 1
        )
    </select>
    <select id="queryStateBySpecificId" resultType="java.util.Map">
        SELECT
            i.update_date,
            i.equipment_index_name
        FROM
            wl_equipment_specific_index i
        WHERE
            i.equipment_specific_id = #{id,jdbcType=VARCHAR}
          AND i.equipment_index_key in ('FHS_PressurePump_Start', 'FHS_PressurePump_Stop')
        ORDER BY
            i.update_date DESC
    </select>

    <select id="getFoamTankLevel" resultType="java.util.Map">
        SELECT
            IF
                (
                        max( CASE WHEN fi.field_name = 'minLevel' THEN fi.field_value END ) = ''
                        OR max( CASE WHEN fi.field_name = 'minLevel' THEN fi.field_value END ) IS NULL,
                        0,
                        max( CASE WHEN fi.field_name = 'minLevel' THEN fi.field_value END )) AS minValues,
            IF
                (
                        max( CASE WHEN fi.field_name = 'maxLevel' THEN fi.field_value END ) = ''
                        OR max( CASE WHEN fi.field_name = 'maxLevel' THEN fi.field_value END ) IS NULL,
                        1000,
                        max( CASE WHEN fi.field_name = 'maxLevel' THEN fi.field_value END )) AS maxValues
        FROM
            wl_form_instance_equip fi
        WHERE
            fi.instance_id = #{equipSpeId}
    </select>

    <select id="getPipeNetwork" resultType="java.util.Map">
        SELECT
            IF
                (
                        max( CASE WHEN fi.field_name = 'minPressure' THEN fi.field_value END ) = ''
                        OR max( CASE WHEN fi.field_name = 'minPressure' THEN fi.field_value END ) IS NULL,
                        0,
                        max( CASE WHEN fi.field_name = 'minPressure' THEN fi.field_value END )) AS minValues,
            IF
                (
                        max( CASE WHEN fi.field_name = 'maxPressure' THEN fi.field_value END ) = ''
                        OR max( CASE WHEN fi.field_name = 'maxPressure' THEN fi.field_value END ) IS NULL
                        OR max( CASE WHEN fi.field_name = 'maxPressure' THEN fi.field_value END ) = 'null',
                        1000,
                        max( CASE WHEN fi.field_name = 'maxPressure' THEN fi.field_value END )) AS maxValues
        FROM
            wl_form_instance_equip fi
        WHERE
            fi.instance_id = #{equipSpeId}
    </select>

    <select id="getWaterPoolLevel" resultType="java.util.Map">
        SELECT
            ifnull(r.`name`, '') as name,
            r.sequence_nbr AS id,
            ifnull(r.resource_type, '') as resourceType,
            ifnull(rp.min_water_level, 0) AS minValues,
            ifnull(rp.max_water_level, 0) AS maxValues,
            ifnull(rp.level_device_id, '') as levelDeviceId
        FROM
            cb_water_resource_pool rp
                LEFT JOIN cb_water_resource r ON r.sequence_nbr = rp.resource_id
        WHERE
            FIND_IN_SET( #{equipSpeId}, rp.level_device_id )
        ORDER BY
            rp.rec_date DESC
            LIMIT 1
    </select>

    <select id="getWaterPoolLevelByEquipSpeId" resultType="java.math.BigDecimal">
        SELECT
            IFNULL( max( CASE WHEN equipment_index_key = 'FHS_FirePoolDevice_WaterLevel'  or equipment_index_key = 'FHS_WirelessliquidDetector_WaterLevel' THEN `value` END ), 0 )
        FROM
            wl_equipment_specific_index
        WHERE
            equipment_specific_id = #{equipSpeId}
    </select>

    <select id="getEquipExpiryStatistics" resultType="java.util.Map">
        SELECT
        a.equipSortName AS `name`,
        count( 1 ) AS `value`
        FROM
        (
        SELECT
        es.id,
        ed.`name`,
        ed.standard,
        DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ) AS passDate,
        DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE ) AS dayNum,
        DATE_FORMAT( ed.production_date, '%Y-%m-%d' ) AS productDate,
        e.`name` AS equipSortName,
        e.id AS equipSortId
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
        LEFT JOIN wl_stock_detail sd ON sd.equipment_detail_id = ed.id
        WHERE
        ed.production_date IS NOT NULL
        AND ( (sd.`status` != 7) or (sd.`status` is null) or (sd.`status` = ''))
        AND e.expiry_date IS NOT NULL
        AND es.biz_org_code like concat(#{bizOrgCode}, '%')
<!--        AND DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE ) > 0-->
        AND #{expiryDayNum} >= DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE )
        ) a
        GROUP BY
        a.equipSortId
    </select>

    <select id="getEquipExpiryListByPage" resultType="java.util.Map">
        SELECT
        es.id AS specificId,
        ed.`name` AS specificName,
        IFNULL( ed.standard, '' ) AS modelNumber,
        DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ) AS passDate,
        DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE ) AS dayNum,
        DATE_FORMAT( ed.production_date, '%Y-%m-%d' ) AS productDate,
        e.`name` AS equipSortName,
        e.id AS equipSortId,
        IFNULL( ws.full_name, '' ) AS equipAddress
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = es.warehouse_structure_id
        LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
        LEFT JOIN wl_stock_detail sd ON sd.equipment_detail_id = ed.id
        WHERE
        ed.production_date IS NOT NULL
        AND ( (sd.`status` != 7) or (sd.`status` is null) or (sd.`status` = ''))
        AND e.expiry_date IS NOT NULL
        AND es.biz_org_code like concat(#{bizOrgCode}, '%')
<!--        AND DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE ) > 0-->
        AND #{expiryDayNum} >= DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE )
        ORDER BY DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE ) ASC
    </select>

    <select id="getStockEquipStatistics" resultType="java.util.Map">
        SELECT
        '本月已报废' AS `content`,
        'upload/equipment_category_icon/byybf.png' AS image,
        (
        SELECT
        count( 1 )
        FROM
        wl_stock_detail sd
        LEFT JOIN wl_equipment_specific es ON es.id = sd.equipment_specific_id
        WHERE
        sd.`status` = 7
        AND update_date LIKE CONCAT( DATE_FORMAT( CURRENT_DATE, '%Y-%m' ), '%' )
        AND es.biz_org_code LIKE concat(#{bizOrgCode}, '%')
        ) AS countNum UNION ALL
        SELECT
        '累计报废装备' AS `content`,
        'upload/equipment_category_icon/ljbf.png' AS image,
        (
        SELECT
        count( 1 )
        FROM
        wl_stock_detail sd
        LEFT JOIN wl_equipment_specific es ON es.id = sd.equipment_specific_id
        WHERE
        sd.`status` = 7
        AND es.biz_org_code LIKE concat(#{bizOrgCode}, '%')
        ) AS countNum UNION ALL
        SELECT
        '超期未报废' AS `content`,
        'upload/equipment_category_icon/cqwbf.png' AS image,
        (
        SELECT
        count( es.id )
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
        LEFT JOIN wl_stock_detail sd ON sd.equipment_detail_id = ed.id
        WHERE
        ed.production_date IS NOT NULL
        AND ( (sd.`status` != 7) or (sd.`status` is null) or (sd.`status` = ''))
        AND e.expiry_date IS NOT NULL
        AND es.biz_org_code LIKE concat(#{bizOrgCode}, '%')
        AND 0 >= DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE )
        ) AS countNum UNION ALL
        SELECT
        '近2月临期设备' AS `content`,
        'upload/equipment_category_icon/j2ylqsb.png' AS image,
        (
        SELECT
        count( es.id )
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
        LEFT JOIN wl_stock_detail sd ON sd.equipment_detail_id = ed.id
        WHERE
        ed.production_date IS NOT NULL
        AND ( (sd.`status` != 7) or (sd.`status` is null) or (sd.`status` = ''))
        AND e.expiry_date IS NOT NULL
        AND es.biz_org_code LIKE concat(#{bizOrgCode}, '%')
<!--        AND DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE ) > 0-->
        AND 60 >= DATEDIFF( DATE_ADD( DATE_FORMAT( ed.production_date, '%Y-%m-%d' ), INTERVAL e.expiry_date YEAR ), CURRENT_DATE )
        ) AS countNum
    </select>
    <select id="getSystemInfoList" resultType="java.util.Map">
        SELECT
            fs.id AS `key`,
            fs.`code`,
            fs.`name`,
            fs.system_type_code AS systemTypeCode,
            CASE WHEN (SELECT
                           count(1)
                       FROM
                           wl_equipment_specific_alarm
                       WHERE `status` = 1 AND find_in_set(fs.id,system_ids))>0 THEN
                '异常'
                ELSE '正常'
                END as 'status'
        FROM
            f_fire_fighting_system fs
        where system_type_code IS NOT NULL AND LENGTH(trim(system_type_code)) != 0
    </select>
    <select id="getSystemAlarmInfoList" resultType="java.util.Map">
        SELECT
        `fs`.`id` AS `id`,
        `fs`.`code` AS `code`,
        `fs`.`name` AS `name`,
        (
        SELECT
        count( 1 )
        FROM
        `wl_equipment_specific_alarm_log`
        WHERE
        0 <![CDATA[<>]]> find_in_set(`fs`.`id`, `wl_equipment_specific_alarm_log`.`system_ids`)
        <if test="startDate!=null">
            AND DATE_FORMAT(`wl_equipment_specific_alarm_log`.update_date,'%y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{startDate},'%y-%m-%d')
        </if>
        <if test="endDate!=null">
            AND DATE_FORMAT(`wl_equipment_specific_alarm_log`.update_date,'%y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{endDate},'%y-%m-%d')
        </if>
        ) AS `value`
        FROM
        `f_fire_fighting_system` `fs`
        where
            fs.system_type_code IS NOT NULL AND LENGTH(trim(fs.system_type_code)) != 0 AND fs.system_type_code != 'otherSys'
    </select>

    <select id="getSystemCountInfo" resultType="java.util.Map">
        SELECT
            ( SELECT COUNT( 1 ) AS sysNum FROM `f_fire_fighting_system` `fs` WHERE fs.system_type_code IS NOT NULL AND fs.system_type_code = 'fireWaterSys' ) AS fireWaterSys,
            ( SELECT COUNT( 1 ) AS sysNum FROM `f_fire_fighting_system` `fs` WHERE fs.system_type_code IS NOT NULL AND fs.system_type_code = 'fireCAFSSys' ) AS fireCAFSSys,
            ( SELECT COUNT( 1 ) AS sysNum FROM `f_fire_fighting_system` `fs` WHERE fs.system_type_code IS NOT NULL AND fs.system_type_code = 'fireAlarmSys' ) AS fireAlarmSys,
            ( SELECT COUNT( 1 ) AS sysNum FROM `f_fire_fighting_system` `fs` WHERE fs.system_type_code IS NOT NULL AND fs.system_type_code = 'fireONLSys' ) AS fireONLSys
    </select>
    <select id="getSystemRunningInfoList" resultType="java.util.Map">
        SELECT
            (
                SELECT
                    COUNT( DISTINCT fs.id )
                FROM
                    `f_fire_fighting_system` `fs`
                        LEFT JOIN `wl_equipment_specific` `wes` ON 0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `wes`.`system_id` )
                        LEFT JOIN `wl_equipment_specific_alarm` `wesi` ON wesi.equipment_specific_id = wes.id
                WHERE
                    fs.system_type_code IS NOT NULL
                  AND fs.system_type_code = 'fireWaterSys'
                  AND wesi.`status` = 1
            ) fireWaterSys,
            (
                SELECT
                    COUNT( DISTINCT fs.id )
                FROM
                    `f_fire_fighting_system` `fs`
                        LEFT JOIN `wl_equipment_specific` `wes` ON 0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `wes`.`system_id` )
                        LEFT JOIN `wl_equipment_specific_alarm` `wesi` ON wesi.equipment_specific_id = wes.id
                WHERE
                    fs.system_type_code IS NOT NULL
                  AND fs.system_type_code = 'fireCAFSSys'
                  AND wesi.`status` = 1
            ) fireCAFSSys,
            (
                SELECT
                    COUNT( DISTINCT fs.id )
                FROM
                    `f_fire_fighting_system` `fs`
                        LEFT JOIN `wl_equipment_specific` `wes` ON 0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `wes`.`system_id` )
                        LEFT JOIN `wl_equipment_specific_alarm` `wesi` ON wesi.equipment_specific_id = wes.id
                WHERE
                    fs.system_type_code IS NOT NULL
                  AND fs.system_type_code = 'fireAlarmSys'
                  AND wesi.`status` = 1
            ) fireAlarmSys,
            (
                SELECT
                    COUNT( DISTINCT fs.id )
                FROM
                    `f_fire_fighting_system` `fs`
                        LEFT JOIN `wl_equipment_specific` `wes` ON 0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `wes`.`system_id` )
                        LEFT JOIN `wl_equipment_specific_alarm` `wesi` ON wesi.equipment_specific_id = wes.id
                WHERE
                    fs.system_type_code IS NOT NULL
                  AND fs.system_type_code = 'fireONLSys'
                  AND wesi.`status` = 1
            ) fireONLSys
    </select>

    <select id="getFireCarInfoByYJYA" resultType="java.util.Map">
        SELECT
        `wc`.`id` AS `id`,
        `wc`.`iot_code` AS `iot_code`,
        `wc`.`name` AS `name`,
        IFNULL( max( CASE WHEN ( `wcp`.`equipment_index_key` = 'FireCar_WaterCapacity' ) THEN `wcp`.`value` END ), 0 ) AS `waterCapacity`,
        IFNULL( max( CASE WHEN ( `wcp`.`equipment_index_key` = 'FireCar_FoamCapacity' ) THEN `wcp`.`value` END ), 0 ) AS `foamCapacity`,
        (select  value  from  wl_car_property  where wl_car_property.car_id=`wc`.`id` and   equipment_index_key ='FireCar_Start') AS  startup
        FROM
        `wl_car` `wc`
        LEFT JOIN `wl_car_property` `wcp` ON `wcp`.`car_id` = `wc`.`id`
        <where>
            1=1
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                AND wc.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
        GROUP BY
        `wc`.`id`
    </select>

    <select id="getCenterWaterInfo" resultType="java.util.Map">
        SELECT
        a.`name`,
        'FHS_FirePoolDevice_WaterLevel,FHS_WirelessliquidDetector_WaterLevel' nameKey,
        (
        CASE

        WHEN a.nowLevel IS NULL THEN
        '--'
        WHEN a.nowLevel >= IFNULL( a.minLevel, 0 )
        AND a.maxLevel IS NULL THEN
        '100'
        WHEN IFNULL( a.minLevel, 0 ) > a.nowLevel
        AND a.maxLevel IS NULL THEN
        '--' ELSE IFNULL((
        FORMAT(
        abs(
        IFNULL(
        a.nowLevel,
        IFNULL( a.minLevel, 0 )) /
        IF
        (
        IFNULL( a.maxLevel, 0 ) = 0,
        1,
        IFNULL( a.maxLevel, 0 ))) * 100,
        2
        )
        ),
        0
        )
        END
        ) AS levelAbs,
        IFNULL( a.nowLevel, '--' ) nowLevel,
        (
        CASE

        WHEN a.nowLevel IS NULL
        OR a.minLevel IS NULL THEN
        '--'
        WHEN IFNULL( a.minLevel, 0 ) > IFNULL(
        a.nowLevel,
        IFNULL( a.minLevel, 0 )) THEN
        '缺水' ELSE '正常'
        END
        ) AS levelStatus
        FROM
        (
        SELECT
        r.`name`,
        IFNULL( rp.min_water_level, 0 ) AS minLevel,
        IFNULL( rp.max_water_level, 0 ) AS maxLevel,
        (
        SELECT
        FORMAT( avg( IFNULL( ei.`value`, 0 )), 2 )
        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,
        rp.level_device_id
        FROM
        cb_water_resource r
        LEFT JOIN cb_water_resource_pool rp ON rp.resource_id = r.sequence_nbr
        WHERE
        r.resource_type IN ( 'pool', 'industryPool' )
        AND r.is_delete = 1
        AND r.`biz_org_code` IS NOT NULL
        <if test="bizOrgCode!=null and bizOrgCode!=''">
            AND r.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        GROUP BY
        r.sequence_nbr
        ) a  ORDER BY
        levelStatus DESC
    </select>



    <select id="getWaterlevelUnit" resultType="java.util.Map">
        SELECT
            wes.unit
        FROM
            wl_equipment_specific_index wes
        WHERE
            wes.equipment_index_key = #{equipmentIndexKey}
          AND wes.equipment_specific_id = #{equipmentSpecificId}
            LIMIT 1
    </select>

    <select id="getStationConnectStatus" resultType="java.util.Map">
        SELECT
            SUM(a.`online`) AS `online`,
            SUM(a.`notOnline`) AS `notOnline`
        FROM
            (
                SELECT
                    IF(si.`online` = 1, 1, 0) 'online',
                        IF(si.`online` !=1, 1, 0) 'notOnline'
                FROM
                    idx_biz_station_info si
                GROUP BY
                    si.`code`
            ) a
    </select>

    <select id="getStationStatusStatistics" resultType="java.util.Map">
        SELECT
            s.`code`,
            s.`name`,
            IF
                ( s.total > 0, 1, 0 ) AS `status`
        FROM
            (
                SELECT
                    si.id,
                    si.`code`,
                    si.`name`,
                    SUM(
                            IF
                                (
                                        ( wesa.`status` = 1 AND wesa.equipment_specific_index_value = 'true' ),
                                        1,
                                        0
                                )
                        ) AS total
                FROM
                    idx_biz_station_info si
                        LEFT JOIN wl_equipment_specific_alarm wesa ON si.`code` = wesa.station_code
                WHERE
                    si.ONLINE = 1
                GROUP BY
                    si.id
            ) s
        GROUP BY
            s.id
    </select>
    <select id="selectAllPressurePumpInfo" resultType="java.util.Map">
        SELECT
        ed.`name`,
        concat_ws( '-', ws.full_name, ed.area ) area,
        es.iot_code,
        es.id,
        IFNULL( sum( `status` ), 0 ) AS isAlarm
        FROM
        wl_equipment_specific es
        LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = es.warehouse_structure_id
        LEFT JOIN wl_equipment_specific_alarm esa ON esa.equipment_specific_id = es.id
        WHERE
        ed.`code` LIKE '92010800%'
        AND es.iot_code IS NOT NULL
        <if test="bizOrgCode != null and bizOrgCode != ''" >
            AND es.biz_org_code like concat(#{bizOrgCode}, '%')
        </if>
        GROUP BY
        es.id
    </select>

    <select id="selectAllDays" resultType="java.util.Map">
        select temp.date from (
        SELECT
            date
        FROM
            (
            SELECT
            DATE_FORMAT(
            DATE_SUB(
            last_day(curdate()),
            INTERVAL xc - 1 DAY
            ),
            '%Y-%m-%d'
            ) AS date
            FROM
            (
            SELECT
            @xi :=@xi + 1 AS xc
            FROM
            (
            SELECT
            1
            UNION
            SELECT
            2
            UNION
            SELECT
            3
            UNION
            SELECT
            4
            UNION
            SELECT
            5
            UNION
            SELECT
            6
            ) xc1,
            (
            SELECT
            1
            UNION
            SELECT
            2
            UNION
            SELECT
            3
            UNION
            SELECT
            4
            UNION
            SELECT
            5
            UNION
            SELECT
            6
            ) xc2,
            (SELECT @xi := 0) xc0
            ) xcxc
            ) x0
        WHERE
            x0.date >= (
            SELECT
            date_add(
            curdate(),
            INTERVAL - DAY (curdate()) + 1 DAY
            )
            )
                      )temp
        order by temp.date
    </select>

    <select id="getEquip" resultType="java.util.Map">
        SELECT
            spe.id,
            wle.`name`,
            wle.`code`,
            (
                CASE
        ( SELECT count(*) FROM wl_equipment_specific_alarm wesa WHERE wesa.equipment_specific_id in (SELECT id from wl_equipment_specific sp where sp.equipment_code = wle.code)  AND STATUS = 1 )
                    WHEN 0 THEN
                        '正常' ELSE '异常'
                    END
                ) `status`,
            wle.shbz_img shbzImg
        FROM
            wl_equipment_specific AS spe
                LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, spe.system_id )
                LEFT JOIN wl_equipment_detail AS det ON spe.equipment_detail_id = det.id
                LEFT JOIN wl_equipment AS wle ON wle.id = det.equipment_id
        WHERE
            fs.system_type_code IS NOT NULL
            <if test="bizOrgCode != null and bizOrgCode != ''">
                AND spe.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
            <if test="systemCode != null and systemCode != ''">
                AND fs.system_type_code = #{systemCode}
            </if>
        GROUP BY det.`code`
        ORDER BY status
    </select>

    <select id="getFireSystemEquipStatusList" resultType="java.util.Map">
        SELECT
            spe.id,
            spe.`name`,
            spe.`code`,
            CASE when 'false' = spe.realtime_iot_index_value or  spe.realtime_iot_index_value is null or spe.realtime_iot_index_value = ''  then '正常' ELSE  spe.realtime_iot_index_name END as status,
            wle.shbz_img shbzImg,
            ei.is_alarm AS type,
            IFNULL( spe.realtime_iot_index_value, '--' ) AS realtimeValue,
            CASE when ei.is_alarm = 1 and spe.realtime_iot_index_value = 'true' then 1 else 0  END as orderNo,
            IFNULL( ws.full_name, '--' ) AS fullName,
            IFNULL( spe.realtime_iot_index_update_date, '--' ) AS updateDate
        FROM
            wl_equipment_specific AS spe
            LEFT JOIN wl_equipment_index ei ON spe.realtime_iot_index_id = ei.id
            LEFT JOIN wl_warehouse_structure ws ON spe.warehouse_structure_id = ws.id
            LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, spe.system_id )
            LEFT JOIN wl_equipment_detail AS det ON spe.equipment_detail_id = det.id
            LEFT JOIN wl_equipment AS wle ON wle.id = det.equipment_id
        WHERE
            fs.system_type_code IS NOT NULL
            <if test="bizOrgCode != null and bizOrgCode != ''">
                AND spe.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
            <if test="systemCode != null and systemCode != ''">
                AND fs.system_type_code = #{systemCode}
            </if>
            <if test="categoryCodes != null and categoryCodes.split(',').length >0">
                AND
                <foreach collection="categoryCodes.split(',')" item="item" index="index" open="(" close=")" separator=" OR ">
                    LOCATE(#{item}, det.`code`) > 0
                </foreach>
            </if>
        GROUP BY spe.id
        ORDER BY orderNo desc
    </select>

    <select id="selectPressureDetails" resultType="java.util.Map">
        SELECT
            ed.`name`,
            concat_ws('-', ws.full_name, ed.area) area,
            es.iot_code as iotCode,
            es.id,
            (
                SELECT
                    DATE_FORMAT(wesi.update_date,'%Y-%m-%d %H:%i:%S')
                FROM
                    wl_equipment_specific_index wesi
                WHERE
                    wesi.equipment_specific_id = es.id
                  AND wesi.equipment_index_key IN ('FHS_PressurePump_Stop')
                  AND wesi.value = 'true'
                ORDER BY
                    wesi.update_date DESC
                      LIMIT 1
            ) AS stopTime,
	(
		SELECT
		DATE_FORMAT(wesi.update_date,'%Y-%m-%d %H:%i:%S')
		FROM
			wl_equipment_specific_index wesi
		WHERE
			wesi.equipment_specific_id = es.id
		AND wesi.equipment_index_key IN ('FHS_PressurePump_Start')
		AND wesi.value = 'true'
		ORDER BY
			wesi.update_date DESC
		LIMIT 1
	) AS startTime
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
            LEFT JOIN wl_warehouse_structure ws ON ws.id = es.warehouse_structure_id
            LEFT JOIN wl_equipment_specific_alarm esa ON esa.equipment_specific_id = es.id
        WHERE
            ed.`code` LIKE '92010800%'
          AND es.iot_code IS NOT NULL
          AND es.biz_org_code like CONCAT(#{bizOrgCode}, '%')
        GROUP BY
            es.id
    </select>
    <select id="selectEquipmentSpecificById" resultType="java.util.Map">
        select * from wl_equipment_specific where  id = #{id}
    </select>
    <select id="selectWeekAlarmsEquip" resultType="java.lang.Integer">

        SELECT
        COUNT(DISTINCT(e.equipment_specific_id))
        FROM
        wl_equipment_alarm_report_day e
        WHERE
        FIND_IN_SET( #{systemId},e.system_ids)
        AND e.equipment_code = #{equipmentCode}
        AND e.index_type = #{typeCode}
        AND e.report_date >= DATE_FORMAT(#{startDate},'%y-%m-%d')
        AND e.report_date &lt;= DATE_FORMAT(#{endDate},'%y-%m-%d')
    </select>
    <select id="judgeIsTrend" resultType="Map">
        SELECT
            CASE
                WHEN wei.is_trend = 1 then "1"
                WHEN wei.is_trend = 0 then "0"
                END AS isTrend
        FROM
            wl_equipment_specific_index AS wesi
            LEFT JOIN wl_equipment_specific AS wes ON wes.id = wesi.equipment_specific_id
            LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE
            wes.id = #{id}
          AND wei.is_iot = true
        ORDER BY wesi.update_date DESC
        limit 1
    </select>

    <select id="getYaoCeSpeIndex" resultType="com.yeejoin.equipmanage.common.vo.SpeIndexVo">
        SELECT
            *
        FROM
            (
                SELECT
                    eqin.name_key AS `key`,
                    eqin.`name` AS `name`,
                    eqin.type_code,
                    spein.update_date AS updateDate,
                    spein.equipment_specific_id as equipmentSpecificId,
                    IF (
                            eqin.unit IS NULL,
                            IF (
                                    (
                                            ISNULL(spein.value_label)
                                            OR spein.value_label = ''
                                        ),
                                    spein.`value`,
                                    spein.value_label
                                ),
                            concat(
                                    IF (
                                            (
                                                    ISNULL(spein.value_label)
                                                    OR spein.value_label = ''
                                                ),
                                            spein.`value`,
                                            spein.value_label
                                        ),
                                    ' ',
                                    eqin.unit
                                )
                        ) AS `value`,
                    spein.emergency_level_color AS color,
                    spein.is_alarm AS isAlarm,
                    spein.emergency_level AS emergencyLevel,
                    spein.emergency_level_describe AS emergencyLevelDescribe,
                    (SELECT IF(SUM( IF ( wesa.equipment_specific_index_value = 'true', 1, 0 ) ) > 0, 'true', 'false' ) AS indexValue FROM wl_equipment_specific_alarm wesa WHERE wesa.equipment_specific_id = wes.id) AS indexValue,
                    spein.equipment_index_name AS indexName,
                    wes.qr_code AS qrCode
                FROM
                    wl_equipment_specific_index AS spein
                        LEFT JOIN wl_equipment_index AS eqin ON spein.equipment_index_id = eqin.id
                        LEFT JOIN wl_equipment_specific AS wes ON wes.id = spein.equipment_specific_id
                WHERE
                    spein.equipment_specific_id = #{id}
                ORDER BY
                    eqin.sort_num
            ) AS dat
        WHERE
            `key` IS NOT NULL
          AND `key` != ''
        ORDER BY
            dat.updateDate DESC
    </select>

    <update id="updateStatusById">
        update f_fire_fighting_system set system_status = #{status} where id = #{id}
    </update>

    <select id="getFireWaterStatics" resultType="java.util.Map">
        select
            (select
                count(sequence_nbr)
            from
            cb_water_resource
            <where>
                (resource_type = 'industryPool' or resource_type = 'pool')
                <if test="bizOrgCode != null and bizOrgCode != ''">
                   AND biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            ) AS total,
            (select
                count(sequence_nbr)
            from
            cb_water_resource
            <where>
                water_status = '2'
                AND (resource_type = 'industryPool' or resource_type = 'pool')
                <if test="bizOrgCode != null and bizOrgCode != ''">
                    AND biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            ) AS redCode,
            (select
            count(sequence_nbr)
            from
            cb_water_resource
            <where>
                water_status = '1'
                AND (resource_type = 'industryPool' or resource_type = 'pool')
                <if test="bizOrgCode != null and bizOrgCode != ''">
                    AND biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            ) AS yellowCode
    </select>

    <select id="selectFireFightingSystemStats" resultType="java.util.Map">
        SELECT
            COUNT(*)                                                                    AS totalCount,
            COUNT(CASE WHEN ffs.system_status = '1' THEN 1 END)                         AS yellowCodeCount,
            COUNT(CASE WHEN ffs.system_status = '2' THEN 1 END)                         AS redCodeCount
        FROM f_fire_fighting_system ffs
        WHERE ffs.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
    </select>

    <select id="selectEquipmentSpecificStats" resultType="java.util.Map">
        SELECT
            COUNT(*) AS totalCount,
            COUNT( CASE WHEN wes.equip_status = '1' THEN 1 END ) AS yellowCodeCount,
            COUNT( CASE WHEN wes.equip_status = '2' THEN 1 END ) AS redCodeCount
        FROM
            wl_equipment_specific wes
            LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
        WHERE
            wes.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
            AND wed.equipment_name IS NOT NULL

    </select>

    <select id="selectCarStats" resultType="java.util.Map">
        SELECT
            COUNT(*) AS totalCount,
            IFNULL(SUM(CASE WHEN wc.equip_status = 1 then 1 else 0 end ), 0) AS yellowCodeCount,
            IFNULL(SUM(CASE WHEN wc.equip_status = 2 then 1 else 0 end ), 0) AS redCodeCount
        FROM
            wl_car wc
            LEFT JOIN wl_equipment wle ON wle.id = wc.equipment_id
            LEFT JOIN wl_equipment_category wec ON wle.category_id = wec.id
        WHERE
            wc.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%')
            and LEFT (wec.CODE, 6) = '210101'
    </select>

    <select id="getFireWaterInfo" resultType="Map">
        select
            (select
            count(sequence_nbr)
            from
            cb_water_resource
            <where>
                (resource_type = 'industryPool' or resource_type = 'pool')
                <if test="bizOrgCode != null and bizOrgCode != ''">
                  AND  biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            ) AS total,

            (select
            count(sequence_nbr)
            from
            cb_water_resource
            <where>
                resource_type = 'pool'
                <if test="bizOrgCode != null and bizOrgCode != ''">
                    AND biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            ) AS pool,
            (select
            count(sequence_nbr)
            from
            cb_water_resource
            <where>
                resource_type = 'industryPool'
                <if test="bizOrgCode != null and bizOrgCode != ''">
                    AND biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            ) AS industryPool
    </select>

    <select id="getWaterInfoPage" resultType="Map">
        select
            sequence_nbr AS id,
            biz_org_name AS bizOrgName,
            resource_type_name AS typeName,
            biz_org_code,
            resource_type,
            water_status,
            name,
            CASE
                water_status
                WHEN '0' THEN
                    'green'
                WHEN '1' THEN
                    'yellow'
                ELSE
                    'red'
                END AS statusCode
        from
            (select * from cb_water_resource where resource_type = 'industryPool' or resource_type = 'pool') a
        <where>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
            <if test="type != null and type != ''">
                AND resource_type = #{type}
            </if>
            <if test="status != null and status != ''">
                AND water_status = #{status}
            </if>
        </where>
    </select>
    <select id="getEquiplistBySystemIdPage"
            resultType="com.yeejoin.equipmanage.common.entity.vo.EquiplistSpecificBySystemVO">
        SELECT
            spe.id,
            det.`name` equipment_name,
            spe.`code`,
            spe.`iot_code` iotCode,
            cate.`name` AS category_name,
            find_in_set(spe.id,(select  point_in_scene from  wl_source_scene  where source_id=#{systemId}))	 is_bound,
            spe.equip_status equipStatus
        FROM
            wl_equipment_specific AS spe
                LEFT JOIN wl_equipment_detail AS det ON spe.equipment_detail_id = det.id
                LEFT JOIN wl_equipment AS wle ON wle.id = det.equipment_id
                LEFT JOIN wl_equipment_category cate ON cate.id = wle.category_id
        WHERE
            find_in_set(#{systemId},spe.system_id) and spe.single = true
        ORDER BY
            spe.equip_status desc
    </select>
</mapper>
