Commit 410a48a6cd0261bbbd8f41125375b37e1773ae42
1 parent
9df247c3
Exists in
master
考勤设备ID获取
Showing
3 changed files
with
107 additions
and
84 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/MyTask.java
... | ... | @@ -74,11 +74,6 @@ public class MyTask implements ApplicationRunner { |
74 | 74 | //自注册 |
75 | 75 | autoRegister(); |
76 | 76 | |
77 | - /** | |
78 | - * 考勤监听 | |
79 | - */ | |
80 | - kaoQinRecord(); | |
81 | - | |
82 | 77 | // System.out.println(" sendRecordDao:"+sendRecordDao.getSenSuccess()); |
83 | 78 | } |
84 | 79 | |
... | ... | @@ -105,8 +100,6 @@ public class MyTask implements ApplicationRunner { |
105 | 100 | if (!StringUtils.isEmpty(deviceId)) { |
106 | 101 | attendanceService.updateConnectStateWithDevid(0, deviceId); |
107 | 102 | GateModule.stopRealLoadPic(lLongMap.get(deviceId)); |
108 | - //人脸识别、人脸检测事件 | |
109 | - FaceRecognitionModule.stopRealLoadPicture(lLongMap.get(deviceId)); | |
110 | 103 | lLongMap.remove(deviceId); |
111 | 104 | // devMap.remove(deviceId); |
112 | 105 | removeDevice(deviceId); |
... | ... | @@ -249,7 +242,7 @@ public class MyTask implements ApplicationRunner { |
249 | 242 | for (DeviceInfoBean dev : |
250 | 243 | deviceInfoBeans) { |
251 | 244 | if (lLongMap.get(dev.getDevcieId()).intValue() > 0) { |
252 | - NetSDKLib.LLong lLong = GateModule.realLoadPic(0, analyzerCallback, lLongMap.get(dev.getDevcieId())); | |
245 | + NetSDKLib.LLong lLong = GateModule.realLoadPic2(0, analyzerCallback, lLongMap.get(dev.getDevcieId()),dev.getDevcieId()); | |
253 | 246 | // System.out.println("监听成功:"+dev.getDevcieId()); |
254 | 247 | // if (lLong.intValue() != -1) { |
255 | 248 | // //deviceInfoBeans.remove(dev); |
... | ... | @@ -260,22 +253,6 @@ public class MyTask implements ApplicationRunner { |
260 | 253 | } |
261 | 254 | } |
262 | 255 | |
263 | - /** | |
264 | - * 考勤监听 | |
265 | - */ | |
266 | - public synchronized void kaoQinRecord() { | |
267 | - isHasNewDevice = false; | |
268 | - if (null != deviceInfoBeans && deviceInfoBeans.size() > 0) { | |
269 | - for (DeviceInfoBean dev : | |
270 | - deviceInfoBeans) { | |
271 | - if (lLongMap.get(dev.getDevcieId()).intValue() > 0) { | |
272 | - //人脸识别、人脸检测事件监听 | |
273 | - NetSDKLib.LLong lLong = FaceRecognitionModule.realLoadPicture(0, analyzerCallback); | |
274 | - } | |
275 | - } | |
276 | - } | |
277 | - } | |
278 | - | |
279 | 256 | |
280 | 257 | //智能订阅 |
281 | 258 | private AnalyzerDataCB analyzerCallback = new AnalyzerDataCB(); |
... | ... | @@ -300,12 +277,19 @@ public class MyTask implements ApplicationRunner { |
300 | 277 | path.mkdir(); |
301 | 278 | } |
302 | 279 | |
280 | + //设备ID获取 | |
281 | + NetSDKLib.NET_DEVICEINFO_Ex deviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); | |
282 | + ToolKits.GetPointerData(dwUser, deviceInfo); | |
283 | + | |
284 | + String szSn = new String(deviceInfo.sSerialNumber).trim(); | |
285 | + | |
303 | 286 | ///< 门禁事件 |
304 | 287 | if (dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { |
305 | 288 | NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); |
306 | 289 | ToolKits.GetPointerData(pAlarmInfo, msg); |
307 | 290 | //卡号 |
308 | 291 | String card = new String(msg.szCardNo).trim(); |
292 | + | |
309 | 293 | System.out.println("sda:" + card + " 抓拍照片存储地址:"); |
310 | 294 | |
311 | 295 | try { |
... | ... | @@ -329,11 +313,11 @@ public class MyTask implements ApplicationRunner { |
329 | 313 | if (null != cardBean && cardBean.getType() == 0) { |
330 | 314 | //老师人脸信息,保存人脸记录表 |
331 | 315 | TeacherBean teacherBean = userDao.getTeacherWithId(cardBean.getUser_id()); |
332 | - sendRecordDao.addFaceRecoder("", teacherBean.getUser_id(), teacherBean.getName(), snapPicPath, 1, time, card,""); | |
316 | + sendRecordDao.addFaceRecoder(szSn, teacherBean.getUser_id(), teacherBean.getName(), snapPicPath, 1, time, card,""); | |
333 | 317 | } else if (null != cardBean && cardBean.getType() == 2) { |
334 | 318 | //学生人脸信息,保存人脸记录表 |
335 | 319 | UserInfoBean userInfoBean = userDao.getStudentWithid(cardBean.getUser_id()); |
336 | - sendRecordDao.addFaceRecoder("", userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath, 1, time, card,""); | |
320 | + sendRecordDao.addFaceRecoder(szSn, userInfoBean.getUser_id(), userInfoBean.getName(), snapPicPath, 1, time, card,""); | |
337 | 321 | } |
338 | 322 | |
339 | 323 | // TODO 考勤记录 |
... | ... | @@ -344,7 +328,7 @@ public class MyTask implements ApplicationRunner { |
344 | 328 | //刷卡时间 |
345 | 329 | String eventTime = msg.UTC.toStringTime(); |
346 | 330 | //保存考勤记录 |
347 | - kaoQinRecord(status,eventType,card,"",eventTime,snapPicPath); | |
331 | + kaoQinRecord(status,eventType,card,szSn,eventTime,snapPicPath); | |
348 | 332 | } |
349 | 333 | |
350 | 334 | } catch (IOException e2) { | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
... | ... | @@ -18,10 +18,12 @@ import com.example.dahua.lib.NetSDKLib.*; |
18 | 18 | import com.example.dahua.lib.ToolKits; |
19 | 19 | import com.sun.jna.Memory; |
20 | 20 | import com.sun.jna.ptr.IntByReference; |
21 | +import lombok.extern.slf4j.Slf4j; | |
21 | 22 | |
22 | 23 | import javax.imageio.ImageIO; |
23 | 24 | |
24 | 25 | |
26 | +@Slf4j | |
25 | 27 | public class GateModule { |
26 | 28 | // 查询句柄 |
27 | 29 | private static LLong m_lFindHandle = new LLong(0); |
... | ... | @@ -50,6 +52,33 @@ public class GateModule { |
50 | 52 | return m_hAttachHandle; |
51 | 53 | } |
52 | 54 | |
55 | + public static LLong realLoadPic2(int ChannelId, NetSDKLib.fAnalyzerDataCallBack m_AnalyzerDataCB, LLong lLong,String devcieId) { | |
56 | + | |
57 | + final NetSDKLib.NET_DEVICEINFO_Ex deviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); | |
58 | + | |
59 | + // 设备ID | |
60 | + System.arraycopy(devcieId.getBytes(), 0, deviceInfo.sSerialNumber, 0, devcieId.getBytes().length); | |
61 | + | |
62 | + /** | |
63 | + * 说明: | |
64 | + * 通道数可以在有登录是返回的信息 m_stDeviceInfo.byChanNum 获取 | |
65 | + * 下列仅订阅了0通道的智能事件. | |
66 | + */ | |
67 | + int bNeedPicture = 1; // 是否需要图片 | |
68 | + deviceInfo.write(); | |
69 | + LLong m_hAttachHandle = LoginModule.netsdk.CLIENT_RealLoadPictureEx(lLong, ChannelId, NetSDKLib.EVENT_IVS_ALL, | |
70 | + bNeedPicture, m_AnalyzerDataCB, deviceInfo.getPointer(), null); | |
71 | + deviceInfo.read(); | |
72 | + if (m_hAttachHandle.longValue() != 0) { | |
73 | + System.out.println("CLIENT_RealLoadPictureEx Success ChannelId : \n" + ChannelId); | |
74 | + } else { | |
75 | + System.err.println("CLIENT_RealLoadPictureEx Failed!" + ToolKits.getErrorCodePrint()); | |
76 | + return null; | |
77 | + } | |
78 | + | |
79 | + return m_hAttachHandle; | |
80 | + } | |
81 | + | |
53 | 82 | /** |
54 | 83 | * 停止上传智能分析数据-图片 |
55 | 84 | */ |
... | ... | @@ -169,6 +198,7 @@ public class GateModule { |
169 | 198 | // return true; |
170 | 199 | } |
171 | 200 | |
201 | + | |
172 | 202 | public static synchronized int insertCard(String cardNo, String userId, String cardName, String cardPwd, |
173 | 203 | int cardStatus, int cardType, int useTimes, int isFirstEnter, |
174 | 204 | int isValid, String startValidTime, String endValidTime, LLong lLong,String userType) { |
... | ... | @@ -254,24 +284,25 @@ public class GateModule { |
254 | 284 | accessCardInfo.read(); |
255 | 285 | |
256 | 286 | if(!bRet) { |
257 | - //System.err.println("添加卡信息失败." + ToolKits.getErrorCodePrint()); | |
258 | 287 | String ret=ToolKits.getErrorCodePrint(); |
259 | - System.err.println("添加卡信息失败." + ret); | |
260 | 288 | String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); |
261 | - if(number.equals("21")||number.equals("146"))//146用户已存在,21对返回数据的校验出错,1162未知错误 number.equals("1162")|| | |
262 | - { | |
289 | + log.info("添加卡信息失败,错误信息:{} ,错误码:{} ",ret,number); | |
290 | + //146用户已存在,21对返回数据的校验出错,1162未知错误 number.equals("1162")|| | |
291 | + if(number.equals("21")||number.equals("146")) { | |
292 | + //用户已存在/返回数据校验出错时,执行删除用户 | |
263 | 293 | deleteUser( userId, lLong); |
294 | + //重新下发卡至设备 | |
264 | 295 | return insertCard( cardNo, userId, cardName, cardPwd, |
265 | 296 | cardStatus, cardType, useTimes, isFirstEnter, |
266 | 297 | isValid, startValidTime, endValidTime, lLong, userType); |
267 | 298 | } |
299 | + //其他错误码,返回-1 | |
268 | 300 | return -1; |
269 | 301 | } else { |
270 | - System.out.println("添加卡信息成功,卡信息记录集编号 : " + insert.stuCtrlRecordSetResult.nRecNo); | |
302 | + log.info("添加卡信息成功,卡信息记录集编号 : "+ insert.stuCtrlRecordSetResult.nRecNo); | |
271 | 303 | return insert.stuCtrlRecordSetResult.nRecNo; |
272 | 304 | } |
273 | 305 | |
274 | - | |
275 | 306 | // return true; |
276 | 307 | } |
277 | 308 | |
... | ... | @@ -378,7 +409,8 @@ public class GateModule { |
378 | 409 | |
379 | 410 | CFG_ACCESS_TIMESCHEDULE_INFO msg = new CFG_ACCESS_TIMESCHEDULE_INFO(); |
380 | 411 | String strCmd = NetSDKLib.CFG_CMD_ACCESSTIMESCHEDULE; |
381 | - int nChannel = 120; // 通道号 | |
412 | + // 通道号 | |
413 | + int nChannel = 120; | |
382 | 414 | // msg.stuTimeWeekDay[0].stuTimeSection[0].dwRecordMask |
383 | 415 | String name = "3"; |
384 | 416 | System.arraycopy(name.getBytes(), 0, msg.szName, 0, name.getBytes().length); |
... | ... | @@ -387,13 +419,11 @@ public class GateModule { |
387 | 419 | List<WeekDay> weekDays = permissionBean.getWeekDays(); |
388 | 420 | Map<Integer, List<WeekTime>> map = new HashMap<>(); |
389 | 421 | |
390 | - for (WeekDay weekDay : | |
391 | - weekDays) { | |
422 | + for (WeekDay weekDay : weekDays) { | |
392 | 423 | //整理时间 |
393 | 424 | initWeedayAndTimes(weekDay, map); |
394 | 425 | //设置周计划信息 |
395 | - for (Map.Entry<Integer, List<WeekTime>> entry : | |
396 | - map.entrySet()) { | |
426 | + for (Map.Entry<Integer, List<WeekTime>> entry : map.entrySet()) { | |
397 | 427 | |
398 | 428 | int weekDayIndex = entry.getKey(); |
399 | 429 | |
... | ... | @@ -632,7 +662,25 @@ public class GateModule { |
632 | 662 | return true; |
633 | 663 | } |
634 | 664 | |
635 | - public static int modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd, | |
665 | + /** | |
666 | + * 修改设备卡信息 | |
667 | + * @param recordNo | |
668 | + * @param cardNo | |
669 | + * @param userId | |
670 | + * @param cardName | |
671 | + * @param cardPwd | |
672 | + * @param cardStatus | |
673 | + * @param cardType | |
674 | + * @param useTimes | |
675 | + * @param isFirstEnter | |
676 | + * @param isValid | |
677 | + * @param startValidTime | |
678 | + * @param endValidTime | |
679 | + * @param lLong | |
680 | + * @param userType | |
681 | + * @return | |
682 | + */ | |
683 | + public static boolean modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd, | |
636 | 684 | int cardStatus, int cardType, int useTimes, int isFirstEnter, |
637 | 685 | int isValid, String startValidTime, String endValidTime, LLong lLong,String userType) { |
638 | 686 | /** |
... | ... | @@ -717,28 +765,24 @@ public class GateModule { |
717 | 765 | CtrlType.CTRLTYPE_CTRL_RECORDSET_UPDATE, update.getPointer(), 5000); |
718 | 766 | update.read(); |
719 | 767 | accessCardInfo.read(); |
720 | - | |
768 | + // 返回值:1成功,否则返回 | |
721 | 769 | if (!bRet) { |
722 | - //System.err.println("修改卡信息失败." + ToolKits.getErrorCodePrint()); | |
723 | 770 | String ret=ToolKits.getErrorCodePrint(); |
724 | - System.err.println("修改卡信息失败." + ret); | |
771 | + //结果码 | |
725 | 772 | String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); |
726 | - if(number.equals("21")||number.equals("147"))//147用户不存在,21对返回数据的校验出错 | |
727 | - { | |
728 | -// newRecordNo= insertCard( cardNo, userId, cardName, cardPwd, | |
729 | -// cardStatus, cardType, useTimes, isFirstEnter, | |
730 | -// isValid, startValidTime, endValidTime, lLong, userType); | |
731 | - } | |
732 | - if(number.equals("1091")||number.equals("1147"))//未知错误 | |
733 | - { | |
734 | - return Integer.parseInt(number); | |
735 | - } | |
736 | - return 0; | |
737 | - } else { | |
738 | - System.out.println("修改卡信息成功 "); | |
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 | +// } | |
781 | + log.error("修改卡信息失败,错误信息:{} ,错误码:{} ",ret,number); | |
782 | + return false; | |
739 | 783 | } |
740 | - | |
741 | - return 1; | |
784 | + log.info("修改卡信息成功!"); | |
785 | + return true; | |
742 | 786 | } |
743 | 787 | |
744 | 788 | /** |
... | ... | @@ -778,8 +822,7 @@ public class GateModule { |
778 | 822 | msg.pBuf = new IntByReference(recordNo).getPointer(); |
779 | 823 | |
780 | 824 | msg.write(); |
781 | - boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(lLong, | |
782 | - CtrlType.CTRLTYPE_CTRL_RECORDSET_REMOVE, msg.getPointer(), 5000); | |
825 | + boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(lLong, CtrlType.CTRLTYPE_CTRL_RECORDSET_REMOVE, msg.getPointer(), 5000); | |
783 | 826 | msg.read(); |
784 | 827 | |
785 | 828 | if (!bRet) { |
... | ... | @@ -1035,12 +1078,10 @@ public class GateModule { |
1035 | 1078 | * 打印具体的信息 |
1036 | 1079 | */ |
1037 | 1080 | for (int i = 0; i < nMaxNum; i++) { |
1038 | - System.out.println("[" + i + "]删除用户结果:" | |
1039 | - + failCodes[i].nFailCode); | |
1081 | + log.info("[" + i + "]删除用户结果:" + failCodes[i].nFailCode); | |
1040 | 1082 | } |
1041 | 1083 | } else { |
1042 | - //System.err.println("删除用户失败, " + getErrorCode()); | |
1043 | - System.err.println("删除用户失败, " + ToolKits.getErrorCodePrint()); | |
1084 | + log.error("添加卡信息失败"+ ToolKits.getErrorCodePrint()); | |
1044 | 1085 | } |
1045 | 1086 | |
1046 | 1087 | stIn.read(); |
... | ... | @@ -1128,23 +1169,21 @@ public class GateModule { |
1128 | 1169 | stIn.read(); |
1129 | 1170 | stOut.read(); |
1130 | 1171 | if (bRet) { |
1131 | - System.out.println("添加人脸成功!"); | |
1172 | + log.info("添加人脸成功!"); | |
1132 | 1173 | } else { |
1133 | -// System.err.println("添加人脸失败!" + ToolKits.getErrorCodePrint()); | |
1134 | 1174 | String ret=ToolKits.getErrorCodePrint(); |
1135 | - System.err.println("添加人脸失败!" + ret); | |
1136 | 1175 | String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); |
1137 | - if(number.equals("1031"))//照片已存在 | |
1138 | - { | |
1139 | - return modifyFaceInfo( userId, memory, lLong)==1?true:false; | |
1176 | + log.error("修改卡信息失败,错误信息:{} ,错误码:{} ",ret,number); | |
1177 | + //number = 1031:照片已存在;number = 1029 :用户ID不存在 | |
1178 | + if(number.equals("1031")){ | |
1179 | + return modifyFaceInfo( userId, memory, lLong); | |
1140 | 1180 | } |
1141 | - if(number.equals("1029"))//照片已存在 | |
1181 | + if(number.equals("1029")) | |
1142 | 1182 | { |
1143 | 1183 | return addFaceInfo( userId, memory, lLong); |
1144 | 1184 | } |
1145 | 1185 | return false; |
1146 | 1186 | } |
1147 | - | |
1148 | 1187 | return true; |
1149 | 1188 | } |
1150 | 1189 | |
... | ... | @@ -1186,7 +1225,7 @@ public class GateModule { |
1186 | 1225 | stIn.read(); |
1187 | 1226 | stOut.read(); |
1188 | 1227 | if (bRet) { |
1189 | - System.out.println("修改人脸成功!"); | |
1228 | + log.info("修改人脸成功!"); | |
1190 | 1229 | } else { |
1191 | 1230 | // System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint()); |
1192 | 1231 | String ret=ToolKits.getErrorCodePrint(); |
... | ... | @@ -1199,7 +1238,7 @@ public class GateModule { |
1199 | 1238 | } |
1200 | 1239 | |
1201 | 1240 | |
1202 | - public static int modifyFaceInfo(String userId, Memory memory, LLong lLong) { | |
1241 | + public static boolean modifyFaceInfo(String userId, Memory memory, LLong lLong) { | |
1203 | 1242 | int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_UPDATE; // 修改 |
1204 | 1243 | |
1205 | 1244 | /** |
... | ... | @@ -1229,22 +1268,16 @@ public class GateModule { |
1229 | 1268 | boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(lLong, emType, stIn.getPointer(), stOut.getPointer(), 5000); |
1230 | 1269 | stIn.read(); |
1231 | 1270 | stOut.read(); |
1271 | + | |
1232 | 1272 | if (bRet) { |
1233 | - System.out.println("修改人脸成功!"); | |
1273 | + log.info("修改人脸成功!"); | |
1234 | 1274 | } else { |
1235 | -// System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint()); | |
1236 | 1275 | String ret=ToolKits.getErrorCodePrint(); |
1237 | - System.err.println("修改人脸失败!" + ret); | |
1238 | 1276 | String number = ret.substring(ret.indexOf("|") + 1, ret.indexOf(")")); |
1239 | - if(number.equals("1029"))//1029用户ID不存在 | |
1240 | - { | |
1241 | - //return addFaceInfo(userId, memory, lLong); | |
1242 | - return Integer.parseInt(number); | |
1243 | - } | |
1244 | - return 0; | |
1277 | + log.error("修改人脸失败,错误信息:{} ,错误码:{} ",ret,number); | |
1278 | + return false; | |
1245 | 1279 | } |
1246 | - | |
1247 | - return 1; | |
1280 | + return true; | |
1248 | 1281 | } |
1249 | 1282 | |
1250 | 1283 | /** | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/UserService.java
... | ... | @@ -54,6 +54,12 @@ public interface UserService { |
54 | 54 | */ |
55 | 55 | boolean sendPermission(PermissionBean permissionBean); |
56 | 56 | |
57 | + /** | |
58 | + * 根据学籍号、学校id获取用户id | |
59 | + * @param code | |
60 | + * @param schoolId | |
61 | + * @return | |
62 | + */ | |
57 | 63 | String getUserId(String code,String schoolId); |
58 | 64 | |
59 | 65 | ... | ... |