<?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.depart.handover.mapper.HandoverMapper">

    <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.type,
        a.proc_ins_id,
        a.process_definition_id,
        a.project_manager,
        a.remarks,
        a.department,
        a.draft_administrator,
        a.registration_id,
        a.xml_file_path,
        a.pdf_file_path,
        a.word_file_path
    </sql>
    <update id="updateStatusById">
        UPDATE human_resources_depart_handover SET type = #{type}
		WHERE id = #{id}
    </update>



    <select id="getById" resultType="com.jeeplus.human.depart.handover.domain.Handover">
        select
        <include refid="Base_Column_List"></include>,
        so.name as departmentName,
        su2.name as projectManagerName
        from human_resources_depart_handover a
        left join sys_user su on a.create_by_id = su.id
        left join sys_office so on su.office_id = so.id
        left join sys_user su2 on a.project_manager = su2.id
        where a.id = #{id} and a.del_flag = '0'
    </select>
    <select id="getUserInfoById" resultType="com.jeeplus.human.depart.handover.domain.Handover">
        SELECT a.name,a.arrival_date,a.depart_resignation_date FROM human_resources_depart_registration a
        LEFT JOIN human_resources_depart_handover b on a.id = b.registration_id
        WHERE b.id = #{handoverId}
    </select>

    <select id="queryByContractId" resultType="com.jeeplus.human.depart.handover.domain.Handover">
        select
        <include refid="Base_Column_List"></include>
        from human_resources_depart_handover a
        where a.signature_contract_id = #{signatureContractId} and a.del_flag = '0'
    </select>
    <select id="getUserInfoByUserId" resultType="java.lang.String">
        select id FROM human_resources_depart_registration where create_by_id = #{userId} and del_flag = 0
    </select>

    <update id="updateSignatureUrl">
        UPDATE human_resources_depart_handover SET signature_url = #{signatureUrl}
		WHERE id = #{id}
    </update>

    <insert id="saveProject">
        INSERT INTO human_resources_depart_handover_project (
        project_number,
        project_name,
        report_code,
        node_location,
        type,
        handover_id
        )
        VALUES
        <foreach collection="handoverProject" item="project" separator=",">
            (#{project.projectNumber}, #{project.projectName}, #{project.reportCode}, #{project.nodeLocation}, #{project.type}, #{project.handoverId})
        </foreach>
    </insert>

    <select id="findProjectList" resultType="com.jeeplus.human.depart.handover.domain.HandoverProject">
        select
            a.id,
            a.create_time as createTime,
            a.create_by_id as createById,
            a.report_code as reportCode,
            a.node_location as nodeLocation,
            a.type,
            a.handover_id as handoverId
            FROM human_resources_depart_handover_project a where a.handover_id = #{id} and del_flag = 0
    </select>

</mapper>