lxw
2022-10-31 3dd3a893194e6d6756fffaf41171edbbcee6efd2
解析文件加版本
2个文件已修改
180 ■■■■■ 已修改文件
src/main/java/com/whyc/dto/XmlFileOpreate.java 160 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/FileParam.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/XmlFileOpreate.java
@@ -15,10 +15,126 @@
import java.util.*;
public class XmlFileOpreate {
    //解析FBR-6000NT基础2.7
    public static FileInfo readFBR_6000NT_jc(String xmlFilePath){
        FileInfo fileInfo=new FileInfo();//文件信息
        FileParam fparam=fileInfo.getFileParam();//文件参数
        boolean res = true;
        try
        {
            SAXReader reader = new SAXReader();
            FileInputStream  fiso=new FileInputStream(xmlFilePath);
            Document document = reader.read(fiso);
            Element rootnode = document.getRootElement();
    //解析xml文件
    public static FileInfo readXml(String xmlFilePath)
    {
            Element node;//根节点
            Element file_node;//文件节点
            //------------------------------------------------------------//
            node = rootnode.element("TEST_TIME");
            String testTime=node.getTextTrim();
            testTime=testTime.replace("_"," ");
            fparam.setTestTime(ActionUtil.sdfwithALL.parse(testTime));
            //------------------------------------------------------------//
            node = rootnode.element("VERSION");
            fparam.setVersion(node.getTextTrim());
            //------------------------------------------------------------//
            node = rootnode.element("BATT_PARAM");
            file_node=node.element("batt_group_name");
            fparam.setBattGroupName(file_node.getTextTrim());
            file_node=node.element("batt_producer");
            if(file_node!=null){
                fparam.setBattProducer(file_node.getTextTrim());
            }
            file_node=node.element("batt_cap");
            fparam.setBattCap(Float.parseFloat(file_node.getTextTrim()));
            file_node=node.element("batt_count");
            fparam.setBattCount(Integer.parseInt(file_node.getTextTrim()));
            file_node=node.element("batt_vol");
            fparam.setBattVol(Float.parseFloat(file_node.getTextTrim()));
            file_node=node.element("batt_vol_good");
            if(file_node!=null){
                fparam.setBattVolGood(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("batt_vol_bad");
            if(file_node!=null){
                fparam.setBattVolBad(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("batt_res");
            fparam.setBattRes(Float.parseFloat(file_node.getTextTrim()));
            file_node=node.element("batt_res_good");
            if(file_node!=null){
                fparam.setBattResGood(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("batt_res_bad");
            if(file_node!=null){
                fparam.setBattResBad(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("batt_ser");
            fparam.setBattSer(Float.parseFloat(file_node.getTextTrim()));
            file_node=node.element("batt_ser_good");
            if(file_node!=null){
                fparam.setBattSerGood(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("batt_ser_bad");
            if(file_node!=null){
                fparam.setBattSerBad(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("concount_pb");
            fparam.setConcountPb(Integer.parseInt(file_node.getTextTrim()));
            file_node=node.element("conn_res");
            if(file_node!=null){
                fparam.setConnRes(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("conn_res_good");
            if(file_node!=null){
                fparam.setConnResGood(Float.parseFloat(file_node.getTextTrim()));
            }
            file_node=node.element("conn_res_bad");
            if(file_node!=null){
                fparam.setConnResBad(Float.parseFloat(file_node.getTextTrim()));
            }
            //-----根据groupNum的值读取测试数据---------------------------//
            Iterator nodes = rootnode.elementIterator("node_batt_num");
            while (nodes.hasNext()){
                node= (Element) nodes.next();
                BattgroupInfo battInfo=new BattgroupInfo();
                List<BattgroupData> battDataList=new ArrayList();
                BattgroupData battData=new BattgroupData();
                battData.setMonNum(Integer.parseInt(node.attributeValue("batt_num")));
                file_node=node.element("bv_1");
                battData.setBv(file_node.getTextTrim());
                file_node=node.element("br_1");
                battData.setBr(file_node.getTextTrim());
                file_node=node.element("bs_1");
                battData.setBs(file_node.getTextTrim());
                file_node=node.element("cr_1");
                battData.setCr(file_node.getTextTrim());
                battDataList.add(battData);
                battInfo.setBattDataList(battDataList);
                fileInfo.getBattInfoList().add(battInfo);
            }
            fileInfo.setFileParam(fparam);
            fiso.close();
        } catch (NullPointerException | NumberFormatException | DocumentException | ParseException | FileNotFoundException e) {
            res = false;
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(false == res)
                return null;
        }
        return fileInfo;
    }
    //解析FBR-6000NT带标记版本2.0
    public static FileInfo readFBR_6000NT_bj(String xmlFilePath){
        boolean res = true;
        FileInfo fileInfo=new FileInfo();//文件信息
        FileParam fparam=fileInfo.getFileParam();//文件参数
@@ -36,6 +152,7 @@
            //------------------------------------------------------------//
            node = rootnode.element("TEST_TIME");
            String testTime=node.getTextTrim();
            testTime.replace("_"," ");
            fparam.setTestTime(ActionUtil.sdfwithALL.parse(testTime));
            //------------------------------------------------------------//
            node = rootnode.element("VERSION");
@@ -144,6 +261,35 @@
        }
        return  fileInfo;
    }
    //解析xml文件
    public static FileInfo readXml(String xmlFilePath)
    {
        FileInfo fileInfo=new FileInfo();
        try
        {
            SAXReader reader = new SAXReader();
            FileInputStream  fiso=new FileInputStream(xmlFilePath);
            Document document = reader.read(fiso);
            Element rootnode = document.getRootElement();
            //------------------------------------------------------------//
            Element node = rootnode.element("VERSION");
            if(node!=null){
                String version=node.getTextTrim();
                switch (version){
                    case "V2.0": fileInfo=readFBR_6000NT_bj(xmlFilePath);break;
                    case "V2.7": fileInfo=readFBR_6000NT_jc(xmlFilePath);break;
                    default:break;
                }
            }
            fiso.close();
        } catch (NullPointerException | NumberFormatException | DocumentException  | FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return  fileInfo;
    }
    public static boolean writeXml( Map<String,String> map,String xmlFilePath){
        boolean res=true;
@@ -177,10 +323,10 @@
    }
    public static void main(String[] args) {
        String filePath="D://2022-06-14 16-02-34.xml";
        String filePath="D:\\fileTest\\FBR-5000CT -原数据20221031\\\\2022-10-31_09-14-48.xml";
        Map map=new HashMap() ;
        //FileInfo fileInfo=XmlFileOpreate.readXml(filePath);
        //System.out.println(fileInfo);
        FileInfo fileInfo=XmlFileOpreate.readXml(filePath);
        System.out.println(fileInfo);
        map.put("ChainRes", "50.0");
        map.put("battTestNum","9");
        map.put("battModel","SD-001");
@@ -211,6 +357,6 @@
        map.put("batt_group_name","后备电源室1#UPS系统lxw");
        map.put("battStation","鼓楼站lxw");
        XmlFileOpreate.writeXml(map,filePath);
        //XmlFileOpreate.writeXml(map,filePath);
    }
}
src/main/java/com/whyc/pojo/FileParam.java
@@ -95,9 +95,29 @@
    @ApiModelProperty(value = "标称电压")
    private Float battVol;
    private Float battVolGood;
    private Float battVolBad;
    @ApiModelProperty(value = "标称内阻(毫欧)")
    private Float battRes;
    private Float battResGood;
    private Float battResBad;
    @ApiModelProperty(value = "标称电导")
    private Float battSer;
    private Float battSerGood;
    private Float battSerBad;
    @ApiModelProperty(value = "连接条阻抗")
    private Float connRes;
    private Float connResGood;
    private Float connResBad;
    @ApiModelProperty(value = "concount_pb")
    private Integer concountPb;
    @ApiModelProperty(value = "厂家")
    private String battProducer;
    @ApiModelProperty(value = "组数")
    private Integer groupNum;