UserControl.java
8.28 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
package com.sincere.haikangface.control;
import com.sincere.common.dto.smartCampus.SZ_AttendanceDto;
import com.sincere.common.util.BaiduApiUtiols;
import com.sincere.haikangface.CMSServer;
import com.sincere.haikangface.async.SendUserAsync;
import com.sincere.haikangface.bean.StudentInfo;
import com.sincere.haikangface.dao.UserDao;
import com.sincere.haikangface.fegin.HaikangfaceFegin;
import com.sincere.haikangface.utils.*;
import com.sincere.haikangface.xiananDao.SendRecordDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import sun.rmi.runtime.Log;
import java.io.*;
import java.math.BigInteger;
import java.util.List;
@RestController
@RequestMapping("/facereco/*")
@Api("用户控制")
public class UserControl {
@Autowired
SendUserAsync sendUserAsync;
@Autowired
UserDao userDao;
@Autowired
HaikangfaceFegin haikangfaceFegin;
// DeviceDao deviceDao;
@Autowired
CMSServer cmsServer;
@Autowired
SendRecordDao sendRecordDao;
SendRecoderUtils sendRecoderUtils;
@RequestMapping(value = "sendStuCardAndImg", method = RequestMethod.GET)
@ApiOperation("下发人脸给设备")
public boolean sendCardAndImg(@RequestParam("filePath") String filePath, @RequestParam("card") String card
, @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("startTime") String startTime,
@RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) {
try {
FileUtils.getInstance().writeLogs("filePath:" + filePath + " card:" + card + " name:" + name + " deviceId:" + deviceId, FileUtils.sendUserInfo);
long time = System.currentTimeMillis();
// if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png");
if (new File(filePath.trim()).exists()) {
String targetPath = FileUtils.picPathComp + new File(filePath).getName();
try {
int isPiliang = 0;//0:批量,1:单张
if (filePath.contains("face17e50")) {//批量发送
isPiliang = 0;
} else {//单图发送
isPiliang = 1;
}
sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16)+"", startTime, endTime, validTimeEnabled, name, deviceId, userType, isPiliang);
System.out.println("time:" + (System.currentTimeMillis() - time) / 1000);
} catch (Exception e) {
e.printStackTrace();
return false;
}
} else {
if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils();
sendRecoderUtils.sendFail(sendRecordDao, Long.parseLong(getCard(card), 16)+"", filePath, deviceId, userDao, "文件不存在", userType);
System.out.println("文件不存在:" + filePath);
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
// return HttpUtil.uploadImgs(filePath,card,name,deviceId,startTime,endTime,validTimeEnabled,userType);
}
@RequestMapping(value = "DeleteCard", method = RequestMethod.GET)
@ApiOperation("删除人脸")
public boolean deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) {
cmsServer.deleteCard(deviceId, Long.parseLong(getCard(card), 16) + "");
return true;
}
@RequestMapping(value = "getCard", method = RequestMethod.GET)
@ApiOperation("获取设备人脸是否存在")
public boolean getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) {
cmsServer.getFace(deviceId, Long.parseLong(getCard(card), 16) + "");
return true;
}
@RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET)
@ApiOperation("判断设备是否在线")
public boolean IsDeviceOnline(@RequestParam("deviceId") String deviceId) {
if (cmsServer.getIsDeviceOnline(deviceId)) {
return true;
} else {
return false;
}
/*if ( HttpUtil.IsDeviceOnline(deviceId)) {
return true;
} else {
return false;
}*/
}
@RequestMapping(value = "FaceUploadFile", method = RequestMethod.POST)
@ApiOperation("人脸图片上传")
public String FaceUploadFile(@RequestParam("file") MultipartFile file) {
String targetPath = FileUtils.picPathComp;
System.out.println("fileName:" + file.getOriginalFilename());
return "";
}
@RequestMapping(value = "getKaoqinTem", method = RequestMethod.GET)
@ApiOperation("根据设备获取考勤模板")
public String getKaoqinTem(@RequestParam("deviceId") String deviceId) {
SZ_AttendanceDto attendanceBean = haikangfaceFegin.selectAttendaceWithId(deviceId);
System.out.println("isKaoqin:"+attendanceBean.toString());
int isKaoqin = attendanceBean.getIsKaoqin();//获取考勤模板id
List<SZ_AttendanceDto> attendanceBeans = haikangfaceFegin.getAttensWithIsKaoqin(isKaoqin);//获取同一模板下的设备
String content = "";
for (int i = 0; i < attendanceBeans.size(); i++) {
String clientId = attendanceBeans.get(i).getClint_id();
if (!StringUtils.isEmpty(clientId)) content += clientId + ",";
}
return content.substring(0, content.lastIndexOf(","));
}
@RequestMapping(value = "addFace", method = RequestMethod.GET)
@ApiOperation("注册人脸")
public String addFace(@RequestParam("imgPath") String imgPath, @RequestParam("group_id") String group_id,
@RequestParam("user_id") String user_id, @RequestParam("user_info") String user_info) {
return BaiduApiUtiols.getInstance().registerFace(imgPath, group_id, user_id, user_info);
}
@RequestMapping(value = "searchFace", method = RequestMethod.GET)
@ApiOperation("搜索人脸")
public String searchFace(@RequestParam("imgPath") String imgPath, @RequestParam("group_id") String group_id,
@RequestParam("user_id") String user_id) {
return BaiduApiUtiols.getInstance().searchFace(imgPath, group_id, user_id);
}
@RequestMapping(value = "sendFiles", method = RequestMethod.GET)
@ApiOperation("批量下发人脸")
public String sendFiles() {
List<StudentInfo> studentBeans = userDao.getAllStus();
String filePath = "";
List<String> deviceId = userDao.getDeviceIdsWidthSchoolId(562);
for (int i = 0; i < studentBeans.size(); i++) {
StudentInfo studentBean = studentBeans.get(i);
filePath = "C://Student//" + studentBean.getStudentcode() + ".png";
System.out.println("filePath:" + new File(filePath).exists() + " devId:" + deviceId.toString());
if (!new File(filePath).exists())
FileUtils.getInstance().writeLogs(studentBean.getStudentcode(), FileUtils.studentcode);
for (int j = 0; j < deviceId.size(); j++) {
String devId = deviceId.get(j);
sendCardAndImg(filePath, studentBean.getStudent_num(), studentBean.getName(), devId, "2019-10-30 12:00:00", "2030-10-10 10:00:00",
1, "2");
}
}
return "";
}
private 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 "";
}
}
}