SendFaceBatchTask253.java
3.27 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
package com.sincere.haikangface.async;
import com.sincere.haikangface.bean.StudentBean;
import com.sincere.haikangface.enums.EnumSzBusinessType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;
/**
* 多线程执行卡下发
* @author xuquan
* @date 2021/01/12 15:56
*/
@Slf4j
public class SendFaceBatchTask253 implements Runnable {
private String schoolId;
private String userType;
private List<StudentBean> students;
private String sno;
private SendUserAsync sendUserAsync;
CountDownLatch begin;
CountDownLatch end;
public SendFaceBatchTask253(String schoolId, String userType,String sno,List<StudentBean> students,
SendUserAsync sendUserAsync, CountDownLatch begin, CountDownLatch end){
this.userType=userType;
this.schoolId=schoolId;
this.students=students;
this.sno=sno;
this.sendUserAsync=sendUserAsync;
this.begin=begin;
this.end=end;
}
@Override
public void run() {
try {
begin.await();
String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, 10);
String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
//下发标识:详情见枚举 EnumHkOperateType
int validTimeEnabled = EnumSzBusinessType.EnumHkOperateType.ADD.code;
for(StudentBean studentBean : students){
try{
String photo= studentBean.getPhoto();
if (StringUtils.isBlank(photo)){
continue;
}
String userName= studentBean.getName();
String cardNum ="";
String typeName="";
if(userType.equals("1")){
cardNum = studentBean.getTeacher_num();
typeName= "Teacher";
}else {
cardNum = studentBean.getStudent_num();
typeName= "Student";
}
String path = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName;
//以学籍号为名的文件名
String fileName = photo.split(typeName+"/")[1];
//100服务器上人脸照绝对路径
String filePath = path+ "\\" + fileName;
Thread.sleep(1000);
//下发253服务器
sendUserAsync.uploadImgs(filePath, cardNum, userName, sno, startTime, endTime, validTimeEnabled, userType,Integer.parseInt(schoolId));
}catch (Exception e){
log.error("人脸下发失败");
e.printStackTrace();
continue;
}
}
}catch (Exception e){
log.error("下发人脸异常,信息:");
e.printStackTrace();
}finally {
end.countDown();
}
}
}