1、包结构修改

2、dict的bug修改
3、arangodb查询find()默认1000条修改为库里所有数据
This commit is contained in:
2019-07-02 17:37:55 +08:00
parent bbf9b8b9c4
commit 972fb387c7
44 changed files with 397 additions and 248 deletions

View File

@@ -15,7 +15,7 @@
</response> </response>
<resource-servlet/> <resource-servlet/>
<rest autoload="true" base="net.tccn.servlet.BaseServlet"/> <rest autoload="true" base="net.tccn.base.BaseServlet"/>
<services autoload="true"/> <services autoload="true"/>
<servlets autoload="true"/> <servlets autoload="true"/>
<render value="net.tccn.base.MetaRender"/> <render value="net.tccn.base.MetaRender"/>

View File

@@ -1,8 +1,5 @@
package net.tccn.service; package net.tccn.base;
import net.tccn.base.MetaKit;
import net.tccn.base.TplKit;
import net.tccn.base.X;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.service.Service; import org.redkale.service.Service;

View File

@@ -1,12 +1,9 @@
package net.tccn.servlet; package net.tccn.base;
import com.arangodb.ArangoDBException; import com.arangodb.ArangoDBException;
import net.tccn.base.CfgException;
import net.tccn.base.JBean;
import net.tccn.base.Kv;
import net.tccn.base.arango.ArangoSource; import net.tccn.base.arango.ArangoSource;
import net.tccn.service.UserService;
import net.tccn.user.User; import net.tccn.user.User;
import net.tccn.user.UserService;
import org.redkale.net.http.HttpRequest; import org.redkale.net.http.HttpRequest;
import org.redkale.net.http.HttpResponse; import org.redkale.net.http.HttpResponse;
import org.redkale.net.http.HttpServlet; import org.redkale.net.http.HttpServlet;
@@ -72,7 +69,7 @@ public class BaseServlet extends HttpServlet {
super.execute(request, response); super.execute(request, response);
} catch (ArangoDBException e) { } catch (ArangoDBException e) {
logger.log(Level.INFO, "arangodb init!", e); logger.log(Level.INFO, "arangodb init!", e);
ArangoSource.init(); ArangoSource.use();
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
e.printStackTrace(); e.printStackTrace();
response.finish(JBean.by(-1, e.getMessage())); response.finish(JBean.by(-1, e.getMessage()));

View File

@@ -2,9 +2,9 @@ package net.tccn.base;
import lombok.Getter; import lombok.Getter;
import net.tccn.base.arango.Doc; import net.tccn.base.arango.Doc;
import net.tccn.dbq.jdbc.api.DbAccount; import net.tccn.base.dbq.jdbc.api.DbAccount;
import net.tccn.dbq.jdbc.api.DbKit; import net.tccn.base.dbq.jdbc.api.DbKit;
import net.tccn.dbq.table.Field; import net.tccn.base.dbq.table.Field;
import net.tccn.dict.Dict; import net.tccn.dict.Dict;
import net.tccn.meta.*; import net.tccn.meta.*;
import net.tccn.plat.DbPlat; import net.tccn.plat.DbPlat;

View File

@@ -1,14 +1,19 @@
package net.tccn.base.arango; package net.tccn.base.arango;
import com.arangodb.*; import com.arangodb.ArangoCollection;
import com.arangodb.ArangoDB;
import com.arangodb.ArangoDatabase;
import com.arangodb.Function;
import com.arangodb.entity.DocumentCreateEntity; import com.arangodb.entity.DocumentCreateEntity;
import com.arangodb.entity.DocumentDeleteEntity; import com.arangodb.entity.DocumentDeleteEntity;
import com.arangodb.entity.MultiDocumentEntity; import com.arangodb.entity.MultiDocumentEntity;
import net.tccn.base.PropKit;
import net.tccn.base.X;
import javax.persistence.Table; import javax.persistence.Table;
import java.lang.reflect.InvocationTargetException; import java.util.Collection;
import java.lang.reflect.Method; import java.util.HashMap;
import java.util.*; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -16,6 +21,7 @@ import static java.util.Arrays.asList;
/** /**
* 管理 数据源连接对象 * 管理 数据源连接对象
*
* @author: liangxianyou at 2018/12/15 11:35. * @author: liangxianyou at 2018/12/15 11:35.
*/ */
public class ArangoSource { public class ArangoSource {
@@ -24,38 +30,46 @@ public class ArangoSource {
private ArangoDB arangoDb; private ArangoDB arangoDb;
private static Map<String, ArangoSource> sources = new HashMap(); private static Map<String, ArangoSource> sources = new HashMap();
static {
init();
}
public static void init() { private ArangoSource(ArangoDB arangoDb) {
sources.put("main", new ArangoSource(new ArangoDB.Builder().host("120.24.230.60", 8529).user("root").password("abc123").build()));
sources.put("abc", new ArangoSource(new ArangoDB.Builder().host("192.168.199.135", 8529).user("root").password("root").build()));
}
public ArangoSource(ArangoDB arangoDb) {
this.arangoDb = arangoDb; this.arangoDb = arangoDb;
} }
public static ArangoSource use() { public static ArangoSource use() {
return use("main"); return use("main");
} }
public static ArangoSource use(String unit) { public static ArangoSource use(String unit) {
if (unit == null || unit.isEmpty()) { if (unit == null || unit.isEmpty() || "main".equals(unit)) {
unit = "main"; unit = "";
} else {
unit = "." + unit;
} }
return sources.get(unit);
ArangoSource source = sources.get(unit);
if (source == null) {
String host = PropKit.getProperty("arango.host" + unit);
int port = Integer.parseInt(PropKit.getProperty("arango.port" + unit, "8529"));
String user = PropKit.getProperty("arango.user" + unit);
String password = PropKit.getProperty("arango.passwd" + unit);
source = new ArangoSource(new ArangoDB.Builder().host(host, port).user(user).password(password).build());
}
return source;
} }
public ArangoDB arangoDB() { public ArangoDB arangoDB() {
return arangoDb; return arangoDb;
} }
public ArangoDatabase db(String db) { public ArangoDatabase db(String db) {
return arangoDb.db(db); return arangoDb.db(db);
} }
public <T extends Doc> ArangoCollection collection(Doc<T> doc) { public <T extends Doc> ArangoCollection collection(Doc<T> doc) {
return collection(doc.getClass()); return collection(doc.getClass());
} }
public <T extends Doc> ArangoCollection collection(Class<T> type) { public <T extends Doc> ArangoCollection collection(Class<T> type) {
Table table = type.getAnnotation(Table.class); Table table = type.getAnnotation(Table.class);
//createDb(table.catalog()); //createDb(table.catalog());
@@ -70,6 +84,7 @@ public class ArangoSource {
logger.log(Level.INFO, "arango database exists"); logger.log(Level.INFO, "arango database exists");
return true; return true;
} }
public <T extends Doc> ArangoCollection createDocument(Doc<T> doc) { public <T extends Doc> ArangoCollection createDocument(Doc<T> doc) {
Class<? extends Doc> type = doc.getClass(); Class<? extends Doc> type = doc.getClass();
Table table = type.getAnnotation(Table.class); Table table = type.getAnnotation(Table.class);
@@ -92,92 +107,9 @@ public class ArangoSource {
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});
}
/**
* 还原 Doc对象
* @param map
* @param type
* @param <T>
* @return
*/
public <T extends Doc> T toDoc1(Map<String, Object> map, Class<T> type) {
try {
Doc doc = type.newInstance();
map.forEach((k, v) -> {
String methodName = "set" + upFirst.apply(k);
Method method = null;
Class[] clazzs = clazzMap.get(v == null ? null : v.getClass());
if (clazzs == null) {
doc.set(k, v);
} else {
for (Class clazz : clazzs) {
try {
method = type.getDeclaredMethod(methodName, clazz);
} catch (NoSuchMethodException e) {
}
if (method != null) {
try {
if (v.getClass() == Long.class && clazz != Long.class) {//多种数值类型的处理
Object _v;
switch (clazz.getSimpleName()) {
case "int":
case "Integer": _v = (int)((long) v); break;
case "short":
case "Short": _v = (short)((long) v); break;
default: _v = v;
}
System.out.println(clazz.getSimpleName());
method.invoke(doc, _v);
} else {
method.invoke(doc, v);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
doc.set(k, v);
} catch (InvocationTargetException e) {
e.printStackTrace();
doc.set(k, v);
}
break;
}
}
}
if (method == null) {
doc.set(k, v);
}
});
return (T) doc;
} catch (Exception e) {
}
return null;
}
private Predicate isEmpty = (x) -> {
if (x == null)
return true;
if (x instanceof List)
return ((List) x).isEmpty();
if (x instanceof String)
return ((String) x).isEmpty();
if (x instanceof Map)
return ((Map) x).isEmpty();
if (x instanceof Collection)
return ((Collection) x).isEmpty();
return false;
};
/** /**
* Doc 转为查询对象 * Doc 转为查询对象
*
* @param t * @param t
* @param <T> * @param <T>
* @return * @return
@@ -205,7 +137,7 @@ public class ArangoSource {
private Function<Doc, StringBuilder> orderBuilder = (t) -> { private Function<Doc, StringBuilder> orderBuilder = (t) -> {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
Map<String, Integer> order = t.getOrder(); Map<String, Integer> order = t.getOrder();
if (isEmpty.test(order)) { if (X.isEmpty(order)) {
return buf.append(" sort d._key desc"); return buf.append(" sort d._key desc");
} }
buf.append(" sort "); buf.append(" sort ");
@@ -219,7 +151,7 @@ public class ArangoSource {
private Function<Doc, StringBuilder> returnBuilder = (t) -> { private Function<Doc, StringBuilder> returnBuilder = (t) -> {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
if (isEmpty.test(t.get_Shows())) { if (X.isEmpty(t.get_Shows())) {
return buf.append(" return d"); return buf.append(" return d");
} }
@@ -239,6 +171,7 @@ public class ArangoSource {
//logger.log(Level.INFO, buf.toString()); //logger.log(Level.INFO, buf.toString());
return buf.toString(); return buf.toString();
} }
public <T extends Doc> String parseAql(T t, int offset, int ps) { public <T extends Doc> String parseAql(T t, int offset, int ps) {
if (offset < 0) offset = 0; if (offset < 0) offset = 0;
if (ps <= 0) ps = 1000; if (ps <= 0) ps = 1000;
@@ -251,6 +184,7 @@ public class ArangoSource {
//logger.log(Level.INFO, buf.toString()); //logger.log(Level.INFO, buf.toString());
return buf.toString(); return buf.toString();
} }
//---------------------------------------- //----------------------------------------
//ok //ok
public <T extends Doc> T save(T doc) { public <T extends Doc> T save(T doc) {

View File

@@ -43,12 +43,12 @@ public abstract class Doc<T extends Doc> {
this._key = key; this._key = key;
} }
public Doc<T> set(String k, Object v) { protected Doc<T> set(String k, Object v) {
attr.put(k, v); attr.put(k, v);
return this; return this;
} }
public <V> V get(String k) { protected <V> V get(String k) {
return (V)attr.get(k); return (V)attr.get(k);
} }
@@ -212,16 +212,17 @@ public abstract class Doc<T extends Doc> {
return findFirst(arangoSource.parseAql(t, 0, 1), (Class<T>) t.getClass()); return findFirst(arangoSource.parseAql(t, 0, 1), (Class<T>) t.getClass());
} }
public List<T> find() { public List<T> find() {
return find((T) this, 0, 1000); int count = count(this);
return find((T) this, 0, count);
} }
public List<T> find(T t) { public List<T> find(T t) {
return find(t, 0, 1000); return find(t, 0, 1000);
} }
public <T extends Doc> List<T> find(T t, int offset, int pn) { public <T extends Doc> List<T> find(T t, int offset, int ps) {
if (t == null) { if (t == null) {
t = (T) this; t = (T) this;
} }
return find(arangoSource.parseAql(t, offset, pn), (Class<T>)this.getClass()); return find(arangoSource.parseAql(t, offset, ps), (Class<T>)this.getClass());
} }
public <T> List<T> find(String aql, Class<T> clazz) { public <T> List<T> find(String aql, Class<T> clazz) {
@@ -230,7 +231,7 @@ public abstract class Doc<T extends Doc> {
} catch (ArangoDBException e) { } catch (ArangoDBException e) {
System.out.println(aql); System.out.println(aql);
e.printStackTrace(); e.printStackTrace();
ArangoSource.init(); ArangoSource.use();
} }
return db.query(aql, clazz).asListRemaining(); return db.query(aql, clazz).asListRemaining();
} }
@@ -240,19 +241,19 @@ public abstract class Doc<T extends Doc> {
} catch (ArangoDBException e) { } catch (ArangoDBException e) {
System.out.println(aql); System.out.println(aql);
e.printStackTrace(); e.printStackTrace();
ArangoSource.init(); ArangoSource.use();
} }
return db.query(aql, clazz).first(); return db.query(aql, clazz).first();
} }
public long count() { public int count() {
return count(this); return count(this);
} }
public <T extends Doc> long count(T t) { public <T extends Doc> int count(T t) {
if (t == null) { if (t == null) {
t = (T) this; t = (T) this;
} }
return db.query(arangoSource.parseAqlCount(t), long.class).first(); return db.query(arangoSource.parseAqlCount(t), int.class).first();
} }
//ok //ok
public <T extends Doc> T findByKey(Object key) { public <T extends Doc> T findByKey(Object key) {

View File

@@ -1,10 +1,10 @@
package net.tccn.dbq; package net.tccn.base.dbq;
import net.tccn.base.MetaKit; import net.tccn.base.MetaKit;
import net.tccn.base.PageBean; import net.tccn.base.PageBean;
import net.tccn.dbq.fbean.FBean; import net.tccn.base.dbq.fbean.FBean;
import net.tccn.dbq.jdbc.api.DbKit; import net.tccn.base.dbq.jdbc.api.DbKit;
import net.tccn.dbq.parser.ParseMysql; import net.tccn.base.dbq.parser.ParseMysql;
import net.tccn.meta.MetaService; import net.tccn.meta.MetaService;
import net.tccn.meta.MetaTable; import net.tccn.meta.MetaTable;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.fbean; package net.tccn.base.dbq.fbean;
/** /**
* Created by liangxianyou at 2018/12/14 15:34. * Created by liangxianyou at 2018/12/14 15:34.

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.fbean; package net.tccn.base.dbq.fbean;
import lombok.Data; import lombok.Data;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.fbean; package net.tccn.base.dbq.fbean;
import lombok.Data; import lombok.Data;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.fbean; package net.tccn.base.dbq.fbean;
import net.tccn.base.Kv; import net.tccn.base.Kv;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.fbean; package net.tccn.base.dbq.fbean;
import lombok.Data; import lombok.Data;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.fbean; package net.tccn.base.dbq.fbean;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.jdbc.api; package net.tccn.base.dbq.jdbc.api;
import lombok.Data; import lombok.Data;
import net.tccn.base.arango.Doc; import net.tccn.base.arango.Doc;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.jdbc.api; package net.tccn.base.dbq.jdbc.api;
import net.tccn.base.X; import net.tccn.base.X;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.jdbc.api; package net.tccn.base.dbq.jdbc.api;
import net.tccn.base.IService; import net.tccn.base.IService;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.jdbc.api; package net.tccn.base.dbq.jdbc.api;
import net.tccn.base.CfgException; import net.tccn.base.CfgException;
import net.tccn.base.Kv; import net.tccn.base.Kv;

View File

@@ -1,6 +1,6 @@
package net.tccn.dbq.parser; package net.tccn.base.dbq.parser;
import net.tccn.dbq.fbean.FBean; import net.tccn.base.dbq.fbean.FBean;
/** /**
* Created by liangxianyou at 2018/12/24 15:49. * Created by liangxianyou at 2018/12/24 15:49.

View File

@@ -1,6 +1,6 @@
package net.tccn.dbq.parser; package net.tccn.base.dbq.parser;
import net.tccn.dbq.fbean.FBean; import net.tccn.base.dbq.fbean.FBean;
/** /**
* Created by liangxianyou at 2018/12/24 15:49. * Created by liangxianyou at 2018/12/24 15:49.

View File

@@ -1,7 +1,7 @@
package net.tccn.dbq.parser; package net.tccn.base.dbq.parser;
import net.tccn.base.*; import net.tccn.base.*;
import net.tccn.dbq.fbean.*; import net.tccn.base.dbq.fbean.*;
import net.tccn.meta.MetaLink; import net.tccn.meta.MetaLink;
import net.tccn.meta.MetaService; import net.tccn.meta.MetaService;
import net.tccn.meta.MetaTable; import net.tccn.meta.MetaTable;
@@ -20,20 +20,6 @@ import java.util.stream.Collectors;
*/ */
public class ParseMysql implements Parser { public class ParseMysql implements Parser {
private Predicate isEmpty = (x) -> {
if (x == null)
return true;
if (x instanceof List)
return ((List) x).isEmpty();
if (x instanceof String)
return ((String) x).isEmpty();
if (x instanceof Map)
return ((Map) x).isEmpty();
if (x instanceof Collection)
return ((Collection) x).isEmpty();
return false;
};
Predicate<Kv<String, MetaTable>> sameDbFun = (kv) -> { Predicate<Kv<String, MetaTable>> sameDbFun = (kv) -> {
String dbPlatId = null; String dbPlatId = null;
for (MetaTable metaTable : kv.values()) { for (MetaTable metaTable : kv.values()) {
@@ -78,20 +64,20 @@ public class ParseMysql implements Parser {
if (sameDbFun.test(tables) || true) { if (sameDbFun.test(tables) || true) {
// where 1=1 and xx=xx // where 1=1 and xx=xx
StringBuffer bufWhere = new StringBuffer(); StringBuffer bufWhere = new StringBuffer();
if (!isEmpty.test(filters)) { if (!X.isEmpty(filters)) {
bufWhere.append(Filter.filter(filters, DbType.MYSQL)); bufWhere.append(Filter.filter(filters, DbType.MYSQL));
} }
//select a.x, b.y, c.z //select a.x, b.y, c.z
StringBuffer bufSelect = new StringBuffer(); StringBuffer bufSelect = new StringBuffer();
bufSelect.append("select "); bufSelect.append("select ");
if ("export".equals(fBean.getType()) && !isEmpty.test(exports)) { if ("export".equals(fBean.getType()) && !X.isEmpty(exports)) {
exports.forEach(x -> { exports.forEach(x -> {
bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',"); bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',");
}); });
bufSelect.deleteCharAt(bufSelect.length() - 1); bufSelect.deleteCharAt(bufSelect.length() - 1);
} }
else if ("list".equals(fBean.getType()) && !isEmpty.test(shows)) { else if ("list".equals(fBean.getType()) && !X.isEmpty(shows)) {
shows.forEach(x -> { shows.forEach(x -> {
bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',"); bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',");
}); });
@@ -104,7 +90,7 @@ public class ParseMysql implements Parser {
StringBuilder bufFrom = new StringBuilder(); StringBuilder bufFrom = new StringBuilder();
bufFrom.append(" from ").append(metaTable.getCatalog()).append(".`").append(metaTable.getName()).append("` ").append(metaTable.getAlias()); bufFrom.append(" from ").append(metaTable.getCatalog()).append(".`").append(metaTable.getName()).append("` ").append(metaTable.getAlias());
//left join //left join
if (!isEmpty.test(links)) { if (!X.isEmpty(links)) {
links.forEach(x -> { links.forEach(x -> {
MetaTable rightTable = tables.get(metaTable.getAlias().equals(x.getTables()[0]) ? x.getTables()[1] : x.getTables()[0]); MetaTable rightTable = tables.get(metaTable.getAlias().equals(x.getTables()[0]) ? x.getTables()[1] : x.getTables()[0]);
if (rightTable != null) { if (rightTable != null) {
@@ -122,7 +108,7 @@ public class ParseMysql implements Parser {
StringBuffer bufOth = new StringBuffer(); StringBuffer bufOth = new StringBuffer();
//order by //order by
if (!isEmpty.test(orders)) { if (!X.isEmpty(orders)) {
bufOth.append(" ").append(Order.order(orders, DbType.MYSQL)); bufOth.append(" ").append(Order.order(orders, DbType.MYSQL));
} }
//limit //limit

View File

@@ -1,6 +1,6 @@
package net.tccn.dbq.parser; package net.tccn.base.dbq.parser;
import net.tccn.dbq.fbean.FBean; import net.tccn.base.dbq.fbean.FBean;
/** /**
* Db 执行解释层 * Db 执行解释层

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.qtask; package net.tccn.base.dbq.qtask;
import lombok.Data; import lombok.Data;
import net.tccn.base.arango.Doc; import net.tccn.base.arango.Doc;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.table; package net.tccn.base.dbq.table;
import lombok.Data; import lombok.Data;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.table; package net.tccn.base.dbq.table;
import lombok.Data; import lombok.Data;

View File

@@ -1,4 +1,4 @@
package net.tccn.dbq.table; package net.tccn.base.dbq.table;
import lombok.Data; import lombok.Data;

View File

@@ -11,9 +11,6 @@ import java.util.*;
* @author: liangxianyou * @author: liangxianyou
*/ */
public final class DictKit { public final class DictKit {
private static String dcate = "db";
private static String dataPath;
private static Map<String, DictKit> kits = new HashMap<>(); private static Map<String, DictKit> kits = new HashMap<>();
private String platToken; private String platToken;
private Map<String, List<Dict>> dicts; private Map<String, List<Dict>> dicts;
@@ -32,6 +29,10 @@ public final class DictKit {
return dictKit; return dictKit;
} }
public synchronized void reload() {
this.dicts = MetaKit.getDictData(platToken);
}
// 初始化字典,不同模式下,数据来源不同 // 初始化字典,不同模式下,数据来源不同
private void stop() { private void stop() {
@@ -144,7 +145,7 @@ public final class DictKit {
Objects.requireNonNull(label, "label 不能为空"); Objects.requireNonNull(label, "label 不能为空");
List<Dict> dicts = getDicts(code); List<Dict> dicts = getDicts(code);
Optional<Dict> any = dicts.stream().filter(x -> label.equals(x.get("label"))).findAny(); Optional<Dict> any = dicts.stream().filter(x -> label.equals(x.getLabel())).findAny();
return any.isPresent() ? any.get().getValue() : ""; return any.isPresent() ? any.get().getValue() : "";
} }

View File

@@ -1,8 +1,7 @@
package net.tccn.service; package net.tccn.dict;
import net.tccn.base.BaseService;
import net.tccn.base.JBean; import net.tccn.base.JBean;
import net.tccn.dict.Dict;
import net.tccn.dict.DictKit;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestParam; import org.redkale.net.http.RestParam;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;

View File

@@ -1,5 +1,6 @@
package net.tccn.servlet; package net.tccn.file;
import net.tccn.base.BaseServlet;
import net.tccn.base.JBean; import net.tccn.base.JBean;
import net.tccn.base.Kv; import net.tccn.base.Kv;
import org.redkale.net.http.*; import org.redkale.net.http.*;

View File

@@ -1,10 +1,7 @@
package net.tccn.service; package net.tccn.file;
import net.tccn.base.ExcelKit; import net.tccn.base.*;
import net.tccn.base.JBean; import net.tccn.base.dbq.table.Field;
import net.tccn.base.Kv;
import net.tccn.base.MetaKit;
import net.tccn.dbq.table.Field;
import net.tccn.meta.MetaTable; import net.tccn.meta.MetaTable;
import net.tccn.plat.SysPlat; import net.tccn.plat.SysPlat;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;

View File

@@ -2,7 +2,7 @@ package net.tccn.meta;
import lombok.Data; import lombok.Data;
import net.tccn.base.arango.Doc; import net.tccn.base.arango.Doc;
import net.tccn.dbq.table.Field; import net.tccn.base.dbq.table.Field;
import javax.persistence.Table; import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
@@ -30,7 +30,7 @@ public class MetaTable extends Doc<MetaTable> implements Serializable {
private Integer hv;//临时 private Integer hv;//临时
// ------------------------------------------------ // ------------------------------------------------
public static MetaTable toAs(net.tccn.dbq.table.Table table) { public static MetaTable toAs(net.tccn.base.dbq.table.Table table) {
List<Field> fields = table.getColumns().stream().map(Field::toAs).collect(Collectors.toList()); List<Field> fields = table.getColumns().stream().map(Field::toAs).collect(Collectors.toList());
MetaTable _bean = new MetaTable(); MetaTable _bean = new MetaTable();

View File

@@ -1,10 +1,10 @@
package net.tccn.service; package net.tccn.meta;
import net.tccn.base.BaseService;
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.base.MetaKit;
import net.tccn.dbq.table.Field; import net.tccn.base.dbq.table.Field;
import net.tccn.meta.*;
import net.tccn.plat.SysPlat; import net.tccn.plat.SysPlat;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestParam; import org.redkale.net.http.RestParam;

View File

@@ -1,15 +1,14 @@
package net.tccn.service; package net.tccn.open;
import net.tccn.base.*; import net.tccn.base.*;
import net.tccn.dbq.DbExecutors; import net.tccn.base.dbq.fbean.FBean;
import net.tccn.dbq.fbean.FBean; import net.tccn.base.dbq.*;
import net.tccn.dict.DictKit; import net.tccn.dict.DictKit;
import net.tccn.meta.MetaService; import net.tccn.meta.MetaService;
import org.redkale.net.http.HttpScope; import org.redkale.net.http.HttpScope;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestParam; import org.redkale.net.http.RestParam;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;
import org.redkale.util.Comment;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@@ -1,14 +0,0 @@
package net.tccn.oth;
import net.tccn.base.Kv;
/**
* @author: liangxianyou
*/
public class QtaskTest {
public Kv abx(Kv kv) {
return Kv.of("hello", "world").putAll(kv);
}
}

View File

@@ -1,11 +1,10 @@
package net.tccn.service; package net.tccn.plat;
import net.tccn.base.BaseService;
import net.tccn.base.JBean; import net.tccn.base.JBean;
import net.tccn.base.MetaKit; import net.tccn.base.MetaKit;
import net.tccn.base.PageBean; import net.tccn.base.PageBean;
import net.tccn.dbq.jdbc.api.DbAccount; import net.tccn.base.dbq.jdbc.api.DbAccount;
import net.tccn.plat.DbPlat;
import net.tccn.plat.SysPlat;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;
import org.redkale.source.Flipper; import org.redkale.source.Flipper;

View File

@@ -1,12 +1,13 @@
package net.tccn.service; package net.tccn.plat;
import net.tccn.base.BaseService;
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.base.MetaKit;
import net.tccn.dbq.jdbc.api.DbAccount; import net.tccn.base.dbq.jdbc.api.DbAccount;
import net.tccn.dbq.jdbc.api.DbKit; import net.tccn.base.dbq.jdbc.api.DbKit;
import net.tccn.dbq.table.Column; import net.tccn.base.dbq.table.Column;
import net.tccn.dbq.table.Table; import net.tccn.base.dbq.table.Table;
import net.tccn.meta.MetaTable; import net.tccn.meta.MetaTable;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;

View File

@@ -1,9 +1,11 @@
package net.tccn.service; package net.tccn.plat;
import net.tccn.base.BaseService;
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.base.MetaKit;
import net.tccn.dbq.table.Table; import net.tccn.base.dbq.table.Table;
import net.tccn.file._FileService;
import net.tccn.meta.MetaTable; import net.tccn.meta.MetaTable;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestParam; import org.redkale.net.http.RestParam;

View File

@@ -1,8 +1,8 @@
package net.tccn.service; package net.tccn.qtask;
import net.tccn.base.BaseService;
import net.tccn.base.JBean; import net.tccn.base.JBean;
import net.tccn.base.Kv; import net.tccn.base.Kv;
import net.tccn.qtask.TaskKit;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestParam; import org.redkale.net.http.RestParam;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;

View File

@@ -2,7 +2,7 @@ package net.tccn.qtask;
import lombok.Data; import lombok.Data;
import net.tccn.base.Kv; import net.tccn.base.Kv;
import net.tccn.dbq.jdbc.api.DbAccount; import net.tccn.base.dbq.jdbc.api.DbAccount;
/** /**
* |- dbp: 调用谁, 参数, * |- dbp: 调用谁, 参数,

View File

@@ -1,10 +1,9 @@
package net.tccn.service; package net.tccn.qtask;
import net.tccn.base.BaseService;
import net.tccn.base.JBean; import net.tccn.base.JBean;
import net.tccn.base.MetaKit; import net.tccn.base.MetaKit;
import net.tccn.base.PageBean; import net.tccn.base.PageBean;
import net.tccn.qtask.TaskEntity;
import net.tccn.qtask.TaskKit;
import org.redkale.net.http.RestParam; import org.redkale.net.http.RestParam;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;
import org.redkale.source.Flipper; import org.redkale.source.Flipper;

View File

@@ -4,7 +4,7 @@ import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.template.Engine; import com.jfinal.template.Engine;
import com.jfinal.template.Template; import com.jfinal.template.Template;
import net.tccn.base.MetaKit; import net.tccn.base.MetaKit;
import net.tccn.dbq.jdbc.api.DbKit; import net.tccn.base.dbq.jdbc.api.DbKit;
import net.tccn.qtask.QTask; import net.tccn.qtask.QTask;
import net.tccn.qtask.Task; import net.tccn.qtask.Task;

View File

@@ -1,8 +1,8 @@
package net.tccn.service; package net.tccn.user;
import net.tccn.base.BaseService;
import net.tccn.base.JBean; import net.tccn.base.JBean;
import net.tccn.base.MetaKit; import net.tccn.base.MetaKit;
import net.tccn.user.User;
import org.redkale.net.http.RestMapping; import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestService; import org.redkale.net.http.RestService;
import org.redkale.net.http.RestSessionid; import org.redkale.net.http.RestSessionid;

View File

@@ -0,0 +1 @@
net.tccn.base.dbq.jdbc.api.DbSourceMysql

View File

@@ -1 +0,0 @@
net.tccn.dbq.jdbc.api.DbSourceMysql

View File

@@ -1,8 +1,9 @@
import net.tccn.base.*; import net.tccn.base.*;
import net.tccn.dbq.fbean.FBean; import net.tccn.base.dbq.fbean.FBean;
import net.tccn.dbq.jdbc.api.DbAccount; import net.tccn.base.dbq.jdbc.api.DbAccount;
import net.tccn.dbq.jdbc.api.DbKit; import net.tccn.base.dbq.jdbc.api.DbKit;
import net.tccn.dbq.parser.ParseMysql; import net.tccn.base.dbq.parser.ParseMysql;
import net.tccn.dict.Dict;
import net.tccn.dict.DictKit; import net.tccn.dict.DictKit;
import net.tccn.meta.MetaService; import net.tccn.meta.MetaService;
import net.tccn.meta.MetaTable; import net.tccn.meta.MetaTable;
@@ -22,6 +23,8 @@ import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.*; import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
@@ -66,7 +69,7 @@ public class RunTest<T> {
System.out.println("list:" + parse[1]); System.out.println("list:" + parse[1]);
} }
@Test //@Test
public void jdbcTest() { public void jdbcTest() {
//DbAccount jdbcAccount = new DbAccount("jdbc:mysql://192.168.202.11:3306/gxbii_dev", "root", "eversec123098"); //DbAccount jdbcAccount = new DbAccount("jdbc:mysql://192.168.202.11:3306/gxbii_dev", "root", "eversec123098");
DbAccount dbAccount = new DbAccount(); DbAccount dbAccount = new DbAccount();
@@ -91,7 +94,7 @@ public class RunTest<T> {
System.out.println(int.class);*/ System.out.println(int.class);*/
} }
@Test //@Test
public void toAsTest() { public void toAsTest() {
Date date = Kv.toAs("2019-03-17 12:11:12", Date.class); Date date = Kv.toAs("2019-03-17 12:11:12", Date.class);
System.out.println(date); System.out.println(date);
@@ -128,7 +131,7 @@ public class RunTest<T> {
System.out.println(kv); System.out.println(kv);
} }
@Test //@Test
public void upDb$() { public void upDb$() {
/*MetaKit.getMetaServices().forEach(m -> { /*MetaKit.getMetaServices().forEach(m -> {
List<String> shows = new ArrayList<>(); List<String> shows = new ArrayList<>();
@@ -146,7 +149,7 @@ public class RunTest<T> {
} }
@Test //@Test
public void findMaxNum() { public void findMaxNum() {
int xx = asList("1", "5", "3").stream().filter(x -> !x.isEmpty()).mapToInt(x -> { int xx = asList("1", "5", "3").stream().filter(x -> !x.isEmpty()).mapToInt(x -> {
return Integer.parseInt(x) * 2; return Integer.parseInt(x) * 2;
@@ -166,12 +169,12 @@ public class RunTest<T> {
user.save(); user.save();
} }
@Test //@Test
public void t() { public void t() {
System.out.println(MetaKit.nextAlias()); System.out.println(MetaKit.nextAlias());
} }
@Test //@Test
public void kvTest() { public void kvTest() {
Map map = new HashMap<>(); Map map = new HashMap<>();
@@ -186,7 +189,7 @@ public class RunTest<T> {
System.out.println(kv); System.out.println(kv);
} }
@Test //@Test
public void tplTest() { public void tplTest() {
TplKit use = TplKit.use(true); TplKit use = TplKit.use(true);
use.addTpl(new File(FileKit.rootPath(), "tpl")); //ok use.addTpl(new File(FileKit.rootPath(), "tpl")); //ok
@@ -243,7 +246,7 @@ public class RunTest<T> {
} }
} }
@Test //@Test
public void dataToFileTest() { public void dataToFileTest() {
List<MetaService> metaServices = MetaService.dao.find(); List<MetaService> metaServices = MetaService.dao.find();
@@ -256,7 +259,7 @@ public class RunTest<T> {
FileKit.strToFile(convert.convertTo(metaKit), file); FileKit.strToFile(convert.convertTo(metaKit), file);
} }
@Test //@Test
public void readJson() { public void readJson() {
File file = new File("tmp/MetaService.json"); File file = new File("tmp/MetaService.json");
try { try {
@@ -333,7 +336,7 @@ public class RunTest<T> {
} }
// 通用导出组件测试 // 通用导出组件测试
@Test //@Test
public void exportTest() { public void exportTest() {
List<Map> list = dbKitTest(); List<Map> list = dbKitTest();
@@ -351,7 +354,7 @@ public class RunTest<T> {
} }
@Test //@Test
public void switchTest() { public void switchTest() {
String a = "2"; String a = "2";
switch (a) { switch (a) {
@@ -367,7 +370,7 @@ public class RunTest<T> {
System.out.println("end"); System.out.println("end");
} }
@Test //@Test
public void exceptionTest() { public void exceptionTest() {
try { try {
@@ -377,4 +380,251 @@ public class RunTest<T> {
} }
} }
/**
* IP区间包含IP数计算含首尾
*
* @param startIp 其实ip
* @param endIp 结束ip
* @return
*/
public int ipv4Count(String startIp, String endIp) {
String[] srartArr = startIp.split("[.]");
String[] endArr = endIp.split("[.]");
int[] c = new int[4];
int[] carryOver = {16581375, 65025, 255, 1}; // IP进位数
for (int i = 0; i < 4; i++) {
if (!srartArr[i].equals(endArr[i])) {
c[i] = Integer.parseInt(endArr[i]) - Integer.parseInt(srartArr[i]);
}
}
int count = 0;
for (int i = 0; i < c.length; i++) {
if (c[i] != 0) {
count += c[i] * carryOver[i];
}
}
return (count < 0 ? -count : count) + 1;
}
//@Test
public void timerTest() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("run task..");
}
}, 5000, 2000);
int[] n = {0};
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("周期任务 .. " + ++n[0]);
if (n[0] == 2) {
System.out.println("周期任务完成");
cancel();
}
}
}, 6000, 1000);
try {
Thread.sleep(1000 * 10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//---------------------------- LOCK TEST -----------------------------
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
int[] n = {0};
public String read() {
readLock.lock();
try {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("read result:" + n[0]);
return n[0] + "";
} finally {
readLock.unlock();
}
}
public void write() {
writeLock.lock();
try {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
n[0]++;
} finally {
writeLock.unlock();
}
}
//@Test
public void lockTest() {
new Thread(() -> {
for (int i = 0; i < 50; i++) {
read();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(() -> {
for (int i = 0; i < 50; i++) {
write();
System.out.println("写入数据次数:--------" + (i + 1));
try {
Thread.sleep(150);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(() -> {
for (int i = 0; i < 50; i++) {
write();
System.out.println("write--------" + (i + 1));
}
}).start();
try {
Thread.sleep(1000 * 30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//@Test
public void tx() {
System.out.println(ipv4Count("0.0.0.2", "0.0.0.0"));
}
Predicate<Dict> isProvice = (s) -> String.valueOf(s.getValue()).trim().endsWith("0000");
Predicate<Dict> isCity = (s) -> !isProvice.test(s) && String.valueOf(s.getValue()).trim().endsWith("00");
BiPredicate<Dict, Dict> belongProvice = (p, x) -> String.valueOf(x.getValue()).trim().startsWith(String.valueOf(p.getValue()).trim().substring(0, 2));
@Test
public void dictTest() {
MetaKit.init();
System.out.println("-------- 1 -------");
DictKit dictKit = DictKit.use("ipsm_v4");
System.out.println(dictKit.getDictLabel("useSubclass", "3"));
System.out.println(dictKit.getDictValue("isp", "广电"));
/*List<Dict> list = dictKit.getDicts("city");
list.stream().filter(x -> x.getValue().startsWith("52") && isCity.test(x)).sorted((a, b) -> a.getValue().compareTo(b.getValue())).forEach(x -> {
System.out.println(x);
});
List<Map> data = new ArrayList<>();
list.stream().filter(x -> isProvice.test(x)).sorted((a, b) -> a.getValue().compareTo(b.getValue())).forEach(x -> {
Kv kv = Kv.of("value", x.get("value")).set("label", x.get("label"));
List<Kv> childs = new ArrayList<>();
list.stream().filter(y -> y.getValue().startsWith(x.getValue().substring(0,2))
&& isCity.test(y)
).forEach(y -> {
childs.add(Kv.of("label", y.get("label")).set("value", y.get("value")));
});
childs.forEach(y -> {
List<Kv> childs2 = new ArrayList<>();
list.stream().filter(z -> z.getValue().startsWith(String.valueOf(y.get("value")).substring(0, 3))
&& !z.getValue().endsWith("00")
).forEach(z -> {
childs2.add(Kv.of("label", z.get("label")).set("value", z.get("value")));
});
y.set("childs", childs2);
});
kv.set("childs", childs);
data.add(kv);
});
FileKit.strToFile(convert.convertTo(data), new File("tmp/city.json"));*/
}
public void dictType() {
}
//@Test
public void txx() {
//2400:18c0:0:0:0:0:0:0
//System.out.println(Integer.parseInt("2400", 16));
//System.out.println(Math.pow(2, 32));
/*String[] arr = "213123".split("");
for (String x : arr) {
System.out.println(x);
}*/
/*for (int i = 1; i < 8; i++) {
String v = "1";
for (int j = 0; j < i; j++) {
v = ride(v , "65536");
}
System.out.printf("%s - %s%n", i, v);
}*/
/*String ip = "::9";
System.out.println(ipv6Num("::1"));
System.out.println(ip);*/
//System.out.println(ipv6Num("2400:18c0:0:0:0:0:0:0"));
/*for (int x = 0; x < 100; x++) {
for (int y = 0; y < 100; y++) {
long a = Integer.parseInt(IpKit.add(x + "", y + ""));
long b = x + y;
if (a != b) {
System.out.printf("%d + %d = %s, \t %s \n", x, y, a, b);
} else {
System.out.printf("=");
}
}
}*/
/*System.out.println(toNum("127.0.0.1"));
System.out.println(ipCount("0::0:0", "0::0:2"));*/
//System.out.println(toNum("254.16.3.56"));
}
} }