田源
2025-01-16 a13255b4129ee8a7a7b7e1ecd8e02dd2c78f7c17
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package com.vci.web.utility;
 
import com.vci.corba.common.PLException;
import com.vci.corba.portal.data.PLPageDefination;
import com.vci.corba.portal.data.PLTabButton;
import com.vci.corba.portal.data.PLTabPage;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.web.util.UITools;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 加载UI上下文
 * @author ludc
 * @date 2024/10/15 10:32
 */
public class UIDataFetcher {
 
    //上下文map
    private Map<String, List<PLUILayout>> contextMap = new HashMap<String, List<PLUILayout>>();
 
    //tab页签map
    private Map<String, List<PLTabPage>> tabMap = new HashMap<String, List<PLTabPage>>();
 
    //组件map
    private Map<String, List<PLPageDefination>> defMap = new HashMap<String, List<PLPageDefination>>();
 
    //按钮map
    private Map<String, List<PLTabButton>> buttonMap = new HashMap<String, List<PLTabButton>>();
 
    public UIDataFetcher() {
        initUIDefination();
    }
 
    public static void main(String[] args) {
        new UIDataFetcher();
    }
 
    /**
     * 初始化所有UI定义信息
     */
    private void initUIDefination() {
        try {
            //初始化所有的上下文
            //long s = System.currentTimeMillis();
            PLUILayout[] allContext = UITools.getService().getAllPLUILayouts();
            //long e = System.currentTimeMillis();
            //System.out.println(allContext.length + " 1: " + (e - s));
            //s = System.currentTimeMillis();
            List<PLUILayout> relatedTypeList = null;
            //List<PLUILayout> contextList = null;
            for (PLUILayout context : allContext) {
                if (contextMap.get(context.plRelatedType) == null) {
                    relatedTypeList = new ArrayList<>();
                    contextMap.put(context.plRelatedType, relatedTypeList);
                } else {
                    relatedTypeList = contextMap.get(context.plRelatedType);
                }
                relatedTypeList.add(context);
                //处理btmName+context方式存的数据
                /*if(contextMap.get(context.plRelatedType + "-" + context.plOId) == null){
                    contextList = new ArrayList<>();
                    contextMap.put(context.plRelatedType + "-" + context.plOId,contextList);
                }else{
                    contextList = contextMap.get(context.plRelatedType + "-" + context.plOId);
                }
                contextList.add(context);*/
            }
 
 
            //e = System.currentTimeMillis();
            //System.out.println("2: " + (e - s));
            //初始化所有的页签
            //s = System.currentTimeMillis();
            PLTabPage[] allTabs = UITools.getService().getAllPLTabPages();
            //e = System.currentTimeMillis();
            //System.out.println(allTabs.length + " 3: " + (e - s));
            //s = System.currentTimeMillis();
            List<PLTabPage> tabList = null;
            for (PLTabPage tab : allTabs) {
                if (tabMap.get(tab.plContextOId) == null) {
                    tabList = new ArrayList<PLTabPage>();
                    tabMap.put(tab.plContextOId, tabList);
                } else {
                    tabList = tabMap.get(tab.plContextOId);
                }
                tabList.add(tab);
            }
            //e = System.currentTimeMillis();
            //System.out.println("4: " + (e - s));
            //s = System.currentTimeMillis();
            //初始化组建定义
            PLPageDefination[] allDefinations = UITools.getService().getAllPLPageDefinationsWithNoConf();
            //e = System.currentTimeMillis();
            //System.out.println(allDefinations.length + " 5: " + (e - s));
            //s = System.currentTimeMillis();
            List<PLPageDefination> defList = null;
            for (PLPageDefination def : allDefinations) {
                if (defMap.get(def.plTabPageOId) == null) {
                    defList = new ArrayList<PLPageDefination>();
                    defMap.put(def.plTabPageOId, defList);
                } else {
                    defList = defMap.get(def.plTabPageOId);
                }
                defList.add(def);
            }
            //e = System.currentTimeMillis();
            //System.out.println("6: " + (e - s));
            //初始化button
            //s = System.currentTimeMillis();
            PLTabButton[] allButtons = UITools.getService().getAllPLTabButtons();
            //e = System.currentTimeMillis();
            //System.out.println(allButtons.length + " 7: " + (e - s));
            //s = System.currentTimeMillis();
            List<PLTabButton> allButtonList = Arrays.stream(allButtons).filter(item -> item.show.equals("0")).collect(Collectors.toList());
            List<PLTabButton> buttonList = null;
            for (PLTabButton button : allButtonList) {
                if (buttonMap.get(button.plTableOId) == null) {
                    buttonList = new ArrayList<PLTabButton>();
                    buttonMap.put(button.plTableOId, buttonList);
                } else {
                    buttonList = buttonMap.get(button.plTableOId);
                }
                buttonList.add(button);
            }
            //e = System.currentTimeMillis();
            //System.out.println("8: " + (e - s));
        } catch (PLException e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 获取业务类型下的上下文信息
     * @param btmType
     * @return
     */
    public List<PLUILayout> getContext(String btmType) {
        return contextMap.get(btmType);
    }
 
    /**
     * 获取上下文件下的tab页签信息
     * @param contextId
     * @return
     */
    public List<PLTabPage> getTabs(String contextId) {
        return tabMap.get(contextId);
    }
 
    /**
     * 获取tab页签下的组件信息
     * @param tabId
     * @return
     */
    public List<PLPageDefination> getComopnent(String tabId) {
        return defMap.get(tabId);
    }
 
    /**
     * 获取组件下的按钮信息
     * @param componentId
     * @return
     */
    public List<PLTabButton> getButtons(String componentId) {
        List<PLTabButton> buttons = this.buttonMap.get(componentId);
        if (buttons != null) {
            sort(buttons);
        }
        return buttons;
    }
 
    /**
     * 按钮顺序好排序button
     * @param buttons
     */
    private void sort(List<PLTabButton> buttons) {
        Collections.sort(buttons, new Comparator<PLTabButton>(){
 
            @Override
            public int compare(PLTabButton o1, PLTabButton o2) {
                return new Integer(o1.plSeq).compareTo(new Integer(o2.plSeq));
            }
        });
    }
 
}