<?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.EnrollmentLaborContractInfoMapper">

    <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.type,
        a.code,
        a.term,
        a.start_date,
        a.end_date,
        a.trial_end_date,
        a.processe_date,
        a.enrollment_registration_id,
        a.user_id,
        a.remarks
    </sql>

    <select id="getByRegistrationId"
            resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentLaborContractInfo">
        select
        <include refid="Base_Column_List"></include>
        from human_resources_enrollment_contract_info a
        where a.del_flag = '0'
        <if test="userId != null and userId != ''">
            and a.user_id = #{userId}
        </if>
    </select>

    <select id="getById"
            resultType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentLaborContractInfo">
        select
        <include refid="Base_Column_List"></include>,
        re.name as userName,
        so.name as departmentName
        from human_resources_enrollment_contract_info a
        left join human_resources_enrollment_registration re on a.user_id = re.user_id and re.del_flag = '0'
        left join sys_office so on re.department = so.id
        where a.id = #{id} and a.del_flag = '0'
    </select>

    <update id="updateContractById" parameterType="com.jeeplus.human.enrollment.enrollmentRegistration.domain.EnrollmentLaborContractInfo">
        UPDATE human_resources_enrollment_contract_info
        SET
            type = #{type},
            code = #{code},
            term = #{term},
            start_date = #{startDate},
            end_date = #{endDate},
            trial_end_date = #{trialEndDate},
            processe_date = #{processeDate},
            status = #{status},
            update_time = NOW()
        WHERE id = #{id} and del_flag = '0'
    </update>

    <delete id="deleteByRegistrationId" parameterType="String">
        DELETE FROM human_resources_enrollment_training_info
        WHERE enrollment_registration_id = #{enrollmentRegistrationId}
    </delete>

    <select id="findDtos" resultType="com.jeeplus.sys.service.dto.WorkAttachmentInfoDTO">
        SELECT
            id,
            url,
            attachment_name AS `name`,
            create_by_id AS `by`,
            create_time,
            attachment_flag AS attachmentFlag
        FROM
            work_attachment
        WHERE
            del_flag = 0
          AND attachment_id = #{id}
    </select>
</mapper>