zhanghua
2025-03-04 b8d8733ad9eeeb170a71897d1078acdbea7680f2
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package com.ycl.sccgplatform;
 
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dahua.netsdk.lib.callback.impl.AnalyzerDataCB;
import com.ycl.common.util.UtilNumber;
import com.ycl.entity.dingding.DingUserInfo;
import com.ycl.entity.user.UmsAdmin;
import com.ycl.mapper.unlawful.UnlawfulMapper;
import com.ycl.service.caseHandler.IBaseCaseService;
import com.ycl.service.caseHandler.IViolationsService;
import com.ycl.service.oss.OssService;
import com.ycl.utils.ConstantPropertiesUtils;
import com.ycl.vo.casePool.BaseCaseVO;
import net.coobird.thumbnailator.Thumbnails;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
 
import javax.annotation.Resource;
import javax.xml.bind.DatatypeConverter;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
@ComponentScan("com.dahua.netsdk")
@SpringBootTest
public class Test1 {
 
    @Autowired
    private IBaseCaseService baseCaseService;
 
    @Autowired
    private OssService ossService;
 
    @Autowired
    private IViolationsService violationsService;
 
    @Resource
    private UnlawfulMapper unlawfuldao;
    @Autowired
    UtilNumber utilNumber;
 
    @Test
    void test() {
        String fileUrl = "https://xshlivelesson.oss-cn-shenzhen.aliyuncs.com/2.pptx?Expires=1738857178&OSSAccessKeyId=LTAIxtcfDe3fgfcf&Signature=wTwx6JA6VWbPB0skVySy9MCexog=";
        // http://zhzfptoss.oss-cn-zjls-lszwy-d01-a.ops.zjlscloud.com/sczf/2023062950465224.jpg?Expires=2634106907&OSSAccessKeyId=Tkf72Q1gdzETsZf6&Signature=ttME%2BeFhss8wPbkRCxAsV%2FPNWGQ%3D
 
        OSS ossClient = null;
        try {
 
            String endpoint = "https://oss-cn-beijing.aliyuncs.com";
            String accessKeyId = "LTAIxtcfDe3fgfcf";
            String accessKeySecret = "xHxLVU5dm7USdJuQaCfp1hpcUU1u8v";
            String bucketName = "huachuang-resource";
 
            String[] urlArray = fileUrl.split("Expires=");
 
            String objectName = urlArray[0].replace(ConstantPropertiesUtils.PREFIX_URL, "");
            objectName = objectName.replace("?", "");
 
            ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
 
 
            // 设置签名URL过期时间,单位为毫秒。本示例以设置过期时间为1小时为例。
            Date expiration = new Date(new Date().getTime() + 3600 * 1000L);
            // 生成以GET方法访问的签名URL。本示例没有额外请求头,其他人可以直接通过浏览器访问相关内容。
            URL url = ossClient.generatePresignedUrl(bucketName, objectName, expiration);
            System.out.println(url);
 
//
//        // http://zhzfptoss.oss-cn-zjls-lszwy-d01-a.ops.zjlscloud.com/sczf/2025020620664017jpg?v=2684887407&OSSAccessKeyId=Tkf72Q1gdzETsZf6&Signature=88dn7R/gDdqxWUCqZdCi/NgSXg8=
//        OSS ossClient = null;
//        try {
//            // 以华东1(杭州)的外网Endpoint为例,其它Region请按实际情况填写。
//            String endpoint = "https://oss-cn-beijing.aliyuncs.com";
//            // 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
////            EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
//            // 填写Bucket名称,例如examplebucket。
//            String bucketName = "huachuang-resource";
//            // 填写Object完整路径,例如exampleobject.txt。Object完整路径中不能包含Bucket名称。
//            String objectName = "家庭教育/中国陶行知协会家庭教育专委会.doc";
//            // 填写Bucket所在地域。以华东1(杭州)为例,Region填写为cn-hangzhou。
//            String region = "cn-beijing";
//            String accessKeyId = "LTAIxtcfDe3fgfcf";
//            String accessKeySecret = "xHxLVU5dm7USdJuQaCfp1hpcUU1u8v";
//            // 创建OSSClient实例。
//            ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
//            clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
//
//            ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
//
//
//            // 设置签名URL过期时间,单位为毫秒。本示例以设置过期时间为1小时为例。
//            Date expiration = new Date(new Date().getTime() + 3600 * 1000L);
//            // 生成以GET方法访问的签名URL。本示例没有额外请求头,其他人可以直接通过浏览器访问相关内容。
//            URL url = ossClient.generatePresignedUrl(bucketName, objectName, expiration);
//
//
//            try {
//                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//                conn.setRequestMethod("GET");
//                conn.setConnectTimeout(10 * 1000);
//                conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//
//                InputStream input = conn.getInputStream();// 通过输入流获取图片数据
//
//                FileOutputStream downloadFile = new FileOutputStream("D://1.doc");
//
//                int index;
//                byte[] bytes = new byte[1024];
//
//                while ((index = input.read(bytes)) != -1) {
//                    downloadFile.write(bytes, 0, index);
//                    downloadFile.flush();
//                }
//                downloadFile.close();
//                input.close();
 
//
//                    ByteArrayOutputStream outs = new ByteArrayOutputStream();
//                    Thumbnails.of(in).scale(0.6).outputQuality(1).toOutputStream(outs);
//                    InputStream ins = new ByteArrayInputStream(outs.toByteArray());
//                    String picData = ossService.uploadImages(ins, ".png", 0);
//                    System.out.println(picData);
 
 
        } catch (
                OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
 
    }
 
//        List<CategoryDto> data = unlawfuldao.getDataByType(0, 5,"2022-12-14 17:19:01", "2022-12-14 17:19:03");
//        System.out.println(data);
//        String url = "http://test.xshcs.com/10%E6%9C%88%E6%8E%92%E6%9C%9F.jpg";
//        try {
//            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
//            connection.setReadTimeout(5000);
//            connection.setConnectTimeout(5000);
//            connection.setRequestMethod("GET");
//            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
//                InputStream in = connection.getInputStream();
//                ByteArrayOutputStream outs = new ByteArrayOutputStream();
//                Thumbnails.of(in).scale(0.6).outputQuality(1).toOutputStream(outs);
//                InputStream ins = new ByteArrayInputStream(outs.toByteArray());
//                String picData = ossService.uploadImages(ins, ".png",0);
//                System.out.println(picData);
//            }
//        } catch (IOException e) {
//            System.out.println("获取网络图片出现异常,图片路径为:" + url);
//
//            e.printStackTrace();
//        }
//}
 
//    @Test
//    void test1(){
//        List<StatusDto> statusData = unlawfuldao.getStatusData(null, null, 23);
//        System.out.println(statusData);
//    }
 
    @Test
    void test2() {
        double v = Double.parseDouble("1.0");
        double v1 = Double.parseDouble("3.0");
        System.out.println(v / v1);
    }
 
    @Test
    void test3() {
        System.out.println("sczf/" + String.valueOf(UUID.randomUUID()));
    }
 
    @Test
    void test4() throws Exception {
        String extension = "jpg";
 
        File file = new File("src/main/resources/file.txt");
        FileInputStream fis = new FileInputStream(file);
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(isr);
 
        String PicData = br.readLine();
        byte[] data = DatatypeConverter.parseBase64Binary(PicData);
        InputStream inputStream = new ByteArrayInputStream(data);
        String s = ossService.uploadImages(inputStream, extension, 0);
        System.out.println(s);
 
        br.close();
        isr.close();
        fis.close();
    }
 
//    @Autowired
//    AnalyzerDataCB analyzerDataCB;
 
    @Test
    void alarmTest() throws UnsupportedEncodingException {
 
//        analyzerDataCB.invoke(null, 0, null, null, 0, null, 0, null);
 
//        AlarmDataCB cbMessage = new AlarmDataCB();
//        String m_strIp = "172.28.194.177";
//        int m_nPort = 37777;
//        String m_strUser = "admin";
//        String m_strPassword = "scdx@123";
//        LoginModule.login(m_strIp, m_nPort, m_strUser, m_strPassword);
//        AlarmListenModule.startListen(cbMessage);
//
//        System.out.println(cbMessage.data);
 
        //  https://xshlivelesson.oss-accelerate.aliyuncs.com/sczf/2025-02-28%2015%3A53%3A293732..JPG?Expires=2686809213&OSSAccessKeyId=LTAIDlTWjHW0IVyW&Signature=Q5WO2kQcWRpq0SQiYjBCo6rGyJE%3D"
 
//        ossService.deleteImages("https://xshlivelesson.oss-cn-shenzhen.aliyuncs.com/sczf/2025022845414037.JPG?Expires=2686811218&OSSAccessKeyId=LTAIDlTWjHW0IVyW&Signature=5SQ7PInLkbd62zJ1aurljeO0c%2Bw%3D");
//
//        int i = 1;
//        while (true) {
//            String beginTime = "2025-01-01 00:00:00";
//            String endTime = LocalDateTime.now().plusDays(-4).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//            Page<BaseCaseVO> page = baseCaseService.selectVideoInspection(i, 10, null, null, beginTime, endTime, null);
//            if (page.getRecords().size() > 0) {
//                page.getRecords().forEach(baseCaseVO -> {
//                    String picData = baseCaseVO.getPicData();
//                    String[] urls = picData.split(",");
//                    for (String url : urls) {
//                        ossService.deleteImages(url);
//
//                    }
//                    baseCaseService.removeById(baseCaseVO.getBaseId());
//                    violationsService.removeById(baseCaseVO.getBaseId());
//                });
//            } else {
//                break;
//            }
//            i++;
//        }
    }
 
 
}