package com.cf.imes.module.executor.dal.redis.listener;

import com.cf.imes.framework.mq.redis.core.pubsub.AbstractRedisSimpleMessageListener;
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
import com.cf.imes.framework.security.core.service.SecurityFrameworkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.stereotype.Component;

/**
 * executor PERMISSION_REFRESH redis监听器
 *
 * @author Gqr
 * @since 2024/6/13 10:32
 */
@Component
@Slf4j
public class ExecutorPermissionRefreshRedisListener extends AbstractRedisSimpleMessageListener {

    private final SecurityFrameworkService securityFrameworkService;

    public ExecutorPermissionRefreshRedisListener(SecurityFrameworkService securityFrameworkService) {
        super.setTopic(new ChannelTopic(RedisKeyConstants.PERMISSION_REFRESH));
        this.securityFrameworkService = securityFrameworkService;
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        log.info("[SystemPermissionRefreshRedisListener][onMessage][{}收到刷新本地权限缓存]", message);
        securityFrameworkService.invalidateAllPermissionsCache();
    }
}
