Commit 3b1634ff2a2849e27a899c3f7736b7d9bb25ddf7
1 parent
c3235b53
Exists in
master
大华一体机考勤,添加发送数据看板
Showing
2 changed files
with
24 additions
and
8 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/MyTask.java
| 1 | 1 | package com.example.dahua; |
| 2 | 2 | |
| 3 | +import com.example.dahua.async.MyScheduledTask; | |
| 3 | 4 | import com.example.dahua.bean.*; |
| 4 | 5 | import com.example.dahua.dao.UserDao; |
| 5 | 6 | import com.example.dahua.enums.EnumSendFaceType; |
| ... | ... | @@ -10,6 +11,7 @@ import com.example.dahua.lib.Utils; |
| 10 | 11 | import com.example.dahua.module.AutoRegisterModule; |
| 11 | 12 | import com.example.dahua.module.GateModule; |
| 12 | 13 | import com.example.dahua.module.LoginModule; |
| 14 | +import com.example.dahua.mqtt.MqttManager; | |
| 13 | 15 | import com.example.dahua.service.AttendanceService; |
| 14 | 16 | import com.example.dahua.utils.DateUtils; |
| 15 | 17 | import com.example.dahua.utils.FileUtils; |
| ... | ... | @@ -71,6 +73,9 @@ public class MyTask implements ApplicationRunner { |
| 71 | 73 | |
| 72 | 74 | public boolean isHasNewDevice = false;//判断是否有新设备上线 |
| 73 | 75 | |
| 76 | + @Autowired | |
| 77 | + private MyScheduledTask myScheduledTask; | |
| 78 | + | |
| 74 | 79 | @Override |
| 75 | 80 | public void run(ApplicationArguments args) throws Exception { |
| 76 | 81 | // 121.40.109.21 |
| ... | ... | @@ -307,7 +312,8 @@ public class MyTask implements ApplicationRunner { |
| 307 | 312 | ImageIO.write(gateBufferedImage, "png", new File(snapPicPath)); |
| 308 | 313 | } |
| 309 | 314 | log.info("设备ID: {},卡号: {},抓拍照片存储地址:{}" ,szSn,card,snapPicPath); |
| 310 | - if(isMatch(REGEX_POSITIVE_Symbol, szSn)){//验证设备id是否存在特殊字符 | |
| 315 | + //验证设备id是否存在特殊字符 | |
| 316 | + if(isMatch(REGEX_POSITIVE_Symbol, szSn)){ | |
| 311 | 317 | log.info("—设备ID异常: {},卡号: {}",szSn,card); |
| 312 | 318 | return 0; |
| 313 | 319 | } |
| ... | ... | @@ -316,12 +322,13 @@ public class MyTask implements ApplicationRunner { |
| 316 | 322 | if(org.apache.commons.lang.StringUtils.isNotBlank(schoolIdStr)){ |
| 317 | 323 | schoolId=Integer.parseInt(schoolIdStr); |
| 318 | 324 | } |
| 319 | - //卡号取反(大写) | |
| 320 | - //if(!szSn.startsWith("ytj")||(szSn.startsWith("ytj")&&schoolId==126&&schoolId==393)){ | |
| 325 | + /** | |
| 326 | + * 卡号取反(大写) | |
| 327 | + * 注:若设备为一体机、且非"126上虞城东小学、393上虞实验中学"学校,卡则取反 | |
| 328 | + */ | |
| 321 | 329 | if(szSn.startsWith("ytj")&&schoolId!=126&&schoolId!=393){ |
| 322 | 330 | card = card; |
| 323 | - } | |
| 324 | - else{ | |
| 331 | + } else{ | |
| 325 | 332 | card = cardNo(card); |
| 326 | 333 | } |
| 327 | 334 | //根据卡号获取卡身份信息 |
| ... | ... | @@ -342,10 +349,10 @@ public class MyTask implements ApplicationRunner { |
| 342 | 349 | } |
| 343 | 350 | |
| 344 | 351 | if(szSn.startsWith("ytj")) { |
| 345 | - | |
| 346 | 352 | // TODO 考勤记录 |
| 347 | 353 | //刷卡结果,1表示成功, 0表示失败 |
| 348 | 354 | int status = msg.bStatus; |
| 355 | + | |
| 349 | 356 | //门禁事件类型:1进2出 |
| 350 | 357 | int eventType = msg.emEventType; |
| 351 | 358 | //刷卡时间 |
| ... | ... | @@ -407,6 +414,7 @@ public class MyTask implements ApplicationRunner { |
| 407 | 414 | return isNum.matches(); |
| 408 | 415 | } |
| 409 | 416 | |
| 417 | + private static MqttManager mqttManager; | |
| 410 | 418 | /** |
| 411 | 419 | * 大华设备考勤记录 |
| 412 | 420 | * @param status |
| ... | ... | @@ -429,6 +437,14 @@ public class MyTask implements ApplicationRunner { |
| 429 | 437 | if (checkIn.getIsSuccess() == 1) { |
| 430 | 438 | //考勤成功 |
| 431 | 439 | String content = "考勤成功!,设备:" + deviceId + "卡号:" + cardNo + "方向:" + (eventType == 1 ? "进门" : "出门") + "______" + eventTime; |
| 440 | + | |
| 441 | + //一体机设备,抓拍到人脸,将人脸发送数据看板 | |
| 442 | + if(null == mqttManager){ | |
| 443 | + mqttManager = new MqttManager(); | |
| 444 | + mqttManager.init(); | |
| 445 | + } | |
| 446 | + myScheduledTask.sendMQMess(content); | |
| 447 | + | |
| 432 | 448 | //记录学生考勤签到记录 |
| 433 | 449 | FileUtils.getInstance().writeLogs(content, FileUtils.qiandaoSuccess); |
| 434 | 450 | } else { |
| ... | ... | @@ -462,7 +478,7 @@ public class MyTask implements ApplicationRunner { |
| 462 | 478 | //若即不成功,也不是请假,则按刷卡异常处理 |
| 463 | 479 | List<User> users = userDao.selectUserByCardNum(cardNo); |
| 464 | 480 | if(users.size()<1){ |
| 465 | - log.warn("考勤记录:卡号: {}没找到对应学生或老师,考勤时间: {}",cardNo,DateUtils.date2String(new Date(), DateUtils.format2)); | |
| 481 | + log.warn("考勤记录:卡号: {},没找到对应学生或老师,考勤时间: {}",cardNo,DateUtils.date2String(new Date(), DateUtils.format2)); | |
| 466 | 482 | return; |
| 467 | 483 | } |
| 468 | 484 | User user = users.get(0); | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
| ... | ... | @@ -235,7 +235,7 @@ public class MyScheduledTask { |
| 235 | 235 | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - private void sendMQMess(String content) { | |
| 238 | + public void sendMQMess(String content) { | |
| 239 | 239 | String cardNum = content.substring(content.indexOf("卡号") + 3, content.indexOf("卡号") + 11); |
| 240 | 240 | |
| 241 | 241 | // System.out.println("cardNum:" + cardNum); | ... | ... |