/*
package com.ruoyi.interfaces.snailJob;

import com.google.gson.Gson;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.interfaces.domain.vo.JobUserResponseVO;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;

import javax.json.JsonObject;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
public class AuthService {
    @Value("${snail-job.login.url}")
    private  String url;
    @Value("${snail-job.login.username}")
    private String username;
    @Value("${snail-job.login.password}")
    private String password;
    @Value("${snail-job.login.timeout}")
    private Integer timeout;

    public static final String AUTHENTICATION = "SNAIL-JOB-AUTH";
    public static final String NAMESPACE_ID = "SNAIL-JOB-NAMESPACE-ID";
    @Autowired
    private RedisCache redisCache;

    private static final String JOB_USER_KEY = "JOB_USER_KEY";

    public JobUserResponseVO authenticate() {

        String bodyPar = "{\n" +
                "  \"username\": \"" + username + "\",\n" +
                "  \"password\": \"" + password + "\"\n" +
                "}";
        String token = "";
        JobUserResponseVO response = new JobUserResponseVO();
        try {
            token = HttpUtils.sendBodyPostTest(url+"/auth/login", bodyPar, null);
            System.out.println(token);
            String data = new JSONObject(token).getString("data");
            System.out.println(data);
            Gson gson = new Gson();
            response = gson.fromJson(data, JobUserResponseVO.class);
            redisCache.setCacheObject(JOB_USER_KEY, response, timeout, TimeUnit.MINUTES);
        } catch (IOException | JSONException e) {
            throw new RuntimeException(e);
        }
        return response;
    }

    public JobUserResponseVO getJobUserResponse() {
        JobUserResponseVO jobUser = redisCache.getCacheObject(JOB_USER_KEY);
        if (StringUtils.isNull(jobUser)) {
            return authenticate();
        }
        return jobUser;
    }

    public String getUrl(){
        return url;
    }
    public HashMap<String, String> getHeaders(){
        HashMap<String, String> map = new HashMap<>();
        HttpServletRequest request = ServletUtils.getRequest();
        map.put(AUTHENTICATION,request.getHeader(AUTHENTICATION));
        map.put(NAMESPACE_ID,ServletUtils.getRequest().getHeader(NAMESPACE_ID));
        return map;
    }
}*/
