1、解决默认提供的删除功能异常 2、重构DbKit,解决存在的catalog未设置导致的查询失败

This commit is contained in:
2019-06-13 11:27:22 +08:00
parent 7590f73651
commit 61a90c8591
10 changed files with 85 additions and 39 deletions

View File

@@ -299,7 +299,30 @@
},
dealFieldFmt(bean, colFmt) { //处理字典数据 及 自定义函数处理数据
if (colFmt["fmt"]) {
let v = ""
if (colFmt.inType == "DICT") {
// 取字典值返回
v = bean[colFmt["col"]]
}
else if (colFmt.inType == "INPUT_DAY") {
v = bean[colFmt["col"]]
}
else if (colFmt.inType == "INPUT_TIME") {
v = bean[colFmt["col"]]
}
else if (colFmt.inType == "INPUT_FUNC") {
v = bean[colFmt["col"]]
}
else {
v = bean[colFmt["col"]]
}
return v + " -> "+colFmt.inType
/*if (colFmt["fmt"]) {
let fmt = colFmt["fmt"]
let cate = ""
if (fmt.indexOf("|") > 0) {
@@ -323,7 +346,7 @@
} else {
//console.log(`k-v:${colFmt["col"]}-${bean[colFmt["col"]]}`)
return bean[colFmt["col"]]
}
}*/
},
dealField(bean, field) {
let str = "";

View File

@@ -224,7 +224,6 @@
}
}
console.log(itemEdit)
this.itemEdit = itemEdit;
},
deep: true
@@ -289,10 +288,10 @@
$('#show>table>tbody').sortable({
selector: 'tr',
finish: function (e) {
var rows = e.list;
var shows = [];
for (var i = 0; i < rows.length; i++) {
var item = $(rows[i]).find("input[name='name']").val();
let rows = e.list;
let shows = [];
for (let i = 0; i < rows.length; i++) {
let item = $(rows[i]).find("input[name='name']").val();
shows.push(item);
}
vm.meta.shows = shows;
@@ -302,10 +301,10 @@
$('#import>table>tbody').sortable({
selector: 'tr',
finish: function (e) {
var rows = e.list;
var shows = [];
for (var i = 0; i < rows.length; i++) {
var item = $(rows[i]).find("input[name='name']").val();
let rows = e.list;
let shows = [];
for (let i = 0; i < rows.length; i++) {
let item = $(rows[i]).find("input[name='name']").val();
shows.push(item);
}
vm.meta.imports = shows;
@@ -329,10 +328,10 @@
$('#filter>table>tbody').sortable({
selector: 'tr',
finish: function (e) {
var rows = e.list;
var filterArr = [];
for (var i = 0; i < rows.length; i++) {
var item = $(rows[i]).find("input[name='name']").val();
let rows = e.list;
let filterArr = [];
for (let i = 0; i < rows.length; i++) {
let item = $(rows[i]).find("input[name='name']").val();
filterArr.push(item);
}
vm.filterArr = filterArr;
@@ -399,7 +398,8 @@
}
},
dealTableLabel(table) {
return `${table.name} [${table.comment}] (${table.linkCount})`
// (${table.linkCount})
return `${table.name} [${table.comment}]`
},
getFieldLabel (col) {
if (!col) {

View File

@@ -41,6 +41,11 @@
</tr>
</tbody>
</table>
<div v-show="!row || list.rows == 0" style="text-align: center">
<img src="../res/img/none.png">
<p>暂无数据</p>
</div>
</div>
<!-- modal-tpl -->

View File

@@ -208,7 +208,7 @@ public final class MetaKit {
String comment = metaService.getComment();
//List<Field> items = new ArrayList<>();
Kv<String, Kv<String, Kv>> _items2 = Kv.of();
/*Kv<String, Kv<String, Kv>> _items2 = Kv.of();
metaTables.forEach((k, v) -> {
Kv<String, Kv> _items = Kv.of();
v.getItems().forEach(x -> {
@@ -222,7 +222,7 @@ public final class MetaKit {
});
_items2.set(k, _items);
});
});*/
//shows
/*List _shows = new ArrayList();
@@ -232,7 +232,7 @@ public final class MetaKit {
.filter(y -> x.split("[.]")[1].equals(y.getName()))
.findFirst().ifPresent(y -> _shows.add(Kv.of("col", x).set("order", true)));
});*/
List<Kv> _shows = shows.stream().map(x -> {
/*List<Kv> _shows = shows.stream().map(x -> {
Kv kv = Kv.of();
kv.putAll(x);
@@ -246,7 +246,7 @@ public final class MetaKit {
kv.remove("inType");
kv.remove("inExt");
return kv;
}).collect(Collectors.toList());
}).collect(Collectors.toList());*/
//filters
@@ -337,7 +337,7 @@ public final class MetaKit {
return Kv.of()
.set("pk", _pks.toString())
.set("title", comment)
.set("items", _items2)
//.set("items", _items2)
.set("shows", shows)
.set("filters", _filters)
.set("edits", edits)
@@ -460,11 +460,11 @@ public final class MetaKit {
return tables;
}
public static DbKit getDbKit(String dbPlatId) {
/*public static DbKit getDbKit(String dbPlatId) {
Optional<DbAccount> dbAccount = dbPlats.stream().filter(x -> x.getKey().equals(dbPlatId)).findAny();
return new DbKit(dbAccount.get());
}
}*/
public static DbKit getDbKit(String dbPlatId, String catalog) {
Optional<DbAccount> dbAccount = dbPlats.stream().filter(x -> x.getKey().equals(dbPlatId)).findAny();
return new DbKit(dbAccount.get(), catalog);

View File

@@ -25,7 +25,7 @@ public class DbExecutors {
MetaTable mainTable = MetaKit.getMetaTableByAlias(metaService.getTable());
DbKit dbKit = MetaKit.getDbKit(mainTable.getDbPlatId());
DbKit dbKit = MetaKit.getDbKit(mainTable.getDbPlatId(), mainTable.getCatalog());
//System.out.printf("----------------%n countSql:%s%n findSql:%s%n----------------%n", sqls[0], sqls[1]);
CompletableFuture<Integer> countFuture = CompletableFuture.supplyAsync(() -> dbKit.queryColumn(sqls[0], int.class));
@@ -42,7 +42,7 @@ public class DbExecutors {
MetaTable mainTable = MetaKit.getMetaTableByAlias(metaService.getTable());
DbKit dbKit = MetaKit.getDbKit(mainTable.getDbPlatId());
DbKit dbKit = MetaKit.getDbKit(mainTable.getDbPlatId(), mainTable.getCatalog());
String delSql = PARSER.parseDel(name, data, token);
dbKit.exetute(delSql);

View File

@@ -14,7 +14,7 @@ public class DbKit implements DbSource{
private DbSource dbSource;
private String catalog;
public DbKit(DbAccount dbAccount) {
/*public DbKit(DbAccount dbAccount) {
this.dbAccount = dbAccount;
try {
DbSource dbSource = Liangs.getDbSource(DbSource.class, dbAccount.getCate());
@@ -24,13 +24,18 @@ public class DbKit implements DbSource{
} catch (Exception e) {
throw new IllegalArgumentException(String.format("创建DbKit失败数据库类型[cate:%s]未知", dbAccount.getCate()));
}
}
}*/
public DbKit(DbAccount dbAccount, String catalog) {
this.dbAccount = dbAccount;
this.catalog = catalog;
if ("mysql".equalsIgnoreCase(dbAccount.getCate())) {
dbSource = new DbSourceMysql(dbAccount, catalog);
} else {
try {
DbSource dbSource = Liangs.getDbSource(DbSource.class, dbAccount.getCate());
dbSource.setDbAccount(dbAccount);
dbSource.setCatalog(catalog);
this.dbSource = dbSource;
} catch (Exception e) {
throw new IllegalArgumentException(String.format("创建DbKit失败数据库类型[cate:%s]未知", dbAccount.getCate()));
}
}
@@ -38,7 +43,14 @@ public class DbKit implements DbSource{
@Override
public void setDbAccount(DbAccount dbAccount) {
// nothing to do
this.dbAccount = dbAccount;
dbSource.setDbAccount(dbAccount);
}
@Override
public void setCatalog(String catelog) {
this.catalog = catelog;
dbSource.setCatalog(catalog);
}
@Override

View File

@@ -11,6 +11,7 @@ import java.util.List;
public interface DbSource extends IService {
void setDbAccount(DbAccount dbAccount);
void setCatalog(String catelog);
<T> List<T> findList(String sql, Class<T> type);

View File

@@ -32,6 +32,11 @@ public class DbSourceMysql implements DbSource {
this.accountKey = dbAccount.accountKey();
}
@Override
public void setCatalog(String catalog) {
this.catalog = catalog;
}
public DbSourceMysql(DbAccount dbAccount) {
this.dbAccount = dbAccount;
this.accountKey = dbAccount.accountKey();
@@ -159,7 +164,7 @@ public class DbSourceMysql implements DbSource {
//fixme: lxy 处理连接超过8小时失效问题
private Connection connection() {
Connection connection = connection(0);
if (connection != null && catalog != null) {
if (connection != null && catalog != null && !catalog.isEmpty()) {
try {
connection.setCatalog(catalog); //还回连接的时候是否需要重置catalog 后续观察
} catch (SQLException e) {

View File

@@ -26,9 +26,9 @@ public class _DbService extends BaseService {
JBean jBean = new JBean();
DbKit dbKit = null;
if (dbAccount != null) {
dbKit = new DbKit(dbAccount);
dbKit = new DbKit(dbAccount, "");
} else {
dbKit = MetaKit.getDbKit(dbPlatId);
dbKit = MetaKit.getDbKit(dbPlatId, "");
}
List<Map> list = dbKit.findList("SHOW DATABASES;", Map.class);
@@ -40,7 +40,7 @@ public class _DbService extends BaseService {
@RestMapping(name = "table_list", comment = "数据库表列表")
public List<Table> tableList(String dbPlatId, String catalog, String[] tables) {
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
DbKit dbKit = MetaKit.getDbKit(dbPlatId, "");
String sql = tplKit.getTpl("db.table_list", Kv.of("catalog", catalog).set("tables", tables));
return dbKit.findList(sql, Table.class);
@@ -71,7 +71,7 @@ public class _DbService extends BaseService {
@RestMapping(ignore = true, comment = "查询表信息")
public Table tableInfo(String dbPlatId, String catalog, String tableName) {
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
DbKit dbKit = MetaKit.getDbKit(dbPlatId, catalog);
String sql = tplKit.getTpl("db.table_list", Kv.of("table", tableName));
String columnSql = String.format("SHOW FULL COLUMNS FROM %s.`%s`", catalog, tableName);
@@ -94,7 +94,7 @@ public class _DbService extends BaseService {
public JBean tableCreate(String dbPlatId, String catalog, String sql) {
JBean jBean = new JBean();
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
DbKit dbKit = MetaKit.getDbKit(dbPlatId, catalog);
dbKit.createTable(sql);
return jBean;

View File

@@ -75,7 +75,7 @@ public class RunTest<T> {
dbAccount.setUser("root");
dbAccount.setPwd("eversec123098");
DbKit dbKit = new DbKit(dbAccount);
DbKit dbKit = new DbKit(dbAccount, "");
//String sql = "select * from basic_concat limit 1";
String sql = "show databases;";
@@ -320,7 +320,7 @@ public class RunTest<T> {
dbAccount.setUser("root");
dbAccount.setPwd("eversec123098");
DbKit dbKit = new DbKit(dbAccount);
DbKit dbKit = new DbKit(dbAccount, "");
String sql = "select platID,platDomain,platIP from basic_domain limit 10";
String countSql = "select count(*) from basic_domain";