<?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.jeeplus.human.enrollment.enrollmentRegistration.mapper.EnrollmentRegistrationMapper">

    <sql id="Base_Column_List">
        a.id,
        a.create_by_id,
        a.create_time,
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.name,
        a.sex,
        a.age,
        a.birthday,
        a.political_outlook,
        a.native_place,
        a.nation,
        a.marital_status,
        a.mobile_phone,
        a.id_card,
        a.home_address,
        a.permanent_address,
        a.graduated_from,
        a.speciality,
        a.start_time,
        a.end_time,
        a.education,
        a.education_nature,
        a.graduated_or_not,
        a.english_level,
        a.ncre,
        a.department,
        a.entry_date,
        a.contract_start_date,
        a.contract_end_date,
        a.tenant_id,
        a.type,
        a.proc_ins_id,
        a.process_definition_id,
        a.user_id,
        a.project_manager,
        a.remarks,
        a.on_job_status,
        a.process_type
    </sql>
    <update id="updateStatusById">
        UPDATE human_resources_enrollment_registration SET type = #{type}
		WHERE id = #{id}
    </update>
    <update id="removeById">
        UPDATE human_resources_enrollment_registration SET del_flag = '1'
		WHERE id = #{id}
    </update>
    <update id="updateByUserId">
        update human_resources_enrollment_registration SET on_job_status = '离职' where user_id = #{userId}
    </update>
    <delete id="deleteByIdOnPhysic">
         DELETE a, b
        FROM human_resources_enrollment_registration a
        LEFT JOIN human_resources_enrollment_social_security_card b ON a.id = b.enrollment_registration_id
        WHERE a.id = #{id};
    </delete>

    <select id="findList"
            resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentRegistration">
        select
        <include refid="Base_Column_List"></include>,
        d.ID_ AS task_id,
        su.name as projectManagerName,
        so.name as departmentName
        from human_resources_enrollment_registration a
        LEFT JOIN act_ru_task d ON a.proc_ins_id = d.PROC_INST_ID_
        left join sys_user su on a.project_manager = su.id
        left join sys_office so on a.department = so.id
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>
    <select id="exportList"
            resultType="com.jeeplus.human.enrollment.enrollmentRegistration.service.dto.ExportDTO">
        select
        <include refid="Base_Column_List"></include>,
        d.ID_ AS task_id,
        su.name as projectManagerName,
        so.name as departmentName,
        so1.name as company
        from human_resources_enrollment_registration a
        LEFT JOIN act_ru_task d ON a.proc_ins_id = d.PROC_INST_ID_
        left join sys_user su on a.project_manager = su.id
        left join sys_office so on a.department = so.id
        left join sys_office so1 on so.parent_id = so1.id
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>

    <select id="getById"
            resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentRegistration">
        select
        <include refid="Base_Column_List"></include>,
        b.social_security_number,
        b.social_security_bank_number,
        b.social_security_picture_front,
        b.social_security_picture_opposite as socialSecurityPictureOpposite,
        c.zx_bank_card_number as zxBankCardNumber,
        c.zx_account_holder as zxAccountHolder,
        c.account_holder_front as accountHolderFront,
        c.account_holder_opposite as accountHolderOpposite,
        c.gs_bank_card_number as gsBankCardNumber,
        c.gs_account_holder as gsAccountHolder,
        c.gs_account_holder_front as gsAccountHolderFront,
        c.gs_account_holder_opposite as gsAccountHolderOpposite,
        c.id as wageCardId
        from human_resources_enrollment_registration a
        left join human_resources_enrollment_social_security_card b on a.id = b.enrollment_registration_id and b.del_flag = '0'
        left join human_resources_enrollment_wage_card c on a.id = c.enrollment_registration_id and c.del_flag = '0'
        where a.id = #{id} and a.del_flag = '0'
    </select>
    <select id="getFormalUserInfo"
            resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentRegistration">
        SELECT
        <include refid="Base_Column_List"></include>
        FROM `human_resources_enrollment_registration`  a
        LEFT JOIN sys_user su on a.user_id = su.id and su.del_flag = '0'
        LEFT JOIN human_resources_depart_registration hrdr ON hrdr.create_by_id = a.user_id
        <where>
            a.on_job_status = '离职'
        and hrdr.depart_resignation_date &lt; CURDATE()
        </where>
    </select>
    <select id="getAllUserIdInSuccess" resultType="java.lang.String">
        SELECT DISTINCT a.user_id
        FROM human_resources_enrollment_registration a
        LEFT JOIN sys_user su ON a.user_id = su.id
        WHERE a.del_flag = '0' AND a.user_id IS NOT NULL AND a.user_id != '' and su.del_flag = '0'

        UNION

        SELECT DISTINCT b.user_id
        FROM (
            SELECT DISTINCT a.user_id
            FROM human_resources_practice_registration a
                LEFT JOIN sys_user su ON a.user_id = su.id
            WHERE a.del_flag = '0' AND a.user_id IS NOT NULL AND a.user_id != '' and su.del_flag = '0'

        ) b;
    </select>

    <select id="getByUserId" resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentRegistration">
        SELECT
        <include refid="Base_Column_List"></include>
        FROM `human_resources_enrollment_registration`  a
        WHERE a.user_id = #{userId} and a.del_flag = '0'
    </select>
    <delete id="delByUserId">
        UPDATE human_resources_enrollment_registration SET del_flag = '1'
		WHERE user_id = #{id}
    </delete>
    <select id="getByMobile" resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentRegistration">
        SELECT
        <include refid="Base_Column_List"></include>
        FROM `human_resources_enrollment_registration`  a
        WHERE a.mobile_phone = #{mobilePhone} and a.del_flag = '0'
    </select>
</mapper>