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

    <select id="findPageList" resultType="com.jeeplus.business.humanResources.service.dto.StaffUserInfoDTO">
        select distinct
            a.id,
            a.create_by_id,
            a.create_time,
            a.name,
            a.sex,
            a.age,
            a.birthday,
            a.political_outlook,
            a.native_place,
            a.nation,
            a.marital_status,
            a.mobile_phone,
            a.id_card,
            a.home_address,
            a.permanent_address,
            a.graduated_from,
            a.speciality,
            a.start_time,
            a.end_time,
            a.education,
            a.education_nature,
            a.graduated_or_not,
            a.english_level,
            a.ncre,
            a.department,
            (select name from sys_office where id = a.department) as departmentName,
            a.in_time,
            a.proc_ins_id,
            a.process_definition_id,
            a.user_id,
            a.on_job_status,
            a.role_id,
            a.post_id,
            a.bank_number,
            a.email,
            a.type,
            a.fund_number,
            (case when su1.login_flag = '0' then '冻结' when su1.login_flag = '1' then '正常' else '' end) as flagName,
            a.manager_office,
            so1.name as officeName,
            su.name as createName,
            su1.login_flag,
            (select group_concat(name) from sys_role sr where FIND_IN_SET(sr.id,(select role_id from staff_user_info where id=a.id))) as roleName,
            art1.ID_ as task_id,
            ra.id as applyId,
            ra.proc_ins_id as procInsIdApply,
            ra.process_definition_id as procDefIdApply,
            ra.status as applyStatus,
            art2.ID_ as task_id_apply
        from staff_user_info 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 sys_user su1 on a.user_id = su1.id and su1.del_flag = '0'
        left join sys_office so1 on su1.office_id = so1.id and so1.del_flag = '0'
        left join jy_regular_apply ra on ra.info_id = a.id and ra.del_flag = '0'
        LEFT JOIN act_ru_task art1 ON a.proc_ins_id = art1.PROC_INST_ID_
        LEFT JOIN act_ru_task art2 ON ra.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.StaffUserInfoDTO">
        select
            a.id,
            a.create_by_id,
            a.create_time,
            a.name,
            a.sex,
            a.age,
            a.birthday,
            a.political_outlook,
            a.native_place,
            a.nation,
            a.marital_status,
            a.mobile_phone,
            a.id_card,
            a.home_address,
            a.permanent_address,
            a.graduated_from,
            a.speciality,
            a.start_time,
            a.end_time,
            a.education,
            a.education_nature,
            a.graduated_or_not,
            a.english_level,
            a.ncre,
            a.department,
            a.in_time,
            a.proc_ins_id,
            a.process_definition_id,
            a.user_id,
            a.on_job_status,
            a.role_id,
            a.post_id,
            a.bank_number,
            a.email,
            a.type,
            a.remarks,
            a.time_limit,
            a.fund_number,
            a.manager_office,
            so.name as officeName,
            su.name as createName,
            su.login_flag,
            art1.ID_ as task_id
        from staff_user_info 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>

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

    <update id="updatestatusById">
        update staff_user_info set type = #{type} where id=#{id}
    </update>

    <select id="findByApplyId" resultType="com.jeeplus.business.humanResources.domain.RegularApply">
        select
            a.id,
            a.create_by_id,
            a.create_time,
            a.proc_ins_id,
            a.process_definition_id,
            a.info_id,
            a.is_pass,
            a.is_employ,
            a.is_postpone,
            a.status,
            a.reason,
            su.name as createName,
            so.name as officeName
        from jy_regular_apply a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_office so on so.id = su.office_id and so.del_flag = '0'
        where a.id = #{id}
    </select>

    <update id="updateStatusByApplyId">
        update jy_regular_apply set status = #{status} where id=#{id}
    </update>

    <select id="getList" resultType="com.jeeplus.business.humanResources.service.dto.StaffUserInfoDTO">
    select
            a.id,
            a.create_by_id,
            a.create_time,
            a.name,
            a.sex,
            a.age,
            a.birthday,
            a.political_outlook,
            a.native_place,
            a.nation,
            a.marital_status,
            a.mobile_phone,
            a.id_card,
            a.home_address,
            a.permanent_address,
            a.graduated_from,
            a.speciality,
            a.start_time,
            a.end_time,
            a.education,
            a.education_nature,
            a.graduated_or_not,
            a.english_level,
            a.ncre,
            a.department,
            (select name from sys_office where id = a.department) as departmentName,
            a.in_time,
            a.proc_ins_id,
            a.process_definition_id,
            a.user_id,
            a.on_job_status,
            a.role_id,
            a.post_id,
            a.bank_number,
            a.email,
            a.type,
            a.fund_number,
            a.time_limit,
            (case when su1.login_flag = '0' then '冻结' when su1.login_flag = '1' then '正常' else '' end) as flagName,
            a.manager_office,
            so.name as officeName,
            su.name as createName,
            su1.login_flag,
            (select group_concat(name) from sys_role sr where FIND_IN_SET(sr.id,(select role_id from staff_user_info where id=a.id))) as roleName,
            art1.ID_ as task_id,
            ra.id as applyId,
            ra.proc_ins_id as procInsIdApply,
            ra.process_definition_id as procDefIdApply,
            ra.status as applyStatus,
            art2.ID_ as task_id_apply
        from staff_user_info 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 sys_user su1 on a.user_id = su1.id and su1.del_flag = '0'
        left join jy_regular_apply ra on ra.info_id = a.id and ra.del_flag = '0'
        LEFT JOIN act_ru_task art1 ON a.proc_ins_id = art1.PROC_INST_ID_
        LEFT JOIN act_ru_task art2 ON ra.proc_ins_id = art2.PROC_INST_ID_
    where a.on_job_status = '1'
    </select>



</mapper>