package com.ruoyi.cai.ws.job;

import com.ruoyi.cai.ws.cache.OnlineDataCache;
import com.ruoyi.cai.ws.service.RoomService;
import com.ruoyi.cai.ws.service.SettleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class RoomCheckJob {
    @Autowired
    private OnlineDataCache onlineDataCache;
    @Autowired
    private RoomCheckJobService roomCheckJobService;

    /**
     * 每 7分钟执行一次
     */
    @Scheduled(fixedDelay = 7,timeUnit = TimeUnit.MINUTES)
    public void run(){
        Set<String> all = onlineDataCache.getAll();
        for (String roomIdS : all) {
            try {
                Long roomId = Long.valueOf(roomIdS);
                roomCheckJobService.checkRoom(roomId);
            }catch (Exception e){
                log.info("定时检测房间失败！需要开发排查问题 roomId={}", roomIdS, e);
            }
        }
    }
}
