fuliqi
2024-09-11 b14531e3b850fe6d2fa916ba7b88b3e2bd2ff30a
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;
@@ -40,21 +42,22 @@
            if (OSDString == null) return null;
            //解析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();
            //解析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();
@@ -67,7 +70,7 @@
                if (node.getNodeType() == Node.ELEMENT_NODE && "TextOverlay".equals(tagName1)) {
                    Element element = (Element) node;
                    String textContent = element.getElementsByTagName(tagName2).item(0).getTextContent();
    //                log.info("TEXT : " + textContent);
                    //                log.info("TEXT : " + textContent);
                    if (i == 0) {
                        osdResult.setOSD1(textContent);
                    } else if (i == 1) {
@@ -82,7 +85,7 @@
                } 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);
                    // 将OffsetDateTime转换为Date对象
@@ -90,8 +93,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());
        }
    }
@@ -109,8 +112,8 @@
        // 设置请求配置
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(1000)
                .setSocketTimeout(1000)
                .setConnectTimeout(3000)
                .setSocketTimeout(3000)
                .build();
        httpGet.setConfig(requestConfig);
        try (CloseableHttpResponse response = httpClient.execute(httpGet)) {