<?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.rwk.system.mapper.RwkStaffInformationMapper">

    <resultMap type="RwkStaffInformation" id="RwkStaffInformationResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="nation"    column="nation"    />
        <result property="nationality"    column="nationality"    />
        <result property="birthday"    column="birthday"    />
        <result property="birthplace"    column="birthplace"    />
        <result property="nativePlace"    column="native_place"    />
        <result property="overseasResidencyStatus"    column="overseas_residency_status"    />
        <result property="acquiringCountry"    column="acquiring_country"    />
        <result property="idNumber"    column="id_number"    />
        <result property="workTime"    column="work_time"    />
        <result property="idCard"    column="id_card"    />
        <result property="party"    column="party"    />
        <result property="partyPositions"    column="party_positions"    />
        <result property="joinTime"    column="join_time"    />
        <result property="talentCategory"    column="talent_category"    />
        <result property="religion"    column="religion"    />
        <result property="currentOccupation"    column="current_occupation"    />
        <result property="zlhJob"    column="zlh_job"    />
        <result property="qrzSchoolMajor"    column="qrz_school_major"    />
        <result property="qrzQualification"    column="qrz_qualification"    />
        <result property="qrzDegree"    column="qrz_degree"    />
        <result property="zzSchoolMajor"    column="zz_school_major"    />
        <result property="zzQualification"    column="zz_qualification"    />
        <result property="zzDegree"    column="zz_degree"    />
        <result property="unitJob"    column="unit_job"    />
        <result property="technicalTitle"    column="technical_title"    />
        <result property="speciality"    column="speciality"    />
        <result property="unitAttribute"    column="unit_attribute"    />
        <result property="jobLevel"    column="job_level"    />
        <result property="currentTenure"    column="current_tenure"    />
        <result property="unitAddress"    column="unit_address"    />
        <result property="unitPhone"    column="unit_phone"    />
        <result property="unitZipCode"    column="unit_zip_code"    />
        <result property="homeAddress"    column="home_address"    />
        <result property="homePhone"    column="home_phone"    />
        <result property="homeZipCode"    column="home_zip_code"    />
        <result property="email"    column="email"    />
        <result property="mobilePhone"    column="mobile_phone"    />
        <result property="wxCode"    column="wx_code"    />
        <result property="hobby"    column="hobby"    />
        <result property="resume"    column="resume"    />
        <result property="training"    column="training"    />
        <result property="achievement"    column="achievement"    />
        <result property="familyMemberCode"    column="family_member_code"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="photo"    column="photo"    />
    </resultMap>

    <resultMap id="RwkStaffInformationRwkFamilyMemberResult" type="RwkStaffInformation" extends="RwkStaffInformationResult">
        <collection property="rwkFamilyMemberList" ofType="RwkFamilyMember" column="family_member_code" select="selectRwkFamilyMemberList" />
    </resultMap>

    <resultMap type="RwkFamilyMember" id="RwkFamilyMemberResult">
        <result property="id"    column="id"    />
        <result property="appellation"    column="appellation"    />
        <result property="name"    column="name"    />
        <result property="birthday"    column="birthday"    />
        <result property="politicalStatus"    column="political_status"    />
        <result property="unitJob"    column="unit_job"    />
        <result property="familyMemberCode"    column="family_member_code"    />
    </resultMap>

    <sql id="selectRwkStaffInformationVo">
        select id, name, sex, nation, nationality, birthday, birthplace, native_place, overseas_residency_status,
               acquiring_country, id_number, work_time, id_card, party, party_positions, join_time, talent_category,
               religion, current_occupation, zlh_job, qrz_school_major, qrz_qualification, qrz_degree, zz_school_major,
               zz_qualification, zz_degree, unit_job, technical_title, speciality, unit_attribute, job_level, current_tenure,
               unit_address, unit_phone, unit_zip_code, home_address, home_phone, home_zip_code, email, mobile_phone,
               wx_code, hobby, resume, training, achievement, family_member_code, create_time, create_by, update_time,
               update_by, photo from rwk_staff_information
    </sql>

    <select id="selectRwkStaffInformationList" parameterType="RwkStaffInformation" resultMap="RwkStaffInformationResult">
        <include refid="selectRwkStaffInformationVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="nation != null  and nation != ''"> and nation = #{nation}</if>
            <if test="nationality != null  and nationality != ''"> and nationality = #{nationality}</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="birthplace != null  and birthplace != ''"> and birthplace = #{birthplace}</if>
            <if test="nativePlace != null  and nativePlace != ''"> and native_place = #{nativePlace}</if>
            <if test="overseasResidencyStatus != null  and overseasResidencyStatus != ''"> and overseas_residency_status = #{overseasResidencyStatus}</if>
            <if test="acquiringCountry != null  and acquiringCountry != ''"> and acquiring_country = #{acquiringCountry}</if>
            <if test="idNumber != null  and idNumber != ''"> and id_number = #{idNumber}</if>
            <if test="workTime != null  and workTime != ''"> and work_time = #{workTime}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="party != null  and party != ''"> and party = #{party}</if>
            <if test="partyPositions != null  and partyPositions != ''"> and party_positions = #{partyPositions}</if>
            <if test="joinTime != null  and joinTime != ''"> and join_time = #{joinTime}</if>
            <if test="talentCategory != null  and talentCategory != ''"> and talent_category = #{talentCategory}</if>
            <if test="religion != null  and religion != ''"> and religion = #{religion}</if>
            <if test="currentOccupation != null  and currentOccupation != ''"> and current_occupation = #{currentOccupation}</if>
            <if test="zlhJob != null  and zlhJob != ''"> and zlh_job = #{zlhJob}</if>
            <if test="qrzSchoolMajor != null  and qrzSchoolMajor != ''"> and qrz_school_major = #{qrzSchoolMajor}</if>
            <if test="qrzQualification != null  and qrzQualification != ''"> and qrz_qualification = #{qrzQualification}</if>
            <if test="qrzDegree != null  and qrzDegree != ''"> and qrz_degree = #{qrzDegree}</if>
            <if test="zzSchoolMajor != null  and zzSchoolMajor != ''"> and zz_school_major = #{zzSchoolMajor}</if>
            <if test="zzQualification != null  and zzQualification != ''"> and zz_qualification = #{zzQualification}</if>
            <if test="zzDegree != null  and zzDegree != ''"> and zz_degree = #{zzDegree}</if>
            <if test="unitJob != null  and unitJob != ''"> and unit_job = #{unitJob}</if>
            <if test="technicalTitle != null  and technicalTitle != ''"> and technical_title = #{technicalTitle}</if>
            <if test="speciality != null  and speciality != ''"> and speciality = #{speciality}</if>
            <if test="unitAttribute != null  and unitAttribute != ''"> and unit_attribute = #{unitAttribute}</if>
            <if test="jobLevel != null  and jobLevel != ''"> and job_level = #{jobLevel}</if>
            <if test="currentTenure != null  and currentTenure != ''"> and current_tenure = #{currentTenure}</if>
            <if test="unitAddress != null  and unitAddress != ''"> and unit_address = #{unitAddress}</if>
            <if test="unitPhone != null  and unitPhone != ''"> and unit_phone = #{unitPhone}</if>
            <if test="unitZipCode != null  and unitZipCode != ''"> and unit_zip_code = #{unitZipCode}</if>
            <if test="homeAddress != null  and homeAddress != ''"> and home_address = #{homeAddress}</if>
            <if test="homePhone != null  and homePhone != ''"> and home_phone = #{homePhone}</if>
            <if test="homeZipCode != null  and homeZipCode != ''"> and home_zip_code = #{homeZipCode}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="mobilePhone != null  and mobilePhone != ''"> and mobile_phone = #{mobilePhone}</if>
            <if test="wxCode != null  and wxCode != ''"> and wx_code = #{wxCode}</if>
            <if test="hobby != null  and hobby != ''"> and hobby = #{hobby}</if>
            <if test="resume != null  and resume != ''"> and resume = #{resume}</if>
            <if test="training != null  and training != ''"> and training = #{training}</if>
            <if test="achievement != null  and achievement != ''"> and achievement = #{achievement}</if>
            <if test="familyMemberCode != null  and familyMemberCode != ''"> and family_member_code = #{familyMemberCode}</if>
            <if test="photo != null  and photo != ''"> and photo = #{photo}</if>
        </where>
    </select>

    <select id="selectRwkStaffInformationById" parameterType="Long" resultMap="RwkStaffInformationRwkFamilyMemberResult">
        select id, name, sex, nation, nationality, birthday, birthplace, native_place, overseas_residency_status,
               acquiring_country, id_number, work_time, id_card, party, party_positions, join_time, talent_category,
               religion, current_occupation, zlh_job, qrz_school_major, qrz_qualification, qrz_degree, zz_school_major,
               zz_qualification, zz_degree, unit_job, technical_title, speciality, unit_attribute, job_level, current_tenure,
               unit_address, unit_phone, unit_zip_code, home_address, home_phone, home_zip_code, email, mobile_phone, wx_code,
               hobby, resume, training, achievement, family_member_code, create_time, create_by, update_time, update_by, photo
        from rwk_staff_information
        where id = #{id}
    </select>

    <select id="selectRwkFamilyMemberList" resultMap="RwkFamilyMemberResult">
        select id, appellation, name, birthday, political_status, unit_job, family_member_code
        from rwk_family_member
        where family_member_code = #{family_member_code}
    </select>

    <insert id="insertRwkStaffInformation" parameterType="RwkStaffInformation" useGeneratedKeys="true" keyProperty="id">
        insert into rwk_staff_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="sex != null">sex,</if>
            <if test="nation != null">nation,</if>
            <if test="nationality != null">nationality,</if>
            <if test="birthday != null">birthday,</if>
            <if test="birthplace != null">birthplace,</if>
            <if test="nativePlace != null">native_place,</if>
            <if test="overseasResidencyStatus != null">overseas_residency_status,</if>
            <if test="acquiringCountry != null">acquiring_country,</if>
            <if test="idNumber != null">id_number,</if>
            <if test="workTime != null">work_time,</if>
            <if test="idCard != null">id_card,</if>
            <if test="party != null">party,</if>
            <if test="partyPositions != null">party_positions,</if>
            <if test="joinTime != null">join_time,</if>
            <if test="talentCategory != null">talent_category,</if>
            <if test="religion != null">religion,</if>
            <if test="currentOccupation != null">current_occupation,</if>
            <if test="zlhJob != null">zlh_job,</if>
            <if test="qrzSchoolMajor != null">qrz_school_major,</if>
            <if test="qrzQualification != null">qrz_qualification,</if>
            <if test="qrzDegree != null">qrz_degree,</if>
            <if test="zzSchoolMajor != null">zz_school_major,</if>
            <if test="zzQualification != null">zz_qualification,</if>
            <if test="zzDegree != null">zz_degree,</if>
            <if test="unitJob != null">unit_job,</if>
            <if test="technicalTitle != null">technical_title,</if>
            <if test="speciality != null">speciality,</if>
            <if test="unitAttribute != null">unit_attribute,</if>
            <if test="jobLevel != null">job_level,</if>
            <if test="currentTenure != null">current_tenure,</if>
            <if test="unitAddress != null">unit_address,</if>
            <if test="unitPhone != null">unit_phone,</if>
            <if test="unitZipCode != null">unit_zip_code,</if>
            <if test="homeAddress != null">home_address,</if>
            <if test="homePhone != null">home_phone,</if>
            <if test="homeZipCode != null">home_zip_code,</if>
            <if test="email != null">email,</if>
            <if test="mobilePhone != null">mobile_phone,</if>
            <if test="wxCode != null">wx_code,</if>
            <if test="hobby != null">hobby,</if>
            <if test="resume != null">resume,</if>
            <if test="training != null">training,</if>
            <if test="achievement != null">achievement,</if>
            <if test="familyMemberCode != null">family_member_code,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="photo != null">photo,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="nation != null">#{nation},</if>
            <if test="nationality != null">#{nationality},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="birthplace != null">#{birthplace},</if>
            <if test="nativePlace != null">#{nativePlace},</if>
            <if test="overseasResidencyStatus != null">#{overseasResidencyStatus},</if>
            <if test="acquiringCountry != null">#{acquiringCountry},</if>
            <if test="idNumber != null">#{idNumber},</if>
            <if test="workTime != null">#{workTime},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="party != null">#{party},</if>
            <if test="partyPositions != null">#{partyPositions},</if>
            <if test="joinTime != null">#{joinTime},</if>
            <if test="talentCategory != null">#{talentCategory},</if>
            <if test="religion != null">#{religion},</if>
            <if test="currentOccupation != null">#{currentOccupation},</if>
            <if test="zlhJob != null">#{zlhJob},</if>
            <if test="qrzSchoolMajor != null">#{qrzSchoolMajor},</if>
            <if test="qrzQualification != null">#{qrzQualification},</if>
            <if test="qrzDegree != null">#{qrzDegree},</if>
            <if test="zzSchoolMajor != null">#{zzSchoolMajor},</if>
            <if test="zzQualification != null">#{zzQualification},</if>
            <if test="zzDegree != null">#{zzDegree},</if>
            <if test="unitJob != null">#{unitJob},</if>
            <if test="technicalTitle != null">#{technicalTitle},</if>
            <if test="speciality != null">#{speciality},</if>
            <if test="unitAttribute != null">#{unitAttribute},</if>
            <if test="jobLevel != null">#{jobLevel},</if>
            <if test="currentTenure != null">#{currentTenure},</if>
            <if test="unitAddress != null">#{unitAddress},</if>
            <if test="unitPhone != null">#{unitPhone},</if>
            <if test="unitZipCode != null">#{unitZipCode},</if>
            <if test="homeAddress != null">#{homeAddress},</if>
            <if test="homePhone != null">#{homePhone},</if>
            <if test="homeZipCode != null">#{homeZipCode},</if>
            <if test="email != null">#{email},</if>
            <if test="mobilePhone != null">#{mobilePhone},</if>
            <if test="wxCode != null">#{wxCode},</if>
            <if test="hobby != null">#{hobby},</if>
            <if test="resume != null">#{resume},</if>
            <if test="training != null">#{training},</if>
            <if test="achievement != null">#{achievement},</if>
            <if test="familyMemberCode != null">#{familyMemberCode},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="photo != null">#{photo},</if>
        </trim>
    </insert>

    <update id="updateRwkStaffInformation" parameterType="RwkStaffInformation">
        update rwk_staff_information
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="nation != null">nation = #{nation},</if>
            <if test="nationality != null">nationality = #{nationality},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="birthplace != null">birthplace = #{birthplace},</if>
            <if test="nativePlace != null">native_place = #{nativePlace},</if>
            <if test="overseasResidencyStatus != null">overseas_residency_status = #{overseasResidencyStatus},</if>
            <if test="acquiringCountry != null">acquiring_country = #{acquiringCountry},</if>
            <if test="idNumber != null">id_number = #{idNumber},</if>
            <if test="workTime != null">work_time = #{workTime},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="party != null">party = #{party},</if>
            <if test="partyPositions != null">party_positions = #{partyPositions},</if>
            <if test="joinTime != null">join_time = #{joinTime},</if>
            <if test="talentCategory != null">talent_category = #{talentCategory},</if>
            <if test="religion != null">religion = #{religion},</if>
            <if test="currentOccupation != null">current_occupation = #{currentOccupation},</if>
            <if test="zlhJob != null">zlh_job = #{zlhJob},</if>
            <if test="qrzSchoolMajor != null">qrz_school_major = #{qrzSchoolMajor},</if>
            <if test="qrzQualification != null">qrz_qualification = #{qrzQualification},</if>
            <if test="qrzDegree != null">qrz_degree = #{qrzDegree},</if>
            <if test="zzSchoolMajor != null">zz_school_major = #{zzSchoolMajor},</if>
            <if test="zzQualification != null">zz_qualification = #{zzQualification},</if>
            <if test="zzDegree != null">zz_degree = #{zzDegree},</if>
            <if test="unitJob != null">unit_job = #{unitJob},</if>
            <if test="technicalTitle != null">technical_title = #{technicalTitle},</if>
            <if test="speciality != null">speciality = #{speciality},</if>
            <if test="unitAttribute != null">unit_attribute = #{unitAttribute},</if>
            <if test="jobLevel != null">job_level = #{jobLevel},</if>
            <if test="currentTenure != null">current_tenure = #{currentTenure},</if>
            <if test="unitAddress != null">unit_address = #{unitAddress},</if>
            <if test="unitPhone != null">unit_phone = #{unitPhone},</if>
            <if test="unitZipCode != null">unit_zip_code = #{unitZipCode},</if>
            <if test="homeAddress != null">home_address = #{homeAddress},</if>
            <if test="homePhone != null">home_phone = #{homePhone},</if>
            <if test="homeZipCode != null">home_zip_code = #{homeZipCode},</if>
            <if test="email != null">email = #{email},</if>
            <if test="mobilePhone != null">mobile_phone = #{mobilePhone},</if>
            <if test="wxCode != null">wx_code = #{wxCode},</if>
            <if test="hobby != null">hobby = #{hobby},</if>
            <if test="resume != null">resume = #{resume},</if>
            <if test="training != null">training = #{training},</if>
            <if test="achievement != null">achievement = #{achievement},</if>
            <if test="familyMemberCode != null">family_member_code = #{familyMemberCode},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="photo != null">photo = #{photo},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRwkStaffInformationById" parameterType="Long">
        delete from rwk_staff_information where id = #{id}
    </delete>

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

    <delete id="deleteRwkFamilyMemberByFamilyMemberCodes" parameterType="String">
        delete from rwk_family_member where family_member_code in
        (select family_member_code from rwk_staff_information where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>)
    </delete>

    <delete id="deleteRwkFamilyMemberByFamilyMemberCode" parameterType="Long">
        delete from rwk_family_member where family_member_code =
        (select family_member_code from rwk_staff_information where id = #{id})
    </delete>

    <insert id="batchRwkFamilyMember">
        insert into rwk_family_member(appellation, name, birthday, political_status, unit_job, family_member_code) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.appellation}, #{item.name}, #{item.birthday}, #{item.politicalStatus}, #{item.unitJob}, #{item.familyMemberCode})
        </foreach>
    </insert>

</mapper>