ludc
2024-08-06 daf9ff33f0a36c9037af70f574697d80174915f8
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java
@@ -1,27 +1,59 @@
package com.vci.web.service.impl;
import com.vci.client.common.datatype.VTDouble;
import com.vci.client.common.datatype.VTInteger;
import com.vci.client.common.datatype.VTLong;
import com.vci.client.common.datatype.VTString;
import com.vci.client.mw.ClientSessionUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.atm.AttributeDef;
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.po.OsAttributePO;
import com.vci.po.OsEnumPO;
import com.vci.starter.poi.bo.ReadExcelOption;
import com.vci.starter.poi.bo.WriteExcelData;
import com.vci.starter.poi.bo.WriteExcelOption;
import com.vci.starter.poi.constant.ExcelLangCodeConstant;
import com.vci.starter.poi.util.ExcelUtil;
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.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.model.OsAttributeDO;
import com.vci.web.pageModel.OsAttributeVO;
import com.vci.starter.web.util.*;
import com.vci.model.OsAttributeDO;
import com.vci.pagemodel.OsAttributeVO;
import com.vci.web.properties.UsedNames;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsBaseServiceI;
import com.vci.web.service.OsEnumServiceI;
import com.vci.web.service.OsLinkTypeServiceI;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.util.HSSFColor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
//import static com.vci.client.omd.attribpool.ui.VTDataTypePanel.*;
@@ -52,6 +84,47 @@
   @Autowired(required = false)
   @Lazy
   private OsAttributeServiceI self;
   /**
    * 属性名称最大长度
    */
   private Integer NAME_MAX_LENGTH = 28;
   /**
    * 系统中变量配置文件中配置的key
    */
   private final String SYSUSEDNAMES = "sysUsedNames";
   /**
    * 数据库中关键字配置文件中配置的key
    */
   private final String DATABASEUSEDNAMES = "dataBaseUsedNames";
   /**
    * 链接类型服务
    */
   @Autowired(required = false)
   @Lazy
   private OsLinkTypeServiceI osLinkTypeServiceI;
   /**
    * 业务类型服务
    */
   @Autowired(required = false)
   @Lazy
   private OsBtmServiceImpl osBtmService;
   /**
    * 枚举的服务
    */
   @Autowired
   @Lazy
   private OsEnumServiceI  enumService;
   /**
    *  必填列
    */
   private List<Integer> ColumnNameisRed = new ArrayList<Integer>();
   /**
    * 默认的属性
@@ -126,6 +199,22 @@
   }
   /**
    * 根据多个属性名称查询属性
    * @param attrNames
    * @return
    */
   @Override
   public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException {
      VciBaseUtil.alertNotNull(attrNames,"属性名");
      List<OsAttributeVO> osAttributeVOS = new ArrayList<>();
      AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefsByNames(attrNames);
      Arrays.stream(attributeDefs).forEach(attr->{
         osAttributeVOS.add(attributeDO2VO(attr));
      });
      return osAttributeVOS;
   }
   /**
    * 属性的数据对象转换为显示对象
    *
    * @param attribItems 数据对象
@@ -154,8 +243,8 @@
         attributeVO.setId(attribItem.name);
         attributeVO.setCreator(attribItem.creator);
         try {
            attributeVO.setCreateTime(VciDateUtil.str2Date(String.valueOf(attribItem.createTime),VciDateUtil.DateTimeFormat));
            attributeVO.setLastModifyTime(VciDateUtil.str2Date(String.valueOf(attribItem.modifyTime),VciDateUtil.DateTimeFormat));
            attributeVO.setCreateTime(new Date(attribItem.createTime));
            attributeVO.setLastModifyTime(new Date(attribItem.modifyTime));
            attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat));
         }catch (Throwable e){
@@ -166,7 +255,13 @@
         attributeVO.setAttributeDataType(attribItem.vtDataType);
         attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType));
         attributeVO.setDefaultValue(attribItem.defValue);
         attributeVO.setRange(attribItem.rage);
         if(Func.isNotBlank(attribItem.rage)){
            attributeVO.setRange(attribItem.rage.replace("&lt;","<"));
         }else{
            attributeVO.setRange(attribItem.rage);
         }
         attributeVO.setOther(attribItem.other);
         //处理参照相关属性
         if(StringUtils.isNotBlank(attribItem.other)) {
            if (isReferAttr(attribItem.other)) {
               //说明这个的确是参照字段
@@ -176,6 +271,12 @@
                     attributeVO.setBtmTypeId(s.split("=")[1].trim());
                  }
                  //链接类型不支持
                  if (s.toLowerCase().contains("link") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
                     attributeVO.setLinkTypeName(s.split("=")[1].trim());
                  }
                  if (s.toLowerCase().contains("version") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
                     attributeVO.setVersion(WebUtil.getInt(s.split("=")[1].trim()));
                  }
               }
            }
            //必输和长度
@@ -364,6 +465,641 @@
   }
   /**
    * 添加单条属性
    * @param osAttributeDTO
    * @return true成功,false失败
    */
   @Override
   public boolean addAttribute(OsAttributeDTO osAttributeDTO) throws PLException {
      //判空
      VciBaseUtil.alertNotNull(
      osAttributeDTO,"创建的属性对象",
         osAttributeDTO.getId(),"属性名称",
         osAttributeDTO.getAttributeDataType(),"属性类型"
      );
      //属性英文名称校验(判空、系统中判重、是否关键字、是否合规等)
      checkName(osAttributeDTO.getId());
      //检查默认值与属性类型是否匹配
      checkDefValue(osAttributeDTO);
      //osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
      AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
      return platformClientUtil.getAttributeService().addAttributeDef(attributeDef);
   }
   /**
    * 修改单条属性
    * @param osAttributeDTO
    * @return true成功,false失败
    */
   @Override
   public boolean updateAttribute(OsAttributeDTO osAttributeDTO) throws PLException {
      //判空
      VciBaseUtil.alertNotNull(
            osAttributeDTO,"修改的属性对象",
            osAttributeDTO.getId(),"属性名称",
            osAttributeDTO.getTs(),"事务TS",
            osAttributeDTO.getAttributeDataType(),"属性类型"
      );
      //名称不允许修改所以不用查重
      //但是需要检查属性是否存在
      OsAttributeVO osAttributeVO = getByAttributeNames(new String[]{osAttributeDTO.getId()}).get(0);
      if(Func.isEmpty(osAttributeVO) || Func.isBlank(osAttributeVO.getOid())){
         throw new PLException("500",new String[]{"属性在系统中不存在,请刷新后重试!"});
      }
      //检查默认值与属性类型是否匹配
      checkDefValue(osAttributeDTO);
      boolean compatible = isCompatible(osAttributeVO,osAttributeDTO);
      boolean hasInstance = hasInstance(osAttributeDTO.getName());
      //产生数据, 并且不兼容
      if(hasInstance && !compatible){
         throw new PLException("500",new String[]{"无效变更, 不兼容已产生的数据!"});
      }
      String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
      osAttributeDTO.setLastModifier(userId);
      osAttributeDTO.setCreator(osAttributeVO.getCreator());
      osAttributeDTO.setCreateTime(osAttributeVO.getCreateTime());
      osAttributeDTO.setLastModifyTime(new Date());
      try {
         AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
         boolean mdSuccess = platformClientUtil.getAttributeService().modifyAttributeDef(attributeDef);
         if(!mdSuccess){
            return false;
         }
         //属性修改成功,修改业务类型, 链接类型中该属性字段
         boolean alterApBoolean = this.alterAp(attributeDef.name);
         if(!alterApBoolean){
            logger.error("属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!");
            throw new PLException("500",new String[]{"属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!"});
         }
         return true;
      } catch (PLException e1) {
         e1.printStackTrace();
      }
      return false;
   }
   /**
    * DTO对象转实际存储所需的AttributeDef对象
    * @param osAttributeDTO
    * @return
    */
   private AttributeDef osAttributeDTO2AttributeDef(OsAttributeDTO osAttributeDTO) {
      AttributeDef attributeDef = new AttributeDef();
      attributeDef.oid = osAttributeDTO.getOid();
      attributeDef.name = osAttributeDTO.getId().toLowerCase().replaceAll(" ", "");
      attributeDef.label = osAttributeDTO.getName();
      attributeDef.description = osAttributeDTO.getDescription();
      attributeDef.vtDataType = (String)osAttributeDTO.getAttributeDataType();
      attributeDef.defValue = Func.isBlank(osAttributeDTO.getDefaultValue()) ? "" : osAttributeDTO.getDefaultValue();
      if(Func.isBlank(osAttributeDTO.getRange())){
         attributeDef.rage = "";
      }else{
         //特殊字符处理,直接存储<会报错
         attributeDef.rage = osAttributeDTO.getRange().replace("<","&lt;");
      }
      attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat);
      attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator();
      attributeDef.createTime = Func.isEmpty(osAttributeDTO.getCreateTime()) ? System.currentTimeMillis():osAttributeDTO.getCreateTime().getTime();
      attributeDef.modifier = Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier();
      attributeDef.modifyTime = System.currentTimeMillis();
      //other需要自行处理
      StringBuffer sb = new StringBuffer();
      sb.append(ALLOWNULL).append(" = ").append(osAttributeDTO.isNullableFlag() ? "yes" : "no").append(";");
      VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(osAttributeDTO.getAttributeDataType());
      String[] otherInfos = attributeDef.other.split(";");
      int length = 0;
      if(otherInfos!=null&& otherInfos.length > 0){
         for(String s : otherInfos){
            if(s.contains(LENGTH+" =") || s.contains(LENGTH+"=")){
               length = VciBaseUtil.getInt(s.split("=")[1]);
               break;
            }
         }
      }
      switch (fieldTypeEnum) {
         case VTDouble:
            if(osAttributeDTO.getAttrLength() == null){
               osAttributeDTO.setAttrLength(20);
            }
            if(osAttributeDTO.getPrecisionLength() == null){
               osAttributeDTO.setPrecisionLength(2);
            }
            sb.append(ACCURACY).append(" = ").append(osAttributeDTO.getPrecisionLength()).append(";");
            sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
            break;
         case VTInteger:
            if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
               sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";");
            }
            break;
         case VTString:
            if (StringUtils.isNotBlank(osAttributeDTO.getBtmTypeId())) {
               //参照业务类型
               sb.append(BTM).append(" = ").append(osAttributeDTO.getBtmTypeId()).append(";");
            }
            if(StringUtils.isNotBlank(osAttributeDTO.getLinkTypeName())){
               //参照链接类型
               sb.append(LINKTYPENAME).append(" = ").append(osAttributeDTO.getLinkTypeName()).append(";");
               sb.append(VERSION).append(" = ").append(osAttributeDTO.getVersion()).append(";");
            }
            sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
            if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
               sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";");
            }
            break;
         default:
            //不需要处理
            break;
      }
      attributeDef.other = sb.toString();
      if (attributeDef.other.endsWith(";")) {
         attributeDef.other = attributeDef.other.substring(0, attributeDef.other.length() - 1);
      }
      return attributeDef;
   }
   /**
    * 修改属性时, 判断当前输入的属性是否能兼容之前的属性
    * @param osAttributeVO 数据库中存储的
    * @param osAttributeDTO 修改后的内容
    * @return
    */
   private boolean isCompatible(OsAttributeVO osAttributeVO/*数据库中存储的*/,OsAttributeDTO osAttributeDTO/*修改后的内容*/){
      String dataType = osAttributeVO.getAttributeDataType();
      //String other = osAttributeVO.getOther();
      //String newOther = abItem.other == null ? "" : abItem.other;
      String newType = osAttributeDTO.getAttributeDataType();
      if(newType.equals(VTDataType.VTSTRING)){
         if(dataType.equals(VTDataType.VTINTEGER) || dataType.equals(VTDataType.VTLONG)){
            return true;
         }
         if(dataType.equals(VTDataType.VTSTRING)){
            int length = osAttributeVO.getAttrLength();//Integer.valueOf(getOtherValueByType(other, "length"));
            int newLen = osAttributeDTO.getAttrLength();//Integer.valueOf(getOtherValueByType(newOther, "length"));
            if(length <= newLen){
               return true;
            }else{
               return false;
            }
         }
      }
      if(newType.equals(dataType)){
         return true;
      }
      return false;
   }
   /**
    * 判断该属性是否已经在业务类型中, 或者链接类型中产生了数据
    * @param abName
    * @return
    */
   private boolean hasInstance(String abName) throws PLException {
      return osBtmService.hasInstance(abName) && osLinkTypeServiceI.hasInstance(abName);
   }
   /**
    * 检查属性名称是否符合规范
    * @param attributeName
    * @return 没有返回值,存在问题直接抛出错误
    */
   private void checkName(String attributeName) throws PLException {
      if(attributeName.equals("")){
         throw new PLException("500",new String[]{"注意,属性名不能为空!"});
      }
      if(!attributeName.matches("[a-z A-Z]*")){
         throw new PLException("500",new String[]{"注意:属性名只能为英文字母!"});
      }
      int length = attributeName.length();
      if(length > NAME_MAX_LENGTH){
         throw new PLException("500",new String[]{"属性名过长,属性名长度不能超过"+ NAME_MAX_LENGTH});
      }
      String abName = attributeName.toLowerCase();
      //检查属性名是否是为系统基础属性,如createTime,ts,oid等
      if(usedBySystem(abName)){
         throw new PLException("500",new String[]{"属性名无效,原因:属性名已被系统属性使用!"});
      }
      //检查属性名是否是关键字
      if(usedByDataBase(abName)){
         throw new PLException("500",new String[]{"属性名无效,原因:属性名是数据库关键字!"});
      }
      //检查属性名是否已存在与系统中
      if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
         throw new PLException("500",new String[]{"属性名称【" + abName + "】在系统中已存在!"});
      }
   }
   /**
    * 检查默认值与属性类型是否匹配
    * @param osAttributeDTO
    * @return
    */
   private void checkDefValue(OsAttributeDTO osAttributeDTO) throws PLException {
      String defValue = osAttributeDTO.getDefaultValue();
      String vtType = osAttributeDTO.getAttributeDataType();
      String rages = osAttributeDTO.getRange();
      if(defValue != null && !defValue.equals("")){
         if(vtType.equals(VTDataType.VTSTRING)){
            try{
               String.valueOf(defValue);
            }catch(Exception e){
               throw new PLException("500",new String[]{"请输入String类型的默认值!"});
            }
            if(rages == null || rages.equals("")){
               return;
            }
            VTString obj = new VTString(String.valueOf(defValue));
            boolean flag = obj.checkRageValueByRage(rages);
            if(!flag){
               throw new PLException("500",new String[]{"默认值与值域冲突!"});
            }
         }else if(vtType.equals(VTDataType.VTINTEGER)){
            try{
               Integer.valueOf(defValue);
            }catch(Exception e){
               throw new PLException("500",new String[]{"请输入Integer类型的默认值!"});
            }
            if(rages == null || rages.equals("")){
               return;
            }
            VTInteger obj = new VTInteger(Integer.valueOf(defValue));
            boolean flag = obj.checkRageValueByRage(rages);
            if(!flag){
               throw new PLException("500",new String[]{"默认值与值域冲突!"});
            }
         }else if(vtType.equals(VTDataType.VTLONG)){
            try{
               Long.valueOf(defValue);
            }catch(Exception e){
               throw new PLException("500",new String[]{"请输入Long类型的默认值!"});
            }
            if(rages == null || rages.equals("")){
               return;
            }
            VTLong obj = new VTLong(Long.valueOf(defValue));
            boolean flag = obj.checkRageValueByRage(rages);
            if(!flag){
               throw new PLException("500",new String[]{"默认值与值域冲突!"});
            }
         }else if(vtType.equals(VTDataType.VTDOUBLE)){
            try{
               Double.valueOf(defValue);
            }catch(Exception e){
               throw new PLException("500",new String[]{"请输入Double类型的默认值!"});
            }
            if(rages == null || rages.equals("")){
               return;
            }
            VTDouble obj = new VTDouble(Double.valueOf(defValue));
            boolean flag = obj.checkRageValueByRage(rages);
            if(!flag){
               throw new PLException("500",new String[]{"默认值与值域冲突!"});
            }
         }
      }
   }
   /**
    * 检查该属性名是否被系统属性使用
    * @param abName
    * @return
    */
   private boolean usedBySystem(String abName) {
      boolean flag = false;
      String[] names = UsedNames.getProperty(SYSUSEDNAMES).toUpperCase().split(",");
      List<String> nameList = Arrays.asList(names);
      if(nameList.contains(abName.toUpperCase())){
         flag = true;
      }
      return flag;
   }
   /**
    * 检查该属性名是否属于数据库关键字
    * @param abName
    * @return
    */
   private boolean usedByDataBase(String abName){
      boolean flag = false;
      String[] names = UsedNames.getProperty(DATABASEUSEDNAMES).toUpperCase().split(",");
      List<String> nameList = Arrays.asList(names);
      if(nameList.contains(abName.toUpperCase())){
         flag = true;
      }
      return flag;
   }
   /**
    * 删除属性
    * @param osAttributeDTOS
    * @return true成功,false失败
    */
   @Override
   public boolean deleteAttributes(List<OsAttributeDTO> osAttributeDTOS) throws PLException {
      VciBaseUtil.alertNotNull(osAttributeDTOS,"待删除的属性列表");
      //平台的deleteEnumTypes方法必传三个参数,oid、name和ts
      List<AttributeDef> attributeDefs = new ArrayList<>();
      for(OsAttributeDTO osAttributeDTO : osAttributeDTOS){
         //oid和ts判空
         String oid = osAttributeDTO.getOid();
         //name主要用来对缓存数据删除
         String name = osAttributeDTO.getName();
         Date ts = osAttributeDTO.getTs();
         if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){
            throw new PLException("500",new String[]{"待删除的属性列表中主键【oid】、调整时间【ts】、属性名【name】不能为空!"});
         }
         //判断属性是否有被引用
         List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name);
         if(Func.isNotEmpty(usedAttrList)){
            throw new PLException("500",new String[]{"删除的属性中,属性名称为:【" + name + "】,已被引用!"});
         }
         AttributeDef attributeDef = new AttributeDef();
         attributeDef.oid = oid;
         attributeDef.name = name;
         attributeDef.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat);
         attributeDefs.add(attributeDef);
      }
      if(Func.isEmpty(attributeDefs)){
         return false;
      }
      return platformClientUtil.getAttributeService().deleteAttributeDefs(attributeDefs.toArray(new AttributeDef[attributeDefs.size()]));
   }
   /**
    * 查看属性的使用范围
    * @param attributeName
    * @return key:属性 ,value使用该属性的业务类型
    */
   @Override
   public List<Map<String, String>> getUsedAttributeList(String attributeName) throws PLException {
      if(Func.isBlank(attributeName)){
         throw new PLException("500",new String[]{"请选择要查询应用范围的属性!"});
      }
      String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName);
      if(Func.isEmpty(btNames)){
         return new ArrayList<>();
      }
      List<Map<String,String>> btmNameMapList = new ArrayList<>();
      Arrays.stream(btNames).forEach(btName->{
         Map<String, String> itemMap = new HashMap<>();
         itemMap.put("attributeName",attributeName);
         itemMap.put("source",btName);
         btmNameMapList.add(itemMap);
      });
      return btmNameMapList;
   }
   /**
    * 导出选中的属性
    * @param exportFileName 导出的文件名
    * @param attrNames 需要导出的属性名称
    * @param flag 控制导出的列名是否和导入模板一致
    * @return
    */
   @Override
   public String exportAttributes(String exportFileName, String attrNames,boolean flag/*控制导出的列名是否和导入模板一致*/) throws PLException {
      if(Func.isBlank(attrNames)){
         throw new PLException("500",new String[]{"请勾选要导出的属性!"});
      }
      //界面没传名称,使用默认导出名称
      exportFileName = Func.isBlank(exportFileName) ?  "属性池中属性导出_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
      //设置列名
      List<String> columns = this.getCloumns(flag);
      //写excel
      String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName +  ".xls";
      try {
         new File(excelPath).createNewFile();
      } catch (Throwable e) {
         throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
      }
      //设置列
      List<WriteExcelData> excelDataList = new ArrayList<>();
      //设置列头
      for (int index = 0; index < columns.size(); index++) {
         excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
      }
      //按照属性名查询属性,然后处理属性导出
      List<String> attrameList = Func.toStrList(attrNames);
      List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(attrameList);
      if(Func.isEmpty(osAttributeVOS)){
         excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!"));
      }else{
         //先按照属性类型排序,不同属性类型导出的数据乱的效果
         osAttributeVOS.sort(Comparator.comparing(OsAttributeVO::getAttributeDataType));
         for (int i = 0; i < osAttributeVOS.size(); i++) {
            OsAttributeVO osAttributeVO = osAttributeVOS.get(i);
            excelDataList.add(new WriteExcelData(i+1,0, osAttributeVO.getId()));
            excelDataList.add(new WriteExcelData(i+1,1, osAttributeVO.getName()));
            excelDataList.add(new WriteExcelData(i+1,2, osAttributeVO.getDescription()));
            if(flag){
               excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()));
            }else{
               excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()+"("+osAttributeVO.getAttributeDataTypeText()+")"));
            }
            excelDataList.add(new WriteExcelData(i+1,4, osAttributeVO.isNullableFlag()));
            excelDataList.add(new WriteExcelData(i+1,5, osAttributeVO.getDefaultValue()));
            excelDataList.add(new WriteExcelData(i+1,6, osAttributeVO.getEnumId()));
            //excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName()));
            excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getBtmTypeId()));
            //excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName()));
            excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getAttrLength()));
            excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getLinkTypeName()));
            excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getVersion()));
            excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getPrecisionLength()));
            excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength()));
            excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange()));
            if(!flag){
               excelDataList.add(new WriteExcelData(i+1,14, Func.format(osAttributeVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss")));
            }
         }
      }
      WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
      ExcelUtil.writeDataToFile(excelPath, excelOption);
      return excelPath;
   }
   /**
    * 获取导出或导入模板的列名
    * @param flag 是否获取导入模板列名
    * @return
    */
   private List<String> getCloumns(boolean flag){
      if(flag){
         return new ArrayList<>(
               Arrays.asList("属性名", "标签", "描述",
                     "属性类型(参照新增界面的属性类型如VTString)", "允许为空(是/否)", "默认值", "使用的枚举英文名称"
                     , "参照的业务类型编号","参照的链接类型编号","版本版次","属性长度", "小数精度位数","小数刻度位数"
                     ,"取值范围"
               )
         );
      }
      return new ArrayList<>(
            Arrays.asList("属性名", "标签", "描述",
                  "属性类型", "允许为空", "默认值", "使用的枚举英文名称(枚举名)",
                  "参照的业务类型编号", "参照的链接类型编号","版本版次","属性长度",
                  "小数精度位数","小数刻度位数","取值范围","创建时间")
      );
   }
   /**
    * 下载属性导入模板
    * @param exportFileName
    * @return
    * @throws PLException
    */
   @Override
   public String downloadAttributeTemplate(String exportFileName) throws Exception {
      //界面没传名称,使用默认导出名称
      exportFileName = Func.isBlank(exportFileName) ?  "属性池导入模板_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
      //设置列名
      List<String> columns = this.getCloumns(true);
      //设置必填列
      ColumnNameisRed.clear();
      ColumnNameisRed.add(0);
      ColumnNameisRed.add(3);
      ColumnNameisRed.add(10);
      //写excel
      String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName +  ".xls";
      try {
         new File(excelPath).createNewFile();
      } catch (Throwable e) {
         throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
      }
      //设置列
      List<WriteExcelData> excelDataList = new ArrayList<>();
      //设置列头
      for (int index = 0; index < columns.size(); index++) {
         //判断是否为必填列,给必填列设置颜色
         if(ColumnNameisRed.contains(index)){
            WriteExcelData excelData = new WriteExcelData(0, index, columns.get(index));
            excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex()));
            excelDataList.add(excelData);
         }else{
            excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
         }
      }
      WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
      ExcelUtil.writeDataToFile(excelPath, excelOption);
      return excelPath;
   }
   /**
    * 导入属性
    * @param file
    * @return
    */
   @Override
   public BaseResult importAttributes(File file) throws Exception{
      VciBaseUtil.alertNotNull(file,"excel文件");
      if(!file.exists()){
         throw new VciBaseException("导入的excel文件不存在,{0}",new String[]{file.getPath()});
      }
      try{
         //1、读取excel中的数据,组成对象
         ReadExcelOption excelOption = new ReadExcelOption();
         List<OsAttributePO> poList = ExcelUtil.readDataObjectFromExcel(file, OsAttributePO.class,excelOption,(value, po, fieldName)->{});
         //去除都是空的情况
         if(CollectionUtils.isEmpty(poList)){
            return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{});
         }
         //excel判重,数据校验,dto对象转换,存储对象转换,执行保存
         List<OsAttributeDTO> dtoList = new ArrayList<>();
         //当前excel中是否重复用的判重Map:(key:判重属性,value:行号)
         Map<String, String> excelReapeat = new HashMap<>();
         poList.stream().forEach(osAttributePO -> {
            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()+"】行数据,属性名重复");
            }
            //属性名校验
            try {
               checkName(osAttributePO.getId());
            } catch (PLException e) {
               e.printStackTrace();
               throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
            }
            //属性名excel中判重处理
            excelReapeat.put(osAttributePO.getId(),osAttributePO.getRowIndex());
            OsAttributeDTO osAttributeDTO = new OsAttributeDTO();
            //查询属性是否存在,填写了枚举但没填写取值范围,这时候直接使用枚举项值作为默认的range
            if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){
               try {
                  OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId());
                  if(Func.isEmpty(enumVO)){
                     throw new VciBaseException("第【" + osAttributePO.getRowIndex() + "】行数据,通过枚举名称【" + osAttributePO.getEnumId()
                           + "】未获取到枚举信息!");
                  }
                  String itemValues = enumVO.getItemMaps().values().stream().collect(Collectors.joining(";"));
                  osAttributeDTO.setRange(itemValues);
               } catch (PLException e) {
                  e.printStackTrace();
                  throw new VciBaseException("枚举查询失败,原因:"+e.getMessage());
               }
               osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId());
            }
            osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
            osAttributeDTO.setId(osAttributePO.getId());
            osAttributeDTO.setName(osAttributePO.getName());
            osAttributeDTO.setDescription(osAttributePO.getDescription());
            osAttributeDTO.setDefaultValue(osAttributePO.getDefaultValue());
            osAttributeDTO.setAttrLength(osAttributePO.getAttrLength());
            osAttributeDTO.setAttributeDataType(osAttributePO.getAttributeDataType());
            osAttributeDTO.setBtmTypeId(osAttributePO.getBtmTypeId());
            //osAttributeDTO.setBtmTypeName(osAttributePO.getBtmname());
            osAttributeDTO.setLinkTypeName(osAttributePO.getLinkTypeName());
            osAttributeDTO.setVersion(osAttributePO.getVersion());
            osAttributeDTO.setEnumId(osAttributePO.getEnumId());
            //osAttributeDTO.setEnumName(osAttributePO.getEnumId());
            osAttributeDTO.setPrecisionLength(osAttributePO.getPrecisionLength());
            osAttributeDTO.setScaleLength(osAttributePO.getScaleLength());
            osAttributeDTO.setRange(osAttributePO.getRange());
            osAttributeDTO.setNullableFlag("是".equals(osAttributePO.getNullableFlag()) ? true:false);
            try {
               //检查默认值与属性类型是否匹配
               checkDefValue(osAttributeDTO);
            } catch (PLException e) {
               e.printStackTrace();
               throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
            }
            dtoList.add(osAttributeDTO);
         });
         //执行保存操作
         dtoList.stream().forEach(dto->{
            try {
               boolean b = platformClientUtil.getAttributeService().addAttributeDef(osAttributeDTO2AttributeDef(dto));
               if(!b){
                  throw new VciBaseException("save and return false");
               }
            } catch (PLException e) {
               e.printStackTrace();
               throw new VciBaseException("执行保存时出现错误,错误属性对象名为:【" + dto.getId() + "】,原因:"+VciBaseUtil.getExceptionMessage(e));
            }
         });
      }catch (Exception e){
         if(logger.isErrorEnabled()){
            logger.error("读取excel内容时或保存属性时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e));
         }
         e.printStackTrace();
         return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
      }
      return BaseResult.success("属性导入成功!");
   }
   /**
    * 是否默认的属性
    *
    * @param attr 属性编号
@@ -384,18 +1120,17 @@
    */
   private boolean isReferAttr(String other){
      if(StringUtils.isNotBlank(other)
            && (other.toLowerCase().contains("btm") || other.toLowerCase().contains("ltm"))){
            && (other.toLowerCase().contains("btm") || other.toLowerCase().contains("link"))){
         //还不能确定,因为枚举的时候也会设置btm
         String[] temp = other.split(";");
         for(String s : temp){
            if((s.contains("btm") || s.contains("ltm")) && s.split("=").length>1){
            if((s.contains("btm") || s.contains("link")) && s.split("=").length>1){
               return true;
            }
         }
      }
      return false;
   }
   /**
    * 是否为枚举的属性
@@ -416,7 +1151,6 @@
      return false;
   }
   /**
    * 清除缓存
    */
@@ -424,4 +1158,15 @@
   public void clearCache() {
   }
   /**
    * 调用修改业务类型和连接类型中对应属性名的属性
    * @param apName
    * @return
    * @throws PLException
    */
   private boolean alterAp(String apName) throws PLException {
      return osBtmService.alterAp(apName) && osLinkTypeServiceI.alterAp(apName);
   }
}