From 46c0be4ad0028db3d9a41e29d9a5b46ab46056a0 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期四, 05 十二月 2024 18:17:46 +0800
Subject: [PATCH] 省厅标签拆分2
---
ycl-server/src/main/java/com/ycl/api/HK/HKApi.java | 76 ++++++++++++++++++++++++++++---------
1 files changed, 57 insertions(+), 19 deletions(-)
diff --git a/ycl-server/src/main/java/com/ycl/api/HK/HKApi.java b/ycl-server/src/main/java/com/ycl/api/HK/HKApi.java
index cd6869c..b6c5c17 100644
--- a/ycl-server/src/main/java/com/ycl/api/HK/HKApi.java
+++ b/ycl-server/src/main/java/com/ycl/api/HK/HKApi.java
@@ -1,7 +1,9 @@
package com.ycl.api.HK;
import com.ycl.platform.domain.result.OSDResult;
+import com.ycl.utils.StringUtils;
import constant.ApiConstants;
+import enumeration.DeviceType;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
@@ -31,30 +33,69 @@
@Slf4j
public class HKApi {
- public static OSDResult getOsdByIP(String ip, String userName, String password) {
+ public static OSDResult getOsdByIP(String serialNumber, String ip, String userName, String password) {
OSDResult osdResult = new OSDResult();
String hostUrl = "http://" + ip;
try {
//鑾峰彇OSD
- String OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH, userName, password);
+ /**
+ * 閫氳繃鍥芥爣鍊掓暟绗竷浣嶅垽鏂�氶亾 0/鍏ㄦ櫙 1/缁嗚妭
+ * 瀵逛簬娴峰悍鏉ヨ锛� 鍥芥爣鍊�7 0/鍏ㄦ櫙/閫氶亾2 1/缁嗚妭/閫氶亾1
+ * 瀵逛簬澶у崕鏉ヨ锛� 鍥芥爣鍊�7 0/鍏ㄦ櫙/閫氶亾1 1/缁嗚妭/閫氶亾2
+ * 瀹囪鍗曢�氶亾涓嶈�冭檻
+ */
+ String OSDString = null;
+ if(StringUtils.isEmpty(serialNumber)) return null;
+ if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_All ) {
+ OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password);
+ }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_Detail){
+ OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password);
+ }
+ //閫氳繃璁惧绫诲瀷鍒ゆ柇锛堝純鐢級
+// if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 1 ){
+// //鏋満
+// if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 1){
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password);
+// }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 0){
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password);
+// }
+// }else if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 2){
+// //鐞冩満
+// if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 0){
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password);
+// }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 1){
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password);
+// }
+// }else if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 3){
+// //鍗″彛 鍗曢�氶亾
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password);
+// }else if(serialNumber.charAt(ApiConstants.SerialNumber_Category) == 4){
+// //楂樼┖
+// if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 0){
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_1, userName, password);
+// }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == 1){
+// OSDString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_PATH_2, userName, password);
+// }
+// }
if (OSDString == null) return null;
//瑙f瀽xml
- parseXMl(OSDString, "TextOverlay", "displayText", osdResult, null,ip);
+ parseXMl(OSDString, "TextOverlay", "displayText", osdResult, null, ip);
//鑾峰彇Time
String timeString = getHttpResponse(hostUrl + ApiConstants.HK_OSD_TIME, userName, password);
if (timeString == null) return null;
Date date = new Date();
//瑙f瀽xml
- parseXMl(timeString, "Time", "localTime", osdResult, date,ip);
+ parseXMl(timeString, "Time", "localTime", osdResult, date, ip);
+ osdResult.setDeviceBrand(DeviceType.HK.getType());
} catch (Exception e) {
return null;
}
return osdResult;
}
- private static void parseXMl(String OSDString, String tagName1, String tagName2, OSDResult osdResult, Date date,String ip) throws ParserConfigurationException, SAXException, IOException {
+ private static void parseXMl(String OSDString, String tagName1, String tagName2, OSDResult osdResult, Date date, String ip) throws ParserConfigurationException, SAXException, IOException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -66,26 +107,23 @@
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE && "TextOverlay".equals(tagName1)) {
Element element = (Element) node;
- String id = element.getElementsByTagName("id").item(0).getTextContent();
String textContent = element.getElementsByTagName(tagName2).item(0).getTextContent();
- // log.info("TEXT : " + textContent);
- if ("1".equals(id)) {
+ // log.info("TEXT : " + textContent);
+ if (i == 0) {
osdResult.setOSD1(textContent);
- } else if ("2".equals(id)) {
+ } else if (i == 1) {
osdResult.setOSD2(textContent);
- } else if ("3".equals(id)) {
+ } else if (i == 2) {
osdResult.setOSD3(textContent);
- } else if ("4".equals(id)) {
+ } else if (i == 3) {
osdResult.setName(textContent);
- } else if ("5".equals(id)) {
- osdResult.setName2(textContent);
- } else if ("7".equals(id)) {
+ } else if (i == 4) {
osdResult.setOSD4(textContent);
}
} else if (node.getNodeType() == Node.ELEMENT_NODE && "Time".equals(tagName1)) {
Element element = (Element) node;
String textContent = element.getElementsByTagName(tagName2).item(0).getTextContent();
- // log.info("TEXT : " + textContent);
+ // log.info("TEXT : " + textContent);
osdResult.setCheckTime(date);
OffsetDateTime dateTime = OffsetDateTime.parse(textContent);
// 灏哋ffsetDateTime杞崲涓篋ate瀵硅薄
@@ -93,8 +131,8 @@
}
}
} catch (Exception e) {
- log.error("ip:{}鍑虹幇寮傚父,{}",ip,e.getMessage());
- throw new RuntimeException(e.getMessage());
+ log.error("ip:{}鍑虹幇寮傚父,{}", ip, e.getMessage());
+ throw new RuntimeException(e.getMessage());
}
}
@@ -112,8 +150,8 @@
// 璁剧疆璇锋眰閰嶇疆
RequestConfig requestConfig = RequestConfig.custom()
- .setConnectTimeout(1000)
- .setSocketTimeout(1000)
+ .setConnectTimeout(3000)
+ .setSocketTimeout(3000)
.build();
httpGet.setConfig(requestConfig);
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
--
Gitblit v1.8.0