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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.MONITORINGDEVICE_NAME,
		f.MONITORINGDEVICE_NUMBER,
		f.MONITORINGDEVICE_TYPE,
		f.MONITORINGDEVICE_STATUS,
		f.MONITORINGDEVICE_LONGITUDE,
		f.MONITORINGDEVICE_LATITUDE,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.CORPINFO_ID,
		f.MONITORINGDEVICE_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		MONITORINGDEVICE_NAME,
		MONITORINGDEVICE_NUMBER,
		MONITORINGDEVICE_TYPE,
		MONITORINGDEVICE_STATUS,
		MONITORINGDEVICE_LONGITUDE,
		MONITORINGDEVICE_LATITUDE,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID,
		MONITORINGDEVICE_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{MONITORINGDEVICE_NAME},
		#{MONITORINGDEVICE_NUMBER},
		#{MONITORINGDEVICE_TYPE},
		#{MONITORINGDEVICE_STATUS},
		#{MONITORINGDEVICE_LONGITUDE},
		#{MONITORINGDEVICE_LATITUDE},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{CORPINFO_ID},
		#{MONITORINGDEVICE_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
			MONITORINGDEVICE_ID = #{MONITORINGDEVICE_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			MONITORINGDEVICE_NAME = #{MONITORINGDEVICE_NAME},
			MONITORINGDEVICE_NUMBER = #{MONITORINGDEVICE_NUMBER},
			MONITORINGDEVICE_TYPE = #{MONITORINGDEVICE_TYPE},
			MONITORINGDEVICE_STATUS = #{MONITORINGDEVICE_STATUS},
			MONITORINGDEVICE_LONGITUDE = #{MONITORINGDEVICE_LONGITUDE},
			MONITORINGDEVICE_LATITUDE = #{MONITORINGDEVICE_LATITUDE},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			MONITORINGDEVICE_ID = MONITORINGDEVICE_ID
		where
			MONITORINGDEVICE_ID = #{MONITORINGDEVICE_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		SELECT
		d2.NAME MONITORINGDEVICE_TYPE_NAME,
		<include refid="Field"></include>
		FROM
		<include refid="tableName"></include> f
		LEFT JOIN
		<include refid="dicTableName"></include> d2
		ON f.MONITORINGDEVICE_TYPE = d2.BIANMA AND d2.PARENT_ID = '6a724d36c3ad416fad22049d932c1987'
		WHERE
			f.MONITORINGDEVICE_ID = #{MONITORINGDEVICE_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		SELECT
		d2.NAME MONITORINGDEVICE_TYPE_NAME,
		<include refid="Field"></include>
		FROM
		<include refid="tableName"></include> f
		LEFT JOIN
		<include refid="dicTableName"></include> d2
		ON f.MONITORINGDEVICE_TYPE = d2.BIANMA AND d2.PARENT_ID = '6a724d36c3ad416fad22049d932c1987'
		WHERE f.ISDELETE = '0' AND f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 设备名称 -->
			AND f.MONITORINGDEVICE_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.MONITORINGDEVICE_TYPE != null and pd.MONITORINGDEVICE_TYPE != ''"><!-- 设备类型 -->
			AND f.MONITORINGDEVICE_TYPE = #{pd.MONITORINGDEVICE_TYPE}
		</if>
		<if test="pd.MONITORINGDEVICE_STATUS != null and pd.MONITORINGDEVICE_STATUS != ''"><!-- 设备状态 -->
			AND f.MONITORINGDEVICE_STATUS = #{pd.MONITORINGDEVICE_STATUS}
		</if>
		ORDER BY f.OPERATTIME DESC
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		SELECT
		d2.NAME MONITORINGDEVICE_TYPE_NAME,
		<include refid="Field"></include>
		FROM
		<include refid="tableName"></include> f
		LEFT JOIN
		<include refid="dicTableName"></include> d2
		ON f.MONITORINGDEVICE_TYPE = d2.BIANMA AND d2.PARENT_ID = '6a724d36c3ad416fad22049d932c1987'
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
	</select>

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

</mapper>
