xyz.erupt.core.util.DataHandlerUtil Maven / Gradle / Ivy
package xyz.erupt.core.util;
import org.springframework.util.CollectionUtils;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.core.service.EruptCoreService;
import xyz.erupt.core.view.EruptFieldModel;
import xyz.erupt.core.view.EruptModel;
import xyz.erupt.core.view.TreeModel;
import java.util.*;
/**
* @author YuePeng
* date 2019-04-28.
*/
public class DataHandlerUtil {
// 引用方式 生成树结构数据
public static List quoteTree(List treeModels) {
Map treeModelMap = new LinkedHashMap<>(treeModels.size());
treeModels.forEach(treeModel -> treeModelMap.put(treeModel.getId(), treeModel));
List resultTreeModels = new ArrayList<>();
treeModels.forEach(treeModel -> {
if (treeModel.isRoot()) {
treeModel.setLevel(1);
resultTreeModels.add(treeModel);
return;
}
Optional.ofNullable(treeModelMap.get(treeModel.getPid())).ifPresent(parentTreeModel -> {
Collection children = CollectionUtils.isEmpty(parentTreeModel.getChildren()) ? new ArrayList<>() : parentTreeModel.getChildren();
children.add(treeModel);
children.forEach(child -> child.setLevel(Optional.ofNullable(parentTreeModel.getLevel()).orElse(1) + 1));
parentTreeModel.setChildren(children);
});
});
return resultTreeModels;
}
private static EruptFieldModel cycleFindFieldByKey(EruptModel eruptModel, String key) {
EruptFieldModel fieldModel = eruptModel.getEruptFieldMap().get(key);
if (null != fieldModel) {
return fieldModel;
}
if (key.contains("_")) {
return cycleFindFieldByKey(eruptModel, key.substring(0, key.lastIndexOf("_")));
}
return null;
}
public static void convertDataToEruptView(EruptModel eruptModel, Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy