package com.ruoyi.common.utils.bpm;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.config.bpm.BpmProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author hmc
 * @date 2023-11-02 15:29
 * @Description:
 */
@Component
public class BpmUtils {

    @Autowired
    private BpmProperties bpmProperties;

    /**
     * 根据用户查询角色key
     *
     * @param userId
     * @return
     */
    public String[] getRoleKeyByUserId(Long userId) {
        RestTemplate restTemplate = new RestTemplate();
        String ret = restTemplate.getForObject(bpmProperties.mainRolesKeyIp + userId, String.class);
        JSONObject jsonObject = JSONObject.parseObject(ret);
        String s = (String) jsonObject.get("rolesKey");
        String[] strings = JSONObject.parseObject(s, String[].class);
        return strings;
    }
}
