Commit fc3450829fea257b9a356b6891d56e0c1c4958fb

Authored by 徐泉
1 parent 3964921d
Exists in master

下发接口修改

cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
1 package com.example.dahua.async; 1 package com.example.dahua.async;
2 2
3 //import com.example.dahua.Gate.Gate; 3 //import com.example.dahua.Gate.Gate;
  4 +
  5 +import com.alibaba.fastjson.JSON;
4 import com.example.dahua.MyTask; 6 import com.example.dahua.MyTask;
5 -import com.example.dahua.bean.*; 7 +import com.example.dahua.bean.AttendanceBean;
  8 +import com.example.dahua.bean.SendRecordBean;
  9 +import com.example.dahua.bean.TeacherBean;
  10 +import com.example.dahua.bean.UserInfoBean;
6 import com.example.dahua.common.Res; 11 import com.example.dahua.common.Res;
7 import com.example.dahua.dao.UserDao; 12 import com.example.dahua.dao.UserDao;
  13 +import com.example.dahua.enums.*;
8 import com.example.dahua.lib.CompressPic; 14 import com.example.dahua.lib.CompressPic;
9 import com.example.dahua.lib.FilePath; 15 import com.example.dahua.lib.FilePath;
10 import com.example.dahua.lib.NetSDKLib; 16 import com.example.dahua.lib.NetSDKLib;
@@ -14,15 +20,11 @@ import com.example.dahua.utils.FileUtils; @@ -14,15 +20,11 @@ import com.example.dahua.utils.FileUtils;
14 import com.example.dahua.utils.HttpUtils; 20 import com.example.dahua.utils.HttpUtils;
15 import com.example.dahua.xiananDao.SendRecordDao; 21 import com.example.dahua.xiananDao.SendRecordDao;
16 import com.sun.jna.Memory; 22 import com.sun.jna.Memory;
  23 +import lombok.extern.slf4j.Slf4j;
17 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
18 -import org.springframework.http.HttpEntity;  
19 -import org.springframework.http.HttpHeaders;  
20 -import org.springframework.http.MediaType;  
21 import org.springframework.http.ResponseEntity; 25 import org.springframework.http.ResponseEntity;
22 import org.springframework.scheduling.annotation.Async; 26 import org.springframework.scheduling.annotation.Async;
23 import org.springframework.stereotype.Component; 27 import org.springframework.stereotype.Component;
24 -import org.springframework.util.LinkedMultiValueMap;  
25 -import org.springframework.util.MultiValueMap;  
26 import org.springframework.util.StringUtils; 28 import org.springframework.util.StringUtils;
27 import org.springframework.web.client.RestTemplate; 29 import org.springframework.web.client.RestTemplate;
28 30
@@ -34,6 +36,7 @@ import java.util.*; @@ -34,6 +36,7 @@ import java.util.*;
34 * 下发卡号的异步操作 36 * 下发卡号的异步操作
35 */ 37 */
36 @Component 38 @Component
  39 +@Slf4j
37 public class SendUserInfoTask { 40 public class SendUserInfoTask {
38 41
39 @Autowired 42 @Autowired
@@ -42,21 +45,32 @@ public class SendUserInfoTask { @@ -42,21 +45,32 @@ public class SendUserInfoTask {
42 @Autowired 45 @Autowired
43 SendRecordDao sendRecordDao; 46 SendRecordDao sendRecordDao;
44 47
  48 + /**
  49 + * 下发单个用户人脸任务
  50 + * @param file
  51 + * @param attendanceBeans
  52 + * @param userInfoBean
  53 + * @param schoolId
  54 + * @param failType
  55 + * @param userType
  56 + * @throws Exception
  57 + */
45 // @Async("taskExecutor") 58 // @Async("taskExecutor")
46 public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType, int userType) throws Exception { 59 public void doTaskOne(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String schoolId, int failType, int userType) throws Exception {
47 File studentFile = new File(file); 60 File studentFile = new File(file);
  61 + //学籍号
48 String studentCode = studentFile.getName().split("\\.")[0]; 62 String studentCode = studentFile.getName().split("\\.")[0];
49 //判断是否是副卡 63 //判断是否是副卡
50 String[] studentCodes = studentCode.split("_"); 64 String[] studentCodes = studentCode.split("_");
51 65
52 -  
53 - if (studentCodes.length > 1) {//副卡  
54 - 66 + //副卡
  67 + if (studentCodes.length > 1) {
55 String cardType = studentCodes[1]; 68 String cardType = studentCodes[1];
  69 + //获取卡号
56 String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), cardType); 70 String cardNum = userDao.getCardNum(userInfoBean.getStudent_id(), cardType);
57 userInfoBean.setStudent_num(cardNum); 71 userInfoBean.setStudent_num(cardNum);
58 -  
59 } 72 }
  73 + //设置下发记录
60 SendRecordBean sendRecordBean = new SendRecordBean(); 74 SendRecordBean sendRecordBean = new SendRecordBean();
61 sendRecordBean.setSchoolId(Integer.parseInt(schoolId)); 75 sendRecordBean.setSchoolId(Integer.parseInt(schoolId));
62 sendRecordBean.setSchoolName(userDao.getSchoolName(schoolId)); 76 sendRecordBean.setSchoolName(userDao.getSchoolName(schoolId));
@@ -65,9 +79,11 @@ public class SendUserInfoTask { @@ -65,9 +79,11 @@ public class SendUserInfoTask {
65 sendRecordBean.setNum(userInfoBean.getStudent_num()); 79 sendRecordBean.setNum(userInfoBean.getStudent_num());
66 sendRecordBean.setName(userInfoBean.getName()); 80 sendRecordBean.setName(userInfoBean.getName());
67 sendRecordBean.setImgPath(file); 81 sendRecordBean.setImgPath(file);
  82 + //用户id(即学生ID)
68 sendRecordBean.setCustomerid(userInfoBean.getStudent_id()); 83 sendRecordBean.setCustomerid(userInfoBean.getStudent_id());
69 sendRecordBean.setFailType(failType); 84 sendRecordBean.setFailType(failType);
70 - sendUserInfoToDev(file, attendanceBeans, userInfoBean, userType + "", sendRecordBean); 85 + //下发至设备
  86 + sendUserInfoToDev(file, attendanceBeans, userInfoBean, String.valueOf(userType), sendRecordBean);
71 } 87 }
72 88
73 // @Async("taskExecutor") 89 // @Async("taskExecutor")
@@ -215,26 +231,30 @@ public class SendUserInfoTask { @@ -215,26 +231,30 @@ public class SendUserInfoTask {
215 231
216 private synchronized boolean sendUserInfoToDev(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String userType, SendRecordBean sendRecordBean) { 232 private synchronized boolean sendUserInfoToDev(String file, List<AttendanceBean> attendanceBeans, UserInfoBean userInfoBean, String userType, SendRecordBean sendRecordBean) {
217 try { 233 try {
  234 + //用户信息
218 if (userInfoBean == null) { 235 if (userInfoBean == null) {
219 - System.out.println("学生用户不存在"); 236 + log.warn("学生用户信息不存在");
220 return false; 237 return false;
221 } 238 }
222 - if (attendanceBeans.size() == 0) {//"该学校下没有人脸设备"  
223 - System.out.println("该学校下没有人脸设备:");  
224 - sendRecordBean.setFailType(2);  
225 - sendRecordBean.setFailContent("图片目录不存在");  
226 - String schoolName = sendRecordDao.getSchoolDevice(sendRecordBean.getSchoolId(), 2);//判断是否已经记录改学校没有设备  
227 - if (StringUtils.isEmpty(schoolName)) {//不存在记录则添加,保证没有设备的学校记录只有一条  
228 - sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 2);//更新下发失败状态  
229 - addFailDace(sendRecordBean);  
230 - }  
231 - return false;  
232 - }  
233 - 239 + //卡号
234 String cardNum = userInfoBean.getStudent_num(); 240 String cardNum = userInfoBean.getStudent_num();
235 - System.out.println("cardNum:" + cardNum);  
236 if (StringUtils.isEmpty(cardNum) || cardNum.equals("null")) { 241 if (StringUtils.isEmpty(cardNum) || cardNum.equals("null")) {
237 - System.out.println("卡号为空"); 242 + log.warn("下发卡号为空");
  243 + return false;
  244 + }
  245 + //该学校下没有人脸设备
  246 + if (attendanceBeans.size() == 0) {
  247 + sendRecordBean.setFailType(EnumSendFaceType.NOT_EXIST_DEVICE.code);
  248 + sendRecordBean.setFailContent(EnumSendFaceType.NOT_EXIST_DEVICE.message);
  249 + //获取学校下发失败记录,判断是否已经记录该学校没有设备
  250 + String schoolName = sendRecordDao.getSchoolDevice(sendRecordBean.getSchoolId(), EnumSendFaceType.NOT_EXIST_DEVICE.code);
  251 + //不存在记录则添加,保证没有设备的学校记录只有一条
  252 + if (StringUtils.isEmpty(schoolName)) {
  253 + //更新下发失败状态
  254 + sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), EnumSendFaceType.NOT_EXIST_DEVICE.code);
  255 + addFailDace(sendRecordBean);
  256 + }
  257 + log.warn("该学校下没有人脸设备");
238 return false; 258 return false;
239 } 259 }
240 260
@@ -274,174 +294,235 @@ public class SendUserInfoTask { @@ -274,174 +294,235 @@ public class SendUserInfoTask {
274 } catch (Exception e) { 294 } catch (Exception e) {
275 e.printStackTrace(); 295 e.printStackTrace();
276 } 296 }
277 -  
278 - for (AttendanceBean attendanceBean :  
279 - attendanceBeans) { 297 + //下发至所有设备
  298 + for (AttendanceBean attendanceBean : attendanceBeans) {
280 pushCardAndFace(attendanceBean, userInfoBean.getUser_id(), userInfoBean.getStudent_num(), userInfoBean.getName(), memory, sendRecordBean,userType); 299 pushCardAndFace(attendanceBean, userInfoBean.getUser_id(), userInfoBean.getStudent_num(), userInfoBean.getName(), memory, sendRecordBean,userType);
281 } 300 }
282 } 301 }
283 302
  303 + /**
  304 + * 下发人脸/卡信息
  305 + * @param attendanceBean
  306 + * @param user_id
  307 + * @param student_num
  308 + * @param name
  309 + * @param memory
  310 + * @param sendRecordBean
  311 + * @param userType
  312 + */
284 private synchronized void pushCardAndFace(AttendanceBean attendanceBean, String user_id, String student_num, String name, Memory memory, SendRecordBean sendRecordBean,String userType) { 313 private synchronized void pushCardAndFace(AttendanceBean attendanceBean, String user_id, String student_num, String name, Memory memory, SendRecordBean sendRecordBean,String userType) {
285 try{ 314 try{
286 - sendRecordBean.setDeviceID(attendanceBean.getClint_id());  
287 - sendRecordBean.setSchoolId(Integer.parseInt(attendanceBean.getSchool_id()));  
288 - sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));  
289 - sendRecordBean.setSchoolName(userDao.getSchoolName(attendanceBean.getSchool_id()));  
290 - String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());  
291 - Calendar calendar = Calendar.getInstance();  
292 - calendar.add(Calendar.YEAR, 4);  
293 - String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());  
294 - int bCardFlags = -1;//记录集编号,存在于设备的  
295 - bCardFlags = userDao.getRecordNo(user_id, attendanceBean.getClint_id()) == null ? -1 : Integer.parseInt(userDao.getRecordNo(user_id, attendanceBean.getClint_id()));  
296 -  
297 - NetSDKLib.LLong loginHandleLong = MyTask.lLongMap.get(attendanceBean.getClint_id());  
298 -// System.out.println("loginHandleLong:" + loginHandleLong + MyTask.lLongMap.toString() + " 设备ID:" + attendanceBean.getClint_id());  
299 -// System.out.println("loginHandleLong:" +loginHandleLong);  
300 - if (loginHandleLong == null) {  
301 - System.out.println("设备不在线:" + attendanceBean.getClint_id());  
302 - FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices);  
303 - String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id());  
304 - sendRecordBean.setFailType(2);  
305 - sendRecordBean.setFailContent("设备不在线");  
306 - if (!StringUtils.isEmpty(deviceId)) {  
307 - sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 2);//更新下发失败状态  
308 - addFailDace(sendRecordBean);  
309 - } 315 + sendRecordBean.setDeviceID(attendanceBean.getClint_id());
  316 + sendRecordBean.setSchoolId(Integer.parseInt(attendanceBean.getSchool_id()));
  317 + sendRecordBean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
  318 + sendRecordBean.setSchoolName(userDao.getSchoolName(attendanceBean.getSchool_id()));
310 319
311 - } else {  
312 - boolean bFaceFalgs = false; 320 + String startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  321 + Calendar calendar = Calendar.getInstance();
  322 + calendar.add(Calendar.YEAR, 4);
  323 + String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
313 324
314 - String cardNum = cardNo(student_num);  
315 -// GateModule.getFace(user_id, loginHandleLong);  
316 -// GateModule.getUser(user_id, loginHandleLong);  
317 -// GateModule.getCard(cardNum, loginHandleLong);  
318 - if (bCardFlags != -1) {//修改卡信息  
319 - int newRecordNo=0;  
320 - int bFaceFalgsInt=0;  
321 -  
322 - newRecordNo=GateModule.modifyCard(bCardFlags, cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1),  
323 - 0, 0, 1, startTime, endTime, loginHandleLong, userType);  
324 - if(newRecordNo==1){  
325 - userDao.updateRecordNo(user_id, bCardFlags, attendanceBean.getClint_id());}  
326 -  
327 - bFaceFalgsInt = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong);  
328 - if(bFaceFalgsInt==1) {//1照片修改成功  
329 - bFaceFalgs=true; 325 + /**
  326 + * 注:用户下发逻辑
  327 + * 下发时,先从下发记录表:SZ_Student_RecoderNo 获取当前用户下发记录集编号,存在于设备的,新增卡号时返回,
  328 + * 若存在记录集编号,则表示用户已下发过,执行修改用户信息,反之,则新增下发用户人脸、卡信息
  329 + */
  330 +
  331 + //人脸下发成功标识:false:失败 true:成功
  332 + boolean bFaceFalgs = false;
  333 + //卡下发成功标识:false:失败 true:成功
  334 + boolean bCardFlags = false;
  335 + //卡操作错误号
  336 + String cardErrNum ="";
  337 + //人脸操作错误号
  338 + String faceErrNum ="";
  339 + //新的记录集编号
  340 + int newRecordNo = 0;
  341 + //获取记录集编号
  342 + String recordNo = userDao.getRecordNo(user_id, attendanceBean.getClint_id());
  343 + if(!StringUtils.isEmpty(recordNo)){
  344 + bCardFlags = true;
  345 + }
  346 + //登录设备
  347 + NetSDKLib.LLong loginHandleLong = MyTask.lLongMap.get(attendanceBean.getClint_id());
  348 + log.info("设备ID: {},设备登录句柄: {}",loginHandleLong,attendanceBean.getClint_id() );
  349 +
  350 + //若设备不在线时,且人脸下发失败表中存在记录,则执行修改下发失败状态为:设备不在线
  351 + if (loginHandleLong == null) {
  352 + log.info("设备不在线, 设备ID: {} ",attendanceBean.getClint_id() );
  353 + FileUtils.getInstance().writeLogs("设备不在线:" + attendanceBean.getClint_id(), FileUtils.devices);
  354 + //设备不在线
  355 + sendRecordBean.setFailType(EnumSendFaceType.NOT_ONLINE_DEVICE.code);
  356 + sendRecordBean.setFailContent(EnumSendFaceType.NOT_ONLINE_DEVICE.message);
  357 + //判断该学校设备ID对应失败记录是否存在:Face_SendFail
  358 + String deviceId = sendRecordDao.getFailIsExit(attendanceBean.getClint_id(), attendanceBean.getSchool_id());
  359 + if (!StringUtils.isEmpty(deviceId)) {
  360 + //更新下发失败状态
  361 + sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), EnumSendFaceType.NOT_ONLINE_DEVICE.code);
  362 + //添加下发失败记录
  363 + addFailDace(sendRecordBean);
  364 + }
  365 + } else {
  366 + log.info("=================开始执行下发人脸及卡号任务=================");
  367 + //卡号取反
  368 + String cardNum = cardNo(student_num);
  369 + //bCardFlags = true, 存在下发记录,则存在下发记录集编号,执行修改卡、人脸信息
  370 + if (bCardFlags) {
  371 + //修改设备卡信息
  372 + boolean isEditCard = GateModule.modifyCard(Integer.parseInt(recordNo),cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1),
  373 + Res.string().getCardTypeInt(1), 0, 0, 1, startTime, endTime, loginHandleLong, userType,cardErrNum);
  374 +
  375 + if (isEditCard) {
  376 + //修改卡成功, 更新下发记录集编号表
  377 + userDao.updateRecordNo(user_id, Integer.parseInt(recordNo), attendanceBean.getClint_id());
  378 + //修改卡成功, 更新设备用户人脸信息
  379 + boolean isEditFace = GateModule.modifyFaceInfo(user_id, memory, loginHandleLong,faceErrNum);
  380 + //修改卡信息成功,但是人脸修改不成功的话,就需要新增人脸
  381 + if (!isEditFace) {
  382 + bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong,faceErrNum);
  383 + }
  384 + }else{
  385 + //设备修改卡信息失败,则删除下发记录集编号表记录:SZ_Student_RecoderNo,重新下发.
  386 + userDao.deleteRecordNo(user_id, Integer.parseInt(recordNo));
  387 + //重新下发卡号至设备
  388 + newRecordNo = GateModule.insertCard(cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1),
  389 + Res.string().getCardTypeInt(1), 0, 1, 1, startTime, endTime, loginHandleLong,userType,cardErrNum);
  390 +
  391 + //下发卡至设备,返回值不为-1为下发成功,保存下发记录集编号表
  392 + if (newRecordNo != -1) {
  393 + userDao.saveRecordNo(user_id, newRecordNo, name, attendanceBean.getClint_id());//存储记录集编号
  394 + }
  395 + //添加人脸
  396 + bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong,faceErrNum);
330 } 397 }
331 - else{bFaceFalgs=false;}  
332 - //卡号添加成功,但是人脸不成功的话,就需要新增人脸  
333 - if (!bFaceFalgs)  
334 - bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong);  
335 - else{  
336 - userDao.deleteRecordNo(user_id, bCardFlags);  
337 - bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456" 398 +
  399 + } else {
  400 + //新增卡信息, 新增人脸信息至设备
  401 + newRecordNo = GateModule.insertCard(cardNum, user_id, name, "123456"
338 , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1 402 , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1
339 - , 1, startTime, endTime, loginHandleLong,userType);  
340 - if (bCardFlags != -1) {  
341 - int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号 403 + , 1, startTime, endTime, loginHandleLong,userType,cardErrNum);
  404 +
  405 + //下发卡至设备,返回值不为-1为下发成功,保存下发记录集编号表
  406 + if (newRecordNo != -1) {
  407 + userDao.saveRecordNo(user_id, newRecordNo, name, attendanceBean.getClint_id());
342 } 408 }
343 //添加人脸 409 //添加人脸
344 - bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong);  
345 - } 410 + bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong,faceErrNum);
346 411
347 - } else {//新增卡信息  
348 -  
349 - bCardFlags = GateModule.insertCard(cardNum, user_id, name, "123456"  
350 - , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1  
351 - , 1, startTime, endTime, loginHandleLong,userType);  
352 -  
353 - if (bCardFlags != -1) {  
354 - int index = userDao.saveRecordNo(user_id, bCardFlags, name, attendanceBean.getClint_id());//存储记录集编号  
355 } 412 }
356 -  
357 - //添加人脸  
358 - bFaceFalgs = GateModule.addFaceInfo(user_id, memory, loginHandleLong);  
359 -  
360 - }  
361 -  
362 - if (bCardFlags != -1 && bFaceFalgs) {  
363 - FileUtils.getInstance().writeLogs("下发人脸和卡号成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt);  
364 - System.out.println("人脸下发成功" + "sendRecordBean:" + sendRecordBean);  
365 -  
366 - //先判断是否已经存在了  
367 - List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceSucceIsexit(sendRecordBean.getDeviceID(), String.valueOf(sendRecordBean.getSchoolId()), sendRecordBean.getCustomerid());  
368 - if (sendRecordBeanList.size() > 0) {  
369 -  
370 - //删除重复数据  
371 - for (int i = 0; i < sendRecordBeanList.size(); i++) {  
372 - sendRecordDao.deleteFaceSuccess(sendRecordBeanList.get(i).getDeviceID(), sendRecordBeanList.get(i).getNum()); 413 + /**
  414 + * 人脸和卡都下发成功
  415 + */
  416 + if (bCardFlags && bFaceFalgs) {
  417 + FileUtils.getInstance().writeLogs("下发人脸和卡号成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt);
  418 + log.info("下发人脸和卡号成功, sendRecordBean: "+ JSON.toJSONString(sendRecordBean));
  419 +
  420 + //人脸下发成功记录, 先判断是否已经存在了
  421 + List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceSucceIsexit(sendRecordBean.getDeviceID(), String.valueOf(sendRecordBean.getSchoolId()), sendRecordBean.getCustomerid());
  422 + if (sendRecordBeanList.size() > 0) {
  423 + //删除重复数据
  424 + for (int i = 0; i < sendRecordBeanList.size(); i++) {
  425 + sendRecordDao.deleteFaceSuccess(sendRecordBeanList.get(i).getDeviceID(), sendRecordBeanList.get(i).getNum());
  426 + }
373 } 427 }
  428 + //重新添加人脸下发记录
  429 + sendRecordDao.addFaceSuccess(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(),
  430 + sendRecordBean.getSchoolName(), sendRecordBean.getImgPath(), sendRecordBean.getSchoolId(), sendRecordBean.getUserType(), 22);
374 431
375 -// //更新数据  
376 -// sendRecordDao.updateFaceSuccess(sendRecordBean.getTime(), sendRecordBean.getDeviceID(), sendRecordBean.getNum());  
377 - } else { 432 + //重新下发时,删除之前失败记录
  433 + if (sendRecordBean.getFailType() != 0){
  434 + sendRecordDao.deleteFaceFail(sendRecordBean.getNum(), sendRecordBean.getDeviceID());
  435 + }
  436 + }
  437 + /**
  438 + * 人脸和卡都下发失败
  439 + */
  440 + if (!bCardFlags && !bFaceFalgs) {
  441 + FileUtils.getInstance().writeLogs("下发人脸和卡号失败:" + cardNum + " user_id: " + user_id + " loginHandleLong: " + loginHandleLong, FileUtils.sendUserErrTxt);
  442 + log.info("下发人脸和卡号失败, sendRecordBean: "+ JSON.toJSONString(sendRecordBean));
  443 + //失败信息
  444 + String failContent = analysisErrorMsg(cardErrNum,faceErrNum);
  445 + sendRecordBean.setFailType(EnumSendFaceType.FACE_AND_CARD_FAIL.code);
  446 + sendRecordBean.setFailContent(failContent);
  447 + sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), EnumSendFaceType.FACE_AND_CARD_FAIL.code);
  448 + addFailDace(sendRecordBean);
  449 + }
  450 + /**
  451 + * 下发卡号成功,下发人脸失败,
  452 + */
  453 + if (bCardFlags && !bFaceFalgs) {
  454 + FileUtils.getInstance().writeLogs("下发卡号成功,下发人脸失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt);
  455 + log.info("下发卡号成功,下发人脸失败, sendRecordBean: " + JSON.toJSONString(sendRecordBean));
  456 + //失败信息
  457 + String failContent = analysisErrorMsg(cardErrNum,faceErrNum);
  458 + sendRecordBean.setFailType(EnumSendFaceType.FACE_FAIL_CARD_SUCCESS.code);
  459 + sendRecordBean.setFailContent(failContent);
  460 + sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), EnumSendFaceType.FACE_FAIL_CARD_SUCCESS.code);
  461 + addFailDace(sendRecordBean);
  462 + }
  463 + /**
  464 + * 下发卡号失败,下发人脸成功,
  465 + * 注:此一般不存在
  466 + */
  467 + if (!bCardFlags && bFaceFalgs) {
  468 + FileUtils.getInstance().writeLogs("卡信息已存在,下发人脸成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt);
  469 + log.info("-----------卡信息已存在,添加人脸成功----------");
378 } 470 }
379 - int index = sendRecordDao.addFaceSuccess(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(),  
380 - sendRecordBean.getSchoolName(), sendRecordBean.getImgPath(), sendRecordBean.getSchoolId(), sendRecordBean.getUserType(), 22);  
381 -// File imgFile = new File(sendRecordBean.getImgPath());  
382 -// imgFile.deleteOnExit();  
383 - //删除成功  
384 - if (sendRecordBean.getFailType() != 0)  
385 - sendRecordDao.deleteFaceFail(sendRecordBean.getNum(), sendRecordBean.getDeviceID());  
386 -  
387 - }  
388 -  
389 - // 添加卡信息和人脸失败  
390 - if (bCardFlags == -1 && !bFaceFalgs) {  
391 - FileUtils.getInstance().writeLogs("下发人脸和卡号失败:" + cardNum + " user_id: " + user_id + " loginHandleLong: " + loginHandleLong, FileUtils.sendUserErrTxt);  
392 -// System.out.println("添加卡信息和人脸失败");  
393 - System.out.println("下发人脸和卡号失败" + "sendRecordBean:" + sendRecordBean.getDeviceID() + " ," + sendRecordBean.getNum() + "," + loginHandleLong + ",bCardFlags:" + bCardFlags + "\r\n");  
394 - sendRecordBean.setFailContent("下发人脸和卡号失败");  
395 - sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 7);//更新下发失败状态  
396 - sendRecordBean.setFailType(8);  
397 - addFailDace(sendRecordBean);  
398 - }  
399 -  
400 - // 添加卡信息成功,添加人脸失败  
401 - if (bCardFlags != -1 && !bFaceFalgs) {  
402 - FileUtils.getInstance().writeLogs("下发卡号成功,人脸失败:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserErrTxt);  
403 -// System.out.println("添加卡信息成功,添加人脸失败");  
404 - System.out.println("customerId:" + sendRecordBean.getCustomerid() + " deviceId:" + sendRecordBean.getDeviceID() + " failType:" + sendRecordBean.getFailType() + "\r\n");  
405 - sendRecordDao.updateFace(sendRecordBean.getNum(), sendRecordBean.getDeviceID(), sendRecordBean.getFailType(), 5);//更新下发失败状态  
406 - sendRecordBean.setFailContent("下发卡号成功,人脸失败:照片特征值提取失败");  
407 - sendRecordBean.setFailType(5);  
408 - addFailDace(sendRecordBean);  
409 - }  
410 -  
411 - // 卡信息已存在,添加人脸成功  
412 - if (bCardFlags == -1 && bFaceFalgs) {  
413 - FileUtils.getInstance().writeLogs("下发人脸成功:" + cardNum + " " + attendanceBean.getClint_id(), FileUtils.sendUserSucTxt);  
414 - System.out.println("卡信息已存在,添加人脸成功-----------\n");  
415 } 471 }
416 - }  
417 } catch (Exception e) { 472 } catch (Exception e) {
418 e.printStackTrace(); 473 e.printStackTrace();
419 } 474 }
420 } 475 }
421 476
422 - //人脸发送失败信息添加 477 + /**
  478 + * 解析下发异常信息
  479 + * @param cardErrNum
  480 + * @param faceErrNum
  481 + * @return
  482 + */
  483 + private String analysisErrorMsg(String cardErrNum,String faceErrNum){
  484 + StringBuffer sb = new StringBuffer();
  485 + //卡异常信息
  486 + if(!StringUtils.isEmpty(cardErrNum)){
  487 + String message = EnumSendCardErrorType.getByCode(cardErrNum).getMessage();
  488 + sb.append("卡:").append(message).append("+");
  489 + }
  490 + //人脸异常信息
  491 + if(!StringUtils.isEmpty(faceErrNum)){
  492 + String message = EnumSendFaceErrorType.getByCode(faceErrNum).getMessage();
  493 + sb.append("人脸:").append(message);
  494 + }
  495 + return sb.toString();
  496 + }
  497 +
  498 +
  499 + /**
  500 + * 添加人脸下发失败记录
  501 + * @param sendRecordBean
  502 + */
423 private void addFailDace(SendRecordBean sendRecordBean) { 503 private void addFailDace(SendRecordBean sendRecordBean) {
424 -// System.out.println("sendRecordBean:" + sendRecordBean != null ? sendRecordBean.toString() : "不存在"); 504 + //获取指定设备指定用户的人脸失败记录
425 List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceFailIsExit(sendRecordBean.getDeviceID(), sendRecordBean.getCustomerid()); 505 List<SendRecordBean> sendRecordBeanList = sendRecordDao.getFaceFailIsExit(sendRecordBean.getDeviceID(), sendRecordBean.getCustomerid());
426 - 506 + if(sendRecordBeanList.size() ==0){
  507 + return;
  508 + }
  509 + //删除失败记录
427 for (int i = 0; i < sendRecordBeanList.size(); i++) { 510 for (int i = 0; i < sendRecordBeanList.size(); i++) {
428 sendRecordDao.deleteFaceFail(sendRecordBeanList.get(i).getNum(), sendRecordBeanList.get(i).getDeviceID()); 511 sendRecordDao.deleteFaceFail(sendRecordBeanList.get(i).getNum(), sendRecordBeanList.get(i).getDeviceID());
429 } 512 }
430 -  
431 -// String name = sendRecordDao.getFailNameIsExit(sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getFailType());  
432 -  
433 -// if (StringUtils.isEmpty(name)) {  
434 - 513 + //TODO 不明含义
435 if (sendRecordBean.getFailType() == 5) sendRecordBean.setFailType(8); 514 if (sendRecordBean.getFailType() == 5) sendRecordBean.setFailType(8);
  515 + //
  516 + String rootPath = sendRecordBean.getUserType() == EnumSzBusinessType.EnumUserType.TEACHER.code ? "Teacher" : "Student" ;
  517 + //人脸路径
  518 + String imagePath = sendRecordBean.getImgPath().replace("C:/imgCom", String.format("E:\\wwwhtdocs\\smartcampus\\face17e5\\School%s\\%s", sendRecordBean.getSchoolId(), rootPath));
436 519
437 - String imagePath = sendRecordBean.getImgPath().replace("C:/imgCom",  
438 - String.format("E:\\wwwhtdocs\\smartcampus\\face17e5\\School%s\\%s", sendRecordBean.getSchoolId(), sendRecordBean.getUserType() == 1 ? "Teacher" : "Student"));  
439 - 520 + //添加失败记录
440 sendRecordDao.addFaceFail(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(), 521 sendRecordDao.addFaceFail(sendRecordBean.getCustomerid(), sendRecordBean.getDeviceID(), sendRecordBean.getNum(), sendRecordBean.getName(), sendRecordBean.getTime(),
441 - sendRecordBean.getSchoolName(), imagePath, sendRecordBean.getSchoolId(), sendRecordBean.getFailContent(), sendRecordBean.getFailType(), sendRecordBean.getUserType(), 22);  
442 -// } 522 + sendRecordBean.getSchoolName(), imagePath, sendRecordBean.getSchoolId(), sendRecordBean.getFailContent(), sendRecordBean.getFailType(), sendRecordBean.getUserType(), EnumDeviceType.DH_FACE.deviceType);
443 } 523 }
444 524
  525 +
445 public String cardNo(String cardDex) { 526 public String cardNo(String cardDex) {
446 527
447 String cardR = ""; 528 String cardR = "";
cloud/dahua/src/main/java/com/example/dahua/bean/SendRecordBean.java
@@ -7,27 +7,27 @@ import java.io.Serializable; @@ -7,27 +7,27 @@ import java.io.Serializable;
7 */ 7 */
8 public class SendRecordBean implements Serializable { 8 public class SendRecordBean implements Serializable {
9 9
10 -  
11 - private String customerid;//用户编号  
12 - 10 + //用户编号:学生student_id;老师teacher_id
  11 + private String customerid;
  12 + //卡号
13 private String Num; 13 private String Num;
14 - 14 + //用户姓名
15 private String Name; 15 private String Name;
16 - 16 + //学校ID
17 private int schoolId; 17 private int schoolId;
18 -  
19 - private String schoolName;//下发结果  
20 - 18 + //学校名
  19 + private String schoolName;
  20 + //设备iD
21 private String deviceID; 21 private String deviceID;
22 -  
23 - private String imgPath;//下发的图片路径  
24 - 22 + //下发的图片路径
  23 + private String imgPath;
  24 + //用户类型
25 private int userType; 25 private int userType;
26 - 26 + //下发时间
27 private String time; 27 private String time;
28 - 28 + //下发失败原因
29 private String failContent; 29 private String failContent;
30 - 30 + //下发失败类型:详情见枚举:EnumSendFaceType
31 private int failType; 31 private int failType;
32 32
33 33
cloud/dahua/src/main/java/com/example/dahua/control/FileControl.java
@@ -42,6 +42,16 @@ public class FileControl { @@ -42,6 +42,16 @@ public class FileControl {
42 @Autowired 42 @Autowired
43 UserDao userDao; 43 UserDao userDao;
44 44
  45 + /**
  46 + * 单个人脸下发至设备
  47 + * @param file
  48 + * @param schoolId
  49 + * @param studentCode
  50 + * @param clint_type
  51 + * @param userType
  52 + * @param deviceId
  53 + * @return
  54 + */
45 @RequestMapping(method = RequestMethod.POST, value = "uploadImg") 55 @RequestMapping(method = RequestMethod.POST, value = "uploadImg")
46 public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, 56 public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId,
47 @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type, 57 @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type,
@@ -67,6 +77,11 @@ public class FileControl { @@ -67,6 +77,11 @@ public class FileControl {
67 return "0"; 77 return "0";
68 } 78 }
69 79
  80 + /**
  81 + * 权限下发至设备
  82 + * @param permissionBean
  83 + * @return
  84 + */
70 @RequestMapping(value = "sendPermission", method = RequestMethod.POST) 85 @RequestMapping(value = "sendPermission", method = RequestMethod.POST)
71 @ApiOperation(value = "设置权限") 86 @ApiOperation(value = "设置权限")
72 public boolean sendPermission(@RequestBody PermissionBean permissionBean) { 87 public boolean sendPermission(@RequestBody PermissionBean permissionBean) {
cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java
@@ -48,7 +48,14 @@ public class UserControl { @@ -48,7 +48,14 @@ public class UserControl {
48 @Autowired 48 @Autowired
49 UserDao userDao; 49 UserDao userDao;
50 50
51 - 51 + /**
  52 + * 单个人脸下发至设备
  53 + * @param file
  54 + * @param schoolId
  55 + * @param studentCode
  56 + * @param clint_type
  57 + * @return
  58 + */
52 @RequestMapping(value = "uploadImgAndUserInfo", method = RequestMethod.GET) 59 @RequestMapping(value = "uploadImgAndUserInfo", method = RequestMethod.GET)
53 @ApiOperation(value = "上传用户信息") 60 @ApiOperation(value = "上传用户信息")
54 public boolean uploadImgAndUserInfo(@RequestParam("file") String file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type) { 61 public boolean uploadImgAndUserInfo(@RequestParam("file") String file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode, @RequestParam("clint_type") String clint_type) {
@@ -56,6 +63,11 @@ public class UserControl { @@ -56,6 +63,11 @@ public class UserControl {
56 return HttpUtils.uploadImgs(new File(file), schoolId, studentCode, clint_type, file.contains("Teacher") ? 1 : 2,""); 63 return HttpUtils.uploadImgs(new File(file), schoolId, studentCode, clint_type, file.contains("Teacher") ? 1 : 2,"");
57 } 64 }
58 65
  66 + /**
  67 + * 权限下发至设备
  68 + * @param permissionBean
  69 + * @return
  70 + */
59 @RequestMapping(value = "sendPermission", method = RequestMethod.POST) 71 @RequestMapping(value = "sendPermission", method = RequestMethod.POST)
60 @ApiOperation(value = "设置权限") 72 @ApiOperation(value = "设置权限")
61 public boolean sendPermission(@RequestBody PermissionBean permissionBean) { 73 public boolean sendPermission(@RequestBody PermissionBean permissionBean) {
@@ -69,6 +81,12 @@ public class UserControl { @@ -69,6 +81,12 @@ public class UserControl {
69 return true; 81 return true;
70 } 82 }
71 83
  84 + /**
  85 + * 批量下发人脸
  86 + * @param deviceIds
  87 + * @param schoolId
  88 + * @param userType
  89 + */
72 @RequestMapping(value = "sendFaces", method = RequestMethod.GET) 90 @RequestMapping(value = "sendFaces", method = RequestMethod.GET)
73 @ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备") 91 @ApiOperation(value = "下发学校下所有人脸给指定设备", notes = "下发所有人脸给指定设备")
74 public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) { 92 public void sendFaces(@RequestParam("deviceIds") String deviceIds, @RequestParam("schoolId") String schoolId, @RequestParam("userType") String userType) {
cloud/dahua/src/main/java/com/example/dahua/enums/EnumDeviceType.java 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +package com.example.dahua.enums;
  2 +
  3 +/**
  4 + * 设备类型枚举
  5 + *
  6 + * @author xuquan
  7 + * @date 2020/11/11 16:06
  8 + */
  9 +
  10 +public enum EnumDeviceType {
  11 +
  12 + SCHOOL_CARD(1, "校牌"),
  13 + CLASS_CARD(2, "班牌"),
  14 + CLOUD_WINDOW(4, "云视窗"),
  15 + ZJ_CONTROL(6, "闸机控制器"),
  16 + LOAN_PERIOD(7, "话机"),
  17 + HK_FACE(18, "海康人脸设备"),
  18 + FACE(19, "人脸设备"),
  19 + DH_FACE(22, "大华人脸设备"),
  20 + HK_ZW(23, "海康指纹机"),
  21 + ZK_ZW(24, "中控指纹机"),
  22 + BG_FACE_WG(25, "博观人脸带温感"),
  23 + BG_FACE_CG(26, "博观人脸常规"),
  24 + LQ_QS(27, "乐清寝室看板"),
  25 + HK_FACE_YTJ(28, "海康人脸权限一体机"),
  26 + DH_FACE_YTJ(29, "大华人脸权限一体机");
  27 +
  28 + public final int deviceType;
  29 + public final String deviceName;
  30 +
  31 + EnumDeviceType(int deviceType, String deviceName) {
  32 + this.deviceType = deviceType;
  33 + this.deviceName = deviceName;
  34 + }
  35 +
  36 +}
cloud/dahua/src/main/java/com/example/dahua/enums/EnumSendCardErrorType.java 0 → 100644
@@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
  1 +package com.example.dahua.enums;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +
  5 +/**
  6 + *下发卡常见异常码、异常描述枚举
  7 + * @author xuquan
  8 + * @date 2020/11/11 15:19
  9 + */
  10 +
  11 +public enum EnumSendCardErrorType {
  12 +
  13 + CHECK_DATA_ERR_21("21", "对返回数据的校验出错"),
  14 + EXIST_USER_146("146", "用户已存在"),
  15 + NOT_ONLINE_USER_147("147", "用户不存在"),
  16 + UNKNOWN_1091("1091" , "未知错误"),
  17 + UNKNOWN_1147("1147" , "未知错误"),
  18 + UNKNOWN_1162("1162", "未知错误");
  19 +
  20 + public final String code;
  21 + public final String message;
  22 +
  23 + public String getCode() {
  24 + return code;
  25 + }
  26 +
  27 + public String getMessage() {
  28 + return message;
  29 + }
  30 +
  31 + EnumSendCardErrorType(String code, String message) {
  32 + this.code = code;
  33 + this.message = message;
  34 + }
  35 +
  36 + /**
  37 + * 根据key获得具体的值
  38 + */
  39 + public static EnumSendCardErrorType getByCode(String code){
  40 + if(StringUtils.isBlank(code)){
  41 + return null;
  42 + }
  43 + for(EnumSendCardErrorType enums: EnumSendCardErrorType.values()){
  44 + if(enums.getCode().equals(code)){
  45 + return enums;
  46 + }
  47 + }
  48 + return null;
  49 + }
  50 +
  51 +}
cloud/dahua/src/main/java/com/example/dahua/enums/EnumSendFaceErrorType.java 0 → 100644
@@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
  1 +package com.example.dahua.enums;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +
  5 +/**
  6 + * 下发人脸常见异常码、异常描述枚举
  7 + * @author xuquan
  8 + * @date 2020/11/11 15:23
  9 + */
  10 +public enum EnumSendFaceErrorType {
  11 +
  12 + EXCEED_SIZE_1028("1028", "图片大小超限"),
  13 + NOT_EXIST_USER_1029("1029", "用户ID不存在"),
  14 + EXTRACT_ERROR_1030("1030", "照片特征值提取失败"),
  15 + EXIST_IMG_1031("1031", "照片已存在"),
  16 + UPPER_LIMIT_1032("1032", "照片数量超过上限");
  17 +
  18 + public final String code;
  19 + public final String message;
  20 +
  21 + public String getCode() {
  22 + return code;
  23 + }
  24 +
  25 + public String getMessage() {
  26 + return message;
  27 + }
  28 +
  29 + EnumSendFaceErrorType(String code, String message) {
  30 + this.code = code;
  31 + this.message = message;
  32 + }
  33 +
  34 + /**
  35 + * 根据key获得具体的值
  36 + */
  37 + public static EnumSendFaceErrorType getByCode(String code){
  38 + if(StringUtils.isBlank(code)){
  39 + return null;
  40 + }
  41 + for(EnumSendFaceErrorType enums: EnumSendFaceErrorType.values()){
  42 + if(enums.getCode().equals(code)){
  43 + return enums;
  44 + }
  45 + }
  46 + return null;
  47 + }
  48 +
  49 +}
cloud/dahua/src/main/java/com/example/dahua/enums/EnumSendFaceType.java 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +package com.example.dahua.enums;
  2 +
  3 +/**
  4 + * 下发人脸枚举配置中心
  5 + *
  6 + * @Author: xuquan
  7 + * @Date: 2020/11/1 14:59
  8 + */
  9 +public enum EnumSendFaceType {
  10 +
  11 + NOT_EXIST_DEVICE(1, "设备不存在"),
  12 + NOT_ONLINE_DEVICE(2, "设备不在线"),
  13 + FACE_AND_CARD_FAIL(3, "人脸信息、卡信息下发失败"),
  14 + FACE_FAIL_CARD_SUCCESS(4, "人脸信息下发失败,卡信息下发成功"),
  15 + FACE_SUCCESS_CARD_FAIl(5, "人脸信息下发成功,卡信息下发失败");
  16 +
  17 + public final int code;
  18 + public final String message;
  19 +
  20 + EnumSendFaceType(int code, String message) {
  21 + this.code = code;
  22 + this.message = message;
  23 + }
  24 +
  25 +}
cloud/dahua/src/main/java/com/example/dahua/enums/EnumSzBusinessType.java 0 → 100644
@@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
  1 +package com.example.dahua.enums;
  2 +
  3 +/**
  4 + * 顺治科技智能校卫业务枚举配置中心
  5 + *
  6 + * @author xuquan
  7 + * @date 2020/11/11 14:43
  8 + */
  9 +
  10 +public interface EnumSzBusinessType {
  11 +
  12 + /**
  13 + * 用户类型
  14 + */
  15 + public enum EnumUserType {
  16 +
  17 + TEACHER(1, "teacher","老师"),
  18 + STUDENT(2, "student","学生");
  19 +// PARENT(3, "parent","家长");
  20 +
  21 + public final int code;
  22 + public final String enName;
  23 + public final String cnName;
  24 +
  25 + EnumUserType(int code, String enName,String cnName) {
  26 + this.code = code;
  27 + this.enName = enName;
  28 + this.cnName = cnName;
  29 + }
  30 + }
  31 +
  32 +// public enum EnumCardType {
  33 +//
  34 +// STUDENT(1, "student","学生"),
  35 +// TEACHER(2, "teacher","老师");
  36 +//// PARENT(3, "parent","家长");
  37 +//
  38 +// public final int code;
  39 +// public final String enName;
  40 +// public final String cnName;
  41 +//
  42 +// EnumUserType(int code, String enName,String cnName) {
  43 +// this.code = code;
  44 +// this.enName = enName;
  45 +// this.cnName = cnName;
  46 +// }
  47 +// }
  48 +
  49 +}
cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
1 package com.example.dahua.module; 1 package com.example.dahua.module;
2 2
3 -import java.awt.image.BufferedImage;  
4 -import java.io.ByteArrayInputStream;  
5 -import java.io.File;  
6 -import java.io.IOException;  
7 -import java.io.UnsupportedEncodingException;  
8 -import java.util.ArrayList;  
9 -import java.util.HashMap;  
10 -import java.util.List;  
11 -import java.util.Map;  
12 -  
13 import com.example.dahua.bean.PermissionBean; 3 import com.example.dahua.bean.PermissionBean;
14 import com.example.dahua.bean.WeekDay; 4 import com.example.dahua.bean.WeekDay;
15 import com.example.dahua.bean.WeekTime; 5 import com.example.dahua.bean.WeekTime;
  6 +import com.example.dahua.enums.EnumSendCardErrorType;
  7 +import com.example.dahua.enums.EnumSendFaceErrorType;
16 import com.example.dahua.lib.NetSDKLib; 8 import com.example.dahua.lib.NetSDKLib;
17 import com.example.dahua.lib.NetSDKLib.*; 9 import com.example.dahua.lib.NetSDKLib.*;
18 import com.example.dahua.lib.ToolKits; 10 import com.example.dahua.lib.ToolKits;
@@ -21,6 +13,15 @@ import com.sun.jna.ptr.IntByReference; @@ -21,6 +13,15 @@ import com.sun.jna.ptr.IntByReference;
21 import lombok.extern.slf4j.Slf4j; 13 import lombok.extern.slf4j.Slf4j;
22 14
23 import javax.imageio.ImageIO; 15 import javax.imageio.ImageIO;
  16 +import java.awt.image.BufferedImage;
  17 +import java.io.ByteArrayInputStream;
  18 +import java.io.File;
  19 +import java.io.IOException;
  20 +import java.io.UnsupportedEncodingException;
  21 +import java.util.ArrayList;
  22 +import java.util.HashMap;
  23 +import java.util.List;
  24 +import java.util.Map;
24 25
25 26
26 @Slf4j 27 @Slf4j
@@ -201,7 +202,8 @@ public class GateModule { @@ -201,7 +202,8 @@ public class GateModule {
201 202
202 public static synchronized int insertCard(String cardNo, String userId, String cardName, String cardPwd, 203 public static synchronized int insertCard(String cardNo, String userId, String cardName, String cardPwd,
203 int cardStatus, int cardType, int useTimes, int isFirstEnter, 204 int cardStatus, int cardType, int useTimes, int isFirstEnter,
204 - int isValid, String startValidTime, String endValidTime, LLong lLong,String userType) { 205 + int isValid, String startValidTime, String endValidTime, LLong lLong,
  206 + String userType,String cardErrNum) {
205 /** 207 /**
206 * 门禁卡记录集信息 208 * 门禁卡记录集信息
207 */ 209 */
@@ -287,16 +289,18 @@ public class GateModule { @@ -287,16 +289,18 @@ public class GateModule {
287 String ret=ToolKits.getErrorCodePrint(); 289 String ret=ToolKits.getErrorCodePrint();
288 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); 290 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
289 log.info("添加卡信息失败,错误信息:{} ,错误码:{} ",ret,number); 291 log.info("添加卡信息失败,错误信息:{} ,错误码:{} ",ret,number);
290 - //146用户已存在,21对返回数据的校验出错,1162未知错误 number.equals("1162")||  
291 - if(number.equals("21")||number.equals("146")) { 292 + cardErrNum = number;
  293 + //146用户已存在,21对返回数据的校验出错,1162未知错误
  294 + if(number.equals(EnumSendCardErrorType.CHECK_DATA_ERR_21.code)|| number.equals(EnumSendCardErrorType.EXIST_USER_146.code)||
  295 + number.equals(EnumSendCardErrorType.UNKNOWN_1162.code)) {
292 //用户已存在/返回数据校验出错时,执行删除用户 296 //用户已存在/返回数据校验出错时,执行删除用户
293 deleteUser( userId, lLong); 297 deleteUser( userId, lLong);
294 //重新下发卡至设备 298 //重新下发卡至设备
295 - return insertCard( cardNo, userId, cardName, cardPwd,  
296 - cardStatus, cardType, useTimes, isFirstEnter,  
297 - isValid, startValidTime, endValidTime, lLong, userType); 299 + cardErrNum = "";
  300 + return insertCard(cardNo, userId, cardName, cardPwd, cardStatus, cardType, useTimes, isFirstEnter,
  301 + isValid, startValidTime, endValidTime, lLong, userType,cardErrNum);
298 } 302 }
299 - //其他错误码,返回-1 303 + //新增卡失败,错误码,返回-1
300 return -1; 304 return -1;
301 } else { 305 } else {
302 log.info("添加卡信息成功,卡信息记录集编号 : "+ insert.stuCtrlRecordSetResult.nRecNo); 306 log.info("添加卡信息成功,卡信息记录集编号 : "+ insert.stuCtrlRecordSetResult.nRecNo);
@@ -682,7 +686,8 @@ public class GateModule { @@ -682,7 +686,8 @@ public class GateModule {
682 */ 686 */
683 public static boolean modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd, 687 public static boolean modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd,
684 int cardStatus, int cardType, int useTimes, int isFirstEnter, 688 int cardStatus, int cardType, int useTimes, int isFirstEnter,
685 - int isValid, String startValidTime, String endValidTime, LLong lLong,String userType) { 689 + int isValid, String startValidTime, String endValidTime, LLong lLong,
  690 + String userType,String cardErrNum) {
686 /** 691 /**
687 * 门禁卡记录集信息 692 * 门禁卡记录集信息
688 */ 693 */
@@ -770,21 +775,20 @@ public class GateModule { @@ -770,21 +775,20 @@ public class GateModule {
770 String ret=ToolKits.getErrorCodePrint(); 775 String ret=ToolKits.getErrorCodePrint();
771 //结果码 776 //结果码
772 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); 777 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
773 - //147用户不存在,21对返回数据的校验出错  
774 -// if(number.equals("21")||number.equals("147")) {  
775 -//  
776 -// }  
777 -// if(number.equals("1091")||number.equals("1147"))//未知错误  
778 -// {  
779 -// return Integer.parseInt(number);  
780 -// } 778 + cardErrNum = number;
781 log.error("修改卡信息失败,错误信息:{} ,错误码:{} ",ret,number); 779 log.error("修改卡信息失败,错误信息:{} ,错误码:{} ",ret,number);
  780 +
782 return false; 781 return false;
783 } 782 }
784 log.info("修改卡信息成功!"); 783 log.info("修改卡信息成功!");
785 return true; 784 return true;
786 } 785 }
787 786
  787 + public static void main(String[] args) {
  788 + String s = "(0x80000000|147)";
  789 + System.out.println(s.substring(s.indexOf("|") + 1, s.indexOf(")")));
  790 + }
  791 +
788 /** 792 /**
789 * 删除卡信息(单个删除) 793 * 删除卡信息(单个删除)
790 * 794 *
@@ -1081,7 +1085,7 @@ public class GateModule { @@ -1081,7 +1085,7 @@ public class GateModule {
1081 log.info("[" + i + "]删除用户结果:" + failCodes[i].nFailCode); 1085 log.info("[" + i + "]删除用户结果:" + failCodes[i].nFailCode);
1082 } 1086 }
1083 } else { 1087 } else {
1084 - log.error("添加卡信息失败"+ ToolKits.getErrorCodePrint()); 1088 + log.error("删除用户失败"+ ToolKits.getErrorCodePrint());
1085 } 1089 }
1086 1090
1087 stIn.read(); 1091 stIn.read();
@@ -1138,7 +1142,7 @@ public class GateModule { @@ -1138,7 +1142,7 @@ public class GateModule {
1138 return true; 1142 return true;
1139 } 1143 }
1140 1144
1141 - public static synchronized boolean addFaceInfo(String userId, Memory memory, LLong lLong) { 1145 + public static synchronized boolean addFaceInfo(String userId, Memory memory, LLong lLong,String faceErrNum) {
1142 int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_ADD; // 添加 1146 int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_ADD; // 添加
1143 1147
1144 /** 1148 /**
@@ -1173,14 +1177,17 @@ public class GateModule { @@ -1173,14 +1177,17 @@ public class GateModule {
1173 } else { 1177 } else {
1174 String ret=ToolKits.getErrorCodePrint(); 1178 String ret=ToolKits.getErrorCodePrint();
1175 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); 1179 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
1176 - log.error("修改卡信息失败,错误信息:{} ,错误码:{} ",ret,number);  
1177 - //number = 1031:照片已存在;number = 1029 :用户ID不存在  
1178 - if(number.equals("1031")){  
1179 - return modifyFaceInfo( userId, memory, lLong); 1180 + faceErrNum = number;
  1181 + log.error("添加信息失败,错误信息:{} ,错误码:{} ",ret,number);
  1182 + //照片已存在
  1183 + if(number.equals(EnumSendFaceErrorType.EXIST_IMG_1031.code)){
  1184 + faceErrNum = "";
  1185 + return modifyFaceInfo(userId, memory, lLong,faceErrNum);
1180 } 1186 }
1181 - if(number.equals("1029"))  
1182 - {  
1183 - return addFaceInfo( userId, memory, lLong); 1187 + //用户Id不存在
  1188 + if(number.equals(EnumSendFaceErrorType.NOT_EXIST_USER_1029.code)) {
  1189 + faceErrNum = "";
  1190 + return addFaceInfo( userId, memory, lLong,faceErrNum);
1184 } 1191 }
1185 return false; 1192 return false;
1186 } 1193 }
@@ -1238,7 +1245,7 @@ public class GateModule { @@ -1238,7 +1245,7 @@ public class GateModule {
1238 } 1245 }
1239 1246
1240 1247
1241 - public static boolean modifyFaceInfo(String userId, Memory memory, LLong lLong) { 1248 + public static boolean modifyFaceInfo(String userId, Memory memory, LLong lLong,String faceErrNum) {
1242 int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_UPDATE; // 修改 1249 int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_UPDATE; // 修改
1243 1250
1244 /** 1251 /**
@@ -1274,6 +1281,7 @@ public class GateModule { @@ -1274,6 +1281,7 @@ public class GateModule {
1274 } else { 1281 } else {
1275 String ret=ToolKits.getErrorCodePrint(); 1282 String ret=ToolKits.getErrorCodePrint();
1276 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); 1283 String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")"));
  1284 + faceErrNum = number;
1277 log.error("修改人脸失败,错误信息:{} ,错误码:{} ",ret,number); 1285 log.error("修改人脸失败,错误信息:{} ,错误码:{} ",ret,number);
1278 return false; 1286 return false;
1279 } 1287 }
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java
@@ -4,9 +4,11 @@ import com.example.dahua.MyTask; @@ -4,9 +4,11 @@ import com.example.dahua.MyTask;
4 import com.example.dahua.async.SendUserInfoTask; 4 import com.example.dahua.async.SendUserInfoTask;
5 import com.example.dahua.bean.*; 5 import com.example.dahua.bean.*;
6 import com.example.dahua.dao.UserDao; 6 import com.example.dahua.dao.UserDao;
  7 +import com.example.dahua.enums.EnumDeviceType;
7 import com.example.dahua.lib.NetSDKLib; 8 import com.example.dahua.lib.NetSDKLib;
8 import com.example.dahua.module.GateModule; 9 import com.example.dahua.module.GateModule;
9 import com.example.dahua.service.UserService; 10 import com.example.dahua.service.UserService;
  11 +import lombok.extern.slf4j.Slf4j;
10 import org.apache.commons.lang.StringUtils; 12 import org.apache.commons.lang.StringUtils;
11 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Repository; 14 import org.springframework.stereotype.Repository;
@@ -16,6 +18,7 @@ import java.util.List; @@ -16,6 +18,7 @@ import java.util.List;
16 18
17 @Repository 19 @Repository
18 @Service 20 @Service
  21 +@Slf4j
19 public class UserServiceImp implements UserService { 22 public class UserServiceImp implements UserService {
20 23
21 @Autowired 24 @Autowired
@@ -26,13 +29,16 @@ public class UserServiceImp implements UserService { @@ -26,13 +29,16 @@ public class UserServiceImp implements UserService {
26 29
27 @Override 30 @Override
28 public List<AttendanceBean> getAttendanceBeans(String schoolId, String clint_type, String devid) { 31 public List<AttendanceBean> getAttendanceBeans(String schoolId, String clint_type, String devid) {
29 -  
30 - if (!StringUtils.isEmpty(devid)) return userDao.getAttendanceBeanWithId(schoolId, clint_type, devid); 32 + //如果设备ID未传,则返回该学校下所有设备,反之,查询对应设备
  33 + if (!StringUtils.isEmpty(devid)) {
  34 + return userDao.getAttendanceBeanWithId(schoolId, clint_type, devid);
  35 + }
31 36
32 List<AttendanceBean> attendanceBeanList = userDao.getAttendanceBeans(schoolId, clint_type); 37 List<AttendanceBean> attendanceBeanList = userDao.getAttendanceBeans(schoolId, clint_type);
33 -  
34 - if (attendanceBeanList.size()==0)attendanceBeanList = userDao.getAttendanceBeans(schoolId,"29");  
35 - 38 + if (attendanceBeanList.size()==0){
  39 + //若未查询到结果,则查询大华人脸一体机 29
  40 + attendanceBeanList = userDao.getAttendanceBeans(schoolId,String.valueOf(EnumDeviceType.DH_FACE_YTJ.deviceType));
  41 + }
36 return attendanceBeanList; 42 return attendanceBeanList;
37 } 43 }
38 44
@@ -52,10 +58,12 @@ public class UserServiceImp implements UserService { @@ -52,10 +58,12 @@ public class UserServiceImp implements UserService {
52 */ 58 */
53 @Override 59 @Override
54 public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType, String devid) { 60 public boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType, String devid) {
55 - List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type, devid);//获取学校下的大华设备  
56 -  
57 - System.out.println("设备数量:" + attendanceBeans.size());  
58 - 61 + //获取学校下的大华设备
  62 + List<AttendanceBean> attendanceBeans = getAttendanceBeans(schoolId, clint_type, devid);
  63 + if(attendanceBeans.size()<1){
  64 + log.info("下发用户人脸信息失败,学校ID: {},该学校下无设备!设备类型:{}",schoolId,clint_type);
  65 + }
  66 + log.info("设备数量:" + attendanceBeans.size());
59 UserInfoBean userInfoBean = null; 67 UserInfoBean userInfoBean = null;
60 try { 68 try {
61 if (userType == 2) { 69 if (userType == 2) {
@@ -87,7 +95,7 @@ public class UserServiceImp implements UserService { @@ -87,7 +95,7 @@ public class UserServiceImp implements UserService {
87 userInfoBean.setStudent_id(teacher.getTeacher_id()); 95 userInfoBean.setStudent_id(teacher.getTeacher_id());
88 } 96 }
89 } 97 }
90 - 98 + //下发任务
91 myTask.doTaskOne(file, attendanceBeans, userInfoBean, schoolId, -1, userType); 99 myTask.doTaskOne(file, attendanceBeans, userInfoBean, schoolId, -1, userType);
92 } catch (Exception e) { 100 } catch (Exception e) {
93 e.printStackTrace(); 101 e.printStackTrace();
@@ -107,14 +115,20 @@ public class UserServiceImp implements UserService { @@ -107,14 +115,20 @@ public class UserServiceImp implements UserService {
107 myTask.doTaskSendUserInfos(schoolId, clint_type, type, -1); 115 myTask.doTaskSendUserInfos(schoolId, clint_type, type, -1);
108 } 116 }
109 117
  118 + /**
  119 + * 下发权限至设备
  120 + * @param permissionBean
  121 + * @return
  122 + */
110 @Override 123 @Override
111 public boolean sendPermission(PermissionBean permissionBean) { 124 public boolean sendPermission(PermissionBean permissionBean) {
112 - 125 + //下发权限对应设备集合
113 List<String> deviceIds = permissionBean.getDeviceIds(); 126 List<String> deviceIds = permissionBean.getDeviceIds();
114 if (null != deviceIds) 127 if (null != deviceIds)
115 - for (String deviceId :  
116 - deviceIds) { 128 + for (String deviceId : deviceIds) {
  129 + // 句柄
117 NetSDKLib.LLong loginHandleLong = MyTask.lLongMap.get(deviceId); 130 NetSDKLib.LLong loginHandleLong = MyTask.lLongMap.get(deviceId);
  131 + //下发权限
118 GateModule.setAccessTimeSchedule(loginHandleLong, permissionBean); 132 GateModule.setAccessTimeSchedule(loginHandleLong, permissionBean);
119 GateModule.getAccessTimeSchedule1(loginHandleLong); 133 GateModule.getAccessTimeSchedule1(loginHandleLong);
120 } 134 }
cloud/dahua/src/main/java/com/example/dahua/utils/HttpUtils.java
@@ -22,6 +22,17 @@ import java.util.Map; @@ -22,6 +22,17 @@ import java.util.Map;
22 22
23 public class HttpUtils { 23 public class HttpUtils {
24 24
  25 + /**
  26 + * 单个人脸下发至设备
  27 + * 文件先由文件服务上传至100服务上,在21服务进行下发动作
  28 + * @param file
  29 + * @param schoolId
  30 + * @param studentCode
  31 + * @param clint_type
  32 + * @param userType
  33 + * @param deviceId
  34 + * @return
  35 + */
25 public static boolean uploadImgs(File file, String schoolId, String studentCode, String clint_type, int userType,String deviceId) { 36 public static boolean uploadImgs(File file, String schoolId, String studentCode, String clint_type, int userType,String deviceId) {
26 37
27 if (!file.exists()) { 38 if (!file.exists()) {
@@ -88,7 +99,11 @@ public class HttpUtils { @@ -88,7 +99,11 @@ public class HttpUtils {
88 return result.getBody(); 99 return result.getBody();
89 } 100 }
90 101
91 - 102 + /**
  103 + * 权限下发至设备
  104 + * @param permissionBean
  105 + * @return
  106 + */
92 public static boolean sendPermission(PermissionBean permissionBean) { 107 public static boolean sendPermission(PermissionBean permissionBean) {
93 String url = "http://121.40.109.21:8991/file/sendPermission"; 108 String url = "http://121.40.109.21:8991/file/sendPermission";
94 RestTemplate restTemplate = new RestTemplate(); 109 RestTemplate restTemplate = new RestTemplate();
@@ -107,6 +122,10 @@ public class HttpUtils { @@ -107,6 +122,10 @@ public class HttpUtils {
107 return responseEntity.getBody().equals("1"); 122 return responseEntity.getBody().equals("1");
108 } 123 }
109 124
  125 + /**
  126 + * 权限下发至海康设备
  127 + * @param permissionFaceBean
  128 + */
110 public static void sendPermission2HK(PermissionFaceBean permissionFaceBean) { 129 public static void sendPermission2HK(PermissionFaceBean permissionFaceBean) {
111 String url = "http://114.55.30.100:8089/facereco/sendPermiss"; 130 String url = "http://114.55.30.100:8089/facereco/sendPermiss";
112 PermissionBean permissionBean = permissionFaceBean.getPermissionBean(); 131 PermissionBean permissionBean = permissionFaceBean.getPermissionBean();