package com.ics.quartz.task;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.ics.admin.domain.meeting.Reservation;
import com.ics.admin.service.meeting.IReservationService;
import com.ics.common.utils.device.WisDomDeviceUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service("meetingOpenStatusTask")
public class MeetingOpenStatusTask {

    @Autowired
    private  IReservationService iReservationService;


    public  void meetingOpen() {


        //获取当天所有预约的会议室
        List<Reservation> reservations = iReservationService.selectReservationListByDay();

        if (CollUtil.isNotEmpty(reservations)){
            for (Reservation reservation : reservations) {
                log.info("预约会议室信息111111111111："+reservation);
                Date date = new Date();

                Date next = DateUtil.offsetMinute(date, 10);
                String format = DateUtil.format(next, "HH:mm");
                Date startTime = reservation.getStartTime();
                String format1 = DateUtil.format(startTime, "HH:mm");
                log.info("时间为==============="+(format.equals(format1)));
                if (format.equals(format1)) {
                    log.info("结果为------------");
                    //大会议室
                    if (reservation.getRoomContentId() == 52L) {
                        Boolean aBoolean = WisDomDeviceUtils.shortControl("312", 1);
                        log.info("大会议室情景结果为："+ aBoolean);
                    } else if (reservation.getRoomContentId() == 53L) {//茶室
                        Boolean aBoolean = WisDomDeviceUtils.shortControl("286", 1);
                        log.info("茶室情景结果为："+aBoolean);
                    } else if (reservation.getRoomContentId() == 54L) { //小会议室
                        WisDomDeviceUtils.deviceControl("244", true);
                        WisDomDeviceUtils.deviceControl("245", true);
                        WisDomDeviceUtils.deviceControl("246", true);
                        log.info("小会议室情景结果为：");
                    }
                }
            }
        }

    }
}
