lihang
2023-05-04 3579af2945dd38d841a23cd340acd474bb63773a
Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java
@@ -4,22 +4,27 @@
import com.alibaba.nacos.api.exception.NacosException;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.omd.constant.BtmTypeConstant;
import com.vci.ubcs.omd.constant.BtmTypeFieldConstant;
import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO;
import com.vci.ubcs.omd.repeater.DomainRepeater;
import com.vci.ubcs.omd.service.IBtmTypeAttributeService;
import com.vci.ubcs.omd.service.IModifyAttributeService;
import com.vci.ubcs.omd.wrapper.BtmTypeAttributeWrapper;
import com.vci.ubcs.omd.wrapper.BtmTypeWrapper;
import com.vci.ubcs.omd.wrapper.ModifyAttributeWrapper;
import com.vci.ubcs.starter.web.constant.OmdRegExpConstant;
import com.vci.ubcs.omd.dto.BtmTypeDTO;
import com.vci.ubcs.omd.dto.BtmTypeLinkAttributesDTO;
import com.vci.ubcs.omd.entity.BtmType;
import com.vci.ubcs.omd.entity.BtmTypeAttribute;
import com.vci.ubcs.omd.entity.ModifyAttributeInfoDO;
import com.vci.ubcs.omd.entity.ModifyAttributeInfo;
import com.vci.ubcs.omd.mapper.BtmTypeMapper;
import com.vci.ubcs.omd.service.IBtmTypeService;
import com.vci.ubcs.omd.vo.BtmTypeVO;
import com.vci.ubcs.omd.vo.BtmTypeAttributeVO;
import com.vci.ubcs.omd.vo.LinkTypeVO;
import com.vci.ubcs.starter.exception.VciBaseException;
import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import com.vci.ubcs.starter.web.util.VciDateUtil;
import org.springblade.core.log.exception.ServiceException;
@@ -27,6 +32,7 @@
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
@@ -37,6 +43,7 @@
import javax.validation.constraints.NotEmpty;
import java.util.*;
import java.util.stream.Collectors;
/**
 * Description: 业务类型服务的实现类
@@ -58,6 +65,17 @@
    */
   @Autowired
   private IBtmTypeAttributeService btmTypeAttributeService;
   /**
    * 字段修改信息的服务
    */
   @Autowired
   private IModifyAttributeService modifyAttributeService;
   /**
    * 表名前缀
    */
   public static final String PL = "PL";
   /**
    * 设置平台本身的业务类型
@@ -93,7 +111,10 @@
    */
   @Override
   public List<BtmTypeVO> listBtmTypeByOids(String pkBtmTypes) throws ServiceException {
      return null;
      VciBaseUtil.alertNotNull(pkBtmTypes, "业务类型的主键");
      List<String> pkList = new ArrayList<>();
      Collections.addAll(pkList, pkBtmTypes.split(","));
      return listBtmTypeByOidCollection(pkList);
   }
   /**
@@ -105,6 +126,12 @@
    */
   @Override
   public List<BtmTypeVO> listBtmTypeByOidCollection(Collection<String> pkBtmTypeCollection) throws ServiceException {
      if (!CollectionUtils.isEmpty(pkBtmTypeCollection)) {
         List<BtmType> btmTypeDOList = listBtmTypeDOByOidCollection(pkBtmTypeCollection);
         if (!CollectionUtils.isEmpty(btmTypeDOList)) {
            return BtmTypeWrapper.build().listEntityVO(btmTypeDOList);
         }
      }
      return null;
   }
@@ -117,6 +144,11 @@
    */
   @Override
   public BtmTypeVO getBtmTypeById(String id) throws ServiceException {
      VciBaseUtil.alertNotNull(id, "业务类型的英文名称");
      List<BtmTypeVO> btmTypeVOList = listBtmTypeByIds(id);
      if (!CollectionUtils.isEmpty(btmTypeVOList)) {
         return btmTypeVOList.get(0);
      }
      return null;
   }
@@ -129,7 +161,8 @@
    */
   @Override
   public List<BtmTypeVO> listBtmTypeByIds(String ids) throws ServiceException {
      return null;
      Func.requireNotNull(ids,"英文名称不能为空");
      return listBtmTypeByIdCollection(Func.toStrList(",",ids));
   }
   /**
@@ -141,7 +174,7 @@
    */
   @Override
   public List<BtmTypeVO> listBtmTypeByIdCollection(Collection<String> idCollection) throws ServiceException {
      return null;
      return CollectionUtils.isEmpty(idCollection) ?  null : BtmTypeWrapper.build().listEntityVO(baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId,idCollection)));
   }
   /**
@@ -153,7 +186,7 @@
    */
   @Override
   public List<BtmType> listBtmTypeDOByIdCollection(Collection<String> idCollection) throws ServiceException {
      return null;
      return CollectionUtils.isEmpty(idCollection) ? null : baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId, idCollection));
   }
   /**
@@ -165,6 +198,9 @@
    */
   @Override
   public List<BtmType> listBtmTypeDOByOidCollection(Collection<String> oidCollection) throws ServiceException {
      if (!CollectionUtils.isEmpty(oidCollection)) {
         return baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getOid, oidCollection));
      }
      return null;
   }
@@ -177,7 +213,7 @@
    */
   @Override
   public String getNameByOid(String oid) throws ServiceException {
      return null;
      return Objects.requireNonNull(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid,oid))).getName();
   }
   /**
@@ -189,7 +225,7 @@
    */
   @Override
   public String getNameById(String id) throws ServiceException {
      return null;
      return Objects.requireNonNull(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getId,id))).getName();
   }
   /**
@@ -213,6 +249,16 @@
    */
   @Override
   public List<BtmTypeAttributeVO> listHasAttributeById(String id) throws ServiceException {
      VciBaseUtil.alertNotNull(id,"业务类型英文名称");
      List<String> ids = Func.toStrList(",", id);
      Map<String, List<BtmTypeAttributeVO>> attributeMap = batchListHasAttributesByIdCollection(ids);
      if (!CollectionUtils.isEmpty(attributeMap)) {
         List<BtmTypeAttributeVO> attributeVOList = new ArrayList<>();
         attributeMap.forEach((k, v) -> {
            attributeVOList.addAll(v);
         });
         return attributeVOList;
      }
      return null;
   }
@@ -225,7 +271,7 @@
    */
   @Override
   public Map<String, List<BtmTypeAttributeVO>> batchListHasAttributesByOidCollection(Collection<String> oidCollection) throws ServiceException {
      return null;
      return btmTypeAttributeService.batchListHasAttributesByBtmTypeOidCollection(oidCollection).stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType));
   }
   /**
@@ -237,7 +283,8 @@
    */
   @Override
   public Map<String, List<BtmTypeAttributeVO>> batchListHasAttributesByIdCollection(Collection<String> idCollection) throws ServiceException {
      return null;
      List<String> btmTypeOidList = baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId, idCollection)).stream().map(BtmType::getOid).collect(Collectors.toList());
      return btmTypeAttributeService.batchListHasAttributesByBtmTypeOidCollection(btmTypeOidList).stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType));
   }
   /**
@@ -261,7 +308,8 @@
    */
   @Override
   public boolean checkBtmTypeUsed(String pkBtmType) throws ServiceException {
      return false;
      VciBaseUtil.alertNotNull(pkBtmType, "业务类型主键");
      return checkBtmTypeUseds(VciBaseUtil.str2List(pkBtmType));
   }
   /**
@@ -273,113 +321,40 @@
    */
   @Override
   public boolean checkBtmTypeUseds(Collection<String> oidCollection) throws ServiceException {
      VciBaseUtil.alertCollectionNotNull("校验是否引用的业务类型对象的主键", oidCollection);
      //检查链接类型
      //因为链接类型中fromBtmType和toBtmType都是逗号分隔的,所以直接查询所有的链接类型中的使用的业务类型名称
      List<BtmType> btmTypeDOList = listBtmTypeDOByOidCollection(oidCollection);
      if (CollectionUtils.isEmpty(btmTypeDOList)) {
         return false;
      }
      /*Set<String> usedBtmTypeSet = linkTypeServiceI.listUsedBtmType();
      if (btmTypeDOList.stream().anyMatch(s -> usedBtmTypeSet.contains(s.getId().trim().toLowerCase()))) {
         return true;
      }*/
      return false;
   }
   /**
    * 添加业务类型
    *
    * @param btmTypeDTO      业务类型数据传输对象
    * @param autoCreateTable 是否自动创建表格
    * @return 添加后的业务类型
    * @throws ServiceException 添加出错的时候会抛出异常
    * 添加默认的字段
    * @param attributes 字段集
    * @param fieldMap 默认字段集
    * @return 添加后的字段集
    */
   @Override
   public BtmTypeDTO addSave(BtmTypeDTO btmTypeDTO, boolean autoCreateTable) throws ServiceException {
      TransactionStatus transaction = null;
      DefaultTransactionDefinition def = null;
      if (autoCreateTable) {
         def = new DefaultTransactionDefinition();
         def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
         // 事物隔离级别,开启新事务,这样会比较安全些。
         transaction = dataSourceTransactionManager.getTransaction(def);
         // 获得事务状态
      }
      BtmType btmTypeDO = new BtmType();
      try {
         VciBaseUtil.alertNotNull(btmTypeDTO, "要添加的业务类型", btmTypeDTO.getId(), "业务类型的英文名称", btmTypeDTO.getName(), "业务类型中文名称");
         if (btmTypeDTO.isViewFlag() && (StringUtils.isBlank(btmTypeDTO.getViewCreateSql())
            || StringUtils.isBlank(btmTypeDTO.getTableName()))) {
            throw new VciBaseException("如果当前是业务类型是视图的时候,请必须输入视图的创建语句和视图名称");
   private List<BtmTypeLinkAttributesDTO> addAttributeByFieldMap(List<BtmTypeLinkAttributesDTO> attributes, Map<String, String> fieldMap) {
      Map<String, BtmTypeLinkAttributesDTO> existFieldMap = attributes.stream().collect(Collectors.toMap(BtmTypeLinkAttributesDTO::getId, t -> t, (o1, o2) -> o1));
      fieldMap.forEach((k,v) -> {
         if (!existFieldMap.containsKey(k)){
            BtmTypeLinkAttributesDTO attr = new BtmTypeLinkAttributesDTO();
            attr.setId(k);
            attr.setAttrDataType(VciFieldTypeEnum.VTString.name());
            attr.setAttributeLength(50);
            attr.setNullableFlag(false);
            attr.setDescription(v);
            attributes.add(attr);
         }
         if (!btmTypeDTO.isViewFlag()) {
            VciBaseUtil.alertCollectionNotNull("属性", btmTypeDTO.getAttributesDTOList());
         }
         if (!btmTypeDTO.getId().matches(OmdRegExpConstant.LETTER)) {
            throw new VciBaseException("业务类型英文名称只能是纯英文,目前为{0}", new Object[]{btmTypeDTO.getId()});
         }
         if (btmTypeDTO.getId().length() > 24) {
            throw new VciBaseException("业务类型英文名称不能超过18,目前长度为{0}", new Object[]{btmTypeDTO.getId().length()});
         }
         List<BtmType> btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId()));
         if (!CollectionUtils.isEmpty(btmTypeDOList) && btmTypeDOList.size() > 0) {
            BtmType existBtmType = btmTypeDOList.get(0);
            throw new VciBaseException("业务类型英文名称已经存在(不区分大小写),这个英文名称对应的中文名称为{0},创建人{1},创建时间{2}"
               , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)});
         }
         /*
         //检查使用的版本规则是否存在
         if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) {
            if (revisionRuleServiceI.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) {
               throw new VciBaseException("版本规则{0}[{1}]在系统中不存在,请先查证",
                  new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()});
            }
         }
         //检查使用的生命周期是否存在
         if (StringUtils.isNotBlank(btmTypeDTO.getLifeCycleId())
            && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId())) {
            if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getLifeCycleId())) {
               throw new VciBaseException("生命周期{0}[{1}]在系统中不存在,请先查证",
                  new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()});
            }
         }
         if (StringUtils.isNotBlank(btmTypeDTO.getSubLifeCycleId())) {
            if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getSubLifeCycleId())) {
               throw new VciBaseException("备用生命周期{0}[{1}]中其中有某些在系统中不存在,请先查证",
                  new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()});
            }
         }
         */
         if (StringUtils.isBlank(btmTypeDTO.getOid())) {
            btmTypeDTO.setOid(VciBaseUtil.getPk());
         }
         BeanUtil.copy(btmTypeDTO, btmTypeDO);
         String creator = AuthUtil.getUserAccount();
         Date now = new Date();
         btmTypeDO.setCreator(creator);
         btmTypeDO.setCreateTime(now);
         btmTypeDO.setOwner(creator);
         btmTypeDO.setBtmname(BtmTypeConstant.OMD_BTMTYPE);
         btmTypeDO.setTs(now);
         if (StringUtils.isBlank(btmTypeDO.getTableName())) {
            btmTypeDO.setTableName(getTableName(btmTypeDO.getId()));
         }
         //处理属性
         addAttributeForBtm(btmTypeDTO, creator, now);
         baseMapper.insert(btmTypeDO);
         if (autoCreateTable) {
            dataSourceTransactionManager.commit(transaction);
         }
      } catch (ServiceException e) {
         if (autoCreateTable) {
            dataSourceTransactionManager.rollback(transaction);
         }
         throw e;
      } catch (Throwable e) {
         if (autoCreateTable) {
            dataSourceTransactionManager.rollback(transaction);
         }
         throw e;
      }
      if (autoCreateTable) {
         BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(btmTypeDO);
         btmTypeVO.setAttributes(listHasAttributesByOid(btmTypeDO.getOid()));
         checkTableSame(btmTypeVO);
      }
      return btmTypeDTO;
      });
      return attributes;
   }
   /**
@@ -388,43 +363,44 @@
    * @param btmTypeVO 业务类型的显示对象
    */
   private void checkTableSame(BtmTypeVO btmTypeVO) {
      /*List<OmdBtmTypeVO> btmTypeVOList = new ArrayList<>();
      List<BtmTypeVO> btmTypeVOList = new ArrayList<>();
      btmTypeVOList.add(btmTypeVO);
      List<OsModifyAttributeInfoDO> modifyAttributeInfoDOList = ddlServiceI.checkDifferent(btmTypeVOList, null);
      BtmAndLinkTypeDdlDTO ddlDTO = new BtmAndLinkTypeDdlDTO();
      ddlDTO.setBtmTypeList(btmTypeVOList);
      try {
         modifyAttributeServiceI.batchAddSave(modifyAttributeInfoDOList);
      } catch (Throwable e) {
         if (logger.isErrorEnabled()) {
            logger.error("保存【修改属性】数据", e);
         // 将以前的checkDifferent和reflexDifferent结合了
         R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getDomain());
         if (result.isSuccess()){
            List<ModifyAttributeInfo> infoList = new ArrayList<>();
            Object data = result.getData();
            if (data instanceof List){
               List dataList = (List) data;
               dataList.forEach(s -> {
                  if (s instanceof ModifyAttributeInfo){
                     ModifyAttributeInfo info = (ModifyAttributeInfo) s;
                     infoList.add(info);
                  }
               });
               modifyAttributeService.saveBatch(ModifyAttributeWrapper.build().listEntityBeforeSave(infoList));
            }
         }
      } catch (NacosException e) {
         if (log.isDebugEnabled()) {
            log.error("保存【修改属性】数据", e);
         }
         throw new RuntimeException(e);
      }
      ddlServiceI.reflexDifferent(modifyAttributeInfoDOList);
      modifyAttributeServiceI.finishModify(modifyAttributeInfoDOList);*/
//      modifyAttributeServiceI.finishModify(modifyAttributeInfoList);
   }
   /**
    * 添加属性到业务类型中
    *
    * @param btmTypeDTO 业务类型的数据传输对象
    * @param creator    创建人
    * @param now        当前时间
    */
   private void addAttributeForBtm(BtmTypeDTO btmTypeDTO, String creator, Date now) throws VciBaseException{
      List<BtmTypeLinkAttributesDTO> attributesDTOList = btmTypeDTO.getAttributesDTOList();
      btmTypeAttributeService.checkAndInsert(btmTypeDTO.getOid(),attributesDTOList,creator,now);
   }
   /**
    * 修改业务类型
    *
    * @param btmTypeDTO    业务类型数据传输对象
    * @param autoEditTable 是否自动更新表格
    * @return 修改后的业务类型
    * @throws ServiceException 修改出错的时候会抛出异常
    */
   @Override
   public BtmTypeDTO editSave(BtmTypeDTO btmTypeDTO, boolean autoEditTable) throws ServiceException {
      return null;
   private List<BtmTypeAttributeVO> addAttributeForBtm(BtmTypeDTO btmTypeDTO) throws VciBaseException{
      List<BtmTypeLinkAttributesDTO> attributesDTOList = btmTypeDTO.getAttributes();
      return btmTypeAttributeService.checkAndInsert(btmTypeDTO.getOid(),attributesDTOList,AuthUtil.getUserAccount(),new Date());
   }
   /**
@@ -459,7 +435,7 @@
    * @throws ServiceException 参数为空或者查询出错时会抛出异常
    */
   @Override
   public List<ModifyAttributeInfoDO> checkDbTableSame(String pkBtmType) throws ServiceException {
   public List<ModifyAttributeInfo> checkDbTableSame(String pkBtmType) throws ServiceException {
      return null;
   }
@@ -471,102 +447,14 @@
    * @throws ServiceException 参数为空的时候会抛出异常
    */
   @Override
   public String getTableName(String id) throws ServiceException {
      return null;
   }
   /**
    * 将业务类型使用的属性的传输对象转换为数据对象
    *
    * @param attributesDTO 属性的数据传输对象
    * @param pkBtmType     业务类型的主键
    * @param creator       创建人
    * @param now           当前时间
    * @return 属性的数据对象
    */
   @Override
   public BtmTypeAttribute btmTypeAttributeDTO2DO(BtmTypeLinkAttributesDTO attributesDTO, String pkBtmType, String creator, Date now) {
      return null;
   }
   /**
    * 业务类型的属性显示对象转换为数据对象
    *
    * @param thisBtmTypeHasAttributeVOList 业务类型属性显示对象
    * @return 数据对象
    */
   @Override
   public List<BtmTypeAttribute> btmTypeAttributeVO2DO(List<BtmTypeAttributeVO> thisBtmTypeHasAttributeVOList) {
      return null;
   }
   /**
    * 批量将业务类型的数据对象转换为显示对象
    *
    * @param attributeDOList 属性的数据对象列表
    * @return 属性的显示对象列表
    */
   @Override
   public List<BtmTypeAttributeVO> batchBtmTypeAttributeDO2VO(List<BtmTypeAttribute> attributeDOList) {
      return null;
   }
   /**
    * 批量将业务类型的数据对象转换为显示对象
    *
    * @param attributesDO 属性的数据对象
    * @return 属性的显示对象列表
    */
   @Override
   public BtmTypeAttributeVO btmTypeAttributeDO2VO(BtmTypeAttribute attributesDO) {
      return null;
   }
   /**
    * 获取业务类型的指定属性
    *
    * @param id                    链接类型的英文名称
    * @param attributeIdCollection 属性的集合,如果为空则获取全部
    * @return 属性的显示对象
    */
   @Override
   public List<BtmTypeAttribute> listAttributeDOByIdsForBtm(String id, Collection<String> attributeIdCollection) {
      return null;
   }
   /**
    * 根据业务类型的编号获取属性
    *
    * @param id 业务类型的编号
    * @return 属性的显示对象
    */
   @Override
   public List<BtmTypeAttributeVO> listAttributeByBtmTypeId(String id) {
      return null;
   }
   /**
    * 根据业务类型的主键获取属性
    *
    * @param oid 业务类型的主键
    * @return 属性的显示对象
    */
   @Override
   public List<BtmTypeAttributeVO> listAttributeByBtmTypeOid(String oid) {
      return null;
   }
   /**
    * 批量根据业务类型编号或者主键获取包含的属性
    *
    * @param oidsOrIds 主键或者编号集合
    * @param queryById 是否使用编号查询
    * @return key是业务类型的主键或者编号,值是包含的属性的信息
    * @throws ServiceException 参数为空或者查询出错会抛出异常
    */
   @Override
   public List<BtmTypeAttributeVO> batchListAttributeByBtmType(Collection<String> oidsOrIds, boolean queryById) throws ServiceException {
      return null;
   public String getTableName(String id,String domain) throws ServiceException {
      VciBaseUtil.alertNotNull(id,"业务类型英文名称",domain,"领域名称");
      if (domain.contains("ubcs-")){
         domain = domain.split("ubcs-")[1];
      }else {
         throw new VciBaseException("领域名称不符合规则");
      }
      return PL + StringPool.UNDERSCORE + domain + StringPool.UNDERSCORE + id;
   }
   /**
@@ -576,16 +464,154 @@
    * @return 执行结果
    */
   @Override
   public boolean submit(BtmTypeDTO btmTypeDTO) {
      addSave(btmTypeDTO,false);
      try {
         R result = DomainRepeater.submitBtmType(btmTypeDTO.getDomain(), Objects.requireNonNull(BeanUtil.copy(btmTypeDTO, BtmTypeVO.class)));
         return result.isSuccess();
      } catch (NacosException e) {
         throw new RuntimeException(e);
   public R submit(BtmTypeDTO btmTypeDTO, boolean autoCreateTable) {
      TransactionStatus transaction = null;
      DefaultTransactionDefinition def = null;
      if (autoCreateTable) {
         def = new DefaultTransactionDefinition();
         def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
         // 事物隔离级别,开启新事务,这样会比较安全些。
         transaction = dataSourceTransactionManager.getTransaction(def);
         // 获得事务状态
      }
      checkBtmTypeBeforeSave(btmTypeDTO);
      BtmType btmTypeDO = Optional.ofNullable(BeanUtil.copy(btmTypeDTO, BtmType.class)).orElseGet(BtmType::new);
      List<BtmTypeLinkAttributesDTO> attributes = btmTypeDTO.getAttributes();
      List<BtmTypeAttributeVO> afterAttributes;
      if (StringUtils.isBlank(btmTypeDO.getOid())){
         btmTypeDO = BtmTypeWrapper.build().entityBeforeInsert(btmTypeDO);
         if (StringUtils.isBlank(btmTypeDO.getTableName())) {
            btmTypeDO.setTableName(getTableName(btmTypeDO.getId(),btmTypeDO.getDomain()));
         }
         // 添加属性
         afterAttributes = addAttributeForBtm(btmTypeDTO);
         baseMapper.insert(btmTypeDO);
      }else {
         BtmTypeVO btmTypeByOid = getBtmTypeByOid(btmTypeDO.getOid());
         List<BtmTypeAttributeVO> beforeAttributes = btmTypeByOid.getAttributes();
         // 处理属性,多余的删除,不存在的添加
         afterAttributes = updateAttributeForBtm(btmTypeByOid.getOid(),beforeAttributes, attributes);
      }
      BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(btmTypeDO);
      btmTypeVO.setAttributes(afterAttributes);
      try {
         if (autoCreateTable) {
            checkTableSame(btmTypeVO);
            R result = DomainRepeater.submitBtmType(btmTypeDTO.getDomain(), btmTypeVO);
            if (result.isSuccess()){
               List<ModifyAttributeInfo> infoList = new ArrayList<>();
               Object data = result.getData();
               if (data instanceof List){
                  List dataList = (List) data;
                  dataList.forEach(s -> {
                     if (s instanceof ModifyAttributeInfo){
                        ModifyAttributeInfo info = (ModifyAttributeInfo) s;
                        infoList.add(info);
                     }
                  });
                  modifyAttributeService.saveBatch(ModifyAttributeWrapper.build().listEntityBeforeSave(infoList));
               }
               dataSourceTransactionManager.commit(transaction);
            }else {
               dataSourceTransactionManager.rollback(transaction);
            }
         }
      } catch (Throwable e) {
         if (autoCreateTable) {
            dataSourceTransactionManager.rollback(transaction);
         }
      }
      return R.data(btmTypeVO);
   }
   /**
    * 更新业务类型的属性
    * @param oid 逐渐
    * @param beforeAttr 更新前的属性
    * @param afterAttr 更新后的属性
    */
   private List<BtmTypeAttributeVO> updateAttributeForBtm(String oid, List<BtmTypeAttributeVO> beforeAttr, List<BtmTypeLinkAttributesDTO> afterAttr) {
      List<BtmTypeAttributeVO> deleteList = beforeAttr.stream().filter(before -> afterAttr.stream().noneMatch(after -> StringUtils.equals(before.getId(), after.getId()))).collect(Collectors.toList());
      List<BtmTypeLinkAttributesDTO> addList = afterAttr.stream().filter(after -> beforeAttr.stream().noneMatch(before -> StringUtils.equals(before.getId(), after.getId()))).collect(Collectors.toList());
      List<BtmTypeLinkAttributesDTO> modifyList = new ArrayList<>();
      Map<String, BtmTypeAttributeVO> beforeAttrMap = beforeAttr.stream().collect(Collectors.toMap(BtmTypeAttributeVO::getId, t -> t, (o1, o2) -> o1));
      Map<String, BtmTypeLinkAttributesDTO> afterAttrMap = afterAttr.stream().collect(Collectors.toMap(BtmTypeLinkAttributesDTO::getId, t -> t, (o1, o2) -> o1));
      afterAttrMap.forEach((k,v) -> {
         if (beforeAttrMap.containsKey(k)){
            modifyList.add(v);
         }
      });
      btmTypeAttributeService.checkAndRemove(deleteList.stream().map(BtmTypeAttributeVO::getOid).collect(Collectors.toList()));
      List<BtmTypeAttributeVO> voListAdd = btmTypeAttributeService.checkAndInsert(oid, addList, AuthUtil.getUserAccount(), new Date());
      List<BtmTypeAttributeVO> voListUpdate = btmTypeAttributeService.checkAndUpdate(oid, modifyList, AuthUtil.getUserAccount(), new Date());
      List<BtmTypeAttributeVO> returnList = new ArrayList<>();
      returnList.addAll(Objects.requireNonNull(voListAdd));
      returnList.addAll(Objects.requireNonNull(voListUpdate));
      return returnList;
   }
   /**
    * 检查业务类型符合规范
    * @param btmTypeDTO 业务类型页面传输对象
    */
   private void checkBtmTypeBeforeSave(BtmTypeDTO btmTypeDTO) {
      VciBaseUtil.alertNotNull(btmTypeDTO, "要添加的业务类型", btmTypeDTO.getId(), "业务类型的英文名称", btmTypeDTO.getName(), "业务类型中文名称");
      if (btmTypeDTO.isViewFlag() && (StringUtils.isBlank(btmTypeDTO.getViewCreateSql())
         || StringUtils.isBlank(btmTypeDTO.getTableName()))) {
         throw new VciBaseException("如果当前是业务类型是视图的时候,请必须输入视图的创建语句和视图名称");
      }
      if (!btmTypeDTO.isViewFlag()) {
         VciBaseUtil.alertCollectionNotNull("属性", btmTypeDTO.getAttributes());
      }
      if (!btmTypeDTO.getId().matches(OmdRegExpConstant.LETTER)) {
         throw new VciBaseException("业务类型英文名称只能是纯英文,目前为{0}", new Object[]{btmTypeDTO.getId()});
      }
      if (btmTypeDTO.getId().length() > 24) {
         throw new VciBaseException("业务类型英文名称不能超过18,目前长度为{0}", new Object[]{btmTypeDTO.getId().length()});
      }
      List<BtmType> btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId()));
      if (!CollectionUtils.isEmpty(btmTypeDOList) && btmTypeDOList.size() > 0) {
         BtmType existBtmType = btmTypeDOList.get(0);
         throw new VciBaseException("业务类型英文名称已经存在(不区分大小写),这个英文名称对应的中文名称为{0},创建人{1},创建时间{2}"
            , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)});
      }
      if (btmTypeDTO.isRevisionFlag()){
         // 需要控制版本
         // 检查使用的版本规则是否存在
//            if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) {
//               if (revisionRuleServiceI.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) {
//                  throw new VciBaseException("版本规则{0}[{1}]在系统中不存在,请先查证",
//                     new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()});
//               }
//            }
         btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP));
      }
      if (btmTypeDTO.isLifeCycleFlag()){
         // 需要控制生命周期
         //检查使用的生命周期是否存在
//            if (StringUtils.isNotBlank(btmTypeDTO.getLifeCycleId())
//               && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId())) {
//               if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getLifeCycleId())) {
//                  throw new VciBaseException("生命周期{0}[{1}]在系统中不存在,请先查证",
//                     new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()});
//               }
//            }
//            if (StringUtils.isNotBlank(btmTypeDTO.getSubLifeCycleId())) {
//               if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getSubLifeCycleId())) {
//                  throw new VciBaseException("备用生命周期{0}[{1}]中其中有某些在系统中不存在,请先查证",
//                     new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()});
//               }
//            }
         btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP));
      }
      if (btmTypeDTO.isSecretFlag()){
         // 需要控制密级
         btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP));
      }
      if (StringUtils.isBlank(btmTypeDTO.getOid())) {
         btmTypeDTO.setOid(VciBaseUtil.getPk());
      }
   }
   @Override
   public boolean deleteLogic(@NotEmpty List<Long> ids) {
      return false;