|
@@ -76,7 +76,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
list.add("create_time datetime NULL DEFAULT NULL COMMENT '创建时间'");
|
|
|
list.add("update_by varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '更新者'");
|
|
|
list.add("update_time datetime NULL DEFAULT NULL COMMENT '更新时间'");
|
|
|
- list.add("del_flag char(1) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)'");
|
|
|
+ list.add("del_flag char(1) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '' COMMENT '删除标志(0代表存在 2代表删除)'");
|
|
|
tableInfoMapper.createMysqlTable(tableName, tableComment, list);
|
|
|
}
|
|
|
|
|
@@ -345,6 +345,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void updateMysqlTable(Map<String, Object> map) {
|
|
|
String tableName = (String) map.get("tableName");
|
|
|
String tableComment = (String) map.get("tableComment");
|
|
@@ -399,6 +400,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void updateSqlserverTable(Map<String, Object> map) {
|
|
|
String tableName = (String) map.get("tableName");
|
|
|
String tableComment = (String) map.get("tableComment");
|
|
@@ -431,10 +433,48 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
}
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //暂存要删除的表结构信息
|
|
|
+ List<TableInfo> tableInfoList = tableFieldInfo(map);
|
|
|
// 删除表
|
|
|
tableInfoMapper.dropSqlserverTable(tableName);
|
|
|
- // 新增表
|
|
|
- tableInfoMapper.updateSqlserverTable(tableName, list, descriptionList, tableComment);
|
|
|
+ try {
|
|
|
+ // 新增表
|
|
|
+ tableInfoMapper.updateSqlserverTable(tableName, list, descriptionList, tableComment);
|
|
|
+ }catch (Exception e){
|
|
|
+ List<String> list1 = tableInfoList.stream().map(filed -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsNull()) {
|
|
|
+ stringBuilder.append("NOT NULL ");
|
|
|
+ }
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
+ stringBuilder.append("PRIMARY KEY ");
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
+ stringBuilder.append("IDENTITY(1,1) ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<String> descriptionList1 = tableInfoList.stream().map(filed -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ if (StringUtils.hasLength(filed.getFieldDescription())) {
|
|
|
+ stringBuilder.append("EXECUTE sp_addextendedproperty N'MS_Description',")
|
|
|
+ .append("'" + filed.getFieldDescription() + "'")
|
|
|
+ .append(", N'user', N'dbo', N'table', N")
|
|
|
+ .append("'" + tableName + "'")
|
|
|
+ .append(", N'column', N")
|
|
|
+ .append("'" + filed.getFieldName() + "'");
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 新增表
|
|
|
+ tableInfoMapper.updateSqlserverTable(tableName, list1, descriptionList1, tableComment);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -533,10 +573,58 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //暂存要删除表的表结构
|
|
|
+ List<TableInfo> tableInfoList = tableFieldInfo(map);
|
|
|
+ //删除表
|
|
|
tableInfoMapper.dropDmTable(databaseName, tableName);
|
|
|
- tableInfoMapper.createDmTable(databaseName, tableName, list);
|
|
|
- descriptionList.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
|
|
|
- tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
|
|
|
+
|
|
|
+ try {
|
|
|
+ //创建表
|
|
|
+ tableInfoMapper.createDmTable(databaseName, tableName, list);
|
|
|
+ //添加表字段注释
|
|
|
+ descriptionList.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
|
|
|
+ //添加表注释
|
|
|
+ tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
|
|
|
+ }catch (Exception e){
|
|
|
+ List<String> descriptionList1 = new ArrayList<>();
|
|
|
+ List<String> list1 = tableInfoList.stream().map(filed -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
+ stringBuilder.append("IDENTITY(1,1) ");
|
|
|
+ }
|
|
|
+ stringBuilder.append("PRIMARY KEY ");
|
|
|
+ }
|
|
|
+ if (filed.getIsNull()) {
|
|
|
+ stringBuilder.append("NOT NULL ");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.hasLength(filed.getFieldDescription())) {
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ builder.append("COMMENT ON COLUMN \"")
|
|
|
+ .append(databaseName)
|
|
|
+ .append("\".\"")
|
|
|
+ .append(tableName)
|
|
|
+ .append("\".\"")
|
|
|
+ .append(filed.getFieldName() + "\" IS ")
|
|
|
+ .append("'" + filed.getFieldDescription() + "'");
|
|
|
+ descriptionList.add(builder.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return stringBuilder.toString();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //创建表
|
|
|
+ tableInfoMapper.createDmTable(databaseName, tableName, list1);
|
|
|
+ //添加表字段注释
|
|
|
+ descriptionList1.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
|
|
|
+ //添加表注释
|
|
|
+ tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|