<?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>

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

    </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,
                    wes.equipment_code ecode,
					'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`,
                  wes.system_id systemId,
         ( SELECT GROUP_CONCAT(fs.name) FROM f_fire_fighting_system fs WHERE `wes`.`system_id`  like  CONCAT('%',fs.id,'%') )  AS systemName

         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,
                        '' as ecode,
                        'car' AS type,
                        wc.car_num AS `code`,
                         '' systemId,
                         '' systemName
					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\": 20, \"height\": 20}'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',
			equipindex.color AS emergencyLevelColor,
			equipindex.isAlarm AS isAlarm

		FROM
			(
				SELECT
					esi.equipment_index_id,
					esi.equipment_specific_id,
					esi.`value`,
					esi.emergency_level_color as color,
					esi.is_alarm as isAlarm
				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="getStatusAll" resultType="java.util.HashMap">

      select  COUNT(id)  num,  wl_video_equipment_specific.equipment_specific_id as id  from   wl_video_equipment_specific   where  find_in_set(
            wl_video_equipment_specific.equipment_specific_id,
            (
                SELECT
                    wss.point_in_scene
                FROM
                    wl_source_scene wss
                WHERE
                    wss.scene_id =  #{sceneId}
            )
        )  GROUP BY wl_video_equipment_specific.equipment_specific_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',
                (SELECT IF(SUM( IF ( wesa.`status` = 1, 1, 0 ) ) > 0, 'true', 'false' ) AS indexValue FROM wl_equipment_specific_alarm wesa WHERE wesa.equipment_specific_id = es.id) AS 'value',
                ei.is_alarm AS isAlarm,
            ei.emergency_level_color AS 'emergencyLevelColor'
        FROM
            wl_equipment_index ei,
            wl_equipment_specific es
        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,
        equipment_detail.equipment_name as eqpDefName,
        equipment_detail.equipment_id as eqpDefId,
        spec.biz_org_name as bizOrgName,
        <!-- CONCAT(area.prevName,'-',structure.NAME) AS acre,-->
        spec.position 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 spec.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="companyId != null and companyId != ''">
           and spec.agency_id = #{companyId}
        </if>
        <if test="equipCode != '' and equipCode != null">and spec.code like concat('%', #{equipCode}, '%')</if>
        <if test="equipName != '' and equipName != null">
            and spec.name like CONCAT('%', #{equipName},'%')
        </if>
        <if test="current != null and size != null">
            Limit #{current},#{size}
        </if>
    </select>

    <select id="getEquipBySourceIdCount" resultType="int">
        SELECT
       count(spec.id)
        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 spec.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="companyId != null and companyId != ''">
            and spec.agency_id = #{companyId}
        </if>
        <if test="equipCode != '' and equipCode != null">and spec.code like concat('%', #{equipCode}, '%')</if>
        <if test="equipName != '' and equipName != null">
            and spec.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
        WHERE
            wws.parent_id is not null
    </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
            DISTINCT
            es.id,
            es.`code` AS mrid,
            es.`code` AS materialObjectId,
            es.`name`,
            es.`name` AS aliasname,
            es.`code`,
            e.`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,
            ws.full_name AS fullName,
            a.`name` AS workarea,
            es.qr_code as qrCode
        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 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="getEquipSpecificDetail2"
            resultType="com.yeejoin.equipmanage.common.datasync.vo.FireEquipmentVO">
        SELECT
            ws.source_id AS buildid,
            ws.parent_id AS parentId,
            ws.biz_org_code AS bizOrgCode
        FROM
            wl_equipment_specific es
            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
            es.id = #{id}
    </select>

    <select id="getEquipSpecificDetailsByEquipmentId"
            resultType="com.yeejoin.equipmanage.common.datasync.entity.FireEquipment">
        SELECT
	        es.id,
	        ed.`name`,
			ed.`name` as aliasname,
	        IFNULL(es.`code`,'') as `code`,
	        IFNULL(es.`code`,'') AS mRid,
	        IFNULL(es.system_id,'') AS fightingSystemIds,
	        IFNULL(es.iot_code,'') AS iotCode,
	        e.`name` AS categoryName,
	        e.`code` AS categoryCode,
	        IFNULL(ws.source_id,'') AS buildId,
	        IFNULL(ws.`name`,'') AS buildName,
			IFNULL(a.`name`,'') as `workArea`,
			IFNULL(a.`id`,'') as `areaid`,
			(SELECT
				`name`
			FROM
				f_station_info
			LIMIT 1) as stationname,
			(SELECT
				station_code
			FROM
				f_station_info
			LIMIT 1) as stationCode,
			es.create_date as inUseDate,
        	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
        LEFT JOIN wl_area a ON a.id = es.area_id
        <where>
            <if test="equipmentId != null">
                es.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.team != null  and vo.carId !=null">
              and  es.team_id = (select team_id from  wl_car where id =#{vo.carId})
            </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>

            <if test="vo.bizOrgCode != null and vo.bizOrgCode != ''">
                AND es.`biz_org_code` LIKE CONCAT(#{vo.bizOrgCode}, '%')
            </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.`full_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>
            <if test="bandWbCompany != null and bandWbCompany.size() > 0">
                AND es.id NOT IN
                <foreach collection="bandWbCompany" 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.full_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>
            <if test="bandWbCompany != null and bandWbCompany.size() > 0">
                AND es.id NOT IN
                <foreach collection="bandWbCompany" 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="getEquipLocationInfo" resultType="map">
        SELECT
        wed.longitude as longitude,
        wed.latitude as latitude
        FROM
        wl_stock_detail sd
        LEFT JOIN wl_equipment_detail wed ON sd.equipment_detail_id = wed.id
        <where>
            <if test="equipmentSpecificId != null">
                sd.equipment_specific_id = #{equipmentSpecificId}
            </if>
        </where>
    </select>
    
    <select id="getEquipSpeInfo" resultType="Map">
        SELECT
			es.id,
			ed.`name`,
			es.`code`,
			es.equipment_code AS equipmentCode,
			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 FROM wl_equipment_specific WHERE id = #{specificId};
        DELETE FROM wl_equipment_detail WHERE id = (SELECT equipment_detail_id FROM wl_equipment_specific WHERE id = #{specificId});
        DELETE FROM wl_equipment_specific_alarm WHERE equipment_specific_id = #{specificId};
        DELETE FROM wl_equipment_specific_alarm_log WHERE equipment_specific_id = #{specificId};
        DELETE FROM wl_equipment_alarm_report_day WHERE equipment_specific_id = #{specificId};
        DELETE FROM wl_equipment_specific_index WHERE equipment_specific_id = #{specificId};
        DELETE FROM wl_video_equipment_specific WHERE equipment_specific_id = #{specificId};
        DELETE FROM wl_equipment_specific_relation WHERE equipment_specific_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
                LEFT JOIN wl_equipment_detail ed ON ed.id = s.equipment_detail_id
                LEFT JOIN wl_equipment e ON e.id = ed.equipment_id
                LEFT JOIN wl_equipment_category c ON c.id = e.category_id
        WHERE
            s.biz_org_code != ''
	        AND s.biz_org_code IS NOT NULL
	        AND c.`code` IS NOT NULL
	        AND c.`code` != ''
        GROUP BY
            s.biz_org_code,
            c.`code`
    </select>

    <select id="getEquipmentBySpecificId" resultType="com.yeejoin.equipmanage.common.entity.Equipment">
        select
            we.*
        from
         wl_equipment we
         LEFT JOIN `wl_equipment_detail` wed ON wed.equipment_id = we.id
         LEFT JOIN `wl_equipment_specific` wes ON wes.equipment_detail_id = wed.id
        where
            wes.id = #{specificId} AND we.is_iot = '1'
    </select>
    <select id="getListByWarehouseStructureId"
            resultType="com.yeejoin.equipmanage.common.entity.vo.EquiplistSpecificBySystemVO">
            SELECT
              spe.id,
              spe.name equipment_name,
              spe.code,
              wlec.name AS category_name
            FROM
              wl_equipment_specific AS spe
            LEFT JOIN wl_stock_detail  AS det ON det.equipment_specific_id = spe.id
            LEFT JOIN wl_equipment AS wle ON spe.equipment_code = wle.code
            LEFT JOIN wl_equipment_category AS wlec ON wlec.id = wle.category_id
            WHERE  det.amount > 0 and spe.warehouse_structure_id = #{floorId}
              <if test="isIot != null and isIot != ''">
                  and wle.is_iot = #{isIot}
              </if>

     </select>

    <select id="getStationInfo" resultType="Map">
        SELECT
			`name` AS stationName,
			station_code AS stationCode
		FROM
			f_station_info
		LIMIT 1
    </select>

    <select id="getFireMonitorInfo" resultType="Map">
        SELECT
        wes.id,
        wes.name,
        wes.position,
        wes.equipment_code equipmentCode,
        wes.realtime_iot_index_name realtimeIotIndexName,
        wes.realtime_iot_index_key realtimeIotIndexKey,
        wes.realtime_iot_index_value realtimeIotIndexValue,
        wes.value_label valueLabel,
        wes.realtime_iot_es_index_id realtimeIotSpecificIndexId,
        wes.realtime_iot_index_update_date realtiemIotIndexUpdateDate,
        wes.realtime_iot_index_id realtimeIotIndexId
        FROM
        wl_equipment_specific wes
        LEFT JOIN f_equipment_fire_equipment fire ON wes.id = fire.fire_equipment_id
        <where>
            <if test="list != null and list.length > 0">
                <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                    wes.equipment_code LIKE <![CDATA[CONCAT(#{item},'%')]]>
                </foreach>
            </if>
            <if test="equipmentId != null and equipmentId != ''">
                AND fire.equipment_id = #{equipmentId}
            </if>
        </where>
        ORDER BY realtiemIotIndexUpdateDate DESC
    </select>
    <select id="getFirePumpInfo" resultType="Map">
        SELECT
        wes.id,
        wes.name,
        wes.position,
        wes.code,
        wes.equipment_code equipmentCode,
        wes.realtime_iot_index_name realtimeIotIndexName,
        wes.realtime_iot_index_key realtimeIotIndexKey,
        wes.realtime_iot_index_value realtimeIotIndexValue,
        wes.value_label valueLabel,
        wes.realtime_iot_es_index_id realtimeIotSpecificIndexId,
        wes.realtime_iot_index_update_date realtiemIotIndexUpdateDate,
        wes.realtime_iot_index_id realtimeIotIndexId
        FROM
        wl_equipment_specific wes
        <where>
            <if test="list != null and list.length > 0">
                <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                    wes.equipment_code LIKE <![CDATA[CONCAT(#{item},'%')]]>
                </foreach>
            </if>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                and  wes.biz_org_code LIKE concat(#{bizOrgCode}, '%')
            </if>
        </where>
        ORDER BY realtiemIotIndexUpdateDate DESC
    </select>



    <select id="getFirePumpInfoEQ" resultType="Map">
        SELECT
        wes.id,
        wes.name,
        wes.position,
        wes.code,
        wes.equipment_code equipmentCode,
        wes.realtime_iot_index_name realtimeIotIndexName,
        wes.realtime_iot_index_key realtimeIotIndexKey,
        wes.realtime_iot_index_value realtimeIotIndexValue,
        wes.value_label valueLabel,
        wes.realtime_iot_es_index_id realtimeIotSpecificIndexId,
        wes.realtime_iot_index_update_date realtiemIotIndexUpdateDate,
        wes.realtime_iot_index_id realtimeIotIndexId,
        wes.iot_code iotCode,
        wes.biz_org_code bizOrgCode
        FROM
        wl_equipment_specific wes
        <where>
            <if test="list != null and list.length > 0">
                <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                   wes.equipment_code LIKE <![CDATA[CONCAT(#{item},'%')]]>
                </foreach>
            </if>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                and  wes.biz_org_code LIKE concat(#{bizOrgCode}, '%')
            </if>

        </where>
        ORDER BY realtiemIotIndexUpdateDate DESC
    </select>
    <select id="getListByEquipmentCode" resultType="Map">
        SELECT
        wes.id,
        wes.name,
        wes.code,
        wes.equipment_code equipmentCode,
        wes.realtime_iot_index_name realtimeIotIndexName,
        wes.realtime_iot_index_key realtimeIotIndexKey,
        wes.iot_code iotCode
        FROM
        wl_equipment_specific wes
        <where>
            <if test="list != null and list.length > 0">
                <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                    wes.equipment_code LIKE <![CDATA[CONCAT(#{item},'%')]]>
                </foreach>
            </if>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                AND wes.biz_org_code LIKE concat(#{bizOrgCode}, '%')
            </if>
        </where>
        ORDER BY wes.id
    </select>



    <select id="getAllEquipNum" resultType="java.lang.Integer">
        select count(*) from wl_equipment_specific
        <where>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                biz_org_code = #{bizOrgCode}
            </if>
        </where>
    </select>
    <select id="normalIndexInfoList" resultType="java.util.Map">
        SELECT
            `s`.`name` AS `equipName`,
            `si`.`equipment_index_key` AS `equipmentIndexKey`,
            (CASE si.`value` WHEN 'true' THEN '是' WHEN 'false' THEN '否' ELSE concat(si.`value`, IFNULL(wei.unit, '')) END) AS `value`,
--             (CONCAT((SELECT field_value FROM wl_form_instance_equip fie WHERE fie.instance_id = s.id AND fie.field_name like 'min%'),'-',(SELECT field_value FROM wl_form_instance_equip fie WHERE fie.instance_id = s.id AND fie.field_name like 'max%'), IFNULL(wei.unit, ''))) AS standardValue,
            '' AS standardValue,
            si.update_date AS `time`,
            `si`.`equipment_index_name` AS `equipmentIndexName`,
            `s`.`code` AS `code`,
            a.`name` AS `areaName`,
            (SELECT
            group_concat( `fs`.`charge_person_name` SEPARATOR ',' )
            FROM
            `f_fire_fighting_system` `fs`
            WHERE
            (
            0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `s`.`system_id` ))) AS `chargePersonName`,
            (SELECT
            group_concat( `fs`.`name` SEPARATOR ',' )
            FROM
            `f_fire_fighting_system` `fs`
            WHERE
            (
            0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `s`.`system_id` ))) AS `fightSysName`
        FROM
        `wl_equipment_specific_index` `si` JOIN `wl_equipment_specific` `s`
        LEFT JOIN wl_area a ON a.id = s.area_id
        LEFT JOIN wl_equipment_index wei ON wei.id = si.equipment_index_id
        WHERE
        `si`.`equipment_specific_id` = `s`.`id` AND si.is_alarm = 0
        <if test="startDate!=null">
            AND DATE_FORMAT(si.update_date,'%y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{startDate},'%y-%m-%d')
        </if>
        <if test="endDate!=null">
            AND DATE_FORMAT(si.update_date,'%y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{endDate},'%y-%m-%d')
        </if>
    </select>

    <select id="normalIndexInfoListByPage" resultType="java.util.Map">
        SELECT
        si.id,
        `s`.`name` AS `equipName`,
        `si`.`equipment_index_key` AS `equipmentIndexKey`,
        (
        CASE
        WHEN si.value_label IS NULL
        OR trim(si.value_label) = '' THEN
        (
        CASE si.`value`
        WHEN 'true' THEN
        '开'
        WHEN 'false' THEN
        '关'
        ELSE
        si.`value`
        END
        )
        ELSE
        si.value_label
        END
        ) AS `value`,
        si.unit,
        '' AS standardValue,
        DATE_FORMAT(
        si.update_date,
        '%Y-%m-%d %H:%i:%s'
        ) AS `time`,
        `si`.`equipment_index_name` AS `equipmentIndexName`,
        `s`.`code` AS `code`,
        ifnull(ed.area, '--') AS area,
        (
        SELECT
        group_concat(`fs`.`name` SEPARATOR ',')
        FROM
        `f_fire_fighting_system` `fs`
        WHERE
        (
        0 <![CDATA[<>]]> find_in_set(`fs`.`id`, `s`.`system_id`)
        )
        ) AS `fightSysName`,
        (
        SELECT
        charge_person_name
        FROM
        `f_fire_fighting_system` `fs`
        WHERE
        (
        0 <![CDATA[<>]]> find_in_set(`fs`.`id`, `s`.`system_id`)
        ) LIMIT 1
        ) AS `chargePersonName`
        FROM
        `wl_equipment_specific_index` `si`
        JOIN `wl_equipment_specific` `s`
        LEFT JOIN wl_equipment_detail ed ON s.equipment_detail_id = ed.id
        LEFT JOIN wl_equipment_index wei ON wei.id = si.equipment_index_id
        WHERE
        `si`.`equipment_specific_id` = `s`.`id`
        AND si.is_alarm = 0
        AND si.`value` IS NOT NULL
        <if test="startDate!=null">
            AND DATE_FORMAT(si.update_date,'%y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{startDate},'%y-%m-%d')
        </if>
        <if test="endDate!=null">
            AND DATE_FORMAT(si.update_date,'%y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{endDate},'%y-%m-%d')
        </if>
        <if test="name != null and name != ''">
            AND (s.name LIKE CONCAT('%', #{name}, '%') or si.equipment_index_name LIKE CONCAT('%',#{name},'%'))
        </if>
        <if test="systemCode != null and systemCode != ''">
            AND FIND_IN_SET((SELECT id FROM f_fire_fighting_system  WHERE  code = #{systemCode} ),s.system_id)
        </if>
        order by  si.update_date desc

    </select>
    <select id="getFireAutoSysInfo" resultType="java.util.Map">
        SELECT
        ifnull(`b`.`fightSysId`, NULL) AS `fightSysId`,
        ifnull(`b`.`fightSysCode`, NULL) AS `fightSysCode`,
        ifnull(`b`.`fightSysName`, NULL) AS `fightSysName`,
        ifnull(
        `b`.`reportDate`,
        `c`.`click_date`
        ) AS `reportDate`,
        ifnull(`b`.`Fault`, 0) AS `Fault`,
        ifnull(`b`.`Alarm`, 0) AS `Alarm`,
        ifnull(`b`.`Field`, 0) AS `Field`
        FROM
        (
        (
        SELECT
        curdate() AS `click_date`
        UNION ALL
        SELECT
        (curdate() - INTERVAL 1 DAY) AS `click_date`
        UNION ALL
        SELECT
        (curdate() - INTERVAL 2 DAY) AS `click_date`
        UNION ALL
        SELECT
        (curdate() - INTERVAL 3 DAY) AS `click_date`
        UNION ALL
        SELECT
        (curdate() - INTERVAL 4 DAY) AS `click_date`
        UNION ALL
        SELECT
        (curdate() - INTERVAL 5 DAY) AS `click_date`
        UNION ALL
        SELECT
        (curdate() - INTERVAL 6 DAY) AS `click_date`
        ) `c`
        LEFT JOIN (
        SELECT
        ifnull(`a`.`fightSysName`, NULL) AS `fightSysName`,
        ifnull(`a`.`fightSysCode`, NULL) AS `fightSysCode`,
        ifnull(`a`.`fightSysId`, NULL) AS `fightSysId`,
        ifnull(`a`.`report_date`, NULL) AS `reportDate`,
        sum(
        IF (
        locate('Fault', `a`.`indxKey`),
        `a`.`total`,
        0
        )
        ) AS `Fault`,
        sum(

        IF (
        locate('Alarm', `a`.`indxKey`),
        `a`.`total`,
        0
        )
        ) AS `Alarm`,
        sum(

        IF (
        locate('Shield', `a`.`indxKey`),
        `a`.`total`,
        0
        )
        ) AS `Field`
        FROM
        (
        SELECT
        `rd`.`index_type` AS `indxKey`,
        `rd`.`index_name` AS `index_name`,
        count(
        DISTINCT `rd`.`equipment_specific_id`
        ) AS `total`,
        `rd`.`report_date` AS `report_date`,
        `fs`.`name` AS `fightSysName`,
        `fs`.`code` AS `fightSysCode`,
        `fs`.`id` AS `fightSysId`
        FROM
        (
        `wl_equipment_alarm_report_day` `rd`
        LEFT JOIN `f_fire_fighting_system` `fs` ON (
        (
        0 <![CDATA[<>]]> find_in_set(
        `fs`.`id`,
        `rd`.`system_ids`
        )
        )
        )
        )
        WHERE
        (
        (
        (curdate() - INTERVAL 7 DAY) <![CDATA[<=]]> cast(`rd`.`report_date` AS date)
        )
        AND (
        `fs`.`code` = '011023306003010000000013'
        )
        AND (
        (
        `rd`.`index_type` LIKE '%Fault'
        )
        OR (
        `rd`.`index_type` LIKE '%Alarm'
        )
        OR (
        `rd`.`index_type` LIKE '%Shield'
        )
        )
        AND (`rd`.`value` = 'true')
        )
        GROUP BY
        `rd`.`equipment_specific_id`,
        `rd`.`report_date`,
        `rd`.`alarm_type_name`
        ) `a`
        GROUP BY
        `a`.`report_date`,
        `a`.`fightSysCode`
        ) `b` ON (
        (
        to_days(`c`.`click_date`) = to_days(`b`.`reportDate`)
        )
        )
        )
        ORDER BY
        `c`.`click_date`
    </select>
    <select id="getPaomoSysInfo" resultType="java.util.Map">
        SELECT
        ifnull( `b`.`equipName`, NULL ) AS `equipName`,
        ifnull( `b`.`fightSysId`, NULL ) AS `fightSysId`,
        ifnull( `b`.`fightSysCode`, NULL ) AS `fightSysCode`,
        ifnull( `b`.`fightSysName`, NULL ) AS `fightSysName`,
        ifnull( `b`.`reportDate`, `c`.`click_date` ) AS `reportDate`,
        ifnull( `b`.`FireAlarm`, 0 ) AS `FireAlarm`,
        ifnull( `b`.`Fault`, 0 ) AS `Fault`,
        ifnull( `b`.`Shield`, 0 ) AS `Shield`,
        ifnull( `b`.`Startup`, 0 ) AS `Startup`,
        ifnull( `b`.`State`, 0 ) AS `State`
        FROM
        ((
        SELECT
        curdate() AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 1 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 2 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 3 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 4 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 5 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 6 DAY ) AS `click_date`
        ) `c`
        LEFT JOIN (
        SELECT
        ifnull( `a`.`equipName`, NULL ) AS equipName,
        ifnull( `a`.`fightSysName`, NULL ) AS `fightSysName`,
        ifnull( `a`.`fightSysCode`, NULL ) AS `fightSysCode`,
        ifnull( `a`.`fightSysId`, NULL ) AS `fightSysId`,
        ifnull( `a`.`report_date`, NULL ) AS `reportDate`,
        sum(
        IF
        ( locate( 'Fault', `a`.`indxKey` ), `a`.`total`, 0 )) AS `Fault`,
        sum(
        IF
        ( locate( 'FireAlarm', `a`.`indxKey` ), `a`.`total`, 0 )) AS `FireAlarm`,
        sum(
        IF
        ( locate( 'Shield', `a`.`indxKey` ), `a`.`total`, 0 )) AS `Shield`,
        sum(
        IF
        ( locate( 'Start', `a`.`indxKey` ), `a`.`total`, 0 )) AS `Startup`,
        sum(
        IF
        ( locate( 'State', `a`.`indxKey` ), `a`.`total`, 0 )) AS `State`
        FROM
        (
        SELECT
        rd.equipment_specific_name AS equipName,
        `rd`.`index_type` AS `indxKey`,
        `rd`.`index_name` AS `index_name`,
        count( DISTINCT `rd`.`equipment_specific_id` ) AS `total`,
        `rd`.`report_date` AS `report_date`,
        `fs`.`name` AS `fightSysName`,
        `fs`.`code` AS `fightSysCode`,
        `fs`.`id` AS `fightSysId`
        FROM
        (
        `wl_equipment_alarm_report_day` `rd`
        LEFT JOIN `f_fire_fighting_system` `fs` ON ((
        0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `rd`.`system_ids` ))))
        WHERE
        (((
        curdate() - INTERVAL 7 DAY
        ) <![CDATA[<=]]> cast( `rd`.`report_date` AS date ))
        AND ( `fs`.`code` = '011023306003010000000075' )
        AND ((
        `rd`.`index_type` LIKE '%Fault'
        )
        OR ( `rd`.`index_type` LIKE '%FireAlarm' )
        OR ( `rd`.`index_type` LIKE '%Shield' )
        OR ( `rd`.`index_type` LIKE '%Start' )
        OR ( `rd`.`index_type` LIKE '%State' ))
        AND ( `rd`.`value` = 'true' ))
        GROUP BY
        `rd`.`equipment_specific_id`,
        `rd`.`report_date`,
        `rd`.`alarm_type_name`
        ) `a`
        GROUP BY
        `a`.`report_date`,
        `a`.`fightSysCode`
        ) `b` ON ((
        to_days( `c`.`click_date` ) = to_days( `b`.`reportDate` ))))
        ORDER BY
        `c`.`click_date`
    </select>
    <select id="getWaterSysInfo" resultType="java.util.Map">
        SELECT
        ifnull( `b`.`equipName`, NULL ) AS `equipName`,
        ifnull( `b`.`fightSysId`, NULL ) AS `fightSysId`,
        ifnull( `b`.`fightSysCode`, NULL ) AS `fightSysCode`,
        ifnull( `b`.`fightSysName`, NULL ) AS `fightSysName`,
        ifnull( `b`.`reportDate`, `c`.`click_date` ) AS `reportDate`,
        ifnull( `b`.`FireAlarm`, 0 ) AS `alarm`
        FROM
        ((
        SELECT
        curdate() AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 1 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 2 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 3 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 4 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 5 DAY ) AS `click_date` UNION ALL
        SELECT
        ( curdate() - INTERVAL 6 DAY ) AS `click_date`
        ) `c`
        LEFT JOIN (
        SELECT
        ifnull( `a`.`equipName`, NULL ) AS `equipName`,
        ifnull( `a`.`fightSysName`, NULL ) AS `fightSysName`,
        ifnull( `a`.`fightSysCode`, NULL ) AS `fightSysCode`,
        ifnull( `a`.`fightSysId`, NULL ) AS `fightSysId`,
        ifnull( `a`.`report_date`, NULL ) AS `reportDate`,
        sum(
        IF
        ( locate( 'Alarm', `a`.`indxKey` ), `a`.`total`, 0 )) AS `FireAlarm`
        FROM
        (
        SELECT
        rd.equipment_specific_name AS equipName,
        `rd`.`index_type` AS `indxKey`,
        `rd`.`index_name` AS `index_name`,
        count( DISTINCT `rd`.`equipment_specific_id` ) AS `total`,
        `rd`.`report_date` AS `report_date`,
        `fs`.`name` AS `fightSysName`,
        `fs`.`code` AS `fightSysCode`,
        `fs`.`id` AS `fightSysId`
        FROM
        (
        `wl_equipment_alarm_report_day` `rd`
        LEFT JOIN `f_fire_fighting_system` `fs` ON ((
        0 <![CDATA[<>]]> find_in_set( `fs`.`id`, `rd`.`system_ids` ))))
        WHERE
        (((
        curdate() - INTERVAL 7 DAY
        ) <![CDATA[<=]]> cast( `rd`.`report_date` AS date ))
        AND ( `fs`.`code` = '029026401813010000000047' )
        AND (( `rd`.`index_type` LIKE '%Alarm' )
        )
        AND ( `rd`.`value` = 'true' ))
        GROUP BY
        `rd`.`equipment_specific_id`,
        `rd`.`report_date`,
        `rd`.`alarm_type_name`
        ) `a`
        GROUP BY
        `a`.`report_date`,
        `a`.`fightSysCode`
        ) `b` ON ((
        to_days( `c`.`click_date` ) = to_days( `b`.`reportDate` ))))
        ORDER BY
        `c`.`click_date`
    </select>

    <select id="getEquipmentStatisticsInfo" resultType="java.util.Map">
        SELECT
            (
                SELECT
                    COUNT(DISTINCT wes.id)
                FROM
                    `wl_equipment_specific` wes
                        LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
                WHERE
                    wed.`code` LIKE CONCAT(#{map.extinguisher},'%')
                    <if test="map.bizOrgCode != null and map.bizOrgCode != ''">
                        AND wes.biz_org_code LIKE concat(#{map.bizOrgCode}, '%')
                    </if>
            ) AS 'extinguisher',
                (
                    SELECT
                        COUNT(DISTINCT c.id)
                    FROM
                        `wl_car` c
                            LEFT JOIN wl_equipment we ON we.id = c.equipment_id
                    WHERE
                        we.`code` LIKE CONCAT(#{map.car},'%')
                        <if test="map.bizOrgCode != null and map.bizOrgCode != ''">
                            AND c.biz_org_code LIKE concat(#{map.bizOrgCode}, '%')
                        </if>
                    ) AS 'car',
                (
                    SELECT
                        COUNT(DISTINCT wes.id)
                    FROM
                        `wl_equipment_specific` wes
                            LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
                    WHERE
                        wed.`code` LIKE CONCAT(#{map.foamtank},'%')
                        <if test="map.bizOrgCode != null and map.bizOrgCode != ''">
                            AND wes.biz_org_code LIKE concat(#{map.bizOrgCode}, '%')
                        </if>
                    ) AS 'foamtank'
    </select>

    <select id="fireSysIotEquipCount" resultType="com.yeejoin.equipmanage.common.dto.FireFightingSystemDto">
        SELECT
            fs.id,
            fs.`code`,
            fs.`name`,
            fs.`sort`,
            SUM(IF(e.is_iot = 1,1,0)) AS equipTotal,
            ec.image
        FROM
            f_fire_fighting_system fs
                LEFT JOIN `wl_equipment_specific` `wes` ON find_in_set( `fs`.`id`, `wes`.`system_id` )
                LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
                LEFT JOIN wl_equipment e ON wed.`equipment_id` = e.`id`
                LEFT JOIN wl_equipment_category ec ON ec.id = fs.system_type
        <where>
            fs.`name` != '其他系统'
            <if test="bizOrgCode!=null and bizOrgCode!=''">
                AND fs.biz_org_code like concat(#{bizOrgCode}, '%')
            </if>
        </where>
        GROUP BY
            fs.id
        ORDER BY
            fs.sort
    </select>
    <select id="fireSysIotEquipAlarmCount" resultType="com.yeejoin.equipmanage.common.dto.FireFightingSystemDto">
        SELECT
            s.id,
            s.`name`,
            IFNULL(s.alarmEquipTotal, 0) AS alarmEquipTotal,
            IF(s.countAlarmEquipTotal > 0,1,0) AS `status`
        FROM
            (SELECT
            fs.id,
            fs.`name`,
            SUM(IF(TO_DAYS(wesi.update_date) = TO_DAYS(#{date}),1,0)) AS alarmEquipTotal,
            COUNT( 1 ) AS countAlarmEquipTotal
            FROM
            f_fire_fighting_system fs
            LEFT JOIN `wl_equipment_specific` `wes` ON find_in_set( `fs`.`id`, `wes`.`system_id` )
            LEFT JOIN wl_equipment_specific_alarm wesi ON wesi.equipment_specific_id = wes.id
            <where>
                wesi.`status` = '1'
                <if test="bizOrgCode!=null and bizOrgCode!=''">
                    AND fs.biz_org_code like concat(#{bizOrgCode}, '%')
                </if>
            </where>
            GROUP BY
            fs.id) s
    </select>

    <select id="getWater" resultType="java.util.Map">
         SELECT
        r.*
        FROM
        cb_water_resource r
        LEFT JOIN cb_water_resource_pool rp ON rp.resource_id = r.sequence_nbr


        WHERE
        r.resource_type in ( 'industryPool','pool')
        and FIND_IN_SET( #{id}, rp.level_device_id) > 0

    </select>

    <select id="getStationCode" resultType="java.util.Map">
             SELECT
            u.`station_code`,
              u.`station_name`
            from
            (SELECT
            s.`code` as station_code ,
            b.biz_org_code,
            b.biz_org_name as station_name
            FROM
            `idx_biz_station_info` s,
             cb_org_usr b
            where s.`code` = b.`code`) u
            where LOCATE(u.biz_org_code, (SELECT  wl_equipment_specific.biz_org_code   FROM  wl_equipment_specific   WHERE  wl_equipment_specific.id=#{id})) > 0
    </select>
    <select id="getEquipmentSpecificIotCodeWYB"
            resultType="com.yeejoin.equipmanage.common.entity.vo.EquipmentSpecificVo">
            select iot_code from wl_equipment_specific where equipment_code = '92010800KAL44' and iot_code is not null
    </select>

    <select id="getEquipSpecificEntityByCode" resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecific">
        SELECT
            *,
            IF(SUM( IF ( a.equipment_specific_index_value = 'true', 1, 0 ) ) > 0, '异常', '正常' ) AS equipCondition
        FROM
            wl_equipment_specific es
            LEFT JOIN wl_equipment_specific_alarm a ON a.equipment_specific_id = es.id
        <where>
            <if test="code != '' and code != null">
                AND es.code like CONCAT('%',#{code},'%')
            </if>
        </where>
    </select>
    <select id="getEquipment" resultType="com.yeejoin.equipmanage.common.entity.vo.ImportantEquipmentVO">
        SELECT
            a.id,
            a.`name`,
            a.`status`,
            a.risk_source_id AS riskSource,
            'equipment' AS type
        FROM
            `f_equipment` a
    </select>

    <update id="updateEquipSpecificStatus">
        update wl_equipment_specific set equip_status = #{status} where id = #{id}
    </update>

    <update id="updateWaterResourceStatus">
        update cb_water_resource set water_status = #{status} where equip_id = #{id}
    </update>

    <select id="getEquipStatusList" resultType="java.lang.String">
        SELECT
            wles.equip_status AS equipStatus
        FROM
            `wl_equipment_specific` `wles`
            LEFT JOIN f_fire_fighting_system fs ON FIND_IN_SET(fs.id, wles.system_id)
        WHERE
            fs.id = #{id}
            ORDER BY wles.equip_status DESC
            limit 1
    </select>

    <select id="getSpecificStatusByEquipmentCode" resultType="java.lang.String">
        SELECT
            wles.equip_status AS equipStatus
        FROM
            `wl_equipment_specific` `wles`
        WHERE
            wles.equipment_code = #{equipCode}
            ORDER BY wles.equip_status DESC
            limit 1
    </select>

    <select id="countEquipStatusListByEquipId" resultType="java.lang.Long">
        SELECT
            cwr.sequence_nbr AS id
        FROM
            cb_water_resource cwr
        where
            cwr.equip_id = #{id}
    </select>

    <select id="updateEquipSpecificStatusByCheckInput" resultType="java.lang.String">
        SELECT
            ppc.equipment_id
        FROM
            p_check_input ci
                LEFT JOIN `p_point_classify` ppc ON ci .point_classify_id = ppc.id
        WHERE ci.id = #{id}
    </select>

    <select id="selectListByPatrolCheck" resultType="map">
        SELECT
            c.*
        FROM
            p_check c
                LEFT JOIN p_check_input ci on  ci.check_id = c.id
                LEFT JOIN p_point_classify ppc on  ci .point_classify_id = ppc.id
        WHERE
            ppc.equipment_id = #{id}
    </select>


    <select id="selectIdsByPatrolCheck" resultType="string">
        SELECT
            c.id
        FROM
            p_check c
                LEFT JOIN p_check_input ci on  ci.check_id = c.id
                LEFT JOIN p_point_classify ppc on  ci .point_classify_id = ppc.id
        WHERE
            ppc.equipment_id = #{id}
    </select>

    <select id="queryCheckInputItemsByCheckId" resultType="Map">
        SELECT
            ci.check_id as id,
            ppc.point_id pointId,
            ii.item_no,
            ii.NAME inputItem,
            ci.input_value,
            CASE
                ci.is_ok
                WHEN 1 THEN
                    '合格'
                WHEN 2 THEN
                    '不合格' ELSE '漏检'
                END AS is_ok,
            ii.biz_org_code,
            ii.biz_org_name,
            ci.score ,
            ci.id as traceId,
            ppc.equipment_id as equipId
        FROM
                p_check_input ci
                LEFT JOIN p_input_item ii ON ii.id = ci.input_id
                LEFT JOIN p_point_classify ppc on ci.point_classify_id = ppc.id
        WHERE
            ci.id = #{checkId}
        ORDER BY
            ci.order_no
    </select>

    <select id="getPointById" resultType="Map">
        SELECT
        p.id,
        p.route_name routeName,
        p.point_no pointNo,
        p.NAME pointName,
        (CASE p.is_fixed
        WHEN 1 THEN
        '固定点'
        ELSE
        '移动点'
        END) fixed,
        p.charge_person_name userName,
        p.biz_org_name departmentName,
        IFNULL(p.risk_source_id, '') as buildingId,
        p.remark,
        p.offline
        FROM
        p_point p
        where p.id = #{pointId}
    </select>

    <select id="getEquipIdByCheckInputId" resultType="String">
        SELECT
            ppc.equipment_id as equipId
        FROM
            p_check_input pci
            LEFT JOIN p_point_classify ppc on pci.point_classify_id = ppc.id
        WHERE
            pci.id = #{id}
        limit 1
    </select>

    <select id="getPatrolData" resultType="Map">
        SELECT
            pp.id pointId,
            pp.NAME pointName,
            pp.point_no pointNo,
            pc.is_ok pointStatus,
            ppl. NAME planName,
            pc.dep_name departmentName,
            pc.user_name username,
            pc.check_time checkTime,
            pc.remark checkRemark,
            pci.check_id checkId,
            pci.remark,
            pii.name inputName,
            pii.risk_desc riskDesc,
            pii.item_type itemType,
            pii.item_type itemType,
            pii.data_json dataJson,
            pii.is_must isMust,
            pii.picture_json pictureJson,
            pii.is_multiline isMultiline,
            pci.input_value inputValue,
            pci.is_ok inputStatus,
            pci.input_id checkInputId,
            pci.order_no orderNo,
            pci.point_classify_name classifyName,
            pci.point_classify_id classifyId,
            pr.name routeName
        FROM
            p_check_input pci
            INNER JOIN p_input_item pii ON  pii.id = pci.input_id
            LEFT JOIN p_check pc ON pc.id = pci.check_id
            LEFT JOIN p_point pp ON pp.id = pc.point_id
            LEFT JOIN p_plan ppl ON ppl.id = pc.plan_id
            LEFT JOIN `p_route` pr ON pr.id = pc.`route_id`
        WHERE
            pci.id = #{checkId}
        order by pci.order_no
        limit 1
    </select>

    <select id="getListByIds" resultType="Map">
        SELECT
            wes.id,
            wes.name,
            wes.position,
            wes.code,
            wes.equipment_code equipmentCode,
            wes.realtime_iot_index_name realtimeIotIndexName,
            wes.realtime_iot_index_key realtimeIotIndexKey,
            wes.realtime_iot_index_value realtimeIotIndexValue,
            wes.value_label valueLabel,
            wes.realtime_iot_es_index_id realtimeIotSpecificIndexId,
            wes.realtime_iot_index_update_date realtiemIotIndexUpdateDate,
            wes.realtime_iot_index_id realtimeIotIndexId
        FROM
            wl_equipment_specific wes
            <where>
                <if test="list != null and list.length > 0">
                    <foreach collection="list" item="item" index="index" open="(" close=")" separator="OR">
                        wes.id = #{item}
                    </foreach>
                </if>
                <if test="bizOrgCode != null and bizOrgCode != ''">
                    and  wes.biz_org_code LIKE concat(#{bizOrgCode}, '%')
                </if>
            </where>
    </select>

    <select id="getListByCode" resultType="Map">
        SELECT
        wes.id,
        wes.name,
        wes.position,
        wes.code,
        wes.equipment_code equipmentCode,
        wes.realtime_iot_index_name realtimeIotIndexName,
        wes.realtime_iot_index_key realtimeIotIndexKey,
        wes.realtime_iot_index_value realtimeIotIndexValue,
        wes.value_label valueLabel,
        wes.realtime_iot_es_index_id realtimeIotSpecificIndexId,
        wes.realtime_iot_index_update_date realtiemIotIndexUpdateDate,
        wes.realtime_iot_index_id realtimeIotIndexId
        FROM
        wl_equipment_specific wes
        <where>
            <if test="code != null and code != ''">
                wes.equipment_code = #{code}
            </if>
            <if test="bizOrgCode != null and bizOrgCode != ''">
                and wes.biz_org_code LIKE concat(#{bizOrgCode}, '%')
            </if>
        </where>
    </select>

    <select id="getEquipStatusList" resultType="java.lang.String">
        SELECT
            pci.check_id AS `id`
        FROM
            p_check_input pci
        WHERE
            pci.id = #{id}
            limit 1
    </select>

    <select id="getMonitoringUnitList" resultMap="CategoryAmountList">
        SELECT
            wes.id,
            wes.biz_org_code as bizOrgCode,
            wes.biz_org_name as bizOrgName,
            wes.name as equipmentName,
            wed.equipment_name systemType,
            wes.equip_status AS equipStatus
        FROM
            wl_equipment_specific wes
        LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
        <where>
            <if test="equipTypeAmountPage.bizOrgCode!=null and equipTypeAmountPage.bizOrgCode!=''">
                AND  wes.biz_org_code LIKE CONCAT(#{equipTypeAmountPage.bizOrgCode},'%')
            </if>
            <if test="equipTypeAmountPage.equipStatus!=null and equipTypeAmountPage.equipStatus!=''">
                And wes.equip_status = #{equipTypeAmountPage.equipStatus}
            </if>
            <if test="equipTypeAmountPage.equipmentClassificationCode!=null and equipTypeAmountPage.equipmentClassificationCode!=''">
                and wed.`code` like concat(#{equipTypeAmountPage.equipmentClassificationCode}, '%')
            </if>
            AND wed.equipment_name is not null
        </where>
        ORDER BY  CONVERT(bizOrgName USING gbk) ASC, equipStatus DESC
    </select>
    <select id="getMonitoringCount" resultType="java.util.Map">
        SELECT
            wes.id,
            count(wed.code) AS count,
            LEFT(wed.code, 8) AS code,
            wed.equipment_name name
                FROM
                    wl_equipment_specific wes
                    LEFT JOIN wl_equipment_detail wed ON wed.id = wes.equipment_detail_id
                WHERE
                    wes.biz_org_code LIKE CONCAT( #{bizOrgCode}, '%' )
                  AND wed.equipment_name is not null
                GROUP BY code
    </select>

    <select id="getMonitoringEquip" resultType="java.util.Map">
       SELECT IFNULL(SUM(IF(aqr.SOURCE = 'equip', 1, 0)), 0) as num FROM dl_amos_idx_biz.idx_access_qrcode_record aqr WHERE aqr.buss_id = #{id}
    </select>
    <select id="getMonitoringOther" resultType="java.util.Map">
        SELECT IFNULL(SUM(IF(aqr.SOURCE != 'equip', 1, 0)), 0) as num FROM dl_amos_idx_biz.idx_access_qrcode_record aqr WHERE aqr.buss_id = #{id}
    </select>

    <update id="updateEquipQrCode" parameterType="list">
        UPDATE wl_equipment_specific SET equip_status = #{status} WHERE id IN
        <foreach collection="ids" separator="," item="id" open="(" close=")">
            #{id}
        </foreach>
    </update>

</mapper>