<?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.practice.register.mapper.InterRegistrationMapper">

    <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.id_card,
        a.native_place,
        a.nation,
        a.political_outlook,
        a.graduated_from,
        a.speciality,
        a.mobile_phone,
        a.qq_num,
        a.type,
        a.proc_ins_id,
        a.process_definition_id,
        a.practice_status,
        a.user_id,
        a.practice_complete_day,
        a.practice_start_day,
        a.practice_office,
        a.practice_unit_name,
        a.project_manager,
        a.remarks
    </sql>
    <update id="updateStatusById">
        UPDATE human_resources_practice_registration SET type = #{type}
		WHERE id = #{id}
    </update>
    <update id="removeById">
        update human_resources_practice_registration set del_flag = '1' where id = #{id}
    </update>
    <update id="updatePracticeStatus">
        update human_resources_practice_registration set practice_status = '1',practice_complete_day = #{endTime} where user_id = #{createById}
    </update>
    <delete id="deleteByIdOnPhysic">

        DELETE a, b, c
        FROM human_resources_practice_registration a
        LEFT JOIN human_resources_practice_registration_experience b ON a.id = b.registration_id
        LEFT JOIN human_resources_practice_registration_family_members c ON a.id = c.registration_id
        WHERE a.id = #{id};

    </delete>

    <select id="findList" resultType="com.jeeplus.human.practice.register.service.dto.RegistrationDto">
        select
        <include refid="Base_Column_List"></include>,
        d.ID_ AS task_id,
        su.name as projectManagerName,
        so.name as departmentName
        from human_resources_practice_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.practice_office = so.id
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>
    <select id="getById" resultType="com.jeeplus.human.practice.register.domain.Registration">
        select
        <include refid="Base_Column_List"></include>
        from human_resources_practice_registration a
        where a.id = #{id} and a.del_flag = '0'
    </select>
    <select id="getTimeOutRegisters" resultType="com.jeeplus.human.practice.register.domain.Registration">
        select
        <include refid="Base_Column_List"></include>
        from human_resources_practice_registration a
        left join
        (
        SELECT
        MAX(create_time) AS last_create_time,
        create_by_id
        FROM
        human_resources_practice_registration_work_log
        WHERE
        del_flag = 0
        GROUP BY
        create_by_id
        ) b ON a.user_id = b.create_by_id
        <where>
            a.del_flag = 0
            and a.type = 5
            and a.practice_status = '0'
            AND b.last_create_time &lt;= #{threeDayAgo}
        </where>
        ORDER BY a.update_time DESC
    </select>
    <select id="findList2" resultType="com.jeeplus.human.practice.register.service.dto.RegistrationDto">
        select a.name,a.practice_start_day,a.practice_complete_day,a.practice_status,a.project_manager,
        b.last_create_time as lastCreateTime,b.work_name as workName,b.id as workId,su.name as projectManagerName
        from human_resources_practice_registration a
        left join (
        SELECT
        MAX(create_time) AS last_create_time,
        create_by_id,work_name,id
        FROM
        human_resources_practice_registration_work_log
        WHERE
        del_flag = 0
        GROUP BY
        create_by_id
        ) b ON a.user_id = b.create_by_id
        left join sys_user su on a.project_manager = su.id
        ${ew.customSqlSegment}
    </select>
    <select id="getTimeOutReimburseRegisters"
            resultType="com.jeeplus.human.practice.register.domain.Registration">
        select
        <include refid="Base_Column_List"></include>
        from human_resources_practice_registration a
        left join
        (
        SELECT
        MAX(create_time) AS last_create_time,
        create_by_id
        FROM
        human_resources_practice_reimburse_register
        WHERE
        del_flag = 0 and type = '5'
        GROUP BY
        create_by_id
        ) b ON a.user_id = b.create_by_id
        left join sys_user su on a.user_id = su.id
        where a.practice_status = '1' and su.del_flag = '0'
    </select>
</mapper>