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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.MAJORDANGERSOURCE_ID,
		f.MAJORDANGERSOURCE_NAME,
		f.MAJORDANGERSOURCE_TYPE,
		f.MAJORDANGERSOURCE_ADDRESS,
		f.MAJORDANGERSOURCE_LONGITUDE,
		f.MAJORDANGERSOURCE_LATITUDE,
		f.MAJORDANGERSOURCE_NUMBER,
		f.MAJORDANGERSOURCE_STATUS,
		f.USE_DATE,
		f.DECLARATION_LEVEL,
		f.STORAGE_ACTUAL,
		f.STORAGE_MAX,
		f.CONTROL_MEASURES,
		f.BRANCHEMERGENCYPLAN_NAME,
		f.BRANCHEMERGENCYPLAN_FILEPATH,
		f.RESPONSIBLE_PERSON_NAME,
		f.RESPONSIBLE_PERSON_PHONE,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.CORPINFO_ID,
		f.MAJORDANGERSOURCELOG_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		MAJORDANGERSOURCE_ID,
		MAJORDANGERSOURCE_NAME,
		MAJORDANGERSOURCE_TYPE,
		MAJORDANGERSOURCE_ADDRESS,
		MAJORDANGERSOURCE_LONGITUDE,
		MAJORDANGERSOURCE_LATITUDE,
		MAJORDANGERSOURCE_NUMBER,
		MAJORDANGERSOURCE_STATUS,
		USE_DATE,
		DECLARATION_LEVEL,
		STORAGE_ACTUAL,
		STORAGE_MAX,
		CONTROL_MEASURES,
		BRANCHEMERGENCYPLAN_NAME,
		BRANCHEMERGENCYPLAN_FILEPATH,
		RESPONSIBLE_PERSON_NAME,
		RESPONSIBLE_PERSON_PHONE,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID,
		MAJORDANGERSOURCELOG_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{MAJORDANGERSOURCE_ID},
		#{MAJORDANGERSOURCE_NAME},
		#{MAJORDANGERSOURCE_TYPE},
		#{MAJORDANGERSOURCE_ADDRESS},
		#{MAJORDANGERSOURCE_LONGITUDE},
		#{MAJORDANGERSOURCE_LATITUDE},
		#{MAJORDANGERSOURCE_NUMBER},
		#{MAJORDANGERSOURCE_STATUS},
		#{USE_DATE},
		#{DECLARATION_LEVEL},
		#{STORAGE_ACTUAL},
		#{STORAGE_MAX},
		#{CONTROL_MEASURES},
		#{BRANCHEMERGENCYPLAN_NAME},
		#{BRANCHEMERGENCYPLAN_FILEPATH},
		#{RESPONSIBLE_PERSON_NAME},
		#{RESPONSIBLE_PERSON_PHONE},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{CORPINFO_ID},
		#{MAJORDANGERSOURCELOG_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
			MAJORDANGERSOURCELOG_ID = #{MAJORDANGERSOURCELOG_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			MAJORDANGERSOURCE_ID = #{MAJORDANGERSOURCE_ID},
			MAJORDANGERSOURCE_NAME = #{MAJORDANGERSOURCE_NAME},
			MAJORDANGERSOURCE_TYPE = #{MAJORDANGERSOURCE_TYPE},
			MAJORDANGERSOURCE_ADDRESS = #{MAJORDANGERSOURCE_ADDRESS},
			MAJORDANGERSOURCE_LONGITUDE = #{MAJORDANGERSOURCE_LONGITUDE},
			MAJORDANGERSOURCE_LATITUDE = #{MAJORDANGERSOURCE_LATITUDE},
			MAJORDANGERSOURCE_NUMBER = #{MAJORDANGERSOURCE_NUMBER},
			MAJORDANGERSOURCE_STATUS = #{MAJORDANGERSOURCE_STATUS},
			USE_DATE = #{USE_DATE},
			DECLARATION_LEVEL = #{DECLARATION_LEVEL},
			STORAGE_ACTUAL = #{STORAGE_ACTUAL},
			STORAGE_MAX = #{STORAGE_MAX},
			CONTROL_MEASURES = #{CONTROL_MEASURES},
			BRANCHEMERGENCYPLAN_NAME = #{BRANCHEMERGENCYPLAN_NAME},
			BRANCHEMERGENCYPLAN_FILEPATH = #{BRANCHEMERGENCYPLAN_FILEPATH},
			RESPONSIBLE_PERSON_NAME = #{RESPONSIBLE_PERSON_NAME},
			RESPONSIBLE_PERSON_PHONE = #{RESPONSIBLE_PERSON_PHONE},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			MAJORDANGERSOURCELOG_ID = MAJORDANGERSOURCELOG_ID
		where
			MAJORDANGERSOURCELOG_ID = #{MAJORDANGERSOURCELOG_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		d2.NAME MAJORDANGERSOURCE_TYPE_NAME,
		d8.NAME DECLARATION_LEVEL_NAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d2
		on f.MAJORDANGERSOURCE_TYPE = d2.BIANMA and d2.PARENT_ID = '6f7469fadb75401e9928edb0ab19b17e'
		left join
		<include refid="dicTableName"></include> d8
		on f.DECLARATION_LEVEL = d8.BIANMA and d8.PARENT_ID = '246a2fe3af964eb18f0e005339e334dd'
		where
			f.MAJORDANGERSOURCELOG_ID = #{MAJORDANGERSOURCELOG_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		d2.NAME MAJORDANGERSOURCE_TYPE_NAME,
		d8.NAME DECLARATION_LEVEL_NAME,
		u.NAME USER_NAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d2
			on f.MAJORDANGERSOURCE_TYPE = d2.BIANMA and d2.PARENT_ID = '6f7469fadb75401e9928edb0ab19b17e'
		left join
			<include refid="dicTableName"></include> d8
			on f.DECLARATION_LEVEL = d8.BIANMA and d8.PARENT_ID = '246a2fe3af964eb18f0e005339e334dd'
			LEFT JOIN SYS_USER u ON u.USERNAME = f.CREATOR
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.MAJORDANGERSOURCE_ID != null and pd.MAJORDANGERSOURCE_ID != ''"><!-- 重大危险源ID -->
			and f.MAJORDANGERSOURCE_ID = #{pd.MAJORDANGERSOURCE_ID}
		</if>
		<if test="pd.MAJORDANGERSOURCE_NAME != null and pd.MAJORDANGERSOURCE_NAME != ''"><!-- 重大危险源名称检索 -->
			and f.MAJORDANGERSOURCE_NAME LIKE CONCAT(CONCAT('%', #{pd.MAJORDANGERSOURCE_NAME}),'%')
		</if>
		<if test="pd.RESPONSIBLE_PERSON_NAME != null and pd.RESPONSIBLE_PERSON_NAME != ''"><!-- 责任人检索 -->
			and f.RESPONSIBLE_PERSON_NAME LIKE CONCAT(CONCAT('%', #{pd.RESPONSIBLE_PERSON_NAME}),'%')
		</if>
		<if test="pd.CREATTIME != null and pd.CREATTIME != ''"><!-- 重大危险源ID -->
			and f.CREATTIME &lt;= #{pd.CREATTIME}
		</if>
		order by f.CREATTIME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
		order by f.CREATTIME desc
	</select>

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

</mapper>
