<?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>
    </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="iotCode" column="iotCode"></result>
        <result property="eqtype" column="eqtype"></result>
        <result property="bizOrgCode" column="bizOrgCode"></result>
        <result property="bizOrgName" column="bizOrgName"></result>

    </resultMap>
    <select id="getEquiplistBySystemId" resultMap="EquiplistBySystemId">
       SELECT
            spe.id,
            det.`name` equipment_name,
            spe.`code`,
            wle.`name` AS category_name
        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
        WHERE
            find_in_set(#{systemId},spe.system_id) and spe.single = true
    </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
                )
                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}
                )
    </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}
              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="getPointData" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        select * from (
        select
        'component' as template,
        true as openStatus,
        <if test="id == null">
            if((select count(1) from `wl_source_scene` ss where find_in_set(spe.id, ss.point_in_scene) and EXISTS
            (SELECT es.instance_id FROM `wl_form_instance` es WHERE ss.source_id = es.instance_id)) = 0,0,1) as
            isBinding, -- 一个装备只能在一个建筑使用
        </if>
        <if test="id != null  and  id !=''">
            if((SELECT count(1) FROM `wl_source_scene` ss where ss.source_id = #{id} and
            FIND_IN_SET(spe.id,ss.point_in_scene)) = 0,0,1) as isBinding,-- 一个装备可在多个系统使用
        </if>
        if(spe.code is null,eqdet.name,concat(eqdet.name,'(',spe.code,')')) as displayName,
        '{\"width\": 42, \"height\": 42}'as initStyle,
        'CommonEquip' as componentName,
        spe.id as sequenceNbr,
        'equipment' as componentKey,
        'equipment' as `key`,
        equ.img as imgPath,
        spe.qr_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,
        null as ip,
        null as token,
        null 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) 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
            (
            ( SELECT ss.id FROM wl_source_scene ss WHERE ss.video_in_scene LIKE CONCAT( '%', vid.id, '%' ) ) IS NULL,
            0,
            1
            ) AS isBinding,
            IF
            ( vid.CODE IS NULL, vid.NAME, concat( vid.NAME, '(', vid.CODE, ')' ) ) AS displayName,
            '{\"width\": 42, \"height\": 42}' AS initStyle,
            'CommonEquip' AS componentName,
            vid.id AS sequenceNbr,
            'equipment' AS componentKey,
            'video' AS `key`,
            img AS imgPath,
            vid.CODE AS equipCode,
            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>
    </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,
             if (eqin.unit is null, spein.value,concat(spein.value,eqin.unit)) as value
             from
             wl_equipment_specific_index as spein
             left join wl_equipment_index as eqin on spein.equipment_index_id = eqin.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
        FROM
        (
        SELECT
            wlesal.id,
            wlesal.equipment_specific_id AS equipmentSpecificId,
            IFNULL(wlesal.equipment_specific_code,'') AS fireEquipmentCode,
            wlesal.equipment_specific_name AS fireEquipmentName,
            wlesal.equipment_index_id AS fireEquipmentIndexId,
            wlesal.equipment_specific_index_key AS fireEquipmentSpecificIndexKey,
            wlesal.equipment_specific_index_name AS fireEquipmentSpecificIndexName,
            if(wlesal.confirm_type IS NULL,0,1) AS confirmType,
            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 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 BETWEEN CONCAT( DATE_ADD( DATE_FORMAT( NOW( ), '%Y-%m-%d ' ), INTERVAL - 7 DAY ), '00:00:00' )
                AND CONCAT( DATE_FORMAT( NOW( ), '%Y-%m-%d ' ), '%', '23:59:59' )
            </if>
            <if test='createDate != null and createDate == "30"'>
                AND wlesal.create_date BETWEEN CONCAT( DATE_ADD( DATE_FORMAT( NOW( ), '%Y-%m-%d ' ), INTERVAL - 30 DAY ), '00:00:00' )
                AND CONCAT( DATE_FORMAT( NOW( ), '%Y-%m-%d ' ), '%', '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>
        </where>
        ) d
        <where>
            d.fireEquipmentName IS NOT NULL
            <choose>
                <when test="type != null and type != ''">
                    AND d.type = #{type}
                </when>
                <otherwise>
                    AND ( d.type = 'FIREALARM' OR d.type = 'BREAKDOWN' OR d.type = 'SHIELD' )
                </otherwise>
            </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.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 
              <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
                 where  s1.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
            </if>

            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                where  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.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!=''">
                 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>

        </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,'') 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="id != null and id !=''">
                fs.id = #{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_AirSampler_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>
    <select id="fireAlarmSysIndexNumber" resultType="java.util.Map">
        select
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_SmokeAlarm_Shield'
        and s.`value` = 'true') as ywtcqpb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_SmokeAlarm_Fault'
        and s.`value` = 'true') as ywtcqgz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_SmokeAlarm_FireAlarm'
        and s.`value` = 'true') as ywtcqhj,

        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_SoundLightAlarm_Shield'
        and s.`value` = 'true') as sgbjqpb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_SoundLightAlarm_Fault'
        and s.`value` = 'true') as sgbjqgz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_SoundLightAlarm_FireAlarm'
        and s.`value` = 'true') as sgbjqhj,

        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_InfraredLight_Shield'
        and s.`value` = 'true') as hwdspb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_InfraredLight_Fault'
        and s.`value` = 'true') as hwdsgz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_InfraredLight_FireAlarm'
        and s.`value` = 'true') as hwdshj,

        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_ManualAlarm_Shield'
        and s.`value` = 'true') as sdbjapb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_ManualAlarm_Fault'
        and s.`value` = 'true') as sdbjagz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_ManualAlarm_FireAlarm'
        and s.`value` = 'true') as sdbjahj,

        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_TemperatureCable_Shield'
        and s.`value` = 'true') as gwdlpb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_TemperatureCable_Fault'
        and s.`value` = 'true') as gwdlgz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_TemperatureCable_FireAlarm'
        and s.`value` = 'true') as gwdlhj,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_TemperatureFireDetector_Shield'
        and s.`value` = 'true') as fbwgpb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_TemperatureFireDetector_Fault'
        and s.`value` = 'true') as fbwggz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_TemperatureFireDetector_FireAlarm'
        and s.`value` = 'true') as fbwgqhj,

        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_AirSampler_Shield'
        and s.`value` = 'true') as kqcypb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_AirSampler_Fault'
        and s.`value` = 'true') as kqcygz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_AirSampler_FireAlarm'
        and s.`value` = 'true') as kqcyhj,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_UltravioletLight_Shield'
        and s.`value` = 'true') as zwhypb,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_UltravioletLight_Fault'
        and s.`value` = 'true') as zwhygz,
        (SELECT
        count(1)
        FROM `wl_equipment_specific_index` s
        where s.equipment_index_key = 'FAS_UltravioletLight_FireAlarm'
        and s.`value` = 'true') as zwhyhj
    </select>
    <select id="fireWaterSysHydrant" resultType="java.util.Map">
        SELECT
        xhsanhj,
        xhsangz,
        xhsanpb,
        (xhsan - xhsanhj- xhsangz-xhsanpb) 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
        ) as hydrant
    </select>
    <select id="fireWaterSysCollectingDevice" resultType="java.util.Map">
        SELECT
            sbfcjzzyc,
            sbfcjzzbs,
            (sbfcjzz-sbfcjzzyc-sbfcjzzbs) 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(1)
            from
            `wl_equipment_specific_index` si
            where
            si.equipment_index_key  = 'FHS_CollectingDevice_DeviceAbnormal') as sbfcjzz
    ) 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_FeedbackModuleShield'
        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="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.fhznum,
	d.fhzpb,
	d.fhzgz,
	d.fhzhj,
	d.yjgbnum,
	d.yjgbpb,
	d.yjgbgz,
	d.yjgbqd
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` si
        where
        si.equipment_index_key = 'SCS_FireDamper_FireAlarm') as fhznum,
		(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,

            (SELECT
                count(1)
            from
            `wl_equipment_specific_index` si
            where
            si.equipment_index_key = 'FES_FireBroadcast_Start') as yjgbnum,

            (SELECT
            count(1)
            FROM `wl_equipment_specific_index` s
            where s.equipment_index_key = 'FES_FireBroadcast_Shield'
            and s.`value` = 'true') as yjgbpb,
            (SELECT
            count(1)
            FROM `wl_equipment_specific_index` s
            where s.equipment_index_key = 'FES_FireBroadcast_Fault'
            and s.`value` = 'true') as yjgbgz,
            (SELECT
            count(1)
            FROM `wl_equipment_specific_index` s
            where s.equipment_index_key = 'FES_FireBroadcast_Start'
            and s.`value` = 'true') as yjgbqd
	) `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,
        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.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>
        )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,
            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.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
            <if test="equipTypeAmountPage.warehouseStructureName!=null and equipTypeAmountPage.warehouseStructureName!=''">
                where  s1.full_name LIKE CONCAT('%',#{equipTypeAmountPage.warehouseStructureName},'%')
            </if>

            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                where  s1.bizOrgCode LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
            </if>
        order by 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>


</mapper>
