<?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.meetingRoom.mapper.MeetingRoomMapper">

    <select id="findPageList" resultType="com.jeeplus.business.meetingRoom.domain.MeetingRoom">
        select distinct
            a.id,
            a.create_by_id,
            su.name as createName,
            a.title,
            a.start_time,
            a.start_date,
            a.duration,
            a.remarks,
            a.create_time as createDate,
            concat(a.start_date,' ',a.start_time) as roomDateTime,
            (case when a.duration = '30' then concat(a.duration,'分钟')
            when a.duration in ('1','2','3') then concat(a.duration,'小时') else '' end) as longTime,
            (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 roomTypeName,
            a.status,
            so.id as officeId,
            so.name as officeName,
            a.proc_ins_id as procInsId ,
            a.process_definition_id as processDefinitionId,
            art.ID_ as task_id
        from
            jy_meeting_room 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
        left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
        left join sys_user_manage_office sumo on sumo.office_id = su.office_id
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>

    <select id="findById" resultType="com.jeeplus.business.meetingRoom.service.dto.MeetingRoomDTO">
        select
            a.id,
            a.create_by_id,
            su.name as createName,
            a.title,
            a.start_time,
            a.start_date,
            a.duration,
            a.remarks,
            a.create_time as createDate,
            a.status,
            so.id as officeId,
            so.name as officeName,
            a.proc_ins_id as procInsId ,
            a.process_definition_id as processDefinitionId,
            art.ID_ as task_id
        from
            jy_meeting_room 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
        left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
        where a.id=#{id}
    </select>

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

    <select id="checkTime" resultType="com.jeeplus.business.meetingRoom.domain.MeetingRoom">
        select
             a.id,
            a.create_by_id,
            su.name as createName,
            a.title,
            a.start_time,
            a.end_time,
            a.duration,
            a.remarks,
            a.create_time as createDate,
            a.status,
            so.id as officeId,
            so.name as officeName,
            a.proc_ins_id as procInsId ,
            a.process_definition_id as processDefinitionId,
            art.ID_ as task_id
        from
            jy_meeting_room 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
        left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
        where (a.start_date=#{date}) and a.del_flag =0 and  a.`status` not in ('1', '3','4')
        order by a.end_time DESC
    </select>

</mapper>