yuxc
2023-05-25 27f7b8f0459ed7c91cd532ae04c9aa3d15d11d84
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.vci.ubcs.starter.revision.service;
 
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.vci.ubcs.starter.revision.model.BaseModel;
import com.vci.ubcs.starter.revision.model.TreeWrapperOptions;
import com.vci.ubcs.starter.web.pagemodel.Tree;
import com.vci.ubcs.starter.web.service.VciSecretServiceI;
import com.vci.ubcs.starter.web.util.BeanUtilForVCI;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
 
@Component
public class RevisionModelUtil implements VciSecretServiceI {
 
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public static volatile Map<String, Map<String, String>> modelColumnAnnotationMap = new ConcurrentHashMap();
//    public static volatile Map<String, VciBtmType> modelAnnotationMap = new ConcurrentHashMap();
    public static boolean CHECK_IDEMPOTENCE = false;
 
    public void copyFromDTOIgnore(Object dto, BaseModel baseModel) {
        VciBaseUtil.alertNotNull(new Object[]{dto, "数据传输对象", baseModel, "数据库中的数据对象"});
        BaseModel tempModel = new BaseModel();
        BeanUtilForVCI.copyPropertiesIgnoreCase(baseModel, tempModel);
        BeanUtilForVCI.copyPropertiesIgnoreCase(dto, baseModel);
        BeanUtilForVCI.copyPropertiesIgnoreCase(tempModel, baseModel);
        baseModel.setId(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("id", dto)));
        baseModel.setName(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("name", dto)));
        baseModel.setDescription(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("description", dto)));
        tempModel = null;
    }
 
    public <T, R> List<Tree> doList2Trees(List<T> doList, TreeWrapperOptions wrapperOptions, Function<T, R> f) {
        if (CollectionUtils.isEmpty(doList)) {
            return new ArrayList();
        } else {
            List<Tree> allTree = new ArrayList();
            List<Tree> children = new ArrayList();
            Iterator var6 = doList.iterator();
 
            while(true) {
                while(var6.hasNext()) {
                    T doObject = (T) var6.next();
                    Tree tree = new Tree();
                    List<String> oidFieldNames = VciBaseUtil.str2List(wrapperOptions.getOidFieldName());
                    List<String> oidValues = new LinkedList();
                    oidFieldNames.stream().forEach((s) -> {
                        oidValues.add(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField(s, doObject)));
                    });
                    tree.setOid((String)oidValues.stream().collect(Collectors.joining(wrapperOptions.getOidValueSep())));
                    tree.setName((String) VciBaseUtil.getValueFromField("name", doObject));
                    if (f != null) {
                        tree.setText((String)f.apply(doObject));
                    } else {
                        List<String> textFieldNames = VciBaseUtil.str2List(wrapperOptions.getTextFieldName());
                        List<String> textValues = new LinkedList();
                        textFieldNames.stream().forEach((s) -> {
                            textValues.add(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField(s, doObject)));
                        });
                        tree.setText((String)textValues.stream().collect(Collectors.joining(wrapperOptions.getTextValueSep())));
                    }
 
                    if (StringUtils.isNotBlank(wrapperOptions.getParentFieldName())) {
                        tree.setParentId(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField(wrapperOptions.getParentFieldName(), doObject)));
                    }
 
                    if (wrapperOptions.isAllAttributes()) {
                        try {
                            tree.setAttributes(VciBaseUtil.objectToMapString(doObject));
                        } catch (Exception var13) {
                            if (this.logger.isErrorEnabled()) {
                                this.logger.error("把对象转换为map时出现了错误,但是不影响树的展示,对业务可能有影响");
                            }
                        }
                    }
 
                    if (wrapperOptions.isMultipleSelect() || wrapperOptions.isShowCheckBox()) {
                        tree.setShowCheckbox(true);
                    }
 
                    if (wrapperOptions.getParentOid() == null) {
                        wrapperOptions.setParentOid("");
                    }
 
                    if (!StringUtils.isBlank(tree.getParentId()) && (!StringUtils.isNotBlank(wrapperOptions.getParentOid()) || !wrapperOptions.getParentOid().equalsIgnoreCase(tree.getParentId()))) {
                        children.add(tree);
                    } else {
                        allTree.add(tree);
                    }
                }
 
                (new Tree()).findChild(allTree, children);
                if (allTree.size() <= 0) {
                    allTree.addAll(children);
                }
 
                return allTree;
            }
        }
    }
 
}