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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.NAME,
		f.PHONE,
		f.IDENTITY_NUMBER,
		f.EDUCATION_LEVEL,
		f.PROFESSION,
		f.IDENTITY_FILEPATH_FRONT,
		f.IDENTITY_FILEPATH_REVERSE,
		f.DIPLOMA_FILEPATH,
		f.CERTIFICATE_FILEPATH,
		f.ISDELETE,
		f.OPERATOR,
		f.OPERATTIME,
		f.CREATOR,
		f.CREATTIME,
		f.CORPINFO_ID,
		f.TEACHER_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		NAME,
		PHONE,
		IDENTITY_NUMBER,
		EDUCATION_LEVEL,
		PROFESSION,
		IDENTITY_FILEPATH_FRONT,
		IDENTITY_FILEPATH_REVERSE,
		DIPLOMA_FILEPATH,
		CERTIFICATE_FILEPATH,
		ISDELETE,
		OPERATOR,
		OPERATTIME,
		CREATOR,
		CREATTIME,
		CORPINFO_ID,
		TEACHER_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{NAME},
		#{PHONE},
		#{IDENTITY_NUMBER},
		#{EDUCATION_LEVEL},
		#{PROFESSION},
		#{IDENTITY_FILEPATH_FRONT},
		#{IDENTITY_FILEPATH_REVERSE},
		#{DIPLOMA_FILEPATH},
		#{CERTIFICATE_FILEPATH},
		#{ISDELETE},
		#{OPERATOR},
		#{OPERATTIME},
		#{CREATOR},
		#{CREATTIME},
		#{CORPINFO_ID},
		#{TEACHER_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
			TEACHER_ID = #{TEACHER_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			NAME = #{NAME},
			PHONE = #{PHONE},
			IDENTITY_NUMBER = #{IDENTITY_NUMBER},
			EDUCATION_LEVEL = #{EDUCATION_LEVEL},
			PROFESSION = #{PROFESSION},
			IDENTITY_FILEPATH_FRONT = #{IDENTITY_FILEPATH_FRONT},
			IDENTITY_FILEPATH_REVERSE = #{IDENTITY_FILEPATH_REVERSE},
			DIPLOMA_FILEPATH = #{DIPLOMA_FILEPATH},
			CERTIFICATE_FILEPATH = #{CERTIFICATE_FILEPATH},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			TEACHER_ID = TEACHER_ID
		where
			TEACHER_ID = #{TEACHER_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		,d1.name EDUCATION_LEVEL_NAME
		,d2.name PROFESSION_NAME
		from
		<include refid="tableName"></include> f
		LEFT JOIN <include refid="dicTableName"></include> d1 on d1.BIANMA = f.EDUCATION_LEVEL
		LEFT JOIN <include refid="dicTableName"></include> d2 on d2.BIANMA = f.PROFESSION
		where
			f.TEACHER_ID = #{TEACHER_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		,GROUP_CONCAT(REPLACE(cd.NAME,'/',',')) AS QUALIFICATION_TYPE_NAMES
		,fd1.NAME EDUCATION_LEVEL_NAME
		,fd2.NAME PROFESSION_NAME
		from
		<include refid="tableName"></include> f
		 LEFT JOIN <include refid="dicTableName"></include> fd1 ON fd1.BIANMA = f.EDUCATION_LEVEL AND fd1.PARENT_ID = 'd7d80f08d73a4accbccf4fd3d8d1d867'
		 LEFT JOIN <include refid="dicTableName"></include> fd2 ON fd2.BIANMA = f.PROFESSION AND fd2.PARENT_ID = '95530fecbcb3421ca600b58c206b99d6'
		LEFT JOIN BUS_TEACHERCERTIFICATE c ON c.TEACHER_ID = f.TEACHER_ID AND c.ISDELETE = '0'
		LEFT JOIN <include refid="dicTableName"></include> cd ON cd.BIANMA = c.QUALIFICATION_TYPE AND cd.PARENT_ID = '82d41f1cab2a4ed394ddbe69a15bb8f1'
		where f.ISDELETE = '0'
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 教师姓名模糊检索 -->
			and f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.QUALIFICATION_TYPE != null and pd.QUALIFICATION_TYPE != ''"><!-- 资质类型 -->
			and c.QUALIFICATION_TYPE = #{pd.QUALIFICATION_TYPE}
		</if>
		GROUP BY f.TEACHER_ID
		ORDER BY f.CREATTIME DESC
	</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
		TEACHER_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
		TEACHER_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
	<!-- 列表(全部) -->
	<select id="listAllBySelect" parameterType="pd" resultType="pd">
		select
		f.TEACHER_ID ,f.NAME
		from
		<include refid="tableName"></include> f
		WHERE
		f.ISDELETE = '0'
	</select>
</mapper>
