Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java
@@ -7,10 +7,8 @@
import com.vci.ubcs.ddl.bo.DdlTableInDataBaseBO;
import com.vci.ubcs.ddl.enums.BusinessTypeEnum;
import com.vci.ubcs.ddl.enums.ModifyTableTaskEnum;
import com.vci.ubcs.ddl.processor.ddl.DdlMapperProcessStrategy;
import com.vci.ubcs.ddl.processor.ddl.DdlMapperProcessor;
import com.vci.ubcs.ddl.processor.dll.DllMapperProcessor;
import com.vci.ubcs.ddl.processor.dll.DllMapperProcessorStrategy;
import com.vci.ubcs.ddl.properties.DdlPropertise;
import com.vci.ubcs.ddl.service.IDdlService;
import com.vci.ubcs.omd.cache.BtmTypeCache;
@@ -35,6 +33,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -64,13 +63,15 @@
   /**
    * ddl数据操作服务
    */
   private final DdlMapperProcessor ddlMapper = DdlMapperProcessStrategy.getProcessor();
   @Autowired
   private DdlMapperProcessor ddlMapper;
   /**
    * dll数据操作服务
    */
   private final DllMapperProcessor dllMapper = DllMapperProcessorStrategy.getProcessor();
   @Autowired
   private DllMapperProcessor dllMapper;
   private static final String YES = "Y";
@@ -80,25 +81,25 @@
   private final Map<String, LinkTypeVO> idLinkMap = new ConcurrentHashMap<>();
   private void putBtm(@NotNull BtmTypeVO... voList) throws ServiceException {
   private void putBtm(@NotNull BtmTypeVO... voList) throws Throwable {
      String collect = Arrays.stream(voList).map(BtmTypeVO::getId).filter(idBtmMap::containsKey).collect(Collectors.joining(","));
      if (StringUtils.isBlank(collect)) {
         Arrays.stream(voList).forEach(vo -> {
            idBtmMap.put(vo.getId(), vo);
         });
      } else {
         throw new ServiceException("业务类型:[" + collect + "]正在被其他用户操作");
         throw new Throwable("业务类型:[" + collect + "]正在被其他用户操作");
      }
   }
   private void putLink(@NotNull LinkTypeVO... voList) throws ServiceException {
   private void putLink(@NotNull LinkTypeVO... voList) throws Throwable {
      String collect = Arrays.stream(voList).map(LinkTypeVO::getId).filter(idLinkMap::containsKey).collect(Collectors.joining(","));
      if (StringUtils.isBlank(collect)) {
         Arrays.stream(voList).forEach(vo -> {
            idLinkMap.put(vo.getId(), vo);
         });
      } else {
         throw new ServiceException("链接类型:[" + collect + "]正在被其他用户操作");
         throw new Throwable("链接类型:[" + collect + "]正在被其他用户操作");
      }
   }
@@ -185,6 +186,26 @@
   }
   /**
    * 创建链接类型的表格
    *
    * @param linkTypeVO 链接类型的显示对象
    * @throws VciBaseException 执行出错的时候会抛出异常
    */
   private void createDbTableForLink(LinkTypeVO linkTypeVO) throws VciBaseException {
      VciBaseUtil.alertNotNull(linkTypeVO, "要创建表格所属的业务类型", linkTypeVO.getTableName(), "业务类型的表格名称");
      String tableName = linkTypeVO.getTableName();
      if (!checkTableExistByTableName(tableName)) {
         String attributeSql = getCreateSqlByAttributeForLink(linkTypeVO.getAttributes());
         dllMapper.createTableBySql(tableName, attributeSql);
         if (StringUtils.isNotBlank(linkTypeVO.getName())) {
            dllMapper.commentTable(tableName, linkTypeVO.getName());
         }
         linkTypeVO.getAttributes().forEach(s -> {
            dllMapper.commentColumnTable(tableName, s.getId(), s.getName());
         });
      }
   }
   /**
    * 获取创建的sql语句中属性部分
    *
    * @param attributeVOList 属性的立碑
@@ -196,7 +217,26 @@
      attributeVOList.forEach(a -> {
         sb.append(a.getId()).append(StringPool.SPACE);
         VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.forValue(a.getAttrDataType());
         sb.append(dllMapper.getColumnTypeSql(fieldTypeEnum, a));
         sb.append(dllMapper.getColumnTypeSql(fieldTypeEnum, a)).append(",");
      });
      return sb.substring(0, sb.lastIndexOf(","));
   }
   /**
    * 获取创建的sql语句中属性部分
    *
    * @param attributeVOList 属性的立碑
    * @return sql语句
    */
   @Override
   public String getCreateSqlByAttributeForLink(List<LinkTypeAttributeVO> attributeVOList) {
      StringBuilder sb = new StringBuilder();
      attributeVOList.forEach(a -> {
         BtmTypeAttributeVO attributeVO = Optional.ofNullable(BeanUtil.copy(a, BtmTypeAttributeVO.class)).orElseGet(BtmTypeAttributeVO::new);
         attributeVO.setPkBtmType(a.getPkLinkType());
         sb.append(a.getId()).append(StringPool.SPACE);
         VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.forValue(a.getAttrDataType());
         sb.append(dllMapper.getColumnTypeSql(fieldTypeEnum, attributeVO)).append(",");
      });
      return sb.substring(0, sb.lastIndexOf(","));
   }
@@ -210,19 +250,10 @@
   @Override
   public void createDbTablesById(String ids) throws VciBaseException {
      VciBaseUtil.alertNotNull(ids, "业务类型/链接类型的英文集合");
      List<BtmTypeVO> btmTypeVOList = BtmTypeCache.selectByIdCollection(VciBaseUtil.str2List(ids));
//      List<OsLinkTypeVO> linkTypeVOList = linkTypeService.listLinkTypeByIdCollection(VciBaseUtil.str2List(ids));
      if (!CollectionUtils.isEmpty(btmTypeVOList)) {
         //说明是业务类型
         btmTypeVOList.forEach(this::createDbTableForBtm);
      }
      /*//试试链接类型
      if(!CollectionUtils.isEmpty(linkTypeVOList)){
         //的确是链接类型
         linkTypeVOList.stream().forEach( s -> {
            createDbTableForLink(s);
         });
      }*/
      // 业务类型
      Func.toStrList(",",ids).stream().filter(idBtmMap::containsKey).map(idBtmMap::get).forEach(this::createDbTableForBtm);
      // 链接类型
      Func.toStrList(",",ids).stream().filter(idLinkMap::containsKey).map(idLinkMap::get).forEach(this::createDbTableForLink);
   }
   /**
@@ -540,6 +571,7 @@
               modifyAttributeInfo.setBeforeModifyAttributes(String.join(",", beforeList));
            }
         }
         modifyAttributeInfoDOList.add(modifyAttributeInfo);
      });
      return modifyAttributeInfoDOList;
   }
@@ -641,6 +673,7 @@
               }
            }
            modifyAttributeInfoDOList.add(modifyAttributeInfo);
      });
      return modifyAttributeInfoDOList;
   }
@@ -719,8 +752,8 @@
   @Override
   public void reflexDifferent(List<ModifyAttributeInfo> differentAttributeList, List<BtmTypeVO> btmTypeVOList, List<LinkTypeVO> linkTypeVOList) throws VciBaseException {
      VciBaseUtil.alertNotNull(differentAttributeList, "要清理的数据库的信息为空");
      Map<String, BtmTypeVO> idBtmTypeMap = btmTypeVOList.stream().collect(Collectors.toMap(BtmTypeVO::getId, t -> t, (o1, o2) -> o1));
      Map<String, LinkTypeVO> idLinkTypeMap = linkTypeVOList.stream().collect(Collectors.toMap(LinkTypeVO::getId, t -> t, (o1, o2) -> o1));
      Map<String, BtmTypeVO> idBtmTypeMap = Optional.ofNullable(btmTypeVOList).orElseGet(ArrayList::new).stream().collect(Collectors.toMap(BtmTypeVO::getId, t -> t, (o1, o2) -> o1));
      Map<String, LinkTypeVO> idLinkTypeMap = Optional.ofNullable(linkTypeVOList).orElseGet(ArrayList::new).stream().collect(Collectors.toMap(LinkTypeVO::getId, t -> t, (o1, o2) -> o1));
      differentAttributeList.forEach(s -> {
//         BtmTypeVO btmType = idBtmTypeMap.get(id);
         if (ModifyTableTaskEnum.CREATE.getValue().equalsIgnoreCase(s.getTaskName())) {
@@ -943,7 +976,7 @@
    * @return 执行结果
    */
   @Override
   public R<List<ModifyAttributeInfo>> submit(BtmAndLinkTypeDdlDTO ddlDTO) {
   public R<List<ModifyAttributeInfo>> submit(BtmAndLinkTypeDdlDTO ddlDTO) throws Throwable {
      try {
         List<ModifyAttributeInfo> changedList = new ArrayList<>();
         if (!CollectionUtils.isEmpty(ddlDTO.getBtmTypeList())) {
@@ -958,11 +991,23 @@
            changedList.addAll(checkDifferent(null,linkTypeList));
            removeLink(linkTypeList.toArray(new LinkTypeVO[0]));
         }
         R<List<ModifyAttributeInfo>> result = R.success("数据库操作成功");
         String msg = changedList.isEmpty() ? "数据库操作成功" : changedList.get(0).getHandleResult();
         R<List<ModifyAttributeInfo>> result = R.success(msg);
         result.setData(changedList);
         return result;
      } catch (ServiceException e) {
         throw new RuntimeException(e.getMessage());
      } catch (Exception e) {
         try {
            // 建表失败有异常,捕获后返回,并释放线程中的内容
            if (!CollectionUtils.isEmpty(ddlDTO.getBtmTypeList())) {
               removeBtm(ddlDTO.getBtmTypeList().toArray(new BtmTypeVO[0]));
            }
            if (!CollectionUtils.isEmpty(ddlDTO.getLinkTypeList())) {
               removeLink(ddlDTO.getLinkTypeList().toArray(new LinkTypeVO[0]));
            }
            return R.fail(e.getMessage());
         }catch (ServiceException e2){
            return R.fail(e.getMessage());
         }
      }
   }
@@ -1024,7 +1069,7 @@
               BtmTypeAttributeVO attributeVO = new BtmTypeAttributeVO();
               attributeVO.setId(col.getId().toLowerCase());
               attributeVO.setName(col.getName());
               attributeVO.setNullableFlag(col.getNullableFlag());
               attributeVO.setNullableFlag(StringUtils.equals(col.getNullableFlag(), BooleanEnum.TRUE.getValue()));
               attributeVO.setAttributeLength(col.getAttributeLength());
               attributeVO.setPrecisionLength(col.getPrecisionLength());
               attributeVO.setScaleLength(col.getScaleLength());