package com.ruoyi.cai.mq.consumer;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.cai.manager.UserForbidManager;
import com.ruoyi.cai.mq.dto.CommonDelayDto;
import com.ruoyi.cai.mq.CommonDelayMqConfig;
import com.ruoyi.cai.ws.job.CheckTimeOutJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CommonDelayMqConsumer {
    @Autowired
    private CheckTimeOutJob checkTimeOutJob;
    @Autowired
    private UserForbidManager userForbidManager;

    @RabbitListener(queues = CommonDelayMqConfig.QUEUE_NAME
            ,containerFactory = "customContainerFactory")
    public void checkTimeOutMq(String message) {
        log.info("CommonDelayMqConsumer: " + message);
        CommonDelayDto dto = JSON.parseObject(message, CommonDelayDto.class);
        switch (dto.getType()){
            case 1:
                checkTimeOutJob.deal(dto.getRoomId());
                break;
            case 2:
                userForbidManager.checkAll();
                break;
            default:
                break;
        }
    }
}
