DahuaApplicationTests.java
24 KB
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
package com.example.dahua;
import com.alibaba.fastjson.JSON;
import com.example.dahua.async.SendUserInfoTask;
import com.example.dahua.bean.*;
import com.example.dahua.bean.yx.FaceBean;
import com.example.dahua.bean.yx.ImportStudent;
import com.example.dahua.dao.TestDao;
import com.example.dahua.dao.UserDao;
import com.example.dahua.mqtt.MqttManager;
import com.example.dahua.service.UserService;
import com.example.dahua.service.imp.BaseService;
import com.example.dahua.xiananDao.SearchMapper;
import com.example.dahua.xiananDao.SendRecordDao;
import org.apache.http.util.TextUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DahuaApplicationTests {
@Autowired
UserService userService;
@Autowired
SendUserInfoTask sendUserInfoTask;
@Autowired
UserDao userDao;
// @Autowired
// TestDao testDao;
@Autowired
SendRecordDao sendRecordDao;
List<String> list = new ArrayList<String>();
long sysTime = 0;
/* @Test
public void changeOptions() {
//获取高级中学所有住校生
List<UserInfoBean> userInfoBeans = userDao.getUsers();
//获取高级中学某幢楼的学生
List<UserInfoBean> userInfoBeanList = userDao.getUserInfos();
List<UserInfoBean> userInfoBeansHas = new ArrayList<>();
for (int i = 0; i < userInfoBeans.size(); i++) {
UserInfoBean userInfoBean = userInfoBeans.get(i);
boolean isHas = false;
for (int j = 0; j < userInfoBeanList.size(); j++) {
UserInfoBean userInfoBean1 = userInfoBeanList.get(j);
if (userInfoBean.getStudent_id().equals(userInfoBean1.getStudent_id())) {
isHas = true;
}
}
if (!isHas) {
userInfoBeansHas.add(userInfoBean);
}
}
System.out.println("userInfoBeansHas:" + userInfoBeansHas.toString() + " size:" + userInfoBeansHas.size());
RestTemplate restTemplate = new RestTemplate();
for (int i = 0; i < userInfoBeansHas.size(); i++) {
UserInfoBean userInfoBean = userInfoBeansHas.get(i);
String url = "http://121.40.109.21:8083/haikang/user/deleteCard?student_id=" + userInfoBean.getStudent_id() + "&clint_id=50275628&clint_type=23&name=" + userInfoBean.getName()
+ "&valid=0";
String result = restTemplate.getForObject(url, String.class);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("result:" + result);
}
//盖北考勤记录查询
*//*List<AttendanceRecords> attendanceRecordsList = sendRecordDao.getAttendanceRecords();
List<UserInfoBean> userInfoBeanList = userDao.getUsers();
List<UserInfoBean> userInfoBeans = new ArrayList<>();
for (int i = 0; i < userInfoBeanList.size(); i++) {
boolean isHas =false;
for (int j = 0; j < attendanceRecordsList.size(); j++) {
if (userInfoBeanList.get(i).getStudent_num().equals(attendanceRecordsList.get(j).getCard_num())){
isHas = true;
continue;
}
}
if (!isHas){
isHas = false;
userInfoBeans.add(userInfoBeanList.get(i));
}
}
System.out.println(userInfoBeans.size()+"");
String content = "";
for (int i = 0; i < userInfoBeans.size(); i++) {
UserInfoBean userInfoBea1n = userInfoBeans.get(i);
if (userInfoBea1n!=null&&!content.contains(userInfoBea1n.toString())){
content+=userInfoBea1n.getClass_name()+" "+userInfoBea1n.getName()+" "+userInfoBea1n.getStudent_num()+"\r\n";
}
}
System.out.println(content);*//*
}
int index = 0;
private void addPic(List<String> list) {
String content = list.get(index);
// System.out.println("content:" + content);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!StringUtils.isEmpty(content) && content.split(",").length > 1) {
String studdentCode = content.split(",")[0];
String card = content.split(",")[1];
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
multiValueMap.add("StudentCode", "1111111111");
multiValueMap.add("ParentId", "0");
multiValueMap.add("SchoolId", "479");
multiValueMap.add("OldCard", "");
multiValueMap.add("Card", "17903CD6");//d9ad1e9d d90d1b9d
multiValueMap.add("TerminalType", "1");
multiValueMap.add("Count", "1");
multiValueMap.add("UpdateType", "1");
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>(multiValueMap,
headers);
String url = "http://campus.myjxt.com/api/OneCard/UpdateDataBK";
// String url = "http://114.55.30.100:9020/facereco/SendStudentSingleImage?schoolId=110&deviceId=212476514&studentCode=" + studdentCode;
ResponseEntity<String> result = restTemplate.postForEntity(url, requestEntity, String.class);
// String result = restTemplate.getForObject(url, String.class);
System.out.println("result:" + result.getBody() + " studdentCode:" + studdentCode);
}
// index++;
// addPic(list);
}
@Test
public void contextLoads() {
File file1 = new File("C:\\TaoHandong\\实验小学1");
File file2 = new File("C:\\TaoHandong\\实验小学2");
//筛选出没有匹配的人脸
*//*File file = new File("C:\\TaoHandong\\实验小学\\替换合并");
File[] files = file.listFiles();
System.out.println("imgFile:"+files.length);
for (int i = 0; i < files.length; i++) {
File imgFile = files[i];
findUser(imgFile.getName().split("\\.")[0],imgFile,file1,file2);
// System.out.println("imgFile:"+imgFile.getAbsolutePath());
}*//*
//从没有匹配的人脸库中,通过名字再去匹配
*//*File fileOut2 = new File("C:\\TaoHandong\\实验小学3");
File[] files2 = file2.listFiles();
for (int i = 0; i < files2.length; i++) {
File imgPath = files2[i];
findUsers(imgPath.getName().split("\\.")[0],imgPath,file1);
}*//*
}
private void findUser(String studentId, File imgFile, File file1, File file2) {
if (!file1.exists()) file1.mkdirs();
if (!file2.exists()) file2.mkdirs();
try {
File fileTxt = new File("C:\\TaoHandong\\实验小学\\人员.txt");
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileTxt));
String content = null;
while ((content = bufferedReader.readLine()) != null) {
if (content.split("\t")[0].equals(studentId)) {
String name = content.split("\t")[1];
String cardNnum = content.split("\t")[2];
UserInfoBean userInfoBean = userDao.getStudent(cardNnum, name);
// List<TeacherBean> teacherBeans = userDao.getTeachers(cardNnum);
if (userInfoBean != null) {
File writeImg = new File(file1.getAbsolutePath(), userInfoBean.getStudentcode() + ".jpg");
writeImg(writeImg, imgFile);
} else {
File writeImg = new File(file2.getAbsolutePath(), imgFile.getName());
writeImg(writeImg, imgFile);
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void findUsers(String studentId, File imgFile, File file1) {
if (!file1.exists()) file1.mkdirs();
try {
File fileTxt = new File("C:\\TaoHandong\\实验小学\\人员.txt");
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileTxt));
String content = null;
while ((content = bufferedReader.readLine()) != null) {
if (content.split("\t")[0].equals(studentId)) {
String name = content.split("\t")[1];
String cardNnum = content.split("\t")[2];
List<UserInfoBean> userInfoBean = userDao.getStudentWithName(name);
if (userInfoBean != null && userInfoBean.size() == 1) {
File writeImg = new File(file1.getAbsolutePath(), userInfoBean.get(0).getStudentcode() + ".jpg");
writeImg(writeImg, imgFile);
} else {
System.out.println(content);
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void writeImg(File writeImg, File imgFile) {
if (writeImg.exists()) writeImg.delete();
try {
FileOutputStream fileOutputStream = new FileOutputStream(writeImg);
FileInputStream fileInputStream = new FileInputStream(imgFile);
byte[] bytes = new byte[1024];
int length = 0;
while ((length = fileInputStream.read(bytes)) != -1) {
fileOutputStream.write(bytes, 0, length);
}
fileOutputStream.close();
fileInputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// System.out.println("imgFile:"+imgFile.exists());
// if (imgFile.exists())imgFile.delete();
}
@Test
public void uploadImg() {
//获取高级中学所有住校生
List<UserInfoBean> userInfoBeans = userDao.getUsers();
//获取高级中学某幢楼的学生
List<UserInfoBean> userInfoBeanList = userDao.getUserInfos();
List<UserInfoBean> userInfoBeansHas = new ArrayList<>();
for (int i = 0; i < userInfoBeans.size(); i++) {
UserInfoBean userInfoBean = userInfoBeans.get(i);
boolean isHas = false;
for (int j = 0; j < userInfoBeanList.size(); j++) {
UserInfoBean userInfoBean1 = userInfoBeanList.get(j);
if (userInfoBean.getStudent_id().equals(userInfoBean1.getStudent_id())) {
isHas = true;
}
}
if (!isHas) {
userInfoBeansHas.add(userInfoBean);
}
}
System.out.println("userInfoBeansHas:" + userInfoBeansHas.toString() + " size:" + userInfoBeansHas.size());
RestTemplate restTemplate = new RestTemplate();
for (int i = 0; i < userInfoBeansHas.size(); i++) {
UserInfoBean userInfoBean = userInfoBeansHas.get(i);
String url = "http://121.40.109.21:8083/haikang/user/deleteCard?student_id=" + userInfoBean.getStudent_id() + "&clint_id=50275667&clint_type=23&name=" + userInfoBean.getName()
+ "&valid=0";
String result = restTemplate.getForObject(url, String.class);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("result:" + result);
}
}*/
Logger logger = LoggerFactory.getLogger(DahuaApplicationTests.class);
@Test
public void test2() {
RestTemplate restTemplate = new RestTemplate();
String sex = "2";
List<UserInfoBean> studentBeans = userDao.getStudentWithSchoolId("27", sex, "2");
String[] deviceids = null;
if (sex.equals("1")) {
deviceids = new String[]{"253169240", "253169204", "253169216", "253169229", "253169870", "253169869", "253169873", "253169226", "253169191"};
} else if (sex.equals("2") || sex.equals("3")) {
deviceids = new String[]{"253169192", "253169444", "253169469", "253169463", "253169456", "253169467", "253169462", "253169468"};
} else {
}
String times = "00:00,23:00";
System.out.println("studentBeans:" + studentBeans.get(0).toString());
for (int i = 0; i < studentBeans.size(); i++) {
UserInfoBean studentBean = studentBeans.get(i);
String card = studentBean.getStudent_num();
if (!TextUtils.isEmpty(card)) {
for (int j = 0; j < deviceids.length; j++) {
String clint_id = deviceids[j];
String url = "http://campus.myjxt.com/api/OneCard/SendSingleByClintId?SchoolId=" + 27 + "&Card=" + card + "&ClassId=" + studentBean.getClass_id() + "&clint_id=" + clint_id + "×=" + times
+ "&studentType=2&sex=" + sex;
System.out.println("下发卡号url:" + url);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
logger.error("下发卡号:{}", responseEntity.getBody());
}
}
}
}
@Test
public void sendStuPost() {
RestTemplate restTemplate = new RestTemplate();
List<TeacherBean> teacherBeans = userDao.getTeachers("562");
String[] deviceids = new String[]{"253164171", "253164252"};
String url = "http://121.40.109.21:9000/setSignalCardInfo";
for (int i = 0; i < teacherBeans.size(); i++) {
TeacherBean teacherBean = teacherBeans.get(i);
if (!TextUtils.isEmpty(teacherBean.getTeacher_num()))
for (int j = 0; j < deviceids.length; j++) {
String deviceId = deviceids[j];
SendCards sendCards = new SendCards();
sendCards.setCardNo(teacherBean.getTeacher_num());
sendCards.setEndTime("2030-06-23 00:07:59");
sendCards.setId("5");
sendCards.setShiduan("0");
sendCards.setSn(deviceId);
sendCards.setStartTime("2020-06-23 00:07:59");
sendCards.setType("1");
Map<String, String> body = new HashMap<String, String>();
body.put("cardNo", teacherBean.getTeacher_num());
body.put("endTime", "2030-06-23T00:07:59");
body.put("id", "5");
body.put("shiduan", "0");
body.put("sn", deviceId);
body.put("startTime", "2020-06-23T00:07:59");
body.put("type", "1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String jsonData = JSON.toJSONString(body);
HttpEntity<String> request = new HttpEntity<String>(jsonData, headers);
// String responseEntity = restTemplate.postForObject(url,new Gson().toJson(sendCards), String.class);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
System.out.println("下发卡号:" + responseEntity.getBody());
}
}
}
@Test
public void delete() {
RestTemplate restTemplate = new RestTemplate();
String sex = "2";
List<UserInfoBean> studentBeans = userDao.getStudentWithSchoolId("27", sex, "1");
String[] deviceids = null;
//女生设备
deviceids = new String[]{"253169192", "253169444", "253169469", "253169463", "253169456", "253169467", "253169462", "253169468", "253169454"};
String url = "http://121.40.109.21:9000/clearSinglePower";
System.out.println("学生数量:" + studentBeans.size());
for (int i = 0; i < studentBeans.size(); i++) {
UserInfoBean teacherBean = studentBeans.get(i);
if (!TextUtils.isEmpty(teacherBean.getStudent_num()))
for (int j = 0; j < deviceids.length; j++) {
String deviceId = deviceids[j];
Map<String, String> body = new HashMap<String, String>();
body.put("cardNo", teacherBean.getStudent_num());
body.put("id", "8");
body.put("sn", deviceId);
body.put("type", "1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String jsonData = JSON.toJSONString(body);
HttpEntity<String> request = new HttpEntity<String>(jsonData, headers);
// String responseEntity = restTemplate.postForObject(url,new Gson().toJson(sendCards), String.class);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
System.out.println("下发卡号:" + responseEntity.getBody());
}
}
}
@Test
public void delete1() {
RestTemplate restTemplate = new RestTemplate();
String sex = "2";
List<UserInfoBean> studentBeans = userDao.getStudentWithSchoolId("27", sex, "2");
String[] deviceids = null;
//男生设备
deviceids = new String[]{"253169240", "253169204", "253169216", "253169229", "253169870", "253169869", "253169873", "253169226", "253169191"};
String url = "http://121.40.109.21:9000/clearSinglePower";
System.out.println("学生数量:" + studentBeans.size());
for (int i = studentBeans.size() - 1; i >= 0; i--) {
UserInfoBean teacherBean = studentBeans.get(i);
if (!TextUtils.isEmpty(teacherBean.getStudent_num()))
for (int j = 0; j < deviceids.length; j++) {
String deviceId = deviceids[j];
Map<String, String> body = new HashMap<String, String>();
body.put("cardNo", teacherBean.getStudent_num());
body.put("id", "8");
body.put("sn", deviceId);
body.put("type", "1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String jsonData = JSON.toJSONString(body);
HttpEntity<String> request = new HttpEntity<String>(jsonData, headers);
// String responseEntity = restTemplate.postForObject(url,new Gson().toJson(sendCards), String.class);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
System.out.println("下发卡号:" + responseEntity.getBody());
}
}
}
@Test
public void test1() {
List<StudentBean> studentBeans = userDao.getStus();
for (int i = 0; i < studentBeans.size(); i++) {
StudentBean studentBean = studentBeans.get(i);
System.out.println("studentBean:"+studentBean.toString());
userDao.insertUpdateCard(studentBean.getUser_id(),studentBean.getStudent_id(),studentBean.getStudent_type()+"","2",
studentBean.getName(),studentBean.getClass_id()+"",studentBean.getClass_name(),studentBean.getStudent_num(),studentBean.getSchool_id()+"",
"1","1","2020-09-23 11:40:00",studentBean.getSex()+"",studentBean.getStudentcode(),"");
}
}
@Test
public void Mqtt() {
MqttManager mqttManager = new MqttManager();
mqttManager.init();
List<String> stringList = userDao.getAllDecWithSch(27);
System.out.println("stringList:" + stringList.size());
for (int i = 0; i < stringList.size(); i++) {
String devId = stringList.get(i);
//30关闭显示屏 31打开显示屏,9升级客户端
mqttManager.sendMq(devId, "9");
}
}
@Resource
private BaseService baseService;
@Resource
private SearchMapper searchMapper;
@Test
public void test8(){
//根据类型获取下发用户信息
String deviceIds = "ytj7locb3apaj33b6a,ytj7locb3apaj412af,ytj7locb3apaj76210,ytj7locb3apajb69c3";
// String deviceIds = "ytj7locb3apaj8ob3c,ytj7locb3apaj5cao8,ytj7locb3apaj7fc35,ytj7locb3apajdb8f4";
List<String> deviceList = new ArrayList<>(Arrays.asList(deviceIds.split(",")));
List<ImportStudent> studentBeanList = baseService.getYxStudentList(12,"B幢");
System.out.println("统计共有下发用户数量:{}"+studentBeanList.size());
studentBeanList.stream()
.filter(importStudent -> !StringUtils.isEmpty(importStudent.getPhoto()))
.forEach(importStudent -> {
System.out.println(importStudent.getName());
deviceList.stream().forEach(s -> {
FaceBean faceBean = new FaceBean();
faceBean.setDeviceId(s);
faceBean.setName(importStudent.getName());
faceBean.setNum(importStudent.getCardNum());
faceBean.setUserId(importStudent.getUserId());
faceBean.setSchoolId(12);
faceBean.setSchoolName("绍兴艺术学校");
faceBean.setChannel(1);
faceBean.setStatus(1);
faceBean.setDeviceType(29);
faceBean.setTime(new Date());
searchMapper.insertFace(faceBean);
});
});
}
@Test
public void test9(){
//根据类型获取下发用户信息
// String deviceIds = "ytj7locb3apaj33b6a,ytj7locb3apaj412af,ytj7locb3apaj76210,ytj7locb3apajb69c3";
String deviceIds = "ytj7locb3apaj8ob3c,ytj7locb3apaj5cao8,ytj7locb3apaj7fc35,ytj7locb3apajdb8f4";
List<String> deviceList = new ArrayList<>(Arrays.asList(deviceIds.split(",")));
List<StudentBean> studentBeanList = baseService.getTeacherList(12);
System.out.println("统计共有下发用户数量: "+studentBeanList.size());
studentBeanList.stream()
.filter(studentBean -> !StringUtils.isEmpty(studentBean.getFace()))
.forEach(studentBean -> {
System.out.println(studentBean.getName());
deviceList.stream().forEach(s -> {
FaceBean faceBean = new FaceBean();
faceBean.setDeviceId(s);
faceBean.setName(studentBean.getName());
faceBean.setNum(studentBean.getTeacher_num());
faceBean.setUserId(studentBean.getUser_id());
faceBean.setSchoolId(12);
faceBean.setSchoolName("绍兴艺术学校");
faceBean.setChannel(1);
faceBean.setStatus(1);
faceBean.setDeviceType(29);
faceBean.setUserType(1);
faceBean.setTime(new Date());
searchMapper.insertFace(faceBean);
});
});
}
}