SendFaceBatchTask2.java
3.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
package com.example.dahua.async;
import com.example.dahua.bean.StudentBean;
import com.example.dahua.bean.UserInfoBean;
import com.example.dahua.dao.UserDao;
import com.example.dahua.utils.DateFormatUtil;
import com.example.dahua.xiananDao.SearchMapper;
import com.example.dahua.xiananDao.SendRecordDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
/**
* 多线程执行卡下发
* @author xuquan
* @date 2021/01/12 15:56
*/
@Slf4j
public class SendFaceBatchTask2 implements Runnable {
CountDownLatch begin;
CountDownLatch end;
UserDao userDao;
SendRecordDao sendRecordDao;
SearchMapper searchMapper;
Integer schoolId;
Integer roomId;
Integer type;
Integer outof;
String intime;
String clintId;
String startTime;
String endTime;
public SendFaceBatchTask2(UserDao userDao, SendRecordDao sendRecordDao, SearchMapper searchMapper, Integer schoolId, Integer roomId,
Integer type, Integer outof, String intime, String clintId, String startTime, String endTime, CountDownLatch begin, CountDownLatch end){
this.begin=begin;
this.end=end;
this.userDao=userDao;
this.sendRecordDao=sendRecordDao;
this.searchMapper=searchMapper;
this.schoolId=schoolId;
this.roomId=roomId;
this.type= type;
this.outof=outof;
this.intime=intime;
this.clintId=clintId;
this.startTime=startTime;
this.endTime=endTime;
}
@Override
public void run() {
try {
begin.await();
int num= (int)(Math.random()*50)+150;
List<StudentBean> studentIds = userDao.getStudentList(schoolId,1,null);
if(!CollectionUtils.isEmpty(studentIds)){
System.out.println("总数:"+studentIds.size());
for(int i=0;i<=studentIds.size();i++){
if(i==num){
return;
}
String cardNum = studentIds.get(i).getStudent_num();
String userId = studentIds.get(i).getUser_id();
String com = studentIds.get(i).getStudent_id();
String classId = studentIds.get(i).getClass_id();
String className = studentIds.get(i).getClass_name();
String name= studentIds.get(i).getName();
String mobile= studentIds.get(i).getParentMobile();
String sex = String.valueOf(studentIds.get(i).getSex());
String cid= UUID.randomUUID().toString().toUpperCase();
int count = sendRecordDao.getKaoQin(schoolId,cardNum,type,outof,startTime,endTime);;
System.out.println("count: "+count);
System.out.println("cardNum "+cardNum);
if(count ==0){
intime = DateFormatUtil.getDateAdd(intime);
searchMapper.insert(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime);
i++;
}
}
}
}catch (Exception e){
log.error("异常,信息:",e);
}finally {
end.countDown();
}
}
public static void main(String[] args) {
for(int i=1;i<20;i++){
int num= (int)(Math.random()*50)+150;
// int num= (int)(Math.random()*20)+30;
System.out.println(num);
}
}
}