<?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.holiday.mapper.HolidayMapper">

    <select id="findPageList" resultType="com.jeeplus.business.holiday.service.dto.HolidayDTO">
        select distinct
            a.id,
            a.create_by_id,
            a.create_time,
            a.start_day,
            a.begin_time,
            a.end_day,
            a.end_time,
            a.days,
            a.type,
            a.proc_ins_id,
            a.process_definition_id,
            (select dv.label from sys_dict_value dv LEFT JOIN sys_dict_type dt on dt.id=dv.dict_type_id where dv.value=a.status and dt.type='program_project_list_info_status') as driveApplyStatus,
            (select dv.label from sys_dict_value dv LEFT JOIN sys_dict_type dt on dt.id=dv.dict_type_id where dv.value=a.type and dt.type='jy_holiday_type') as holidayType,
            concat(a.days,'天') as holidayDays,
            a.status,
            art1.ID_ as task_id,
            su.name as createName,
            so.name as officeName
        from jy_holiday 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 sys_user_manage_office sumo on sumo.office_id = su.office_id
         ${ew.customSqlSegment}
        ORDER BY a.update_time DESC
    </select>

    <select id="findById" resultType="com.jeeplus.business.holiday.service.dto.HolidayDTO">
        select
            a.id,
            a.create_by_id,
            a.create_time,
            a.start_day,
            a.begin_time,
            a.end_day,
            a.end_time,
            a.days,
            a.type,
            a.proc_ins_id,
            a.process_definition_id,
            a.status,
            a.reason,
            art1.ID_ as task_id,
            su.name as createName,
            so.name as officeName
        from jy_holiday 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="findByUserId" resultType="com.jeeplus.business.holiday.service.dto.HolidayDTO">
        select
            in_time,
            user_id
        from staff_user_info
        where user_id = #{id} and del_flag = '0'
    </select>

    <select id="selectByUserId" resultType="com.jeeplus.business.holiday.service.dto.HolidayDTO">
        select
            a.id,
            a.create_by_id,
            a.create_time,
            a.start_day,
            a.begin_time,
            a.end_day,
            a.end_time,
            a.days,
            a.type,
            a.proc_ins_id,
            a.process_definition_id,
            a.status,
            a.reason,
            art1.ID_ as task_id,
            su.name as createName,
            so.name as officeName
        from jy_holiday 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.create_by_id = #{id} and a.type = '1' and YEAR(a.create_time) = YEAR(CURDATE()) and a.del_flag = '0' and a.status = '5'
    </select>

    <update id="updateStatusById">
        update jy_holiday set status = #{status} where id =#{id}
    </update>
    <update id="updateByIdForApp">
        update jy_holiday
        set
        update_by_id = #{holiday.updateById},
        update_time = #{holiday.updateTime},
        start_day = #{holiday.startDay},
        begin_time = #{holiday.beginTime},
        end_day = #{holiday.endDay},
        end_time = #{holiday.endTime},
        days = #{holiday.days},
        type = #{holiday.type},
        reason = #{holiday.reason},
        status = #{holiday.status}
         WHERE id = #{holiday.id}
    </update>

</mapper>