|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public StringBuilder pathName = new StringBuilder(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface NodeSupport<T> { | 
|---|
|  |  |  | T query(); | 
|---|
|  |  |  | T query(T t); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public <T, R extends Serializable> void generatePath(Class<T> cls | 
|---|
|  |  |  | public <T, R extends Serializable> void generatePath0( | 
|---|
|  |  |  | NodeSupport<T> support | 
|---|
|  |  |  | , T t | 
|---|
|  |  |  | , Function<? super T, ? extends R> idMapper | 
|---|
|  |  |  | , Function<? super T, ? extends Long> 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)); | 
|---|
|  |  |  | , Function<? super T, ? extends Long> parentIdMapper) { | 
|---|
|  |  |  | T parent = support.query(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); | 
|---|
|  |  |  | if (parentIdMapper.apply(parent) != null && parentIdMapper.apply(parent) != 0) { | 
|---|
|  |  |  | generatePath0(support, parent, idMapper, nameMapper, parentIdMapper); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | path.deleteCharAt(0); | 
|---|
|  |  |  | pathName.deleteCharAt(0); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|