.
This commit is contained in:
@@ -281,10 +281,11 @@
|
|||||||
if (!col) {
|
if (!col) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
console.log(col)
|
||||||
|
|
||||||
var items = this.cfg.items[col.split("$")[0]];
|
var items = this.cfg.items[col.split(".")[0]];
|
||||||
if (items) {
|
if (items) {
|
||||||
return items[col.split("$")[1]]['label']
|
return items[col.split(".")[1]]['label']
|
||||||
/*for (var i = 0; i < items.items.length; i++) {
|
/*for (var i = 0; i < items.items.length; i++) {
|
||||||
if (tableInfo.items[i].name == col.split("$")[1]) {
|
if (tableInfo.items[i].name == col.split("$")[1]) {
|
||||||
return tableInfo.items[i].label;
|
return tableInfo.items[i].label;
|
||||||
|
|||||||
@@ -61,88 +61,13 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
|||||||
private static Function<String, String> upFirst = (s) -> {
|
private static Function<String, String> upFirst = (s) -> {
|
||||||
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
||||||
};
|
};
|
||||||
/*private static Map<Class, Class[]> clazzMap = new HashMap<>();
|
|
||||||
static {
|
|
||||||
clazzMap.put(ArrayList.class, new Class[]{List.class, ArrayList.class, String.class});
|
|
||||||
clazzMap.put(HashMap.class, new Class[]{Map.class, HashMap.class, String.class});
|
|
||||||
clazzMap.put(Long.class, new Class[]{Long.class, Integer.class, long.class, int.class, short.class, String.class});
|
|
||||||
clazzMap.put(String.class, new Class[]{String.class, Integer.class, Date.class});
|
|
||||||
clazzMap.put(Double.class, new Class[]{Double.class, Long.class, Integer.class, long.class, int.class, short.class, String.class});
|
|
||||||
}*/
|
|
||||||
private static Predicate<Class> isNumber = (t) -> {
|
private static Predicate<Class> isNumber = (t) -> {
|
||||||
return t == Integer.class || t == int.class
|
return t == Integer.class || t == int.class
|
||||||
|| t == Long.class || t == long.class
|
|| t == Long.class || t == long.class
|
||||||
|| t == Double.class || t == double.class
|
|| t == Double.class || t == double.class
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
/*public static <T> T toBean2(Map m, Class<T> type) {
|
|
||||||
try {
|
|
||||||
Object obj = type.newInstance();
|
|
||||||
for (String k : (Set<String>)m.keySet()) {
|
|
||||||
Object v = m.get(k);
|
|
||||||
if (v == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//得到目标方法
|
|
||||||
String methodName = "set" + upFirst.apply(k + "");
|
|
||||||
Method method = null;
|
|
||||||
Class tClazz = null;
|
|
||||||
try {
|
|
||||||
method = type.getDeclaredMethod(methodName, tClazz = v.getClass());
|
|
||||||
if (method == null) {
|
|
||||||
Class[] clazzs = clazzMap.get(v == null ? null : v.getClass());
|
|
||||||
if (clazzs == null) {
|
|
||||||
//doc.set(k, v);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
for (Class clazz : clazzs) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
type.getMethods();
|
|
||||||
|
|
||||||
method = type.getDeclaredMethod(methodName, tClazz = clazz);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method != null) {
|
|
||||||
try {
|
|
||||||
Object _v = toAs(v, tClazz);
|
|
||||||
//如发现 映射异常,打开下面的注释查看 进行映射的值,并对上面的值转换过程升级
|
|
||||||
//System.out.printf("%s:%s %s%n", k,v, v.getClass());
|
|
||||||
method.invoke(obj, _v);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (method != null) {
|
|
||||||
|
|
||||||
}
|
|
||||||
//已知:key,value, 一个实例类型对象
|
|
||||||
//找到目标方法
|
|
||||||
//转换数据类型
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return (T) obj;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static <T> T toAs(Object v, Class<T> clazz) {
|
public static <T> T toAs(Object v, Class<T> clazz) {
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
@@ -269,15 +194,6 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*if (field == null) {
|
|
||||||
fields = clazz.getDeclaredFields();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
while (true){
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (field != null) {
|
if (field != null) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
@@ -292,19 +208,6 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
|||||||
return (T) obj;
|
return (T) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Map map = new HashMap<>();
|
|
||||||
|
|
||||||
map.put("name", "xxxx");
|
|
||||||
map.put("age", 12);
|
|
||||||
map.put("abx", 123);
|
|
||||||
|
|
||||||
User user = toBean(map, User.class);
|
|
||||||
|
|
||||||
System.out.println(user);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -477,12 +477,20 @@ public class MetaKit {
|
|||||||
return plat.get().getKey();
|
return plat.get().getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String nextAlias(String x) {
|
public static String lastAlias;
|
||||||
return next(x, "");
|
public static String nextAlias() {
|
||||||
|
if (lastAlias == null) {
|
||||||
|
lastAlias = MetaTable.dao.findFirst(
|
||||||
|
"for d in MetaTable\n" +
|
||||||
|
"sort length(d.alias) desc, d.alias desc\n" +
|
||||||
|
"limit 1\n" +
|
||||||
|
"return d.alias", String.class);
|
||||||
|
}
|
||||||
|
return lastAlias = next(lastAlias, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用['a',...,'z'] 创建Table 别名
|
//使用['a',...,'z'] 创建Table 别名
|
||||||
private String next(String x, String end) {
|
private static String next(String x, String end) {
|
||||||
if (x == null || "".equals(x)) {
|
if (x == null || "".equals(x)) {
|
||||||
return "a" + end;
|
return "a" + end;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class _DbService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "table_list", comment = "数据库表列表")
|
@RestMapping(name = "table_list", comment = "数据库表列表")
|
||||||
public List<Table> tableList(DbAccount dbAccount, String dbPlatId, String[] catalogs) {
|
public List<Table> tableList(String dbPlatId, String[] catalogs) {
|
||||||
|
|
||||||
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
|
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
|
||||||
|
|
||||||
@@ -56,8 +56,7 @@ public class _DbService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "table_info", comment = "数据库表详情")
|
@RestMapping(name = "table_info", comment = "数据库表详情")
|
||||||
public JBean tableInfo(DbAccount dbAccount,
|
public JBean tableInfo(String dbPlatId, String catalog, String tableName) {
|
||||||
String dbPlatId, String catalog, String tableName) {
|
|
||||||
JBean jBean = new JBean();
|
JBean jBean = new JBean();
|
||||||
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
|
DbKit dbKit = MetaKit.getDbKit(dbPlatId);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.tccn.meta;
|
|||||||
|
|
||||||
import net.tccn.base.JBean;
|
import net.tccn.base.JBean;
|
||||||
import net.tccn.base.Kv;
|
import net.tccn.base.Kv;
|
||||||
|
import net.tccn.base.MetaKit;
|
||||||
import net.tccn.dbq.jdbc.api.DbAccount;
|
import net.tccn.dbq.jdbc.api.DbAccount;
|
||||||
import net.tccn.dbq.table.Table;
|
import net.tccn.dbq.table.Table;
|
||||||
import net.tccn.service.BaseService;
|
import net.tccn.service.BaseService;
|
||||||
@@ -38,7 +39,7 @@ public class _TableService extends BaseService {
|
|||||||
String filePath,
|
String filePath,
|
||||||
|
|
||||||
//mysql {数据库连接账号、数据源id、数据库database数组}
|
//mysql {数据库连接账号、数据源id、数据库database数组}
|
||||||
DbAccount dbAccount, String dbPlatId, String[] catalogs,
|
String dbPlatId, String[] catalogs,
|
||||||
@RestParam(name = "platToken") String token) {
|
@RestParam(name = "platToken") String token) {
|
||||||
|
|
||||||
JBean jBean = new JBean();
|
JBean jBean = new JBean();
|
||||||
@@ -47,7 +48,7 @@ public class _TableService extends BaseService {
|
|||||||
jBean.setBody(fileService.data(filePath, token));
|
jBean.setBody(fileService.data(filePath, token));
|
||||||
|
|
||||||
} else if ("mysql".equals(cate)){
|
} else if ("mysql".equals(cate)){
|
||||||
List<Table> list = dbService.tableList(dbAccount, dbPlatId, catalogs);
|
List<Table> list = dbService.tableList(dbPlatId, catalogs);
|
||||||
|
|
||||||
String[] tableArr = list.stream().map(Table::getName).toArray(String[]::new);
|
String[] tableArr = list.stream().map(Table::getName).toArray(String[]::new);
|
||||||
CompletableFuture<List<String>> hvFuture = tableExist(tableArr, token);
|
CompletableFuture<List<String>> hvFuture = tableExist(tableArr, token);
|
||||||
@@ -100,7 +101,8 @@ public class _TableService extends BaseService {
|
|||||||
MetaTable metaTable = MetaTable.toAs(t);
|
MetaTable metaTable = MetaTable.toAs(t);
|
||||||
metaTable.setCatalog(catalog);
|
metaTable.setCatalog(catalog);
|
||||||
metaTable.setDbPlatId(dbPlatId);
|
metaTable.setDbPlatId(dbPlatId);
|
||||||
metaTable.setAlias("");//todo: 表别名
|
metaTable.setAlias(MetaKit.nextAlias());//todo: 表别名
|
||||||
|
metaTable.setSysPlatId(platId(token));
|
||||||
|
|
||||||
//保存数据到元数据表
|
//保存数据到元数据表
|
||||||
metaTable.save();
|
metaTable.save();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.tccn.user.User;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -150,4 +151,22 @@ public class RunTest<T> {
|
|||||||
user.save();
|
user.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t() {
|
||||||
|
System.out.println(MetaKit.nextAlias());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void kvTest() {
|
||||||
|
Map map = new HashMap<>();
|
||||||
|
|
||||||
|
map.put("name", "xxxx");
|
||||||
|
map.put("age", 12);
|
||||||
|
map.put("abx", 123);
|
||||||
|
|
||||||
|
UserBean user = Kv.toBean(map, UserBean.class);
|
||||||
|
|
||||||
|
System.out.println(user);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
import net.tccn.base.Kv;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author: liangxianyou at 2019/1/20 12:52.
|
|
||||||
*/
|
|
||||||
public class User {
|
|
||||||
private int id;
|
|
||||||
private String IP;
|
|
||||||
private String platContact;
|
|
||||||
private String idType;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIP() {
|
|
||||||
return IP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIP(String IP) {
|
|
||||||
this.IP = IP;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlatContact() {
|
|
||||||
return platContact;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlatContact(String platContact) {
|
|
||||||
this.platContact = platContact;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdType() {
|
|
||||||
return idType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdType(String idType) {
|
|
||||||
this.idType = idType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String say(Kv kv) {
|
|
||||||
String s = String.format("我叫:%s, 今年:%s岁", kv.get("name"), kv.get("age"));
|
|
||||||
System.out.println(s);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "User{" +
|
|
||||||
"id=" + id +
|
|
||||||
", IP='" + IP + '\'' +
|
|
||||||
", platContact='" + platContact + '\'' +
|
|
||||||
", idType='" + idType + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package net.tccn.base;
|
import net.tccn.base.To;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by liangxianyou at 2019/3/26 19:36.
|
* Created by liangxianyou at 2019/3/26 19:36.
|
||||||
*/
|
*/
|
||||||
public class User {
|
public class UserBean {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private int age;
|
private int age;
|
||||||
@To("")
|
@To("abx")
|
||||||
private float attr;
|
private float attr;
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
Reference in New Issue
Block a user