<?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.business.humanResources.mapper.StaffDimissionMapper">

    <select id="findPageList" resultType="com.jeeplus.business.humanResources.service.dto.StaffDimissionDTO">
        select distinct
            a.id,
            a.create_by_id,
            a.create_time,
            a.reason,
            a.status,
            a.dimission_date,
            a.proc_ins_id,
            a.process_definition_id,
            su.name as createName,
            so.name as officeName,
            sh.id as heirId,
            sh.status as heirStatus,
            sh.proc_ins_id as procInsIdHeir,
            sh.process_definition_id as procsDefIdHeir,
            art2.ID_ as taskIdHeir,
            art1.ID_ as task_id
        from
            staff_dimission a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_office so on su.office_id = so.id and so.del_flag = '0'
        LEFT JOIN act_ru_task art1 ON a.proc_ins_id = art1.PROC_INST_ID_
        left join staff_heir sh on a.id = sh.dimission_id and sh.del_flag = '0'
        LEFT JOIN act_ru_task art2 ON sh.proc_ins_id = art2.PROC_INST_ID_
         ${ew.customSqlSegment}
        ORDER BY a.update_time DESC
    </select>

    <select id="findById" resultType="com.jeeplus.business.humanResources.service.dto.StaffDimissionDTO">
        select
            a.id,
            a.create_by_id,
            a.create_time,
            a.reason,
            a.status,
            a.proc_ins_id,
            a.process_definition_id,
            a.dimission_date,
            su.name as createName,
            so.name as officeName,
            art1.ID_ as task_id
        from
            staff_dimission a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_office so on su.office_id = so.id and so.del_flag = '0'
        LEFT JOIN act_ru_task art1 ON a.proc_ins_id = art1.PROC_INST_ID_
        where a.id=#{id}
    </select>

    <update id="updateStatusById">
        update staff_dimission set status = #{status} where id=#{id}
    </update>


</mapper>