From 3b0516a2959e25576e4f3fda697a3b025d06c8c9 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 24 六月 2025 14:09:07 +0800
Subject: [PATCH] 每日录像可用指标添加日志,修改大屏为查看当前月平均

---
 ycl-server/src/main/java/com/ycl/api/YS/YSApi.java |  164 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 142 insertions(+), 22 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/api/YS/YSApi.java b/ycl-server/src/main/java/com/ycl/api/YS/YSApi.java
index 3ec5e46..99c2336 100644
--- a/ycl-server/src/main/java/com/ycl/api/YS/YSApi.java
+++ b/ycl-server/src/main/java/com/ycl/api/YS/YSApi.java
@@ -6,59 +6,179 @@
 import com.ycl.api.DH.utils.DHApi;
 import com.ycl.api.YS.lib.NetDEVSDKLib;
 import com.ycl.api.YS.login.Login;
+import com.ycl.platform.domain.entity.TMonitor;
 import com.ycl.platform.domain.result.OSDResult;
+import com.ycl.utils.StringUtils;
+import enumeration.DeviceType;
 import lombok.extern.slf4j.Slf4j;
 
 import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.regex.Pattern;
 
 import static com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_LOGIN_PROTO_E.NETDEV_LOGIN_PROTO_ONVIF;
 
 @Slf4j
 public class YSApi {
 
-    public static OSDResult getOsd(String ip, String userName, String password){
-        log.info("ip:{},鐢ㄦ埛:{}锛屽瘑鐮�:{}",ip,userName,password);
+    public static OSDResult getOsd(TMonitor monitor, String ip, String userName, String password) {
         //鐧诲綍
         NetDEVSDKLib.NETDEV_DEVICE_LOGIN_INFO_S stDevLoginInfo = new NetDEVSDKLib.NETDEV_DEVICE_LOGIN_INFO_S();
         NetDEVSDKLib.NETDEV_SELOG_INFO_S stSELogInfo = new NetDEVSDKLib.NETDEV_SELOG_INFO_S();
-//        System.arraycopy(userName.getBytes(), 0, stDevLoginInfo.szUserName, 0, userName.getBytes().length);
-//        System.arraycopy(password.getBytes(), 0, stDevLoginInfo.szPassword, 0, password.getBytes().length);
-//        System.arraycopy(ip.getBytes(), 0, stDevLoginInfo.szIPAddr, 0, ip.getBytes().length);
-        stDevLoginInfo.szUserName = userName.getBytes();
-        stDevLoginInfo.szPassword = password.getBytes();
-        stDevLoginInfo.szIPAddr = ip.getBytes();
+        System.arraycopy(userName.getBytes(), 0, stDevLoginInfo.szUserName, 0, userName.getBytes().length);
+        System.arraycopy(password.getBytes(), 0, stDevLoginInfo.szPassword, 0, password.getBytes().length);
+        System.arraycopy(ip.getBytes(), 0, stDevLoginInfo.szIPAddr, 0, ip.getBytes().length);
         stDevLoginInfo.dwPort = 80;
         //鐧诲綍鍗忚
         stDevLoginInfo.dwLoginProto = NETDEV_LOGIN_PROTO_ONVIF;
-        log.info("SDK浼犲弬ip:{},鐢ㄦ埛:{}锛屽瘑鐮�:{}",stDevLoginInfo.szIPAddr,stDevLoginInfo.szUserName,stDevLoginInfo.szPassword);
-        Pointer lpUserID  = YSInit.netdevsdk.NETDEV_Login_V30(stDevLoginInfo, stSELogInfo);
+        Pointer lpUserID = YSInit.netdevsdk.NETDEV_Login_V30(stDevLoginInfo, stSELogInfo);
+        if (lpUserID != null) {
+            OSDResult osdResult = new OSDResult();
+            //鑾峰彇閫氶亾
+            int nMaxChlCount = 256;
+            IntByReference dwChlCount = new IntByReference(nMaxChlCount);
+            NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S[] stVideoChlList = (NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S[]) new NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S().toArray(nMaxChlCount);
+            boolean bRe = YSInit.netdevsdk.NETDEV_QueryVideoChlDetailListEx(lpUserID, dwChlCount, stVideoChlList);
+            if (!bRe) {
+//                log.error("error code" + YSInit.netdevsdk.NETDEV_GetLastError());
+                return null;
+            }
+            //鑾峰彇鏃堕棿
+            NetDEVSDKLib.NETDEV_TIME_CFG_S stTimeCfg = new NetDEVSDKLib.NETDEV_TIME_CFG_S();
+            stTimeCfg.write();
+            boolean bRetime = NetDemo.netdevsdk.NETDEV_GetSystemTimeCfg(lpUserID, stTimeCfg);
+            Date checkTime = new Date();
+            osdResult.setCheckTime(checkTime);
+            if (!bRetime) {
+//                log.error("error code" + YSInit.netdevsdk.NETDEV_GetLastError());
+                return null;
+            } else {
+                stTimeCfg.read();
+                String strTime = "" + stTimeCfg.stTime.dwYear + "-";
+                if (stTimeCfg.stTime.dwMonth < 10) {
+                    strTime += "0";
+                }
+                strTime = strTime + stTimeCfg.stTime.dwMonth + "-";
+                if (stTimeCfg.stTime.dwDay < 10) {
+                    strTime += "0";
+                }
+                strTime = strTime + stTimeCfg.stTime.dwDay + " ";
+                if (stTimeCfg.stTime.dwHour < 10) {
+                    strTime += "0";
+                }
+                strTime = strTime + stTimeCfg.stTime.dwHour + ":";
+                if (stTimeCfg.stTime.dwMinute < 10) {
+                    strTime += "0";
+                }
+                strTime = strTime + stTimeCfg.stTime.dwMinute + ":";
 
-        log.info("鐧诲綍杩斿洖id:{}",lpUserID);
-        if(lpUserID !=null) {
-            log.info("鐧诲綍鎴愬姛");
+                if (stTimeCfg.stTime.dwSecond < 10) {
+                    strTime += "0";
+                }
+                strTime = strTime + stTimeCfg.stTime.dwSecond;
+                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                try {
+                    osdResult.setOsdTime(format.parse(strTime));
+                } catch (Exception e) {
+//                    log.error(ip + "鏃堕棿瑙f瀽鏈夎");
+                }
+            }
             //鑾峰彇osd
             NetDEVSDKLib.NETDEV_VIDEO_OSD_CFG_S stOSDInfo = new NetDEVSDKLib.NETDEV_VIDEO_OSD_CFG_S();
             stOSDInfo.write();
             IntByReference dwBytesReturned = new IntByReference();
 
-            boolean bRet = YSInit.netdevsdk.NETDEV_GetDevConfig(lpUserID, 0, NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E.NETDEV_GET_OSDCFG, stOSDInfo.getPointer(), 616, dwBytesReturned);
+            boolean bRet = YSInit.netdevsdk.NETDEV_GetDevConfig(lpUserID, stVideoChlList[0].dwChannelID, NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E.NETDEV_GET_OSDCFG, stOSDInfo.getPointer(), 616, dwBytesReturned);
             if (!bRet) {
-                log.error("error code"+YSInit.netdevsdk.NETDEV_GetLastError());
+//                log.error("error code" + YSInit.netdevsdk.NETDEV_GetLastError());
                 return null;
             }
             stOSDInfo.read();
-            for (NetDEVSDKLib.NETDEV_OSD_TEXT_OVERLAY_S osd : stOSDInfo.astTextOverlay) {
-                String text = new String(osd.szOSDText, StandardCharsets.UTF_8);
-                log.info("text:" + text);
+
+
+            String name = new String(stOSDInfo.stNameOSD.szOSDText, StandardCharsets.UTF_8).trim();
+            //姝e垯鍚嶅瓧 濡傛灉鍑虹幇鐗规畩瀛楃 鍒欒皟鐢╠h鐨勬帴鍙�
+            log.error("YSname:{}" , name);
+
+            // 姝e垯琛ㄨ揪寮忥紙鍖归厤鍖呭惈 锟� 瀛楃鐨勫瓧绗︿覆锛�
+            String regex = ".*\\uFFFD.*"; // 鏍稿績閫昏緫锛氬尮閰嶄换鎰忎綅缃嚭鐜� 锟� 鐨勫瓧绗︿覆
+            // 缂栬瘧姝e垯琛ㄨ揪寮�
+            Pattern pattern = Pattern.compile(regex);
+            boolean isMatch  = pattern.matcher(name).matches();
+            if(isMatch){
+                log.error("鍑虹幇姝e垯鍚嶅瓧涓湁鐗规畩瀛楃:{}" , name);
+                //澶у崕
+                OSDResult osd = DHApi.getOsd(monitor.getName(),monitor.getSerialNumber(),monitor.getIp(), monitor.getUsername(),monitor.getPassword());
+                OSDResult osdResult2 = checkSuccess(monitor, osd);
+                log.error("osdResult2");
+                if (osdResult2!=null) {
+                    return osd;
+                }else {
+                    return null;
+                }
             }
+
+            if (StringUtils.isNotEmpty(name) && name.contains("|")){
+                String[] osdNames = name.split("\\|");
+                for (int i = 0; i < osdNames.length; i++) {
+                    if (i == 0) {
+                        osdResult.setOSD1(osdNames[i]);
+                    }
+                    if (i == 1) {
+                        osdResult.setOSD2(osdNames[i]);
+                    }
+                    if (i == 2) {
+                        osdResult.setOSD3(osdNames[i]);
+                    }
+                    if (i == 3) {
+                        osdResult.setName(osdNames[i]);
+                    }
+                }
+            }else {
+                //鐪佷唤
+                osdResult.setOSD1(name);
+//                log.info("YSname"+name);
+                int num = 0;
+                for (NetDEVSDKLib.NETDEV_OSD_TEXT_OVERLAY_S osd : stOSDInfo.astTextOverlay) {
+                    String text = new String(osd.szOSDText, StandardCharsets.UTF_8).trim();
+                    log.info("YSnum:"+num+",YStexr:"+text);
+                    if (num == 0) {
+                        osdResult.setOSD2(text);
+                    } else if (num == 1) {
+                        osdResult.setOSD3(text);
+                    } else if (num == 2) {
+                        osdResult.setName(text);
+                    } else if (num == 3) {
+                        osdResult.setOSD4(text);
+                    }
+                    num++;
+                }
+            }
+
+
             //鐧诲嚭
             YSInit.netdevsdk.NETDEV_Logout(lpUserID);
-        }else {
-            log.error("error code"+YSInit.netdevsdk.NETDEV_GetLastError());
+            osdResult.setDeviceBrand(DeviceType.YS.getType());
+            return osdResult;
+        } else {
+//            log.error("ip:"+ip+",error code" + YSInit.netdevsdk.NETDEV_GetLastError());
+            return null;
         }
-        return null;
     }
-    public static void demo(){
+
+    //OSDCheckThread鏂规硶
+    private static OSDResult checkSuccess(TMonitor monitor, OSDResult osd) {
+        if (osd != null) {
+            osd.setSerialNumber(monitor.getSerialNumber());
+            return osd;
+        } else {
+            return null;
+        }
+    }
+
+
+    public static void demo() {
         Login.loginIn();
     }
 }

--
Gitblit v1.8.0