<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.AlarmInfoDAO">
	<resultMap id="AlarmInfoMap" type="AlarmInfo">
		<id property="id" column="id_" />
			<result property="createBy" column="create_by" />
			<result property="createTime" column="create_time" />
			<result property="updateBy" column="update_by" />
			<result property="updateTime" column="update_time" />
			<result property="delFlag" column="del_flag" />
			<result property="deviceNo" column="device_no" />
			<result property="channelName" column="channel_name" />
			<result property="alertType" column="alert_type" />
			<result property="type" column="type_" />
			<result property="videoUrl" column="video_url" />
			<result property="isRead" column="is_read" />
			<result property="message" column="message_" />
			</resultMap>
	<insert id="insert" parameterType="AlarmInfo">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_alarm_info
	    (id_,create_by,create_time,update_by,update_time,del_flag,device_no,channel_name,alert_type,type_,video_url,is_read,message_)
		values
		(
#{id,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{deviceNo,jdbcType=VARCHAR}
,#{channelName,jdbcType=VARCHAR}
,#{alertType,jdbcType=VARCHAR}
,#{type,jdbcType=VARCHAR}
,#{videoUrl,jdbcType=VARCHAR}
,#{isRead,jdbcType= NUMERIC }
,#{message,jdbcType=VARCHAR}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_alarm_info where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="AlarmInfo">
		update base_alarm_info
		<set>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
				<if test="deviceNo!=null">
		device_no=#{deviceNo,jdbcType=VARCHAR},
		</if>
				<if test="channelName!=null">
		channel_name=#{channelName,jdbcType=VARCHAR},
		</if>
				<if test="alertType!=null">
		alert_type=#{alertType,jdbcType=VARCHAR},
		</if>
				<if test="type!=null">
		type_=#{type,jdbcType=VARCHAR},
		</if>
			<if test="videoUrl!=null">
				video_url=#{videoUrl,jdbcType=VARCHAR},
			</if>
			<if test="isRead!=null">
				is_read=#{isRead,jdbcType=NUMERIC},
			</if>
			<if test="message!=null">
				message_=#{message,jdbcType=VARCHAR},
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="AlarmInfoMap">
		select 
id_,create_by,create_time,update_by,update_time,del_flag,device_no,channel_name,alert_type,type_		from base_alarm_info where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_alarm_info where id_=#{0}
	</select>
	<select id="list" resultMap="AlarmInfoMap">
		select * from base_alarm_info
	</select>
	<select id="search" parameterType="hashmap" resultMap="AlarmInfoMap">
		<![CDATA[
			select * from base_alarm_info
		]]>
		<where>
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.type != null">
				and type_ = #{searchParams.type}
			</if>
			<if test='searchParams.queryStartTime!=null'>
				<![CDATA[
                    and create_time >= #{searchParams.queryStartTime}
                ]]>
			</if>
			<if test='searchParams.queryEndTime!=null'>
				<![CDATA[
                    and create_time <= #{searchParams.queryEndTime}
                ]]>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
	<select id="queryLatestAlarm" parameterType="string" resultMap="AlarmInfoMap">
		select * from base_alarm_info where del_flag=0 and type_=#{0} and is_read = 0 order by create_time desc limit 1
	</select>
</mapper>