package com.zy.asrs.wcs.utils;
|
|
|
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.zy.asrs.framework.common.SpringUtils;
|
|
import java.io.Serializable;
|
import java.util.function.Function;
|
|
/**
|
* Created by vincent on 2021/1/19
|
*/
|
public class NodeUtils {
|
|
public StringBuilder path = new StringBuilder();
|
|
public StringBuilder pathName = new StringBuilder();
|
|
public interface NodeSupport<T> {
|
T query();
|
}
|
|
public <T, R extends Serializable> void generatePath(Class<T> cls
|
, T t
|
, Function<? super T, ? extends R> idMapper
|
, Function<? super T, ? extends String> nameMapper
|
, Function<? super T, ? extends R> parentIdMapper) {
|
IService<T> bean = (IService<T>) SpringUtils.getBean(cls.getSimpleName() + "Service");
|
T parent = bean.getById(parentIdMapper.apply(t));
|
if (null != parent) {
|
path.insert(0, idMapper.apply(parent)).insert(0,",");
|
pathName.insert(0, nameMapper.apply(parent)).insert(0,",");
|
if (parentIdMapper.apply(parent) != null) {
|
generatePath(cls, parent, idMapper, nameMapper, parentIdMapper);
|
} else {
|
path.deleteCharAt(0);
|
pathName.deleteCharAt(0);
|
}
|
}
|
}
|
|
}
|