diff --git a/root/index.html b/root/index.html index 3d5f5e6..8f3893a 100644 --- a/root/index.html +++ b/root/index.html @@ -106,6 +106,7 @@ {url:"/metadata/metaLink.html", name:"实体关系", icon:"icon-branch"}, {url:"/metadata/metaService.html", name:"业务管理", icon: "icon-sliders"}, {url:"/metadata/dataList.html", name:"业务预览", icon:"icon-window-alt"}, + /*{url: "/oth/ddlCompare.html", name: "DDL-Compare", icon: "icon-table"},*/ /*{url:"/metadata/dict.html", name:"字典管理", icon:"icon-usecase"},*/ /*{url:"/content/list.html", name:"游戏查询", icon:"icon-usecase"}, {url:"/content/funs.html", name:"平台功能", icon:"icon-usecase"},*/ diff --git a/root/oth/ddlCompare.html b/root/oth/ddlCompare.html new file mode 100644 index 0000000..7928a4a --- /dev/null +++ b/root/oth/ddlCompare.html @@ -0,0 +1,198 @@ + + + + + + + +
+ 数据源A + + +
+ 数据源B + + + +
实体表(Meta-Table)
+ + +
+
+
+ HAO +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
字段备注数据类型默认值可空
file_download_num下载次数int(11)0YES
xxxxxxxxxx
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
字段备注数据类型默认值可空
file_download_num下载次数int(11)0YES
xxxxxxxxxx
+
+ + + + +
+ + diff --git a/src/main/java/net/tccn/plat/_DbService.java b/src/main/java/net/tccn/plat/_DbService.java index 1d3b785..77faeaf 100644 --- a/src/main/java/net/tccn/plat/_DbService.java +++ b/src/main/java/net/tccn/plat/_DbService.java @@ -100,4 +100,113 @@ public class _DbService extends BaseService { return jBean; } + + // 比对表结构 + /*@RestMapping(name = "table_compare", comment = "对比表结构") + public Kv tableCompare(String dbPlatA, String dbPlatB, String catalog) { + String sql = String.format("SELECT table_name 'tableName', column_name 'columnName', column_comment 'columnComment',column_type 'columnType',column_default 'columnDefault', is_nullable 'isNullable'" + + " FROM INFORMATION_SCHEMA.COLUMNS" + + " WHERE table_schema = '%s'", catalog); + + List listA = MetaKit.getDbKit(dbPlatA, catalog).queryList(sql, Column.class); + List listB = MetaKit.getDbKit(dbPlatB, catalog).queryList(sql, Column.class); + + Map> ddlA = Utils.group(listA, Column::getTableName); + Map> ddlB = Utils.group(listB, Column::getTableName); + + + Set same = new HashSet<>(); // table_name; + List> differ = new ArrayList<>(); // 不相同的表,以及对应 A、B库的字段信息如:[{"tableName": "", A: [{}], B: [{}], dif: [{}] }] + Kv> without = Kv.of(); // A,B不在对方库的表,如:{A: [{}], B: [{}]} + + + ddlA.forEach((tableName, columns) -> { + // A 有,B 无 + if (!ddlB.containsKey(tableName)) { + List tables = without.getOrDefault("A", new ArrayList<>()); + tables.add(new Table(tableName, columns)); + without.set("A", tables); + } + + // TODO 相同 、差异比较 + List columns2 = ddlB.get(tableName); + if (columns2 == null) { + return; + } + List> dif = new ArrayList<>(); + for (Column column : columns) { + Column column2 = columns2.stream().filter(c -> c.getColumnName().equals(column.getColumnName())).findFirst().orElse(null); + + if (column2 == null) { + dif.add(Kv.of("column", column.getColumnName()).set("diff", "column not exist in B")); + } else { + if (!column.getColumnName().equals(column2.getColumnName())) { + dif.add(Kv.of("column", column.getColumnName()).set( "diff", "column name not same")); + } + if (!column.getColumnComment().equals(column2.getColumnComment())) { + dif.add(Kv.of("column", column.getColumnName()).set( "diff", "column comment not same")); + } + if (!column.getColumnType().equals(column2.getColumnType())) { + dif.add(Kv.of("column", column.getColumnName()).set( "diff", "column type not same")); + } + if (!column.getColumnDefault().equals(column2.getColumnDefault())) { + dif.add(Kv.of("column", column.getColumnName()).set( "diff", "column default not same")); + } + if (!column.getIsNullable().equals(column2.getIsNullable())) { + dif.add(Kv.of("column", column.getColumnName()).set( "diff", "column nullable not same")); + } + } + } + // columns2 中有 columns 中没有 + for (Column column2 : columns2) { + if (!columns.stream().anyMatch(c -> c.getColumnName().equals(column2.getColumnName()))) { + dif.add(Kv.of("column", column2.getColumnName()).set( "diff", "column not exist in A")); + } + } + + if (dif.size() > 0) { + differ.add(Kv.of("tableName", tableName).set( "A", columns).set( "B", columns2).set( "dif", dif)); + } + }); + // B 有,A 无 + ddlB.forEach((tableName, columns) -> { + if (ddlA.containsKey(tableName)) { + return; + } + List
tables = without.getOrDefault("B", new ArrayList<>()); + tables.add(new Table(tableName, columns)); + without.set("B", tables); + }); + + Kv retKv = Kv.of(); // 返回结果 + retKv.set("same", same); + retKv.set("differ", differ); + retKv.set("without", without); + return retKv; + } + + @Getter + @Setter + static class Table { + String tableName; + List columns; + + public Table(String tableName, List columns) { + this.tableName = tableName; + this.columns = columns; + } + } + + @Getter + @Setter + static class Column { + @ConvertColumn(ignore = true) + private String tableName; + private String columnName; + private String columnComment; + private String columnType; + private String columnDefault; + private String isNullable; + }*/ + }