ludc
2024-10-08 435e3366a85f797ce02008698c28c9a8ca73b4a6
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java
@@ -5,6 +5,7 @@
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.RoleRightInfo;
import com.vci.corba.omd.btm.BizType;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.qtm.QTInfo;
import com.vci.corba.portal.PortalService;
import com.vci.corba.portal.data.*;
@@ -87,6 +88,11 @@
    private final String IMPORTUIKEY = "importUIKey:";
    /**
     * 当前登录用户的信息
     */
    private SessionInfo sessionInfo = null;
    /**
     * 排序比较器
     */
    private Comparator<PLUILayout> pageLayoutComparator = new Comparator<PLUILayout>() {
@@ -139,7 +145,7 @@
    }
    /**
     * ton通过业务类型和名称查询
     * 通过业务类型和名称查询
     * @param btemName
     * @param context
     * @return
@@ -1049,9 +1055,9 @@
                    pdVO.getShowType(),
                    pdVO.getLinkType(),
                    pdVO.getQueryTemplateName(),
                    pdVO.getShowExpressionRoot(),
                    pdVO.getShowExpression(),
                    pdVO.getRefTreeSet(),
                    pdVO.getRootContent(),
                    pdVO.getShowAbs(),
                    pdVO.getShowLinkAbs(),
                    pdVO.getSeparator(),
                    pdVO.getExpandMode()
                );
@@ -1064,8 +1070,8 @@
            case "6":
                UILayoutComptCheckInput ulci = new UILayoutComptCheckInput(
                    pdVO.getSearchTarger(),
                    pdVO.getShowType(),
                    pdVO.getUiLayout(),
                    pdVO.getSubUIObjType(),
                    pdVO.getSubUILayout(),
                    pdVO.getQueryTemplateName(),
                    pdVO.getQryType()
                );
@@ -1166,9 +1172,9 @@
                        pdVO.getShowType(),
                        pdVO.getLinkType(),
                        pdVO.getQueryTemplateName(),
                        pdVO.getShowExpressionRoot(),
                        pdVO.getShowExpression(),
                        pdVO.getRefTreeSet(),
                        pdVO.getRootContent(),
                        pdVO.getShowAbs(),
                        pdVO.getShowLinkAbs(),
                        pdVO.getSeparator(),
                        pdVO.getExpandMode()
                );
@@ -1181,8 +1187,8 @@
            case "6":
                UILayoutComptCheckInput ulci = new UILayoutComptCheckInput(
                        pdVO.getSearchTarger(),
                        pdVO.getShowType(),
                        pdVO.getUiLayout(),
                        pdVO.getSubUIObjType(),
                        pdVO.getSubUILayout(),
                        pdVO.getQueryTemplateName(),
                        pdVO.getQryType()
                );
@@ -1275,7 +1281,7 @@
        }
        plTabButtonVO.setOId(tabButtonDO.plOId);
        plTabButtonVO.setTableOId(tabButtonDO.plTableOId);
        plTabButtonVO.setPageOId(tabButtonDO.plPageOId);
        //plTabButtonVO.setPageOId(tabButtonDO.plPageOId);
        plTabButtonVO.setActionOId(tabButtonDO.plActionOId);
        plTabButtonVO.setLabel(tabButtonDO.plLabel);
        plTabButtonVO.setAreaType(tabButtonDO.plAreaType);
@@ -1339,7 +1345,7 @@
    private PLTabButton tabButtonVO2TabButton(PLTabButton plTabButton,PLTabButtonVO tabButtonVO) {
        plTabButton.plOId = tabButtonVO.getOId();
        plTabButton.plTableOId = tabButtonVO.getTableOId();
        plTabButton.plPageOId = tabButtonVO.getPageOId();
        //plTabButton.plPageOId = tabButtonVO.getPageOId();
        plTabButton.plActionOId = tabButtonVO.getActionOId();
        plTabButton.plLabel = tabButtonVO.getLabel();
        plTabButton.plAreaType = tabButtonVO.getAreaType();
@@ -1364,7 +1370,7 @@
     * @return
     */
    @Override
    public BaseResult addTapButton(PLTabButtonVO tabButtonVO) {
    public BaseResult addTabButton(PLTabButtonVO tabButtonVO) {
        boolean res = this.saveOrUpdateTapButton(tabButtonVO, true);
        return res ? BaseResult.success("按钮配置添加成功!"):BaseResult.success("按钮配置添加失败!");
    }
@@ -1375,7 +1381,7 @@
     * @return
     */
    @Override
    public BaseResult updateTapButton(PLTabButtonVO tabButtonVO) {
    public BaseResult updateTabButton(PLTabButtonVO tabButtonVO) {
        boolean res = this.saveOrUpdateTapButton(tabButtonVO, false);
        return res ? BaseResult.success("按钮配置修改成功!"):BaseResult.success("按钮配置修改失败!");
    }
@@ -1432,8 +1438,17 @@
                e.printStackTrace();
            }
        }
        this.saveButtonParams(tabButtonVO.getButtonParams(),plTabButton.plOId);
        return true;
    }
        LinkedHashMap<String, String> buttonParams = tabButtonVO.getButtonParams();
    /**
     * 按钮参数保存
     * @param buttonParams
     * @param tabButtonOid
     * @return
     */
    private void saveButtonParams(LinkedHashMap<String, String> buttonParams,String tabButtonOid) throws VciBaseException{
        if(Func.isNotEmpty(buttonParams)) {
            Iterator<Map.Entry<String, String>> iterator = buttonParams.entrySet().iterator();
            while(iterator.hasNext()){
@@ -1447,7 +1462,7 @@
                Map.Entry<String, String> next = kvItor.next();
                PLCommandParameter plCommandParameter = new PLCommandParameter();
                plCommandParameter.plOId = ObjectUtility.getNewObjectID36();
                plCommandParameter.plCommandOId = plTabButton.plOId;
                plCommandParameter.plCommandOId = tabButtonOid;
                plCommandParameter.plKey = next.getKey();
                plCommandParameter.plValue = next.getValue();
                plCommandParameter.plCreateUser = sessionInfo.getUserId();
@@ -1460,7 +1475,6 @@
                }
            }
        }
        return true;
    }
    /**
@@ -1469,7 +1483,7 @@
     * @return
     */
    @Override
    public boolean deleteTapButton(PLTabButtonVO tabButtonVO) throws PLException {
    public boolean deleteTabButton(PLTabButtonVO tabButtonVO) throws PLException {
        VciBaseUtil.alertNotNull(tabButtonVO,"删除的按钮配置对象");
        boolean success = platformClientUtil.getUIService().deletePLTabButton(this.tabButtonVO2TabButton(new PLTabButton(),tabButtonVO));
        if(success == false){
@@ -1485,7 +1499,7 @@
     */
    @Override
    public BaseResult joinBtn(PLTabButtonVO tabButtonVO) throws PLException {
        VciBaseUtil.alertNotNull(tabButtonVO,"需调整为下级按钮",tabButtonVO.getTableOId(),"当前按钮配置所在的页面主键");
        VciBaseUtil.alertNotNull(tabButtonVO,"需调整为下级按钮的对象",tabButtonVO.getTableOId(),"当前按钮配置所在的页面主键");
        //同一页面下的按钮
        List<PLTabButtonVO> plTabButtons = this.getTabButtons(tabButtonVO.getTableOId());
        if(Func.isEmpty(plTabButtons)){
@@ -1697,7 +1711,7 @@
        }
        BizType[] bizTypes=osBtmServiceI.getBizTypes(type);
        List<Tree> treeList=new ArrayList<>();
        Tree   rootNode =new Tree("root","功能模块","root");
        Tree rootNode =new Tree("root","功能模块","root");
        rootNode.setLevel(0);
        rootNode.setShowCheckbox(true);
        rootNode.setExpanded(true);
@@ -2183,7 +2197,7 @@
     * @param vo
     * @return
     */
    private RoleRightDTO  roleRightVOO2DTO(RoleRightVO vo){
    private RoleRightDTO roleRightVOO2DTO(RoleRightVO vo){
        RoleRightDTO dto=new RoleRightDTO();
        dto.setId(vo.getId());
        dto.setCreateTime(vo.getCreateTime());
@@ -2203,7 +2217,7 @@
     * @param dto
     * @return
     */
    private RoleRightInfo  roleRightDTOO2Info(RoleRightDTO dto) throws Exception {
    private RoleRightInfo roleRightDTOO2Info(RoleRightDTO dto) throws Exception {
        RoleRightInfo info=new RoleRightInfo();
        info.id=StringUtils.isBlank(dto.getId())?"":dto.getId();
        info.createTime=StringUtils.isBlank(dto.getCreateTime())?new Date().getTime():VciDateUtil.getTime(VciDateUtil.str2Date(dto.getCreateTime(),""));
@@ -2388,6 +2402,50 @@
    }
    /**
     * 查询链接类型下拉
     * @param baseQueryObject
     * @return
     * @throws PLException
     */
    public DataGrid<LinkType> getLinkDatasByPage(BaseQueryObject baseQueryObject) throws PLException{
        List<LinkType> list = new ArrayList<>();
        Map<String, LinkType> map = new HashMap<>();
        LinkType[] lts = platformClientUtil.getLinkTypeService().getLinkTypes();
        for (LinkType lt : lts) {
            Map<String, String> conditionMap = baseQueryObject.getConditionMap();
            if(Func.isNotEmpty(conditionMap)){
                //选择的对象类型
                String selectBtmType = conditionMap.get("selectBtmType");
                if(selectBtmType != null){
                    boolean existFrom = existInArray(selectBtmType, lt.btmItemsFrom);
                    boolean existTo = existInArray(selectBtmType, lt.btmItemsTo);
                    if(existFrom || existTo){
                        if(!map.containsKey(lt.name)){
                            map.put(lt.name, lt);
                            list.add(lt);
                        }
                    }
                }
            }
        }
        DataGrid<LinkType> res = new DataGrid<>();
        res.setData(list);
        res.setTotal(list.size());
        return res;
    }
    private boolean existInArray(String value, String[] values){
        boolean res = false;
        for (String string : values) {
            if(string.equals(value)){
                res = true;
                break;
            }
        }
        return res;
    }
    /**
     * UI定义下拉查询(templateType为UI定义时的UI定义下拉查询)
     * @param baseQueryObject selectBtmType 选择的源对象,带分页信息
     * @return
@@ -2551,6 +2609,205 @@
        return res;
    }
    /**
     * 通过业务类型获取UI上下文包含其下关联的区域定义>页面定义等所有关联数据,归纳成tree结构
     * @param btmName 业务类型名称
     * @param level 查询到那个层级为止(ui、tab、pageDef)
     * @return
     */
    public Tree getAllLevelTreeByBtm(String btmName,String level) throws PLException {
        VciBaseUtil.alertNotNull(btmName,"业务类型编号",level,"查询层级");
        Tree resTree = new Tree();
        resTree.setText("UI上下文选项");
        resTree.setId("UILayout");
        resTree.setLeaf(false);
        resTree.setLevel(1);
        String level1Oid = ObjectUtility.getNewObjectID36();
        resTree.setOid(level1Oid);
        PLUILayout[] pluiLayouts = platformClientUtil.getUIService().getPLUILayoutsByRelatedType(btmName);
        if(Func.isEmpty(pluiLayouts)){
            return resTree;
        }
        //根据查询的层级不同决定是否返回
        List<Tree> uiChildrenTree = new ArrayList<>();
        Arrays.stream(pluiLayouts).forEach(item->{
            Tree uiTree = new Tree();
            uiTree.setLeaf(level.equals("ui"));
            uiTree.setLevel(2);
            uiTree.setId(item.plCode);
            uiTree.setOid(item.plOId);
            uiTree.setText(item.plCode + "(" + item.plName + ")");
            uiTree.setParentId(level1Oid);
            List<Tree> tabChildren = null;
            if(!level.equalsIgnoreCase("ui")){
                try {
                    tabChildren = this.getTabChildren(item.plOId, level);
                } catch (PLException e) {
                    e.printStackTrace();
                    String exceptionMessage = "查询页签时出现错误:"+VciBaseUtil.getExceptionMessage(e);
                    logger.error(exceptionMessage);
                    throw new VciBaseException(exceptionMessage);
                }
                uiTree.setChildren(tabChildren);
            }
            uiChildrenTree.add(uiTree);
        });
        resTree.setChildren(uiChildrenTree);
        return resTree;
    }
    /**
     * 克隆按钮(存在父子结构关系、关联数据按钮参数)
     * @param uiCloneVO
     * @return
     * @throws Throwable
     */
    @Override
    public BaseResult cloneTabButton(UICloneVO uiCloneVO) throws Throwable {
        VciBaseUtil.alertNotNull(uiCloneVO,"克隆对象",uiCloneVO.getSourceOId(),"源对象主键");
        String fromOId = uiCloneVO.getSourceOId();
        String toOId = uiCloneVO.getToOId();
        //先查询源对象
        //PLTabButton tabButton = platformClientUtil.getUIService().getPLTabButtonById(fromOId);
        String sourceTableOId = uiCloneVO.getCloneParam().get("sourceTableOId");
        if(Func.isBlank(sourceTableOId)){
            return BaseResult.fail("未从请求参数中获取到,源对象关联的页面定义主键!!");
        }
        //判断是否有目标主键,如果没有就说明是克隆到当前页面下
        if(Func.isBlank(toOId)){
            toOId = sourceTableOId;
        }
        //判断前端是否传了克隆名过来(按钮这边不需要名称、编号判重,所以这一块儿逻辑忽略)
        //按钮具有父子级关系,所以还需要做oid和parentOId处理
        List<PLTabButtonVO> tabButtons = this.getTabButtons(sourceTableOId);
        PLTabButtonVO filterTabButton = tabButtons.stream()
                .filter(item -> item.getOId().equals(fromOId)).findFirst().orElse(null);
        if(Func.isEmpty(filterTabButton)){
            return BaseResult.fail("根据源对象主键未查询到源对象,请刷新后重试!!");
        }
        if(Func.isEmpty(sessionInfo)){
            sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
        }
        //改变button对象的oid和parentOId
        this.modifyButtonIdsAndCopy(filterTabButton,toOId,ObjectUtility.getNewObjectID36());
        return BaseResult.success("按钮复制成功!");
    }
    /**
     * 修改oId和parentOid,不改变父子级(oid变换parentOId也需要跟着变换)结构,并保存按钮和其参数
     * @param button
     * @param newOId
     */
    private void modifyButtonIdsAndCopy(PLTabButtonVO button,String toOId, String newOId) throws PLException {
        if (button == null) {
            return;
        }
        // 修改当前节点的oId
        button.setOId(newOId);
        //开始保存按钮和参数
        button.setCreateUser(sessionInfo.getUserId());
        button.setModifyUser(sessionInfo.getUserId());
        button.setTableOId(toOId);
        PLTabButton plTabButton = this.tabButtonVO2TabButton(new PLTabButton(), button);
        boolean res = platformClientUtil.getUIService().savePLTabButton(plTabButton);
        if(!res){
            throw new PLException("500",new String[]{"按钮配置复制失败!"});
        }
        this.saveButtonParams(button.getButtonParams(),button.getOId());
        // 递归遍历子节点
        if (button.getChildren() != null) {
            for (PLTabButtonVO child : button.getChildren()) {
                // 子对象的 parentOid 设置为当前节点的新oid
                modifyButtonIdsAndCopy(child,toOId, ObjectUtility.getNewObjectID36());
                child.setParentOid(button.getOId());  // 确保子对象的parentOid指向当前的oid
            }
        }
    }
    /**
     * 克隆页签
     * @param uiCloneVO
     * @return
     * @throws Throwable
     */
    @Override
    public BaseResult clonetabPage(UICloneVO uiCloneVO) throws Throwable {
        return null;
    }
    /**
     * 克隆页面定义
     * @param uiCloneVO
     * @return
     * @throws Throwable
     */
    @Override
    public BaseResult clonePageDef(UICloneVO uiCloneVO) throws Throwable {
        return null;
    }
    /**
     * 获取页签这一层的关联数据
     * @return
     */
    private List<Tree> getTabChildren(String uiLayoutOid,String level) throws PLException {
        List<Tree> tabChildren = new ArrayList<>();
        if(Func.isNotBlank(uiLayoutOid)){
            PLTabPage[] tabPages = platformClientUtil.getUIService().getPLTabPagesByPageDefinationOId(uiLayoutOid);
            Arrays.stream(tabPages).forEach(tabPage->{
                Tree tabTree = new Tree();
                tabTree.setLeaf(level.equals("tab"));
                tabTree.setLevel(2);
                tabTree.setId(tabPage.plCode);
                tabTree.setOid(tabPage.plOId);
                tabTree.setText(tabPage.plCode + "(" + tabPage.plName + ")");
                tabTree.setParentId(uiLayoutOid);
                if(!level.equalsIgnoreCase("tab")){
                    try {
                        tabTree.setChildren(this.getPageDefChildren(tabPage.plOId,level));
                    } catch (PLException e) {
                        e.printStackTrace();
                        String exceptionMessage = "查询页面定义时出现错误:"+VciBaseUtil.getExceptionMessage(e);
                        logger.error(exceptionMessage);
                        throw new VciBaseException(exceptionMessage);
                    }
                }
                tabChildren.add(tabTree);
            });
        }
        return tabChildren;
    }
    /**
     * 获取页面定义这一层的关联数据
     * @return
     */
    private List<Tree> getPageDefChildren(String tabPageOid,String level) throws PLException {
        List<Tree> pageDefChildren = new ArrayList<>();
        if(Func.isNotBlank(tabPageOid)){
            PLPageDefination[] pageDefs = platformClientUtil.getUIService().getPLPageDefinationsByPageContextOId(tabPageOid);
            Arrays.stream(pageDefs).forEach(pageDef->{
                Tree tabTree = new Tree();
                tabTree.setLeaf(true);
                tabTree.setLevel(2);
                tabTree.setId(pageDef.name);
                tabTree.setOid(pageDef.plOId);
                tabTree.setText(pageDef.name + "(" + pageDef.desc + ")");
                tabTree.setParentId(tabPageOid);
                pageDefChildren.add(tabTree);
            });
        }
        return pageDefChildren;
    }
    //基础公共检查接口
    private abstract class BaseComptInter {