田源
2025-01-16 a13255b4129ee8a7a7b7e1ecd8e02dd2c78f7c17
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIEngineServiceImpl.java
@@ -10,20 +10,15 @@
import com.vci.pagemodel.*;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.util.BeanUtilForVCI;
import com.vci.starter.web.util.LangBaseUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.starter.web.util.*;
import com.vci.starter.web.util.Lcm.Func;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.enumpck.UIComponentDisplayTypeEnum;
import com.vci.web.enumpck.UIComponentTypeEnum;
import com.vci.web.enumpck.UIFieldTypeEnum;
import com.vci.web.enumpck.UILayoutAreaTypeEnum;
import com.vci.web.other.AllActionThreadLocal;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsBtmServiceI;
import com.vci.web.service.UIEngineServiceI;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.service.*;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import com.vci.web.xmlmodel.UIComponentDefineXO;
@@ -92,10 +87,10 @@
   private OsAttributeServiceI attrService;
   /**
    * 业务类型的服务
    * UI定义管理服务
    */
   @Autowired
   private WebBoServiceI boService;
   private UIManagerServiceI uiManagerServiceI;
   /**
    * 表单的字段类型映射
@@ -414,16 +409,13 @@
      if(StringUtils.isBlank(btmId) || StringUtils.isBlank(id)){
         return null;
      }
      if(!QUERY_BY_CACHE){
         PortalVI portalVI = null;
         try {
            portalVI = platformClientUtil.getUIService().getPortalVIByTypeNameAndVIName(btmId, id);
         } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
         }
         return formDO2VO(portalVI);
      PortalVI portalVI = null;
      try {
         portalVI = platformClientUtil.getUIService().getPortalVIByTypeNameAndVIName(btmId, id);
      } catch (PLException vciError) {
         throw WebUtil.getVciBaseException(vciError);
      }
      return self.selectAllFormMap().getOrDefault(btmId.toLowerCase()+SEP+id.toLowerCase(),null);
      return formDO2VO(portalVI);
   }
   /**
@@ -876,7 +868,7 @@
   private List<UIContentVO> UIContentDO2VOs(Collection<PLUILayout> pageLayoutDefinations){
      List<UIContentVO> contentVOS = new ArrayList<>();
      Optional.ofNullable(pageLayoutDefinations).orElseGet(()->new ArrayList<PLUILayout>()).stream().forEach(pageLayout->{
         contentVOS.add(UIContentDO2VO(pageLayout,false));
         contentVOS.add(UIContentDO2VO(pageLayout,false,null));
      });
      if(!CollectionUtils.isEmpty(contentVOS)) {
         Map<String, List<UILayoutVO>> layoutMap = batchListLayoutByContent(contentVOS.stream().map(UIContentVO::getOid).collect(Collectors.toSet()));
@@ -902,7 +894,7 @@
    */
   @VciUnLog
   @Override
   public UIContentVO UIContentDO2VO(PLUILayout pageLayoutDefination, boolean queryDetail){
   public UIContentVO UIContentDO2VO(PLUILayout pageLayoutDefination, boolean queryDetail,Map<String, List<RoleRightVO>> roleRightMap){
      UIContentVO contentVO = new UIContentVO();
      if(pageLayoutDefination !=null){
         contentVO.setOid(pageLayoutDefination.plOId);
@@ -920,14 +912,16 @@
         contentVO.setLastModifier(pageLayoutDefination.plModifyUser);
         if(queryDetail){
            //查询包含的内容
            List<UILayoutVO> layoutVOS = listLayoutByContent(contentVO.getOid());
            List<UILayoutVO> layoutVOS = null;
            //判断是否根据权限返回
            layoutVOS = listLayoutByContent(contentVO.getOid(),roleRightMap);
            if(!CollectionUtils.isEmpty(layoutVOS)){
               if(layoutVOS.size() == 1){
                  //只有一个区域
                  UILayoutVO layoutVO = layoutVOS.get(0);
                  List<UIComponentVO> componentVOs = layoutVO.getComponentVOs();
                  //第一个作为center
                  UIComponentVO firstCompVO = componentVOs.stream().min((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum())).get();
                  UIComponentVO firstCompVO = componentVOs.stream().min(Comparator.comparing(UIComponentVO::getOrderNum)).get();
                  List<UIComponentVO> southCompVO = componentVOs.stream().filter(s->!s.getOid().equals(firstCompVO.getOid())).collect(Collectors.toList());
                  UILayoutVO centerVO = new UILayoutVO();
@@ -1016,16 +1010,79 @@
   //   }
   /**
    * 获取某个UI上下文的区域
    * 获取某个UI上下文的区域,根据权限控制返回
    * @param pkContent UI上下文的主键
    * @return 上下文
    */
   private List<UILayoutVO> listLayoutByContent(String pkContent){
   private List<UILayoutVO> listLayoutByContent(String pkContent,Map<String, List<RoleRightVO>> roleRightMap){
      try {
         return UILayoutDO2VOs(Arrays.stream(platformClientUtil.getUIService().getPLTabPagesByPageDefinationOId(pkContent)).collect(Collectors.toList()),true);
         List<PLTabPage> tabPageList = Arrays.stream(platformClientUtil.getUIService().getPLTabPagesByPageDefinationOId(pkContent)).collect(Collectors.toList());
         //过滤掉没有访问权限的UI
         tabPageList = this.filterTabPageByRoleRight(tabPageList,roleRightMap);
         return UILayoutDO2VOs(tabPageList,true,roleRightMap);
      } catch (PLException vciError) {
         throw WebUtil.getVciBaseException(vciError);
      }
   }
   /**
    * 根据权限集合过滤掉没有访问权限的页签数据
    * @param tabPageList
    * @param roleRightMap
    */
   private List<PLTabPage> filterTabPageByRoleRight(List<PLTabPage> tabPageList, Map<String, List<RoleRightVO>> roleRightMap){
      if(Func.isEmpty(roleRightMap) || Func.isEmpty(tabPageList)){
         return tabPageList;
      }
      List<PLTabPage> filterList = new ArrayList<>();
      for (int i = 0; i < tabPageList.size(); i++) {
         PLTabPage tabPage = tabPageList.get(i);
         if(roleRightMap.containsKey(tabPage.plOId)){
            filterList.add(tabPage);
         }
         /*if(roleRightMap.containsKey(tabPage.plContextOId)) {
            Long rightValue = roleRightMap.get(tabPage.plContextOId).getRightValue();
            int nodeValue = tabPage.plSeq;
            if (nodeValue >= 0 && nodeValue <= 63) {
               //进行位与操作,如果相等则表示具有当前操作的权限
               long preValue = (rightValue >> nodeValue) & 1;
               if (preValue != 1) {
                  tabPageList.remove(tabPage);
               }
            }
         }*/
      }
      return filterList;
   }
   /**
    * 根据权限集合过滤掉没有访问权限的页面定义数据
    * @param plPageDefinationList
    * @param roleRightMap
    */
   private List<PLPageDefination> filterPageDefByRoleRight(List<PLPageDefination> plPageDefinationList, Map<String, List<RoleRightVO>> roleRightMap){
      if(Func.isEmpty(roleRightMap) || Func.isEmpty(plPageDefinationList)){
         return plPageDefinationList;
      }
      List<PLPageDefination> filterList = new ArrayList<>();
      for (int i = 0; i < plPageDefinationList.size(); i++) {
         PLPageDefination plPageDefination = plPageDefinationList.get(i);
         if(roleRightMap.containsKey(plPageDefination.plOId)){
            filterList.add(plPageDefination);
         }
         /*if(roleRightMap.containsKey(plPageDefination.plTabPageOId)) {
            Long rightValue = roleRightMap.get(plPageDefination.plTabPageOId).getRightValue();
            int nodeValue = plPageDefination.seq;
            if (nodeValue >= 0 && nodeValue <= 63) {
               //进行位与操作,如果相等则表示具有当前操作的权限
               long preValue = (rightValue >> nodeValue) & 1;
               if (preValue != 1) {
                  plPageDefinationList.remove(plPageDefination);
               }
            }
         }*/
      }
      return filterList;
   }
   /**
@@ -1079,7 +1136,7 @@
    * @param pages 区域的数据对象
    * @return 显示对象
    */
   private List<UILayoutVO> UILayoutDO2VOs(Collection<PLTabPage> pages, boolean queryDetail){
   private List<UILayoutVO> UILayoutDO2VOs(Collection<PLTabPage> pages, boolean queryDetail, Map<String, List<RoleRightVO>> roleRightMap){
      List<UILayoutVO> contentVOS = new ArrayList<>();
      Map<String, OsAttributeVO> attributeVOMap;
      if(pages != null && pages.size() > 0){
@@ -1093,7 +1150,7 @@
         attributeVOMap = null;
      }
      Optional.ofNullable(pages).orElseGet(()->new ArrayList<PLTabPage>()).stream().forEach(page->{
         UILayoutVO layoutVO = UILayoutDO2VO(page, queryDetail,attributeVOMap);
         UILayoutVO layoutVO = UILayoutDO2VO(page, queryDetail,attributeVOMap,roleRightMap);
         if(layoutVO.isEnableStatus()) {
            contentVOS.add(layoutVO);
         }
@@ -1117,7 +1174,7 @@
    * @return 区域的显示对象
    */
   @VciUnLog
   private UILayoutVO UILayoutDO2VO(PLTabPage page, boolean queryDetail,Map<String, OsAttributeVO> attributeVOMap){
   private UILayoutVO UILayoutDO2VO(PLTabPage page, boolean queryDetail,Map<String, OsAttributeVO> attributeVOMap, Map<String, List<RoleRightVO>> roleRightMap){
      UILayoutVO layoutVO = new UILayoutVO();
      if(page !=null ){
         layoutVO.setOid(page.plOId);
@@ -1157,7 +1214,10 @@
         if(queryDetail){
            //单个的,直接获取
            try {
               layoutVO.setComponentVOs(uiComponentDO2VOs(Arrays.stream(platformClientUtil.getUIService().getPLPageDefinationsByPageContextOId(layoutVO.getOid())).collect(Collectors.toList()),true,attributeVOMap));
               List<PLPageDefination> pageDefinationList = Arrays.stream(platformClientUtil.getUIService().getPLPageDefinationsByPageContextOId(layoutVO.getOid())).collect(Collectors.toList());
               pageDefinationList = this.filterPageDefByRoleRight(pageDefinationList,roleRightMap);
               List<UIComponentVO> uiComponentVOS = uiComponentDO2VOs(pageDefinationList, true, attributeVOMap,roleRightMap);
               layoutVO.setComponentVOs(uiComponentVOS);
            } catch (PLException vciError) {
               throw WebUtil.getVciBaseException(vciError);
            }
@@ -1165,6 +1225,7 @@
      }
      return layoutVO;
   }
   /**
    * 查询所有的上下文的区域的映射
    *
@@ -1201,20 +1262,11 @@
      if(StringUtils.isBlank(componentOid)){
         return null;
      }
      if(!QUERY_BY_CACHE){
         try {
            return uiComponentDO2VO(platformClientUtil.getUIService().getPLPageDefinationById(componentOid),true,attributeVOMap);
         } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
         }
      }else{
         List<UIComponentVO> componentVOS = self.selectAllUIComponent();
         List<UIComponentVO> componentVOList = Optional.ofNullable(componentVOS).orElseGet(() -> new ArrayList<>()).stream().filter(s -> s.getOid().equalsIgnoreCase(componentOid)).collect(Collectors.toList());
         if(!CollectionUtils.isEmpty(componentVOList)){
            return componentVOList.get(0);
         }
      try {
         return uiComponentDO2VO(platformClientUtil.getUIService().getPLPageDefinationById(componentOid),true,attributeVOMap,null);
      } catch (PLException vciError) {
         throw WebUtil.getVciBaseException(vciError);
      }
      return null;
   }
   /**
@@ -1222,10 +1274,10 @@
    * @param pages 数据对象
    * @return 显示对象
    */
   private List<UIComponentVO> uiComponentDO2VOs(Collection<com.vci.corba.portal.data.PLPageDefination> pages, boolean queryDetail,Map<String, OsAttributeVO> attributeVOMap){
   private List<UIComponentVO> uiComponentDO2VOs(Collection<PLPageDefination> pages, boolean queryDetail,Map<String, OsAttributeVO> attributeVOMap, Map<String, List<RoleRightVO>> roleRightMap){
      List<UIComponentVO> componentVOS = new ArrayList<>();
      pages.stream().forEach(page->{
         componentVOS.add(uiComponentDO2VO(page,queryDetail,attributeVOMap));
         componentVOS.add(uiComponentDO2VO(page,queryDetail,attributeVOMap,roleRightMap));
      });
      return componentVOS;
   }
@@ -1236,7 +1288,7 @@
    * @return 显示对象
    */
   @VciUnLog
   private UIComponentVO uiComponentDO2VO(PLPageDefination page, boolean queryDetail, Map<String, OsAttributeVO> attributeVOMap){
   private UIComponentVO uiComponentDO2VO(PLPageDefination page, boolean queryDetail, Map<String, OsAttributeVO> attributeVOMap, Map<String, List<RoleRightVO>> roleRightMap){
      UIComponentVO componentVO = new UIComponentVO();
      if(page !=null){
         componentVO.setOid(page.plOId);
@@ -1244,6 +1296,7 @@
         componentVO.setName(page.name);
         componentVO.setDescription(page.desc);
         componentVO.setOrderNum((int) page.seq);
         UIComponentDefineXO componentDefineXO = null;
         try {
            componentDefineXO = readInfoFromXML(page.plDefination, UIComponentDefineXO.class);
@@ -1251,6 +1304,8 @@
            logger.error("读取xml出错",e);
            return  null;
         }
         //自定义查询方式
         componentVO.setBsDataModel(componentDefineXO.getBsDataModel());
         //之前的类型的值是1,2,3等看着不直观
         UIComponentTypeEnum componentTypeEnum = null;
         if("1".equals(componentDefineXO.getTemplateType())){
@@ -1374,8 +1429,8 @@
            treeDefineVO.setBtmType(componentDefineXO.getShowType());
            treeDefineVO.setLinkType(componentDefineXO.getLinkType());
            treeDefineVO.setLoadType("1".equalsIgnoreCase(componentDefineXO.getExpandMode())?"node":"all");
            //TODO:这个属性现在由链接类型查询控制,不由页面定义控制了
            //treeDefineVO.setOrientation("positive".equalsIgnoreCase(componentDefineXO.getOrientation())?false:true);
            //TODO:这个属性现在由链接类型查询模板配置上控制,不在页面定义控制了,但是为了兼容以前的UI定义所以需要考虑保留
            treeDefineVO.setOrientation(componentDefineXO.getOrientation());
            treeDefineVO.setShowImage("1".equalsIgnoreCase(componentDefineXO.getIsShowImage())?true:false);
            treeDefineVO.setRootContent(componentDefineXO.getRootContent());
            treeDefineVO.setFieldSep(StringUtils.isBlank(componentDefineXO.getSeparator())?",":componentDefineXO.getSeparator());
@@ -1400,39 +1455,43 @@
         }
         componentVO.setUiParseClass(componentDefineXO.getUIParser());
         componentVO.setExtendAttr(componentDefineXO.getExtAttr());
         componentVO.setButtons(listButtonByComponent(componentVO.getOid()));
         componentVO.setButtons(listButtonByComponent(componentVO.getOid(),roleRightMap));
      }
      return componentVO;
   }
   /**
    * 获取某个组件的按钮
    * 获取某个组件的按钮(根据权限过滤)
    * @param pkComponent 组件的主键
    * @return 按钮的信息
    */
   @Override
   public List<UIButtonDefineVO> listButtonByComponent(String pkComponent){
   public List<UIButtonDefineVO> listButtonByComponent(String pkComponent, Map<String, List<RoleRightVO>> roleRightMap){
      try {
         List<UIButtonDefineVO> buttonDefineVOS = buttonDO2VOs(Arrays.stream(platformClientUtil.getUIService().getPLTabButtonsByTableOId(pkComponent)).collect(Collectors.toSet())).stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList());
         Map<String,RoleRightInfo> allRightRoleMap = new HashMap<>();
         RoleRightInfo[] bts = platformClientUtil.getFrameworkService().getRoleRightByUserName("bt");
         Map<String,Long> rightMap = new HashMap<String,Long>();
         for(RoleRightInfo obj:bts){
            allRightRoleMap.put(obj.funcId, obj);
            rightMap.put(obj.funcId,obj.rightValue);
         if(Func.isEmpty(roleRightMap)){
            roleRightMap = uiManagerServiceI.getRoleRightMap(null);
         }
         //循环对按钮权限进行判断,没有权限的将移除buttonDefineVOS对象
         Iterator<UIButtonDefineVO> buttonDefineVO = buttonDefineVOS.iterator();
         while (buttonDefineVO.hasNext()){
            UIButtonDefineVO buttonDefine = buttonDefineVO.next();
            if(rightMap.containsKey(buttonDefine.getPkComponent())) {
               Long rightValue = rightMap.get(buttonDefine.getPkComponent());
            if(roleRightMap.containsKey(buttonDefine.getPkComponent())) {
               List<Long> rightValues = roleRightMap.get(buttonDefine.getPkComponent()).stream()
                     .map(e -> e.getRightValue()).collect(Collectors.toList());
               int nodeValue = buttonDefine.getOrderNum();
               if (nodeValue >= 0 && nodeValue <= 63) {
                  boolean authFlag = false;
                  //进行位与操作,如果相等则表示具有当前操作的权限
                  long preValue = (rightValue >> nodeValue) & 1;
                  if (preValue != 1) {
                  for (Long rightValue : rightValues) {
                     long preValue = (rightValue >> nodeValue) & 1;
                     if (preValue == 1) {
                        authFlag = true;
                        break;
                     }
                  }
                  if(!authFlag){
                     buttonDefineVO.remove();
                  }
               }
@@ -1464,7 +1523,7 @@
    * @return 显示对象
    */
   @Override
   public List<UIButtonDefineVO> buttonDO2VOs(Collection<com.vci.corba.portal.data.PLTabButton> buttons){
   public List<UIButtonDefineVO> buttonDO2VOs(Collection<PLTabButton> buttons){
      List<UIButtonDefineVO> buttonDefineVOS = new ArrayList<>();
      if(buttons != null && buttons.size() > 0){
//         Map<String, UIActionVO> actionVOMap = self.selectAllActionMap();
@@ -1488,7 +1547,7 @@
    * @return 显示对象
    */
   @Override
   public UIButtonDefineVO buttonDO2VO(com.vci.corba.portal.data.PLTabButton button, Map<String, UIActionVO> actionVOMap)  {
   public UIButtonDefineVO buttonDO2VO(PLTabButton button, Map<String, UIActionVO> actionVOMap)  {
      UIButtonDefineVO buttonVO = new UIButtonDefineVO();
//      Map<String, UIActionVO> actionVOMap = ServiceProvider.getUIService().getAllPLAction();
      if(button !=null){
@@ -1582,7 +1641,7 @@
    * @return UI上下文的信息
    */
   @Override
   public UIContentVO getUIContentByBtmTypeAndId(String btmType, String id) {
   public UIContentVO getUIContentByBtmTypeAndId(String btmType, String id) throws PLException {
      WebUtil.alertNotNull(btmType,"业务类型或者链接类型",id,"UI上下文的编号");
      PLUILayout[] obj = null;
      try {
@@ -1590,6 +1649,10 @@
      } catch (PLException vciError) {
         throw WebUtil.getVciBaseException(vciError);
      }
      // 1、根据当前角色判断是管理人员还是普通用户(正常来说只有普通用户才会用到该查询接口)
      Map<String, List<RoleRightVO>> roleRightMap = uiManagerServiceI.getRoleRightMap(null);
      // 2、按照当前登录用户查询权限(功能权限和UI授权的授权信息都是放在同一张表里的)
      // 3、找出当前要查询的UI上下文
      PLUILayout context = null;
      for (int i = 0; i < obj.length; i++) {
         if (obj[i].plCode.equals(id)) {
@@ -1597,7 +1660,9 @@
            break;
         }
      }
      return UIContentDO2VO(context,true);
      // 4、每一个菜单查询的都是一个UI上下文,所以UI上下文是有功能授权控制的,只需要控制后面的页签、页面、按钮的权限。
      return UIContentDO2VO(context, true,roleRightMap);
   }
}