<?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.registration.mapper.DepartMapper">

    <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.arrival_date,
        a.depart_resignation_date
    </sql>
    <update id="updateStatusById">
        UPDATE human_resources_depart_registration SET type = #{type}
		WHERE id = #{id}
    </update>

    <select id="findList" resultType="com.jeeplus.human.depart.registration.domain.DepartRegistration">
        select
        <include refid="Base_Column_List"></include>,
        d.ID_ AS task_id,
        e.ID_ AS handover_task_id,
        su.name as projectManagerName,
        su2.mobile as mobile,
        so.name as departmentName,
        dh.id as handoverId,
        dh.proc_ins_id as handoverProcInsId,
        ifnull(dh.type,"0") as "handoverType",
        ifnull(wa.url,"") as "dimissionProveUrl",
        im.id as imprestId,
        im.proc_ins_id as imprestProcInsId,
        im.process_definition_id as imprestProcDefId,
        ifnull(im.type,"0") as "imprestType",
        ifnull(compu.type,"0") as "computerType",
        compu.id as computerId,
        compu.proc_ins_id as computerProcInsId,
        compu.process_definition_id as computerProcDefId,
        ifnull(acco.type,"0") as "accountsType",
        acco.id as accountsId,
        acco.proc_ins_id as accountsProcInsId,
        acco.process_definition_id as accountsProcDefId,
        ifnull(sse.type,"0") as "securityType",
        sse.id as securityId,
        sse.proc_ins_id as securityProcInsId,
        sse.process_definition_id as securityProcDefId,
        ifnull(dhd.type,"0") as "draftType",
        dhd.id as draftId,
        dhd.proc_ins_id as draftProcInsId,
        dhd.process_definition_id as draftProcDefId,
        ifnull(reco.type,"0") as "recoveryType",
        reco.id as recoveryId,
        reco.proc_ins_id as recoveryProcInsId,
        reco.process_definition_id as recoveryProcDefId
        from human_resources_depart_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_user su2 on a.create_by_id = su2.id
        LEFT JOIN sys_office so on a.department = so.id
        left join human_resources_depart_handover dh on a.id = dh.registration_id
        left join work_attachment wa on dh.id = wa.attachment_id
        LEFT JOIN act_ru_task e ON dh.proc_ins_id = e.PROC_INST_ID_
        left join human_resources_depart_handover_imprest im on dh.id = im.handover_id
        left join human_resources_depart_handover_computer compu on dh.id = compu.handover_id
        left join human_resources_depart_handover_accounts acco on dh.id = acco.handover_id
        left join human_resources_depart_handover_social_security sse on dh.id = sse.handover_id
        left join human_resources_depart_handover_draft dhd on dh.id = dhd.handover_id
        left join human_resources_depart_handover_recovery reco on dh.id = reco.handover_id
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>
    <select id="getById" resultType="com.jeeplus.human.depart.registration.domain.DepartRegistration">
        select
        <include refid="Base_Column_List"></include>
        from human_resources_depart_registration a
        where a.id = #{id} and a.del_flag = '0'
    </select>


    <select id="getByHandoverId" resultType="com.jeeplus.human.depart.registration.domain.DepartRegistration">
        select
        <include refid="Base_Column_List"></include>,
        d.ID_ AS task_id,
        e.ID_ AS handover_task_id,
        su.name as projectManagerName,
        su2.mobile as mobile,
        so.name as departmentName,
        dh.id as handoverId,
        dh.proc_ins_id as handoverProcInsId,
        ifnull(dh.type,"0") as "handoverType",
        ifnull(wa.url,"") as "dimissionProveUrl",
        im.id as imprestId,
        im.proc_ins_id as imprestProcInsId,
        im.process_definition_id as imprestProcDefId,
        ifnull(im.type,"0") as "imprestType",
        ifnull(compu.type,"0") as "computerType",
        compu.id as computerId,
        compu.proc_ins_id as computerProcInsId,
        compu.process_definition_id as computerProcDefId,
        ifnull(acco.type,"0") as "accountsType",
        acco.id as accountsId,
        acco.proc_ins_id as accountsProcInsId,
        acco.process_definition_id as accountsProcDefId,
        ifnull(sse.type,"0") as "securityType",
        sse.id as securityId,
        sse.proc_ins_id as securityProcInsId,
        sse.process_definition_id as securityProcDefId,
        ifnull(dhd.type,"0") as "draftType",
        dhd.id as draftId,
        dhd.proc_ins_id as draftProcInsId,
        dhd.process_definition_id as draftProcDefId,
        ifnull(reco.type,"0") as "recoveryType",
        reco.id as recoveryId,
        reco.proc_ins_id as recoveryProcInsId,
        reco.process_definition_id as recoveryProcDefId
        from human_resources_depart_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_user su2 on a.create_by_id = su2.id
        LEFT JOIN sys_office so on a.department = so.id
        left join human_resources_depart_handover dh on a.id = dh.registration_id
        left join work_attachment wa on dh.id = wa.attachment_id
        LEFT JOIN act_ru_task e ON dh.proc_ins_id = e.PROC_INST_ID_
        left join human_resources_depart_handover_imprest im on dh.id = im.handover_id
        left join human_resources_depart_handover_computer compu on dh.id = compu.handover_id
        left join human_resources_depart_handover_accounts acco on dh.id = acco.handover_id
        left join human_resources_depart_handover_social_security sse on dh.id = sse.handover_id
        left join human_resources_depart_handover_draft dhd on dh.id = dhd.handover_id
        left join human_resources_depart_handover_recovery reco on dh.id = reco.handover_id
        <where>
            dh.id = #{handoverId}
        </where>
        ORDER BY a.create_time DESC
    </select>

</mapper>