.
This commit is contained in:
@@ -2,7 +2,9 @@ package net.tccn.service;
|
||||
|
||||
import com.arangodb.Predicate;
|
||||
import com.google.gson.Gson;
|
||||
import net.tccn.base.FileKit;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.base.TplKit;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.CacheSource;
|
||||
@@ -52,7 +54,13 @@ public class BaseService implements Service {
|
||||
@Resource(name = "APP_HOME")
|
||||
protected File APP_HOME;
|
||||
|
||||
@Resource(name = "property.tplPath")
|
||||
private String tplPath;
|
||||
|
||||
public static Properties prop = new Properties();
|
||||
protected static TplKit tplKit = TplKit.use(true);
|
||||
|
||||
private static boolean tplInit = false;
|
||||
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
@@ -64,6 +72,16 @@ public class BaseService implements Service {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!tplInit) {
|
||||
tplInit = true;
|
||||
tplKit.addTpl(new File(FileKit.rootPath(), tplPath));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
|
||||
@@ -2,18 +2,18 @@ package net.tccn.service;
|
||||
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.dbq.Field;
|
||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
import net.tccn.plat.SysPlat;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.meta.MetaLink;
|
||||
import net.tccn.meta.MetaService;
|
||||
import net.tccn.meta.MetaTable;
|
||||
import net.tccn.plat.SysPlat;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -77,31 +77,21 @@ public class MetadataService extends BaseService { //arango
|
||||
//----------- 元数据管理 ---------------
|
||||
@RestMapping(name = "tablelist", comment = "table列表")
|
||||
public JBean tableList(@RestParam(name = "platToken") String token, String catalog, String dbPlatId, String name) {
|
||||
JBean jBean = JBean.by(0, "");
|
||||
SysPlat sysPlat = qtaskService.getSysPlat(token);
|
||||
if (sysPlat == null) {
|
||||
return jBean.set(-1, "平台信息未知");
|
||||
}
|
||||
JBean jBean = new JBean();
|
||||
|
||||
List<Kv> list = MetaKit.getMetaTables()
|
||||
.stream()
|
||||
.filter(x -> {
|
||||
return (isEmpty.test(catalog) || catalog.equals(x.getCatalog())) &&
|
||||
(isEmpty.test(dbPlatId) || dbPlatId.equals(x.getDbPlatId())) &&
|
||||
(isEmpty.test(name) || x.getName().contains(name));
|
||||
})
|
||||
.sorted(Comparator.comparing(MetaTable::getName))
|
||||
.map(x -> {
|
||||
//组装返回的数据
|
||||
Kv kv = Kv.of("name", x.getName())
|
||||
.set("comment", x.getComment())
|
||||
.set("catalog", x.getCatalog());
|
||||
MetaKit.getDbPlats().stream().filter(d -> d.getKey().equals(x.getDbPlatId())).findAny().ifPresent(d -> kv.set("dbPlatName", d.getName()));
|
||||
return kv;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return jBean.setBody(list);
|
||||
List<Kv> list =
|
||||
MetaKit.getMetaTables().stream().filter(x ->
|
||||
(isEmpty.test(catalog) || catalog.equals(x.getCatalog())) &&
|
||||
(isEmpty.test(dbPlatId) || dbPlatId.equals(x.getDbPlatId())) &&
|
||||
(isEmpty.test(name) || x.getName().contains(name)) &&
|
||||
(isEmpty.test(token) || x.getSysPlatId().equals(platId(token)))
|
||||
).map(x -> Kv.of("name", x.getName())
|
||||
.set("comment", x.getComment())
|
||||
.set("catalog", x.getCatalog())
|
||||
.set("dbPlatId", x.getDbPlatId())
|
||||
).collect(Collectors.toList());
|
||||
jBean.setBody(list);
|
||||
return jBean;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,6 +200,29 @@ public class MetadataService extends BaseService { //arango
|
||||
return JBean.by(0, "");
|
||||
}
|
||||
|
||||
@RestMapping(name = "link_list", comment = "实体关系列表")
|
||||
public JBean linkList() {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
List<MetaLink> links = MetaKit.getMetaLinks();
|
||||
|
||||
jBean.setBody(links);
|
||||
return jBean;
|
||||
}
|
||||
|
||||
@RestMapping(name = "link_list", comment = "实体关系列表")
|
||||
public JBean linkSave(MetaLink link, @RestParam(name = "platToken") String token) {
|
||||
if (link.getKey() != null) {
|
||||
link.update();
|
||||
} else {
|
||||
link.save();
|
||||
}
|
||||
MetaKit.reload(MetaLink.class);
|
||||
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
|
||||
@RestMapping(name = "plat_list", comment = "平台列表")
|
||||
public JBean platList() {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package net.tccn.service;
|
||||
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||
import net.tccn.dbq.jdbc.api.DbKit;
|
||||
import net.tccn.dbq.table.Column;
|
||||
import net.tccn.dbq.table.Table;
|
||||
import net.tccn.meta.MetaTable;
|
||||
import net.tccn.service.BaseService;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -38,30 +39,41 @@ public class _DbService extends BaseService {
|
||||
}
|
||||
|
||||
@RestMapping(name = "table_list", comment = "数据库表列表")
|
||||
public List<Table> tableList(String dbPlatId, String[] catalogs) {
|
||||
|
||||
public List<Table> tableList(String dbPlatId, String catalog, String[] tables) {
|
||||
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
|
||||
|
||||
StringBuffer sqlBuf = new StringBuffer("SELECT TABLE_NAME 'name',TABLE_COMMENT 'comment',table_schema 'catalog' FROM INFORMATION_SCHEMA.TABLES");
|
||||
if (catalogs != null && catalogs.length > 0) {
|
||||
sqlBuf.append(" WHERE TABLE_SCHEMA in (");
|
||||
for (String catalog : catalogs) {
|
||||
sqlBuf.append("'").append(catalog).append("',");
|
||||
}
|
||||
sqlBuf.deleteCharAt(sqlBuf.length() - 1);
|
||||
sqlBuf.append(")");
|
||||
}
|
||||
List<Table> list = dbKit.findList(sqlBuf.toString(), Table.class);
|
||||
String sql = tplKit.getTpl("db.table_list", Kv.of("catalog", catalog).set("tables", tables));
|
||||
return dbKit.findList(sql, Table.class);
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public List<Table> tableInfoList(String dbPlatId, String catalog, String[] tables) {
|
||||
List<Table> list = new ArrayList<>(tables.length);
|
||||
for (String table : tables) {
|
||||
list.add(tableInfo(dbPlatId, catalog, table));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@RestMapping(name = "table_info", comment = "数据库表详情")
|
||||
public JBean tableInfo(String dbPlatId, String catalog, String tableName) {
|
||||
public JBean MetatableInfo(String dbPlatId, String catalog, String tableName) {
|
||||
JBean jBean = new JBean();
|
||||
try {
|
||||
Table table = tableInfo(dbPlatId, catalog, tableName);
|
||||
|
||||
jBean.setBody(MetaTable.toAs(table));
|
||||
} catch (Exception e) {
|
||||
jBean.set(-1, "查询表信息失败");
|
||||
new IllegalArgumentException("查询表信息失败", e);
|
||||
}
|
||||
return jBean;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true, comment = "查询表信息")
|
||||
public Table tableInfo(String dbPlatId, String catalog, String tableName) {
|
||||
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
|
||||
|
||||
String sql = String.format("SELECT TABLE_NAME 'name',TABLE_COMMENT 'comment',table_schema 'catalog' FROM INFORMATION_SCHEMA.TABLES where TABLE_NAME='%s'", tableName);
|
||||
String sql = tplKit.getTpl("db.table_list", Kv.of("table", tableName));
|
||||
String columnSql = String.format("SHOW FULL COLUMNS FROM %s.`%s`", catalog, tableName);
|
||||
|
||||
CompletableFuture<Table> tableFuture = CompletableFuture.supplyAsync(() -> dbKit.findfirst(sql, Table.class));
|
||||
@@ -71,14 +83,11 @@ public class _DbService extends BaseService {
|
||||
Table table = tableFuture.get();
|
||||
table.setColumns(columnFuture.get());
|
||||
|
||||
//jBean.setBody(table);
|
||||
jBean.setBody(MetaTable.toAs(table)); //todo: 将此转换提取到 单独方法中<依据六边形架构原则>
|
||||
return table;
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
jBean.set(-1, "查询表信息失败");
|
||||
new IllegalArgumentException("查询表信息失败", e);
|
||||
}
|
||||
|
||||
return jBean;
|
||||
return null;
|
||||
}
|
||||
|
||||
@RestMapping(name = "table_create", comment = "新建表[mysql]")
|
||||
@@ -90,12 +99,4 @@ public class _DbService extends BaseService {
|
||||
|
||||
return jBean;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true, comment = "查询表信息")
|
||||
public List<Table> tableList(String dbPlatId, String catalog, String ... tables) {
|
||||
//todo:
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class _TableService extends BaseService {
|
||||
String filePath,
|
||||
|
||||
//mysql {数据库连接账号、数据源id、数据库database数组}
|
||||
String dbPlatId, String[] catalogs,
|
||||
String dbPlatId, String catalog,
|
||||
@RestParam(name = "platToken") String token) {
|
||||
|
||||
JBean jBean = new JBean();
|
||||
@@ -46,7 +46,7 @@ public class _TableService extends BaseService {
|
||||
jBean.setBody(fileService.data(filePath, token));
|
||||
|
||||
} else if ("mysql".equals(cate)){
|
||||
List<Table> list = dbService.tableList(dbPlatId, catalogs);
|
||||
List<Table> list = dbService.tableList(dbPlatId, catalog, null);
|
||||
|
||||
String[] tableArr = list.stream().map(Table::getName).toArray(String[]::new);
|
||||
CompletableFuture<List<String>> hvFuture = tableExist(tableArr, token);
|
||||
@@ -90,7 +90,7 @@ public class _TableService extends BaseService {
|
||||
@RestParam(name = "platToken") String token) {
|
||||
|
||||
CompletableFuture<List<String>> hvfuture = tableExist(tableArr, token);
|
||||
List<Table> tables = dbService.tableList(dbPlatId, catalog, tableArr);
|
||||
List<Table> tables = dbService.tableInfoList(dbPlatId, catalog, tableArr);
|
||||
|
||||
try {
|
||||
List<String> hvs = hvfuture.get();
|
||||
@@ -106,6 +106,7 @@ public class _TableService extends BaseService {
|
||||
metaTable.save();
|
||||
}
|
||||
});
|
||||
MetaKit.reload(MetaTable.class);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user