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> contextMap = new HashMap>(); //tab页签map private Map> tabMap = new HashMap>(); //组件map private Map> defMap = new HashMap>(); //按钮map private Map> buttonMap = new HashMap>(); 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 relatedTypeList = null; //List 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 tabList = null; for (PLTabPage tab : allTabs) { if (tabMap.get(tab.plContextOId) == null) { tabList = new ArrayList(); 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 defList = null; for (PLPageDefination def : allDefinations) { if (defMap.get(def.plTabPageOId) == null) { defList = new ArrayList(); 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 allButtonList = Arrays.stream(allButtons).filter(item -> item.show.equals("0")).collect(Collectors.toList()); List buttonList = null; for (PLTabButton button : allButtonList) { if (buttonMap.get(button.plTableOId) == null) { buttonList = new ArrayList(); 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 getContext(String btmType) { return contextMap.get(btmType); } /** * 获取上下文件下的tab页签信息 * @param contextId * @return */ public List getTabs(String contextId) { return tabMap.get(contextId); } /** * 获取tab页签下的组件信息 * @param tabId * @return */ public List getComopnent(String tabId) { return defMap.get(tabId); } /** * 获取组件下的按钮信息 * @param componentId * @return */ public List getButtons(String componentId) { List buttons = this.buttonMap.get(componentId); if (buttons != null) { sort(buttons); } return buttons; } /** * 按钮顺序好排序button * @param buttons */ private void sort(List buttons) { Collections.sort(buttons, new Comparator(){ @Override public int compare(PLTabButton o1, PLTabButton o2) { return new Integer(o1.plSeq).compareTo(new Integer(o2.plSeq)); } }); } }