liujie
2023-08-31 d6811336d546e4963a9af3bd7cd8654d14193bce
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
package com.stylefeng.guns.modular.system.utils.PortUtil;
 
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.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper;
 
import java.io.IOException;
 
public class LBCTStrategy implements WharfStrategy {
 
    private static final String url = "https://www.lbct.com/CargoSearch/GetMultiCargoSearchJson";
 
 
//    public static void main(String[] args) throws IOException {
//
//        // 假设您有一个JSON字符串
//        String jsonString = "{\"field1\":\"value1\",\"nestedObject\":{\"field2\":\"value2\"}}";
//
//// 创建ObjectMapper对象
//        ObjectMapper objectMapper = new ObjectMapper();
//
//// 将JSON字符串解析为JsonNode对象
//        JsonNode jsonNode = objectMapper.readTree(jsonString);
//
//// 获取嵌套对象中的字段值
//        String field2Value = jsonNode.get("nestedObject").get("field2").asText();
//
//        System.out.println(field2Value);
//
//
//    }
 
    public static void main(String[] args) {
        String us = url+ "?timestamp="+System.currentTimeMillis()+"&listOfSearchId="+"GCXU5491260";
        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", "?timestamp=" + System.currentTimeMillis() + "&listOfSearchId=" + "GCXU5491260")
                .execute();
        String body = execute.body();
        System.out.println(body);
    }
    @Override
    public TerminaleDataWarpper executeLogic(String... params) {
        String enums = "";
        if (params.length == 0) {
            throw new GunsException(BizExceptionEnum.REQUEST_EMPTY_ERROR);
        } else {
            enums = params[0];
        }
        String us = url+ "?timestamp="+System.currentTimeMillis()+"&listOfSearchId="+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", "?timestamp=" + System.currentTimeMillis() + "&listOfSearchId=" + enums)
                .execute();
        String body = execute.body();
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonArray = null;
        TerminaleDataWarpper warpper = new TerminaleDataWarpper();
        if (ToolUtil.isEmpty(body)){
            return warpper;
        }
        try {
            jsonArray = objectMapper.readTree(body);
            JsonNode jsonNode = jsonArray.get(0);
            String appointmentDateTimeLocal = jsonNode.get("gateAppt").asText();
            JSONObject jsonObject = JSONObject.parseObject(appointmentDateTimeLocal);
            Object o = jsonObject.get("IsTMF");
            if (o.equals("true")){
                warpper.setPierpass("hold");
            }
 
            Object location = jsonObject.get("location");
            if ("GROUNDED".equals(location)){
                warpper.setClosedArea(location.toString());
            }
            Object lfd = jsonObject.get("freeTimeExpiration");
            if (ToolUtil.isNotEmpty(lfd)){
                warpper.setLfd(lfd.toString());
            }
 
            Object available = jsonObject.get("available");
            if (ToolUtil.isNotEmpty(available)){
                warpper.setAvailability(available.toString());
            }
 
            ObjectMapper insMapp = new ObjectMapper();
            JsonNode gateAppt1 = insMapp.readTree(jsonObject.get("gateAppt").toString());
            String gkey = gateAppt1.get("Gkey").asText();
            if (ToolUtil.isNotEmpty(gkey)){
                warpper.setAppointmentNumber(gkey);
            }
 
            Object listOfFlag = jsonNode.get(0).get("listOfFlag");
            Gson gson = new Gson();
            JsonArray jsonElements = gson.fromJson(listOfFlag.toString(), JsonArray.class);
            for (JsonElement jsonElement : jsonElements) {
                String holdName = jsonElement.getAsJsonObject().get("holdName").getAsString();
                String type = jsonElement.getAsJsonObject().get("type").getAsString();
                switch (holdName){
                    case "CTF_CONTAINER_HOLD":
                            warpper.setCtf(type);
                        break;
                    case "CUSTOMS_DEFAULT_HOLD":
                            warpper.setCustomHold(type);
                        break;
                    case "FREIGHT_BL_HOLD":
                            warpper.setLineHold(type);
                        break;
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return warpper;
    }
}