<?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.FireEquipPointMapper">


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

		<!-- select * from f_fire_equipment_point where id = ${id} -->
	</select>

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

		<!-- select count(1) from f_fire_equipment_point
		where fire_equipment_id = ${fireEqumntId}
		<if test="name!=null">
			and fp.name like '%${name}%'
		</if> -->
	</select>
	<select id="queryForPage" resultType="java.util.Map">

		<!-- select * from f_fire_equipment_point fp
		where fp.fire_equipment_id = ${fireEqumntId}
		<if test="name!=null">
			and fp.name like '%${name}%'
		</if>
		 LIMIT ${start},${length} ; -->
	</select>


	<select id="queryForEqueAndPointName" resultType="map">
		<!-- SELECT
			ep.`name`,
			(
				SELECT
					fe.`name`
				FROM
					f_fire_equipment fe
				WHERE
					fe.id = ep.fire_equipment_id
			) fireEquipmentName
		FROM
			f_fire_equipment_point ep
		WHERE
			EXISTS (
				SELECT
					1
				FROM
					f_risk_source_equipment se
				WHERE
					se.fire_equipment_id = ep.fire_equipment_id
				AND se.risk_source_id = ${riskSourceId}
			)
		AND ep.type = 'SWITCH'
		AND ep.`value` = 1 -->
	</select>


	<select id="queryStopCountByEuipmentIdAndAlarmType" resultType="int">
	<!-- SELECT
		count(1)
	FROM
		f_equipment e,
		f_equipment_fire_equipment fe,
		f_fire_equipment_point ep,
		f_dict d
	WHERE
		e.id = fe.equipment_id
	AND fe.fire_equipment_id = ep.fire_equipment_id
	and d.id = ep.alarm_type
	AND d.dict_value = #{alarmType}
	AND e.id = #{equimentId}
	AND ep.`value` = #{value} -->
	</select>

	<select id="queryCountByEuipmentIdAndAlarmType" resultType="int">
	<!--  SELECT
		count(1)
	FROM
		f_equipment e,
		f_equipment_fire_equipment fe,
		f_fire_equipment_point ep,
		f_dict d
	WHERE
		e.id = fe.equipment_id
	AND fe.fire_equipment_id = ep.fire_equipment_id
	and d.id = ep.alarm_type
	AND d.dict_value = #{alarmType}
	AND e.id = #{equimentId}-->
	</select>

	<update id="updateValue">
		<!-- update f_fire_equipment_point set value = #{state},create_date = NOW() where id = #{id} -->
	</update>

	<insert id="saveBatch" keyColumn="id" keyProperty="id"
			parameterType="com.yeejoin.amos.fas.business.param.FireEquipmentPointParam"
			useGeneratedKeys="true">
		<!--  insert into f_fire_equipment_point
		(
			name,
			code,
			fire_equipment_id,
			type,
			unit,
			alarm_type,
			org_code,
			create_by
		)
		values
		<foreach collection="list" item="item" index="index" separator=",">
		(
			#{item.name},
			#{item.code},
			#{item.fireEquipmentId},
			#{item.type},
			#{item.unit},
			#{item.alarmType},
			#{item.orgCode},
			#{item.createBy}
		)
		</foreach>-->
	</insert>

	<select id="listByMap" resultType="com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity">
		<!-- select
			a.id,
			a.name,
			a.code,
			a.fire_equipment_id as fireEquipmentId,
			a.create_by as createBy,
			a.create_date as createDate,
			a.remark,
			a.type,
			a.value,
			a.unit,
			a.org_code as orgCode,
			a.alarm_type as alarmType,
			fd.dict_name as alarmTypeName,
			b.name as fireEquipmentName,
			b.code as fireEquipmentCode
		from
			f_fire_equipment_point as a
		left join
			f_fire_equipment as b on a.fire_equipment_id = b.id
		left join f_dict fd on fd.id = a.alarm_type
		<where>
			a.org_code = #{compCode}
			<if test="searchValue!=null and searchValue.trim() != ''">
				and (a.name like concat('%',#{searchValue},'%') or a.code like concat('%',#{searchValue},'%'))
			</if>
			<if test="fireEquipmentId!=null">
				and a.fire_equipment_id = #{fireEquipmentId}
			</if>
			<if test="type!=null and type.trim() != ''">
				and a.type = #{type}
			</if>
		</where>
		order by a.create_date desc
		<if test="pageSize!=null and pageSize!=-1 and offset!=null">
			limit #{offset},#{pageSize}
		</if> -->
	</select>

	<select id="countByMap" resultType="long">
		<!-- select
			count(1)
		from
			f_fire_equipment_point as a
		<where>
			a.org_code = #{compCode}
			<if test="searchValue!=null and searchValue.trim() != ''">
				and (a.name like concat('%',#{searchValue},'%') or a.code like concat('%',#{searchValue},'%'))
			</if>
			<if test="fireEquipmentId!=null">
				and a.fire_equipment_id = #{fireEquipmentId}
			</if>
			<if test="type!=null and type.trim() != ''">
				and a.type = #{type}
			</if>
		</where> -->
	</select>

	<select id="getByCode" resultType="com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity">
		<!-- select
			id,
			name,
			code,
			fire_equipment_id as fireEquipmentId,
			create_by as createBy,
			create_date as createDate,
			remark,
			type,
			value,
			unit,
			org_code as orgCode,
			alarm_type as alarmType
		from
			f_fire_equipment_point
		where
			code = #{code}
		limit 1 -->
	</select>

    <update id="updateBatch">
       <!--  <foreach collection="list" item="item" index="index" separator=";">
            update f_fire_equipment_point
            <set>
                <if test="item.name != null">
                    name = #{item.name},
                </if>
                <if test="item.code != null">
                    code = #{item.code},
                </if>
                <if test="item.fireEquipmentId != null">
                    fire_equipment_id = #{item.fireEquipmentId},
                </if>
                <if test="item.createBy != null">
                    create_by = #{item.createBy},
                </if>
                <if test="item.createDate != null">
                    create_date = #{item.createDate},
                </if>
                <if test="item.remark != null">
                    remark = #{item.remark},
                </if>
                <if test="item.type != null">
                    type = #{item.type},
                </if>
                <if test="item.value != null">
                    value = #{item.value},
                </if>
                <if test="item.unit != null">
                    unit = #{item.unit},
                </if>
                <if test="item.orgCode != null">
                    org_code = #{item.orgCode},
                </if>
                <if test="item.alarmType != null">
                    alarm_type = #{item.alarmType},
                </if>
            </set>
            where id = #{item.id}
        </foreach> -->
    </update>

    <select id="listByCodes" resultType="com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity">
		<!-- select
			id,
			name,
			code,
			fire_equipment_id as fireEquipmentId,
			create_by as createBy,
			create_date as createDate,
			remark,
			type,
			value,
			unit,
			org_code as orgCode,
			alarm_type as alarmType
		from
			f_fire_equipment_point
		where
			code in
            <foreach collection="codes" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach> -->
	</select>

	<select id="getById" resultType="com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity">
		<!-- select
			id,
			name,
			code,
			fire_equipment_id as fireEquipmentId,
			create_by as createBy,
			create_date as createDate,
			remark,
			type,
			value,
			unit,
			org_code as orgCode,
			alarm_type as alarmType
		from
			f_fire_equipment_point
		where
			id = #{id}
		limit 1 -->
	</select>

	<select id="countBindByIds" resultType="java.lang.Long">
		<!-- select
			count(1)
		from
			f_fire_equipment_point
		where
			id in
			<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
				#{item}
			</foreach>
		and
			fire_equipment_id > 0 -->
	</select>

	<update id="updatefireEquipmentIdByIds">
		<!-- update
			f_fire_equipment_point
		set
			fire_equipment_id = #{fireEquipmentId}
		where id in
		<foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
			#{item}
		</foreach> -->
	</update>

	<insert id="save" keyColumn="id" keyProperty="id" parameterType="com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity"
			useGeneratedKeys="true">
		<!-- insert into f_fire_equipment_point
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="name != null">
				name,
			</if>
			<if test="code != null">
				code,
			</if>
			<if test="fireEquipmentId != null">
				fire_equipment_id,
			</if>
			<if test="createBy != null">
				create_by,
			</if>
			<if test="createDate != null">
				create_date,
			</if>
			<if test="remark != null">
				remark,
			</if>
			<if test="type != null">
				type,
			</if>
			<if test="value != null">
				value,
			</if>
			<if test="unit != null">
				unit,
			</if>
			<if test="orgCode != null">
				org_code,
			</if>
			<if test="alarmType != null">
				alarm_type,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="name != null">
				#{name},
			</if>
			<if test="code != null">
				#{code},
			</if>
			<if test="fireEquipmentId != null">
				#{fireEquipmentId},
			</if>
			<if test="createBy != null">
				#{createBy},
			</if>
			<if test="createDate != null">
				#{createDate},
			</if>
			<if test="remark != null">
				#{remark},
			</if>
			<if test="type != null">
				#{type},
			</if>
			<if test="value != null">
				#{value},
			</if>
			<if test="unit != null">
				#{unit},
			</if>
			<if test="orgCode != null">
				#{orgCode},
			</if>
			<if test="alarmType != null">
				#{alarmType},
			</if>
		</trim> -->
	</insert>

	<update id="update" parameterType="com.yeejoin.amos.fas.business.entity.mybatis.FireEquipmentPointEntity">
		<!-- update f_fire_equipment_point
		<set>
			<if test="name != null">
				name = #{name},
			</if>
			<if test="code != null">
				code = #{code},
			</if>
			<if test="fireEquipmentId != null">
				fire_equipment_id = #{fireEquipmentId},
			</if>
			<if test="createBy != null">
				create_by = #{createBy},
			</if>
			<if test="createDate != null">
				create_date = #{createDate},
			</if>
			<if test="remark != null">
				remark = #{remark},
			</if>
			<if test="type != null">
				type = #{type},
			</if>
			<if test="value != null">
				value = #{value},
			</if>
			<if test="unit != null">
				unit = #{unit},
			</if>
			<if test="orgCode != null">
				org_code = #{orgCode},
			</if>
			<if test="alarmType != null">
				alarm_type = #{alarmType},
			</if>
		</set>
		where id = #{id} -->
	</update>

	<delete id="deleteBatchByIds">
		<!-- delete from f_fire_equipment_point
		where
			id in
			<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
				#{item}
			</foreach> -->
	</delete>

	<select id="getPointsByEquipmentIdAndType" resultType="Map">
	 SELECT p.* from
		f_fire_equipment_point p
		LEFT JOIN f_fire_equipment fe on p.fire_equipment_id = fe.id
		LEFT JOIN f_equipment_fire_equipment e on fe.id = e.fire_equipment_id
		where e.equipment_id = #{id}
		and p.type = #{type}
	</select>

</mapper>