/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.dom4j.Document
 *  org.dom4j.Element
 *  org.dom4j.io.SAXReader
 */
package com.hst.taxService.service.imp;

import com.hst.taxService.domain.DhXmlChannelDom;
import com.hst.taxService.domain.DhXmlDepartMentDom;
import com.hst.taxService.domain.DhXmlDeviceDom;
import com.hst.taxService.domain.DhXmlSaveDom;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ImportDhXml {
    public static void main(String[] args) throws Exception {
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File("C:\\Users\\zxc\\Desktop\\1.xml"));
        ArrayList<DhXmlSaveDom> saveList = new ArrayList<DhXmlSaveDom>();
        Element rootElement = document.getRootElement();
        Element department = rootElement.element("Department");
        if (department != null) {
            DhXmlSaveDom saveDom;
            DhXmlDepartMentDom departMentDm = new DhXmlDepartMentDom();
            departMentDm.setName(department.attributeValue("name"));
            departMentDm.setCoding(department.attributeValue("coding"));
            List devices = department.elements("Device");
            List channels = department.elements("Channel");
            for (Element e : devices) {
                String deviceId = e.attributeValue("id");
                DhXmlDeviceDom deviceDom = new DhXmlDeviceDom();
                deviceDom.setId(deviceId);
                for (Element c : channels) {
                    String channelId = c.attributeValue("id");
                    if (!channelId.startsWith(deviceId)) continue;
                    DhXmlChannelDom channelDom = new DhXmlChannelDom();
                    channelDom.setId(channelId);
                    deviceDom.getChannelDoms().add(channelDom);
                    saveDom = new DhXmlSaveDom();
                    saveDom.setChannelId(channelId);
                    saveDom.setSwjgMc(department.attributeValue("name"));
                    saveDom.setDeviceId(deviceId);
                    saveList.add(saveDom);
                }
                departMentDm.getDeviceDoms().add(deviceDom);
            }
            List departments2nd = department.elements("Department");
            for (Element e : departments2nd) {
                DhXmlDepartMentDom departMentDom2nd = new DhXmlDepartMentDom();
                departMentDom2nd.setName(e.attributeValue("name"));
                departMentDom2nd.setCoding(e.attributeValue("coding"));
                List devices2 = e.elements("Device");
                List channels2nd = e.elements("Channel");
                for (Element e2 : devices2) {
                    String deviceId = e2.attributeValue("id");
                    DhXmlDeviceDom deviceDom2nd = new DhXmlDeviceDom();
                    deviceDom2nd.setId(deviceId);
                    for (Element c2 : channels2nd) {
                        String channelId = c2.attributeValue("id");
                        if (!channelId.startsWith(deviceId)) continue;
                        DhXmlChannelDom channelDom2n = new DhXmlChannelDom();
                        channelDom2n.setId(channelId);
                        deviceDom2nd.getChannelDoms().add(channelDom2n);
                        saveDom = new DhXmlSaveDom();
                        saveDom.setChannelId(channelId);
                        saveDom.setSwjgMc(e.attributeValue("name"));
                        saveDom.setDeviceId(deviceId);
                        saveList.add(saveDom);
                    }
                    departMentDm.getDeviceDoms().add(deviceDom2nd);
                }
                List departments3rd = e.elements("Department");
                for (Element dep3 : departments3rd) {
                    DhXmlDepartMentDom departMentDom3rd = new DhXmlDepartMentDom();
                    departMentDom3rd.setName(dep3.attributeValue("name"));
                    departMentDom3rd.setCoding(dep3.attributeValue("coding"));
                    List devices3rd = dep3.elements("Device");
                    List channels3rd = dep3.elements("Channel");
                    for (Element e3 : devices3rd) {
                        String deviceId = e3.attributeValue("id");
                        DhXmlDeviceDom deviceDom3rd = new DhXmlDeviceDom();
                        deviceDom3rd.setId(deviceId);
                        for (Element c3 : channels3rd) {
                            String channelId = c3.attributeValue("id");
                            if (!channelId.startsWith(deviceId)) continue;
                            DhXmlChannelDom channelDom3rd = new DhXmlChannelDom();
                            channelDom3rd.setId(channelId);
                            deviceDom3rd.getChannelDoms().add(channelDom3rd);
                            saveDom = new DhXmlSaveDom();
                            saveDom.setChannelId(channelId);
                            saveDom.setSwjgMc(String.valueOf(e.attributeValue("name")) + "-" + dep3.attributeValue("name"));
                            saveDom.setDeviceId(deviceId);
                            saveList.add(saveDom);
                        }
                        departMentDom3rd.getDeviceDoms().add(deviceDom3rd);
                    }
                    departMentDom2nd.getDepartMentDoms().add(departMentDom3rd);
                }
                departMentDm.getDepartMentDoms().add(departMentDom2nd);
            }
            Element Devices = rootElement.element("Devices");
            if (Devices != null) {
                HashMap<String, String> map = new HashMap<String, String>();
                List deviceElemnts = Devices.elements("Device");
                for (Element device : deviceElemnts) {
                    System.out.println(String.valueOf(device.attributeValue("name")) + "-" + device.attributeValue("ip"));
                    List UnitNodes = device.elements("UnitNodes");
                    for (Element UnitNode : UnitNodes) {
                        List channles = UnitNode.elements("Channel");
                        for (Element channle : channles) {
                            map.put(channle.attributeValue("id"), channle.attributeValue("name"));
                        }
                    }
                }
                for (DhXmlSaveDom dom : saveList) {
                    dom.setChannelMc((String)map.get(dom.getChannelId()));
                }
            }
            System.out.printf("111", new Object[0]);
        }
    }
}
