admin
2024-03-25 6729c925673fcf41cf12f6f1b59d1489a6031731
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.ruoyi.task;
 
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.ruoyi.aibrain.domain.AiCamera;
import com.ruoyi.common.config.RuoYiConfig;
 
import okhttp3.*;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.springframework.stereotype.Component;
 
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
 
/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("sjcsDlTask")
public class SjcsDlTask {
 
    //10秒执行一次
    public void indexDlTask() {
        DataAssembleUtil.AssembleCDSSSJ();//实时数据
        DataAssembleUtil.AssembleCDYCSJ();//异常数据
    }
 
    //5分钟执行一次
    public void indexCameraTask() {
        CameraAssembleUtil.cameraSatus();//实时状态
    }
 
    //执行一次
    public void indexCameraAiError() throws ParseException {
        CameraAssembleUtil.cameraAiError();//摄像头报警传输
    }
 
    //1分钟执行一次
    public void indexCameraAiReturn() {
        AiCamera aiCamera=new AiCamera();
        aiCamera.setCameraNum("1060101");
        //CameraAssembleUtil.cameraAiError(aiCamera);//模拟
    }
 
 
 
 
    public void fileCameraTask() throws UnirestException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException, IOException {
        //请求地址
        String url = "https://192.168.100.89:4200/spjr000/api/open/v1/ai/channel/general/push/";
 
        //String参数
        Map<String, String> params = new HashMap<String, String>();
        params.put("company", RuoYiConfig.getMkbm());//煤矿企业编码
        params.put("biz","1060101");//摄像头编码
        params.put("channel","0030001");//分析类型编码
        params.put("pdt","1705303253");//数据上报时间
        params.put("data","");//扩展参数
 
        System.out.println(1111);
 
        String boundary = "------WebKitFormBoundary7MA4YWxkTrZu0gW--"; // 设置boundary字符串,用于标识参数和附件的边界
 
        final TrustManager[] trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                    }
 
                    @Override
                    public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
                    }
 
                    @Override
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return new java.security.cert.X509Certificate[]{};
                    }
                }
        };
 
        final SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
        final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
 
 
        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0])
                .hostnameVerifier((hostname, session) -> true) // 信任所有主机名
                .build();
        File file = new File("D:\\AI\\aibrain\\upload\\2024\\01\\15\\2201810148791060101003000120240115152044.mp4");
 
 
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
 
                .addFormDataPart("company", params.get("company"))
                .addFormDataPart("biz", params.get("biz"))
                .addFormDataPart("channel", params.get("channel"))
                .addFormDataPart("pdt", params.get("pdt"))
                .addFormDataPart("data", params.get("data"))
 
                .addFormDataPart("file", "2201810148791060101003000120240115152044.mp4",
                        RequestBody.create(MediaType.parse("application/octet-stream"),
                                file))
                .build();
 
 
        Request request = new Request.Builder()
                .url(url)
                .header("Content-Type", "multipart/form-data; boundary=" + boundary)
                .post(body)
                .build();
        Response response = client.newCall(request).execute();
 
        if (response.isSuccessful()) {
            System.out.println("File uploaded successfully1111."+response.body().toString());
 
            System.out.println("File uploaded successfully."+response.toString());
        } else {
            System.out.println("Failed to upload file. Response code: " + response.code());
        }
 
    }
 
 
 
    public void fileCameraTaskls() throws UnirestException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException, FileNotFoundException {
        //请求地址
        String url = "https://192.168.100.89:4200/spjr000/api/open/v1/ai/channel/general/push/";
 
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                .build();
 
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        CloseableHttpClient httpclient = HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .build();
        Unirest.setHttpClient(httpclient);
 
        //String参数
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("company", RuoYiConfig.getMkbm());//煤矿企业编码
        params.put("biz","1060101");//摄像头编码
        params.put("channel","0030001");//分析类型编码
        params.put("pdt","1699529835");//数据上报时间
        params.put("data","");//扩展参数
        System.out.println(1111);
 
        String boundary = "------WebKitFormBoundary7MA4YWxkTrZu0gW--"; // 设置boundary
        File file = new File("D:\\AI\\aibrain\\upload\\2023\\11\\09\\2201810148791060101003000120231109161143.mp4");
 
/*        MultipartBodyRequestBuilder requestBuilder = Unirest.post(url)
                .header("Content-Type", "multipart/form-data; boundary=" + boundary)
                .body(MultipartBody.fromFile(file, "file"));*/
 
        HttpResponse<String> response = Unirest.post(url)
                .header("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)")
                .header("Accept", "*/*")
                .header("Host", "192.168.100.89:4200")
                .header("Connection", "keep-alive")
                .header("Content-Type", "multipart/form-data;boundary=" + boundary)
 
                //携带的参数
                .field("company", params.get("company"))
                .field("biz", params.get("biz"))
                .field("channel", params.get("channel"))
                .field("pdt", params.get("pdt"))
                .field("data", params.get("data"))
                .field("file",file)
                .asString();
        System.out.println(2222);
        System.out.println(response.getBody());
 
    }
 
 
}