lihang
2023-04-25 dd3a6c681f938fd53d5f6cc3a4fcee40e71b259c
Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java
@@ -1,6 +1,5 @@
package com.vci.ubcs.ddl.service.impl;
import com.alibaba.nacos.client.naming.NacosNamingService;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.word.bo.WordMergeStartTableDataBO;
import com.vci.ubcs.ddl.bo.DdlTableBO;
@@ -12,13 +11,13 @@
import com.vci.ubcs.ddl.properties.DdlExportWordFieldProperties;
import com.vci.ubcs.ddl.properties.DdlPropertise;
import com.vci.ubcs.ddl.service.IDdlService;
import com.vci.ubcs.omd.cache.OmdBtmTypeCache;
import com.vci.ubcs.omd.dto.OmdBtmTypeDTO;
import com.vci.ubcs.omd.entity.OsModifyAttributeInfoDO;
import com.vci.ubcs.omd.vo.OmdBtmTypeAttributeVO;
import com.vci.ubcs.omd.vo.OmdBtmTypeVO;
import com.vci.ubcs.omd.vo.OsLinkTypeAttributeVO;
import com.vci.ubcs.omd.vo.OsLinkTypeVO;
import com.vci.ubcs.omd.cache.BtmTypeCache;
import com.vci.ubcs.omd.dto.BtmTypeDTO;
import com.vci.ubcs.omd.entity.ModifyAttributeInfoDO;
import com.vci.ubcs.omd.vo.BtmTypeAttributeVO;
import com.vci.ubcs.omd.vo.BtmTypeVO;
import com.vci.ubcs.omd.vo.LinkTypeAttributeVO;
import com.vci.ubcs.omd.vo.LinkTypeVO;
import com.vci.ubcs.starter.exception.VciBaseException;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.tool.api.R;
@@ -89,7 +88,7 @@
   @Override
   public String getTableNameByBtmTypeOid(String pkBtmType) {
      VciBaseUtil.alertNotNull(pkBtmType, "业务类型或者链接类型的主键");
      OmdBtmTypeVO btmType = OmdBtmTypeCache.getDetail(pkBtmType);
      BtmTypeVO btmType = BtmTypeCache.getDetail(pkBtmType);
      String tableName = "";
      if (btmType == null || StringUtils.isBlank(btmType.getOid())) {
         /*OsLinkTypeDO linkTypeDO = linkTypeDOMapper.selectByPrimaryKey(pkBtmType.trim());
@@ -113,7 +112,7 @@
   @Override
   public String getTableNameByBtmTypeId(String id) {
      VciBaseUtil.alertNotNull(id, "业务类型或者链接类型的英文名称");
      List<OmdBtmTypeVO> btmTypeList = OmdBtmTypeCache.selectByIdCollection(VciBaseUtil.str2List(id));
      List<BtmTypeVO> btmTypeList = BtmTypeCache.selectByIdCollection(VciBaseUtil.str2List(id));
      String tableName = "";
      if (CollectionUtils.isEmpty(btmTypeList)) {
         /*List<OsLinkTypeDO> linkTypeDOList = linkTypeDOMapper.selectByIdCollection(VciBaseUtil.str2List(id));
@@ -161,7 +160,7 @@
   @Override
   public void createDbTablesByOidCollection(Collection<String> oidCollection) throws VciBaseException {
      VciBaseUtil.alertCollectionNotNull("业务类型/链接类型的主键集合", oidCollection);
      List<OmdBtmTypeVO> btmTypeVOList = OmdBtmTypeCache.listBtmTypeByOidCollection(oidCollection);
      List<BtmTypeVO> btmTypeVOList = BtmTypeCache.listBtmTypeByOidCollection(oidCollection);
//      List<OsLinkTypeVO> linkTypeVOList = linkTypeService.listLinkTypeByOidCollection(oidCollection);
      if (!CollectionUtils.isEmpty(btmTypeVOList)) {
         //说明是业务类型
@@ -181,7 +180,7 @@
    * @param btmTypeVO 业务类型的显示对象
    * @throws VciBaseException 执行出错的时候会抛出异常
    */
   private void createDbTableForBtm(OmdBtmTypeVO btmTypeVO) throws VciBaseException {
   private void createDbTableForBtm(BtmTypeVO btmTypeVO) throws VciBaseException {
      VciBaseUtil.alertNotNull(btmTypeVO, "要创建表格所属的业务类型", btmTypeVO.getTableName(), "业务类型的表格名称");
      if (btmTypeVO.isViewFlag() && StringUtils.isNotBlank(btmTypeVO.getViewCreateSql())) {
         //说明是视图
@@ -210,7 +209,7 @@
   @Override
   public void createDbTablesById(String ids) throws VciBaseException {
      VciBaseUtil.alertNotNull(ids, "业务类型/链接类型的英文集合");
      List<OmdBtmTypeVO> btmTypeVOList = OmdBtmTypeCache.selectByIdCollection(VciBaseUtil.str2List(ids));
      List<BtmTypeVO> btmTypeVOList = BtmTypeCache.selectByIdCollection(VciBaseUtil.str2List(ids));
//      List<OsLinkTypeVO> linkTypeVOList = linkTypeService.listLinkTypeByIdCollection(VciBaseUtil.str2List(ids));
      if (!CollectionUtils.isEmpty(btmTypeVOList)) {
         //说明是业务类型
@@ -232,11 +231,11 @@
    * @throws VciBaseException 执行出错的时候会抛出异常
    */
   @Override
   public void changeColumnForBtm(List<OmdBtmTypeAttributeVO> modifyLengthAttrVOList) throws VciBaseException {
   public void changeColumnForBtm(List<BtmTypeAttributeVO> modifyLengthAttrVOList) throws VciBaseException {
      VciBaseUtil.alertCollectionNotNull("要修改长度的属性集", modifyLengthAttrVOList);
      Map<String, List<OmdBtmTypeAttributeVO>> btmTypeHasAttributeVOMap = modifyLengthAttrVOList.stream().collect(Collectors.groupingBy(OmdBtmTypeAttributeVO::getPkBtmType));
      Map<String, List<BtmTypeAttributeVO>> btmTypeHasAttributeVOMap = modifyLengthAttrVOList.stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType));
      btmTypeHasAttributeVOMap.forEach((k, v) -> {
         OmdBtmTypeVO btmTypeVO = OmdBtmTypeCache.getDetail(k);
         BtmTypeVO btmTypeVO = BtmTypeCache.getDetail(k);
         if (btmTypeVO == null || StringUtils.isBlank(btmTypeVO.getOid())) {
            throw new VciBaseException("要修改属性列长度的业务类型不存在");
         }
@@ -259,7 +258,7 @@
    * @param tableName       表格的名称
    * @param attributeVOList 要添加的属性字段
    */
   private void changeColumnsForTable(String tableName, List<OmdBtmTypeAttributeVO> attributeVOList) {
   private void changeColumnsForTable(String tableName, List<BtmTypeAttributeVO> attributeVOList) {
      String attributeSql = dllMapper.getCreateSqlByAttributeForBtm(attributeVOList);
      //先判断表格是否存在
      boolean tableExist = false;
@@ -282,7 +281,7 @@
    * @param tableName       表格名称
    * @param attributeVOList 属性对象列表
    */
   private void commentColumnsForTable(String tableName, List<OmdBtmTypeAttributeVO> attributeVOList) {
   private void commentColumnsForTable(String tableName, List<BtmTypeAttributeVO> attributeVOList) {
      if (StringUtils.isNotBlank(tableName) && !CollectionUtils.isEmpty(attributeVOList)) {
         attributeVOList.stream().forEach(s -> {
            ddlMapper.commentColumnTable(tableName, s.getId(), s.getName());
@@ -297,7 +296,7 @@
    * @throws VciBaseException 执行出错的时候会抛出异常
    */
   @Override
   public void changeColumnForLink(List<OsLinkTypeAttributeVO> modifyLengthAttrDOListForLinkType) throws VciBaseException {
   public void changeColumnForLink(List<LinkTypeAttributeVO> modifyLengthAttrDOListForLinkType) throws VciBaseException {
   }
@@ -308,11 +307,11 @@
    * @throws VciBaseException 执行出错的时候会抛出异常
    */
   @Override
   public void addColumn2TableForBtm(List<OmdBtmTypeAttributeVO> addAttrDOList) throws VciBaseException {
   public void addColumn2TableForBtm(List<BtmTypeAttributeVO> addAttrDOList) throws VciBaseException {
      VciBaseUtil.alertCollectionNotNull("要添加到数据库表中的属性集", addAttrDOList);
      Map<String, List<OmdBtmTypeAttributeVO>> btmTypeHasAttributeVOMap = addAttrDOList.stream().collect(Collectors.groupingBy(OmdBtmTypeAttributeVO::getPkBtmType));
      Map<String, List<BtmTypeAttributeVO>> btmTypeHasAttributeVOMap = addAttrDOList.stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType));
      btmTypeHasAttributeVOMap.forEach((k, v) -> {
         OmdBtmTypeVO btmTypeVO = OmdBtmTypeCache.getDetail(k);
         BtmTypeVO btmTypeVO = BtmTypeCache.getDetail(k);
         if (btmTypeVO == null || StringUtils.isBlank(btmTypeVO.getOid())) {
            throw new com.vci.starter.web.exception.VciBaseException("要修改属性列长度的业务类型不存在");
         }
@@ -329,11 +328,11 @@
    * @param attributeVOList 属性的显示对象
    * @throws com.vci.starter.web.exception.VciBaseException 执行或者获取sql语句的时候出现错误会抛出异常
    */
   private void addColumnForTable(String tableName, List<OmdBtmTypeAttributeVO> attributeVOList) {
   private void addColumnForTable(String tableName, List<BtmTypeAttributeVO> attributeVOList) {
      String attributeSql = dllMapper.getCreateSqlByAttributeForBtm(attributeVOList);
      //先判断表格是否存在
      if (!checkTableExistByTableName(tableName)) {
         OmdBtmTypeAttributeVO attributeVO = attributeVOList.get(0);
         BtmTypeAttributeVO attributeVO = attributeVOList.get(0);
         createDbTables(attributeVO.getPkBtmType());
      } else {
         ddlMapper.addColumn2TableBySql(tableName, attributeSql);
@@ -348,7 +347,7 @@
    * @throws VciBaseException 执行出错的时候会抛出异常
    */
   @Override
   public void addColumn2TableForLink(List<OsLinkTypeAttributeVO> addAttrDOListForLinkType) throws VciBaseException {
   public void addColumn2TableForLink(List<LinkTypeAttributeVO> addAttrDOListForLinkType) throws VciBaseException {
   }
@@ -449,7 +448,7 @@
    * @return 不同的地方,每一个业务类型或者链接类型一条数据
    */
   @Override
   public List<OsModifyAttributeInfoDO> checkDifferent(List<OmdBtmTypeVO> btmTypeVOList, List<OsLinkTypeVO> linkTypeVOList) throws VciBaseException {
   public List<ModifyAttributeInfoDO> checkDifferent(List<BtmTypeVO> btmTypeVOList, List<LinkTypeVO> linkTypeVOList) throws VciBaseException {
      return null;
   }
@@ -460,7 +459,7 @@
    * @throws VciBaseException 参数为空或者执行出错的时候会抛出异常
    */
   @Override
   public void reflexDifferent(List<OsModifyAttributeInfoDO> differentAttributeList) throws VciBaseException {
   public void reflexDifferent(List<ModifyAttributeInfoDO> differentAttributeList) throws VciBaseException {
   }
@@ -556,9 +555,9 @@
    * @return 执行结果
    */
   @Override
   public R submitBtmType(OmdBtmTypeDTO dto) {
   public R submitBtmType(BtmTypeDTO dto) {
      VciBaseUtil.alertNotNull(dto, "业务类型", dto.getAttributesDTOList(), "业务类型属性");
      OmdBtmTypeVO btmTypeVO = Objects.requireNonNull(BeanUtil.copy(dto, OmdBtmTypeVO.class));
      BtmTypeVO btmTypeVO = Objects.requireNonNull(BeanUtil.copy(dto, BtmTypeVO.class));
      if (Func.isNotBlank(dto.getTableName())) {
         checkModifyOrCreateTable(btmTypeVO);
      } else {
@@ -580,12 +579,12 @@
    *
    * @param btmTypeVO 业务类型
    */
   private void checkModifyOrCreateTable(OmdBtmTypeVO btmTypeVO) {
   private void checkModifyOrCreateTable(BtmTypeVO btmTypeVO) {
      if (checkTableExistByTableName(btmTypeVO.getTableName())) {
         // 表已存在,校验属性
         List<OmdBtmTypeVO> vos = new ArrayList<>();
         List<BtmTypeVO> vos = new ArrayList<>();
         vos.add(btmTypeVO);
         List<OsModifyAttributeInfoDO> differentAttributeList = checkDifferent(vos, null);
         List<ModifyAttributeInfoDO> differentAttributeList = checkDifferent(vos, null);
         if (CollectionUtils.isEmpty(differentAttributeList)) {
            // 可以直接删除再创建
            dropTableByName(btmTypeVO.getTableName());