Ver código fonte

异常处理

yingp 6 anos atrás
pai
commit
dd40c57de2

+ 5 - 3
applications/device/device-client/src/main/java/com/usoftchina/smartschool/device/client/listener/AccessControlListener.java

@@ -3,6 +3,7 @@ package com.usoftchina.smartschool.device.client.listener;
 import com.usoftchina.smartschool.device.client.po.AccessControl;
 import com.usoftchina.smartschool.device.client.service.AccessControlService;
 import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+import com.usoftchina.smartschool.device.dto.DeviceInfo;
 import com.usoftchina.smartschool.device.event.AccessControlEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,15 +32,16 @@ public class AccessControlListener {
     @EventListener(AccessControlEvent.class)
     public void onAccessControlEvent(AccessControlEvent event) {
         AccessControlInfo info = event.getAccessControlInfo();
-        AccessControl accessControl = accessControlService.findById(event.getDeviceId());
+        DeviceInfo device = event.getDevice();
+        AccessControl accessControl = accessControlService.findById(device.getId());
         // 通过门禁设备绑定的访问类型,来设置本次事件的访问类型
         if (accessControl.isEntryType()) {
             info.setEventType(AccessControlInfo.EventType.ENTRY);
         } else {
             info.setEventType(AccessControlInfo.EventType.EXIT);
         }
-        if(logger.isDebugEnabled()) {
-            logger.debug(info.toString());
+        if (logger.isDebugEnabled()) {
+            logger.debug("Device[{}] Port[{}] AccessControlEvent[{}]", device.getIp(), device.getPort(), info.toString());
         }
         try {
             accessControlService.saveRecord(info);

+ 7 - 17
applications/device/device-sdk-dahua/src/main/java/com/usoftchina/smartschool/device/dahua/lib/DahuaLibrary.java

@@ -1467,30 +1467,20 @@ public interface DahuaLibrary extends Library {
         public String toString() {
             return "DEV_EVENT_ACCESS_CTL_INFO{" +
                     "nChannelID=" + nChannelID +
-                    ", szName=" + new String(szName) +
+                    ", szName=" + new String(szName).trim() +
                     ", PTS=" + PTS +
                     ", UTC=" + UTC +
                     ", nEventID=" + nEventID +
-                    ", stuObject=" + stuObject +
-                    ", stuFileInfo=" + stuFileInfo +
                     ", emEventType=" + emEventType +
                     ", bStatus=" + bStatus +
                     ", emCardType=" + emCardType +
                     ", emOpenMethod=" + emOpenMethod +
-                    ", szCardNo=" + new String(szCardNo) +
-                    ", szPwd=" + new String(szPwd) +
-                    ", szReaderID=" + new String(szReaderID) +
-                    ", szUserID=" + new String(szUserID) +
-                    ", szSnapURL=" + new String(szSnapURL) +
-                    ", nErrorCode=" + nErrorCode +
-                    ", nPunchingRecNo=" + nPunchingRecNo +
-                    ", nNumbers=" + nNumbers +
-                    ", byImageIndex=" + byImageIndex +
-                    ", dwSnapFlagMask=" + dwSnapFlagMask +
-                    ", emAttendanceState=" + emAttendanceState +
-                    ", szClassNumber=" + new String(szClassNumber) +
-                    ", szPhoneNumber=" + new String(szPhoneNumber) +
-                    ", szCardName=" + new String(szCardName, DEFAULT_CHARSET) +
+                    ", szCardNo=" + new String(szCardNo).trim() +
+                    ", szUserID=" + new String(szUserID).trim() +
+                    ", szSnapURL=" + new String(szSnapURL).trim() +
+                    ", szClassNumber=" + new String(szClassNumber).trim() +
+                    ", szPhoneNumber=" + new String(szPhoneNumber).trim() +
+                    ", szCardName=" + new String(szCardName, DEFAULT_CHARSET).trim() +
                     ", uSimilarity=" + (uSimilarity & 0x0ffffffff) +
                     '}';
         }

+ 10 - 10
applications/device/device-sdk-dahua/src/main/java/com/usoftchina/smartschool/device/dahua/service/DahuaDataAnalyzeService.java

@@ -9,6 +9,7 @@ import com.usoftchina.smartschool.device.dahua.lib.DahuaLibrary.*;
 import com.usoftchina.smartschool.device.dahua.lib.DahuaSdk;
 import com.usoftchina.smartschool.device.dahua.lib.DahuaSdkException;
 import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+import com.usoftchina.smartschool.device.dto.DeviceInfo;
 import com.usoftchina.smartschool.device.event.AccessControlEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,14 +40,14 @@ public class DahuaDataAnalyzeService {
     /**
      * 启动智能数据监听
      *
-     * @param deviceId 门禁设备ID
+     * @param device 门禁设备
      * @param loginHandle 登录句柄
      */
-    public void startListen(String deviceId, NativeLong loginHandle) {
+    public void startListen(DeviceInfo device, NativeLong loginHandle) {
         long key = loginHandle.longValue();
         if (key != 0 && !analyzerHandles.containsKey(key)) {
             NativeLong lAnalyzerHandle = sdk.getInstance().CLIENT_RealLoadPictureEx(loginHandle, 0,
-                    DahuaEvents.EVENT_IVS_ALL, true, new AnalyzerDataCallBack(deviceId),
+                    DahuaEvents.EVENT_IVS_ALL, true, new AnalyzerDataCallBack(device),
                     new NativeLong(), null);
             analyzerHandles.put(key, lAnalyzerHandle);
         }
@@ -56,11 +57,11 @@ public class DahuaDataAnalyzeService {
      * 智能分析数据回调
      */
     class AnalyzerDataCallBack implements fAnalyzerDataCallBack {
-        private final String deviceId;
+        private final DeviceInfo device;
 
-        public AnalyzerDataCallBack(String deviceId) {
+        public AnalyzerDataCallBack(DeviceInfo device) {
             super();
-            this.deviceId = deviceId;
+            this.device = device;
         }
 
         @Override
@@ -73,18 +74,17 @@ public class DahuaDataAnalyzeService {
                 case DahuaEvents.EVENT_IVS_ACCESS_CTL:
                     DEV_EVENT_ACCESS_CTL_INFO info = new DEV_EVENT_ACCESS_CTL_INFO(pAlarmInfo);
                     if (logger.isDebugEnabled()) {
-                        logger.debug(info.toString());
+                        logger.debug("Device[{}] Port[{}] CallBack[{}]", device.getIp(), device.getPort(), info.toString());
                     }
                     AccessControlInfo accessControlInfo = new AccessControlInfo();
                     if (dwBufSize > 0) {
                         accessControlInfo.setImageData(pBuffer.getByteArray(0, dwBufSize));
                     }
-                    accessControlInfo.setCardNo(new String(info.szCardNo));
+                    accessControlInfo.setCardNo(new String(info.szCardNo).trim());
                     accessControlInfo.setEventType(convertEventType(info.emEventType));
                     accessControlInfo.setOpenMethod(convertOpenMethod(info.emOpenMethod));
                     accessControlInfo.setEventTime(info.UTC.toDate());
-                    SpringContextHolder.getContext().publishEvent(new AccessControlEvent(this,
-                            deviceId, accessControlInfo));
+                    SpringContextHolder.getContext().publishEvent(new AccessControlEvent(this, device, accessControlInfo));
                     // 其他地方可通过监听 AccessControlEvent 来扩展
                     break;
                 /**

+ 1 - 1
applications/device/device-sdk-dahua/src/main/java/com/usoftchina/smartschool/device/dahua/service/DahuaDeviceService.java

@@ -44,7 +44,7 @@ public class DahuaDeviceService implements DeviceApi {
             NativeLong loginHandle = login(info.getIp(), info.getPort(), info.getUsername(), info.getPassword());
             loginHandles.put(id, loginHandle);
             // 开启智能事件监听
-            dataAnalyzeService.startListen(info.getId(), loginHandle);
+            dataAnalyzeService.startListen(info, loginHandle);
         }
     }
 

+ 7 - 6
applications/device/device-sdk/src/main/java/com/usoftchina/smartschool/device/event/AccessControlEvent.java

@@ -1,6 +1,7 @@
 package com.usoftchina.smartschool.device.event;
 
 import com.usoftchina.smartschool.device.dto.AccessControlInfo;
+import com.usoftchina.smartschool.device.dto.DeviceInfo;
 import org.springframework.context.ApplicationEvent;
 
 /**
@@ -11,22 +12,22 @@ import org.springframework.context.ApplicationEvent;
  */
 public class AccessControlEvent extends ApplicationEvent {
 
-    private final String deviceId;
+    private final DeviceInfo device;
     private final AccessControlInfo accessControlInfo;
 
-    public AccessControlEvent(Object source, String deviceId, AccessControlInfo accessControlInfo) {
+    public AccessControlEvent(Object source, DeviceInfo device, AccessControlInfo accessControlInfo) {
         super(source);
-        this.deviceId = deviceId;
+        this.device = device;
         this.accessControlInfo = accessControlInfo;
     }
 
     /**
-     * 产生事件的门禁设备ID
+     * 产生事件的门禁设备
      *
      * @return
      */
-    public String getDeviceId() {
-        return deviceId;
+    public DeviceInfo getDevice() {
+        return device;
     }
 
     public AccessControlInfo getAccessControlInfo() {