From 4d571ecaabae01dc825f01ce92ff4a5023f56fb0 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期三, 10 七月 2024 17:03:39 +0800
Subject: [PATCH] 代码提交
---
Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java | 105 ++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 77 insertions(+), 28 deletions(-)
diff --git a/Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java
index 3a8e185..fe24a1a 100644
--- a/Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-ddl/src/main/java/com/vci/ubcs/ddl/service/impl/DdlServiceImpl.java
@@ -1,16 +1,13 @@
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;
@@ -36,6 +33,7 @@
import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotNull;
+import java.rmi.ServerException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@@ -64,13 +62,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";
@@ -185,6 +185,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());
+ });
+ }
+ }
+ /**
* 鑾峰彇鍒涘缓鐨剆ql璇彞涓睘鎬ч儴鍒�
*
* @param attributeVOList 灞炴�х殑绔嬬
@@ -196,7 +216,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(","));
+ }
+
+ /**
+ * 鑾峰彇鍒涘缓鐨剆ql璇彞涓睘鎬ч儴鍒�
+ *
+ * @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 +249,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 +570,7 @@
modifyAttributeInfo.setBeforeModifyAttributes(String.join(",", beforeList));
}
}
+ modifyAttributeInfoDOList.add(modifyAttributeInfo);
});
return modifyAttributeInfoDOList;
}
@@ -641,6 +672,7 @@
}
}
+ modifyAttributeInfoDOList.add(modifyAttributeInfo);
});
return modifyAttributeInfoDOList;
}
@@ -719,8 +751,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())) {
@@ -732,9 +764,9 @@
if (StringUtils.isNotBlank(s.getModifyAttributes()) || StringUtils.isNotBlank(s.getDeleteAttributes())) {
//闇�瑕佸幓鍒ゆ柇鏄惁鍙互鏇存敼
if (checkTableHasDataByTableName(s.getTableName())) {
- //鏈夋暟鎹殑璇濓紝寰楅渶瑕佸垽鏂睘鎬ф槸鍚﹀彲浠ヤ慨鏀�
+ //鏈夋暟鎹殑璇濓紝寰楅渶瑕佸垽鏂睘鎬ф槸鍚﹀彲浠ュ垹闄�
if (StringUtils.isNotBlank(s.getDeleteAttributes())) {
- s.setHandleResult("琛ㄦ牸瀛樺湪鏁版嵁锛屼笉鍏佽鍒犻櫎瀛楁");
+ s.setHandleResult("琛ㄦ牸瀛樺湪鏁版嵁锛屼笉鍏佽鍒犻櫎"+ s.getDeleteAttributes() +"瀛楁");
return;
}
List<DdlTableInDataBaseBO> columnInDbList = selectTableColumnInfo(s.getTableName());
@@ -943,7 +975,7 @@
* @return 鎵ц缁撴灉
*/
@Override
- public R<List<ModifyAttributeInfo>> submit(BtmAndLinkTypeDdlDTO ddlDTO) {
+ public R<List<ModifyAttributeInfo>> submit(BtmAndLinkTypeDdlDTO ddlDTO) throws ServerException {
try {
List<ModifyAttributeInfo> changedList = new ArrayList<>();
if (!CollectionUtils.isEmpty(ddlDTO.getBtmTypeList())) {
@@ -958,11 +990,28 @@
changedList.addAll(checkDifferent(null,linkTypeList));
removeLink(linkTypeList.toArray(new LinkTypeVO[0]));
}
- R<List<ModifyAttributeInfo>> result = R.success("鏁版嵁搴撴搷浣滄垚鍔�");
+ String msg = "鏁版嵁搴撴搷浣滄垚鍔�";
+ R<List<ModifyAttributeInfo>> result = new R<>();
+ if((!changedList.isEmpty())&&Func.isEmpty(changedList.get(0).getHandleResult())){
+ result = R.success(msg);
+ }else {
+ result = R.fail(changedList.get(0).getHandleResult());
+ }
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 +1073,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());
--
Gitblit v1.9.3