<?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.zcloud.mapper.datasource.alarm.DBAlarmMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_DBALARM
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		SYS_DICTIONARIES
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		f.ALARMID,
		f.SCANNERALARMID,
		f.INTELLEXALARMID,
		f.SCANNERCUSTOMERNUMBER,
		f.SCANNERFEEDNUMBER,
		f.SCANNERIP,
		f.VIDEOSOURCESYSTEMID,
		f.VIDEOSOURCECHANNELID,
		f.ALARMTYPE,
		f.MANAGERSTARTTIME,
		f.MANAGERALARMTIME,
		f.MANAGERENDTIME,
		f.VIDEOSOURCEALARMSTARTTIME,
		f.VIDEOSOURCEALARMTIME,
		f.VIDEOSOURCEALARMENDTIME,
		f.JPBPATH,
		f.THUMBNAIL,
		f.THUMBNAILROWS,
		f.THUMBNAILCOLS,
		f.THUMBNAILSIZE,
		f.THUMBNAILPATH,
		f.SCANNERNAME,
		f.SPAREINT1,
		f.SPAREINT2,
		f.SPAREINT3,
		f.SPARESTR32_1,
		f.SPARESTR32_2,
		f.SPARESTR64_1,
		f.SPARESTR64_2,
		f.RULENAME,
		f.ALARMLEVELID,
		f.USERID,
		f.ACKTIME,
		f.RULENAMESTR,
		f.PTZNUMBER,
		f.SPECIESID,
		f.DVUID,
		f.DEVICEID,
		f.CORPINFO_ID,
		f.DBALARM_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		ALARMID,
		SCANNERALARMID,
		INTELLEXALARMID,
		SCANNERCUSTOMERNUMBER,
		SCANNERFEEDNUMBER,
		SCANNERIP,
		VIDEOSOURCESYSTEMID,
		VIDEOSOURCECHANNELID,
		ALARMTYPE,
		MANAGERSTARTTIME,
		MANAGERALARMTIME,
		MANAGERENDTIME,
		VIDEOSOURCEALARMSTARTTIME,
		VIDEOSOURCEALARMTIME,
		VIDEOSOURCEALARMENDTIME,
		JPBPATH,
		THUMBNAIL,
		THUMBNAILROWS,
		THUMBNAILCOLS,
		THUMBNAILSIZE,
		THUMBNAILPATH,
		SCANNERNAME,
		SPAREINT1,
		SPAREINT2,
		SPAREINT3,
		SPARESTR32_1,
		SPARESTR32_2,
		SPARESTR64_1,
		SPARESTR64_2,
		RULENAME,
		ALARMLEVELID,
		USERID,
		ACKTIME,
		RULENAMESTR,
		PTZNUMBER,
		SPECIESID,
		DVUID,
		DEVICEID,
		CORPINFO_ID,
		DBALARM_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{ALARMID},
		#{SCANNERALARMID},
		#{INTELLEXALARMID},
		#{SCANNERCUSTOMERNUMBER},
		#{SCANNERFEEDNUMBER},
		#{SCANNERIP},
		#{VIDEOSOURCESYSTEMID},
		#{VIDEOSOURCECHANNELID},
		#{ALARMTYPE},
		#{MANAGERSTARTTIME},
		#{MANAGERALARMTIME},
		#{MANAGERENDTIME},
		#{VIDEOSOURCEALARMSTARTTIME},
		#{VIDEOSOURCEALARMTIME},
		#{VIDEOSOURCEALARMENDTIME},
		#{JPBPATH},
		#{THUMBNAIL},
		#{THUMBNAILROWS},
		#{THUMBNAILCOLS},
		#{THUMBNAILSIZE},
		#{THUMBNAILPATH},
		#{SCANNERNAME},
		#{SPAREINT1},
		#{SPAREINT2},
		#{SPAREINT3},
		#{SPARESTR32_1},
		#{SPARESTR32_2},
		#{SPARESTR64_1},
		#{SPARESTR64_2},
		#{RULENAME},
		#{ALARMLEVELID},
		#{USERID},
		#{ACKTIME},
		#{RULENAMESTR},
		#{PTZNUMBER},
		#{SPECIESID},
		#{DVUID},
		#{DEVICEID},
		#{CORPINFO_ID},
		#{DBALARM_ID}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<!-- 删除-->
	<delete id="delete" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			DBALARM_ID = #{DBALARM_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ALARMID = #{ALARMID},
			SCANNERALARMID = #{SCANNERALARMID},
			INTELLEXALARMID = #{INTELLEXALARMID},
			SCANNERCUSTOMERNUMBER = #{SCANNERCUSTOMERNUMBER},
			SCANNERFEEDNUMBER = #{SCANNERFEEDNUMBER},
			SCANNERIP = #{SCANNERIP},
			VIDEOSOURCESYSTEMID = #{VIDEOSOURCESYSTEMID},
			VIDEOSOURCECHANNELID = #{VIDEOSOURCECHANNELID},
			ALARMTYPE = #{ALARMTYPE},
			MANAGERSTARTTIME = #{MANAGERSTARTTIME},
			MANAGERALARMTIME = #{MANAGERALARMTIME},
			MANAGERENDTIME = #{MANAGERENDTIME},
			VIDEOSOURCEALARMSTARTTIME = #{VIDEOSOURCEALARMSTARTTIME},
			VIDEOSOURCEALARMTIME = #{VIDEOSOURCEALARMTIME},
			VIDEOSOURCEALARMENDTIME = #{VIDEOSOURCEALARMENDTIME},
			JPBPATH = #{JPBPATH},
			THUMBNAIL = #{THUMBNAIL},
			THUMBNAILROWS = #{THUMBNAILROWS},
			THUMBNAILCOLS = #{THUMBNAILCOLS},
			THUMBNAILSIZE = #{THUMBNAILSIZE},
			THUMBNAILPATH = #{THUMBNAILPATH},
			SCANNERNAME = #{SCANNERNAME},
			SPAREINT1 = #{SPAREINT1},
			SPAREINT2 = #{SPAREINT2},
			SPAREINT3 = #{SPAREINT3},
			SPARESTR32_1 = #{SPARESTR32_1},
			SPARESTR32_2 = #{SPARESTR32_2},
			SPARESTR64_1 = #{SPARESTR64_1},
			SPARESTR64_2 = #{SPARESTR64_2},
			RULENAME = #{RULENAME},
			ALARMLEVELID = #{ALARMLEVELID},
			USERID = #{USERID},
			ACKTIME = #{ACKTIME},
			RULENAMESTR = #{RULENAMESTR},
			PTZNUMBER = #{PTZNUMBER},
			SPECIESID = #{SPECIESID},
			DVUID = #{DVUID},
			DEVICEID = #{DEVICEID},
			DBALARM_ID = DBALARM_ID
		where
			DBALARM_ID = #{DBALARM_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where
			f.DBALARM_ID = #{DBALARM_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where 1 =1
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
					f.SCANNERNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
		</if>
		order by f.MANAGERALARMTIME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
	</select>

	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			DBALARM_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>

</mapper>
