<?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.EquipmentSpecificMapper">
    <resultMap id="ComplementCode" type="com.yeejoin.equipmanage.common.entity.vo.ComplementCodeVO">
        <result property="id" column="id"></result>
        <result property="qrcode" column="qrcode"></result>
        <result property="iotCode" column="iot_code"></result>
        <result property="systemId" column="system_id"></result>
        <result property="single" column="single"></result>
        <result property="equipmentDetailId" column="equipment_detail_id"></result>
        <result property="warehouseStructureId" column="warehouse_structure_id"></result>
        <result property="status" column="status"></result>
        <result property="location" column="location"></result>
        <result property="stockId" column="stock_id"></result>
        <result property="stockDetailId" column="stock_detail_id"></result>
        <result property="code" column="code"></result>
        <result property="systemName" column="system_name"></result>
    </resultMap>

    <resultMap type="com.yeejoin.equipmanage.common.entity.vo.PageSecurityVideoVO" id="menuTree">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="full_name" property="fullName"/>
        <collection property="children" ofType="com.yeejoin.equipmanage.common.entity.vo.PageSecurityVideoVO"
                    column="id" select="getMenuChildren"/>
    </resultMap>

    <select id="getEquipmentSpe" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
        select * from
        (select
        spe.id ,
        det.name,
        spe.iot_code as code,
        (SELECT
        GROUP_CONCAT(d.name)
        FROM
        f_fire_fighting_system d
        WHERE
        find_in_set(d.id, spe.system_id)) as systemName
        from
        wl_equipment_specific as spe
        left join wl_equipment_detail as det on spe.equipment_detail_id = det.id
        where equipment_detail_id
        in (select id from wl_equipment_detail where equipment_id in
        <foreach item="item" collection="ids" separator="," open="(" close=")" index="">
            #{item, jdbcType=NUMERIC}
        </foreach>
        )
        ) data
        where 1=1
        <if test="name != null  ">
            AND name like CONCAT('%',#{name},'%')
        </if>
        <if test="code != null  ">
            AND code like CONCAT('%',#{code},'%')
        </if>
        limit #{sPage},#{size}
    </select>
    <select id="getEquipmentSpeCount" resultType="int">
        select COUNT(1) from
        (select
        spe.id ,
        det.name,
        spe.iot_code as code
        from
        wl_equipment_specific as spe
        left join wl_equipment_detail as det on spe.equipment_detail_id = det.id
        where equipment_detail_id
        in (select id from wl_equipment_detail where equipment_id in
        <foreach item="item" collection="ids" separator="," open="(" close=")" index="">
            #{item, jdbcType=NUMERIC}
        </foreach>
        )
        ) data
        where 1=1
        <if test="name != null  ">
            AND name like CONCAT('%',#{name},'%')
        </if>
        <if test="code != null  ">
            AND code like CONCAT('%',#{code},'%')
        </if>
    </select>
    <select id="selectEquipmentSpecific" resultMap="ComplementCode">
        SELECT
        wesp.id id,
        wesp.code,
        wesp.qr_code qrcode,
        wesp.iot_code,
        wesp.system_id,
        wesp.single,
        wesp.equipment_detail_id,
        wsd.`status`,
        wsd.warehouse_structure_id,
        wsd.id stock_detail_id,
        wsd.stock_id,
        (SELECT GROUP_CONCAT(fem.name) FROM `f_fire_fighting_system` fem WHERE find_in_set(fem.id,wesp.system_id)) as
        system_name,
        wws.full_name location
        FROM
        wl_equipment_specific wesp
        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
        wesp.equipment_detail_id = #{equipmentSpecificDTO.equipmentDetailId}
        <if test="equipmentSpecificDTO.status != null and equipmentSpecificDTO.status.size()>0">
            and wsd.`status` in
            <foreach collection="equipmentSpecificDTO.status" item="status" index="index" open="(" close=")"
                     separator=",">
                #{status}
            </foreach>
        </if>
        <if test="equipmentSpecificDTO.qrcode != null and equipmentSpecificDTO.qrcode!=''">
            and wesp.qr_code like CONCAT('%',#{equipmentSpecificDTO.qrcode},'%' )
        </if>
        order by wesp.create_date desc
    </select>

    <select id="getEquipmentSpecificIotCode" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
        SELECT
        DISTINCT
        wes.iot_code AS iotCode
        FROM
        wl_equipment_specific AS wes
        LEFT JOIN wl_equipment_specific_index AS wesi ON wesi.equipment_specific_id = wes.id
        LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE TRIM(wes.iot_code) != '' AND wes.iot_code IS NOT NULL AND wei.is_iot=1
        UNION ALL
        SELECT
        DISTINCT
        wc.iot_code AS iotCode
        FROM
        wl_car AS wc
        LEFT JOIN wl_car_property AS wcp ON wcp.car_id = wc.id
        LEFT JOIN wl_equipment_index AS wei ON wei.id = wcp.equipment_index_id
        WHERE TRIM(wc.iot_code) != '' AND wc.iot_code IS NOT NULL AND wei.is_iot=1
    </select>

    <select id="getEquipIotCodeLists" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
        SELECT
        DISTINCT
        wes.iot_code AS iotCode
        FROM
        wl_equipment_specific AS wes
        LEFT JOIN wl_equipment_specific_index AS wesi ON wesi.equipment_specific_id = wes.id
        LEFT JOIN wl_equipment_index AS wei ON wei.id = wesi.equipment_index_id
        WHERE TRIM(wes.iot_code) != '' AND wes.iot_code IS NOT NULL AND wei.is_iot=1
    </select>

     <select id="getEquipOrCarByIotCode" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
        SELECT
			temp.*
		FROM
			(
				SELECT
					wes.id,
					wes.iot_code AS iotCode,
					'equip' AS type,
					(SELECT GROUP_CONCAT(fs.system_type_code) FROM f_fire_fighting_system fs WHERE find_in_set(
						`fs`.`id`,
						`wes`.`system_id`
					)) AS `code`
				FROM
					wl_equipment_specific AS wes
			 where TRIM(wes.iot_code) != '' AND wes.iot_code IS NOT NULL
				UNION ALL
					SELECT
						wc.id,
						wc.iot_code AS iotCode,
						'car' AS type,
						wc.car_num AS `code`
					FROM
						wl_car wc
				 where TRIM(wc.iot_code) != '' AND wc.iot_code IS NOT NULL
			) temp
			<where>
			<if test="iotCode!='' and iotCode !=null">
				 temp.iotCode = #{iotCode}
			</if>
			</where>
    </select>

    <select id="getPointData" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        select
         'component' as template,
         true as openStatus,
         spe.is_binding as isBinding,
         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,
         equ.img as imgPath,
         spe.qr_code as equipCode,
         stru.source_id as parentId,
         cat.id as equipId,
         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
    </select>

    <select id="getSystemEquList" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
        select
            catt.id as equipId,
            catt.name as displayName
            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 equ on  det.equipment_id = equ.id
            left join wl_equipment_category as catt on equ.category_id = catt.id
            where
            spe.org_code = #{orgCode}
            and find_in_set(#{id},spe.system_id)
            group by catt.id
            order by catt.code
    </select>
    <select id="getFirstCanvas" resultType="string">
         select
            sce.scene_id
            from
            f_risk_source as sou
            left join wl_risk_source_scene as sce on sou.id = sce.risk_source_id
            where
            sou.parent_id = 0
            and sce.org_code = #{orgCode}
    </select>
    <select id="getSceneName" resultType="string">
    select
        name
        from
        f_risk_source
        where id = #{id}
    </select>
    <select id="getSystemmeanLsit" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
    select
		id as sequenceNbr,
		NAME as displayName,
		SORT as sort,
		SCENE_ID as sceneId
        from
        f_fire_fighting_system
        order by SORT
    </select>
    <select id="getSceList" resultType="com.yeejoin.equipmanage.common.entity.vo.PointTreeVo">
    select scene_id as sceneId from wl_risk_source_scene
    where org_code =#{orgCode}
    </select>
    <select id="getEquipMentStatus" resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
         select
             ind.type_code as type,
             spein.value as value
             from wl_equipment_specific as spe
             left join wl_equipment_specific_index as spein on spe.id = spein.equipment_specific_id
             left join wl_equipment_index as ind on spein.equipment_index_id = ind.id
             where spe.qr_code =#{id}
             AND spe.iot_code is not null
             AND spe.iot_code != ''
			 AND ind.type_code !='' AND ind.type_code is not null
             AND value is not null
             ORDER BY spein.update_date DESC
    </select>
    
    <select id="getEquipIndexLatestStatus" resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
         SELECT
			equipindex.`value`,
			ei.type_code AS 'typeCode',
			es.qr_code AS 'qrCode'
		FROM
			(
				SELECT
					esi.equipment_index_id,
					esi.equipment_specific_id,
					esi.`value`
				FROM
					wl_equipment_specific_index esi,
					(
						SELECT
							equipment_specific_id,
							MAX(update_date) AS update_date
						FROM
							wl_equipment_specific_index
						GROUP BY
							equipment_specific_id
		) esii
				WHERE
					esi.`value` IS NOT NULL
				AND esi.equipment_specific_id = esii.equipment_specific_id
				AND esi.update_date = esii.update_date
				GROUP BY
					esi.equipment_specific_id
			) equipindex,
			wl_equipment_specific es,
			wl_equipment_index ei
		WHERE
			equipindex.equipment_specific_id = es.id
		AND equipindex.equipment_index_id = ei.id
    </select>
    
    <select id = "getEquipLatestStatusBySceneId"  resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex">
    	SELECT
			ei.type_code AS 'typeCode',
			es.`name` as 'equipmentSpecificName',
			es.realtime_iot_index_key AS 'indexKey',
			es.realtime_iot_index_name AS 'indexName',
			es.qr_code AS 'qrCode',
			es.iot_code AS 'iotCode',
			es.realtime_iot_index_value AS 'value'
		FROM
			wl_equipment_specific es,
			wl_equipment_index ei
		WHERE
			es.realtime_iot_index_id = ei.id
		AND find_in_set(
			es.id,
			(
				SELECT
					wss.point_in_scene
				FROM
					wl_source_scene wss
				WHERE
					wss.scene_id = #{sceneId}
			)
		)
    </select>
    
    <select id="getEquipmentIotCodeLists" resultType="String">
        SELECT
            iot_code
        FROM
            wl_equipment_specific
        where iot_code is not null
    </select>
    <select id="getEquipBySourceId" resultType="java.util.HashMap">
        SELECT
        Cast( spec.id as char) as equipmentId,
        spec.name AS name,
        structure.source_id AS sourceId,
        structure.source_code AS sourceCode,
        spec.system_id AS systemId,
        spec.code AS code,
        spec.id AS id,
        category.NAME AS categoryName,
        category.CODE AS categoryCode,
        equipment_detail.area AS address,
        CONCAT(area.prevName,'-',structure.NAME) AS acre,
        we.inspection_spec as inspectionSpecId,
        0 as orderNo
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail equipment_detail ON equipment_detail.id = spec.equipment_detail_id
        LEFT JOIN (
        SELECT
        DISTINCT equipment_specific_id
        , warehouse_structure_id
        FROM
        wl_stock_detail
        ) AS detail ON detail.equipment_specific_id = spec.id
        LEFT JOIN wl_warehouse_structure structure ON detail.warehouse_structure_id = structure.id
        LEFT JOIN (
        SELECT
        s.id,
        s.name AS prevName
        FROM
        wl_warehouse_structure s
        ) AS area ON area.id = structure.parent_id
        LEFT JOIN wl_equipment we ON we.id = equipment_detail.equipment_id
        LEFT JOIN wl_equipment_category category ON category.id = we.category_id
        WHERE 1=1
        <if test="sourceIds != null">and structure.id IN
            <foreach collection="sourceIds" item="sourceIds" index="index" open="(" close=")" separator=",">
                #{sourceIds}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size() > 0">
            and category.id in
            <foreach collection="categoryId" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="equipCode != '' and equipCode != null">and spec.code like concat("%", #{equipCode}, "%")</if>
        <if test="equipName != '' and equipName != null">
            and equipment_detail.name like CONCAT("%", #{equipName},'%')
        </if>
    </select>

    <select id="findAllParents" resultMap="menuTree">
        SELECT
            wws.id AS id,
            wws.parent_id AS parentId,
            wws.name AS name,
            wws.full_name AS fullName
        FROM
            wl_warehouse_structure wws
        WHERE
            wws.parent_id = 0
    </select>

    <select id="getMenuChildren" resultMap="menuTree">
        SELECT
            wws.id AS id,
            wws.parent_id AS parentId,
            wws.name AS name,
            wws.full_name AS fullName
        FROM
            wl_warehouse_structure wws
        WHERE
            wws.parent_id = #{id}
    </select>

    <select id="getEquipsBySourceId" resultType="java.util.HashMap">
        SELECT
        Cast( spec.id as char) as equipmentId,
        we.name AS name,
        structure.source_id AS sourceId,
        structure.source_code AS sourceCode,
        spec.system_id AS systemId,
        spec.code AS code,
        category.id AS id,
        category.NAME AS categoryName,
        category.CODE AS categoryCode,
        structure.full_name AS address,
        structure.NAME AS acre,
        we.inspection_spec as inspectionSpecId,
        0 as orderNo
        FROM
        wl_equipment_specific spec
        LEFT JOIN wl_equipment_detail equipment_detail ON equipment_detail.id = spec.equipment_detail_id
        LEFT JOIN wl_stock_detail detail ON detail.equipment_specific_id = spec.id
        LEFT JOIN wl_warehouse_structure structure ON detail.warehouse_structure_id = structure.id
        LEFT JOIN f_fire_fighting_system AS manage ON manage.id = spec.system_id
        LEFT JOIN wl_equipment we ON we.id = equipment_detail.equipment_id
        LEFT JOIN wl_equipment_category category ON category.id = we.category_id
        WHERE 1=1
        <if test="sourceId !='' and sourceId != null and sourceId != 'null'">and structure.id = #{sourceId}</if>
        <if test="categoryId !='' and categoryId != null">and category.id = #{categoryId}</if>
        <if test="equipCode !='' and equipCode != null">and spec.code = #{equipCode}</if>
        <if test="equipName !='' and equipName != null">and equipment_detail.name like CONCAT(#{equipName},'%')</if>
    </select>

    <select id="findAllMenuChildren" resultMap="menuTree">
        SELECT
            wws.id,
            wws.parent_id,
            wws.name,
            wws.full_name
        FROM
            wl_warehouse_structure wws
    </select>

    <select id="getEquipBySourceIdBycount" resultType="java.lang.Long">
        SELECT
        COUNT(1)
        FROM
        wl_stock_detail detail
        LEFT JOIN wl_warehouse_structure structure ON detail.warehouse_structure_id = structure.id
        LEFT JOIN wl_equipment_detail equipment_detail ON equipment_detail.id = detail.equipment_detail_id
        LEFT JOIN wl_equipment_specific spec ON spec.equipment_detail_id = detail.equipment_detail_id
        LEFT JOIN wl_equipment we ON we.id = equipment_detail.equipment_id
        LEFT JOIN wl_equipment_category category ON category.id = we.category_id
        WHERE 1=1
        <if test="sourceId!=''">and structure.id = #{sourceId}</if>
        <if test="categoryId!=''">and category.id = #{categoryId}</if>
        <if test="equipCode!=''">and spec.code = #{equipCode}</if>
        <if test="equipName!=''">and equipment_detail.name like CONCAT(#{equipName},'%')</if>
    </select>
    <select id="getEquipmentNameByIotCode" resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
        SELECT
        wed.name AS name
        FROM
        wl_equipment_specific AS wes,
        wl_equipment_detail AS wed
        WHERE
        wed.id = wes.equipment_detail_id
        AND
        wes.iot_code = #{iotCode}
    </select>
    <select id="getIotCodeList" resultType="String">
        SELECT
        iot_code
        FROM
        wl_equipment_specific
        WHERE
        1=1
        <if test="id != null and id != ''">
            AND id != #{id}
        </if>
        AND
        iot_code IS NOT NULL
    </select>
    <select id="getOneCard" resultType="java.util.Map">
        SELECT
            a.key,
            a.value


        FROM
            (
            SELECT
                wles.id,
                '名称' AS 'key',
                wled.NAME AS
            value

            FROM
                wl_equipment_specific wles
                LEFT JOIN wl_stock_detail wlsd ON wles.id = wlsd.equipment_specific_id
                LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
                LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                LEFT JOIN wl_unit wlu ON wlu.id = wle.unit_id
                LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id UNION ALL
            SELECT
                wles.id,
                '型号' AS 'key',
                wled.standard AS
            value

            FROM
                wl_equipment_specific wles
                LEFT JOIN wl_stock_detail wlsd ON wles.id = wlsd.equipment_specific_id
                LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
                LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                LEFT JOIN wl_unit wlu ON wlu.id = wle.unit_id
                LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id UNION ALL
            SELECT
                wles.id,
                '品牌' AS 'key',
                wled.brand AS
            value

            FROM
                wl_equipment_specific wles
                LEFT JOIN wl_stock_detail wlsd ON wles.id = wlsd.equipment_specific_id
                LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
                LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                LEFT JOIN wl_unit wlu ON wlu.id = wle.unit_id
                LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id UNION ALL
            SELECT
                wles.id,
                '生产厂家' AS 'key',
                wlmi.NAME AS
            value

            FROM
                wl_equipment_specific wles
                LEFT JOIN wl_stock_detail wlsd ON wles.id = wlsd.equipment_specific_id
                LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
                LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                LEFT JOIN wl_unit wlu ON wlu.id = wle.unit_id
                LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id UNION ALL
            SELECT
                wles.id,
                '数量' AS 'key',
                concat(cast(wlsd.amount as SIGNED), wlu.NAME) AS
            value

            FROM
                wl_equipment_specific wles
                LEFT JOIN wl_stock_detail wlsd ON wles.id = wlsd.equipment_specific_id
                LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
                LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                LEFT JOIN wl_unit wlu ON wlu.id = wle.unit_id
                LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id UNION ALL
            SELECT
                wles.id,
                '状态' AS 'key',
            CASE
                    wlsd.`status`
                    WHEN '1' THEN
                    '在位'
                    WHEN '2' THEN
                    '执勤'
                    WHEN '3' THEN
                    '维修'
                    WHEN '6' THEN
                    '退役'
                    WHEN '7' THEN
                    '报废'
                    WHEN '10' THEN
                    '车载'
                    WHEN '11' THEN
                    '损耗' ELSE '未入库'
            END AS
            value

            FROM
                wl_equipment_specific wles
                LEFT JOIN wl_stock_detail wlsd ON wles.id = wlsd.equipment_specific_id
                LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
                LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
                LEFT JOIN wl_unit wlu ON wlu.id = wle.unit_id
                LEFT JOIN wl_manufacturer_info wlmi ON wlmi.id = wled.manufacturer_id
            ) a
        WHERE
            a.id = #{id}
    </select>
    <select id="getQrCodeAndPic" resultType="java.util.Map">
        SELECT
            CONCAT( '01#', wles.qr_code ) AS qrCode,
            wle.img AS pic
        FROM
            wl_equipment_specific wles
            LEFT JOIN wl_equipment_detail wled ON wled.id = wles.equipment_detail_id
            LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
        WHERE
            wles.id = #{id}
    </select>

    <select id="getEquipmentList" resultType="hashmap">
        SELECT
            a.systemId AS systemId,
            es.id AS speId,
            esd.`name` AS speName,
            ifnull(sd.amount,0) AS amount,
            wlwa.full_name AS address
        FROM
            (
            SELECT
                fs.id as systemId,
                fs.`name` as systemName,
                fs.system_type as systemType,
                ec.`code` as systemCode
            FROM
                f_fire_fighting_system fs
                JOIN wl_equipment_category ec ON ec.id = fs.system_type
                AND ec.`code` != #{alarmSystemCode}
            ) a
            LEFT JOIN wl_equipment_specific es ON FIND_IN_SET(a.systemId,es.system_id)
            LEFT JOIN wl_equipment_detail esd ON esd.id = es.equipment_detail_id
            LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = es.id
            LEFT JOIN wl_warehouse_structure wlwa ON wlwa.id = sd.warehouse_structure_id
            where es.system_id <![CDATA[<>''


        ]]>
    </select>
    <select id="selectSystemList" resultType="String">
        SELECT
            sys.NAME
        FROM
            wl_equipment_specific AS spe
            LEFT JOIN f_fire_fighting_system AS sys ON FIND_IN_SET(sys.id, spe.system_id)
        WHERE
            spe.id = #{id} and spe.system_id <![CDATA[<>''


        ]]>
    </select>
    <select id="selectBuildList" resultType="String">
        select source_name from wl_source_scene
        where point_in_scene like CONCAT('%',#{id},'%' )
    </select>
    <select id="getAlarmEquipmentById" resultType="hashmap">
        SELECT
            a.systemId AS systemId,
            a.systemCode AS systemCode,
            es.id AS speId,
            esd.`name` AS speName,
            sd.amount AS amount,
            wlwa.full_name AS address,
            wlwa.id as areaId
        FROM
            (
            SELECT
                fs.id as systemId,
                fs.`name` as systemName,
                fs.system_type as systemType,
                ec.`code` as systemCode
            FROM
                f_fire_fighting_system fs
                JOIN wl_equipment_category ec ON ec.id = fs.system_type
            ) a
            JOIN wl_equipment_specific es ON find_in_set(a.systemId,es.system_id)
            LEFT JOIN wl_equipment_detail esd ON esd.id = es.equipment_detail_id
            LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = es.id
            LEFT JOIN wl_warehouse_structure wlwa ON wlwa.id = sd.warehouse_structure_id
            where es.id=#{id}
    </select>
    <select id="getSourceNameByEquipSpeId"
            resultType="com.yeejoin.equipmanage.common.entity.vo.SourceNameByEquipSpeIdVO">
        SELECT
            wlec.`name` categoryName,
            frs.`name` sourceName,
            wlws.name warehouseStructureName,
            wled.area area,
            wlws.full_name AS fullName
            FROM
                wl_equipment_specific wles
                left join wl_equipment_detail wled on wles.equipment_detail_id = wled.id
                left join wl_equipment wle on wled.equipment_id = wle.id
                LEFT JOIN wl_equipment_category wlec on wlec.id = wle.category_id
                left join wl_stock_detail wlstd on wlstd.qr_code = wles.qr_code
                LEFT JOIN wl_warehouse_structure wlws ON wlws.id = wlstd.warehouse_structure_id
                left join f_risk_source frs on frs.source_id = wlws.source_id
                where wles.id=#{id}
    </select>
    <select id="getSourceNameList"
            resultType="com.yeejoin.equipmanage.common.entity.vo.SourceNameByEquipSpeIdVO">
        SELECT
        wles.code,
        wled.`name` equipmentName,
        wlec.`name` categoryName,
        frs.`name` sourceName,
        wlws.NAME warehouseStructureName
        FROM
        wl_equipment_specific wles
        LEFT JOIN wl_equipment_detail wled ON wles.equipment_detail_id = wled.id
        LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
        LEFT JOIN wl_equipment_category wlec ON wlec.id = wle.category_id
        LEFT JOIN wl_stock_detail wlstd ON wlstd.qr_code = wles.qr_code
        LEFT JOIN wl_warehouse_structure wlws ON wlws.id = wlstd.warehouse_structure_id
        LEFT JOIN f_risk_source frs ON frs.id = wlws.source_id
        WHERE
        wlws.id=#{warehouseStructureId}
        <if test="sourceId!=null">
            and wlws.source_id=#{sourceId}
        </if>
        <if test="equipmentName!=null and equipmentName!=''">
            and wled.`name` like CONCAT('%',#{equipmentName},'%')
        </if>
        <if test="equipmentCode!=null and equipmentCode!=''">
            and wles.code like CONCAT('%',#{equipmentCode},'%')
        </if>
    </select>
    <select id="getEquipSpecificDetail"
            resultType="com.yeejoin.equipmanage.common.datasync.entity.FireEquipment">
         SELECT
            es.id,
            es.`code` AS mrid,
            es.`name`,
            es.`name` AS aliasname,
            es.`code`,
			ed.equipment_name AS categoryname,
			ed.`code` AS categorycode,
            ( SELECT GROUP_CONCAT( url ) FROM wl_upload_file WHERE file_type = 'image' AND object_type = 'equipment' AND object_id = ed.id ) AS img,
            es.iot_code AS iotcode,
            '' AS stationname,
            '' AS stationcode,
            ws.source_id AS buildid,
            es.system_id AS fightingsystemids,
            TRIM(CONCAT_WS(' ',ws.full_name,sd.description)) AS position,
            es.create_date AS inusedate,
            '正常' AS `status`,
            '在位' AS inusestate,
            es.create_date AS createdate,
            NOW( ) AS updatedate,
            es.area_id AS areaid,
            ws.`name` AS buildname,
            a.`name` AS workarea
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
            LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = es.id
            LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
            LEFT JOIN wl_area a ON es.area_id = a.id
        WHERE
            es.id = #{id}
    </select>
    <select id="getEquipSpecificDetailsByEquipmentId"
            resultType="com.yeejoin.equipmanage.common.datasync.entity.FireEquipment">
        SELECT
        es.id,
        ed.`name`,
        es.`code`,
        es.`code` AS mRid,
        es.system_id AS fightingSystemIds,
        es.iot_code AS iotCode,
        e.`name` AS categoryName,
        e.`code` AS categoryCode,
        ws.source_id AS buildId,
        ws.`name` AS buildName,
        TRIM( CONCAT( IFNULL( ws.full_name, '' ), ' ', IFNULL( sd.description, '' ) ) ) AS position
        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 f_fire_fighting_system fs ON fs.id = es.system_id
        LEFT JOIN wl_stock_detail sd ON sd.equipment_specific_id = es.id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
        <where>
            <if test="equipmentId != null">
                ed.equipment_id = #{equipmentId}
            </if>
        </where>
    </select>
    <select id="getEquipSpeTypeByQrcode" resultType="com.yeejoin.equipmanage.common.entity.EquipmentCategory">
        SELECT
        wlec.code AS code
        FROM
            wl_equipment_specific wles
        LEFT JOIN wl_equipment_detail wled ON wles.equipment_detail_id = wled.id
        LEFT JOIN wl_equipment wle ON wled.equipment_id = wle.id
        LEFT JOIN wl_equipment_category wlec ON wlec.id = wle.category_id
        WHERE wles.qr_code = #{qrCode}
        AND wlec.industry_code='2'
    </select>
    <select id="selectEquipCategoryNumber" resultType="com.yeejoin.equipmanage.common.vo.EquipCategoryVo">
        select
            b.id,
            b.`name`,
            b.img as photo,
            (SELECT
             count(1)
            FROM
            `wl_equipment_specific` es,
            wl_equipment_detail ed
            where es.equipment_detail_id = ed.id
            and ed.equipment_id = b.id
            and FIND_IN_SET(#{systemId},es.system_id)) as number
        from
            (SELECT
             distinct ed.equipment_id
            FROM
            `wl_equipment_specific` es,
            wl_equipment_detail ed
            where es.equipment_detail_id = ed.id
            and FIND_IN_SET(#{systemId},es.system_id)
            ) a,
            wl_equipment b
        where a.equipment_id = b.id order by  b.id
    </select>
    <select id="get3dFightingSysEquipList" resultType="com.yeejoin.equipmanage.common.vo.EquipmentSpecific3dVo">
        SELECT
        es.id,
        ed.`name`,
        es.`code`,
        IF
        ( SUM( IF ( a.equipment_specific_index_value = 'true', 1, 0 ) ) > 0, 0, 1 ) AS `status`,
        ws.full_name AS position,
        fs.`name` AS fightingName
        FROM
        wl_equipment_specific es
        LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_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_stock_detail sd ON sd.equipment_specific_id = es.id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
        LEFT JOIN wl_equipment_specific_alarm a ON a.equipment_specific_id = es.id
        WHERE
        esi.`value` IS NOT NULL AND es.system_id IS NOT NULL
        <if test="id != null">
            AND fs.id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND (es.`code` LIKE CONCAT('%', #{name}, '%') OR ed.`name` LIKE CONCAT('%', #{name}, '%'))
        </if>
        GROUP BY
        es.id
        ORDER BY
        esi.update_date DESC
    </select>

    <select id="listPage" resultType="com.yeejoin.equipmanage.common.vo.EquipmentSpecific3dVo">
        SELECT d.* FROM (
        SELECT
        es.id,
        ed.`name`,
        es.`code`,
        IF
        ( SUM( IF ( a.equipment_specific_index_value = 'true', 1, 0 ) ) > 0, 0, 1 ) AS `status`,
        ws.full_name AS position,
        fs.`name` AS fightingName
        FROM
        wl_equipment_specific es
        LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_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_stock_detail sd ON sd.equipment_specific_id = es.id
        LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
        LEFT JOIN wl_equipment_specific_alarm a ON a.equipment_specific_id = es.id
        WHERE
        esi.`value` IS NOT NULL AND es.system_id IS NOT NULL
        <if test="equipment.id != null and equipment.id != 0">
            AND fs.id = #{equipment.id}
        </if>
        <if test="equipment.name != null and equipment.name != ''">
            AND (es.`code` LIKE CONCAT('%', #{equipment.name}, '%') OR ed.`name` LIKE CONCAT('%', #{equipment.name},
            '%'))
        </if>
        GROUP BY
        es.id
        ORDER BY
        esi.update_date DESC
        ) d
        where 1 = 1
        <if test="equipment.status != null">
            AND d.status = #{equipment.status}
        </if>
        LIMIT #{start},#{size}
    </select>

    <select id="listCount" resultType="int">
        SELECT
            count(1)
        FROM (
            SELECT
                es.id,
                IF
                ( SUM( IF ( a.equipment_specific_index_value = 'true', 1, 0 ) ) > 0, 0, 1 ) AS `status`
            FROM
            wl_equipment_specific es
            LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
            LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_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_stock_detail sd ON sd.equipment_specific_id = es.id
            LEFT JOIN wl_warehouse_structure ws ON ws.id = sd.warehouse_structure_id
            LEFT JOIN wl_equipment_specific_alarm a ON a.equipment_specific_id = es.id
            WHERE
            esi.`value` IS NOT NULL AND es.system_id IS NOT NULL
            <if test="equipment.id != null and equipment.id != 0">
                AND fs.id = #{equipment.id}
            </if>
            <if test="equipment.name != null and equipment.name != ''">
                AND (es.`code` LIKE CONCAT('%', #{equipment.name}, '%') OR ed.`name` LIKE CONCAT('%', #{equipment.name}, '%'))
            </if>
            GROUP BY
            es.id
            ORDER BY
            esi.update_date DESC
        ) d
        where 1 = 1
        <if test="equipment.status != null">
            AND d.status = #{equipment.status}
        </if>
    </select>

    <select id="get3dFightingSysEquipCount" resultType="java.util.LinkedHashMap">
        SELECT
        e.`name`,
        COUNT( DISTINCT es.id ) AS amount
        FROM
        wl_equipment_specific es
        LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_equipment e ON e.id = ed.equipment_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
        WHERE
        esi.`value` IS NOT NULL AND es.system_id IS NOT NULL
        <if test="id != null">
            AND fs.id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND (es.`code` LIKE CONCAT('%', #{name}, '%') OR ed.`name` LIKE CONCAT('%', #{name}, '%'))
        </if>
        <if test="status != null">
            <choose>
                <when test="status == 1">
                    AND a.`status` = #{status}
                </when>
                <otherwise>
                    AND a.`status` = #{status}
                </otherwise>
            </choose>
        </if>
        GROUP BY
        ed.equipment_id
    </select>
    <select id="getAirEquipSpecificList" resultType="com.yeejoin.equipmanage.common.vo.EquipmentOnCarVo">
        SELECT
        ed.`name` AS equipmentSpecificName,
        es.`code` AS equipmentSpecificCode,
        es.id AS equipmentSpecificId,
        sd.id AS stockDetailId,
        ed.id AS equipmentDetailId,
        SUM( sd.amount ) AS amount
        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 wl_equipment_category ec ON ec.id = e.category_id
        LEFT JOIN wl_stock_detail sd ON es.id = sd.equipment_specific_id
        <where>
            <if test="vo.like != null and vo.like !=''">
                (ed.`name` LIKE CONCAT('%', #{vo.like}, '%') OR ec.`code` LIKE CONCAT('%', #{vo.like}, '%'))
            </if>
            <if test="status != null">
                AND sd.`status` = #{status}
            </if>
            <if test="arr != null and arr.length > 0">
                AND
                <foreach collection="arr" item="item" index="index" open="(" close=")" separator=" AND ">
                    ec.`code` NOT LIKE CONCAT(#{item}, '%')
                </foreach>
            </if>
            AND sd.amount > 0
        </where>
        GROUP BY
        ed.id
    </select>
    <select id="onCarVoIPage" resultType="com.yeejoin.equipmanage.common.vo.EquipmentOnCarVo">
        SELECT
        ed.`name` AS equipmentSpecificName,
        e.name AS equipDefinitionName,
        es.`code` AS equipmentSpecificCode,
        es.id AS equipmentSpecificId,
        sd.id AS stockDetailId,
        ed.id AS equipmentDetailId,
        SUM( sd.amount ) AS amount,
        sd.status as status
        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 wl_equipment_category ec ON ec.id = e.category_id
        LEFT JOIN wl_stock_detail sd ON es.id = sd.equipment_specific_id
        <where>
            <if test="vo.like != null and vo.like !=''">
                ed.`name` LIKE CONCAT('%', #{vo.like}, '%')
            </if>
            <if test="vo.categories != null and vo.categories != ''">
              AND  ec.`code`  LIKE '1%' and ec.industry_code='2'
               <!--  AND cast(ec.`code` AS SIGNED INTEGER) BETWEEN 10000000 AND 12999900
                               <foreach collection="vo.categories" item="categorie" index="index" open="(" close=")" separator=",">-->
                <!--                    #{categorie}-->
                <!--                </foreach>-->
            </if>
            <if test="vo.status != null">
                AND sd.`status` = #{vo.status}
            </if>
          <!--   <if test="vo.codes != null and vo.codes != ''">
                AND
                <foreach collection="vo.codes" item="item" index="index" open="(" close=")" separator=" AND ">
                    ec.`code` NOT LIKE CONCAT(#{item}, '%')
                </foreach> 
            </if> -->
            <if test="vo.teamId != null and vo.teamId != ''">
                AND es.`team_id` = #{vo.teamId}
            </if>

            <if test="vo.agencyId != null and vo.agencyId != ''">
                AND es.`agency_id` = #{vo.agencyId}
            </if>
            AND sd.amount > 0
        </where>
        GROUP BY
        ed.id
    </select>
    <select id="getAirEquipSpecificDetail" resultType="com.yeejoin.equipmanage.common.vo.EquipmentDetailVo">
        SELECT
        sd.id,
        ed.`name` AS equipmentSpecificName,
        es.team_id as teamId,
        es.team_name AS teamName,
        mi.`name` AS manufacturer,
        ed.standard AS model,
        e.area,
        e.img,
        CONCAT_WS ("",ws.full_name,ed.area) AS location,
        sd.create_date
        FROM
        wl_stock_detail sd
        LEFT JOIN wl_equipment_specific es ON sd.equipment_specific_id = es.id
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_equipment e ON e.id = ed.equipment_id
        LEFT JOIN wl_warehouse_structure ws ON sd.warehouse_structure_id = ws.id
        LEFT JOIN wl_manufacturer_info mi ON mi.id = ed.manufacturer_id
        <where>
            <if test="stockDetailId != null">
                sd.id = #{stockDetailId}
            </if>
        </where>
    </select>
    <select id="getSysEquipClassifyList" resultType="com.yeejoin.equipmanage.common.vo.MaintenanceResourceDataVo">
        <![CDATA[
        SELECT
            e.id AS classifyId,
            e.`code` AS classifyCode,
            e.`name` AS classifyName,
            IFNULL(fs.id,-2) AS fireFightSysId,
            fs.`code` AS fireFightSysCode,
            IFNULL(fs.`name`,'其他') AS  fireFightSysName
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
            LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
            LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
        WHERE
            e.id IS NOT NULL
        GROUP BY
            fs.id,
            e.id
        ]]>
    </select>
    <select id="getSysEquipClassifyDataList" resultType="com.yeejoin.equipmanage.common.entity.MaintenanceResourceData">
        <![CDATA[
        SELECT
            es.id AS fireFacilityId,
            es.`code` AS fire_facility_code,
            ed.`name` AS fireFacilityName,
            e.id AS classifyId,
            e.`code` AS classifyCode,
            e.`name` AS classifyName,
            IFNULL( fs.id, -2 ) AS fireFightSysId,
            fs.`code` AS fireFightSysCode,
            IFNULL( fs.`name`, '其他' ) AS fireFightSysName
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
            LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
            LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
        WHERE
            e.id IS NOT NULL
        GROUP BY
            es.id
        ]]>
    </select>
    <select id="getSysEquipClassifyDataPage" resultType="com.yeejoin.equipmanage.common.vo.MaintenanceResourceDataVo">
        SELECT
            es.id AS fireFacilityId,
            es.`qr_code` AS fire_facility_code,
            ed.`name` AS fireFacilityName,
            e.id AS classifyId,
            e.`code` AS classifyCode,
            e.`name` AS classifyName,
            IFNULL( fs.id, -2 ) AS fireFightSysId,
            fs.`code` AS fireFightSysCode,
            IFNULL( fs.`name`, '其他' ) AS fireFightSysName,
            'equip' AS fireFacilityType,
            ws.source_id AS buildingId,
            ws.`name` AS buildingName,
            ed.maintenance_cycle,
            ed.area AS location
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
            LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
            LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET( fs.id, es.system_id )
            LEFT JOIN wl_stock_detail sd ON es.id = sd.equipment_specific_id
            LEFT JOIN wl_warehouse_structure ws ON sd.warehouse_structure_id = ws.id
        <where>
            e.id IS NOT NULL
            <if test="fireFightSysId != null">
                AND fs.id = #{fireFightSysId}
            </if>
            <if test="classifyId != null and classifyId != ''">
                AND e.`id` = #{classifyId}
            </if>
            <if test="fireFacilityId != null">
                AND es.id = #{fireFacilityId}
            </if>
            <if test="fireFacilityName != null and fireFacilityName != ''">
                AND (ed.`name` LIKE CONCAT('%', #{fireFacilityName}, '%') OR es.`code` LIKE CONCAT('%', #{fireFacilityName}, '%'))
            </if>
            <if test="buildingId != null and buildingId.size() > 0">
                AND ws.source_id IN
                <foreach collection="buildingId" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
            es.id
    </select>
    <select id="getEquipClassifyDataPage" resultType="com.yeejoin.equipmanage.common.vo.MaintenanceResourceDataVo">
        SELECT
            es.id AS fireFacilityId,
            es.`qr_code` AS fire_facility_code,
            ed.`name` AS fireFacilityName,
            e.id AS classifyId,
            e.`code` AS classifyCode,
            e.`name` AS classifyName,
            -2 AS fireFightSysId,
            NULL AS fireFightSysCode,
            '其他' AS fireFightSysName,
            'equip' AS fireFacilityType,
            ws.source_id AS buildingId,
            ws.`name` AS buildingName,
            ed.area AS location
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
            LEFT JOIN wl_equipment e ON ed.equipment_id = e.id
            LEFT JOIN wl_stock_detail sd ON es.id = sd.equipment_specific_id
            LEFT JOIN wl_warehouse_structure ws ON sd.warehouse_structure_id = ws.id
        <where>
            e.id IS NOT NULL
            <if test="fireFightSysId != null and fireFightSysId == -2">
                AND (es.system_id IS NULL OR es.system_id = '')
            </if>
            <if test="classifyId != null and classifyId != ''">
                AND e.`id` = #{classifyId}
            </if>
            <if test="fireFacilityId != null">
                AND es.id = #{fireFacilityId}
            </if>
            <if test="fireFacilityName != null and fireFacilityName != ''">
                AND (ed.`name` LIKE CONCAT('%', #{fireFacilityName}, '%') OR es.`code` LIKE CONCAT('%', #{fireFacilityName}, '%'))
            </if>
            <if test="buildingId != null and buildingId.size() > 0">
                AND ws.source_id IN
                <foreach collection="buildingId" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
            es.id
    </select>
    <select id="getEquipSpecificLocationInfo" resultType="com.yeejoin.equipmanage.common.dto.UserDto">
        SELECT
            ws.full_name AS personName,
            fi.field_name AS fieldCode,
            fi.field_value
        FROM
            wl_stock_detail sd
            LEFT JOIN wl_warehouse_structure ws ON sd.warehouse_structure_id = ws.id
            LEFT JOIN wl_form_instance fi ON fi.instance_id = ws.source_id
        <where>
            <if test="equipmentSpecificId != null">
                sd.equipment_specific_id = #{equipmentSpecificId}
            </if>
            <if test="fieldName != null and fieldName.length > 0">
                AND fi.field_name IN
                <foreach collection="fieldName" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="getEquipSpeInfo" resultType="Map">
        SELECT
			es.id,
			ed.`name`,
			es.`code`,
			es.`qr_code` AS qrCde,
			es.system_id,
			ws.full_name as location
		FROM
			wl_equipment_specific es
		LEFT JOIN wl_equipment_detail ed ON es.equipment_detail_id = ed.id
		LEFT JOIN wl_stock_detail sd ON es.id = sd.equipment_specific_id
		LEFT JOIN wl_warehouse_structure ws ON sd.warehouse_structure_id = ws.id
		WHERE es.id = #{equipmentSpecificId}
    </select>
    <delete id="deleteEquipDataBySpecificId">
            DELETE  es, ed, esi, ves, esr, esa, esal, eard FROM
                wl_equipment_specific es
                LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
                LEFT JOIN wl_equipment_specific_index esi ON es.id = esi.equipment_specific_id
                LEFT JOIN wl_video_equipment_specific ves ON es.id = ves.equipment_specific_id
                LEFT JOIN wl_equipment_specific_relation esr ON ed.id = esr.equipment_specific_id
                LEFT JOIN wl_equipment_specific_alarm esa ON ed.id = esa.equipment_specific_id
                LEFT JOIN wl_equipment_specific_alarm_log esal ON ed.id = esal.equipment_specific_id
                LEFT JOIN wl_equipment_alarm_report_day eard ON ed.id = eard.equipment_specific_id
             WHERE es.id = #{specificId}
    </delete>
    <delete id="deleteEquipDataByStockDetailId">
        DELETE
            sd, ws, swr, sbd, sb, wln, wb, md, wm, wlrd, wlr, weoc, eoc, wj
        FROM
            wl_stock_detail sd
            LEFT JOIN wl_stock ws ON ws.id = sd.stock_id
            LEFT JOIN wl_stock_warning_rule swr ON ws.id = swr.stock_id
            LEFT JOIN wl_stock_bill_detail sbd ON sd.id = sbd.stock_bill_id
            LEFT JOIN wl_stock_bill sb ON sb.id = sbd.stock_bill_id
            LEFT JOIN wl_notice wln ON sb.id = wln.stock_bill_id
            LEFT JOIN wl_wastage_bill_detail wbd ON sd.id = wbd.stock_detail_id
            LEFT JOIN wl_wastage_bill wb ON wb.id = wbd.wastage_bill_id
            LEFT JOIN wl_maintain_detail md ON sd.id = md.stock_detail_id
            LEFT JOIN wl_maintain wm ON wm.id = md.maintain_id
            LEFT JOIN wl_repair_detail wlrd ON sd.id = wlrd.stock_detail_id
            LEFT JOIN wl_repair wlr ON wlr.id = wlrd.repair_id
            LEFT JOIN wl_equipment_on_car weoc ON sd.id = weoc.stock_detail_id
            LEFT JOIN wl_extinguishant_on_car eoc ON sd.id = eoc.stock_detail_id
            LEFT JOIN wl_journal wj ON sd.id = wj.stock_detail_id
         WHERE sd.id = #{stockDetailId};
    </delete>
    <select id="getRainRoomIndexDetails" resultType="java.util.Map">
       SELECT
            fi.instance_id id,
            MAX(
                CASE
                WHEN fi.field_name = 'name' THEN
                    fi.field_value
                END
            ) `name`,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                LEFT JOIN `wl_equipment_specific` s ON i.equipment_specific_id = s.id
                WHERE
                    s.warehouse_structure_id = fi.instance_id
                AND i.equipment_index_key = 'FESS_TemperatureProbes_Value'
                LIMIT 1
            ) AS realTemperature,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                LEFT JOIN `wl_equipment_specific` s ON i.equipment_specific_id = s.id
                WHERE
                    s.warehouse_structure_id = fi.instance_id
                AND i.equipment_index_key = 'FESS_Humidity_Value'
                LIMIT 1
            ) AS realHumidity,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                LEFT JOIN `wl_equipment_specific` s ON i.equipment_specific_id = s.id
                WHERE
                    s.warehouse_structure_id = fi.instance_id
                AND i.equipment_index_key = 'FESS_Heater_RunStatus'
                LIMIT 1
            ) AS heaterStatus
        FROM
            `wl_form_instance` `fi`
        WHERE
            fi.group_code = 'rainRoom'
        OR fi.group_code = 'r_rainRoom'
        group by fi.instance_id
    </select>
    <select id="getTropicsIndexDetails" resultType="java.util.Map">
        SELECT
            s.id,
            s.`name`,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                WHERE
                    i.equipment_specific_id = s.id
                AND i.equipment_index_key = 'FESS_TropicsTemperature_Value'
            ) AS realTemperature,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                WHERE
                    i.equipment_specific_id = s.id
                AND i.equipment_index_key = 'FESS_Tropics_RunStatus'
            ) AS runStatus,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                WHERE
                    i.equipment_specific_id = s.id
                AND i.equipment_index_key = 'FESS_Tropics_LoseFault'
            ) AS loseFault,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                WHERE
                    i.equipment_specific_id = s.id
                AND i.equipment_index_key = 'FESS_Tropics_HotFault'
            ) AS hotFault
        FROM
            `wl_equipment_specific` s
        WHERE
            s.equipment_code = '11010300DFU44'
    </select>
    <select id="getChoiceRoomIndexDetails" resultType="java.util.Map">
        SELECT
            fi.instance_id id,
            MAX(
                CASE
                WHEN fi.field_name = 'name' THEN
                    fi.field_value
                END
            ) `name`,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                LEFT JOIN `wl_equipment_specific` s ON s.id = i.equipment_specific_id
                WHERE
                    s.warehouse_structure_id = fi.instance_id
                AND i.equipment_index_key = 'FESS_Hightemperature_Alarm'
                LIMIT 1
            ) AS highTemperatureAlarm,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                LEFT JOIN `wl_equipment_specific` s ON s.id = i.equipment_specific_id
                WHERE
                    s.warehouse_structure_id = fi.instance_id
                AND i.equipment_index_key = 'FESS_Lowtemperature_Alarm'
                LIMIT 1
            ) AS lowTemperatureAlarm
        FROM
            `wl_form_instance` `fi`
        WHERE
            fi.group_code = 'fireFoamRoom' OR fi.group_code = 'r_fireFoamRoom'
            group by fi.instance_id
    </select>
    <select id="getBoxTropicsIndexDetails" resultType="java.util.Map">
        SELECT
            s.id,
            s.`name`,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                WHERE
                    i.equipment_specific_id = s.id
                AND i.equipment_index_key = 'FESS_BoxTropics_RunStatus'
            ) AS runStatus,
            (
                SELECT
                    CONCAT_WS(',', i.value, i.update_date)
                FROM
                    `wl_equipment_specific_index` i
                WHERE
                    i.equipment_specific_id = s.id
                AND i.equipment_index_key = 'FESS_BoxTropics_LoseFault'
            ) AS loseFault
        FROM
            `wl_equipment_specific` s
        WHERE
            s.equipment_code = '92251100TZE44'
    </select>
    <select id="queryCompanyStaData" resultType="java.util.Map">
        SELECT
        s.biz_org_code as bizOrgCode,
        c.code as categoryCode,
        count(1) as total
        FROM
        `wl_equipment_specific` s,
        wl_equipment e,
        wl_equipment_category c
        where
        s.equipment_code = e.`code`
        and e.category_id = c.id
        and s.biz_org_code <![CDATA[<>]]> ''
        GROUP BY s.biz_org_code ,c.code
    </select>
</mapper>