SendRecoderUtils.java
5.61 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
package com.sincere.haikangface.utils;
import com.sincere.haikangface.bean.SendRecordBean;
import com.sincere.haikangface.bean.StudentBean;
import com.sincere.haikangface.dao.UserDao;
import com.sincere.haikangface.xiananDao.SendRecordDao;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class SendRecoderUtils {
/**
* 下发人脸成功
*
* @param sendRecordDao
* @param card
* @param faceUrl
* @param deviceId
* @param userDao
*/
public void sendSuccess(SendRecordDao sendRecordDao, String card, String faceUrl, String deviceId, UserDao userDao, String userType) {
// BigInteger bigInteger = new BigInteger(card);
long lon = Long.parseLong(card);
String resultCard = getCard(String.format("%08x", lon)).toUpperCase();
StudentBean studentBean = null;
String customerId = "";
switch (userType) {
case "1"://老师
studentBean = userDao.getTeacherWithCard(resultCard);
customerId = studentBean.getTeacher_id();
break;
case "2"://学生
studentBean = userDao.getStudentWithCard(resultCard);
customerId = studentBean.getStudent_id();
break;
case "3"://家长
break;
}
if (null != studentBean) {
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + "");
List<SendRecordBean> sendRecordBeans = sendRecordDao.getSuccessIsExitStu(deviceId, resultCard);
SendRecordBean sendRecordBean = null;
//处理重复添加的数据
if (null != sendRecordBeans && sendRecordBeans.size() > 1) {
for (int i = 0; i < sendRecordBeans.size(); i++) {
sendRecordDao.deleteFaceSuccess(sendRecordBeans.get(i).getNum(), sendRecordBeans.get(i).getDeviceID());
}
} else if (null != sendRecordBeans && sendRecordBeans.size() == 1) {
sendRecordBean = sendRecordBeans.get(0);
}
if (null == sendRecordBean) {
//添加成功日志
sendRecordDao.addFaceSuccess(customerId, deviceId, resultCard, studentBean.getName(), time, schoolName,
faceUrl, studentBean.getSchool_id(), Integer.parseInt(userType), 18);
} else {
sendRecordDao.updateFaceSuccess(deviceId, resultCard, time, faceUrl);
}
//删除下发失败表中的数据
sendRecordDao.deleteFaceFail(resultCard, deviceId);
} else {
System.out.println("用户不存在:" + resultCard);
}
}
/**
* 下发人脸失败
*
* @param sendRecordDao
* @param card
* @param faceUrl
* @param deviceId
* @param userDao
*/
public void sendFail(SendRecordDao sendRecordDao, String card, String faceUrl, String deviceId, UserDao userDao, String content, String userType) {
// BigInteger bigInteger = new BigInteger(card);
long lon = Long.parseLong(card);
String resultCard = getCard(String.format("%08x", lon)).toUpperCase();
StudentBean studentBean = null;
String customerId = "";
switch (userType) {
case "1"://老师
studentBean = userDao.getTeacherWithCard(resultCard);
customerId = studentBean.getTeacher_id();
break;
case "2"://学生
studentBean = userDao.getStudentWithCard(resultCard);
customerId = studentBean.getStudent_id();
break;
case "3"://家长
break;
}
// System.out.println("studentBean:" + studentBean);
if (null != studentBean) {
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String schoolName = userDao.getSchoolName(studentBean.getSchool_id() + "");
List<SendRecordBean> sendRecordBeans = sendRecordDao.getFailIsExit(deviceId, resultCard);
SendRecordBean sendRecordBean = null;
//处理重复添加的数据
if (null != sendRecordBeans && sendRecordBeans.size() > 1) {
for (int i = 0; i < sendRecordBeans.size(); i++) {
sendRecordDao.deleteFaceFail(sendRecordBeans.get(i).getNum(), sendRecordBeans.get(i).getDeviceID());
}
} else if (null != sendRecordBeans && sendRecordBeans.size() == 1) {
sendRecordBean = sendRecordBeans.get(0);
}
if (null == sendRecordBean) {
sendRecordDao.addFaceFail(customerId, deviceId, resultCard, studentBean.getName(), time, schoolName,
faceUrl, studentBean.getSchool_id(), content, 9, Integer.parseInt(userType), 18);
} else {
sendRecordDao.updateFaceFail(deviceId, resultCard, time, content);
}
} else {
System.out.println("用户不存在:" + resultCard);
}
}
public String getCard(String card) {
if (card.length() == 8) {
int length = card.length();
String result = card.substring(length - 2, length) + card.substring(length - 4, length - 2) + card.substring(length - 6, length - 4)
+ card.substring(length - 8, length - 6);
return result;
} else {
System.out.println("卡号位数不对:" + card);
return "";
}
}
}