/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.usky.meeting.repository;


import com.usky.meeting.domain.MeetingInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
* @website https://el-admin.vip
* @author shiguangji
* @date 2021-03-15
**/
public interface MeetingInfoRepository extends JpaRepository<MeetingInfo, Long>, JpaSpecificationExecutor<MeetingInfo> {
//
//    @Query(value =
//            "SELECT " +
//                    " CONCAT(m.meeting_id,'') as meetingId," +
//                    " m.meeting_name as meetingName," +
//                    " r.room_name as roomName," +
//                    " d.`name` as deptName," +
//                    " m.meeting_describe as meetingDescribe," +
//                    " m.meeting_type as meetingType," +
//                    " u.`name` as initiatorUserName," +
//                    " m.approve_status as approveStatus," +
//                    " m.approve_suggest as approveSuggest," +
//                    " m.is_cancel as isCancel," +
//                    " date_format(a.approve_date,'%Y-%m-%d %H:%i:%s') as approveDate," +
//                    " act.task_id as taskId" +
//                    " FROM dm_meeting as m" +
//                    " left join dm_meeting_room as r on r.room_id = m.room_id" +
//                    " left join sys_dept as d on d.dept_id = m.dept_id" +
//                    " left join (select meeting_id,approve_result,MAX(approve_date) as approve_date from dm_meeting_approve GROUP BY meeting_id,approve_result) as a on m.meeting_id = a.meeting_id and a.approve_result = m.approve_status " +
//                    " left join dm_user as u on u.id = m.initiator_id" +
//                    " left join (" +
//                        " select max(CONVERT(t.ID_,SIGNED)) as task_id,t.ASSIGNEE_ as user_id,temp.meeting_id" +
//                        " from act_hi_taskinst as t" +
//                        " left join (" +
//                            " select PROC_INST_ID_,MAX(LONG_) as meeting_id" +
//                            " from act_hi_varinst" +
//                            " WHERE NAME_ = 'op_id'" +
//                            " GROUP BY PROC_INST_ID_" +
//                        " ) as temp on temp.PROC_INST_ID_ = t.PROC_INST_ID_" +
//                        " group by t.ASSIGNEE_,temp.meeting_id"+
//                    " ) as act on act.meeting_id = m.meeting_id" +
//                    " WHERE 1=1" +
//                    " and act.user_id = :dmUserId" +
//                    " and if(:meetingName != '',m.meeting_name like :meetingName,1=1)"+
//                    " and if(:roomName != '',r.room_name like :roomName,1=1)"+
//                    " and if(:deptId != '',m.dept_id = :deptId,1=1)"+
//                    " and if(:initUserName != '',u.`name` like :initUserName,1=1)"+
//                    " and if(:approveStatus != '',m.approve_status like :approveStatus,1=1)"+
//                    " and if(:startDate != '',a.approve_date >= :startDate,1=1)"+
//                    " and if(:endDate != '',a.approve_date <= :endDate,1=1)",
//            countQuery = "SELECT count(1) " +
//                    " FROM dm_meeting as m" +
//                    " left join dm_meeting_approve as a on m.meeting_id = a.meeting_id and a.approve_result = 0 " +
//                    " left join dm_user as u on u.id = m.initiator_id" +
//                    " left join (" +
//                        " select max(t.ID_) as task_id,t.ASSIGNEE_ as user_id,temp.meeting_id" +
//                        " from act_hi_taskinst as t" +
//                        " left join (" +
//                            " select PROC_INST_ID_,MAX(LONG_) as meeting_id" +
//                            " from act_hi_varinst" +
//                            " WHERE NAME_ = 'op_id'" +
//                            " GROUP BY PROC_INST_ID_" +
//                        " ) as temp on temp.PROC_INST_ID_ = t.PROC_INST_ID_" +
//                        " group by t.ASSIGNEE_,temp.meeting_id"+
//                    " ) as act on act.meeting_id = m.meeting_id" +
//                    " WHERE 1=1" +
//                    " and if(:dmUserId != null,act.user_id = :dmUserId,act.user_id = 'NULL')" +
//                    " and if(:meetingName != '',m.meeting_name like :meetingName,1=1)"+
//                    " and if(:roomName != '',r.room_name like :roomName,1=1)"+
//                    " and if(:deptId != '',m.dept_id = :deptId,1=1)"+
//                    " and if(:initUserName != '',u.`name` like :initUserName,1=1)"+
//                    " and if(:approveStatus != '',m.approve_status like :approveStatus,1=1)"+
//                    " and if(:startDate != '',a.approve_date >= :startDate,1=1)"+
//                    " and if(:endDate != '',a.approve_date <= :endDate,1=1)",
//            nativeQuery = true)
//    Page<Map<String,String>> findApproveDmMeetingList(@Param("dmUserId") String dmUserId,
//                                                      @Param("meetingName") String meetingName,
//                                                      @Param("roomName") String roomName,
//                                                      @Param("deptId") String deptId,
//                                                      @Param("initUserName") String initUserName,
//                                                      @Param("approveStatus") Long approveStatus,
//                                                      @Param("startDate") String startDate,
//                                                      @Param("endDate") String endDate,
//                                                      Pageable pageable);
//
//
//    /**
//     * 判断会议室是否被使用
//     * @param meetingId 会议
//     * @param searchDate 时间
//     * @param roomId 预约的会议室
//     * @return
//     */
//    @Query(value = "select" +
//            " concat(a.meeting_id,'') as meetingId," +
//            " a.meeting_name as meetingName," +
//            " a.meeting_type as meetingType,"+
//            " a.meeting_prop as meetingProp,"+
//            " d.`name` as deptName," +
//            " u.`name` as initiatorUserName," +
//            " a.meeting_describe as meetingDescribe," +
//            " a.plan_count as planCount," +
//            " a.actual_count as actualCount," +
//            " date_format(a.start_date,'%Y-%m-%d %H:%i:%s') as startDate," +
//            " date_format(a.end_date,'%Y-%m-%d %H:%i:%s') as endDate," +
//            " a.remark"+
//            " from dm_meeting as a" +
//            " left join sys_dept as d on d.dept_id = a.dept_id" +
//            " left join dm_user as u on u.id = a.initiator_id" +
//            " where if(:meetingId != '',a.meeting_id != :meetingId,1=1)" +
//            " and if(:roomId != '',a.room_id = :roomId,1=1)" +
//            " and :searchDate between a.start_date and a.end_date" +
//            " and a.is_cancel = 0",
//            nativeQuery = true)
//    List<Map<String,String>> checkDmRoomUsedMeeting(@Param("meetingId")Long meetingId,
//                                           @Param("searchDate") String searchDate,
//                                           @Param("roomId") Long roomId);
//


    /**
     * 判断预约时间是否与别的预约单冲突
     * @param roomId
     * @return
     */
    @Query(value = "select" +
            " a.meeting_id as meetingId," +
            " a.meeting_name as meetingName," +
            " a.room_id as roomId," +
            " a.meeting_describe as meetingDescribe," +
            " date_format(a.start_date,'%Y-%m-%d %H:%i:%s') as startDate," +
            " date_format(a.end_date,'%Y-%m-%d %H:%i:%s') as endDate" +
            " from meeting_info as a" +
            " where a.room_id = :roomId" +
            " and ((a.start_date <= :startDate and a.end_date >= :startDate and a.end_date != :startDate) or (a.start_date <= :endDate and a.end_date >= :endDate and a.start_date != :endDate))" +
            " and if(:meetingId != '',a.meeting_id != :meetingId,1=1)" +
            " and a.is_cancel = 0 and a.meeting_status != 2 and a.approve_status != 2",nativeQuery = true)
    List<Map<String,String>> checkDmRoomMeetingDate(@Param("roomId") Long roomId,
                                           @Param("startDate") String startDate,
                                           @Param("endDate") String endDate,
                                           @Param("meetingId") Long meetingId);
//
//
//    /**
//     * 议设备
//     * @param meetingId
//     * @param deviceId
//     */
//    @Modifying
//    @Query(value = "insert into dm_meeting_device (meeting_id,device_id) values (:meetingId,:deviceId)",nativeQuery = true)
//    void in添加会sertMeetingDevice(@Param("meetingId") Long meetingId, @Param("deviceId") Long deviceId);
//
//    /**
//     * 删除会议设备
//     * @param meetingId
//     */
//    @Modifying
//    @Query(value = "delete from dm_meeting_device where meeting_id = :meetingId",nativeQuery = true)
//    void delMeetingDevice(@Param("meetingId") Long meetingId);
//
//    /**
//     * 查询会议设备名称
//     * @param meetingId
//     */
//    @Query(value = "select GROUP_CONCAT(d.device_id) as deviceIds,GROUP_CONCAT(d.device_name) as deviceNames from dm_meeting_device as a " +
//            " left join dm_device as d on d.device_id = a.device_id " +
//            " where a.meeting_id = :meetingId group by a.meeting_id",nativeQuery = true)
//    Map<String,Object> selectMeetingDeviceNames(@Param("meetingId") Long meetingId);
//
//    /**
//     * 添加会议审批人
//     * @param meetingId
//     * @param userId
//     */
///*    @Modifying
//    @Query(value = "insert into dm_meeting_approve_user (meeting_id,dm_user_id) values (:meetingId,:userId)",nativeQuery = true)
//    void insertMeetingApproveUser(@Param("meetingId") Long meetingId, @Param("userId") Long userId);*/
//
//    /**
//     * 删除会议审批人
//     * @param meetingId
//     */
//    @Modifying
//    @Query(value = "delete from dm_meeting_approve_user where meeting_id = :meetingId",nativeQuery = true)
//    void delMeetingApproveUser(@Param("meetingId") Long meetingId);
//
//    /**
//     * 查询会议审批人名称
//     * @param meetingId
//     */
//    @Query(value = "select GROUP_CONCAT(u.`id`) as userIds,GROUP_CONCAT(u.`name`) as userNames from dm_meeting_approve_user as a " +
//            " left join dm_user as u on a.dm_user_id = u.`id` " +
//            " where a.meeting_id = :meetingId group by a.meeting_id",nativeQuery = true)
//    Map<String,Object> selectMeetingApproveUserNames(@Param("meetingId") Long meetingId);
//
//    /**
//     * 添加高层会议权限用户
//     * @param meetingId
//     * @param userId
//     */
//    @Modifying
//    @Query(value = "insert into dm_meeting_gc_user (meeting_id,dm_user_id) values (:meetingId,:userId)",nativeQuery = true)
//    void insertMeetingGcUser(@Param("meetingId") Long meetingId, @Param("userId") Long userId);
//
//    /**
//     * 删除高层会议权限用户
//     * @param meetingId
//     */
//    @Modifying
//    @Query(value = "delete from dm_meeting_gc_user where meeting_id = :meetingId",nativeQuery = true)
//    void delMeetingGcUser(@Param("meetingId") Long meetingId);
//
//    /**
//     * 删除会与参与人
//     * @param meetingId
//     */
//    @Modifying
//    @Query(value = "delete from dm_meeting_attendee where meeting_id = :meetingId",nativeQuery = true)
//    void delMeetingAttendee(@Param("meetingId") Long meetingId);
//
//    /**
//     * 查询高层会议名称
//     * @param meetingId
//     */
//    @Query(value = "select GROUP_CONCAT(u.`id`) as userIds,GROUP_CONCAT(u.`name`) as userNames from dm_meeting_gc_user as a " +
//            " left join dm_user as u on a.dm_user_id = u.`id` " +
//            " where a.meeting_id = :meetingId group by a.meeting_id",nativeQuery = true)
//    Map<String,Object> selectMeetingGcUserNames(@Param("meetingId") Long meetingId);
//
//    /**
//     * 查询参会人员名称
//     * @param meetingId
//     */
//    @Query(value = "select GROUP_CONCAT(u.`id`) as userIds,GROUP_CONCAT(u.`name`) as userNames" +
//            " from dm_meeting_attendee as a " +
//            " left join dm_user as u on a.user_id = u.`id` " +
//            " where a.meeting_id = :meetingId group by a.meeting_id",nativeQuery = true)
//    Map<String,Object> selectMeetingAttendeeUserNames(@Param("meetingId") Long meetingId);
//
//
//    /**
//     * 查询指定会议室三天内的预约
//     * @param roomId
//     * @return
//     */
//    @Query(value = "select " +
//            " CONCAT(m.meeting_id,'') as meetingId," +
//            " m.meeting_name as meetingName," +
//            " d.`name` as deptName," +
//            " m.meeting_describe as meetingDescribe," +
//            " m.meeting_type as meetingType," +
//            " u.`name` as initiatorUserName," +
//            " date_format(m.start_date,'%Y-%m-%d %H:%i:%s') as startDate," +
//            " date_format(m.end_date,'%Y-%m-%d %H:%i:%s') as endDate," +
//            " m.remark as remark" +
//            " from dm_meeting as m " +
//            " left join sys_dept as d on d.dept_id = m.dept_id" +
//            " left join dm_user as u on u.id = m.initiator_id" +
//            " where 1=1" +
//            " and m.room_id = :roomID" +
//            " and m.is_cancel = 0" +
//            " and m.start_date BETWEEN DATE_FORMAT(NOW(),'%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 3 DAY),'%Y-%m-%d')",nativeQuery = true)
//    List<Map<String,String>> selectRoomThreeDaysReserveList(@Param("roomID") Long roomId);

    /**
     * 查询会议室当天所有的会议预约记录
     * @param roomId
     * @return
     */
    @Query(value = "select * from meeting_info where TO_DAYS(start_date) = TO_DAYS(NOW()) and room_id = :roomId",nativeQuery = true)
    List<MeetingInfo> queryTodayMeetingByRoomId(@Param("roomId") Long roomId);

    /**
     * 查询会议室所有的会议预约记录
     * @param roomId
     * @return
     */
    @Query(value = "select * from meeting_info where room_id = :roomId",nativeQuery = true)
    List<MeetingInfo> queryAllMeetingByRoomId(@Param("roomId") Long roomId);

//
//
//    /**
//     * 更新会议状态为开始状态,同时更新关联的会议室状态为正在使用,最后一次使用时间为当前会议的结束时间
//     * @param updateDate 时间点
//     */
//    @Modifying
//    @Transactional
//    @Query(value =
//            " update" +
//                " dm_meeting as m," +
//                " dm_meeting_room as r" +
//            " set " +
//                " m.meeting_status = 1," +
//                " r.room_status = 1," +
//                " r.last_use_time = m.end_date" +
//            " where m.room_id = r.room_id" +
//            " and m.approve_status in (1,3)" +
//            " and m.is_cancel = 0" +
//            " and (r.room_status = 0 and (m.meeting_status = 1 or m.meeting_status = 0))" +
//            " and DATE_FORMAT(m.start_date,'%Y-%m-%d %H:%i') <= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i') and DATE_FORMAT(m.end_date,'%Y-%m-%d %H:%i') >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')",nativeQuery = true)
//    void updateMeetingStatusAsStart(@Param("updateDate") String updateDate);
//
//    /**
//     * 更新会议状态为结束状态,同时更新关联的会议室状态为未使用
//     * @param updateDate 时间点
//     */
//    @Modifying
//    @Transactional
//    @Query(value =
//            " update" +
//                    " dm_meeting as m," +
//                    " dm_meeting_room as r" +
//                    " set " +
//                    " m.meeting_status = 2," +
//                    " r.room_status = 0 " +
//                    " where m.room_id = r.room_id" +
//                    " and m.approve_status in (1,3)" +
//                    " and m.is_cancel = 0" +
//                    " and r.room_status = 1"+
//                    " and DATE_FORMAT(m.end_date,'%Y-%m-%d %H:%i') <= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')",nativeQuery = true)
//    void autoCloseMeetingAndRoom(@Param("updateDate") String updateDate);

    @Query(value = "select u.`user_id` as userId,u.`nick_name` as userName,u.sex AS sex,u.phonenumber AS phone,u.dept_id as dept," +
            " (CASE a.is_sign WHEN 0 THEN '否' WHEN 1 THEN '是' END) as isSign,(CASE a.sign_type WHEN 0 THEN '人工签到' WHEN 1 THEN '人脸签到' WHEN 2 THEN '二维码签到' END) as signType," +
            " a.sign_date as `date`,a.meeting_id as meetingId,m.approve_status as approveStatus,m.meeting_status as meetingStatus" +
            " from meeting_attendee as a " +
            " left join sys_user as u on a.user_id = u.user_id " +
            " left join meeting_info as m on m.meeting_id = a.meeting_id " +
            " where a.meeting_id = :meetingId and a.tenant_id = :tenantId",nativeQuery = true,countQuery = "select COUNT(DISTINCT a.id ) as subcount from meeting_attendee as a left join sys_user as u on a.user_id = u.user_id left join meeting_info as m on m.meeting_id = a.meeting_id where a.meeting_id = :meetingId")
    List<Map<String,Object>> meetingSignList(@Param("meetingId") Long meetingId,@Param("tenantId") Integer tenantId);
//
//    /**
//     * 查询已完成的会议（根据会议室id）
//     * @param roomId 会议室id
//     * @param meetingStatus 会议状态
//     * @return List<Map<String,String>>
//     */
//    @Query(value = "select " +
//            "CONCAT(m.meeting_id,'') as meetingId, " +
//            "m.meeting_name as meetingName, " +
//            "r.`room_name` as roomName, " +
//            "m.meeting_describe as meetingDescribe, " +
//            "m.meeting_type as meetingType," +
//            "u.`name` as initiatorUserName, " +
//            "date_format(m.start_date,'%Y-%m-%d %H:%i:%s') as startDate, " +
//            "date_format(m.end_date,'%Y-%m-%d %H:%i:%s') as endDate, " +
//            "m.remark as remark, " +
//            "(select count(*) from dm_meeting_attendee as ma where ma.meeting_id = m.meeting_id) as planCount," +
//            "(select count(*) from dm_meeting_attendee as ma where ma.meeting_id = m.meeting_id and ma.is_sign = 1) as actualCount " +
//            "from dm_meeting as m  left join dm_meeting_room as r on r.room_id = m.room_id left join dm_user as u on u.id = m.initiator_id " +
//            "where m.room_id = :roomId and m.meeting_status = :meetingStatus and is_cancel = 0 and approve_status = 1",nativeQuery = true)
//    List<Map<String,Object>> getDmMeeting(@Param("roomId") Long roomId,@Param("meetingStatus") Long meetingStatus,Pageable pageable);
//
//    @Query(value = "select count(DISTINCT m.meeting_id) from dm_meeting as m  left join dm_meeting_room as r on r.room_id = m.room_id left join dm_user as u on u.id = m.initiator_id " +
//            "where m.room_id = :roomId and m.meeting_status = :meetingStatus and is_cancel = 0 and approve_status = 1",nativeQuery = true)
//    Long getDmMeetingCount(@Param("roomId") Long roomId,@Param("meetingStatus") Long meetingStatus);
//
//
//    @Modifying
//    @Transactional
//    @Query(value = " update" +
//            " dm_meeting_attendee" +
//            " set is_sign = 1," +
//            " sign_date = NOW()," +
//            " sign_type = 0" +
//            " where user_id = :userId" +
//            " and meeting_id = :meetingId",nativeQuery = true)
//    void signOn(@Param("userId") String userId,@Param("meetingId") Long meetingId);
//
//    /**
//     * 查询会议设备名称
//     * @param taskId
//     */
//    @Query(value = "select * from dm_meeting where task_id = :taskId",nativeQuery = true)
//    DmMeetingDto getDmMeetingByTaskId(@Param("taskId") String taskId);
//
//    /**
//     * 获取所有未开始会议的会议id
//     */
//    @Query(value = "select m.meeting_id from dm_meeting as m where meeting_status!=2 and approve_status=1 and m.is_cancel = 0 and to_days(start_date) = to_days(now())",nativeQuery = true)
//    List<Object> getMeetingIdListByNotStarted();
//
//    /**
//     * 根据会议状态获取所有会议id
//     */
//    @Query(value = "select m.meeting_id from dm_meeting as m where meeting_status = :meetingStatus and approve_status=1 and m.is_cancel = 0 ",nativeQuery = true)
//    List<Long> getMeetingIdListByMeetingStatus(@Param("meetingStatus") Long meetingStatus);
//
//    /**
//     * 根据会有id更改会议状态
//     */
//    @Transactional
//    @Modifying
//    @Query(value = "update dm_meeting set meeting_status = :meetingStatus where meeting_id = :meetingId ",nativeQuery = true)
//    void updateMeetingStatus(@Param("meetingId") Long meetingId,@Param("meetingStatus") Long meetingStatus);
//
//    /**
//     * 根据会有id更改会议状态
//     */
//    @Transactional
//    @Modifying
//    @Query(value = "update dm_meeting_attendee set is_sign = :isSign,sign_date = :signInTime,sign_type = 1 where meeting_id = :meetingId and user_id = :userId ",nativeQuery = true)
//    void updateUserSignIn(@Param("isSign") Long isSign, @Param("signInTime") String signInTime,@Param("meetingId") Long meetingId,@Param("userId") String userId);
//
//    /**
//     * 根据会议id获取会议详情
//     */
//    @Query(value = "select " +
//            "m.meeting_id as meetingId," +
//            "m.meeting_name as meetingName," +
//            "m.meeting_describe as meetingDescribe," +
//            "m.meeting_mode as meetingMode," +
//            "m.start_date as startDate," +
//            "m.end_date as endDate," +
//            "mr.room_id as roomId," +
//            "mr.room_name as roomName," +
//            "ifnull(d.dmDeviceIdList,'') as dmDeviceIdList," +
//            "ifnull(d.dmDeviceNameList,'') as dmDeviceNameList," +
//            "ifnull(attendee.attendeeUserIdList,'') as attendeeUserIdList," +
//            "ifnull(attendee.attendeeUserNameList,'') as attendeeUserNameList," +
//            "ifnull(file.fileList,'') as fileList " +
//            "from " +
//            "dm_meeting AS m left join dm_meeting_room as mr on m.room_id = mr.room_id " +
//            "left join ( select md.meeting_id,GROUP_CONCAT(d.device_id) as dmDeviceIdList, GROUP_CONCAT(d.device_name) as dmDeviceNameList from dm_device as d left join dm_meeting_device as md on md.device_id = d.device_id group by md.meeting_id ) as d on d.meeting_id = m.meeting_id  " +
//            "left join ( select a.meeting_id,GROUP_CONCAT(a.user_id) as attendeeUserIdList, GROUP_CONCAT(u.`name`) as attendeeUserNameList from dm_meeting_attendee as a left join dm_user as u on a.user_id = u.id group by a.meeting_id ) as attendee on attendee.meeting_id = m.meeting_id " +
//            "left join ( select mf.meeting_id,CONCAT(\"[\",GROUP_CONCAT(CONCAT(ls.storage_id)),\"]\") as fileList from dm_meeting_file as mf left join tool_local_storage as ls on mf.storage_id = ls.storage_id where mf.meeting_id = :meetingId group by mf.meeting_id ) as file on file.meeting_id = m.meeting_id " +
//            "where m.meeting_id = :meetingId",nativeQuery = true)
//    Map<String,Object> getMeetingDetails(@Param("meetingId") Long meetingId);

    /**
     * 根据会议开始时间的年和月，查询出所有数据
     */
    @Query(value = "select * from meeting_info where (month(start_date) <= :month and month(end_date)>=:month) and (YEAR(start_date) <= :year and YEAR(end_date)>=:year) and (day(start_date) <= :day and day(end_date)>=:day) and room_id = :roomId and is_cancel = 0 and approve_status!=2 and tenant_id = :tenantId ORDER BY start_date ASC",nativeQuery = true)
    List<MeetingInfo> getDmMeetingByStartDatDay(@Param("roomId") Long roomId, @Param("year") Integer year, @Param("month") Integer month, @Param("day") Integer day, @Param("tenantId") Integer tenantId);

    /**
     * 根据会议开始时间的年和月，查询出所有数据
     */
    @Query(value = "select * from meeting_info where month(start_date) = :month and YEAR(start_date) = :year and room_id = :roomId and is_cancel = 0 and approve_status!=2 and tenant_id = :tenantId ORDER BY start_date ASC",nativeQuery = true)
    List<Map<String,Object>> getDmMeetingByStartDateYearAndMonth(@Param("roomId") Long roomId,@Param("year") Integer year, @Param("month") Integer month, @Param("tenantId") Integer tenantId);
//
//    /**
//     * 提供根据会议室和会议时间查询会议发起人信息
//     */
//    @Query(value = "select u.name,u.contacts,m.meeting_name as meetingName from dm_meeting as m left join dm_user as u on m.initiator_id = u.id where m.room_id = :roomId and m.start_date = :startDate and m.end_date = :endDate and m.is_cancel = 0",nativeQuery = true)
//    Map<String,Object> getInitiator(@Param("roomId") Long roomId,@Param("startDate") String startDate,@Param("endDate") String endDate);
//
//    /**
//     * 根据会议查询未签到的签到信息
//     */
//    @Query(value = "select user_id as userId from dm_meeting_attendee where meeting_id = :meetingId and is_sign = 0 ",nativeQuery = true)
//    List<String> getUserSignIn(@Param("meetingId") Long meetingId);
//
//    /**
//     * 根据会议室id删除对应所有会议
//     */
//    @Transactional
//    @Modifying
//    @Query(value = "DELETE FROM dm_meeting WHERE room_id = :roomId",nativeQuery = true)
//    void deleteByRoomId(@Param("roomId")Long roomId);
//
//    /**
//     * 新增参会人
//     */
//    @Transactional
//    @Modifying
//    @Query(value = "insert into dm_meeting_attendee (meeting_id, user_id) values (:meetingId,:userId) ",nativeQuery = true)
//    void createMeetingAttendee(@Param("meetingId") Long meetingId, @Param("userId") String userId);

    @Query(value = "select count(a.meeting_id) as total,if(ISNULL(sum(if(a.meeting_status=0,1,0))),0,sum(if(a.meeting_status=0,1,0))) as notStarted,if(ISNULL(sum(if(a.meeting_status=1,1,0))),0,sum(if(a.meeting_status=1,1,0))) as haveInHand,if(ISNULL(sum(if(a.meeting_status=2,1,0))),0,sum(if(a.meeting_status=2,1,0))) as `end` from meeting_info as a where a.tenant_id=:tenantId and to_days(a.start_date) = to_days(now()) and a.approve_status=1 and is_cancel != 1" ,nativeQuery = true)
    Map<String,Object> meetingSummary(@Param("tenantId") Integer tenantId);

    @Query(value = "select sum(MONTH(start_date)=1) as one,sum(MONTH(start_date)=2) as two,sum(MONTH(start_date)=3) as three,sum(MONTH(start_date)=4) as four,sum(MONTH(start_date)=5) as five,sum(MONTH(start_date)=6) as six,sum(MONTH(start_date)=7) as seven,sum(MONTH(start_date)=8) as eight,sum(MONTH(start_date)=9) as nine,sum(MONTH(start_date)=10) as ten,sum(MONTH(start_date)=11) as eleven,sum(MONTH(start_date)=12) as twelve from meeting_info where tenant_id=:tenantId and YEAR(start_date)=:year and approve_status=1 and is_cancel != 1" ,nativeQuery = true)
    Map<String,Object> meetingSummaryByYear(@Param("year") String year,@Param("tenantId") Integer tenantId);

    @Query(value = "select meeting_id as meetingId from meeting_attendee where user_id = :userId" , nativeQuery = true)
    List<BigInteger> queryMeetingIdsByUserId(@Param("userId") Long userId);

    @Query(value = "select meeting_id as meetingId from meeting_info where initiator_id  = :initiatorId" , nativeQuery = true)
    List<BigInteger> queryMeetingIdsByInitiatorId(@Param("initiatorId") Long initiatorId);
}