xiejun
2024-09-04 ac3f3629a261770f573f27e5e23f7ec19d096c2a
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java
@@ -7,14 +7,14 @@
import com.vci.client.mw.ClientSessionUtility;
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 +25,10 @@
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.PortalVITypeFlag;
import com.vci.web.properties.UsedNames;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsBaseServiceI;
@@ -135,6 +133,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);
         }
      }
   }
   /**
    * 获取默认的属性
@@ -479,6 +572,10 @@
      );
      //属性英文名称校验(判空、系统中判重、是否关键字、是否合规等)
      checkName(osAttributeDTO.getId());
      //检查属性名是否已存在与系统中
      if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributeDTO.getId())){
         throw new PLException("500",new String[]{"属性名称【" + osAttributeDTO.getId() + "】在系统中已存在!"});
      }
      //检查默认值与属性类型是否匹配
      checkDefValue(osAttributeDTO);
      //osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
@@ -693,9 +790,9 @@
         throw new PLException("500",new String[]{"属性名无效,原因:属性名是数据库关键字!"});
      }
      //检查属性名是否已存在与系统中
      if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
      /*if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
         throw new PLException("500",new String[]{"属性名称【" + abName + "】在系统中已存在!"});
      }
      }*/
   }
   /**
@@ -997,10 +1094,12 @@
   /**
    * 导入属性
    * @param file
    * @param isContinue 系统中出现重复是否跳过报错继续执行
    * @return
    * @throws Exception
    */
   @Override
   public BaseResult importAttributes(File file) throws Exception{
   public BaseResult importAttributes(File file, boolean isContinue) throws Exception{
      VciBaseUtil.alertNotNull(file,"excel文件");
      if(!file.exists()){
         throw new VciBaseException("导入的excel文件不存在,{0}",new String[]{file.getPath()});
@@ -1017,13 +1116,29 @@
         List<OsAttributeDTO> dtoList = new ArrayList<>();
         //当前excel中是否重复用的判重Map:(key:判重属性,value:行号)
         Map<String, String> excelReapeat = new HashMap<>();
         poList.stream().forEach(osAttributePO -> {
         for (int i = 0; i < poList.size(); i++) {
            OsAttributePO osAttributePO = poList.get(i);
            if(Func.isBlank(osAttributePO.getId())){//属性名判空
               throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,attrnameerror");
            }else if(Func.isBlank(osAttributePO.getAttributeDataType())){
               throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,typeerror");
            }else if(excelReapeat.containsKey(osAttributePO.getId())){//属性名表格中判重
               throw new VciBaseException("第【"+excelReapeat.get(osAttributePO.getId())+"】行和第【"+osAttributePO.getRowIndex()+"】行数据,属性名重复");
            }else {
               try {
                  if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributePO.getId())){
                     throw new PLException("500",new String[]{"属性名称【" + osAttributePO.getId() + "】在系统中已存在!"});
                  }
               } catch (PLException e) {
                  e.printStackTrace();
                  String errorMsg = "与系统中属性名查重时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
                  logger.error(errorMsg);
                  //是否跳过当期重复数据
                  if(isContinue){
                     continue;
                  }
                  throw new VciBaseException(errorMsg);
               }
            }
            //属性名校验
            try {
@@ -1076,7 +1191,7 @@
               throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
            }
            dtoList.add(osAttributeDTO);
         });
         }
         //执行保存操作
         dtoList.stream().forEach(dto->{
            try {
@@ -1091,7 +1206,7 @@
         });
      }catch (Exception e){
         if(logger.isErrorEnabled()){
            logger.error("读取excel内容时或保存用户信息时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e));
            logger.error("读取excel内容时或保存属性时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e));
         }
         e.printStackTrace();
         return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
@@ -1114,6 +1229,50 @@
   }
   /**
    * 根据业务类型获取属性信息
    * @param btName 业务类型/链接类型
    * @param typeFlag 0:业务类型,1:链接类型
    * @return
    */
   @Override
   public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag,boolean isDefault) throws Exception{
      VciBaseUtil.alertNotNull(btName,"参数不允许为空",typeFlag,"参数不允许为空");
      List<OsAttributeVO> attributeVOS=new ArrayList<>();
      try {
         List<AttributeDef> attributeDefList=new ArrayList<>();
         if(typeFlag==0){
            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{
            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(attributeDefList);
      }catch (PLException e){
         throw new Exception("根据业务类型获取属性异常"+e.getMessage());
      }
      return attributeVOS;
   }
   /**
    * 是否为参照属性
    * @param other 配置的其他
    * @return true 是参照