<?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.ruoyi.oa.mapper.EmployeeOnboardingMapper">

    <resultMap type="com.ruoyi.oa.domain.EmployeeOnboarding" id="EmployeeOnboardingResult">
        <result property="onboardingId" column="onboarding_id"/>
        <result property="idPhoto" column="id_photo"/>
        <result property="userId" column="user_id"/>
        <result property="joiningDate" column="joining_date"/>
        <result property="managerId" column="manager_id"/>
        <result property="highestDegree" column="highest_degree"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
        <result property="birthDate" column="birth_date"/>
        <result property="ethnicity" column="ethnicity"/>
        <result property="confirmDate" column="confirm_date"/>
        <result property="maritalStatus" column="marital_status"/>
        <result property="politicalStatus" column="political_status"/>
        <result property="height" column="height"/>
        <result property="weight" column="weight"/>
        <result property="emergencyContact1" column="emergency_contact1"/>
        <result property="emergencyContact2" column="emergency_contact2"/>
        <result property="status" column="status"/>
    </resultMap>


    <update id="updateByUserId" parameterType="com.ruoyi.oa.domain.EmployeeOnboarding">
        update employee_onboarding
        <set>
            <if test="idPhoto != null">id_photo = #{idPhoto},</if>
            <if test="joiningDate != null">joining_date = #{joiningDate},</if>
            <if test="managerId != null and managerId != ''">manager_id = #{managerId},</if>
            <if test="highestDegree != null and highestDegree != ''">highest_degree = #{highestDegree},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="birthDate != null and birthDate != ''">birth_date = #{birthDate},</if>
            <if test="ethnicity != null and ethnicity != ''">ethnicity = #{ethnicity},</if>
            <if test="confirmDate != null">confirm_date = #{confirmDate},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="maritalStatus != null and maritalStatus != ''">marital_status = #{maritalStatus},</if>
            <if test="politicalStatus != null and politicalStatus != ''">political_status = #{politicalStatus},</if>
            <if test="height != null and height != ''">height = #{height},</if>
            <if test="weight != null and weight != ''">weight = #{weight},</if>
            <if test="emergencyContact1 != null and emergencyContact1 != ''">emergency_contact1 = #{emergencyContact1},</if>
            <if test="emergencyContact2 != null and emergencyContact2 != ''">emergency_contact2 = #{emergencyContact2},</if>
        </set>
        where user_id = #{userId}
    </update>

    <select id="selectVoPagePlus" resultType="com.ruoyi.oa.domain.vo.EmployeeOnboardingVo">
        SELECT
            eo.user_id,
            su.nick_name,
            eo.joining_date,
            DATEDIFF(CURDATE(), eo.joining_date) AS workTime,
            eo.confirm_date,
            highest_degree,
            eo.remark,
            eo.birth_date,
            eo.status,
            eo.onboarding_id,
            CASE
                WHEN eo.confirm_date IS NULL THEN 0
                ELSE 1
                END AS confirmStatus
        FROM employee_onboarding eo
                 LEFT JOIN sys_user su
                           ON su.user_id = eo.user_id
            ${ew.getCustomSqlSegment}


    </select>


    <select id="selectVoByUserId" resultType="com.ruoyi.oa.domain.vo.EmployeeOnboardingVo">
        SELECT
            eo.onboarding_id,
            eo.user_id,
            su.nick_name,
            eo.joining_date,
            DATEDIFF(CURDATE(), eo.joining_date) AS workTime,
            eo.confirm_date,
            highest_degree,
            eo.remark,
            eo.birth_date,
            eo.status,
            political_status,
            CASE
                WHEN eo.confirm_date IS NULL THEN 0
                ELSE 1
                END AS confirmStatus
        FROM employee_onboarding eo
                 LEFT JOIN sys_user su
                           ON su.user_id = eo.user_id

        where eo.user_id = #{userId}

    </select>


</mapper>
