<?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.majordangersource.MonitoringDeviceSensorMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.MAJORDANGERSOURCE_ID,
		f.MONITORINGDEVICE_ID,
		f.MONITORINGDEVICESENSOR_NAME,
		f.MONITORINGDEVICESENSOR_TYPE,
		f.RANGE_MIN,
		f.RANGE_MAX,
		f.RANGE1_MIN,
		f.RANGE1_MAX,
		f.RANGE2_MIN,
		f.RANGE2_MAX,
		f.RANGE3_MIN,
		f.RANGE3_MAX,
		f.RANGE4_MIN,
		f.RANGE4_MAX,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.CORPINFO_ID,
		f.MONITORINGDEVICESENSOR_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		MAJORDANGERSOURCE_ID,
		MONITORINGDEVICE_ID,
		MONITORINGDEVICESENSOR_NAME,
		MONITORINGDEVICESENSOR_TYPE,
		RANGE_MIN,
		RANGE_MAX,
		RANGE1_MIN,
		RANGE1_MAX,
		RANGE2_MIN,
		RANGE2_MAX,
		RANGE3_MIN,
		RANGE3_MAX,
		RANGE4_MIN,
		RANGE4_MAX,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID,
		MONITORINGDEVICESENSOR_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{MAJORDANGERSOURCE_ID},
		#{MONITORINGDEVICE_ID},
		#{MONITORINGDEVICESENSOR_NAME},
		#{MONITORINGDEVICESENSOR_TYPE},
		#{RANGE_MIN},
		#{RANGE_MAX},
		#{RANGE1_MIN},
		#{RANGE1_MAX},
		#{RANGE2_MIN},
		#{RANGE2_MAX},
		#{RANGE3_MIN},
		#{RANGE3_MAX},
		#{RANGE4_MIN},
		#{RANGE4_MAX},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{CORPINFO_ID},
		#{MONITORINGDEVICESENSOR_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',
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME}
		where
			MONITORINGDEVICESENSOR_ID = #{MONITORINGDEVICESENSOR_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			MAJORDANGERSOURCE_ID = #{MAJORDANGERSOURCE_ID},
			MONITORINGDEVICE_ID = #{MONITORINGDEVICE_ID},
			MONITORINGDEVICESENSOR_NAME = #{MONITORINGDEVICESENSOR_NAME},
			MONITORINGDEVICESENSOR_TYPE = #{MONITORINGDEVICESENSOR_TYPE},
			RANGE_MIN = #{RANGE_MIN},
			RANGE_MAX = #{RANGE_MAX},
			RANGE1_MIN = #{RANGE1_MIN},
			RANGE1_MAX = #{RANGE1_MAX},
			RANGE2_MIN = #{RANGE2_MIN},
			RANGE2_MAX = #{RANGE2_MAX},
			RANGE3_MIN = #{RANGE3_MIN},
			RANGE3_MAX = #{RANGE3_MAX},
			RANGE4_MIN = #{RANGE4_MIN},
			RANGE4_MAX = #{RANGE4_MAX},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			MONITORINGDEVICESENSOR_ID = MONITORINGDEVICESENSOR_ID
		where
			MONITORINGDEVICESENSOR_ID = #{MONITORINGDEVICESENSOR_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
			d2.NAME MONITORINGDEVICESENSOR_TYPE_NAME,
			<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES_CORP d2
			on f.MONITORINGDEVICESENSOR_TYPE = d2.BIANMA and d2.CORPINFO_ID = #{pd.CORPINFO_ID} and d2.PARENT_ID = '6a724d36c3ad416fad22049d932c1987'
		where
			f.MONITORINGDEVICESENSOR_ID = #{MONITORINGDEVICESENSOR_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
			d2.NAME MONITORINGDEVICESENSOR_TYPE_NAME,
			<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES_CORP d2
			on f.MONITORINGDEVICESENSOR_TYPE = d2.DICTIONARIES_ID and d2.CORPINFO_ID = #{pd.CORPINFO_ID} and d2.PARENT_ID = '6a724d36c3ad416fad22049d932c1987'
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.MAJORDANGERSOURCE_ID != null and pd.MAJORDANGERSOURCE_ID != ''">
			and f.MAJORDANGERSOURCE_ID = #{pd.MAJORDANGERSOURCE_ID}
		</if>
		<if test="pd.MONITORINGDEVICE_ID != null and pd.MONITORINGDEVICE_ID != ''">
			and f.MONITORINGDEVICE_ID = #{pd.MONITORINGDEVICE_ID}
		</if>
		ORDER BY f.OPERATTIME DESC
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
			d2.NAME MONITORINGDEVICESENSOR_TYPE_NAME,
			<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES_CORP d2
			on f.MONITORINGDEVICESENSOR_TYPE = d2.BIANMA and d2.CORPINFO_ID = #{CORPINFO_ID} and d2.PARENT_ID = '6a724d36c3ad416fad22049d932c1987'
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
		<if test="MAJORDANGERSOURCE_ID != null and MAJORDANGERSOURCE_ID != ''">
			and f.MAJORDANGERSOURCE_ID = #{MAJORDANGERSOURCE_ID}
		</if>
		<if test="MONITORINGDEVICE_ID != null and MONITORINGDEVICE_ID != ''">
			and f.MONITORINGDEVICE_ID = #{MONITORINGDEVICE_ID}
		</if>
		ORDER BY f.MONITORINGDEVICESENSOR_TYPE ASC
	</select>

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

	<!-- 列表(根据所选ID获取数据) -->
	<select id="findByIds" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where
			MONITORINGDEVICESENSOR_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
				#{item}
		</foreach>
	</select>

</mapper>
