<?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.amos.fas.business.dao.mapper.ImpAndFireEquipMapper">



	<select id="queryForList" resultType="com.yeejoin.amos.fas.dao.entity.EquipmentFireEquipment">

		SELECT
			*
		FROM
			f_equipment_fire_equipment t
		WHERE
		1=1
		<if test="fireEquipmentId != null">
			 and t.fire_equipment_id = ${fireEquipmentId}
		</if>

			<if test="equipmentId != null">
				AND t.equipment_id = ${equipmentId};
	</if>
	</select>


	<select id="queryForOne" resultType="com.yeejoin.amos.fas.dao.entity.EquipmentFireEquipment">
		SELECT
		*
		FROM
		f_equipment_fire_equipment t
		WHERE
		t.fire_equipment_id = ${fireEquipmentId}
		AND t.equipment_id = ${equipmentId};
	</select>


	<select id="queryImpEqumtByFireEquipmt" resultType="com.yeejoin.amos.fas.dao.entity.Equipment">
		SELECT
			*
		FROM
			f_equipment f
		WHERE
			f.id IN (
				SELECT
					efe.equipment_id
				FROM
					f_equipment_fire_equipment efe
				WHERE
					efe.fire_equipment_id = ${fireEquipmentId}
			)
			LIMIT 0,1 ;
	</select>




<!-- 
	<select id="queryBindFirEqumtPage" resultType="com.yeejoin.amos.fas.dao.entity.FireEquipment">
		SELECT
			rs.`name` production_area,
			fe.id,
			fe.`code`,
			fe.`name`,
			fe.org_code,
			fe.equip_classify,
			fe.equip_type,
			fe.position3d,
			fe.room,
			fe.risk_source_id,
			fe.is_indoor,
			fe.model,
			fe.manufacturer,
			fe.floor3d
		FROM
			f_fire_equipment fe
		LEFT JOIN f_risk_source rs ON rs.id = fe.risk_source_id
		WHERE
			EXISTS (
				SELECT
					1
				FROM
					f_equipment_fire_equipment efe
				WHERE
					efe.equipment_id = ${equipmentId}
				AND efe.fire_equipment_id = fe.id
	)
	<if test="start != -1 and length != -1">
	   LIMIT ${start},${length} ;
    </if>
	</select> 

	<select id="queryBindFirEqumtPageCount" resultType="long">

		SELECT
			count(1)
		FROM
			f_fire_equipment fe
		WHERE
			EXISTS (
				SELECT
					1
				FROM
					f_equipment_fire_equipment efe
				WHERE
					efe.equipment_id = ${equipmentId}
				AND efe.fire_equipment_id = fe.id
	)
	</select>-->

	<select id="queryForCamera" resultType="map">
		SELECT
			GROUP_CONCAT(id) ids,
			GROUP_CONCAT(CODE) codes
		FROM
			f_fire_equipment f
		WHERE
			f.equip_classify = '2'
		and   EXISTS (
			SELECT
				1
			FROM
				f_equipment_fire_equipment efe
			WHERE
				efe.equipment_id =${equipmentId}
				and f.id = efe.fire_equipment_id
		)
	</select>

	<select id="queryCamera" resultType="map">
		SELECT
			GROUP_CONCAT(v.id) ids,
			GROUP_CONCAT(v.`code`) codes
		FROM
			wl_video v
			RIGHT JOIN wl_video_important_equipment e ON e.video_id = v.id
		<where>
			<if test="equipmentId !=null and equipmentId != ''">
				e.important_equipment_id = #{equipmentId}
			</if>
		</where>
	</select>
	
	<select id="findEquipVideo" resultType="map">
			SELECT
				eq.`name` equipName,
				eq.id equipId,
				eq.`code` equipCode,
				fe.id,
				fe.`code`,
				fe.`name`,
				fe.video_url url
			FROM
				f_equipment_fire_equipment efe
			LEFT JOIN f_fire_equipment fe ON fe.id = efe.fire_equipment_id
			LEFT JOIN f_equipment eq ON eq.id = efe.equipment_id
			WHERE
				fe.equip_classify = 2
			ORDER BY eq.sort_num DESC
	</select>


	<select id="existsAlarmPointByEqpPointIdAndEquipId" resultType="Boolean">
		SELECT
			1 
		FROM
			wl_equipment_specific_index ep
			LEFT JOIN wl_equipment_specific e ON e.id = ep.equipment_specific_id
			LEFT JOIN f_equipment_fire_equipment fe ON fe.fire_equipment_id = e.id
			LEFT JOIN wl_equipment_index ei on ei.id = ep.equipment_index_id
			where ei.type_code = 'FIREALARM'
			and fe.equipment_id = #{equipmentId}
			and ep.id = #{pointId}
	</select>
	
	<select id="findFireEqupmentByCode" resultType="com.yeejoin.amos.fas.business.vo.EquipmentSpecificIndexVo">
			SELECT
				id as equipmentSpecificId,
				'FIREALARM' as type
			FROM
				wl_equipment_specific
			WHERE
				`code` = #{code}
			LIMIT 1
	</select>

</mapper>