SendUserInfoTask.java
29.6 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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
package com.example.dahua.async;
import com.example.dahua.MyTask;
import com.example.dahua.bean.*;
import com.example.dahua.common.Res;
import com.example.dahua.dao.UserDao;
import com.example.dahua.lib.CompressPic;
import com.example.dahua.lib.FilePath;
import com.example.dahua.lib.NetSDKLib;
import com.example.dahua.lib.ToolKits;
import com.example.dahua.module.GateModule;
import com.example.dahua.utils.FileUtils;
import com.example.dahua.utils.HttpUtils;
import com.example.dahua.xiananDao.SendRecordDao;
import com.sun.jna.Memory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* 下发卡号的异步操作
*/
@Component
public class SendUserInfoTask {
@Autowired
UserDao userDao;
@Autowired
SendRecordDao sendRecordDao;
@Async("taskExecutor")
public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType,int userType) throws Exception {
File studentFile = new File(file);
String studentCode = studentFile.getName().split("\\.")[0];
//判断是否是副卡
String[] studentCodes = studentCode.split("_");
if (studentCodes.length > 1) {//副卡
String cardType = studentCodes[1];
String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), cardType);
userInfoBean.setStudent_num(cardNum);
}
SendRecordBean sendRecordBean = new SendRecordBean();
sendRecordBean.setSchoolId(Integer.parseInt(schoolId));
sendRecordBean.setSchoolName(userDao.getSchoolName(schoolId));
sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
sendRecordBean.setUserType(2);
sendRecordBean.setNum(userInfoBean.getStudent_num());
sendRecordBean.setName(userInfoBean.getName());
sendRecordBean.setImgPath(file);
sendRecordBean.setCustomerid(userInfoBean.getStudent_id());
sendRecordBean.setFailType(failType);
sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType+"", sendRecordBean);
}
@Async("taskExecutor")
public void doTaskSendUserInfos(String schoolId, String clint_type, int type, int failtype) {
try {
String filePathStudent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Student";
String filePathParent = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Parent";
String filePathTeacher = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher";
// String filePathStudent = "F:\\wwwroot\\SmartCampus\\face17e50\\School" + schoolId + "\\Student";
// String filePathParent = "F:\\wwwroot\\SmartCampus\\face17e50\\School" + schoolId + "\\Parent";
// String filePathTeacher = "F:\\wwwroot\\SmartCampus\\face17e50\\School" + schoolId + "\\Teacher";
List<File> fileList = new ArrayList<>();
File filePaths = null;
String userType = "";
if (type == 0) {//主卡下发
filePaths = new File(filePathStudent);
userType = "2";
} else if (type == 1) {//副卡下发
filePaths = new File(filePathParent);
userType = "2";
} else if (type == 2) {//教师卡下发
filePaths = new File(filePathTeacher);
userType = "1";
} else {
filePaths = new File("");
}
SendRecordBean sendRecordBean = new SendRecordBean();
sendRecordBean.setSchoolId(Integer.parseInt(schoolId));
sendRecordBean.setSchoolName(userDao.getSchoolName(schoolId));
sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
sendRecordBean.setUserType(Integer.parseInt(userType));
sendRecordBean.setFailType(failtype);
if (!filePaths.exists()) {
// System.out.println("图片目录不存在:" + filePaths.getAbsolutePath());
// sendRecordBean.setFailType(1);
// sendRecordBean.setFailContent("副卡图片目录不存在");
// addFailDace(sendRecordBean);
return;
}
File[] filesStudent = filePaths.listFiles();
if (filesStudent == null) {
System.out.println("没有找到人脸图片");
// sendRecordBean.setFailType(1);
// sendRecordBean.setFailContent("主卡目录不存在");
// addFailDace(sendRecordBean);
return;
}
/**
* 添加学生人脸
*/
for (int i = 0; i < filesStudent.length; i++) {
fileList.add(filesStudent[i]);
}
// System.out.println("files:" + fileList.size());
while (fileList.size() > 0) {
File studentFile = fileList.get(0);
String studentCode = studentFile.getName().split("\\.")[0];
UserInfoBean userInfoBean = null;
//判断是否是副卡
String[] studentCodes = studentCode.split("_");
System.out.println("学籍号:" + studentCode);
if (studentCodes.length > 1) {//副卡
String studentcode = studentCodes[0];
String cardType = studentCodes[1];
userInfoBean = userDao.getUserInfo(schoolId, studentcode);
if (!userIsExit(fileList, studentcode, userInfoBean, sendRecordBean)) continue;
String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), cardType);
userInfoBean.setStudent_num(cardNum);
} else {
if (type == 0 || type == 1) {//学生信息或家长信息
userInfoBean = userDao.getUserInfo(schoolId, studentCode);
HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,2);
} else if (type == 2) {//教师信息
TeacherBean teacher = userDao.getTeacher(schoolId, studentCode);
if (null != teacher) {
userInfoBean = new UserInfoBean();
userInfoBean.setStudent_num(teacher.getTeacher_num());
userInfoBean.setName(teacher.getName());
userInfoBean.setUser_id(teacher.getUser_id());
userInfoBean.setStudentcode(teacher.getNum());
userInfoBean.setStudent_id(teacher.getTeacher_id());
}
HttpUtils.uploadImgs(studentFile,schoolId,studentCode,clint_type,1);
}
//判断用户是否存在
if (!userIsExit(fileList, studentCode, userInfoBean, sendRecordBean)) continue;
}
// boolean sendResult = sendUserInfoToDev(studentFile.getAbsolutePath(), attendanceBeans, userInfoBean, userType, sendRecordBean);
fileList.remove(0);
}
// System.out.println("全部下发完成:");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 判断用户是否存在
*
* @param fileList
* @param studentcode
* @param userInfoBean
*/
private boolean userIsExit(List<File> fileList, String studentcode, UserInfoBean userInfoBean, SendRecordBean sendRecordBean) {
if (userInfoBean == null) {
// System.out.println("用户信息不存在:" + studentcode);
fileList.remove(0);
sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 3);//更新下发失败状态
sendRecordBean.setFailType(3);
sendRecordBean.setFailContent("用户信息不存在");
addFailDace(sendRecordBean);
return false;
}
return true;
}
/**
* 发送人员信息给设备
*
* @param file
* @param attendanceBeans
* @param userInfoBean
* @return
*/
private synchronized boolean sendUserInfoToDev(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String userType, SendRecordBean sendRecordBean) {
try {
if (userInfoBean == null) {
System.out.println("学生用户不存在");
return false;
}
if (attendanceBeans.size() == 0) {//"该学校下没有人脸设备"
System.out.println("该学校下没有人脸设备:");
sendRecordBean.setFailType(2);
sendRecordBean.setFailContent("图片目录不存在");
String schoolName = sendRecordDao.getSchoolDevice(sendRecordBean.getSchoolId(), 2);//判断是否已经记录改学校没有设备
if (StringUtils.isEmpty(schoolName)) {//不存在记录则添加,保证没有设备的学校记录只有一条
sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 2);//更新下发失败状态
addFailDace(sendRecordBean);
}
return false;
}
String cardNum = userInfoBean.getStudent_num();
System.out.println("cardNum:" + cardNum);
if (StringUtils.isEmpty(cardNum) || cardNum.equals("null")) {
System.out.println("卡号为空");
return false;
}
/**
* 保存图片到本地
*/
sendTodev(file, userInfoBean, attendanceBeans, userType, sendRecordBean.getFailType());
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
/**
* @param picSrc 图片地址
* @param userInfoBean 用户信息
* @param attendanceBeans 设备列表
* @param userType
*/
private synchronized void sendTodev(String picSrc, UserInfoBean userInfoBean, List<AttendanceBean> attendanceBeans, String userType, int failType) {
SendRecordBean sendRecordBean = new SendRecordBean();
sendRecordBean.setCustomerid(userInfoBean.getStudent_id());
sendRecordBean.setName(userInfoBean.getName());
sendRecordBean.setUserType(Integer.parseInt(userType));
sendRecordBean.setNum(userInfoBean.getStudent_num());
sendRecordBean.setFailType(failType);
Memory memory = null;//图片缓存
try {
String targPath = FilePath.picPathComp + userInfoBean.getStudentcode() + ".jpg";
// String targPath = "C:\\Users\\taohandong\\Desktop\\comp\\"+userInfoBean.getStudentcode()+".jpg";
if (new File(picSrc).exists())
CompressPic.CompressPic(picSrc, targPath, userInfoBean.getStudentcode());//压缩后的图片
memory = ToolKits.readPictureFile(targPath);
sendRecordBean.setImgPath(picSrc);
// System.out.println("下发学生信息:" + "targPath:" + new File(targPath).exists() + targPath + " userInfoBean:" + userInfoBean);
} catch (Exception e) {
e.printStackTrace();
}
for (AttendanceBean attendanceBean :
attendanceBeans) {
pushCardAndFace(attendanceBean, userInfoBean.getUser_id(), userInfoBean.getStudent_num(), userInfoBean.getName(), memory, sendRecordBean);
}
}
private synchronized void pushCardAndFace(AttendanceBean attendanceBean, String user_id, String student_num, String name, Memory memory, SendRecordBean sendRecordBean) {
sendRecordBean.setDeviceID(attendanceBean.getClint_id());
sendRecordBean.setSchoolId(Integer.parseInt(attendanceBean.getSchool_id()));
sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
sendRecordBean.setSchoolName(userDao.getSchoolName(attendanceBean.getSchool_id()));
String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, 4);
String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
int bCardFlags = -1;//记录集编号,存在于设备的
bCardFlags = userDao.getRecordNo(user_id, attendanceBean.getClint_id()) == null ? -1 : Integer.parseInt(userDao.getRecordNo(user_id, attendanceBean.getClint_id()));
NetSDKLib.LLong loginHandleLong = MyTask.lLongMap.get(attendanceBean.getClint_id());
// System.out.println("loginHandleLong:" + loginHandleLong + MyTask.lLongMap.toString() + " 设备ID:" + attendanceBean.getClint_id());
// System.out.println("loginHandleLong:" +loginHandleLong);
if (loginHandleLong == null) {
FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices);
String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id());
sendRecordBean.setFailType(2);
sendRecordBean.setFailContent("设备不在线");
if (!StringUtils.isEmpty(deviceId)) {
sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 2);//更新下发失败状态
addFailDace(sendRecordBean);
}
} else {
boolean bFaceFalgs = false;
String cardNum = cardNo(student_num);
if (bCardFlags != -1) {//修改卡信息
GateModule.deleteCard(bCardFlags, loginHandleLong);
userDao.deleteRecordNo(user_id, bCardFlags);
bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456"
, Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 0
, 1, startTime, endTime, loginHandleLong);
if (bCardFlags != -1) {
int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号
}
bFaceFalgs = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong);
//卡号添加成功,但是人脸不成功的话,就需要新增人脸
if (!bFaceFalgs)
bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong);
} else {//新增卡信息
bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456"
, Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 0
, 1, startTime, endTime, loginHandleLong);
if (bCardFlags != -1) {
int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号
}
//添加人脸
bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong);
}
if (bCardFlags != -1 && bFaceFalgs) {
FileUtils.getInstance().writeLogs("下发人脸和卡号成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt);
System.out.println("人脸下发成功" + "sendRecordBean:" + sendRecordBean);
//先判断是否已经存在了
List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceSucceIsexit(sendRecordBean.getDeviceID(), String.valueOf(sendRecordBean.getSchoolId()), sendRecordBean.getCustomerid());
if (sendRecordBeanList.size() > 0) {
//删除重复数据
for (int i = 0; i < sendRecordBeanList.size(); i++) {
sendRecordDao.deleteFaceSuccess(sendRecordBeanList.get(i).getDeviceID(), sendRecordBeanList.get(i).getNum());
}
// //更新数据
// sendRecordDao.updateFaceSuccess(sendRecordBean.getTime(), sendRecordBean.getDeviceID(), sendRecordBean.getNum());
} else {
}
int index = sendRecordDao.addFaceSuccess(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(),
sendRecordBean.getSchoolName(), sendRecordBean.getImgPath(), sendRecordBean.getSchoolId(), sendRecordBean.getUserType(), 22);
// File imgFile = new File(sendRecordBean.getImgPath());
// imgFile.deleteOnExit();
//删除成功
if (sendRecordBean.getFailType() != 0)
sendRecordDao.deleteFaceFail(sendRecordBean.getNum(), sendRecordBean.getDeviceID());
}
// 添加卡信息和人脸失败
if (bCardFlags == -1 && !bFaceFalgs) {
FileUtils.getInstance().writeLogs("下发人脸和卡号失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt);
// System.out.println("添加卡信息和人脸失败");
System.out.println("下发人脸和卡号失败" + "sendRecordBean:" + sendRecordBean);
sendRecordBean.setFailContent("下发人脸和卡号失败");
sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 7);//更新下发失败状态
sendRecordBean.setFailType(8);
addFailDace(sendRecordBean);
}
// 添加卡信息成功,添加人脸失败
if (bCardFlags != -1 && !bFaceFalgs) {
FileUtils.getInstance().writeLogs("下发卡号成功,人脸失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt);
// System.out.println("添加卡信息成功,添加人脸失败");
System.out.println("customerId:" + sendRecordBean.getCustomerid() + " deviceId:" + sendRecordBean.getDeviceID() + " failType:" + sendRecordBean.getFailType());
sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 5);//更新下发失败状态
sendRecordBean.setFailContent("下发卡号成功,人脸失败:照片特征值提取失败");
sendRecordBean.setFailType(5);
addFailDace(sendRecordBean);
}
// 卡信息已存在,添加人脸成功
if (bCardFlags == -1 && bFaceFalgs) {
FileUtils.getInstance().writeLogs("下发人脸成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt);
System.out.println("卡信息已存在,添加人脸成功");
}
}
}
//人脸发送失败信息添加
private void addFailDace(SendRecordBean sendRecordBean) {
// System.out.println("sendRecordBean:" + sendRecordBean != null ? sendRecordBean.toString() : "不存在");
List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceFailIsExit(sendRecordBean.getDeviceID(), sendRecordBean.getCustomerid());
for (int i = 0; i < sendRecordBeanList.size(); i++) {
sendRecordDao.deleteFaceFail(sendRecordBeanList.get(i).getNum(), sendRecordBeanList.get(i).getDeviceID());
}
// String name = sendRecordDao.getFailNameIsExit(sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getFailType());
// if (StringUtils.isEmpty(name)) {
if (sendRecordBean.getFailType() == 5) sendRecordBean.setFailType(8);
sendRecordDao.addFaceFail(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(),
sendRecordBean.getSchoolName(), sendRecordBean.getImgPath(), sendRecordBean.getSchoolId(), sendRecordBean.getFailContent(), sendRecordBean.getFailType(), sendRecordBean.getUserType(), 22);
// }
}
public String cardNo(String cardDex) {
String cardR = "";
int length = cardDex.length();
if (length != 8) {
System.out.println("卡号格式不正确:" + cardDex);
return cardDex;
}
while (length > 0) {
length -= 2;
cardR += cardDex.substring(length, length + 2);
}
return cardR;
}
public void movePic(int schoolId, int userType, String deviceId) {
List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceFails(userType, schoolId, deviceId);
String teaFile = String.format("E:\\wwwhtdocs\\SmartCampus\\face17e50\\School%s\\Teacher", schoolId);
String stuFile = String.format("E:\\wwwhtdocs\\SmartCampus\\face17e50\\School%s\\Student", schoolId);
String targetrFile = "";
if (userType == 1) targetrFile = teaFile;
else if (userType == 2) targetrFile = stuFile;
System.out.println("sendRecordBeanList:" + sendRecordBeanList.size());
for (int i = 0; i < sendRecordBeanList.size(); i++) {
SendRecordBean sendRecordBean = sendRecordBeanList.get(i);
String imgPath = sendRecordBean.getImgPath().replace("face17e50","face17e5");
File file = new File(imgPath);
System.out.println("file:"+file.getAbsolutePath());
if (file.exists()) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
String fileName = file.getName();
fileName = fileName.replace("jpg","png");
fileName = fileName.replace("jpeg","png");
File targetFile = new File(targetrFile, fileName);
if (!targetFile.exists()) targetFile.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(targetFile);
byte[] bytes = new byte[1024];
int length = 0;
while ((length = fileInputStream.read(bytes)) != -1) {
fileOutputStream.write(bytes, 0, length);
}
System.out.println("targetFile:" + targetFile.getAbsolutePath());
fileInputStream.close();
fileOutputStream.flush();
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 删除人脸
*
* @param cardNum
* @param deviceId
*/
public void deleteFace(String cardNum, String deviceId) {
String user_id = userDao.getUerIdWithNum(cardNum);
// int bCardFlags = -1;//记录集编号,存在于设备的
int bCardFlags = userDao.getRecordNo(user_id, deviceId) == null ? -1 : Integer.parseInt(userDao.getRecordNo(user_id, deviceId));
System.out.println("bCardFlags:" + bCardFlags);
if (bCardFlags != -1) {
GateModule.deleteCard(bCardFlags, MyTask.lLongMap.get(deviceId));
}
}
@Async("taskExecutor")
public void addWeiGen(){
List<String> customerIDs = sendRecordDao.getWGFail();
for (int i = 0; i < customerIDs.size(); i++) {
String customerID = customerIDs.get(i);
addKard(customerID, "2");//微耕
}
MyScheduledTask.isSendWeigeng = false;
}
String url = "http://campus.myjxt.com/api/OneCard/UpdateDataBK";
private synchronized void addKard(String customerId, String TerminalType) {
StudentBean studentBean = userDao.getStudentUpdate(customerId);
if (studentBean != null && studentBean.getStudentCode() != null) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
multiValueMap.add("StudentCode", studentBean.getStudentCode());
multiValueMap.add("ParentId", "0");
multiValueMap.add("SchoolId", studentBean.getSchoolId() + "");
multiValueMap.add("OldCard", studentBean.getOldCard());
multiValueMap.add("NewCard", studentBean.getCard());
multiValueMap.add("TerminalType", TerminalType);
multiValueMap.add("Count", "1");
multiValueMap.add("UpdateType", "1");
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<MultiValueMap>(multiValueMap,
headers);
ResponseEntity<String> result = restTemplate.postForEntity(url, requestEntity, String.class);
// System.out.println("result:" + result.getBody() );
} else if (studentBean != null && studentBean.getStudentCode() == null) {
// System.out.println(studentBean.getName()+"学籍号不存在");
}
}
@Async("taskExecutor")
public void addHaikangface(){
List<SendRecordBean> sendRecordBeanList = sendRecordDao.getSenFailHK("18", "9");
RestTemplate restTemplate = new RestTemplate();
for (int i = 0; i < sendRecordBeanList.size(); i++) {
SendRecordBean sendRecordBean = sendRecordBeanList.get(i);
if (sendRecordBean.getFailContent().equals("人脸照片不合格")) continue;
int userType = sendRecordBean.getUserType();
String userTy = "";
switch (userType) {
case 1:
userTy = "Teacher";
break;
case 2:
userTy = "Student";
break;
case 3:
userTy = "Parent";
break;
}
String filePath = String.format("E:\\wwwhtdocs\\SmartCampus\\face17e5\\School%s\\%s\\%s.jpg", sendRecordBean.getSchoolId(), userTy, userDao.getStudentCode(sendRecordBean.getCustomerid()));
String url = String.format("http://114.55.30.100:8089/facereco/sendStuCardAndImg?card=%s&deviceId=%s&endTime=%s&filePath=%s&name=%s&userType=%s&validTimeEnabled=%s&startTime=%s"
, sendRecordBean.getNum(), sendRecordBean.getDeviceID(), "2033-10-01 10:00:00", filePath, sendRecordBean.getName(), "2", "1", "2019-10-01 10:00:00");
boolean result1 = restTemplate.getForObject(url, Boolean.class);
if (result1) {
System.out.println("下发成功:" + url);
} else {
System.out.println("下发失败:" + url);
}
}
MyScheduledTask.isSendHaikang = false;
}
@Async("taskExecutor")
public void addDahuaFace(){
List<SendRecordBean> sendRecordBeanList = sendRecordDao.getSenFail("22");
for (int i = 0; i < sendRecordBeanList.size(); i++) {
SendRecordBean sendRecordBean = sendRecordBeanList.get(i);
switch (sendRecordBean.getFailType()) {
case 2://设备不存在
List<String> deviceIds = userDao.getDeviceIds("22", sendRecordBean.getSchoolId());
if (deviceIds != null && deviceIds.size() > 0) {
doTaskSendUserInfos(String.valueOf(sendRecordBean.getSchoolId()), "22", sendRecordBean.getUserType(), sendRecordBean.getFailType());
}
break;
case 4://设备离线
senfaceToDahua(sendRecordBean);
break;
case 5://下发人脸失败
// if (new File(sendRecordBean.getImgPath()).exists())
// ImageUtils.rotatePhonePhoto(sendRecordBean.getImgPath(), 90);
senfaceToDahua(sendRecordBean);
break;
case 7://意外失败
// senfaceToDahua(sendRecordBean);
break;
}
}
MyScheduledTask.isSendDahua = false;
}
private void senfaceToDahua(SendRecordBean sendRecordBean) {
UserInfoBean userInfoBean = null;
//根据文件命名来判断学籍号
String studentCodes = userDao.getStudentCode(sendRecordBean.getCustomerid());
userInfoBean = userDao.getUserInfo(sendRecordBean.getSchoolId() + "", studentCodes);//获取用户信息
// System.out.println("userInfoBean:" + sendRecordBean.toString());
try {
if (null != userInfoBean) {
userInfoBean.setStudent_num(sendRecordBean.getNum());
String img = sendRecordBean.getImgPath();
if (!StringUtils.isEmpty(img)) {
if (img.startsWith("http"))
img = img.replace("http://campus.myjxt.com//", "E://wwwhtdocs/SmartCampus/");
doTaskOne(img, userDao.getAttendanceBeans(String.valueOf(sendRecordBean.getSchoolId()), "22")
, userInfoBean, sendRecordBean.getSchoolId() + "", sendRecordBean.getFailType(),sendRecordBean.getUserType());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}