数据格式:

{\"id\": \"131d4580-1f1a-4a20-9ad5-d74a30d1b73a\",\"name\": \"parent1\",\"count\": 6112,\"records\": 110478481,\"deltaRecords\": 913979,\"size\": 19826131158,\"children\": [{\"id\": \"131d4580-1f1a-4a20-9ad5-d74a30d1b73a\",\"name\": \"parent2\",\"count\": 6112,\"records\": 110478481,\"deltaRecords\": 913979,\"size\": 19826131158,\"children\": [],\"datasets\": [],\"statTime\": 1545015662762}],\"datasets\": [],\"statTime\": 1545015662762}

后台代码:

实体类:

DataSetOne:

public class DataSetOne extends  Data {

    //  id
    private String id;
    //  名称
    private String name;
    //  系统数
    private BigInteger count;
    //  记录数
    private BigInteger records;
    //  增量
    private BigInteger deltaRecords;
    //  大小
    private BigInteger size;
    //  数据格式
    private String format;
    //  文件路径
    private String path;
    //  子集
    private List<DataSetChild> children;
    //  数据集列表
    private List<DataSet> datasets;
    //  统计时间
    private Date statTime;
    //  父节点 id
    private String parentId;
    //  级数
    private BigInteger level;
    //  系统类型
    private BigInteger type;

    @Override
    public String toString() {
        return \"DataSet{\" +
                \"id=\'\" + id + \'\\\'\' +
                \", name=\'\" + name + \'\\\'\' +
                \", count=\" + count +
                \", records=\" + records +
                \", deltaRecords=\" + deltaRecords +
                \", size=\" + size +
                \", format=\'\" + format + \'\\\'\' +
                \", path=\'\" + path + \'\\\'\' +
                \", children=\" + children +
                \", datasets=\" + datasets +
                \", statTime=\" + statTime +
                \", parentId=\'\" + parentId + \'\\\'\' +
                \", level=\" + level +
                \", type=\" + type +
                \'}\';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigInteger getCount() {
        return count;
    }

    public void setCount(BigInteger count) {
        this.count = count;
    }

    public BigInteger getRecords() {
        return records;
    }

    public void setRecords(BigInteger records) {
        this.records = records;
    }

    public BigInteger getDeltaRecords() {
        return deltaRecords;
    }

    public void setDeltaRecords(BigInteger deltaRecords) {
        this.deltaRecords = deltaRecords;
    }

    public BigInteger getSize() {
        return size;
    }

    public void setSize(BigInteger size) {
        this.size = size;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public List<DataSetChild> getChildren() {
        return children;
    }

    public void setChildren(List<DataSetChild> children) {
        this.children = children;
    }

    public List<DataSet> getDatasets() {
        return datasets;
    }

    public void setDatasets(List<DataSet> datasets) {
        this.datasets = datasets;
    }

    public Date getStatTime() {
        return statTime;
    }

    public void setStatTime(Date statTime) {
        this.statTime = statTime;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public BigInteger getLevel() {
        return level;
    }

    public void setLevel(BigInteger level) {
        this.level = level;
    }

    public BigInteger getType() {
        return type;
    }

    public void setType(BigInteger type) {
        this.type = type;
    }
}

DataSetChild:

public class DataSetChild extends  Data {

    //  id
    private String id;
    //  名称
    private String name;
    //  系统数
    private BigInteger count;
    //  记录数
    private BigInteger records;
    //  增量
    private BigInteger deltaRecords;
    //  大小
    private BigInteger size;
    //  子集
    private List<DataSetChild> children;
    //  数据集列表
    private List<DataSet> datasets;
    //  统计时间
    private Date statTime;
    //  父节点 id
    private String parentId;
    //  级数
    private BigInteger level;
    //  系统类型
    private BigInteger type;

    @Override
    public String toString() {
        return \"DataSet{\" +
                \"id=\'\" + id + \'\\\'\' +
                \", name=\'\" + name + \'\\\'\' +
                \", count=\" + count +
                \", records=\" + records +
                \", deltaRecords=\" + deltaRecords +
                \", size=\" + size +
                \", children=\" + children +
                \", datasets=\" + datasets +
                \", statTime=\" + statTime +
                \", parentId=\'\" + parentId + \'\\\'\' +
                \", level=\" + level +
                \", type=\" + type +
                \'}\';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigInteger getCount() {
        return count;
    }

    public void setCount(BigInteger count) {
        this.count = count;
    }

    public BigInteger getRecords() {
        return records;
    }

    public void setRecords(BigInteger records) {
        this.records = records;
    }

    public BigInteger getDeltaRecords() {
        return deltaRecords;
    }

    public void setDeltaRecords(BigInteger deltaRecords) {
        this.deltaRecords = deltaRecords;
    }

    public BigInteger getSize() {
        return size;
    }

    public void setSize(BigInteger size) {
        this.size = size;
    }

    public List<DataSetChild> getChildren() {
        return children;
    }

    public void setChildren(List<DataSetChild> children) {
        this.children = children;
    }

    public List<DataSet> getDatasets() {
        return datasets;
    }

    public void setDatasets(List<DataSet> datasets) {
        this.datasets = datasets;
    }

    public Date getStatTime() {
        return statTime;
    }

    public void setStatTime(Date statTime) {
        this.statTime = statTime;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public BigInteger getLevel() {
        return level;
    }

    public void setLevel(BigInteger level) {
        this.level = level;
    }

    public BigInteger getType() {
        return type;
    }

    public void setType(BigInteger type) {
        this.type = type;
    }
}

DataSet:

public class DataSet extends  Data {

    //  id
    private String id;
    //  名称
    private String name;
    //  数据格式
    private String format;
    //  文件路径
    private String path;
    //  记录数
    private BigInteger records;
    //  大小
    private BigInteger size;
    //  统计时间
    private Date statTime;
    //  父节点 id
    private String parentId;
    //  级数
    private BigInteger level;
    //  系统类型
    private BigInteger type;

    @Override
    public String toString() {
        return \"DataSet{\" +
                \"id=\'\" + id + \'\\\'\' +
                \", name=\'\" + name + \'\\\'\' +
                \", format=\'\" + format + \'\\\'\' +
                \", path=\'\" + path + \'\\\'\' +
                \", records=\" + records +
                \", size=\" + size +
                \", statTime=\" + statTime +
                \", parentId=\'\" + parentId + \'\\\'\' +
                \", level=\" + level +
                \", type=\" + type +
                \'}\';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public BigInteger getRecords() {
        return records;
    }

    public void setRecords(BigInteger records) {
        this.records = records;
    }

    public BigInteger getSize() {
        return size;
    }

    public void setSize(BigInteger size) {
        this.size = size;
    }

    public Date getStatTime() {
        return statTime;
    }

    public void setStatTime(Date statTime) {
        this.statTime = statTime;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public BigInteger getLevel() {
        return level;
    }

    public void setLevel(BigInteger level) {
        this.level = level;
    }

    public BigInteger getType() {
        return type;
    }

    public void setType(BigInteger type) {
        this.type = type;
    }
}

SaveDataSetToDB:

private void saveDataSetsToData (String insertSql,  Data  Data, String parentId, Integer level) {
    if ( Data instanceof DataSetOne) {
        DataSetOne dataSetOne = (DataSetOne)  Data;
        //  向数据库中添加数据集一级列表
        insertDataSet(insertSql, dataSetOne, parentId, level);
        level++;
        //  向数据库中添加数据集二级列表
        List<DataSetChild> children = dataSetOne.getChildren();
        if (null != children && children.size() != 0) {
            for (int i = 0; i < children.size(); i++) {
                DataSetChild child = children.get(i);
                saveDataSetsToData (insertSql, child, dataSetOne.getId(), level);
                List<DataSet> datasets = child.getDatasets();
                if (null != datasets && datasets.size() != 0) {
                    for (int j = 0; j < datasets.size(); j++) {
                        DataSet dataSet = datasets.get(j);
                        saveDataSetsToData (insertSql, dataSet, parentId, level);
                    }
                }
            }
        }
    } else if ( Data instanceof DataSetChild) {
        //  向数据库中添加数据集一级列表
        DataSetChild dataSetChild = (DataSetChild)  Data;
        insertDataSet(insertSql, dataSetChild, parentId, level);
        level++;
        //  向数据库中添加数据集二级列表
        List<DataSetChild> children = dataSetChild.getChildren();
        if (null != children && children.size() != 0) {
            for (int i = 0; i < children.size(); i++) {
                DataSetChild child = children.get(i);
                saveDataSetsToData (insertSql, child, dataSetChild.getId(), level);
                List<DataSet> datasets = child.getDatasets();
                if (null != datasets && datasets.size() != 0) {
                    for (int j = 0; j < datasets.size(); j++) {
                        DataSet dataSet = datasets.get(j);
                        saveDataSetsToData (insertSql, dataSet, parentId, level);
                    }
                }
            }
        }
    } else if ( Data instanceof DataSet) {
        DataSet dataSet = (DataSet)  Data;
        insertDataSet(insertSql, dataSet, parentId, level);
    }
}

 

收藏 打印