Commit 41b5b3f843e4e08980f36c8aea8937336357f509

Authored by 徐泉
1 parent fd892de1
Exists in master

考勤修改

cloud/dahua/src/main/java/com/example/dahua/MyTask.java
@@ -3,6 +3,7 @@ package com.example.dahua; @@ -3,6 +3,7 @@ package com.example.dahua;
3 import com.example.dahua.async.MyScheduledTask; 3 import com.example.dahua.async.MyScheduledTask;
4 import com.example.dahua.bean.*; 4 import com.example.dahua.bean.*;
5 import com.example.dahua.dao.UserDao; 5 import com.example.dahua.dao.UserDao;
  6 +import com.example.dahua.enums.EnumDeviceType;
6 import com.example.dahua.enums.EnumSendFaceType; 7 import com.example.dahua.enums.EnumSendFaceType;
7 import com.example.dahua.enums.EnumSzBusinessType; 8 import com.example.dahua.enums.EnumSzBusinessType;
8 import com.example.dahua.lib.NetSDKLib; 9 import com.example.dahua.lib.NetSDKLib;
@@ -58,7 +59,7 @@ public class MyTask implements ApplicationRunner { @@ -58,7 +59,7 @@ public class MyTask implements ApplicationRunner {
58 public static String password = "q12345678"; 59 public static String password = "q12345678";
59 60
60 //在线设备信息集合 61 //在线设备信息集合
61 - private List<DeviceInfoBean> deviceInfoBeans = new ArrayList<>(); 62 + private static List<DeviceInfoBean> deviceInfoBeans = new ArrayList<>();
62 63
63 //存放登录句柄 64 //存放登录句柄
64 public static Map<String, NetSDKLib.LLong> lLongMap = new HashMap<>(); 65 public static Map<String, NetSDKLib.LLong> lLongMap = new HashMap<>();
@@ -327,9 +328,9 @@ public class MyTask implements ApplicationRunner { @@ -327,9 +328,9 @@ public class MyTask implements ApplicationRunner {
327 return 0; 328 return 0;
328 } 329 }
329 int schoolId=0; 330 int schoolId=0;
330 - String schoolIdStr=userDao.getSchoolIdbyClint_id(szSn);  
331 - if(org.apache.commons.lang.StringUtils.isNotBlank(schoolIdStr)){  
332 - schoolId=Integer.parseInt(schoolIdStr); 331 + AttendanceBean attendanceBean =userDao.getTypeByClint_id(szSn);
  332 + if(org.apache.commons.lang.StringUtils.isNotBlank(attendanceBean.getSchool_id())){
  333 + schoolId=Integer.parseInt(attendanceBean.getSchool_id());
333 } 334 }
334 /** 335 /**
335 * 卡号取反(大写) 336 * 卡号取反(大写)
@@ -359,17 +360,19 @@ public class MyTask implements ApplicationRunner { @@ -359,17 +360,19 @@ public class MyTask implements ApplicationRunner {
359 } 360 }
360 361
361 if(szSn.startsWith("ytj")) { 362 if(szSn.startsWith("ytj")) {
  363 + //门禁进出类型:1进0出
  364 + int eventType = EnumSzBusinessType.EnumDeviceInAndOut.INT.code;
  365 + if(attendanceBean.getOutOrIn() != EnumSzBusinessType.EnumDeviceInAndOut.INT.code){
  366 + eventType = EnumSzBusinessType.EnumDeviceInAndOut.OUT.code;
  367 + }
362 // TODO 考勤记录 368 // TODO 考勤记录
363 //刷卡结果,1表示成功, 0表示失败 369 //刷卡结果,1表示成功, 0表示失败
364 int status = msg.bStatus; 370 int status = msg.bStatus;
365 -  
366 - //门禁事件类型:1进2出  
367 - int eventType = msg.emEventType;  
368 //刷卡时间 371 //刷卡时间
369 String eventTime = DateUtils.date2String(new Date(), DateUtils.format2); 372 String eventTime = DateUtils.date2String(new Date(), DateUtils.format2);
370 373
371 //保存考勤记录 374 //保存考勤记录
372 - kaoQinRecord(status, eventType, card, szSn, eventTime, snapPicPath, messageCode); 375 + kaoQinRecord(status, eventType, card, szSn, eventTime, snapPicPath, messageCode,lAnalyzerHandle);
373 } 376 }
374 } 377 }
375 378
@@ -434,14 +437,14 @@ public class MyTask implements ApplicationRunner { @@ -434,14 +437,14 @@ public class MyTask implements ApplicationRunner {
434 * @param eventTime 437 * @param eventTime
435 * @param imageUrl 438 * @param imageUrl
436 */ 439 */
437 - public void kaoQinRecord(int status,int eventType,String cardNo,String deviceId,String eventTime,String imageUrl,int messageCode) { 440 + public void kaoQinRecord(int status,int eventType,String cardNo,String deviceId,String eventTime,String imageUrl,int messageCode,NetSDKLib.LLong lLong) {
438 if (status == 1) { 441 if (status == 1) {
439 //有效刷卡调考勤存储过程 442 //有效刷卡调考勤存储过程
440 CheckIn checkIn = new CheckIn(); 443 CheckIn checkIn = new CheckIn();
441 checkIn.setDeviceId(deviceId); 444 checkIn.setDeviceId(deviceId);
442 checkIn.setCardNo(cardNo); 445 checkIn.setCardNo(cardNo);
443 checkIn.setFunNo(8); 446 checkIn.setFunNo(8);
444 - checkIn.setFlag(eventType == 2 ? 1 : 0); 447 + checkIn.setFlag(eventType == EnumSzBusinessType.EnumDeviceInAndOut.INT.code ? 0:1);
445 checkIn.setCheckTime(eventTime); 448 checkIn.setCheckTime(eventTime);
446 searchMapper.checkIn(checkIn); 449 searchMapper.checkIn(checkIn);
447 450
@@ -481,6 +484,10 @@ public class MyTask implements ApplicationRunner { @@ -481,6 +484,10 @@ public class MyTask implements ApplicationRunner {
481 shortMsg.setMsg(mobileMessage.getName() + "家长您好,你的孩子于" + DateUtils.date2String(new Date(), DateUtils.format2) + "请假后进校,请知晓;"); 484 shortMsg.setMsg(mobileMessage.getName() + "家长您好,你的孩子于" + DateUtils.date2String(new Date(), DateUtils.format2) + "请假后进校,请知晓;");
482 } 485 }
483 userDao.insertMessage(shortMsg.getTableName(),shortMsg.getSchoolId()+"",shortMsg.getMobile(),shortMsg.getMsg()); 486 userDao.insertMessage(shortMsg.getTableName(),shortMsg.getSchoolId()+"",shortMsg.getMobile(),shortMsg.getMsg());
  487 + /**
  488 + * 远程开门
  489 + */
  490 + openDoor(lLong);
484 } 491 }
485 } else { 492 } else {
486 //若即不成功,也不是请假,则按刷卡异常处理 493 //若即不成功,也不是请假,则按刷卡异常处理
@@ -532,27 +539,36 @@ public class MyTask implements ApplicationRunner { @@ -532,27 +539,36 @@ public class MyTask implements ApplicationRunner {
532 mqttManager = new MqttManager(); 539 mqttManager = new MqttManager();
533 mqttManager.init(); 540 mqttManager.init();
534 } 541 }
535 - 542 + // inOrOut:1出门0进门
536 String inOrOut = eventType == 1 ? "0" : "1"; 543 String inOrOut = eventType == 1 ? "0" : "1";
537 - //获取寝室关联的场景id 544 + //获取设备关联的场景id
538 String placeId = userDao.getPlaceIdWithKaoqinDevid(deviceId); 545 String placeId = userDao.getPlaceIdWithKaoqinDevid(deviceId);
539 546
540 if (null != placeId) { 547 if (null != placeId) {
541 //关联的显示看板设备 548 //关联的显示看板设备
542 List<String> kanbanIds = userDao.getKanBanIdWithPlaceId(placeId); 549 List<String> kanbanIds = userDao.getKanBanIdWithPlaceId(placeId);
  550 + if(kanbanIds.size()<1){
  551 + log.info("设备id: {},关联placeId: {},未查询到关联看板设备。",deviceId,placeId);
  552 + return;
  553 + }
543 log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds)); 554 log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds));
544 - for (int i = 0; i < kanbanIds.size(); i++) {  
545 - String kanbanId = kanbanIds.get(i); 555 + for (String kanbanId : kanbanIds) {
546 String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; 556 String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}";
547 log.info("====== 开始推送看板======, kanbanId = {}, cardNum = {},content ={}",kanbanId,cardNum,data); 557 log.info("====== 开始推送看板======, kanbanId = {}, cardNum = {},content ={}",kanbanId,cardNum,data);
548 mqttManager.sendMqQD(kanbanId, data); 558 mqttManager.sendMqQD(kanbanId, data);
549 } 559 }
550 -  
551 } else { 560 } else {
552 -  
553 String schoolId = userDao.getSchoolIdWidthCardNum(cardNum); 561 String schoolId = userDao.getSchoolIdWidthCardNum(cardNum);
554 - if(StringUtils.isEmpty(schoolId)||Integer.parseInt(schoolId) <=0)return; 562 + if(StringUtils.isEmpty(schoolId)||Integer.parseInt(schoolId) <=0){
  563 + log.info("卡号未查询到对应学校。卡号: {}",cardNum);
  564 + return;
  565 + }
  566 + //查询学校看板设备ID
555 List<String> clintIds = userDao.getClintIds(schoolId); 567 List<String> clintIds = userDao.getClintIds(schoolId);
  568 + if(clintIds.size()<1){
  569 + log.info("学校下未查询到看板信息,学校id: {}",schoolId);
  570 + return;
  571 + }
556 log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(clintIds)); 572 log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(clintIds));
557 for (int i = 0; i < clintIds.size(); i++) { 573 for (int i = 0; i < clintIds.size(); i++) {
558 String clintId = clintIds.get(i); 574 String clintId = clintIds.get(i);
@@ -561,8 +577,28 @@ public class MyTask implements ApplicationRunner { @@ -561,8 +577,28 @@ public class MyTask implements ApplicationRunner {
561 mqttManager.sendMqQD(clintId, data); 577 mqttManager.sendMqQD(clintId, data);
562 } 578 }
563 } 579 }
  580 + }
  581 +
  582 + /**
  583 + * 远程开门
  584 + */
  585 + private static NetSDKLib.NET_CTRL_ACCESS_OPEN open = new NetSDKLib.NET_CTRL_ACCESS_OPEN();
  586 + public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
  587 +
  588 + public static boolean openDoor(NetSDKLib.LLong lLong) {
  589 + open.nChannelID = 0;
564 590
  591 + open.write();
  592 + boolean openSuccess = LoginModule.netsdk.CLIENT_ControlDeviceEx(lLong, NetSDKLib.CtrlType.CTRLTYPE_CTRL_ACCESS_OPEN, open.getPointer(), null, 5000);
  593 + open.read();
  594 +
  595 + if (!openSuccess) {
  596 + log.warn("open Door error: 0x: "+ Long.toHexString(LoginModule.netsdk.CLIENT_GetLastError()));
  597 + return false;
  598 + }
  599 + return true;
565 } 600 }
  601 +
566 } 602 }
567 603
568 604
cloud/dahua/src/main/java/com/example/dahua/bean/AttendanceBean.java
@@ -16,6 +16,8 @@ public class AttendanceBean implements Serializable { @@ -16,6 +16,8 @@ public class AttendanceBean implements Serializable {
16 private String intime; 16 private String intime;
17 17
18 private String school_id; 18 private String school_id;
  19 + //进出方向
  20 + private int OutOrIn;
19 21
20 public String getClint_id() { 22 public String getClint_id() {
21 return clint_id; 23 return clint_id;
@@ -57,6 +59,14 @@ public class AttendanceBean implements Serializable { @@ -57,6 +59,14 @@ public class AttendanceBean implements Serializable {
57 this.school_id = school_id; 59 this.school_id = school_id;
58 } 60 }
59 61
  62 + public int getOutOrIn() {
  63 + return OutOrIn;
  64 + }
  65 +
  66 + public void setOutOrIn(int outOrIn) {
  67 + OutOrIn = outOrIn;
  68 + }
  69 +
60 @Override 70 @Override
61 public String toString() { 71 public String toString() {
62 return "AttendanceBean{" + 72 return "AttendanceBean{" +
cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
@@ -16,6 +16,14 @@ public interface UserDao { @@ -16,6 +16,14 @@ public interface UserDao {
16 @Select("select school_id from SZ_Attendance where clint_id = #{clint_id} ") 16 @Select("select school_id from SZ_Attendance where clint_id = #{clint_id} ")
17 String getSchoolIdbyClint_id( @Param("clint_id") String clint_id); 17 String getSchoolIdbyClint_id( @Param("clint_id") String clint_id);
18 18
  19 + /**
  20 + * 获取设备出入类型
  21 + * @param clint_id
  22 + * @return
  23 + */
  24 + @Select("select * from SZ_Attendance where clint_id = #{clint_id} ")
  25 + AttendanceBean getTypeByClint_id( @Param("clint_id") String clint_id);
  26 +
19 @Select("select * from SZ_Attendance where school_id = #{school_id} and clint_type = #{clint_type}") 27 @Select("select * from SZ_Attendance where school_id = #{school_id} and clint_type = #{clint_type}")
20 List<AttendanceBean> getAttendanceBeans(@Param("school_id") String school_id, @Param("clint_type") String clint_type); 28 List<AttendanceBean> getAttendanceBeans(@Param("school_id") String school_id, @Param("clint_type") String clint_type);
21 29
cloud/dahua/src/main/java/com/example/dahua/enums/EnumSzBusinessType.java
@@ -47,4 +47,21 @@ public interface EnumSzBusinessType { @@ -47,4 +47,21 @@ public interface EnumSzBusinessType {
47 } 47 }
48 } 48 }
49 49
  50 + /**
  51 + * 设备出入类型
  52 + */
  53 + public enum EnumDeviceInAndOut {
  54 +
  55 + INT(1, "进校"),
  56 + OUT(0, "出校");
  57 +
  58 + public final int code;
  59 + public final String name;
  60 +
  61 + EnumDeviceInAndOut(int code, String name) {
  62 + this.code = code;
  63 + this.name = name;
  64 + }
  65 + }
  66 +
50 } 67 }