lishouyi
2023-05-23 88c3ffe527c13ba2081df8fa9cc66cc726946424
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.stylefeng.guns.modular.system.utils;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 *   码头-车场-客户 运输状态 第三方接口获取数据 APM码头——Import Availability
 *
 * </p>
 *
 * @Author: lisy
 * @date: 2023-05-18 16:52
 * @Description:
 */
 
public class TerminalInterfaceAcquisitionUtil {
 
    //Sandbox Interface
    private static final String url  = "https://api-sandbox.apmterminals.com/import-availability";
 
    //Production Interface
    private static final String proUrl  = "https://api.apmterminals.com/import-availability";
    private static final String auth_url  = "https://api.apmterminals.com/oauth/client_credential/accesstoken";
 
    private static final String KEY  = "di3RgCcM9zlgb5BG1UiYSIxwYdmYUxTo";
    private static final String SECRET  = "AIJczPxBeocsEjtI";
    private static String bearerToken  = "5dDHq3LwPW3EYZ6rtPGK0zqWsRA5";
 
 
    /**
     *
     * @param containerId 容器id
     * @param enums 设施编码
     * @return
     */
    public static TerminaleDataWarpper getTerminalStatus(String containerId,String enums){
        String us = url+ "?assetId="+containerId+"&facilityCode="+enums;
        HttpResponse execute = HttpRequest.get(us).header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36")
                .header("cookie", "_ga=GA1.2.1226281326.1675309614; _gid=GA1.2.1467106222.1675309614; _ga=GA1.4.1226281326.1675309614; _gid=GA1.4.1467106222.1675309614; AWSALB=1bWqINVI+LJP87FTEXfEw1Ob1nkbr+I4baSbUGUmu5+/LdiqL9ic04Nj7F0Vz3rvharAG7a8dVe3MX6YMNEbUINVr++CCv/UBw6JeCRS0PcbRLxK7wVHb1lPT8Jl; AWSALBCORS=1bWqINVI+LJP87FTEXfEw1Ob1nkbr+I4baSbUGUmu5+/LdiqL9ic04Nj7F0Vz3rvharAG7a8dVe3MX6YMNEbUINVr++CCv/UBw6JeCRS0PcbRLxK7wVHb1lPT8Jl")
                .header("path", "?assetId=" + containerId + "&facilityCode=" + enums)
                .header("Authorization", "Bearer " + bearerToken)
                .execute();
        String body = execute.body();
        int status = execute.getStatus();
        if (status != 200){
            getAuth();
            getTerminalStatus(containerId,enums);
        }
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonArray = null;
        TerminaleDataWarpper warpper = new TerminaleDataWarpper();
        try {
            jsonArray = objectMapper.readTree(body);
            for (JsonNode jsonNode : jsonArray) {
                String appointmentDateTimeLocal = jsonNode.get("appointmentDateTimeLocal").asText();
                warpper.setLfd(appointmentDateTimeLocal);
                String appointmentNumber = jsonNode.get("containerId").asText();
                warpper.setAppointmentNumber(appointmentNumber);
                String containerHolds = jsonNode.get("containerHolds").asText();
                List<String> collect = new ArrayList<>();
                if (ToolUtil.isEmpty(containerHolds)){
                    return warpper;
                }
                if (containerHolds.contains(",")){
                    String[] split = containerHolds.split(",");
                    collect =  Arrays.stream(split).collect(Collectors.toList());
                    if (collect.contains("LINE")){
                        warpper.setLineHold(1);
                    }
                    if (collect.contains("TMF")){
                        warpper.setCustomHold(1);
                    }
                    if (collect.contains("PIER")){
                        warpper.setPierpass(1);
                    }
                    if (collect.contains("CTF")){
                        warpper.setCtf(1);
                    }
                    if (collect.contains("AREA")){
                        warpper.setClosedArea(1);
                    }
                }else {
                    if (containerHolds.equals("LINE")){
                        warpper.setLineHold(1);
                    }
                    if (containerHolds.equals("TMF")){
                        warpper.setCustomHold(1);
                    }
                    if (containerHolds.equals("PIER")){
                        warpper.setPierpass(1);
                    }
                    if (containerHolds.equals("CTF")){
                        warpper.setCtf(1);
                    }
                    if (containerHolds.equals("AREA")){
                        warpper.setClosedArea(1);
                    }
                }
            }
 
 
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return warpper;
    }
 
 
    public static void getAuth(){
        String us = auth_url+ "?grant_type=client_credentials";
        String body = HttpRequest.post(us)
                .form("client_id", KEY)
                .form("client_id", SECRET)
                .execute().body();
        JSONObject object = JSONObject.parseObject(body);
        Object o = object.get("access_token");
        if (ToolUtil.isNotEmpty(o)){
            bearerToken = (String) o;
        }
    }
 
 
}