UserControl.java
20.8 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
package com.sincere.haikangface.control;
import com.alibaba.fastjson.JSON;
import com.sincere.haikangface.bean.*;
import com.sincere.haikangface.CMSServer;
import com.sincere.haikangface.async.SendUserAsync;
import com.sincere.haikangface.bean.face.PermissionBean;
import com.sincere.haikangface.bean.face.UserAndPermission;
import com.sincere.haikangface.dao.UserDao;
import com.sincere.haikangface.fegin.HaikangfaceFegin;
import com.sincere.haikangface.service.impl.BaseService;
import com.sincere.haikangface.utils.*;
import com.sincere.haikangface.xiananDao.SendRecordDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@RequestMapping(value = "/facereco/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api("用户控制")
@Slf4j
public class UserControl {
@Autowired
SendUserAsync sendUserAsync;
@Autowired
UserDao userDao;
@Autowired
HaikangfaceFegin haikangfaceFegin;
@Autowired
CMSServer cmsServer;
@Autowired
SendRecordDao sendRecordDao;
@Autowired
BaseService baseService;
@RequestMapping(value = "sendPermiss", method = RequestMethod.POST)
@ApiOperation("下发权限给设备")
public boolean sendPermiss(@RequestBody PermissionBean permissionBean) {
log.error("permissionBean:{}", JSON.toJSONString(permissionBean));
FileUtils.getInstance().writeLogs("传入权限模板:" + JSON.toJSONString(permissionBean), "设置权限内容.txt");
if (!StringUtils.isEmpty(permissionBean.getDeviceIds())) {
return sendUserAsync.sendPermiss(permissionBean, 0);
}
return false;
}
@RequestMapping(value = "sendUsersAndPermiss", method = RequestMethod.POST)
@ApiOperation("下发指定教师用户权限给设备")
public boolean sendUsersAndPermiss(@RequestBody UserAndPermission userAndPermission) {
log.info("下发指定教师权限,权限信息permission:{}", JSON.toJSONString(userAndPermission));
FileUtils.getInstance().writeLogs(JSON.toJSONString(userAndPermission), "下发指定教师用户权限给设备.txt");
PermissionBean permissionBean = new PermissionBean();
permissionBean.setSchoolId(userAndPermission.getSchoolId());
permissionBean.setUserType(String.valueOf(userAndPermission.getUserType()));
permissionBean.setWeekDays(userAndPermission.getWeekDays());
return sendUserAsync.sendPermiss(permissionBean, 0);
}
@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) {
return baseService.sendImg2Device(filePath, card, name, deviceId, userType);
}
@RequestMapping(value = "sendCardAndImg1", method = RequestMethod.GET)
@ApiOperation("下发人脸给设备")
public boolean sendCardAndImg1(@RequestParam("filePath") String filePath, @RequestParam("card") String card,
@RequestParam("name") String name, @RequestParam("deviceId") String deviceId,
@RequestParam("userType") String userType) {
log.error("sendCardAndImg1:---------------------------------");
return baseService.sendImg2Device(filePath, card, name, deviceId, userType);
}
@RequestMapping(value = "sendImg2Devices", method = RequestMethod.POST)
@ApiOperation("本地下发人脸给设备")
public boolean sendImg2Devices(@RequestBody Images2Ddevices images2Ddevices) throws Exception {
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());
String devices = images2Ddevices.getDevices();
String imgPath = images2Ddevices.getImgPath();
String[] devStrs = devices.split(",");
File[] imgStrs = new File(imgPath).listFiles();
String schoolId = null;
log.error("sendImg2Devices:{}", images2Ddevices.toString());
if (null != imgStrs) {
for (int i = 0; i < imgStrs.length; i++) {
File filePath = imgStrs[i];//图片路径
if (filePath.exists()) {
String studentCode = filePath.getName().split("\\.")[0];
String targetPath = FileUtils.picPathComp + filePath.getName();
try {
CompressPic.CompressPic(filePath.getAbsolutePath(), targetPath);
} catch (Exception e) {
e.printStackTrace();
}
/**
* 下发给不同设备
*/
for (int j = 0; j < devStrs.length; j++) {
String devId = devStrs[j];
if (schoolId == null) schoolId = userDao.getSchoolIdWithDevId(devId);
StudentBean studentBean = null;
String card = null;
String name = null;
if (images2Ddevices.getUserType().equals("1")) {//老师
studentBean = userDao.getTeacherWithstudentcode(studentCode, schoolId);
card = studentBean.getTeacher_num();
name = studentBean.getName();
} else if (images2Ddevices.getUserType().equals("2")) {//学生
studentBean = userDao.getStudentWithstudentcode(studentCode, schoolId);
card = studentBean.getStudent_num();
name = studentBean.getName();
}
if (null != studentBean) {
if (cmsServer.getIsDeviceOnline(devId)) {
String cardNum = Long.parseLong(baseService.getCard(card), 16) + "";
sendUserAsync.sendStuToHaiKang(filePath.getAbsolutePath(),targetPath,cardNum, startTime, endTime,1, name, devId, images2Ddevices.getUserType(), 0,card);
} else {
sendUserAsync.uploadImgs(targetPath, card, name, devId, startTime, endTime, 1, images2Ddevices.getUserType());
}
} else {
log.error("学生对象不存在");
}
}
}
}
}
return true;
}
@RequestMapping(value = "sendFaces", method = RequestMethod.GET)
@ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备")
public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) {
String typeName = userType.equals("1") ? "Teacher" : "Student";
String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName;
File imgPathFile = new File(imgPath);//目录
String[] deviceIdsStr = deviceIds.split(",");
if (imgPathFile.exists()) {
File[] imgfiles = imgPathFile.listFiles();
if (null != imgfiles) {
for (int i = 0; i < imgfiles.length; i++) {
File file = imgfiles[i];//图片
String targetPath = FileUtils.picPathComp + file.getName();
try {
CompressPic.CompressPic(file.getAbsolutePath(), targetPath);
} catch (Exception e) {
e.printStackTrace();
}
if (file.exists()){
for (int j = 0; j < deviceIdsStr.length; j++) {
String deviceId = deviceIdsStr[j];
StudentBean studentBean = null;
String card = "", name = "";
if (userType.equals("1")) {
studentBean = userDao.getTeacherWithstudentcode(file.getName().split("\\.")[0], schoolId);
if (null != studentBean) {
card = studentBean.getTeacher_num();
name = studentBean.getName();
}
} else if (userType.equals("2")) {
studentBean = userDao.getStudentWithstudentcode(file.getName().split("\\.")[0], schoolId);
if (null != studentBean) {
card = studentBean.getStudent_num();
name = studentBean.getName();
}
}
if (!StringUtils.isEmpty(card)) {
baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, card, name, userType,Integer.valueOf(schoolId));
}
}
}
}
}
}
}
@RequestMapping(value = "sendErrorFaces", method = RequestMethod.GET)
@ApiOperation(value = "下发失败的人脸", notes = "下发失败的人脸")
@ApiImplicitParams({
@ApiImplicitParam(name = "deviceid", required = false),
@ApiImplicitParam(name = "userType", required = false),
@ApiImplicitParam(name = "schoolId", required = true)
})
public void sendErrorFaces(String schoolId, String deviceid, String userType) {
log.info("开始下发失败人脸:schoolId:" + schoolId + "---deviceid:" + deviceid + "---userType:" + userType);
//不传的话就默认失败表中的类型
if (StringUtils.isEmpty(userType)) userType = "0";
if (!StringUtils.isEmpty(deviceid)) {
baseService.sendFace(deviceid, Integer.parseInt(userType));
} else {
List<String> deviceIds = sendRecordDao.getDeviceIds(schoolId);
if (null != deviceIds) {
for (int j = 0; j < deviceIds.size(); j++) {
String deviceId = deviceIds.get(j);
baseService.sendFace(deviceId, Integer.parseInt(userType));
}
}
}
}
@RequestMapping(value = "sendFaceNotExits", method = RequestMethod.GET)
@ApiOperation(value = "下发学校下还没有下发的人脸给指定设备", notes = "下发学校下还没有下发的人脸给指定设备")
public void sendFaceNotExits(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) {
String typeName = userType.equals("1") ? "Teacher" : "Student";
String imgPath = "E:\\wwwhtdocs\\SmartCampus\\face17e50\\School" + schoolId + "\\" + typeName;
File imgPathFile = new File(imgPath);//目录
String[] deviceIdsStr = deviceIds.split(",");
if (imgPathFile.exists()) {
File[] imgfiles = imgPathFile.listFiles();
if (null != imgfiles) {
for (int i = 0; i < imgfiles.length; i++) {
File file = imgfiles[i];//图片
String targetPath = FileUtils.picPathComp + file.getName();
try {
CompressPic.CompressPic(file.getAbsolutePath(), targetPath);
} catch (Exception e) {
log.error("压缩图片失败",e);
}
if (file.exists()) {
for (int j = 0; j < deviceIdsStr.length; j++) {
String deviceId = deviceIdsStr[j];
StudentBean studentBean = null;
String card = "", name = "";
if (userType.equals("1")) {
studentBean = userDao.getTeacherWithstudentcode(file.getName().split("\\.")[0], schoolId);
if (null != studentBean) {
card = studentBean.getTeacher_num();
name = studentBean.getName();
}
} else if (userType.equals("2")) {
studentBean = userDao.getStudentWithstudentcode(file.getName().split("\\.")[0], schoolId);
if (null != studentBean) {
card = studentBean.getStudent_num();
name = studentBean.getName();
}
}
if (!StringUtils.isEmpty(card)) {
List<SendRecordBean> sendRecordBeans = sendRecordDao.getFaceSendSucess(card, deviceId);
if (sendRecordBeans == null || sendRecordBeans.size() == 0){
baseService.sendImg(file.getAbsolutePath(), targetPath, deviceId, card, name, userType,Integer.valueOf(schoolId));
}else {
log.info("人脸已经下发");
}
}
}
}
}
}
}
}
@RequestMapping(value = "sendFaceToDevices", method = RequestMethod.GET)
@ApiOperation(value = "下发单个用户给指定设备", notes = "下发单个用户给指定设备")
@ApiImplicitParams(
{@ApiImplicitParam(name = "deviceIds", value = "设备id用逗号,拼接"),
@ApiImplicitParam(name = "file", value = "100服务器上图片绝对路径")})
public void sendFaceToDevices(@RequestParam("deviceIds") String deviceIds, @RequestParam("userType") String userType,
@RequestParam("file") String file, @RequestParam("card") String card, @RequestParam("name") String name) {
String[] deviceIdsStr = deviceIds.split(",");
File file1 = new File(file);
String targetPath = FileUtils.picPathComp + file1.getName();
try {
CompressPic.CompressPic(file1.getAbsolutePath(), targetPath);
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 0; i < deviceIdsStr.length; i++) {
String deviceId = deviceIdsStr[i];
StudentBean studentBean = userDao.getStudentWithCard(card);
Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id();
baseService.sendImg(file1.getAbsolutePath(), targetPath, deviceId, card, name, userType,schoolId);
}
}
@RequestMapping(value = "DeleteCard", method = RequestMethod.GET)
@ApiOperation("删除人脸")
public boolean deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) {
StudentBean studentBean = userDao.getStudentWithCard(card);
Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id();
if (cmsServer.getIsDeviceOnline(deviceId)) {
String cardNo = Long.parseLong(baseService.getCard(card), 16) + "";
cmsServer.deleteCard(deviceId, cardNo,schoolId);
}else{
HttpUtil.deleteCard(deviceId, card);
}
return true;
}
@RequestMapping(value = "getCard", method = RequestMethod.GET)
@ApiOperation("获取设备人脸是否存在")
public boolean getCard(@RequestParam("deviceId") String deviceId,@RequestParam("card") String card) {
StudentBean studentBean = userDao.getStudentWithCard(card);
Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id();
String cardNo = Long.parseLong(baseService.getCard(card),16)+"";
return cmsServer.getFace(deviceId, cardNo,schoolId);
}
@RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET)
@ApiOperation("判断设备是否在线")
public boolean IsDeviceOnline(@RequestParam("deviceId") String deviceId) {
if (cmsServer.getIsDeviceOnline(deviceId)) {
return true;
} else {
return sendUserAsync.IsDeviceOnline(deviceId);
}
}
@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 "sss";
}
// @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 "";
}
@RequestMapping(value = "isTeacher", method = RequestMethod.GET)
@ApiOperation("测试教师点名")
public void isTeacher(@RequestParam("deviceId") String deviceId, @RequestParam("cardNo") String cardNo) {
try {
cmsServer.isTeacher(cardNo, deviceId);
} catch (Exception e) {
e.printStackTrace();
}
}
@RequestMapping(value = "sendToKB", method = RequestMethod.GET)
@ApiOperation("发送数据到看板")
public void sendToKB(@RequestParam("filePath") String filePath, @RequestParam("deviceid") String deviceid) {
try {
baseService.sendUserInfoToKB(new File(filePath), deviceid);
} catch (Exception e) {
e.printStackTrace();
}
}
}