<?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.emergency.EmergencyPlanMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.PLAN_NAME,
		f.PLAN_NO,
		f.PLAN_USE_SCOPE,
		f.PLAN_CATEGORY,
		f.PLAN_LEVEL,
		f.ESTAB_UNIT,
		f.ESTAB_USER,
		f.PUBLISH_DATE,
		f.PUBLISH_DOC_NO,
		f.PUBLISH_UNIT,
		f.ISSUER,
		f.PLAN_RECORD_STATUS,
		f.PLAN_RECORD_DATE,
		f.PLAN_RECORD_UNIT,
		f.PLAN_SUMMARY,
		f.PLAN_REMARK,
		f.PLAN_ATTACH_NAME,
		f.PLAN_ATTACH_IDS,
		f.ISDELETE,
		f.OPERATOR,
		f.OPERATTIME,
		f.CREATTIME,
		f.CREATOR,
		f.CORPINFO_ID,
		f.EMERGENCYPLAN_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		PLAN_NAME,
		PLAN_NO,
		PLAN_USE_SCOPE,
		PLAN_CATEGORY,
		PLAN_LEVEL,
		ESTAB_UNIT,
		ESTAB_USER,
		PUBLISH_DATE,
		PUBLISH_DOC_NO,
		PUBLISH_UNIT,
		ISSUER,
		PLAN_RECORD_STATUS,
		PLAN_RECORD_DATE,
		PLAN_RECORD_UNIT,
		PLAN_SUMMARY,
		PLAN_REMARK,
		PLAN_ATTACH_NAME,
		PLAN_ATTACH_IDS,
		ISDELETE,
		OPERATOR,
		OPERATTIME,
		CREATTIME,
		CREATOR,
		CORPINFO_ID,
		EMERGENCYPLAN_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{PLAN_NAME},
		#{PLAN_NO},
		#{PLAN_USE_SCOPE},
		#{PLAN_CATEGORY},
		#{PLAN_LEVEL},
		#{ESTAB_UNIT},
		#{ESTAB_USER},
		#{PUBLISH_DATE},
		#{PUBLISH_DOC_NO},
		#{PUBLISH_UNIT},
		#{ISSUER},
		#{PLAN_RECORD_STATUS},
		#{PLAN_RECORD_DATE},
		#{PLAN_RECORD_UNIT},
		#{PLAN_SUMMARY},
		#{PLAN_REMARK},
		#{PLAN_ATTACH_NAME},
		#{PLAN_ATTACH_IDS},
		#{ISDELETE},
		#{OPERATOR},
		#{OPERATTIME},
		#{CREATTIME},
		#{CREATOR},
		#{CORPINFO_ID},
		#{EMERGENCYPLAN_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
			EMERGENCYPLAN_ID = #{EMERGENCYPLAN_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			PLAN_NAME = #{PLAN_NAME},
			PLAN_NO = #{PLAN_NO},
			PLAN_USE_SCOPE = #{PLAN_USE_SCOPE},
			PLAN_CATEGORY = #{PLAN_CATEGORY},
			PLAN_LEVEL = #{PLAN_LEVEL},
			ESTAB_UNIT = #{ESTAB_UNIT},
			ESTAB_USER = #{ESTAB_USER},
			PUBLISH_DATE = #{PUBLISH_DATE},
			PUBLISH_DOC_NO = #{PUBLISH_DOC_NO},
			PUBLISH_UNIT = #{PUBLISH_UNIT},
			ISSUER = #{ISSUER},
			PLAN_RECORD_STATUS = #{PLAN_RECORD_STATUS},
			PLAN_RECORD_DATE = #{PLAN_RECORD_DATE},
			PLAN_RECORD_UNIT = #{PLAN_RECORD_UNIT},
			PLAN_SUMMARY = #{PLAN_SUMMARY},
			PLAN_REMARK = #{PLAN_REMARK},
			PLAN_ATTACH_NAME = #{PLAN_ATTACH_NAME},
			PLAN_ATTACH_IDS = #{PLAN_ATTACH_IDS},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			EMERGENCYPLAN_ID = EMERGENCYPLAN_ID
		where
			EMERGENCYPLAN_ID = #{EMERGENCYPLAN_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		,d1.NAME as 'PLAN_USE_SCOPE_NAME'
		,d2.NAME as 'PLAN_CATEGORY_NAME'
		,d3.NAME as 'PLAN_LEVEL_NAME'
		,d4.NAME as 'PLAN_RECORD_STATUS_NAME'
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES d1 on f.PLAN_USE_SCOPE = d1.BIANMA and d1.PARENT_ID = 'ab52643da4714042be2ebfb880097330'
		left join SYS_DICTIONARIES d2 on f.PLAN_CATEGORY = d2.BIANMA and d2.PARENT_ID = 'b2759070db524cc4ae2d60ee4b263dc3'
		left join SYS_DICTIONARIES d3 on f.PLAN_LEVEL = d3.BIANMA and d3.PARENT_ID = 'ab54d50f12ef4f578bc29c3b980b83e5'
		left join SYS_DICTIONARIES d4 on f.PLAN_RECORD_STATUS = d4.BIANMA and d4.PARENT_ID = '8d07af03be10473ca17e1516a8e860d2'
		where
			f.EMERGENCYPLAN_ID = #{EMERGENCYPLAN_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		,d1.NAME as 'PLAN_USE_SCOPE_NAME'
		,d2.NAME as 'PLAN_CATEGORY_NAME'
		,d3.NAME as 'PLAN_LEVEL_NAME'
		,d4.NAME as 'PLAN_RECORD_STATUS_NAME'
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES d1 on f.PLAN_USE_SCOPE = d1.BIANMA and d1.PARENT_ID = 'ab52643da4714042be2ebfb880097330'
		left join SYS_DICTIONARIES d2 on f.PLAN_CATEGORY = d2.BIANMA and d2.PARENT_ID = 'b2759070db524cc4ae2d60ee4b263dc3'
		left join SYS_DICTIONARIES d3 on f.PLAN_LEVEL = d3.BIANMA and d3.PARENT_ID = 'ab54d50f12ef4f578bc29c3b980b83e5'
		left join SYS_DICTIONARIES d4 on f.PLAN_RECORD_STATUS = d4.BIANMA and d4.PARENT_ID = '8d07af03be10473ca17e1516a8e860d2'
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and f.PLAN_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				<!--	根据需求自己加检索条件
				(
					字段1 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
					 or
					字段2 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
				-->
		</if>
		ORDER BY f.OPERATTIME 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 = #{pd.CORPINFO_ID}
	</select>

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

</mapper>
