<?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.speEquip.SpecialEquipmentMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.EQUIPMENTNAME,
		f.EQUIPMENTMODEL,
		f.EQUIPMENTCODE,
		f.FACTORYCODE,
		f.EQUIPMENTTYPE,
		f.EQUIPMENTSTATE,
		f.EQUIPMENTUSEPLACE,
		f.RESPONSIBLEUNIT,
		f.PERSONCHARGE,
		f.PERSONCHARGEPHONE,
		f.NEXTINSPECTIONDATE,
		f.PERIOD,
		f.PERIOD_START_DATE,
		f.PERIOD_END_DATE,
		f.TECHNICALFILENAME,
		f.TECHNICALFILEPATH,
		f.REMARKS,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.CORPINFO_ID,
		f.SPECIALEQUIPMENT_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		EQUIPMENTNAME,
		EQUIPMENTMODEL,
		EQUIPMENTCODE,
		FACTORYCODE,
		EQUIPMENTTYPE,
		EQUIPMENTSTATE,
		EQUIPMENTUSEPLACE,
		RESPONSIBLEUNIT,
		PERSONCHARGE,
		PERSONCHARGEPHONE,
		NEXTINSPECTIONDATE,
		PERIOD,
		PERIOD_START_DATE,
		PERIOD_END_DATE,
		TECHNICALFILENAME,
		TECHNICALFILEPATH,
		REMARKS,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID,
		SPECIALEQUIPMENT_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{EQUIPMENTNAME},
		#{EQUIPMENTMODEL},
		#{EQUIPMENTCODE},
		#{FACTORYCODE},
		#{EQUIPMENTTYPE},
		#{EQUIPMENTSTATE},
		#{EQUIPMENTUSEPLACE},
		#{RESPONSIBLEUNIT},
		#{PERSONCHARGE},
		#{PERSONCHARGEPHONE},
		#{NEXTINSPECTIONDATE},
		#{PERIOD},
		#{PERIOD_START_DATE},
		#{PERIOD_END_DATE},
		#{TECHNICALFILENAME},
		#{TECHNICALFILEPATH},
		#{REMARKS},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{CORPINFO_ID},
		#{SPECIALEQUIPMENT_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
		SPECIALEQUIPMENT_ID = #{SPECIALEQUIPMENT_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		EQUIPMENTNAME = #{EQUIPMENTNAME},
		EQUIPMENTMODEL = #{EQUIPMENTMODEL},
		EQUIPMENTCODE = #{EQUIPMENTCODE},
		FACTORYCODE = #{FACTORYCODE},
		EQUIPMENTTYPE = #{EQUIPMENTTYPE},
		EQUIPMENTSTATE = #{EQUIPMENTSTATE},
		EQUIPMENTUSEPLACE = #{EQUIPMENTUSEPLACE},
		RESPONSIBLEUNIT = #{RESPONSIBLEUNIT},
		PERSONCHARGE = #{PERSONCHARGE},
		PERSONCHARGEPHONE = #{PERSONCHARGEPHONE},
		NEXTINSPECTIONDATE = #{NEXTINSPECTIONDATE},
		PERIOD = #{PERIOD},
		PERIOD_START_DATE = #{PERIOD_START_DATE},
		PERIOD_END_DATE = #{PERIOD_END_DATE},
		TECHNICALFILENAME = #{TECHNICALFILENAME},
		TECHNICALFILEPATH = #{TECHNICALFILEPATH},
		REMARKS = #{REMARKS},
		OPERATOR = #{OPERATOR},
		OPERATTIME = #{OPERATTIME},
		SPECIALEQUIPMENT_ID = SPECIALEQUIPMENT_ID
		where
		SPECIALEQUIPMENT_ID = #{SPECIALEQUIPMENT_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		d5.NAME EQUIPMENTTYPENAME,
		d6.NAME EQUIPMENTSTATENAME,
		d7.NAME PERIOD_NAME,
		d.NAME RESPONSIBLEUNITNAME,
		u.NAME PERSONCHARGENAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d5
		on f.EQUIPMENTTYPE = d5.BIANMA
		left join
		<include refid="dicTableName"></include> d6
		on f.EQUIPMENTSTATE = d6.BIANMA
		left join
		<include refid="dicTableName"></include> d7
		on f.PERIOD = d7.BIANMA
		left join OA_DEPARTMENT d on f.RESPONSIBLEUNIT = d.DEPARTMENT_ID
		left join SYS_USER u on f.PERSONCHARGE = u.USER_ID
		where
		f.SPECIALEQUIPMENT_ID = #{SPECIALEQUIPMENT_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		d5.NAME EQUIPMENTTYPENAME,
		d6.NAME EQUIPMENTSTATENAME,
		dp.NAME PERIOD_NAME,
		d.NAME RESPONSIBLEUNITNAME,
		u.NAME PERSONCHARGENAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d5
		on f.EQUIPMENTTYPE = d5.BIANMA and d5.parent_id = 'cffb3d28d48548328ddd78976610b05d'
		left join
		<include refid="dicTableName"></include> d6
		on f.EQUIPMENTSTATE = d6.BIANMA and d6.parent_id = '0feb448f975e422fafbf5db20c0b85c9'
		left join
		<include refid="dicTableName"></include> dp
		on f.PERIOD = dp.BIANMA
		left join OA_DEPARTMENT d on f.RESPONSIBLEUNIT = d.DEPARTMENT_ID
		left join SYS_USER u on f.PERSONCHARGE = u.USER_ID
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.EQUIPMENTNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</if>
		<if test="pd.EQUIPMENTTYPE != null and pd.EQUIPMENTTYPE != ''"><!-- 关键词检索 -->
			and f.EQUIPMENTTYPE = #{pd.EQUIPMENTTYPE}
		</if>
		ORDER BY f.OPERATTIME DESC
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		f.*,
		d5.NAME EQUIPMENTTYPENAME,
		d6.NAME EQUIPMENTSTATENAME,
		d.NAME RESPONSIBLEUNITNAME,
		u.NAME PERSONCHARGENAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d5
		on f.EQUIPMENTTYPE = d5.BIANMA and d5.parent_id = 'cffb3d28d48548328ddd78976610b05d'
		left join
		<include refid="dicTableName"></include> d6
		on f.EQUIPMENTSTATE = d6.BIANMA and d6.parent_id = '0feb448f975e422fafbf5db20c0b85c9'
		left join OA_DEPARTMENT d on f.RESPONSIBLEUNIT = d.DEPARTMENT_ID
		left join SYS_USER u on f.PERSONCHARGE = u.USER_ID
		where f.ISDELETE = '0'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<if test="IS_OVER != null and IS_OVER != ''"><!-- 关键词检索 -->
			and f.PERIOD_END_DATE &lt; now()
		</if>
	</select>

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

	<!-- 列表(根据多选ID查询数据) -->
	<select id="listByIds" parameterType="pd" resultType="pd">
		select
		d5.NAME EQUIPMENTTYPENAME,
		d6.NAME EQUIPMENTSTATENAME,
		d.NAME RESPONSIBLEUNITNAME,
		u.NAME PERSONCHARGENAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d5
		on f.EQUIPMENTTYPE = d5.BIANMA and d5.parent_id = 'cffb3d28d48548328ddd78976610b05d'
		left join
		<include refid="dicTableName"></include> d6
		on f.EQUIPMENTSTATE = d6.BIANMA and d6.parent_id = '0feb448f975e422fafbf5db20c0b85c9'
		left join OA_DEPARTMENT d on f.RESPONSIBLEUNIT = d.DEPARTMENT_ID
		left join SYS_USER u on f.PERSONCHARGE = u.USER_ID
		where f.ISDELETE = '0'
		 and SPECIALEQUIPMENT_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>

</mapper>
