<?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.dsno2.teacher.TeacherCertificateMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.TEACHER_ID,
		f.QUALIFICATION_TYPE,
		f.VOCATIONAL_CERTIFICATE_NUMBER,
		f.IS_PERMANENT_VALID,
		f.CERTIFICATE_DATE_BEGIN,
		f.CERTIFICATE_DATE_END,
		f.CERTIFICATE_FILEPATH,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.CORPINFO_ID,
		f.TEACHERCERTIFICATE_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		TEACHER_ID,
		QUALIFICATION_TYPE,
		VOCATIONAL_CERTIFICATE_NUMBER,
		IS_PERMANENT_VALID,
		CERTIFICATE_DATE_BEGIN,
		CERTIFICATE_DATE_END,
		CERTIFICATE_FILEPATH,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		CORPINFO_ID,
		TEACHERCERTIFICATE_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{TEACHER_ID},
		#{QUALIFICATION_TYPE},
		#{VOCATIONAL_CERTIFICATE_NUMBER},
		#{IS_PERMANENT_VALID},
		#{CERTIFICATE_DATE_BEGIN},
		#{CERTIFICATE_DATE_END},
		#{CERTIFICATE_FILEPATH},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{CORPINFO_ID},
		#{TEACHERCERTIFICATE_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
			TEACHERCERTIFICATE_ID = #{TEACHERCERTIFICATE_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			TEACHER_ID = #{TEACHER_ID},
			QUALIFICATION_TYPE = #{QUALIFICATION_TYPE},
			VOCATIONAL_CERTIFICATE_NUMBER = #{VOCATIONAL_CERTIFICATE_NUMBER},
			IS_PERMANENT_VALID = #{IS_PERMANENT_VALID},
			CERTIFICATE_DATE_BEGIN = #{CERTIFICATE_DATE_BEGIN},
			CERTIFICATE_DATE_END = #{CERTIFICATE_DATE_END},
			CERTIFICATE_FILEPATH = #{CERTIFICATE_FILEPATH},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			TEACHERCERTIFICATE_ID = TEACHERCERTIFICATE_ID
		where
			TEACHERCERTIFICATE_ID = #{TEACHERCERTIFICATE_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		d2.NAME QUALIFICATION_TYPE_NAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d2
		on f.QUALIFICATION_TYPE = d2.BIANMA and d2.PARENT_ID = '82d41f1cab2a4ed394ddbe69a15bb8f1'
		where
			f.TEACHERCERTIFICATE_ID = #{TEACHERCERTIFICATE_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
			d2.NAME QUALIFICATION_TYPE_NAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
			left join
			<include refid="dicTableName"></include> d2
			on f.QUALIFICATION_TYPE = d2.BIANMA and d2.PARENT_ID = '82d41f1cab2a4ed394ddbe69a15bb8f1'
		where f.ISDELETE = '0'
		<if test="pd.TEACHER_ID != null and pd.TEACHER_ID != ''"><!-- 教师ID -->
			and f.TEACHER_ID=#{pd.TEACHER_ID}
		</if>
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
	</select>

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

	<!-- 列表(根据教师ID获取证书数据) -->
	<select id="listByTeacher" parameterType="pd" resultType="pd">
		select
		d2.NAME QUALIFICATION_TYPE_NAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d2
		on f.QUALIFICATION_TYPE = d2.BIANMA and d2.PARENT_ID = '82d41f1cab2a4ed394ddbe69a15bb8f1'
		where f.ISDELETE = '0' and f.TEACHER_ID = #{TEACHER_ID}
	</select>

	<!-- 删除(根据教师ID删除证书数据)-->
	<delete id="deleteByTeacher" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = '1',
		OPERATOR = #{OPERATOR},
		OPERATTIME = #{OPERATTIME}
		where
		ISDELETE = '0' and TEACHER_ID = #{TEACHER_ID}
	</delete>
	<!-- 列表(根据教师IDS获取证书数据) -->
	<select id="listByTeacherAll" parameterType="pd" resultType="pd">
		select
		d2.NAME QUALIFICATION_TYPE_NAME,
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d2
		on f.QUALIFICATION_TYPE = d2.BIANMA and d2.PARENT_ID = '82d41f1cab2a4ed394ddbe69a15bb8f1'
		where f.ISDELETE = '0'
		and f.TEACHER_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>

	<!-- 删除(根据教师IDS删除证书数据)-->
	<delete id="deleteByTeacherAll" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = '1',
		OPERATOR = #{OPERATOR},
		OPERATTIME = #{OPERATTIME}
		where
		ISDELETE = '0'
		and TEACHER_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
			#{item}
		</foreach>
	</delete>

</mapper>
