package com.ruoyi.cai.ws.job;

import com.ruoyi.cai.ws.bean.Room;
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 SettleJob {
    @Autowired
    private OnlineDataCache onlineDataCache;
    @Autowired
    private SettleService settleService;
    @Autowired
    private RoomService roomService;

    /**
     * 每 1 分钟执行一次
     */
//    @Scheduled(fixedDelay = 60,timeUnit = TimeUnit.SECONDS)
    public void run(){
        Set<String> all = onlineDataCache.getAll();
        for (String roomIdS : all) {
            try {
                Long roomId = Long.valueOf(roomIdS);
                settleService.processOn(roomId);
            }catch (Exception e){
                log.info("定时任务结算失败！",e);
            }
        }
    }
}
