#
luxiaotao1123
2024-02-20 8c4fc3d632958daa7aff0fdd8b273d85bec68ead
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
            }
        }
    }
 
}