<?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.vctgo.system.mapper.SysTeachStaffMapper">

    <resultMap type="com.vctgo.system.domain.SysTeachStaff" id="SysTeachStaffResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="kindergartenType" column="kindergarten_type"/>
        <result property="kindergartenId" column="kindergarten_id"/>
        <result property="userName" column="user_name"/>
        <result property="phonenumber" column="phonenumber"/>
        <result property="sex" column="sex"/>
        <result property="email" column="email"/>
        <result property="inchPhotoOne" column="inch_photo_one"/>
        <result property="inchPhotoTwo" column="inch_photo_two"/>
        <result property="politicalStatus" column="political_status"/>
        <result property="mainPost" column="main_post"/>
        <result property="otherPost" column="other_post"/>
        <result property="teacherEducationId" column="teacher_education_id"/>
        <result property="userStatus" column="user_status"/>
        <result property="professionalTitleGrade" column="professional_title_grade"/>
        <result property="isBackbone" column="is_backbone"/>
        <result property="backboneStartTime" column="backbone_start_time"/>
        <result property="backboneEndTime" column="backbone_end_time"/>
        <result property="backboneType" column="backbone_type"/>
        <result property="isDisciplineLeader" column="is_discipline_leader"/>
        <result property="discipline" column="discipline"/>
        <result property="entryTeachingAge" column="entry_teaching_age"/>
        <result property="actualTeachingAge" column="actual_teaching_age"/>
        <result property="informationSource" column="information_source"/>
        <result property="remark" column="remark"/>
        <result property="isDeleted" column="is_deleted"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="identificationCard" column="identification_card"/>
        <result property="birthDate" column="birth_date"/>
        <result property="nation" column="nation"/>
        <result property="bloodType" column="blood_type"/>
        <result property="jobNumber" column="job_number"/>
        <result property="contractType" column="contract_type"/>
        <result property="hiredate" column="hiredate"/>
        <result property="resignationTime" column="resignation_time"/>
        <result property="maritalStatus" column="marital_status"/>
        <result property="accountType" column="account_type"/>
        <result property="emergencyContact" column="emergency_contact"/>
        <result property="contactPhone" column="contact_phone"/>
        <result property="currentProvinceId" column="current_province_id"/>
        <result property="currentCityId" column="current_city_id"/>
        <result property="currentDistrictId" column="current_district_id"/>
        <result property="currentBelongRegion" column="current_belong_region"/>
        <result property="currentAddressDetail" column="current_address_detail"/>
        <result property="birthProvinceId" column="birth_province_id"/>
        <result property="birthCityId" column="birth_city_id"/>
        <result property="birthDistrictId" column="birth_district_id"/>
        <result property="birthBelongRegion" column="birth_belong_region"/>
        <result property="birthAddressDetail" column="birth_address_detail"/>
        <result property="qualifyCertificate" column="qualify_certificate"/>
        <result property="workExperience" column="work_experience"/>
        <result property="honoraryAchievement" column="honorary_achievement"/>
        <result property="projectAchievement" column="project_achievement"/>
        <result property="otherAchievement" column="other_achievement"/>
        <result property="education" column="education"/>
    </resultMap>

    <sql id="selectSysTeachStaffVo">
        select id,
               user_id,
               kindergarten_type,
               kindergarten_id,
               user_name,
               phonenumber,
               sex,
               email,
               inch_photo_one,
               inch_photo_two,
               political_status,
               main_post,
               other_post,
               teacher_education_id,
               user_status,
               professional_title_grade,
               is_backbone,
               backbone_start_time,
               backbone_end_time,
               backbone_type,
               is_discipline_leader,
               discipline,
               entry_teaching_age,
               actual_teaching_age,
               information_source,
               remark,
               is_deleted,
               create_by_id,
               create_by,
               create_time,
               update_by_id,
               update_by,
               update_time,
               tenant_id,
               identification_card,
               birth_date,
               nation,
               blood_type,
               job_number,
               contract_type,
               hiredate,
               resignation_time,
               marital_status,
               account_type,
               emergency_contact,
               contact_phone,
               current_province_id,
               current_city_id,
               current_district_id,
               current_belong_region,
               current_address_detail,
               birth_province_id,
               birth_city_id,
               birth_district_id,
               birth_belong_region,
               birth_address_detail,
               qualify_certificate,
               work_experience,
               honorary_achievement,
               project_achievement,
               other_achievement,
               education
        from sys_teach_staff
    </sql>

    <sql id="defaultDeleteCondition">
        is_deleted = '0'
    </sql>

    <select id="selectByUserId" resultType="com.vctgo.system.domain.SysTeachStaff">
        SELECT
            u.dept_id,
            u.nick_name user_name,
            u.sex,
            u.email,
            u.phonenumber,
            u.user_status,
            u.user_id,
            s.id,
            s.kindergarten_type,
            s.kindergarten_id,
            s.inch_photo_one,
            s.inch_photo_two,
            s.political_status,
            s.main_post,
            s.other_post,
            s.teacher_education_id,
            s.professional_title_grade,
            s.is_backbone,
            s.backbone_start_time,
            s.backbone_end_time,
            s.backbone_type,
            s.is_discipline_leader,
            s.discipline,
            s.entry_teaching_age,
            s.actual_teaching_age,
            s.information_source,
            s.remark,
            s.is_deleted,
            s.create_by_id,
            s.create_by,
            s.create_time,
            s.update_by_id,
            s.update_by,
            s.update_time,
            s.tenant_id,
            s.identification_card,
            s.birth_date,
            s.nation,
            s.blood_type,
            s.job_number,
            s.contract_type,
            s.hiredate,
            s.resignation_time,
            s.marital_status,
            s.account_type,
            s.emergency_contact,
            s.contact_phone,
            s.current_province_id,
            s.current_city_id,
            s.current_district_id,
            s.current_belong_region,
            s.current_address_detail,
            s.birth_province_id,
            s.birth_city_id,
            s.birth_district_id,
            s.birth_belong_region,
            s.birth_address_detail,
            s.qualify_certificate,
            s.work_experience,
            s.honorary_achievement,
            s.project_achievement,
            s.other_achievement,
            s.education
        FROM
            sys_user u
        LEFT JOIN sys_teach_staff s on u.user_id = s.user_id
        where u.user_id = #{userId}
    </select>

    <select id="selectSysTeachStaffList" resultMap="SysTeachStaffResult">
        <include refid="selectSysTeachStaffVo"/>
        <where>
            <include refid="defaultDeleteCondition"/>
            <if test="query.kindergartenType != null  and query.kindergartenType != ''">and kindergarten_type =
                #{query.kindergartenType}
            </if>
            <if test="query.kindergartenId != null ">and kindergarten_id = #{query.kindergartenId}</if>
            <if test="query.userName != null  and query.userName != ''">and user_name like concat('%',
                #{query.userName}, '%')
            </if>
            <if test="query.phonenumber != null  and query.phonenumber != ''">and phonenumber = #{query.phonenumber}</if>
            <if test="query.sex != null  and query.sex != ''">and sex = #{query.sex}</if>
            <if test="query.email != null  and query.email != ''">and email = #{query.email}</if>
            <if test="query.inchPhotoOne != null  and query.inchPhotoOne != ''">and inch_photo_one =
                #{query.inchPhotoOne}
            </if>
            <if test="query.inchPhotoTwo != null  and query.inchPhotoTwo != ''">and inch_photo_two =
                #{query.inchPhotoTwo}
            </if>
            <if test="query.politicalStatus != null  and query.politicalStatus != ''">and political_status =
                #{query.politicalStatus}
            </if>
            <if test="query.mainPost != null  and query.mainPost != ''">and main_post = #{query.mainPost}</if>
            <if test="query.otherPost != null  and query.otherPost != ''">and other_post = #{query.otherPost}</if>
            <if test="query.teacherEducationId != null  and query.teacherEducationId != ''">and teacher_education_id =
                #{query.teacherEducationId}
            </if>
            <if test="query.userStatus != null  and query.userStatus != ''">and user_status = #{query.userStatus}</if>
            <if test="query.professionalTitleGrade != null  and query.professionalTitleGrade != ''">and
                professional_title_grade = #{query.professionalTitleGrade}
            </if>
            <if test="query.isBackbone != null  and query.isBackbone != ''">and is_backbone = #{query.isBackbone}</if>
            <if test="query.backboneStartTime != null ">and backbone_start_time = #{query.backboneStartTime}</if>
            <if test="query.backboneEndTime != null ">and backbone_end_time = #{query.backboneEndTime}</if>
            <if test="query.backboneType != null  and query.backboneType != ''">and backbone_type =
                #{query.backboneType}
            </if>
            <if test="query.isDisciplineLeader != null  and query.isDisciplineLeader != ''">and is_discipline_leader =
                #{query.isDisciplineLeader}
            </if>
            <if test="query.discipline != null  and query.discipline != ''">and discipline = #{query.discipline}</if>
            <if test="query.entryTeachingAge != null  and query.entryTeachingAge != ''">and entry_teaching_age =
                #{query.entryTeachingAge}
            </if>
            <if test="query.actualTeachingAge != null  and query.actualTeachingAge != ''">and actual_teaching_age =
                #{query.actualTeachingAge}
            </if>
            <if test="query.informationSource != null  and query.informationSource != ''">and information_source =
                #{query.informationSource}
            </if>
            <if test="query.isDeleted != null  and query.isDeleted != ''">and is_deleted = #{query.isDeleted}</if>
            <if test="query.createById != null ">and create_by_id = #{query.createById}</if>
            <if test="query.updateById != null ">and update_by_id = #{query.updateById}</if>
            <if test="query.tenantId != null ">and tenant_id = #{query.tenantId}</if>
            <if test="query.identificationCard != null  and query.identificationCard != ''">and identification_card =
                #{query.identificationCard}
            </if>
            <if test="query.birthDate != null  and query.birthDate != ''">and birth_date = #{query.birthDate}</if>
            <if test="query.nation != null  and query.nation != ''">and nation = #{query.nation}</if>
            <if test="query.bloodType != null  and query.bloodType != ''">and blood_type = #{query.bloodType}</if>
            <if test="query.jobNumber != null  and query.jobNumber != ''">and job_number = #{query.jobNumber}</if>
            <if test="query.contractType != null  and query.contractType != ''">and contract_type =
                #{query.contractType}
            </if>
            <if test="query.hiredate != null ">and hiredate = #{query.hiredate}</if>
            <if test="query.resignationTime != null ">and resignation_time = #{query.resignationTime}</if>
            <if test="query.maritalStatus != null  and query.maritalStatus != ''">and marital_status =
                #{query.maritalStatus}
            </if>
            <if test="query.accountType != null  and query.accountType != ''">and account_type = #{query.accountType}
            </if>
            <if test="query.emergencyContact != null  and query.emergencyContact != ''">and emergency_contact =
                #{query.emergencyContact}
            </if>
            <if test="query.contactPhone != null  and query.contactPhone != ''">and contact_phone =
                #{query.contactPhone}
            </if>
            <if test="query.currentProvinceId != null  and query.currentProvinceId != ''">and current_province_id =
                #{query.currentProvinceId}
            </if>
            <if test="query.currentCityId != null  and query.currentCityId != ''">and current_city_id =
                #{query.currentCityId}
            </if>
            <if test="query.currentDistrictId != null  and query.currentDistrictId != ''">and current_district_id =
                #{query.currentDistrictId}
            </if>
            <if test="query.currentBelongRegion != null  and query.currentBelongRegion != ''">and current_belong_region
                = #{query.currentBelongRegion}
            </if>
            <if test="query.currentAddressDetail != null  and query.currentAddressDetail != ''">and
                current_address_detail = #{query.currentAddressDetail}
            </if>
            <if test="query.birthProvinceId != null  and query.birthProvinceId != ''">and birth_province_id =
                #{query.birthProvinceId}
            </if>
            <if test="query.birthCityId != null  and query.birthCityId != ''">and birth_city_id = #{query.birthCityId}
            </if>
            <if test="query.birthDistrictId != null  and query.birthDistrictId != ''">and birth_district_id =
                #{query.birthDistrictId}
            </if>
            <if test="query.birthBelongRegion != null  and query.birthBelongRegion != ''">and birth_belong_region =
                #{query.birthBelongRegion}
            </if>
            <if test="query.birthAddressDetail != null  and query.birthAddressDetail != ''">and birth_address_detail =
                #{query.birthAddressDetail}
            </if>
        </where>
    </select>

    <update id="logicalDeleteSysTeachStaffByIds" parameterType="String">
        update sys_teach_staff set is_deleted = #{query.isDeleted},
        update_by_id = #{query.updateById}, update_by = #{query.updateBy},
        update_time = #{query.updateTime} where user_id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteSysTeachStaffByIds" parameterType="String">
        delete from sys_teach_staff where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <update id="updateSysTeachStaff" >
        update sys_teach_staff
        <set>
            <if test="kindergartenType != null and kindergartenType != ''">kindergarten_type = #{kindergartenType},</if>
            <if test="kindergartenId != null and kindergartenId != ''">kindergarten_id = #{kindergartenId},</if>
            <if test="sex != null and sex != ''">sex = #{sex},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>

            <if test="updateById != null and updateById != ''">update_by_id = #{updateById},</if>
            update_time = sysdate()
        </set>
        where id = #{id}
    </update>
</mapper>
