¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.ddl.service.impl; |
| | | |
| | | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | import com.alibaba.nacos.shaded.com.google.protobuf.ServiceException; |
| | | import com.vci.ubcs.ddl.bo.DdlTableBO; |
| | | 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; |
| | | import com.vci.ubcs.omd.constant.BtmTypeFieldConstant; |
| | | import com.vci.ubcs.omd.constant.BtmTypeLcStatusConstant; |
| | | import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO; |
| | | import com.vci.ubcs.omd.entity.ModifyAttributeInfo; |
| | | import com.vci.ubcs.omd.vo.*; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.web.enumpck.BooleanEnum; |
| | | import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | 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.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Description: æ°æ®åºè¡¨æä½æå¡ |
| | | * |
| | | * @author LiHang |
| | | * @date 2023/4/24 |
| | | */ |
| | | @Service |
| | | public class DdlServiceImpl implements IDdlService { |
| | | |
| | | /** |
| | | * ç¸åºçé
ç½® |
| | | */ |
| | | @Autowired |
| | | private DdlPropertise ddlProperties; |
| | | |
| | | /** |
| | | * word导åºçæ¶åçååæ®µæ å° |
| | | */ |
| | | // @Autowired |
| | | // private DdlExportWordFieldProperties wordFieldProperties; |
| | | |
| | | /** |
| | | * ddlæ°æ®æä½æå¡ |
| | | */ |
| | | private final DdlMapperProcessor ddlMapper = DdlMapperProcessStrategy.getProcessor(); |
| | | |
| | | |
| | | /** |
| | | * dllæ°æ®æä½æå¡ |
| | | */ |
| | | private final DllMapperProcessor dllMapper = DllMapperProcessorStrategy.getProcessor(); |
| | | |
| | | private static final String YES = "Y"; |
| | | |
| | | private static final String NO = "N"; |
| | | |
| | | private final Map<String, BtmTypeVO> idBtmMap = new ConcurrentHashMap<>(); |
| | | |
| | | private final Map<String, LinkTypeVO> idLinkMap = new ConcurrentHashMap<>(); |
| | | |
| | | private void putBtm(@NotNull BtmTypeVO... voList) throws ServiceException { |
| | | 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 + "]æ£å¨è¢«å
¶ä»ç¨æ·æä½"); |
| | | } |
| | | } |
| | | |
| | | private void putLink(@NotNull LinkTypeVO... voList) throws ServiceException { |
| | | 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 + "]æ£å¨è¢«å
¶ä»ç¨æ·æä½"); |
| | | } |
| | | } |
| | | |
| | | private void removeBtm(@NotNull BtmTypeVO... btmTypeVO) throws ServiceException { |
| | | if (Arrays.stream(btmTypeVO).allMatch(s -> idBtmMap.containsKey(s.getId()))) { |
| | | for (BtmTypeVO vo : btmTypeVO) { |
| | | idBtmMap.remove(vo.getId()); |
| | | } |
| | | } else { |
| | | throw new ServiceException("è§£é对象ä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | private void removeLink(@NotNull LinkTypeVO... linkTypeVO) throws ServiceException { |
| | | if (Arrays.stream(linkTypeVO).allMatch(s -> idLinkMap.containsKey(s.getId()))) { |
| | | for (LinkTypeVO vo : linkTypeVO) { |
| | | idLinkMap.remove(vo.getId()); |
| | | } |
| | | } else { |
| | | throw new ServiceException("è§£é对象ä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªä¸å¡ç±»åçæ°æ®åºè¡¨ä¸æ¯å¦ææ°æ® |
| | | * |
| | | * @param pkBtmType ä¸å¡ç±»åçä¸»é® |
| | | * @return trueè¡¨ç¤ºææ°æ®ï¼falseè¡¨ç¤ºæ²¡ææ°æ® |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
æ¥è¯¢åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public boolean checkTableHasData(String pkBtmType) throws VciBaseException { |
| | | return checkTableHasDataByTableName(getTableNameByBtmTypeOid(pkBtmType)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ä¸å¡ç±»åæè
龿¥ç±»åç主é®è·åæ°æ®åºè¡¨æ ¼çåç§° |
| | | * |
| | | * @param pkBtmType ä¸å¡ç±»åæè
龿¥ç±»åçä¸»é® |
| | | * @return æ°æ®åºè¡¨åç§° |
| | | */ |
| | | @Override |
| | | public String getTableNameByBtmTypeOid(String pkBtmType) { |
| | | VciBaseUtil.alertNotNull(pkBtmType, "ä¸å¡ç±»åæè
龿¥ç±»åç主é®"); |
| | | BtmTypeVO btmType = BtmTypeCache.getDetail(pkBtmType); |
| | | String tableName = ""; |
| | | if (btmType == null || StringUtils.isBlank(btmType.getOid())) { |
| | | /*OsLinkTypeDO linkTypeDO = linkTypeDOMapper.selectByPrimaryKey(pkBtmType.trim()); |
| | | if(linkTypeDO == null || StringUtils.isBlank(linkTypeDO.getOid()) ){ |
| | | throw new com.vci.starter.web.exception.VciBaseException("䏿¯ä¸å¡ç±»åï¼ä¹ä¸æ¯é¾æ¥ç±»åï¼è¯·æ¥è¯"); |
| | | }else{ |
| | | tableName = linkTypeService.getTableName(linkTypeDO.getId()); |
| | | }*/ |
| | | } else { |
| | | tableName = btmType.getTableName(); |
| | | } |
| | | return tableName; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ä¸å¡ç±»åè·å龿¥ç±»åçè±æåç§°è·åæ°æ®åºè¡¨æ ¼çåç§° |
| | | * |
| | | * @param id ä¸å¡ç±»åè·å龿¥ç±»åçè±æåç§° |
| | | * @return æ°æ®åºè¡¨åç§° |
| | | */ |
| | | @Override |
| | | public String getTableNameByBtmTypeId(String id) { |
| | | VciBaseUtil.alertNotNull(id, "ä¸å¡ç±»åæè
龿¥ç±»åçè±æåç§°"); |
| | | List<BtmTypeVO> btmTypeList = BtmTypeCache.selectByIdCollection(VciBaseUtil.str2List(id)); |
| | | String tableName = ""; |
| | | if (CollectionUtils.isEmpty(btmTypeList)) { |
| | | /*List<OsLinkTypeDO> linkTypeDOList = linkTypeDOMapper.selectByIdCollection(VciBaseUtil.str2List(id)); |
| | | if(CollectionUtils.isEmpty(linkTypeDOList)){ |
| | | throw new com.vci.starter.web.exception.VciBaseException("䏿¯ä¸å¡ç±»åï¼ä¹ä¸æ¯é¾æ¥ç±»åï¼è¯·æ¥è¯"); |
| | | }else{ |
| | | tableName = linkTypeService.getTableName(linkTypeDOList.get(0).getId()); |
| | | }*/ |
| | | } else { |
| | | tableName = btmTypeList.get(0).getTableName(); |
| | | } |
| | | return tableName; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªä¸å¡ç±»åçæ°æ®åºè¡¨ä¸æ¯å¦ææ°æ® |
| | | * |
| | | * @param id ä¸å¡ç±»åçè±æåç§° |
| | | * @return trueè¡¨ç¤ºææ°æ®ï¼falseè¡¨ç¤ºæ²¡ææ°æ® |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
æ¥è¯¢åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public boolean checkTableHasDataById(String id) throws VciBaseException { |
| | | return checkTableHasDataByTableName(getTableNameByBtmTypeId(id)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå°ä¸å¡ç±»ååå»ºæ°æ®åºè¡¨ |
| | | * |
| | | * @param pkBtmTypes ä¸å¡ç±»åçä¸»é® |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
å建表åºç°äºéè¯¯çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void createDbTables(String pkBtmTypes) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(pkBtmTypes, "ä¸å¡ç±»å/龿¥ç±»åç主é®"); |
| | | createDbTablesByOidCollection(VciBaseUtil.str2List(pkBtmTypes)); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå°ä¸å¡ç±»ååå»ºæ°æ®åºè¡¨ |
| | | * |
| | | * @param oidCollection ä¸å¡ç±»åç主é®éå |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
å建表åºç°äºéè¯¯çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void createDbTablesByOidCollection(Collection<String> oidCollection) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull("ä¸å¡ç±»å/龿¥ç±»åç主é®éå", oidCollection); |
| | | List<BtmTypeVO> btmTypeVOList = BtmTypeCache.listBtmTypeByOidCollection(oidCollection); |
| | | // List<OsLinkTypeVO> linkTypeVOList = linkTypeService.listLinkTypeByOidCollection(oidCollection); |
| | | if (!CollectionUtils.isEmpty(btmTypeVOList)) { |
| | | //è¯´ææ¯ä¸å¡ç±»å |
| | | btmTypeVOList.forEach(this::createDbTableForBtm); |
| | | } |
| | | //龿¥ç±»å |
| | | /*if(!CollectionUtils.isEmpty(linkTypeVOList)){ |
| | | linkTypeVOList.stream().forEach( s -> { |
| | | createDbTableForLink(s); |
| | | }); |
| | | }*/ |
| | | } |
| | | |
| | | /** |
| | | * å建ä¸å¡ç±»åçè¡¨æ ¼ |
| | | * |
| | | * @param btmTypeVO ä¸å¡ç±»åçæ¾ç¤ºå¯¹è±¡ |
| | | * @throws VciBaseException æ§è¡åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | private void createDbTableForBtm(BtmTypeVO btmTypeVO) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(btmTypeVO, "è¦åå»ºè¡¨æ ¼æå±çä¸å¡ç±»å", btmTypeVO.getTableName(), "ä¸å¡ç±»åçè¡¨æ ¼åç§°"); |
| | | if (btmTypeVO.isViewFlag() && StringUtils.isNotBlank(btmTypeVO.getViewCreateSql())) { |
| | | //è¯´ææ¯è§å¾ |
| | | this.createViewBySql("create or replace " + btmTypeVO.getTableName() + " as " + btmTypeVO.getViewCreateSql()); |
| | | } else { |
| | | String tableName = btmTypeVO.getTableName(); |
| | | if (!checkTableExistByTableName(tableName)) { |
| | | String attributeSql = getCreateSqlByAttributeForBtm(btmTypeVO.getAttributes()); |
| | | dllMapper.createTableBySql(tableName, attributeSql); |
| | | if (StringUtils.isNotBlank(btmTypeVO.getName())) { |
| | | dllMapper.commentTable(tableName, btmTypeVO.getName()); |
| | | } |
| | | btmTypeVO.getAttributes().forEach(s -> { |
| | | dllMapper.commentColumnTable(tableName, s.getId(), s.getName()); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åå建çsqlè¯å¥ä¸å±æ§é¨å |
| | | * |
| | | * @param attributeVOList 屿§çç«ç¢ |
| | | * @return sqlè¯å¥ |
| | | */ |
| | | @Override |
| | | public String getCreateSqlByAttributeForBtm(List<BtmTypeAttributeVO> attributeVOList) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | attributeVOList.forEach(a -> { |
| | | sb.append(a.getId()).append(StringPool.SPACE); |
| | | VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.forValue(a.getAttrDataType()); |
| | | sb.append(dllMapper.getColumnTypeSql(fieldTypeEnum, a)); |
| | | }); |
| | | return sb.substring(0, sb.lastIndexOf(",")); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå°ä¸å¡ç±»ååå»ºæ°æ®åºè¡¨ |
| | | * |
| | | * @param ids ä¸å¡ç±»åçè±æåç§° |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
å建表åºç°äºéè¯¯çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @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); |
| | | }); |
| | | }*/ |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸å¡ç±»åä¸ç屿§å段çé¿åº¦ï¼æ³¨æå¨æ§è¡è¿ä¸ªæ¹æ³æ¶å°±ä¼å°ä»¥åçäºå¡æäº¤ã |
| | | * |
| | | * @param modifyLengthAttrVOList éè¦ä¿®æ¹ç屿§å¯¹è±¡ |
| | | * @throws VciBaseException æ§è¡åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void changeColumnForBtm(List<BtmTypeAttributeVO> modifyLengthAttrVOList) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull("è¦ä¿®æ¹é¿åº¦ç屿§é", modifyLengthAttrVOList); |
| | | Map<String, List<BtmTypeAttributeVO>> btmTypeHasAttributeVOMap = modifyLengthAttrVOList.stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType)); |
| | | btmTypeHasAttributeVOMap.forEach((k, v) -> { |
| | | BtmTypeVO btmTypeVO = BtmTypeCache.getDetail(k); |
| | | if (btmTypeVO == null || StringUtils.isBlank(btmTypeVO.getOid())) { |
| | | throw new VciBaseException("è¦ä¿®æ¹å±æ§åé¿åº¦çä¸å¡ç±»åä¸åå¨"); |
| | | } |
| | | if (!isCompatibilityTable(btmTypeVO.getId(), null)) { |
| | | //è¦ççè¿ä¸ªé¾æ¥ç±»å对åºçæ°æ®åºè¡¨æ¯å¦åå¨ |
| | | String tableName = btmTypeVO.getTableName(); |
| | | if (checkTableExistByTableName(tableName)) { |
| | | changeColumnsForTable(tableName, v); |
| | | } else { |
| | | createDbTableForBtm(btmTypeVO); |
| | | } |
| | | changeColumnsForTable(btmTypeVO.getTableName(), v); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * æ§è¡SQLè¯å¥çä¿®æ¹ |
| | | * |
| | | * @param tableName è¡¨æ ¼çåç§° |
| | | * @param attributeVOList è¦æ·»å ç屿§å段 |
| | | */ |
| | | private void changeColumnsForTable(String tableName, List<BtmTypeAttributeVO> attributeVOList) { |
| | | String attributeSql = getCreateSqlByAttributeForBtm(attributeVOList); |
| | | //å
å¤æè¡¨æ ¼æ¯å¦åå¨ |
| | | boolean tableExist = false; |
| | | try { |
| | | ddlMapper.countAll(tableName); |
| | | tableExist = true; |
| | | } catch (Throwable e) { |
| | | //说æè¡¨æ ¼å°±ä¸åå¨ |
| | | createDbTables(attributeVOList.get(0).getPkBtmType()); |
| | | } |
| | | if (tableExist) { |
| | | ddlMapper.modifyTableBySqlBase(tableName, attributeSql); |
| | | commentColumnsForTable(tableName, attributeVOList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç»è¡¨æ ¼çåæ®µæ·»å 注é |
| | | * |
| | | * @param tableName è¡¨æ ¼åç§° |
| | | * @param attributeVOList 屿§å¯¹è±¡å表 |
| | | */ |
| | | private void commentColumnsForTable(String tableName, List<BtmTypeAttributeVO> attributeVOList) { |
| | | if (StringUtils.isNotBlank(tableName) && !CollectionUtils.isEmpty(attributeVOList)) { |
| | | attributeVOList.forEach(s -> { |
| | | ddlMapper.commentColumnTable(tableName, s.getId(), s.getName()); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹é¾æ¥ç±»åä¸ç屿§å段çé¿åº¦ï¼æ³¨æå¨æ§è¡è¿ä¸ªæ¹æ³æ¶å°±ä¼å°ä»¥åçäºå¡æäº¤ã |
| | | * |
| | | * @param modifyLengthAttrDOListForLinkType éè¦ä¿®æ¹ç屿§å¯¹è±¡ |
| | | * @throws VciBaseException æ§è¡åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void changeColumnForLink(List<LinkTypeAttributeVO> modifyLengthAttrDOListForLinkType) throws VciBaseException { |
| | | |
| | | } |
| | | |
| | | /** |
| | | * æ·»å 屿§å段å°ä¸å¡ç±»åä¸ï¼æ³¨æå¨æ§è¡è¿ä¸ªæ¹æ³æ¶å°±ä¼å°ä»¥åçäºå¡æäº¤ã |
| | | * |
| | | * @param addAttrDOList éè¦æ·»å ç屿§å¯¹è±¡ |
| | | * @throws VciBaseException æ§è¡åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void addColumn2TableForBtm(List<BtmTypeAttributeVO> addAttrDOList) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull("è¦æ·»å å°æ°æ®åºè¡¨ä¸ç屿§é", addAttrDOList); |
| | | Map<String, List<BtmTypeAttributeVO>> btmTypeHasAttributeMap = addAttrDOList.stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType)); |
| | | btmTypeHasAttributeMap.forEach((k, v) -> { |
| | | BtmTypeVO btmTypeVO = BtmTypeCache.getDetail(k); |
| | | if (btmTypeVO == null || StringUtils.isBlank(btmTypeVO.getOid())) { |
| | | throw new VciBaseException("è¦ä¿®æ¹å±æ§åé¿åº¦çä¸å¡ç±»åä¸åå¨"); |
| | | } |
| | | if (!isCompatibilityTable(btmTypeVO.getId(), null)) { |
| | | addColumnForTable(btmTypeVO.getTableName(), v); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * æ·»å åæ®µå°è¡¨æ ¼ä¸ |
| | | * |
| | | * @param tableName è¡¨æ ¼åç§° |
| | | * @param attributeVOList 屿§çæ¾ç¤ºå¯¹è±¡ |
| | | * @throws VciBaseException æ§è¡æè
è·åsqlè¯å¥çæ¶ååºç°éè¯¯ä¼æåºå¼å¸¸ |
| | | */ |
| | | private void addColumnForTable(String tableName, List<BtmTypeAttributeVO> attributeVOList) { |
| | | String attributeSql = getCreateSqlByAttributeForBtm(attributeVOList); |
| | | //å
å¤æè¡¨æ ¼æ¯å¦åå¨ |
| | | if (!checkTableExistByTableName(tableName)) { |
| | | BtmTypeAttributeVO attributeVO = attributeVOList.get(0); |
| | | createDbTables(attributeVO.getPkBtmType()); |
| | | } else { |
| | | ddlMapper.addColumn2TableBySql(tableName, attributeSql); |
| | | commentColumnsForTable(tableName, attributeVOList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ·»å 屿§å段å°é¾æ¥ç±»åä¸ï¼æ³¨æå¨æ§è¡è¿ä¸ªæ¹æ³æ¶å°±ä¼å°ä»¥åçäºå¡æäº¤ã |
| | | * |
| | | * @param addAttrDOListForLinkType éè¦æ·»å ç屿§å¯¹è±¡ |
| | | * @throws VciBaseException æ§è¡åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void addColumn2TableForLink(List<LinkTypeAttributeVO> addAttrDOListForLinkType) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull("è¦æ·»å å°æ°æ®åºè¡¨ä¸å±æ§é",addAttrDOListForLinkType); |
| | | Map<String, List<LinkTypeAttributeVO>> linkTypeHasAttributeVOMap = addAttrDOListForLinkType.stream().collect(Collectors.groupingBy(LinkTypeAttributeVO::getPkLinkType)); |
| | | linkTypeHasAttributeVOMap.forEach((k,v) -> { |
| | | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * å¤æè¡¨ä¸æ¯å¦ææ°æ® |
| | | * |
| | | * @param tableName è¡¨æ ¼çåç§° |
| | | * @return trueè¡¨ç¤ºææ°æ®ï¼falseè¡¨ç¤ºæ²¡ææ°æ®ï¼æè
è¿ä¸ªè¡¨æ ¼ä¸åå¨çæ¶åæåºå¼å¸¸ |
| | | * @throws VciBaseException åæ°éè¯¯çæ¶åæåºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public boolean checkTableHasDataByTableName(String tableName) throws VciBaseException { |
| | | try { |
| | | int tableCount = ddlMapper.countAll(tableName); |
| | | if (tableCount > 0) { |
| | | return true; |
| | | } |
| | | } catch (Throwable e) { |
| | | throw new VciBaseException("ç»è®¡æä¸ªè¡¨æ¯å¦å«ææ°æ®åºéï¼å¯è½è¡¨ä¸åå¨"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * å建è§å¾ |
| | | * |
| | | * @param viewCreateSql è§å¾çSQLè¯å¥ |
| | | * @throws VciBaseException åæ°é误æè
æ§è¡éè¯¯çæ¶å伿åºå¼å¸¸ï¼æ§è¡é误主è¦å
æ¬SQLè¯å¥éè¯¯ï¼æ²¡ææéç |
| | | */ |
| | | @Override |
| | | public void createViewBySql(String viewCreateSql) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(viewCreateSql, "è§å¾çSQL"); |
| | | ddlMapper.createViewBySql(viewCreateSql); |
| | | } |
| | | |
| | | /** |
| | | * å é¤è¡¨æ ¼æè
è§å¾ |
| | | * |
| | | * @param tableName è¡¨æ ¼åç§°æè
è§å¾åç§° |
| | | * @throws VciBaseException åæ°é误æè
æ§è¡éè¯¯çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public void dropTableByName(String tableName) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(tableName, "è¦å é¤ç表çåç§°"); |
| | | ddlMapper.dropTable(tableName); |
| | | } |
| | | |
| | | /** |
| | | * å é¤è¡¨æ ¼çæä¸å |
| | | * |
| | | * @param tableName è¡¨æ ¼åç§° |
| | | * @param columnName åçåç§° |
| | | */ |
| | | @Override |
| | | public void dropColumnByName(String tableName, String columnName) { |
| | | VciBaseUtil.alertNotNull(tableName, "è¦å é¤ç表çåç§°", columnName, "è¦å é¤çè¡¨åæ®µåç§°"); |
| | | ddlMapper.dropTableColumn(tableName, columnName); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªä¸å¡ç±»åæè
龿¥ç±»åç对åºçè¡¨æ ¼æ¯å¦åå¨ |
| | | * |
| | | * @param pkBtmType ä¸å¡ç±»åæè
龿¥ç±»åçè¡¨æ ¼ |
| | | * @return true表示åå¨ï¼false表示ä¸åå¨ |
| | | */ |
| | | @Override |
| | | public boolean checkTableExist(String pkBtmType) { |
| | | return checkTableExistByTableName(getTableNameByBtmTypeOid(pkBtmType)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è¡¨æ ¼çåç§°å¤æè¡¨æ ¼æ¯å¦åå¨ |
| | | * |
| | | * @param tableName è¡¨æ ¼åç§° |
| | | * @return rue表示åå¨ï¼false表示ä¸åå¨ |
| | | */ |
| | | @Override |
| | | public boolean checkTableExistByTableName(String tableName) { |
| | | return ddlMapper.checkTableExist(tableName) > 0; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªä¸å¡ç±»åæè
龿¥ç±»åæå¯¹åºçè¡¨æ ¼æ¯å¦åå¨ |
| | | * |
| | | * @param id ä¸å¡ç±»åæè
龿¥ç±»åçè±æåç§° |
| | | * @return true表示åå¨ï¼false表示ä¸åå¨ |
| | | */ |
| | | @Override |
| | | public boolean checkTableExistById(String id) { |
| | | return checkTableExistByTableName(getTableNameByBtmTypeId(id)); |
| | | } |
| | | |
| | | /** |
| | | * è·åæ°æ®åºåä¸å¡ç±»åä¸çä¸åçå°æ¹ |
| | | * |
| | | * @param btmTypeVOList ä¸å¡ç±»åå¯¹è±¡ï¼æå±æ§æ¶éè¦å
å«å±æ§ |
| | | * @param linkTypeVOList 龿¥ç±»åå¯¹è±¡ï¼æå±æ§æ¶éè¦å
å«å±æ§ |
| | | * @return ä¸åçå°æ¹ï¼æ¯ä¸ä¸ªä¸å¡ç±»åæè
龿¥ç±»å䏿¡æ°æ® |
| | | */ |
| | | @Override |
| | | public List<ModifyAttributeInfo> checkDifferent(List<BtmTypeVO> btmTypeVOList, List<LinkTypeVO> linkTypeVOList) throws VciBaseException { |
| | | if (CollectionUtils.isEmpty(btmTypeVOList) && CollectionUtils.isEmpty(linkTypeVOList)) { |
| | | throw new VciBaseException("è¦æ£æ¥çä¸å¡ç±»åå龿¥ç±»å为空"); |
| | | } |
| | | List<ModifyAttributeInfo> modifyAttributeInfoList = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(btmTypeVOList)) { |
| | | modifyAttributeInfoList.addAll(checkBtmType(btmTypeVOList)); |
| | | } |
| | | if (!CollectionUtils.isEmpty(linkTypeVOList)) { |
| | | modifyAttributeInfoList.addAll(checkLinkType(linkTypeVOList)); |
| | | } |
| | | if (CollectionUtils.isEmpty(modifyAttributeInfoList)) { |
| | | reflexDifferent(modifyAttributeInfoList, btmTypeVOList, linkTypeVOList); |
| | | } |
| | | return modifyAttributeInfoList; |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥ä¸å¡ç±»å |
| | | * |
| | | * @param btmTypeVOList ä¸å¡ç±»å |
| | | * @return æ£æ¥ç»æ |
| | | */ |
| | | private List<ModifyAttributeInfo> checkBtmType(List<BtmTypeVO> btmTypeVOList) { |
| | | List<ModifyAttributeInfo> modifyAttributeInfoDOList = new ArrayList<>(); |
| | | btmTypeVOList.stream().filter(s -> !isCompatibilityTable(s.getId(),null)).forEach(btm -> { |
| | | ModifyAttributeInfo modifyAttributeInfo = new ModifyAttributeInfo(); |
| | | modifyAttributeInfo.setId(btm.getId()); |
| | | modifyAttributeInfo.setName(btm.getName()); |
| | | modifyAttributeInfo.setTableName(btm.getTableName()); |
| | | modifyAttributeInfo.setBusinessType(BusinessTypeEnum.BTM.getValue()); |
| | | // 1. è§å¾åæ°å»ºçï¼ç´æ¥å建ï¼è®°å½å建åå² |
| | | if (btm.isViewFlag() || !checkTableExistByTableName(btm.getTableName())){ |
| | | modifyAttributeInfo.setTaskName(ModifyTableTaskEnum.CREATE.getValue()); |
| | | modifyAttributeInfo.setModifyColumnReason(ModifyTableTaskEnum.CREATE.getValue()); |
| | | }else { |
| | | VciBaseUtil.alertNotNull(btm.getAttributes(),"ä¸å¡ç±»å" + btm.getId() + "ç屿§"); |
| | | List<DdlTableInDataBaseBO> columnDataInTable = selectTableColumnInfo(btm.getTableName()); |
| | | if (CollectionUtils.isEmpty(columnDataInTable)){ |
| | | modifyAttributeInfo.setAddAttributes(btm.getAttributes().stream().map(s -> s.getId().toLowerCase().trim()).collect(Collectors.joining(","))); |
| | | modifyAttributeInfo.setTaskName(ModifyTableTaskEnum.EDIT.getValue()); |
| | | modifyAttributeInfo.setModifyColumnReason(ModifyTableTaskEnum.CREATE.getValue()); |
| | | }else { |
| | | // 2. åå¨çæå¤æï¼åæ°å¢å±æ§ã屿§æ´æ¹ã屿§å é¤åå«æä½ |
| | | // 3. 屿§æä½ä¸ç¹å«å¤æ[æ¯å¦æ§å¶çæ¬][æ¯å¦æ§å¶å¯çº§][æ¯å¦æ§å¶çå½å¨æ]æ¥æ·»å 对åºå±æ§ |
| | | Map<String, DdlTableInDataBaseBO> tableColumMap = columnDataInTable.stream().collect(Collectors.toMap(t -> t.getId().toLowerCase().trim(), k -> k)); |
| | | Map<String, BtmTypeAttributeVO> attributeMap = btm.getAttributes().stream().collect(Collectors.toMap(t -> t.getId().toLowerCase().trim(), k -> k)); |
| | | List<String> addList = new ArrayList<>(); |
| | | List<String> editList = new ArrayList<>(); |
| | | List<String> deleteList = new ArrayList<>(); |
| | | List<String> beforeList = new ArrayList<>(); |
| | | attributeMap.forEach((k,v) -> { |
| | | String attributeLowId = k.toLowerCase(); |
| | | if (!checkIsDefaultColumn(attributeLowId)) { |
| | | if (tableColumMap.containsKey(k)) { |
| | | //说æä»¥å乿ï¼é£å°±çæ¯å¦éè¦ä¿®æ¹ |
| | | DdlTableInDataBaseBO columnInDB = tableColumMap.get(k); |
| | | if (columnInDB.getAttributeLength() == null) { |
| | | columnInDB.setAttributeLength(0); |
| | | } |
| | | boolean needEdit = false; |
| | | if (!v.getName().equalsIgnoreCase(columnInDB.getName())) { |
| | | //说æéè¦ä¿®æ¹ |
| | | needEdit = true; |
| | | } |
| | | if (needEdit || checkNeedEditAttr(v, columnInDB)) { |
| | | editList.add(v.getId()); |
| | | beforeList.add(columnInDB.getId() + StringPool.SPACE + columnInDB.getAttrDataType() + "(" + columnInDB.getAttributeLength() + ")" + StringPool.SPACE + columnInDB.getNullableFlag() |
| | | + StringPool.SPACE + columnInDB.getPrecisionLength() + StringPool.SPACE + columnInDB.getScaleLength() + StringPool.SPACE + columnInDB.getName()); |
| | | } |
| | | } else { |
| | | addList.add(v.getId()); |
| | | } |
| | | } else { |
| | | //é对é»è®¤å±æ§ï¼å¦æä»¥å没æï¼ç°å¨æå¯ä»¥æ·»å ï¼å¦æä»¥å |
| | | if (!tableColumMap.containsKey(k)) { |
| | | boolean needAddNewField = false; |
| | | if (!BtmTypeLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btm.getLifeCycleId()) && BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP.containsKey(attributeLowId)) { |
| | | needAddNewField = true; |
| | | } |
| | | if (StringUtils.isNotBlank(btm.getRevisionRuleId()) && BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP.containsKey(attributeLowId)) { |
| | | needAddNewField = true; |
| | | } |
| | | if (btm.isSecretFlag() && BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP.containsKey(attributeLowId)) { |
| | | needAddNewField = true; |
| | | } |
| | | if (needAddNewField) { |
| | | addList.add(v.getId()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | tableColumMap.forEach((k, v) -> { |
| | | if (!attributeMap.containsKey(k)) { |
| | | deleteList.add(k); |
| | | } |
| | | }); |
| | | modifyAttributeInfo.setOrderModifyUserName(AuthUtil.getUserAccount()); |
| | | modifyAttributeInfo.setOrderModifyDate(new Date()); |
| | | modifyAttributeInfo.setModifyColumnReason(ModifyTableTaskEnum.CONSISTENCY_CHECK.getValue()); |
| | | modifyAttributeInfo.setTaskName(ModifyTableTaskEnum.CONSISTENCY_CHECK.getValue()); |
| | | modifyAttributeInfo.setAddAttributes(String.join(",", addList)); |
| | | modifyAttributeInfo.setModifyAttributes(String.join(",", editList)); |
| | | modifyAttributeInfo.setDeleteAttributes(String.join(",", deleteList)); |
| | | modifyAttributeInfo.setBeforeModifyAttributes(String.join(",", beforeList)); |
| | | } |
| | | } |
| | | }); |
| | | return modifyAttributeInfoDOList; |
| | | } |
| | | |
| | | private boolean checkIsDefaultColumn(String attributeLowId) { |
| | | return ((BtmTypeFieldConstant.BASIC_FIELD_MAP.containsKey(attributeLowId) |
| | | && !VciBaseUtil.inArray(new String[]{"id", "name", "description"}, attributeLowId)) |
| | | || BtmTypeFieldConstant.LINK_TYPE_FIELD_MAP.containsKey(attributeLowId) |
| | | || BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP.containsKey(attributeLowId) |
| | | || BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP.containsKey(attributeLowId) |
| | | || BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP.containsKey(attributeLowId)); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥é¾æ¥ç±»å |
| | | * |
| | | * @param linkTypeVOList 龿¥ç±»å |
| | | * @return æ£æ¥ç»æ |
| | | */ |
| | | private List<ModifyAttributeInfo> checkLinkType(List<LinkTypeVO> linkTypeVOList) { |
| | | List<ModifyAttributeInfo> modifyAttributeInfoDOList = new ArrayList<>(); |
| | | linkTypeVOList.stream().filter(s -> !isCompatibilityTable(null,s.getId())).forEach(link -> { |
| | | ModifyAttributeInfo modifyAttributeInfo = new ModifyAttributeInfo(); |
| | | modifyAttributeInfo.setId(link.getId()); |
| | | modifyAttributeInfo.setName(link.getName()); |
| | | modifyAttributeInfo.setTableName(link.getTableName()); |
| | | modifyAttributeInfo.setBusinessType(BusinessTypeEnum.LINK.getValue()); |
| | | // 1. è§å¾åæ°å»ºçï¼ç´æ¥å建ï¼è®°å½å建åå² |
| | | if (!checkTableExistByTableName(link.getTableName())){ |
| | | modifyAttributeInfo.setTaskName(ModifyTableTaskEnum.CREATE.getValue()); |
| | | modifyAttributeInfo.setModifyColumnReason(ModifyTableTaskEnum.CREATE.getValue()); |
| | | }else { |
| | | VciBaseUtil.alertNotNull(link.getAttributes(), "龿¥ç±»å" + link.getId() + "ç屿§"); |
| | | List<DdlTableInDataBaseBO> columnDataInTable = selectTableColumnInfo(link.getTableName()); |
| | | if (CollectionUtils.isEmpty(columnDataInTable)) { |
| | | modifyAttributeInfo.setAddAttributes(link.getAttributes().stream().map(s -> s.getId().toLowerCase().trim()).collect(Collectors.joining(","))); |
| | | modifyAttributeInfo.setTaskName(ModifyTableTaskEnum.EDIT.getValue()); |
| | | modifyAttributeInfo.setModifyColumnReason(ModifyTableTaskEnum.CREATE.getValue()); |
| | | } else { |
| | | // 2. åå¨çæå¤æï¼åæ°å¢å±æ§ã屿§æ´æ¹ã屿§å é¤åå«æä½ |
| | | // 3. 屿§æä½ä¸ç¹å«å¤æ[æ¯å¦æ§å¶çæ¬][æ¯å¦æ§å¶å¯çº§][æ¯å¦æ§å¶çå½å¨æ]æ¥æ·»å 对åºå±æ§ |
| | | Map<String, DdlTableInDataBaseBO> tableColumMap = columnDataInTable.stream().collect(Collectors.toMap(t -> t.getId().toLowerCase().trim(), k -> k)); |
| | | Map<String, LinkTypeAttributeVO> attributeMap = link.getAttributes().stream().collect(Collectors.toMap(t -> t.getId().toLowerCase().trim(), k -> k)); |
| | | List<String> addList = new ArrayList<>(); |
| | | List<String> editList = new ArrayList<>(); |
| | | List<String> deleteList = new ArrayList<>(); |
| | | List<String> beforeList = new ArrayList<>(); |
| | | attributeMap.forEach((k, v) -> { |
| | | String attributeLowId = k.toLowerCase(); |
| | | if (!(BtmTypeFieldConstant.LINK_TYPE_FIELD_MAP.containsKey(attributeLowId))) { |
| | | if (tableColumMap.containsKey(k)) { |
| | | //说æä»¥å乿ï¼é£å°±çæ¯å¦éè¦ä¿®æ¹ |
| | | DdlTableInDataBaseBO columnInDB = tableColumMap.get(k); |
| | | if (columnInDB.getAttributeLength() == null) { |
| | | columnInDB.setAttributeLength(0); |
| | | } |
| | | boolean needEdit = false; |
| | | if (!v.getName().equalsIgnoreCase(columnInDB.getName())) { |
| | | //说æéè¦ä¿®æ¹ |
| | | needEdit = true; |
| | | } |
| | | BtmTypeAttributeVO btmTypeAttributeVO = new BtmTypeAttributeVO(); |
| | | BeanUtil.copy(v, btmTypeAttributeVO); |
| | | if (needEdit || checkNeedEditAttr(btmTypeAttributeVO, columnInDB)) { |
| | | editList.add(v.getId()); |
| | | beforeList.add(columnInDB.getId() + StringPool.SPACE + columnInDB.getAttrDataType() + "(" + columnInDB.getAttributeLength() + ")" + StringPool.SPACE + columnInDB.getNullableFlag() |
| | | + StringPool.SPACE + columnInDB.getPrecisionLength() + StringPool.SPACE + columnInDB.getScaleLength() + StringPool.SPACE + columnInDB.getName()); |
| | | } |
| | | } else { |
| | | addList.add(v.getId()); |
| | | } |
| | | } else { |
| | | //é对é»è®¤å±æ§ï¼å¦æä»¥å没æï¼ç°å¨æå¯ä»¥æ·»å ï¼å¦æä»¥å |
| | | if (!tableColumMap.containsKey(k)) { |
| | | boolean needAddNewField = false; |
| | | if (BtmTypeFieldConstant.LINK_TYPE_FIELD_MAP.containsKey(attributeLowId)) { |
| | | //æ¯é¾æ¥ç±»åç屿§ï¼ä»¥å没æå°±æ·»å ä¸ |
| | | needAddNewField = true; |
| | | } |
| | | if (needAddNewField) { |
| | | addList.add(v.getId()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | tableColumMap.forEach((k, v) -> { |
| | | if (!attributeMap.containsKey(k)) { |
| | | deleteList.add(k); |
| | | } |
| | | }); |
| | | modifyAttributeInfo.setOrderModifyUserName(AuthUtil.getUserAccount()); |
| | | modifyAttributeInfo.setOrderModifyDate(new Date()); |
| | | modifyAttributeInfo.setModifyColumnReason(ModifyTableTaskEnum.CONSISTENCY_CHECK.getValue()); |
| | | modifyAttributeInfo.setTaskName(ModifyTableTaskEnum.CONSISTENCY_CHECK.getValue()); |
| | | modifyAttributeInfo.setAddAttributes(String.join(",", addList)); |
| | | modifyAttributeInfo.setModifyAttributes(String.join(",", editList)); |
| | | modifyAttributeInfo.setDeleteAttributes(String.join(",", deleteList)); |
| | | modifyAttributeInfo.setBeforeModifyAttributes(String.join(",", beforeList)); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | return modifyAttributeInfoDOList; |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¯å¦éè¦ä¿®æ¹å±æ§ |
| | | * |
| | | * @param btmTypeAttributeVO 屿§çæ¾ç¤ºå¯¹è±¡ |
| | | * @param tableInDB æ°æ®åºè¡¨éç对象 |
| | | * @return true表示éè¦ä¿®æ¹ï¼false表示ä¸ä¿®æ¹ |
| | | */ |
| | | private boolean checkNeedEditAttr(BtmTypeAttributeVO btmTypeAttributeVO, DdlTableInDataBaseBO tableInDB) { |
| | | if (tableInDB.getAttributeLength() == null) { |
| | | tableInDB.setAttributeLength(0); |
| | | } |
| | | if (tableInDB.getPrecisionLength() == null) { |
| | | tableInDB.setPrecisionLength(20); |
| | | } |
| | | if (tableInDB.getScaleLength() == null) { |
| | | tableInDB.setScaleLength(0); |
| | | } |
| | | String nullInDb = ""; |
| | | if (YES.equalsIgnoreCase(tableInDB.getNullableFlag())) { |
| | | nullInDb = BooleanEnum.TRUE.getValue(); |
| | | } else if (NO.equalsIgnoreCase(tableInDB.getNullableFlag())) { |
| | | nullInDb = BooleanEnum.FASLE.getValue(); |
| | | } |
| | | if (!(String.valueOf(btmTypeAttributeVO.isNullableFlag()).equalsIgnoreCase(nullInDb))) { |
| | | return true; |
| | | } |
| | | if (StringUtils.isNotBlank(btmTypeAttributeVO.getDefaultValue())) { |
| | | return true; |
| | | } |
| | | |
| | | |
| | | List<VciFieldTypeEnum> fieldTypes = dllMapper.listFieldByColumnStr(tableInDB.getAttrDataType()); |
| | | if (CollectionUtils.isEmpty(fieldTypes)) { |
| | | throw new VciBaseException("æ²¡ææ¾å°å¯¹åºçåæ®µç±»å"); |
| | | } |
| | | Set<String> names = fieldTypes.stream().map(Enum::name).collect(Collectors.toSet()); |
| | | String attributeDataType = btmTypeAttributeVO.getAttrDataType(); |
| | | if (names.size() > 1) { |
| | | return !names.contains(attributeDataType); |
| | | } else { |
| | | VciFieldTypeEnum fieldType = fieldTypes.get(0); |
| | | if (attributeDataType.equalsIgnoreCase(fieldType.name())) { |
| | | switch (fieldType) { |
| | | case VTString: |
| | | if (btmTypeAttributeVO.getAttributeLength().intValue() != tableInDB.getAttributeLength().intValue()) { |
| | | return true; |
| | | } |
| | | break; |
| | | case VTDouble: |
| | | //ä¸è¶
è¿128 |
| | | if (btmTypeAttributeVO.getPrecisionLength().intValue() != tableInDB.getPrecisionLength().intValue()) { |
| | | return true; |
| | | } |
| | | if (btmTypeAttributeVO.getScaleLength().intValue() != tableInDB.getScaleLength().intValue()) { |
| | | return true; |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¸
çä¸å¡ç±»åä¸åæ°æ®åºéä¸ä¸æ ·ç |
| | | * |
| | | * @param differentAttributeList ä¸åç屿§çå表 |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
æ§è¡åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @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)); |
| | | differentAttributeList.forEach(s -> { |
| | | // BtmTypeVO btmType = idBtmTypeMap.get(id); |
| | | if (ModifyTableTaskEnum.CREATE.getValue().equalsIgnoreCase(s.getTaskName())) { |
| | | //ç´æ¥åå»ºè¡¨æ ¼ |
| | | // createDbTableForBtm(btmType); |
| | | createDbTablesById(s.getId()); |
| | | } else { |
| | | String addAttributes = s.getAddAttributes(); |
| | | if (StringUtils.isNotBlank(s.getModifyAttributes()) || StringUtils.isNotBlank(s.getDeleteAttributes())) { |
| | | //éè¦å»å¤ææ¯å¦å¯ä»¥æ´æ¹ |
| | | if (checkTableHasDataByTableName(s.getTableName())) { |
| | | //ææ°æ®çè¯ï¼å¾éè¦å¤æå±æ§æ¯å¦å¯ä»¥ä¿®æ¹ |
| | | if (StringUtils.isNotBlank(s.getDeleteAttributes())) { |
| | | s.setHandleResult("è¡¨æ ¼å卿°æ®ï¼ä¸å
许å é¤å段"); |
| | | return; |
| | | } |
| | | List<DdlTableInDataBaseBO> columnInDbList = selectTableColumnInfo(s.getTableName()); |
| | | Map<String, DdlTableInDataBaseBO> columnInDbMap = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(columnInDbList)) { |
| | | columnInDbMap = columnInDbList.stream().collect(Collectors.toMap(t -> t.getId().toLowerCase(), k -> k)); |
| | | } |
| | | List<BtmTypeAttributeVO> attributeVOList = idBtmTypeMap.getOrDefault(s.getId(), new BtmTypeVO()).getAttributes().stream().filter(vo -> Func.toStrList(",", s.getAddAttributes()).stream().anyMatch(id -> StringUtils.equals(vo.getId().toLowerCase(), id))).collect(Collectors.toList()); |
| | | //æå¯è½ä¹åå¤æçæ¶åæ°æ®åºåå¨ï¼èç°å¨ä¸åå¨äº |
| | | List<String> unExitInDbIdList = new ArrayList<>(); |
| | | Map<String, DdlTableInDataBaseBO> finalColumnInDbMap = columnInDbMap; |
| | | List<BtmTypeAttributeVO> needEditAttributeVOList = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(attributeVOList)) { |
| | | attributeVOList.forEach(t -> { |
| | | if (finalColumnInDbMap.containsKey(t.getId().toLowerCase().trim())) { |
| | | needEditAttributeVOList.add(t); |
| | | } else { |
| | | unExitInDbIdList.add(t.getId()); |
| | | } |
| | | }); |
| | | } |
| | | if (!CollectionUtils.isEmpty(needEditAttributeVOList)) { |
| | | List<BtmTypeAttributeVO> unModifyAttrVOList = needEditAttributeVOList.stream().filter(t -> !checkNotCanEditAttr(t.getAttrDataType(), finalColumnInDbMap.get(t.getId().trim().toLowerCase()))).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(unModifyAttrVOList)) { |
| | | s.setHandleResult("è¡¨æ ¼å卿°æ®ï¼" + unModifyAttrVOList.stream().map(BtmTypeAttributeVO::getId).collect(Collectors.joining(",")) + "è¿äºå段ä¸è½ä¿®æ¹"); |
| | | return; |
| | | } |
| | | needEditAttributeVOList.stream().forEach(t -> { |
| | | String attributeLowerId = t.getId().trim().toLowerCase(); |
| | | DdlTableInDataBaseBO columInDb = finalColumnInDbMap.get(attributeLowerId); |
| | | if (!t.getName().equalsIgnoreCase(columInDb.getName())) { |
| | | ddlMapper.commentColumnTable(s.getTableName(), t.getId(), t.getName()); |
| | | } |
| | | if (columInDb.getAttributeLength() != null && t.getAttributeLength() != null |
| | | && t.getAttributeLength() < columInDb.getAttributeLength()) { |
| | | t.setAttributeLength(columInDb.getAttributeLength()); |
| | | } |
| | | List<BtmTypeAttributeVO> attributeVOS = new ArrayList<>(); |
| | | |
| | | boolean nowNeedNull = false; |
| | | if (!YES.equalsIgnoreCase(columInDb.getNullableFlag()) && !t.isNullableFlag()) { |
| | | //说æä»¥åæ¯ä¸è½ä¸ºç©ºç,使¯ä»¥å乿¯ä¸ä¸ºç©ºçï¼ä¿®æ¹ä¼æ¥éï¼æä»¥è¿ä¸ªè°æ´ä¸ä¸ |
| | | t.setNullableFlag(true); |
| | | } else if (!YES.equalsIgnoreCase(columInDb.getNullableFlag()) && t.isNullableFlag()) { |
| | | //以åä¸ä¸ºç©ºï¼ç°å¨ä¸ºç©º |
| | | nowNeedNull = true; |
| | | } |
| | | attributeVOS.add(t); |
| | | String attributeSql = getCreateSqlByAttributeForBtm(attributeVOS); |
| | | if (nowNeedNull) { |
| | | attributeSql += StringPool.SPACE + "null" + StringPool.SPACE; |
| | | } |
| | | ddlMapper.modifyTableBySql(s.getTableName(), attributeSql); |
| | | }); |
| | | } |
| | | if (!CollectionUtils.isEmpty(unExitInDbIdList)) { |
| | | if (StringUtils.isBlank(addAttributes)) { |
| | | addAttributes = String.join(",", unExitInDbIdList); |
| | | } else { |
| | | addAttributes += "," + String.join(",", unExitInDbIdList); |
| | | ; |
| | | } |
| | | } |
| | | } else { |
| | | //è¯´ææ²¡ææ°æ®ï¼é£å¯ä»¥æä¿®æ¹çååå é¤çåé½å é¤ï¼ç¶åéæ°æ·»å |
| | | if (StringUtils.isNotBlank(s.getModifyAttributes())) { |
| | | List<BtmTypeAttributeVO> attributeVOList = idBtmTypeMap.getOrDefault(s.getId(), new BtmTypeVO()).getAttributes().stream().filter(vo -> Func.toStrList(",", s.getModifyAttributes()).stream().anyMatch(id -> StringUtils.equals(vo.getId(), id))).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(attributeVOList)) { |
| | | attributeVOList.forEach(t -> { |
| | | List<BtmTypeAttributeVO> attributeVOS = new ArrayList<>(); |
| | | attributeVOS.add(t); |
| | | dropColumnByName(s.getTableName(), t.getId()); |
| | | addColumnForTable(s.getTableName(), attributeVOS); |
| | | ddlMapper.commentColumnTable(s.getTableName(), t.getId(), t.getName()); |
| | | }); |
| | | } |
| | | } |
| | | //éè¦å é¤çå |
| | | if (StringUtils.isNotBlank(s.getDeleteAttributes())) { |
| | | List<String> attributeIdList = VciBaseUtil.str2List(s.getDeleteAttributes()); |
| | | Optional.ofNullable(attributeIdList).orElseGet(ArrayList::new).forEach(t -> { |
| | | dropColumnByName(s.getTableName(), t); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | if (StringUtils.isNotBlank(addAttributes)) { |
| | | //åªæ¯æ·»å 屿§å¼ |
| | | if (BusinessTypeEnum.LINK.getValue().equalsIgnoreCase(s.getBusinessType())) { |
| | | List<LinkTypeAttributeVO> attributeVOList = idLinkTypeMap.getOrDefault(s.getId(), new LinkTypeVO()).getAttributes().stream().filter(vo -> Func.toStrList(",", s.getAddAttributes()).stream().anyMatch(id -> StringUtils.equals(vo.getId(), id))).collect(Collectors.toList()); |
| | | //æ¯é¾æ¥ç±»å |
| | | // List<LinkTypeAttributeVO> attributeVOList = linkTypeService.listAttributeVOByIdsForLink(s.getId(), VciBaseUtil.str2List(s.getAddAttributes())); |
| | | addColumn2TableForLink(attributeVOList); |
| | | } else { |
| | | List<BtmTypeAttributeVO> attributeVOList = idBtmTypeMap.getOrDefault(s.getId(), new BtmTypeVO()).getAttributes().stream().filter(vo -> Func.toStrList(",", s.getAddAttributes()).stream().anyMatch(id -> StringUtils.equals(vo.getId(), id))).collect(Collectors.toList()); |
| | | addColumn2TableForBtm(attributeVOList); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private boolean checkNotCanEditAttr(String attributeDataType, DdlTableInDataBaseBO tableInDB) { |
| | | if (tableInDB != null && StringUtils.isNotBlank(attributeDataType)) { |
| | | List<VciFieldTypeEnum> fieldTypeEnums = dllMapper.listFieldByColumnStr(tableInDB.getAttrDataType()); |
| | | Set<String> names = fieldTypeEnums.stream().map(Enum::name).collect(Collectors.toSet()); |
| | | if (names.contains(attributeDataType)) { |
| | | return true; |
| | | } |
| | | return true; |
| | | } else { |
| | | //å ä¸ºæ°æ®åºé没æè¿ä¸ªè¡¨æ ¼æ¶ |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åæ°æ®åºä¸ææçè¡¨æ ¼ |
| | | * |
| | | * @return è¡¨æ ¼çåç§°ï¼å
¨æ¯å¤§å |
| | | */ |
| | | @Override |
| | | public List<String> listAllTableName() { |
| | | return ddlMapper.selectAllTableName(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°æ®åºä¸çè¡¨æ ¼ä¿¡æ¯ |
| | | * |
| | | * @param tableNamesCollections æ°æ®åºè¡¨åéå |
| | | * @return 卿°æ®åºä¸çä¿¡æ¯ |
| | | * @throws VciBaseException åæ°ä¸ºç©ºæè
æ°æ®åºè¡¨ä¸åå¨çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public List<DdlTableBO> listTableInfoInDB(Collection<String> tableNamesCollections) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull("æ°æ®åºè¡¨åç§°ä¸è½ä¸ºç©º", tableNamesCollections); |
| | | List<DdlTableBO> tableBOList = new ArrayList<>(); |
| | | tableNamesCollections.stream().forEach(s -> { |
| | | tableBOList.add(ddlMapper.selectTableComment(s)); |
| | | }); |
| | | return tableBOList; |
| | | } |
| | | |
| | | /** |
| | | * å¯¼åºæ°æ®åºä¸çè¡¨æ ¼ä¿¡æ¯å°excelæä»¶ |
| | | * |
| | | * @param tableNamesCollections è¡¨æ ¼åç§°çéå |
| | | * @param merge åå¹¶è¡¨æ ¼åç§° |
| | | * @return excelçæä»¶åç§° |
| | | * @throws VciBaseException èé£ä¸ºç©ºæè
æ°æ®åºè¡¨ä¸åå¨çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public String exportDataBase2File(Collection<String> tableNamesCollections, boolean merge) throws VciBaseException { |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * è·åå卿件æéè¦çä¸´æ¶æä»¶å¤¹ï¼æä»¶å¤¹ä¸å·²ç»å
å«äº |
| | | * |
| | | * @return æä»¶å¤¹çå°åï¼å¦æé
ç½®æä»¶æ²¡æé
ç½®ï¼åé»è®¤è¿åå½åé¡¹ç®æå¨çæä»¶å¤¹ |
| | | */ |
| | | @Override |
| | | public String getTempFolder() { |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * å¯¼åºæ°æ®åºä¸çè¡¨æ ¼ä¿¡æ¯å°wordæä»¶ä¸ |
| | | * |
| | | * @param tableNamesCollections è¡¨æ ¼åç§°çéå |
| | | * @return wordçæä»¶åç§° |
| | | * @throws VciBaseException èé£ä¸ºç©ºæè
æ°æ®åºè¡¨ä¸åå¨çæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public String exportDataBase2Word(List<String> tableNamesCollections) throws VciBaseException { |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ·è´æ°æ®å°word模æ¿ä¸ |
| | | * |
| | | * @param tableDataBO è¦åå
¥çæ°æ® |
| | | * @return word æä»¶è·¯å¾ |
| | | *//* |
| | | @Override |
| | | public String writeDataToWord(WordMergeStartTableDataBO tableDataBO) { |
| | | return null; |
| | | }*/ |
| | | |
| | | /** |
| | | * 夿æ¯å¦ä¸ºå
¼å®¹æ§ç表ï¼è¿äºè¡¨ä¸åºè¯¥è¢«å建åä¿®æ¹ |
| | | * |
| | | * @param btmTypeId ä¸å¡ç±»åçè±æåç§° |
| | | * @param linkTypeId ä¸å¡ç±»åç䏿åç§° |
| | | * @return true 表示为å
¼å®¹æ§ç表ï¼ç¨æ·ï¼è§è²ï¼é¨é¨ï¼æéè¿äº |
| | | */ |
| | | @Override |
| | | public boolean isCompatibilityTable(String btmTypeId, String linkTypeId) { |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * ä¸å¡ç±»åæ°æ®åºæ°å¢æä¿®æ¹è¡¨ |
| | | * |
| | | * @param ddlDTO ä¸å¡ç±»å龿¥ç±»åä¼ è¾å¯¹è±¡ |
| | | * @return æ§è¡ç»æ |
| | | */ |
| | | @Override |
| | | public R<List<ModifyAttributeInfo>> submit(BtmAndLinkTypeDdlDTO ddlDTO) { |
| | | try { |
| | | List<ModifyAttributeInfo> changedList = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(ddlDTO.getBtmTypeList())) { |
| | | List<BtmTypeVO> btmTypeList = ddlDTO.getBtmTypeList(); |
| | | putBtm(btmTypeList.toArray(new BtmTypeVO[0])); |
| | | changedList.addAll(checkDifferent(btmTypeList, null)); |
| | | removeBtm(btmTypeList.toArray(new BtmTypeVO[0])); |
| | | } |
| | | if (!CollectionUtils.isEmpty(ddlDTO.getLinkTypeList())) { |
| | | List<LinkTypeVO> linkTypeList = ddlDTO.getLinkTypeList(); |
| | | putLink(linkTypeList.toArray(new LinkTypeVO[0])); |
| | | changedList.addAll(checkDifferent(null,linkTypeList)); |
| | | removeLink(linkTypeList.toArray(new LinkTypeVO[0])); |
| | | } |
| | | R<List<ModifyAttributeInfo>> result = R.success("æ°æ®åºæä½æå"); |
| | | result.setData(changedList); |
| | | return result; |
| | | } catch (ServiceException e) { |
| | | throw new RuntimeException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æè¡¨åè·åè¡¨ä¿¡æ¯ |
| | | * |
| | | * @param tableName 表å |
| | | * @return è¡¨ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public DdlTableBO getTableColumnByTableName(String tableName) { |
| | | VciBaseUtil.alertNotNull(tableName, "表å"); |
| | | DdlTableBO tableBO = getTableInfoByTableName(tableName); |
| | | List<DdlTableInDataBaseBO> columnInfo = selectTableColumnInfo(tableName); |
| | | tableBO.setColumns(columnInfo); |
| | | return tableBO; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°æ®åºä¸è¡¨æ ¼çåæ®µä¿¡æ¯ |
| | | * |
| | | * @param tableName è¡¨æ ¼çåç§° |
| | | * @return æ°æ®åºè¡¨çåæ®µä¿¡æ¯ |
| | | */ |
| | | private List<DdlTableInDataBaseBO> selectTableColumnInfo(String tableName) { |
| | | VciBaseUtil.alertNotNull(tableName, "è¡¨æ ¼åç§°"); |
| | | return ddlMapper.selectTableColumnInfo(tableName); |
| | | } |
| | | |
| | | /** |
| | | * 表åè·åè¡¨ä¿¡æ¯ |
| | | * |
| | | * @param tableName 表å |
| | | * @return è¡¨ä¿¡æ¯ |
| | | */ |
| | | private DdlTableBO getTableInfoByTableName(String tableName) { |
| | | VciBaseUtil.alertNotNull(tableName, "è¡¨æ ¼åç§°"); |
| | | return ddlMapper.selectTableComment(tableName); |
| | | } |
| | | |
| | | /** |
| | | * è·åææè¡¨ä¿¡æ¯ |
| | | * |
| | | * @return 表信æ¯éå |
| | | */ |
| | | @Override |
| | | public List<BtmTypeVO> getAllTableInfo() { |
| | | List<String> allTableName = listAllTableName(); |
| | | if (!CollectionUtils.isEmpty(allTableName)) { |
| | | List<DdlTableBO> allTableBO = listTableInfoInDB(allTableName); |
| | | List<BtmTypeVO> btmTypeVOList = new ArrayList<>(); |
| | | allTableBO.forEach(table -> { |
| | | BtmTypeVO vo = new BtmTypeVO(); |
| | | vo.setTableName(table.getTableName()); |
| | | vo.setDescription(table.getTableDesc()); |
| | | List<DdlTableInDataBaseBO> columns = selectTableColumnInfo(table.getTableName()); |
| | | List<BtmTypeAttributeVO> attributes = new ArrayList<>(); |
| | | columns.forEach(col -> { |
| | | BtmTypeAttributeVO attributeVO = new BtmTypeAttributeVO(); |
| | | attributeVO.setId(col.getId()); |
| | | attributeVO.setName(col.getName()); |
| | | attributeVO.setNullableFlag(col.getNullableFlag()); |
| | | attributeVO.setAttributeLength(col.getAttributeLength()); |
| | | attributeVO.setPrecisionLength(col.getPrecisionLength()); |
| | | attributeVO.setScaleLength(col.getScaleLength()); |
| | | VciFieldTypeEnum field = dllMapper.getFieldTypeByColumnStr(col.getAttrDataType(), col.getAttributeLength()); |
| | | if (field != null){ |
| | | attributeVO.setAttrDataType(field.name()); |
| | | } |
| | | attributes.add(attributeVO); |
| | | }); |
| | | vo.setAttributes(attributes); |
| | | btmTypeVOList.add(vo); |
| | | }); |
| | | return btmTypeVOList; |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | } |