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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.EQUIP_NAME,
		f.CATEGORY,
		f.SPEC,
		f.EQUIP_PERFORMANCE,
		f.MAINTAIN_DATE,
		f.VALIDATE_DATE,
		f.USE,
		f.USE_DESC,
		f.STORAGE_PLACE,
		f.STORAGE_PERSON_NAME,
		f.STORAGE_PERSON_PHONE,
		f.ISDELETE,
		f.OPERATOR,
		f.OPERATTIME,
		f.CREATTIME,
		f.CREATOR,
		f.CORPINFO_ID,
		f.EMERGENCYEQUIPMENT_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		EQUIP_NAME,
		CATEGORY,
		SPEC,
		EQUIP_PERFORMANCE,
		MAINTAIN_DATE,
		VALIDATE_DATE,
		`USE`,
		USE_DESC,
		STORAGE_PLACE,
		STORAGE_PERSON_NAME,
		STORAGE_PERSON_PHONE,
		ISDELETE,
		OPERATOR,
		OPERATTIME,
		CREATTIME,
		CREATOR,
		CORPINFO_ID,
		EMERGENCYEQUIPMENT_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{EQUIP_NAME},
		#{CATEGORY},
		#{SPEC},
		#{EQUIP_PERFORMANCE},
		#{MAINTAIN_DATE},
		#{VALIDATE_DATE},
		#{USE},
		#{USE_DESC},
		#{STORAGE_PLACE},
		#{STORAGE_PERSON_NAME},
		#{STORAGE_PERSON_PHONE},
		#{ISDELETE},
		#{OPERATOR},
		#{OPERATTIME},
		#{CREATTIME},
		#{CREATOR},
		#{CORPINFO_ID},
		#{EMERGENCYEQUIPMENT_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
			EMERGENCYEQUIPMENT_ID = #{EMERGENCYEQUIPMENT_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			EQUIP_NAME = #{EQUIP_NAME},
			CATEGORY = #{CATEGORY},
			SPEC = #{SPEC},
			EQUIP_PERFORMANCE = #{EQUIP_PERFORMANCE},
			MAINTAIN_DATE = #{MAINTAIN_DATE},
			VALIDATE_DATE = #{VALIDATE_DATE},
			`USE` = #{USE},
			USE_DESC = #{USE_DESC},
			STORAGE_PLACE = #{STORAGE_PLACE},
			STORAGE_PERSON_NAME = #{STORAGE_PERSON_NAME},
			STORAGE_PERSON_PHONE = #{STORAGE_PERSON_PHONE},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			EMERGENCYEQUIPMENT_ID = EMERGENCYEQUIPMENT_ID
		where
			EMERGENCYEQUIPMENT_ID = #{EMERGENCYEQUIPMENT_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		,d1.NAME as 'CATEGORY_NAME'
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES d1 on f.CATEGORY = d1.BIANMA and d1.PARENT_ID = '716f792cfc354fcf81bf3c0e904fb4f8'
		where
			f.EMERGENCYEQUIPMENT_ID = #{EMERGENCYEQUIPMENT_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		,d1.NAME as 'CATEGORY_NAME'
		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES d1 on f.CATEGORY = d1.BIANMA and d1.PARENT_ID = '716f792cfc354fcf81bf3c0e904fb4f8'
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
				f.EQUIP_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				<!--	根据需求自己加检索条件
					字段1 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
					 or
					字段2 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				-->
				)
		</if>
		<if test="pd.CATEGORY != null and pd.CATEGORY != ''"><!-- 关键词检索 -->
			and f.CATEGORY = #{pd.CATEGORY}
		</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
			EMERGENCYEQUIPMENT_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>

</mapper>
