Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java
@@ -5,16 +5,17 @@
import com.vci.client.common.datatype.VTLong;
import com.vci.client.common.datatype.VTString;
import com.vci.client.mw.ClientSessionUtility;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.atm.AttributeDef;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.vrm.VersionRule;
import com.vci.dto.OsAttributeDTO;
import com.vci.dto.OsEnumDTO;
import com.vci.dto.OsEnumItemDTO;
import com.vci.omd.dataType.VTDataType;
import com.vci.pagemodel.OsEnumItemVO;
import com.vci.pagemodel.OsEnumVO;
import com.vci.pagemodel.OsUsedAttributeVO;
import com.vci.omd.objects.OtherInfo;
import com.vci.pagemodel.*;
import com.vci.po.OsAttributePO;
import com.vci.po.OsEnumPO;
import com.vci.starter.poi.bo.ReadExcelOption;
@@ -25,12 +26,11 @@
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.*;
import com.vci.starter.web.util.*;
import com.vci.model.OsAttributeDO;
import com.vci.pagemodel.OsAttributeVO;
import com.vci.web.enumpck.ItemTypeEnum;
import com.vci.web.enumpck.PortalVITypeFlag;
import com.vci.web.properties.UsedNames;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsBaseServiceI;
@@ -55,6 +55,7 @@
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
//import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*;
import static com.vci.omd.constants.AttributeConstants.*;
@@ -135,6 +136,101 @@
    * 默认属性的映射,key是小写
    */
   private static Map<String,OsAttributeVO> defaultAttributeVOMap = new HashMap<>();
   @Override
   public List<Tree> getTreeAttributesByBtmName(TreeQueryObject treeQueryObject) {
      List<Tree> rootTreeList=new ArrayList<>();
      Map<String, String> conditionMap = treeQueryObject.getConditionMap();
      if (conditionMap == null) {
         conditionMap = new HashMap<>();
      }
      String typeName = StringUtils.isBlank(conditionMap.get("typeName")) ? "" : conditionMap.get("typeName");
      if (StringUtils.isBlank(typeName)) {
         VciBaseUtil.alertNotNull(typeName,"业务类型名称");
      }
      try {
         String typeFlag=StringUtils.isBlank(conditionMap.get("typeFlag"))?"":conditionMap.get("typeFlag");
         PortalVITypeFlag portalVITypeFlag= PortalVITypeFlag.getByName(typeFlag);
         Short viTypeFlag=-1;
         if(portalVITypeFlag!=null){
            viTypeFlag=portalVITypeFlag.getIntVal();
         }
         boolean isDefault =Boolean.parseBoolean(conditionMap.get("isDefault"));
         Tree tree = new Tree("root", "【" + typeName + "】属性信息", "root");
         tree.setLevel(0);
         rootTreeList.add(tree);
         getChildTree(rootTreeList,typeName, viTypeFlag,isDefault);
      }catch (Throwable e){
       e.printStackTrace();
      }
      return rootTreeList;
   }
   /**
    * 构造属性树节点
    * @param parentTreeList
    * @param refTypeName
    * @param refFlag
    * @param isDefault
    * @throws Exception
    */
   private void getChildTree(List<Tree> parentTreeList,String refTypeName,int refFlag,boolean isDefault) throws Exception {
      for (Tree pTree : parentTreeList) {
         if (pTree.getLevel()>= 3) {
            continue;
         }
         Object o= pTree.getData();
         String pName=pTree.getText();
         boolean isOsAttributeVO=false;
         if(o instanceof OsAttributeVO){
            isOsAttributeVO=true;
            OsAttributeVO osAttributeVO=(OsAttributeVO)o;
            String other = osAttributeVO.getOther();
            OtherInfo otherInfo = OtherInfo.getOtherInfoByText(other);
            refFlag = otherInfo.getRefFlag();
            refTypeName = otherInfo.getRefTypeName();
         }
         List<OsAttributeVO> childOsAttributeVOList=new ArrayList<>();
         if (refFlag != -1) {
            // pName: 为参照属性名加上路径
            childOsAttributeVOList=getOsAttributeVOSByBtName(refTypeName,refFlag,isDefault);
            if(!CollectionUtils.isEmpty(childOsAttributeVOList)) {
               List<Tree> childTreeList= new ArrayList<>();
               boolean finalIsOsAttributeVO = isOsAttributeVO;
               childOsAttributeVOList.stream().forEach(childOsAttributeVO->{
                  Tree childTree = new Tree(childOsAttributeVO.getOid(), childOsAttributeVO.getId(), childOsAttributeVO);
                  childTree.setOid(childOsAttributeVO.getOid());
                  childTree.setParentName(pTree.getText());
                  childTree.setParentId(pTree.getOid());
                  childTree.setLevel(pTree.getLevel()+1);
                  childTree.setLeaf(true);
                  if(finalIsOsAttributeVO) {
                     childTree.setText(pName + "." + childOsAttributeVO.getId());
                  }else{
                     childTree.setText(childOsAttributeVO.getId());
                  }
                  if (childTree.getLevel()>= 3) {
                     childTree.setLeaf(true);
                  }
                  childTreeList.add(childTree);
               });
               if(childTreeList.size()>0){
                  pTree.setChildren(childTreeList);
                  pTree.setExpanded(false);
                  getChildTree(childTreeList,refTypeName,refFlag,isDefault);
               }else{
                  pTree.setLeaf(true);
                  pTree.setExpanded(true);
               }
            }
         }else{
            pTree.setExpanded(true);
         }
      }
   }
   /**
    * 获取默认的属性
@@ -247,13 +343,20 @@
            attributeVO.setLastModifyTime(new Date(attribItem.modifyTime));
            attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat));
         }catch (Throwable e){
            e.printStackTrace();
            String errorLog = "属性DO转VO时出错,原因:"+VciBaseUtil.getExceptionMessage(e);
            logger.error(errorLog);
            throw new VciBaseException(errorLog);
         }
         attributeVO.setLastModifier(attribItem.modifier);
         attributeVO.setName(attribItem.label);
         attributeVO.setDescription(attribItem.description);
         attributeVO.setAttributeDataType(attribItem.vtDataType);
         attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType));
         //获取UI属性类型
         attributeVO.setAttributeUIType(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,false));
         //获取UI属性类型文本
         attributeVO.setAttributeUITypeText(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,true));
         attributeVO.setDefaultValue(attribItem.defValue);
         if(Func.isNotBlank(attribItem.rage)){
            attributeVO.setRange(attribItem.rage.replace("&lt;","<"));
@@ -419,6 +522,32 @@
   }
   /**
    * 使用属性编号获取对象--批量
    *
    * @param attrCodes 属性的英文名称
    * @param attributeVOMap 属性对象
    * @return 属性的显示对象
    */
   @Override
   public List<OsAttributeVO> listAttrByIds(Collection<String> attrCodes,Map<String, OsAttributeVO> attributeVOMap) {
      if(CollectionUtils.isEmpty(attrCodes)){
         return null;
      }
      if(attributeVOMap == null){
         attributeVOMap = self.selectAllAttributeMap();
      }
      List<OsAttributeVO> attributeVOS = new ArrayList<>();
      Map<String, OsAttributeVO> finalAttributeVOMap = attributeVOMap;
      attrCodes.stream().forEach(attrCode->{
         OsAttributeVO attributeVO = finalAttributeVOMap.getOrDefault(attrCode.toLowerCase(),null);
         if(attributeVO!=null){
            attributeVOS.add(attributeVO);
         }
      });
      return attributeVOS;
   }
   /**
    * 批量添加属性
    *
    * @param attribItemList 属性的列表
@@ -514,9 +643,10 @@
      //检查默认值与属性类型是否匹配
      checkDefValue(osAttributeDTO);
      boolean compatible = isCompatible(osAttributeVO,osAttributeDTO);
      boolean hasInstance = hasInstance(osAttributeDTO.getName());
      //产生数据, 并且不兼容
      if(hasInstance && !compatible){
      //boolean hasInstance = hasInstance(osAttributeDTO.getId()); //不判断是否产生数据只要被引用就需要进一步判断类型是否兼容
      boolean checkAttrIsUse = this.checkAttrIsUse(osAttributeDTO.getId());
      //TODO:按照以前操作配置文档中的逻辑应该是:不论是否产生数据只要被引用就需要要判断类型是否兼容(如VTString不能转为VTIntger或VTLong)
      if(checkAttrIsUse/*hasInstance*/ && !compatible){
         throw new PLException("500",new String[]{"无效变更, 不兼容已产生的数据!"});
      }
      String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
@@ -666,6 +796,26 @@
    */
   private boolean hasInstance(String abName) throws PLException {
      return osBtmService.hasInstance(abName) && osLinkTypeServiceI.hasInstance(abName);
   }
   /**
    * 查看属性是否被引用
    * @param abName
    * @return false未被引用 true被引用
    */
   private boolean checkAttrIsUse(String abName) throws PLException {
      if(Func.isBlank(abName)){
         return false;
      }
      String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(abName);
      if(Func.isNotEmpty(btNames)){
         return true;
      }
      String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(abName);
      if(Func.isNotEmpty(ltNames)){
         return true;
      }
      return false;
   }
   /**
@@ -849,11 +999,14 @@
         throw new PLException("500",new String[]{"请选择要查询应用范围的属性!"});
      }
      String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName);
      if(Func.isEmpty(btNames)){
      String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(attributeName);
      String[] mergedArray = Stream.concat(Stream.of(btNames), Stream.of(ltNames)).toArray(String[]::new);
      if(Func.isEmpty(mergedArray)){
         return new ArrayList<>();
      }
      List<Map<String,String>> btmNameMapList = new ArrayList<>();
      Arrays.stream(btNames).forEach(btName->{
      Arrays.stream(mergedArray).forEach(btName->{
         Map<String, String> itemMap = new HashMap<>();
         itemMap.put("attributeName",attributeName);
         itemMap.put("source",btName);
@@ -1073,7 +1226,7 @@
               }
               osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId());
            }
            osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
            osAttributeDTO.setOid(ObjectUtility.getNewObjectID36());
            osAttributeDTO.setId(osAttributePO.getId());
            osAttributeDTO.setName(osAttributePO.getName());
            osAttributeDTO.setDescription(osAttributePO.getDescription());
@@ -1142,17 +1295,36 @@
    * @return
    */
   @Override
   public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag) throws Exception{
   public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag,boolean isDefault) throws Exception{
      VciBaseUtil.alertNotNull(btName,"参数不允许为空",typeFlag,"参数不允许为空");
      List<OsAttributeVO> attributeVOS=new ArrayList<>();
      try {
         AttributeDef[] attributeDefs=new AttributeDef[]{};
         List<AttributeDef> attributeDefList=new ArrayList<>();
         if(typeFlag==0){
            attributeDefs=   platformClientUtil.getBtmService().getAttributeDefs(btName);
            AttributeDef [] attributeDefs=   platformClientUtil.getBtmService().getAttributeDefs(btName);
            if(attributeDefs!=null){
               attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList()));
            }
            if(isDefault){
               AttributeDef [] sysAttributeDefs=platformClientUtil.getBtmService().getSysAttributeDefs();
               if(sysAttributeDefs!=null){
                  attributeDefList.addAll(Arrays.stream(sysAttributeDefs).collect(Collectors.toList()));
               }
            }
         }else{
            attributeDefs=platformClientUtil.getLinkTypeService().getAttributes(btName);
            AttributeDef []   attributeDefs=platformClientUtil.getLinkTypeService().getAttributes(btName);
            if(attributeDefs!=null){
               attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList()));
            }
            if(isDefault){
               AttributeDef[] sysAbItems = platformClientUtil.getLinkTypeService().getSysAttributeDefs();
               if(sysAbItems!=null){
                  attributeDefList.addAll(Arrays.stream(sysAbItems).collect(Collectors.toList()));
               }
            }
         }
         attributeVOS=attributeDO2VOs(Arrays.asList(attributeDefs));
         attributeVOS=attributeDO2VOs(attributeDefList);
      }catch (PLException e){
         throw new Exception("根据业务类型获取属性异常"+e.getMessage());
      }