package com.mosty.common.core.config;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 *  默认角色配置
 * @author kevin
 * @date 2022/2/21 1:12 PM
 * @since 1.0.0
 */
@Configuration
@Data
@Slf4j
public class DefaultRoleConfig {

    /** 默认角色列表 多个使用逗号间隔 */
    @Value("${default.role:12345}")
    private String defaultRole;

    public List<Long> getDefaultRoleList() {
        List<Long> defaultRoleList = Lists.newArrayList();
        if (StringUtils.isEmpty(defaultRole)) {
            return defaultRoleList;
        }
        String[] split = defaultRole.split(",");
        for (String roleId : split) {
            try {
                defaultRoleList.add(Long.parseLong(roleId));
            } catch (Exception e) {
                log.error("解析角色id异常", e);
            }
        }
        return defaultRoleList;
    }

}
