package com.sky.ioc.mapper.meeting;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.meeting.MeetingRecord;
import com.sky.ioc.entity.params.IocParam;
import com.sky.ioc.entity.params.IocTimeRange;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MeetingRecordMapper extends BaseMapper<MeetingRecord> {


    @Select("<script> " +
            "SELECT * FROM meeting_record  where 1=1 " +
            "<if test='startTime!=null  '>" +
            "<![CDATA[ and start_time >= #{startTime} " +
            " AND end_time <= #{endTime} ]]> " +
            "</if>" +
            "<if test='roomId!=null '>" +
            " and room_id = #{roomId} " +
            "</if>" +
            " order by end_time desc </script>")
    List<MeetingRecord> getListByTimeAndRoomId(@Param("startTime") String startTime,
                                               @Param("endTime") String endTime,
                                               @Param("roomId") Integer roomId);


    @Select("<script> " +
            "SELECT count(1) FROM meeting_record  where 1=1 " +
            "<if test='timeRange!=null and timeRange.startDate!=null  '>" +
            "<![CDATA[ and start_time >= #{timeRange.startDate} " +
            " AND end_time <= #{timeRange.endDate} ]]> " +
            "</if>" +
            "</script>")
    Long  countByTime(@Param("timeRange") IocTimeRange timeRange);
    @Select("<script> " +
            "SELECT coalesce(sum(person_num),0) FROM meeting_record  where 1=1 " +
            "<if test='timeRange!=null and timeRange.startDate!=null  '>" +
            "<![CDATA[ and start_time >= #{timeRange.startDate} " +
            " AND end_time <= #{timeRange.endDate} ]]> " +
            "</if>" +
            " </script>")
    Long  totalPersonByTime(@Param("timeRange") IocTimeRange timeRange);

    @Select("<script> " +
            "SELECT coalesce(sum(minutes),0) FROM meeting_record  where 1=1 " +
            "<if test='timeRange!=null and timeRange.startDate!=null  '>" +
            "<![CDATA[ and start_time >= #{timeRange.startDate} " +
            " AND end_time <= #{timeRange.endDate} ]]> " +
            "</if>" +
            " </script>")
    Long  totalMinutesByTime(@Param("timeRange") IocTimeRange timeRange);
}
