<?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.srs.teacher.mapper.SysTeacherBasicmessageMapper">
    
    <resultMap type="SysTeacherBasicmessage" id="SysTeacherBasicmessageResult">
        <result property="teacherId"    column="teacher_id"    />
        <result property="name"    column="name"    />
        <result property="gender"    column="gender"    />
        <result property="birthday"    column="birthday"    />
        <result property="nation"    column="nation"    />
        <result property="photo"    column="photo"    />
        <result property="political"    column="political"    />
        <result property="wechat"    column="wechat"    />
        <result property="phone"    column="phone"    />
        <result property="address"    column="address"    />
        <result property="identity"    column="identity"    />
        <result property="qqnumber"    column="qqnumber"    />
        <result property="marriage"    column="marriage"    />
        <result property="anotherDuties"    column="anotherDuties"    />
        <result property="level2units"    column="level2units"    />
        <result property="serviceHours"    column="serviceHours"    />
        <result property="jobNature"    column="jobNature"    />
        <result property="joinWorkHours"    column="joinWorkHours"    />
        <result property="highestEducation"    column="highestEducation"    />
        <result property="educated"    column="educated"    />
        <result property="study"    column="study"    />
        <result property="lastestEducation"    column="lastestEducation"    />
        <result property="awardingInstitutions"    column="awardingInstitutions"    />
        <result property="email"    column="email"    />
        <result property="college"    column="college"    />
    </resultMap>

    <resultMap id="SysTeacherBasicmessageSysTeacherTakeclassResult" type="SysTeacherBasicmessage" extends="SysTeacherBasicmessageResult">
        <collection property="sysTeacherTakeclassList" notNullColumn="sub_takeclass_id" javaType="java.util.List" resultMap="SysTeacherTakeclassResult" />
    </resultMap>

    <resultMap type="SysTeacherTakeclass" id="SysTeacherTakeclassResult">
        <result property="takeclassId"    column="sub_takeclass_id"    />
        <result property="teacherId"    column="sub_teacher_id"    />
        <result property="college"    column="sub_college"    />
        <result property="grade"    column="sub_grade"    />
        <result property="classteam"    column="sub_classteam"    />
        <result property="number"    column="sub_number"    />
    </resultMap>

    <sql id="selectSysTeacherBasicmessageVo">
        select teacher_id, name, gender, birthday, nation, photo, political, wechat, phone, address, identity, qqnumber, marriage, anotherDuties, level2units, serviceHours, jobNature, joinWorkHours, highestEducation, educated, study, lastestEducation, awardingInstitutions, email, college from sys_teacher_basicmessage
    </sql>

    <select id="selectSysTeacherBasicmessageList" parameterType="SysTeacherBasicmessage" resultMap="SysTeacherBasicmessageResult">
        <include refid="selectSysTeacherBasicmessageVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="nation != null  and nation != ''"> and nation = #{nation}</if>
            <if test="photo != null  and photo != ''"> and photo = #{photo}</if>
            <if test="political != null  and political != ''"> and political = #{political}</if>
            <if test="wechat != null  and wechat != ''"> and wechat = #{wechat}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="identity != null  and identity != ''"> and identity = #{identity}</if>
            <if test="qqnumber != null  and qqnumber != ''"> and qqnumber = #{qqnumber}</if>
            <if test="marriage != null  and marriage != ''"> and marriage = #{marriage}</if>
            <if test="anotherDuties != null  and anotherDuties != ''"> and anotherDuties = #{anotherDuties}</if>
            <if test="level2units != null  and level2units != ''"> and level2units = #{level2units}</if>
            <if test="serviceHours != null  and serviceHours != ''"> and serviceHours = #{serviceHours}</if>
            <if test="jobNature != null  and jobNature != ''"> and jobNature = #{jobNature}</if>
            <if test="joinWorkHours != null  and joinWorkHours != ''"> and joinWorkHours = #{joinWorkHours}</if>
            <if test="highestEducation != null  and highestEducation != ''"> and highestEducation = #{highestEducation}</if>
            <if test="educated != null  and educated != ''"> and educated = #{educated}</if>
            <if test="study != null  and study != ''"> and study = #{study}</if>
            <if test="lastestEducation != null  and lastestEducation != ''"> and lastestEducation = #{lastestEducation}</if>
            <if test="awardingInstitutions != null  and awardingInstitutions != ''"> and awardingInstitutions = #{awardingInstitutions}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="college != null  and college != ''"> and college = #{college}</if>
        </where>
    </select>
    
    <select id="selectSysTeacherBasicmessageByTeacherId" parameterType="Long" resultMap="SysTeacherBasicmessageSysTeacherTakeclassResult">
        select a.teacher_id, a.name, a.gender, a.birthday, a.nation, a.photo, a.political, a.wechat, a.phone, a.address, a.identity, a.qqnumber, a.marriage, a.anotherDuties, a.level2units, a.serviceHours, a.jobNature, a.joinWorkHours, a.highestEducation, a.educated, a.study, a.lastestEducation, a.awardingInstitutions, a.email, a.college,
 b.takeclass_id as sub_takeclass_id, b.teacher_id as sub_teacher_id, b.college as sub_college, b.grade as sub_grade, b.classteam as sub_classteam, b.number as sub_number
        from sys_teacher_basicmessage a
        left join sys_teacher_takeclass b on b.teacher_id = a.teacher_id
        where a.teacher_id = #{teacherId}
    </select>
        
    <insert id="insertSysTeacherBasicmessage" parameterType="SysTeacherBasicmessage" useGeneratedKeys="true" keyProperty="teacherId">
        insert into sys_teacher_basicmessage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">teacher_id,</if>
            <if test="name != null">name,</if>
            <if test="gender != null">gender,</if>
            <if test="birthday != null">birthday,</if>
            <if test="nation != null">nation,</if>
            <if test="photo != null">photo,</if>
            <if test="political != null">political,</if>
            <if test="wechat != null">wechat,</if>
            <if test="phone != null">phone,</if>
            <if test="address != null">address,</if>
            <if test="identity != null">identity,</if>
            <if test="qqnumber != null">qqnumber,</if>
            <if test="marriage != null">marriage,</if>
            <if test="anotherDuties != null">anotherDuties,</if>
            <if test="level2units != null">level2units,</if>
            <if test="serviceHours != null">serviceHours,</if>
            <if test="jobNature != null">jobNature,</if>
            <if test="joinWorkHours != null">joinWorkHours,</if>
            <if test="highestEducation != null">highestEducation,</if>
            <if test="educated != null">educated,</if>
            <if test="study != null">study,</if>
            <if test="lastestEducation != null">lastestEducation,</if>
            <if test="awardingInstitutions != null">awardingInstitutions,</if>
            <if test="email != null">email,</if>
            <if test="college != null">college,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">#{teacherId},</if>
            <if test="name != null">#{name},</if>
            <if test="gender != null">#{gender},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="nation != null">#{nation},</if>
            <if test="photo != null">#{photo},</if>
            <if test="political != null">#{political},</if>
            <if test="wechat != null">#{wechat},</if>
            <if test="phone != null">#{phone},</if>
            <if test="address != null">#{address},</if>
            <if test="identity != null">#{identity},</if>
            <if test="qqnumber != null">#{qqnumber},</if>
            <if test="marriage != null">#{marriage},</if>
            <if test="anotherDuties != null">#{anotherDuties},</if>
            <if test="level2units != null">#{level2units},</if>
            <if test="serviceHours != null">#{serviceHours},</if>
            <if test="jobNature != null">#{jobNature},</if>
            <if test="joinWorkHours != null">#{joinWorkHours},</if>
            <if test="highestEducation != null">#{highestEducation},</if>
            <if test="educated != null">#{educated},</if>
            <if test="study != null">#{study},</if>
            <if test="lastestEducation != null">#{lastestEducation},</if>
            <if test="awardingInstitutions != null">#{awardingInstitutions},</if>
            <if test="email != null">#{email},</if>
            <if test="college != null">#{college},</if>
         </trim>
    </insert>

    <update id="updateSysTeacherBasicmessage" parameterType="SysTeacherBasicmessage">
        update sys_teacher_basicmessage
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="nation != null">nation = #{nation},</if>
            <if test="photo != null">photo = #{photo},</if>
            <if test="political != null">political = #{political},</if>
            <if test="wechat != null">wechat = #{wechat},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="address != null">address = #{address},</if>
            <if test="identity != null">identity = #{identity},</if>
            <if test="qqnumber != null">qqnumber = #{qqnumber},</if>
            <if test="marriage != null">marriage = #{marriage},</if>
            <if test="anotherDuties != null">anotherDuties = #{anotherDuties},</if>
            <if test="level2units != null">level2units = #{level2units},</if>
            <if test="serviceHours != null">serviceHours = #{serviceHours},</if>
            <if test="jobNature != null">jobNature = #{jobNature},</if>
            <if test="joinWorkHours != null">joinWorkHours = #{joinWorkHours},</if>
            <if test="highestEducation != null">highestEducation = #{highestEducation},</if>
            <if test="educated != null">educated = #{educated},</if>
            <if test="study != null">study = #{study},</if>
            <if test="lastestEducation != null">lastestEducation = #{lastestEducation},</if>
            <if test="awardingInstitutions != null">awardingInstitutions = #{awardingInstitutions},</if>
            <if test="email != null">email = #{email},</if>
            <if test="college != null">college = #{college},</if>
        </trim>
        where teacher_id = #{teacherId}
    </update>

    <delete id="deleteSysTeacherBasicmessageByTeacherId" parameterType="Long">
        delete from sys_teacher_basicmessage where teacher_id = #{teacherId}
    </delete>

    <delete id="deleteSysTeacherBasicmessageByTeacherIds" parameterType="String">
        delete from sys_teacher_basicmessage where teacher_id in 
        <foreach item="teacherId" collection="array" open="(" separator="," close=")">
            #{teacherId}
        </foreach>
    </delete>
    
    <delete id="deleteSysTeacherTakeclassByTeacherIds" parameterType="String">
        delete from sys_teacher_takeclass where teacher_id in 
        <foreach item="teacherId" collection="array" open="(" separator="," close=")">
            #{teacherId}
        </foreach>
    </delete>

    <delete id="deleteSysTeacherTakeclassByTeacherId" parameterType="Long">
        delete from sys_teacher_takeclass where teacher_id = #{teacherId}
    </delete>

    <insert id="batchSysTeacherTakeclass">
        insert into sys_teacher_takeclass( takeclass_id, teacher_id, college, grade, classteam, number) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.takeclassId}, #{item.teacherId}, #{item.college}, #{item.grade}, #{item.classteam}, #{item.number})
        </foreach>
    </insert>
</mapper>