import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.util.HttpUtils;
import org.junit.jupiter.api.Test;

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 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 authorization = HttpUtil.createGet("https://proj.bim-ace.com:10128/api/Export/GetProjectOverview?ProjectId=372FF2E0-0286-4BD6-AC71-17731D38C2A7").header("Authorization", "Bearer " + access_token).execute();
        System.out.println(authorization.body());
    }
}