From e04e10a0765e1d32535d91292763289adf43d651 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期一, 09 九月 2024 17:49:33 +0800
Subject: [PATCH] 按钮设计对话框:查询、添加、修改接口上传。

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java |  337 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 297 insertions(+), 40 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java
index ff8396d..137973d 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java
@@ -1,8 +1,5 @@
 package com.vci.web.service.impl;
 
-import com.sun.jnlp.ApiDialog;
-import com.vci.client.mw.ClientContextVariable;
-import com.vci.common.qt.object.QTConstants;
 import com.vci.common.utility.ObjectUtility;
 import com.vci.corba.common.PLException;
 import com.vci.corba.framework.data.RoleRightInfo;
@@ -11,10 +8,9 @@
 import com.vci.corba.portal.data.*;
 import com.vci.dto.RoleRightDTO;
 import com.vci.dto.UIAuthorDTO;
-import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI;
-import com.vci.pagemodel.OsBtmTypeVO;
 import com.vci.model.PLDefination;
 import com.vci.pagemodel.PLDefinationVO;
+import com.vci.pagemodel.PLTabButtonVO;
 import com.vci.pagemodel.PLUILayoutCloneVO;
 import com.vci.pagemodel.RoleRightVO;
 import com.vci.starter.web.exception.VciBaseException;
@@ -30,7 +26,6 @@
 import com.vci.web.service.UIManagerServiceI;
 import com.vci.web.util.*;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.ss.formula.functions.T;
 import com.vci.web.util.Func;
 import com.vci.web.util.PlatformClientUtil;
 import com.vci.web.util.UITools;
@@ -40,18 +35,13 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
-
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.swing.*;
-import javax.swing.text.JTextComponent;
 import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import java.util.*;
 import java.util.regex.Pattern;
-import java.util.stream.Collectors;
 
 /**
  * UI瀹氫箟鏈嶅姟鐣岄潰鐩稿叧鎺ュ彛
@@ -66,12 +56,6 @@
      */
     @Resource
     private PlatformClientUtil platformClientUtil;
-
-    /**
-     * 瑙掕壊
-     */
-    @Resource
-    private SmRoleQueryServiceI smRoleQueryServiceI;
 
     /**
      * 涓氬姟绫诲瀷
@@ -91,6 +75,16 @@
         @Override
         public int compare(PLUILayout o1, PLUILayout o2) {
             return o1.plCode.compareTo(o2.plCode);
+        }
+    };
+
+    /**
+     * 鎺掑簭姣旇緝鍣�
+     */
+    private Comparator<PLDefinationVO> pageDefinationComparator = new Comparator<PLDefinationVO>() {
+        @Override
+        public int compare(PLDefinationVO o1, PLDefinationVO o2) {
+            return new Integer(o1.getSeq()).compareTo(new Integer(o2.getSeq()));
         }
     };
 
@@ -336,10 +330,13 @@
      * 鏍规嵁涓婁笅鏂嘔D鍜屽尯鍩熺被鍨嬶紝鎸夐『搴忚幏鍙栧綋鍓嶅尯鍩熺殑tab椤�
      */
     @Override
-    public List<PLTabPage> getTabByContextIdAndType(String contextId, int areaType) throws PLException {
+    public DataGrid getTabByContextIdAndType(String contextId, int areaType) throws PLException {
         VciBaseUtil.alertNotNull(contextId,"涓婁笅鏂囦富閿�",areaType,"鍖哄煙绫诲瀷");
         PLTabPage[] plTabPages = platformClientUtil.getUIService().getTabPagesByContextIdAndType(contextId, (short) areaType);
-        return Arrays.asList(plTabPages);
+        DataGrid dataGrid = new DataGrid();
+        dataGrid.setTotal(plTabPages.length);
+        dataGrid.setData(Arrays.asList(plTabPages));
+        return dataGrid;
     }
 
     /**
@@ -401,13 +398,46 @@
 
     /**
      * 鏌ヨ椤甸潰璁捐瀹氫箟
-     * @param plPageContextOId
+     * @param pageContextOId
      * @return
      */
     @Override
-    public List<PLPageDefination> getPLPageDefinations(String plPageContextOId) {
+    public DataGrid getPLPageDefinations(String pageContextOId) throws PLException {
+        DataGrid dataGrid = new DataGrid();
+        if(Func.isBlank(pageContextOId)) return dataGrid;
+        PLPageDefination[] plPageDefinations = platformClientUtil.getUIService().getPLPageDefinationsByPageContextOId(pageContextOId);
+        if(Func.isEmpty(plPageDefinations)){
+            return dataGrid;
+        }
+        //DO2VO
+        List<PLDefinationVO> plDefinationVOS = this.pageDefinations2PLDefinationVO(Arrays.asList(plPageDefinations));
+        dataGrid.setTotal(plDefinationVOS.size());
+        Collections.sort(plDefinationVOS, Comparator.comparing(PLDefinationVO::getSeq));
+        //Arrays.sort(plDefinationVOS, pageDefinationComparator);
+        dataGrid.setData(plDefinationVOS);
+        return dataGrid;
+    }
 
-        return null;
+    /**
+     * 椤甸潰瀹氫箟鐨凞O2VO瀵硅薄
+     * @param plPageDefinations
+     * @return
+     */
+    private List<PLDefinationVO> pageDefinations2PLDefinationVO(List<PLPageDefination> plPageDefinations){
+        List<PLDefinationVO> plDefinationVOList = new ArrayList<>();
+        plPageDefinations.stream().forEach(item->{
+            try {
+                PLDefinationVO plDefinationVO = new PLDefinationVO();
+                PLDefination plDefination = UITools.getPLDefination(item.plDefination);
+                BeanUtil.copy(plDefination,plDefinationVO);
+                plDefinationVOList.add(plDefinationVO);
+            } catch (Throwable e) {
+                e.printStackTrace();
+                logger.error(e.getMessage());
+                throw new VciBaseException("椤甸潰瀹氫箟DO瀵硅薄杞琕O瀵硅薄鏃跺嚭鐜伴敊璇�,鍘熷洜锛�"+e.getMessage());
+            }
+        });
+        return plDefinationVOList;
     }
 
     /**
@@ -533,15 +563,25 @@
      */
     @Override
     public boolean updatePageDefination(PLDefinationVO pdVO) throws Throwable {
-        /*PLPageDefination pd = getPageDefination();
 
-        PLDefination d = UITools.getPLDefination(pd.plDefination);
+        VciBaseUtil.alertNotNull(pdVO,"椤甸潰瀹氫箟瀵硅薄",pdVO.getSeq(),"缂栧彿",pdVO.getName(),"鍚嶇О");
+        PLPageDefination pd = new PLPageDefination();
+        PLDefination d = new PLDefination();
+        BeanUtil.copy(pdVO,d);
 
         //涓嶈兘涓虹┖灞炴�ф鏌�
         if(!this.baseInfoIsOk(pd,true)){
             return false;
         }
-        setUIValueToObject(pd, d);
+        pd.name = pdVO.getName().trim();
+        pd.seq = Short.valueOf(pdVO.getSeq().trim());
+        pd.desc = pdVO.getDescription();
+        pd.plType = Short.parseShort(pdVO.getTemplateType());
+
+        d.setName(pdVO.getName().trim());
+        d.setUiParser(pdVO.getUiParser().trim());
+        d.setExtAttr(pdVO.getExtAttr().trim());
+        d.setTemplateType(pdVO.getTemplateType());
 
         this.newPLDefinationIsOk(pdVO, true);
 
@@ -622,13 +662,241 @@
                 break;
         }
 
-        d = comptPanel.getNewPLDefination(d);
         d = setEventDataToPLDefination(d,pdVO);
-        pd.plDefination = UITools.getPLDefinationText(d);*/
+        pd.plDefination = UITools.getPLDefinationText(d);
 
-        boolean res = true;//platformClientUtil.getUIService().updatePLPageDefination(pd);
+        return platformClientUtil.getUIService().updatePLPageDefination(pd);
+    }
+
+    /**
+     * 鍒犻櫎椤甸潰瀹氫箟
+     * @param oids
+     * @return
+     */
+    @Override
+    public boolean delPageDefination(String[] oids) throws PLException {
+        VciBaseUtil.alertNotNull(oids,"鍒犻櫎鐨勯〉闈㈠畾涔変富閿�");
+        boolean res = platformClientUtil.getUIService().deletePLUILayoutByOidsForCascade(oids);
         return res;
     }
+
+    /**
+     * 鑾峰彇椤电鍖哄煙鎸夐挳閰嶇疆淇℃伅
+     * @param pageDefinationOid
+     * @return
+     */
+    @Override
+    public List<PLTabButtonVO> getTabButton(String pageDefinationOid) {
+        VciBaseUtil.alertNotNull(pageDefinationOid,"椤甸潰瀹氫箟涓婚敭");
+        List<PLTabButton> buttonList = new ArrayList<>();
+        try {
+            PLTabButton[] plTabButtons = platformClientUtil.getUIService().getPLTabButtonsByTableOId(pageDefinationOid);
+            buttonList = Arrays.asList(plTabButtons);
+            return this.tabButton2TabButtonVOS(buttonList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new VciBaseException("鍔犺浇椤电鍖哄煙鎸夐挳閰嶇疆淇℃伅寮傚父锛�" + e.getMessage());
+        }
+    }
+
+    /**
+     * 澶氫釜鎸夐挳閰嶇疆DO瀵硅薄杞涓猇O瀵硅薄
+     * @param listDO
+     * @return
+     */
+    private List<PLTabButtonVO> tabButton2TabButtonVOS(List<PLTabButton> listDO){
+        List<PLTabButtonVO> plTabButtonVOList = new ArrayList<PLTabButtonVO>();
+        if(Func.isEmpty(listDO)){
+            return plTabButtonVOList;
+        }
+        listDO.stream().forEach(item->{
+            try {
+                PLTabButtonVO plTabButtonVO = this.tabButton2TabButtonVO(item);
+                plTabButtonVOList.add(plTabButtonVO);
+            } catch (PLException e) {
+                e.printStackTrace();
+                String errorLog = "鎸夐挳閰嶇疆DO TO VO鏃跺嚭鐜伴敊璇紝鍘熷洜锛�"+VciBaseUtil.getExceptionMessage(e);
+                logger.error(errorLog);
+                throw new VciBaseException(errorLog);
+            }
+
+        });
+        return plTabButtonVOList;
+    }
+
+    /**
+     * 鎸夐挳閰嶇疆DO瀵硅薄杞琕O瀵硅薄
+     * @param tabButtonDO
+     * @return
+     */
+    private PLTabButtonVO tabButton2TabButtonVO(PLTabButton tabButtonDO) throws PLException {
+        PLTabButtonVO plTabButtonVO = new PLTabButtonVO();
+        if(Func.isEmpty(tabButtonDO) && Func.isBlank(tabButtonDO.plOId)){
+            return plTabButtonVO;
+        }
+        plTabButtonVO.setOId(tabButtonDO.plOId);
+        plTabButtonVO.setTableOId(tabButtonDO.plTableOId);
+        plTabButtonVO.setPageOId(tabButtonDO.plPageOId);
+        plTabButtonVO.setActionOId(tabButtonDO.plActionOId);
+        plTabButtonVO.setLabel(tabButtonDO.plLabel);
+        plTabButtonVO.setAreaType(tabButtonDO.plAreaType);
+        plTabButtonVO.setDesc(tabButtonDO.plDesc);
+        plTabButtonVO.setSeq(tabButtonDO.plSeq);
+        plTabButtonVO.setCreateUser(tabButtonDO.plCreateUser);
+        plTabButtonVO.setCreateTime(tabButtonDO.plCreateTime);
+        plTabButtonVO.setModifyUser(tabButtonDO.plModifyUser);
+        plTabButtonVO.setModifyTime(tabButtonDO.plModifyTime);
+        plTabButtonVO.setLicensOrs(tabButtonDO.plLicensOrs);
+        plTabButtonVO.setParentOid(tabButtonDO.plParentOid);
+        plTabButtonVO.setDisplayMode(tabButtonDO.displayMode);
+        plTabButtonVO.setIconPath(tabButtonDO.iconPath);
+        plTabButtonVO.setAuthorization(tabButtonDO.authorization);
+        plTabButtonVO.setShow(tabButtonDO.show);
+        //鍙傛暟淇℃伅鍥炲~
+        PLCommandParameter[] parameters = platformClientUtil.getUIService().getPLCommandParametersByCommandOId(tabButtonDO.plOId);
+        if(Func.isNotEmpty(parameters)){
+            LinkedHashMap<String, String> parameterMap = (LinkedHashMap<String, String>)Arrays.stream(parameters).collect(Collectors.toMap(parm -> parm.plKey, parm -> parm.plValue));
+            plTabButtonVO.setButtonParams(parameterMap);
+        }
+        return plTabButtonVO;
+    }
+
+    /**
+     * 鎸夐挳閰嶇疆VO瀵硅薄杞珼O瀵硅薄
+     * @param tabButtonVO
+     * @return
+     * @throws PLException
+     */
+    private PLTabButton tabButtonVO2TabButton(PLTabButton plTabButton,PLTabButtonVO tabButtonVO) {
+        plTabButton.plOId = tabButtonVO.getOId();
+        plTabButton.plTableOId = tabButtonVO.getTableOId();
+        plTabButton.plPageOId = tabButtonVO.getPageOId();
+        plTabButton.plActionOId = tabButtonVO.getActionOId();
+        plTabButton.plLabel = tabButtonVO.getLabel();
+        plTabButton.plAreaType = tabButtonVO.getAreaType();
+        plTabButton.plDesc = tabButtonVO.getDesc();
+        plTabButton.plSeq = tabButtonVO.getSeq();
+        plTabButton.plCreateUser = tabButtonVO.getCreateUser();
+        plTabButton.plCreateTime = tabButtonVO.getCreateTime();
+        plTabButton.plModifyUser = tabButtonVO.getModifyUser();
+        plTabButton.plModifyTime = tabButtonVO.getModifyTime();
+        plTabButton.plLicensOrs = tabButtonVO.getLicensOrs();
+        plTabButton.plParentOid = tabButtonVO.getParentOid();
+        plTabButton.displayMode = tabButtonVO.getDisplayMode();
+        plTabButton.iconPath = tabButtonVO.getIconPath();
+        plTabButton.authorization = tabButtonVO.getAuthorization();
+        plTabButton.show = tabButtonVO.getShow();
+        return plTabButton;
+    }
+
+    /**
+     * 娣诲姞鎸夐挳閰嶇疆淇℃伅
+     * @param tabButtonVO
+     * @return
+     */
+    @Override
+    public BaseResult addTapButton(PLTabButtonVO tabButtonVO) {
+        boolean res = this.saveOrUpdateTapButton(tabButtonVO, true);
+        return res ? BaseResult.success("鎸夐挳閰嶇疆娣诲姞鎴愬姛锛�"):BaseResult.success("鎸夐挳閰嶇疆娣诲姞澶辫触锛�");
+    }
+
+    /**
+     * 淇敼鎸夐挳閰嶇疆淇℃伅
+     * @param tabButtonVO
+     * @return
+     */
+    @Override
+    public BaseResult updateTapButton(PLTabButtonVO tabButtonVO) {
+        boolean res = this.saveOrUpdateTapButton(tabButtonVO, false);
+        return res ? BaseResult.success("鎸夐挳閰嶇疆淇敼鎴愬姛锛�"):BaseResult.success("鎸夐挳閰嶇疆淇敼澶辫触锛�");
+    }
+
+    /**
+     * 淇濆瓨鎴栦慨鏀规寜閽厤缃俊鎭�
+     * @param tabButtonVO
+     * @return
+     */
+    @Override
+    public boolean saveOrUpdateTapButton(PLTabButtonVO tabButtonVO,boolean isAdd){
+        VciBaseUtil.alertNotNull(tabButtonVO,"鎸夐挳閰嶇疆瀵硅薄",tabButtonVO.getLabel(),"鍙傛暟鍚嶇О");
+        //妫�鏌ュ綋鍓嶆坊鍔犵殑鍒楄〃鏄惁閲嶅锛屼絾鏄繖鍎垮彧鏀寔鍗曟潯鏁版嵁淇濆瓨锛屾墍鏈夊綋鍓嶅垪琛ㄥ垽閲嶅彲浠ュ墠绔潵鍋�
+        //String btnParamValidate = this.geCheckRes();
+
+        if (tabButtonVO.getSeq() < 1 || tabButtonVO.getSeq() > 63) {
+            throw new VciBaseException("鎸夊簭鍙疯秴鍑鸿寖鍥达紝璇蜂慨鏀癸紝鎸夐挳銆愮紪鍙枫�戝彧鑳藉湪銆�1-63銆戣寖鍥村唴銆�");
+        }
+        //褰撳墠鐧诲綍鐢ㄦ埛鐨勪俊鎭�
+        SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
+        //VO2DO
+        PLTabButton plTabButton = this.tabButtonVO2TabButton(new PLTabButton(), tabButtonVO);
+        if(isAdd) {
+            //濡傛灉鏄鍔犳搷浣滐紝鐩存帴鍒涘缓PLTabButton瀵硅薄
+            plTabButton.plOId = ObjectUtility.getNewObjectID36();
+            plTabButton.plCreateUser = sessionInfo.getUserId();
+            plTabButton.plModifyUser = sessionInfo.getUserId();
+        } else {
+            //淇敼鎿嶄綔
+            plTabButton.plModifyUser = sessionInfo.getUserId();
+        }
+
+        try {
+            if(isAdd){
+                boolean success =  platformClientUtil.getUIService().savePLTabButton(plTabButton);
+                if(success == false) {
+                    throw new VciBaseException("缂栧彿閲嶅锛岀紪鍙峰凡缁忓湪褰撳墠椤电涓嬪瓨鍦紒");
+                }
+            } else if(!isAdd){
+                platformClientUtil.getUIService().updatePLTabButton(plTabButton);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            String errorLog = "淇濆瓨鎸夐挳淇℃伅鏃跺彂鐢熷紓甯革細" + e.getMessage();
+            logger.error(errorLog);
+            throw new VciBaseException(errorLog);
+        }
+        //澶嶇敤浠ュ墠鐨勪唬鐮侊紝瀵逛簬鍙傛暟涓�鏉′竴鏉″垹闄わ紝涓�鏉′竴鏉″垱寤�
+        //鏁版嵁閲忓強骞跺彂杈冨皯锛屾殏鏃惰繖涔堝鐞嗘病鏈変粈涔堥棶棰�
+        if(!isAdd) {
+            try {
+                platformClientUtil.getUIService().deletePLCommandParameterByTabButtonId(plTabButton.plOId);
+            } catch (PLException e) {
+                e.printStackTrace();
+            }
+        }
+
+        LinkedHashMap<String, String> buttonParams = tabButtonVO.getButtonParams();
+        if(!buttonParams.isEmpty()) {
+            Iterator<Map.Entry<String, String>> iterator = buttonParams.entrySet().iterator();
+            while(iterator.hasNext()){
+                Map.Entry<String, String> next = iterator.next();
+                if(StringUtils.isEmpty(next.getKey()) || StringUtils.isEmpty(next.getValue())){
+                    iterator.remove();
+                }
+            }
+            if(!buttonParams.isEmpty()){
+                Iterator<Map.Entry<String, String>> kvItor = buttonParams.entrySet().iterator();
+                while(kvItor.hasNext()){
+                    Map.Entry<String, String> next = kvItor.next();
+                    PLCommandParameter plCommandParameter = new PLCommandParameter();
+                    plCommandParameter.plOId = ObjectUtility.getNewObjectID36();
+                    plCommandParameter.plCommandOId = plTabButton.plOId;
+                    plCommandParameter.plKey = next.getKey();
+                    plCommandParameter.plValue = next.getValue();
+                    plCommandParameter.plCreateUser = sessionInfo.getUserId();
+                    plCommandParameter.plModifyUser = sessionInfo.getUserId();
+                    try {
+                        platformClientUtil.getUIService().savePLCommandParameter(plCommandParameter);
+                    } catch (PLException e) {
+                        e.printStackTrace();
+                        throw new VciBaseException("淇濆瓨鎸夐挳淇℃伅鏃跺彂鐢熷紓甯革細"+ e.getMessage());
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+
 
     /**
      * 澶勭悊閰嶇疆鐨別vent浜嬩欢
@@ -670,18 +938,6 @@
         } else {
             res = true;
         }
-        return res;
-    }
-
-    /**
-     * 鍒犻櫎椤甸潰瀹氫箟
-     * @param oids
-     * @return
-     */
-    @Override
-    public boolean delPageDefination(String[] oids) throws PLException {
-        VciBaseUtil.alertNotNull(oids,"鍒犻櫎鐨勯〉闈㈠畾涔変富閿�");
-        boolean res = platformClientUtil.getUIService().deletePLUILayoutByOidsForCascade(oids);
         return res;
     }
 
@@ -1026,6 +1282,7 @@
             }
         });
     }
+
     /**
      * UI瑙掕壊瀵硅薄杞崲
      * @param infos

--
Gitblit v1.9.3