XiaoRuby
2023-09-24 20956b0f05f81ca47cf6c3e8f9b3b426e9cfd035
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
package com.yuanchu.mom.Task;
 
 
import cn.hutool.http.HttpRequest;
import com.yuanchu.mom.utils.JsonUtil;
import com.yuanchu.mom.vo.Result;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * @Author 张宾
 * @Date 2023/9/19
 */
public class SyncOrder {
 
    private static final String TOKEN_URL = "http://192.168.18.16:9999/auth/oauth/token";
 
    private static final String GET_ORDER_MAIN_URL = "http://192.168.18.16:9999/order/otcService/getOrderInfoForHyxtMes";
 
    private static final String GET_ORDER_INNER_URL = "http://192.168.18.16:9999/order/otcService/getOrderLineForHyxtMes";
 
    private static final String GET_ATTACHMENT_BY_ORDERID = "http://192.168.18.16:9999/order/otcService/getAttachmentByOrderId/";
 
    private static final String DOWN_LOAD = "http://192.168.18.16:9999/order/otcService/download/";
 
    private static final String IFS_URL="http://192.168.20.47:8008/PurchService.ashx?contract=ZTKJ&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_POL_RECEIPT_STD&userId=mes_user&inAttr={\"ORDER_NO\":\"-2050314\"}";
 
    private static final Map<String, String> GET_TOKEN_HEADER = new HashMap<>(2);
 
    private static final Map<String, Object> USER_INFO = new HashMap<>(4);
 
    static {
        GET_TOKEN_HEADER.put("Authorization", "Basic cGlnOnBpZw==");
        GET_TOKEN_HEADER.put("Content-Type", "application/x-www-form-urlencoded");
 
 
        USER_INFO.put("username", "external_interface_hyxt_mes");
        USER_INFO.put("password", "uCc+u3iP83WhO2dAU+5HUkCgfINnKfrHXMT/lwI/1f0=");
        USER_INFO.put("scope", "server");
        USER_INFO.put("grant_type", "password");
    }
 
    private static String getToken() {
        String body = HttpRequest.post(TOKEN_URL)
                .headerMap(GET_TOKEN_HEADER, true)
                .form(USER_INFO)//表单内容
                .timeout(20000)//超时,毫秒
                .execute().body();
        return String.valueOf(JsonUtil.jsonToPojo(body, Map.class).get("access_token"));
    }
 
    public static List<Map<String, Object>> getMainOrder(String time) {
        Map<String, Object> orderCondition = new HashMap<String, Object>();
        orderCondition.put("selectTime", time);
        String result = HttpRequest.get(GET_ORDER_MAIN_URL)
                .header("Authorization", "Bearer " + getToken())
                .form(orderCondition)
                .execute().body();
        List<Map<String, Object>> list = JsonUtil.jsonToPojo(JsonUtil.jsonToString(JsonUtil.jsonToPojo(result, Result.class).getData()), List.class);
        return list.stream().filter(l -> Objects.equals(l.get("status"), "已下达")).collect(Collectors.toList());
    }
 
    public static List<Map<String, Object>> getInnerOrder(String time, String orderNo) {
        Map<String, Object> orderCondition = new HashMap<String, Object>();
        orderCondition.put("selectTime", time);
        orderCondition.put("orderNo", orderNo);
        String result = HttpRequest.get(GET_ORDER_INNER_URL)
                .header("Authorization", "Bearer " + getToken())
                .form(orderCondition)
                .execute().body();
        List<Map<String, Object>> list = JsonUtil.jsonToPojo(JsonUtil.jsonToString(JsonUtil.jsonToPojo(result, Result.class).getData()), List.class);
        return list;
    }
 
    public static List<Map<String, Object>> getAttachmentByOrderId(Integer orderId) {
        String result = HttpRequest.get(GET_ATTACHMENT_BY_ORDERID + orderId)
                .header("Authorization", "Bearer " + getToken())
                .execute().body();
        List<Map<String, Object>> list = JsonUtil.jsonToPojo(JsonUtil.jsonToString(JsonUtil.jsonToPojo(result, Result.class).getData()), List.class);
        return list;
    }
 
    public static String download(Integer id) {
        String result = HttpRequest.get(DOWN_LOAD + id)
                .header("Authorization", "Bearer " + getToken())
                .execute().body();
        return result;
    }
 
    /**
     * ifs
     * @return
     */
    public static List<Map<String, Object>>ifsInterfaces(){
        String result = HttpRequest.get(IFS_URL)
                .header("Authorization", "Bearer " + getToken())
                .execute().body();
        Map<String, Object>map=JsonUtil.jsonToPojo(result,Map.class);
        return JsonUtil.jsonToPojo(JsonUtil.jsonToString(map.get("LIST_INFO")),List.class);
    }
}