import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.util.HttpUtils;
import com.shanghaigeography.entity.ResultMsg;
import com.shanghaigeography.eum.ResultState;
import com.shcd.enums.GhjgPortThreeUrl;
import com.shcd.utils.secret.Encodes;
import org.checkerframework.checker.units.qual.C;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;

import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.HashMap;

public class test {

    @Test
    public void test() {
        HttpResponse execute = HttpUtil.createPost("https://login.bim-ace.com/connect/token").setFollowRedirects(true).form("grant_type", "client_credentials").form("client_id", "34cd20d8489f453d9a9671f1099d53f4").
                form("client_secret", "43f111ec3451405c97b914450a91a18c").form("scope", "HPJV2").timeout(30000).execute();
        HashMap hashMap = JSONObject.parseObject(execute.body(), HashMap.class);
        String access_token = hashMap.get("access_token").toString();
        HttpResponse workTrace = HttpUtil.createGet("https://proj.bim-ace.com:10128/api/Export/GetWorkOrderShipHistoryList" + "?TransportCode=" + "HANGJIE1201" + "&WorkOrderCode=" + "20230715124252-6-0004-A").
                header("Authorization", "Bearer " + access_token).setFollowRedirects(true).timeout(30000).execute();
        HashMap workTraceInfo = JSONObject.parseObject(workTrace.body(), HashMap.class);
        System.out.println(workTraceInfo.get("Data"));
    }


    @Test
    public void test2() {
        HttpResponse execute = HttpUtil.createPost("http://127.0.0.1:8090/dredging/token/getToken").timeout(3000).execute();
        if (Boolean.parseBoolean(execute.body())) {
            HashMap<String, String> map = new HashMap<>();
            map.put("ProjectId","1FAF5519-C64E-4414-A616-2CE989C7560B");
            String s = JSONObject.toJSONString(map);
            HttpResponse projectId = HttpUtil.createPost("http://127.0.0.1:8090/dredging/projectOverview/GetProjectOverview").body(s).timeout(30000).execute();
            HashMap map1 = JSONObject.parseObject(projectId.body(), HashMap.class);
            System.out.println(map1);

            HttpResponse ele = HttpUtil.createPost("http://127.0.0.1:8090/dredging/elecfence/GetElectronicFence").body(s).timeout(30000).execute();
            System.out.println(ele.body());

            HttpResponse workorder = HttpUtil.createPost("http://127.0.0.1:8090/dredging/workOrder/GetWorkOrderList").body(s).timeout(30000).execute();
            System.out.println(workorder.body());


        }
    }


    @Test
    public void test3(){
        HttpResponse authorization = HttpUtil.createGet("https://proj.bim-ace.com:10128/api/Export/GetWorkOrderList?ProjectId=1FAF5519-C64E-4414-A616-2CE989C7560B").header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImJYakhzVnhfc1UyOXVldkM2dmF2eGciLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE2OTI5MzYwMzcsImV4cCI6MTY5MzU0MDgzNywiaXNzIjoiaHR0cHM6Ly9sb2dpbi5iaW0tYWNlLmNvbSIsImF1ZCI6IkhQSlYyIiwiY2xpZW50X2lkIjoiMzRjZDIwZDg0ODlmNDUzZDlhOTY3MWYxMDk5ZDUzZjQiLCJzY29wZSI6WyJIUEpWMiJdfQ.b3k7bhRhp0lzhkt2eh8qMC9ze0MISv60hR4jkelUCzL3FYn-I9QWCvtKXN0ixajKkO_GWjsZ-paxLoJ7ff6SA254VcGPBPjelteNYw8ZJqCMPfTmAkt9aZLQErTFItxa6ZWoGV2x5iywo0ar9Yab5OSDoAauwABaGyD97lNFra3Oiceza4KJRVMWDvsm5eMSZJj_-XdQW9g2I6gyzElAWYl--H85QwBoi9PZXXIpjuoK7Ee2Y4Ha7hxmAuzxrVZtly91gFDsm5fUdK_JWEMbYqC8IGFWp1o7fQ1tEF0H7qqja_0_oFTFZRs-xjcynsaz9l82pNEsC2iS__EOFn_W9A").execute();
        System.out.println(authorization.body());

    }


    @Test
    public void test4(){
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.YEAR);
        int i1 = instance.get(Calendar.MONTH);
        System.out.println(i + "-" + i1);
    }

    String shorePower = "http://106.15.62.234:6060/shorepower/v1/query_token";
    @Test
    public void test5(){
        String result = null;
        String token = null;
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("Sig", "59962D299728C732F772AD9CDE6A9456");
            jsonObject.put("PlatformID", "425009768");
            jsonObject.put("Data","/J9njgV+VvzgibMjaU4c0HH+Zbr9n5DRkJkfxLy0Z8agH7kzqKIbtm97MilBq0XaMbHfhxW+Vwd/JqfFVnvSbA==");
            jsonObject.put("TimeStamp", "16880151424323");
            jsonObject.put("Seq", "0001");
//            result = HttpUtil.createPost("http://106.15.62.234:6060/shorepower/v1/query_token")
            result = HttpUtil.createPost(shorePower)
                    .setConnectionTimeout(3600000)
                    .setReadTimeout(3600000)
                    .header("Content-Type", "application/json")
                    .body(jsonObject.toString())
                    .charset("UTF-8").execute().body();
            JSONObject resultJsonObject = JSONObject.parseObject(result);
            String returnData = (String) resultJsonObject.get("Data");
            token = new String(Encodes.aesDecrypt(
                    Encodes.decodeBase64(returnData),
                    GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes(),
                    GhjgPortThreeUrl.TOKEN_KEY.getUrl().getBytes()), StandardCharsets.UTF_8);
            System.out.println("成功 token："+token);
        } catch (Exception e) {
            System.out.println("异常："+e.getMessage());
        }

    }
}