648540858
2024-05-29 764d04b497356ba6bcbb75fd42b51eca750f7223
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
@@ -3,11 +3,12 @@
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.CivilCodePo;
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
import com.genersoft.iot.vmp.utils.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.dom4j.Attribute;
import org.dom4j.Document;
@@ -74,6 +75,50 @@
        Element e = em.element(tag);
        //
        return null == e ? null : e.getText().trim();
    }
    /**
     * 获取element对象的text的值
     *
     * @param em  节点的对象
     * @param tag 节点的tag
     * @return 节点
     */
    public static Double getDouble(Element em, String tag) {
        if (null == em) {
            return null;
        }
        Element e = em.element(tag);
        if (null == e) {
            return null;
        }
        String text = e.getText().trim();
        if (ObjectUtils.isEmpty(text) || !NumberUtils.isParsable(text)) {
            return null;
        }
        return Double.parseDouble(text);
    }
    /**
     * 获取element对象的text的值
     *
     * @param em  节点的对象
     * @param tag 节点的tag
     * @return 节点
     */
    public static Integer getInteger(Element em, String tag) {
        if (null == em) {
            return null;
        }
        Element e = em.element(tag);
        if (null == e) {
            return null;
        }
        String text = e.getText().trim();
        if (ObjectUtils.isEmpty(text) || !NumberUtils.isParsable(text)) {
            return null;
        }
        return Integer.parseInt(text);
    }
    /**
@@ -195,7 +240,7 @@
        CivilCode, BusinessGroup,VirtualOrganization,Other
    }
    public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event, CivilCodeFileConf civilCodeFileConf){
    public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event){
        DeviceChannel deviceChannel = new DeviceChannel();
        deviceChannel.setDeviceId(device.getDeviceId());
        Element channdelIdElement = itemDevice.element("DeviceID");
@@ -214,12 +259,15 @@
            return deviceChannel;
        }
        Element nameElement = itemDevice.element("Name");
        if (nameElement != null) {
        // 当通道名称为空时,设置通道名称为通道编码,避免级联时因通道名称为空导致上级接收通道失败
        if (nameElement != null && StringUtils.isNotBlank(nameElement.getText())) {
            deviceChannel.setName(nameElement.getText());
        } else {
            deviceChannel.setName(channelId);
        }
        if(channelId.length() <= 8) {
            deviceChannel.setHasAudio(false);
            CivilCodePo parentCode = civilCodeFileConf.getParentCode(channelId);
            CivilCodePo parentCode = CivilCodeUtil.INSTANCE.getParentCode(channelId);
            if (parentCode != null) {
                deviceChannel.setParentId(parentCode.getCode());
                deviceChannel.setCivilCode(parentCode.getCode());
@@ -484,16 +532,17 @@
                    String status = getText(itemDevice, "Status");
                    if (status != null) {
                        // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
                        if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
                        if (status.equalsIgnoreCase("ON") || status.equalsIgnoreCase("On") || status.equalsIgnoreCase("ONLINE") || status.equalsIgnoreCase("OK")) {
                            deviceChannel.setStatus(true);
                        }
                        if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
                        if (status.equalsIgnoreCase("OFF") || status.equalsIgnoreCase("Off") || status.equalsIgnoreCase("OFFLINE")) {
                            deviceChannel.setStatus(false);
                        }
                    }else {
                        deviceChannel.setStatus(true);
                    }
//                    logger.info("状态字符串: {}", status);
//                    logger.info("状态结果: {}", deviceChannel.isStatus());
                    // 经度
                    String longitude = getText(itemDevice, "Longitude");
                    if (NumericUtil.isDouble(longitude)) {
@@ -520,14 +569,14 @@
                        String ptzTypeFromInfo = XmlUtil.getText(info, "PTZType");
                        if(!ObjectUtils.isEmpty(ptzTypeFromInfo)){
                            try {
                                deviceChannel.setPTZType(Integer.parseInt(ptzTypeFromInfo));
                                deviceChannel.setPtzType(Integer.parseInt(ptzTypeFromInfo));
                            }catch (NumberFormatException e){
                                logger.warn("[xml解析] 从通道数据info中获取PTZType失败: {}", ptzTypeFromInfo);
                            }
                        }
                    } else {
                        try {
                            deviceChannel.setPTZType(Integer.parseInt(ptzType));
                            deviceChannel.setPtzType(Integer.parseInt(ptzType));
                        }catch (NumberFormatException e){
                            logger.warn("[xml解析] 从通道数据中获取PTZType失败: {}", ptzType);
                        }