.
This commit is contained in:
@@ -4,12 +4,9 @@ import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.CacheSource;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
@@ -39,28 +36,6 @@ public class BaseService implements Service {
|
||||
|
||||
private static boolean tplInit = false;
|
||||
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
try {
|
||||
File file = new File(APP_HOME.toPath() + "/conf/config.txt");
|
||||
if (file.exists()) {
|
||||
prop.load(new FileInputStream(file));
|
||||
}
|
||||
} 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)
|
||||
public <T> T getT(String key, Class<T> clazz, Supplier<T> supplier) {
|
||||
Object obj = cacheSource.getAndRefresh(key, 1000 * 60 * 3, clazz);
|
||||
@@ -75,21 +50,12 @@ public class BaseService implements Service {
|
||||
return t;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public String getProperty(String k, String defaultValue){
|
||||
return prop.getProperty(k, defaultValue).replace("${APP_HOME}", APP_HOME.getPath());
|
||||
}
|
||||
@RestMapping(ignore = true)
|
||||
public String getProperty(String k){
|
||||
return prop.getProperty(k);
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public String platId(String token) {
|
||||
return MetaKit.getPlatId(token);
|
||||
}
|
||||
|
||||
public boolean isEmpty(Object obj) {
|
||||
return X.isEmpty(obj);
|
||||
return Utils.isEmpty(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package net.tccn.base;
|
||||
|
||||
import com.arangodb.ArangoDBException;
|
||||
import net.tccn.base.arango.ArangoSource;
|
||||
import net.tccn.user.User;
|
||||
import net.tccn.user.UserService;
|
||||
import org.redkale.net.http.HttpRequest;
|
||||
import org.redkale.net.http.HttpResponse;
|
||||
import org.redkale.net.http.HttpServlet;
|
||||
import org.redkale.net.http.HttpUserType;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/11/8 17:05.
|
||||
*/
|
||||
@HttpUserType(User.class)
|
||||
public class BaseServlet extends HttpServlet {
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
@@ -26,6 +24,7 @@ public class BaseServlet extends HttpServlet {
|
||||
private UserService userService;
|
||||
|
||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
public static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
@Override
|
||||
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
@@ -41,6 +40,11 @@ public class BaseServlet extends HttpServlet {
|
||||
User user = userService.current(sessionid);
|
||||
request.setCurrentUser(user);
|
||||
}
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.endsWith(".html")){
|
||||
response.finish(new File(webroot + uri));
|
||||
return;
|
||||
}
|
||||
|
||||
super.preExecute(request, response);
|
||||
}
|
||||
@@ -67,9 +71,6 @@ public class BaseServlet extends HttpServlet {
|
||||
try {
|
||||
// logger.log(Level.INFO, String.format("%s : %s", new Date(), request.getRequestURI()));
|
||||
super.execute(request, response);
|
||||
} catch (ArangoDBException e) {
|
||||
logger.log(Level.INFO, "arangodb init!", e);
|
||||
ArangoSource.use();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
e.printStackTrace();
|
||||
response.finish(JBean.by(-1, e.getMessage()));
|
||||
@@ -81,19 +82,4 @@ public class BaseServlet extends HttpServlet {
|
||||
response.finish(JBean.by(-1, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public Kv getParams(HttpRequest request, String... key) {
|
||||
Kv kv = Kv.of();
|
||||
for (String k : key) {
|
||||
if (k.contains("=")) { //如果没有值使用默认值
|
||||
kv.put(k.split("=")[0], request.getParameter(k.split("=")[0], k.split("=")[1]));
|
||||
continue;
|
||||
} else if (k.contains("<")) { //强制使用"<"右侧的值
|
||||
kv.put(k.split("<")[0], k.split("<")[1]);
|
||||
continue;
|
||||
}
|
||||
kv.put(k, request.getParameter(k));
|
||||
}
|
||||
return kv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class ExcelKit {
|
||||
}
|
||||
|
||||
if (cell.getCellType() == CellType.NUMERIC) {
|
||||
map.put(fields[j], (long) cell.getNumericCellValue() + "");
|
||||
map.put(fields[j], cell.getNumericCellValue() + "");
|
||||
} else {
|
||||
map.put(fields[j], cell.getStringCellValue());
|
||||
}
|
||||
@@ -346,7 +346,7 @@ public class ExcelKit {
|
||||
}
|
||||
|
||||
if (cell.getCellType() == CellType.NUMERIC) {
|
||||
map.put(field, (long) cell.getNumericCellValue() + "");
|
||||
map.put(field, cell.getNumericCellValue() + "");
|
||||
} else {
|
||||
map.put(field, cell.getStringCellValue());
|
||||
}
|
||||
|
||||
@@ -258,6 +258,14 @@ public class IpKit {
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
/*private static Function<String, List<Integer>> _toIntSlice = (str) -> {
|
||||
String[] strArr = str.trim().split("");
|
||||
List<Integer> arr = new ArrayList<>(strArr.length);
|
||||
for (int i = 0; i < strArr.length; i++) {
|
||||
arr.add(Integer.parseInt(strArr[i]));
|
||||
}
|
||||
return arr;
|
||||
};*/
|
||||
|
||||
/**
|
||||
* 任意两个大小正整数相减
|
||||
@@ -349,4 +357,35 @@ public class IpKit {
|
||||
}
|
||||
return _ip;
|
||||
}
|
||||
|
||||
// 任意两个小数相加 x: 0.1213, y: 0.981
|
||||
/*private static String _add(String x, String y) {
|
||||
List<Integer> xArr = _toIntSlice.apply(x.substring(2));
|
||||
List<Integer> yArr = _toIntSlice.apply(y.substring(2));
|
||||
|
||||
|
||||
String v = "";
|
||||
int len = xArr.size() > yArr.size() ? xArr.size() : yArr.size();
|
||||
int carry = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
int a = xArr.size() > (len - i - 1) ? xArr.get(len - i - 1) : 0;
|
||||
int b = yArr.size() > (len - i - 1) ? yArr.get(len - i - 1) : 0;
|
||||
int _v = a + b + carry;
|
||||
|
||||
carry = _v / 10;
|
||||
v = _v % 10 + v;
|
||||
}
|
||||
v = carry + v;
|
||||
StringBuffer buf = new StringBuffer(v).insert(v.length() - len, ".");
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
// 任意两个数相加
|
||||
public static String addx(String x, String y) {
|
||||
String str = _add(x, y);
|
||||
System.out.printf("%s + %s = %s \n", x, y, str);
|
||||
|
||||
return str;
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -15,27 +15,27 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* Created by liangxianyou@eversec.cn at 2018/3/12 14:17.
|
||||
*/
|
||||
public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
public static Kv of(){
|
||||
public class Kv<K, V> extends LinkedHashMap<K, V> {
|
||||
public static Kv of() {
|
||||
return new Kv();
|
||||
}
|
||||
|
||||
public static Kv of(Object k, Object v){
|
||||
return new Kv().set(k,v);
|
||||
public static Kv of(Object k, Object v) {
|
||||
return new Kv().set(k, v);
|
||||
}
|
||||
|
||||
public Kv<K, V> set(K k, V v){
|
||||
public Kv<K, V> set(K k, V v) {
|
||||
put(k, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kv<K,V> putAll(Kv<K,V> kv) {
|
||||
kv.forEach((k,v) -> put(k, v));
|
||||
public Kv<K, V> putAll(Kv<K, V> kv) {
|
||||
kv.forEach((k, v) -> put(k, v));
|
||||
return this;
|
||||
}
|
||||
|
||||
// 将obj 属性映射到Kv 中
|
||||
public static Kv toKv(Object m, String ... fields) {
|
||||
public static Kv toKv(Object m, String... fields) {
|
||||
Kv kv = Kv.of();
|
||||
Stream.of(fields).forEach(field -> {
|
||||
String filedT = field;
|
||||
@@ -45,10 +45,10 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
if (field.contains("=")) {
|
||||
String[] arr = field.split("=");
|
||||
filedT = arr[0];
|
||||
filedS= arr[1];
|
||||
filedS = arr[1];
|
||||
}
|
||||
|
||||
Method method = m.getClass().getDeclaredMethod("get" + X.toUpperCaseFirst(filedS));
|
||||
Method method = m.getClass().getDeclaredMethod("get" + Utils.toUpperCaseFirst(filedS));
|
||||
if (method != null) {
|
||||
kv.set(filedT, method.invoke(m));
|
||||
}
|
||||
@@ -108,87 +108,57 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
return null;
|
||||
} else if (v.getClass() == clazz) {
|
||||
return (T) v;
|
||||
} else if (clazz == String.class) {
|
||||
} else if (clazz == String.class) {
|
||||
return (T) String.valueOf(v);
|
||||
}
|
||||
|
||||
Object v1 = null;
|
||||
Object v1 = v;
|
||||
try {
|
||||
|
||||
if (v.getClass() == Long.class) {//多种数值类型的处理: Long => x
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "int":
|
||||
case "Integer": v1 = (int)(long) v; break;
|
||||
case "short":
|
||||
case "Short": v1 = (short)(long) v; break;
|
||||
case "float":
|
||||
case "Float": v1 = (float)(long) v; break;
|
||||
case "byte":
|
||||
case "Byte": v1 = (byte)(long) v; break;
|
||||
default: v1 = v;
|
||||
case "int", "Integer" -> v1 = (int) (long) v;
|
||||
case "short", "Short" -> v1 = (short) (long) v;
|
||||
case "float", "Float" -> v1 = (float) (long) v;
|
||||
case "byte", "Byte" -> v1 = (byte) (long) v;
|
||||
}
|
||||
} else if (v.getClass() == Double.class) {
|
||||
if (isNumber.test(clazz)) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "long":
|
||||
case "Long": v1 = (long)(double) v; break;
|
||||
case "int":
|
||||
case "Integer": v1 = (int)(double) v; break;
|
||||
case "short":
|
||||
case "Short": v1 = (short)(double) v; break;
|
||||
case "float":
|
||||
case "Float": v1 = (float)(double) v; break;
|
||||
case "byte":
|
||||
case "Byte": v1 = (byte)(double) v; break;
|
||||
default: v1 = v;
|
||||
case "long", "Long" -> v1 = (long) (double) v;
|
||||
case "int", "Integer" -> v1 = (int) (double) v;
|
||||
case "short", "Short" -> v1 = (short) (double) v;
|
||||
case "float", "Float" -> v1 = (float) (double) v;
|
||||
case "byte", "Byte" -> v1 = (byte) (double) v;
|
||||
}
|
||||
} else if (clazz == String.class){
|
||||
} else if (clazz == String.class) {
|
||||
v1 = String.valueOf(v);
|
||||
}
|
||||
} else if (v.getClass() == String.class) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "Date":
|
||||
v1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) v); break;
|
||||
case "short":
|
||||
case "Short": v1 = (short)Double.parseDouble((String) v); break;
|
||||
case "float":
|
||||
case "Float": v1 = (float)Double.parseDouble((String) v); break;
|
||||
case "int":
|
||||
case "Integer": v1 = (int)Double.parseDouble((String) v); break;
|
||||
case "long":
|
||||
case "Long": v1 = (long)Double.parseDouble((String) v); break;
|
||||
case "double":
|
||||
case "Double": v1 = Double.parseDouble((String) v); break;
|
||||
case "byte":
|
||||
case "Byte": v1 = Byte.parseByte((String) v); break;
|
||||
default: v1 = v;
|
||||
case "Date" -> v1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) v);
|
||||
case "short", "Short" -> v1 = (short) Double.parseDouble((String) v);
|
||||
case "float", "Float" -> v1 = (float) Double.parseDouble((String) v);
|
||||
case "int", "Integer" -> v1 = (int) Double.parseDouble((String) v);
|
||||
case "long", "Long" -> v1 = (long) Double.parseDouble((String) v);
|
||||
case "double", "Double" -> v1 = Double.parseDouble((String) v);
|
||||
case "byte", "Byte" -> v1 = Byte.parseByte((String) v);
|
||||
}
|
||||
} else if (v.getClass() == Integer.class) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "long":
|
||||
case "Long": v1 = (long) (int) v; break;
|
||||
case "short":
|
||||
case "Short": v1 = (short) (int) v; break;
|
||||
case "float":
|
||||
case "Float": v1 = (float) (int) v; break;
|
||||
case "byte":
|
||||
case "Byte": v1 = (byte)(int) v; break;
|
||||
default: v1 = v;
|
||||
case "long", "Long" -> v1 = (long) (int) v;
|
||||
case "short", "Short" -> v1 = (short) (int) v;
|
||||
case "float", "Float" -> v1 = (float) (int) v;
|
||||
case "byte", "Byte" -> v1 = (byte) (int) v;
|
||||
}
|
||||
} else if (v.getClass() == Float.class) {
|
||||
switch (clazz.getSimpleName()) {
|
||||
case "long":
|
||||
case "Long": v1 = (long) (float) v; break;
|
||||
case "int":
|
||||
case "Integer": v1 = (int) (float)v; break;
|
||||
case "short":
|
||||
case "Short": v1 = (short) (float) v; break;
|
||||
case "byte":
|
||||
case "Byte": v1 = (byte)(float) v; break;
|
||||
default: v1 = v;
|
||||
case "long", "Long" -> v1 = (long) (float) v;
|
||||
case "int", "Integer" -> v1 = (int) (float) v;
|
||||
case "short", "Short" -> v1 = (short) (float) v;
|
||||
case "byte", "Byte" -> v1 = (byte) (float) v;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
v1 = v;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
@@ -198,7 +168,7 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
}
|
||||
|
||||
public static <T> T toBean(Map map, Class<T> clazz) {
|
||||
//按照方法名 + 类型寻找,
|
||||
//按照方法名 + 类型寻找,
|
||||
//按照方法名 寻找
|
||||
//+
|
||||
Object obj = null;
|
||||
@@ -208,10 +178,9 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
new IllegalArgumentException("创建对象实列失败", e); // 检查clazz是否有无参构造
|
||||
}
|
||||
|
||||
for (String k : (Set<String>)map.keySet()) {
|
||||
for (String k : (Set<String>) map.keySet()) {
|
||||
Object v = map.get(k);
|
||||
if (v == null) continue;
|
||||
//寻找method
|
||||
try {
|
||||
String methodName = "set" + upFirst.apply(k);
|
||||
Class tClazz = null;
|
||||
@@ -243,7 +212,7 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
method.invoke(obj, toAs(v, tClazz));
|
||||
}
|
||||
|
||||
//没有方法,找属性注解
|
||||
//没有方法,找属性注解
|
||||
if (method == null) {
|
||||
Field field = null;
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
@@ -270,5 +239,4 @@ public class Kv<K,V> extends LinkedHashMap<K,V> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -483,7 +483,7 @@ public final class MetaKit {
|
||||
Set<String> allAlias;
|
||||
|
||||
if (!all) {
|
||||
allAlias = X.concat(
|
||||
allAlias = Utils.concat(
|
||||
metaService.getFilters().stream().map(f -> {
|
||||
String col = (String) f.getName();
|
||||
String alias = col.split("[.]")[0];
|
||||
|
||||
@@ -20,11 +20,13 @@ public class MetaListenter implements ApplicationListener {
|
||||
@Resource(name = "property.dataPath")
|
||||
private String dataPath;
|
||||
|
||||
public static ResourceFactory resourceFactory;
|
||||
|
||||
@Override
|
||||
public void preStart(Application application) {
|
||||
CompletableFuture.runAsync(()-> {
|
||||
ResourceFactory rf = application.getResourceFactory();
|
||||
resourceFactory = rf;
|
||||
rf.inject(this);
|
||||
|
||||
MetaKit.dcate = dcate;
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package net.tccn.base;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
public final class PropKit {
|
||||
private static Properties properties = new Properties();
|
||||
static {
|
||||
try {
|
||||
// 读取导入配置文件
|
||||
|
||||
properties.load(new FileReader(new File("conf/config.txt")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getProperty(String key) {
|
||||
return properties.getProperty(key);
|
||||
}
|
||||
public static String getProperty(String key, String value) {
|
||||
String oldValue = getProperty(key);
|
||||
properties.setProperty(key, value);
|
||||
return oldValue;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* Created by liangxianyou at 2019/3/19 18:01.
|
||||
*/
|
||||
public class X {
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* 将集合数组合并到一个Set<T> 集合中
|
||||
@@ -7,9 +7,10 @@ import com.arangodb.Function;
|
||||
import com.arangodb.entity.DocumentCreateEntity;
|
||||
import com.arangodb.entity.DocumentDeleteEntity;
|
||||
import com.arangodb.entity.MultiDocumentEntity;
|
||||
import net.tccn.base.PropKit;
|
||||
import net.tccn.base.X;
|
||||
import net.tccn.base.MetaListenter;
|
||||
import net.tccn.base.Utils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -26,40 +27,35 @@ import static java.util.Arrays.asList;
|
||||
*/
|
||||
public class ArangoSource {
|
||||
|
||||
@Resource(name = "property.arango.host")
|
||||
private String host = "127.0.0.1";
|
||||
@Resource(name = "property.arango.user")
|
||||
private String user = "root";
|
||||
@Resource(name = "property.arango.password")
|
||||
private String password = "123456";
|
||||
@Resource(name = "property.arango.port")
|
||||
private int port = 8529;
|
||||
|
||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
private ArangoDB arangoDb;
|
||||
|
||||
private static Map<String, ArangoSource> sources = new HashMap();
|
||||
private static Map<String, ArangoSource> sourceMap = new HashMap();
|
||||
|
||||
private ArangoSource() {
|
||||
MetaListenter.resourceFactory.inject(this);
|
||||
|
||||
arangoDb = new ArangoDB.Builder().host(host, port).user(user).password(password).build();
|
||||
}
|
||||
|
||||
private ArangoSource(ArangoDB arangoDb) {
|
||||
MetaListenter.resourceFactory.inject(this);
|
||||
|
||||
this.arangoDb = arangoDb;
|
||||
}
|
||||
|
||||
public static ArangoSource use() {
|
||||
return use("main");
|
||||
}
|
||||
|
||||
public static ArangoSource use(String unit) {
|
||||
if (unit == null || unit.isEmpty() || "main".equals(unit)) {
|
||||
unit = "";
|
||||
} else {
|
||||
unit = "." + 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() {
|
||||
return arangoDb;
|
||||
ArangoSource arangoSource = new ArangoSource();
|
||||
return arangoSource;
|
||||
}
|
||||
|
||||
public ArangoDatabase db(String db) {
|
||||
@@ -137,7 +133,7 @@ public class ArangoSource {
|
||||
private Function<Doc, StringBuilder> orderBuilder = (t) -> {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Map<String, Integer> order = t.getOrder();
|
||||
if (X.isEmpty(order)) {
|
||||
if (Utils.isEmpty(order)) {
|
||||
return buf.append(" sort d._key desc");
|
||||
}
|
||||
buf.append(" sort ");
|
||||
@@ -151,7 +147,7 @@ public class ArangoSource {
|
||||
private Function<Doc, StringBuilder> returnBuilder = (t) -> {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
if (X.isEmpty(t.get_Shows())) {
|
||||
if (Utils.isEmpty(t.get_Shows())) {
|
||||
return buf.append(" return d");
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,6 @@ public abstract class Doc<T extends Doc> {
|
||||
} catch (ArangoDBException e) {
|
||||
System.out.println(aql);
|
||||
e.printStackTrace();
|
||||
ArangoSource.use();
|
||||
}
|
||||
return db.query(aql, clazz).asListRemaining();
|
||||
}
|
||||
@@ -241,7 +240,6 @@ public abstract class Doc<T extends Doc> {
|
||||
} catch (ArangoDBException e) {
|
||||
System.out.println(aql);
|
||||
e.printStackTrace();
|
||||
ArangoSource.use();
|
||||
}
|
||||
return db.query(aql, clazz).first();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.tccn.base.dbq.fbean;
|
||||
|
||||
import net.tccn.base.Kv;
|
||||
import net.tccn.base.X;
|
||||
import net.tccn.base.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,7 +31,7 @@ public enum FilterType {
|
||||
|
||||
//不同的条件构建过滤语句
|
||||
public static String buildSql(Filter filter) {
|
||||
if (X.isEmpty(filter.getValue()) && X.isEmpty(filter.getValues())) {
|
||||
if (Utils.isEmpty(filter.getValue()) && Utils.isEmpty(filter.getValues())) {
|
||||
return "";
|
||||
}
|
||||
FilterType filterType = getFilterType(filter.getType());
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package net.tccn.base.dbq.fbean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/12/14 15:36.
|
||||
*/
|
||||
@Data
|
||||
public class Order {
|
||||
private String col;
|
||||
private int desc;//1 or -1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.tccn.base.dbq.jdbc.api;
|
||||
|
||||
import net.tccn.base.X;
|
||||
import net.tccn.base.Utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -31,7 +31,7 @@ public class DbKit implements DbSource{
|
||||
this.catalog = catalog;
|
||||
|
||||
try {
|
||||
DbSource dbSource = X.getDbSource(DbSource.class, dbAccount.getCate());
|
||||
DbSource dbSource = Utils.getDbSource(DbSource.class, dbAccount.getCate());
|
||||
dbSource.setDbAccount(dbAccount);
|
||||
dbSource.setCatalog(catalog);
|
||||
|
||||
|
||||
@@ -60,10 +60,9 @@ public class DbSourceMysql implements DbSource {
|
||||
PreparedStatement ps = connection.prepareStatement(sql);
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
List list = new ArrayList();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int count = metaData.getColumnCount();
|
||||
while (rs.next()) {
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int count = metaData.getColumnCount();
|
||||
|
||||
Map row = new HashMap();
|
||||
for (int i = 1; i <= count; i++) {
|
||||
String columnTypeName = metaData.getColumnTypeName(i);
|
||||
@@ -87,6 +86,7 @@ public class DbSourceMysql implements DbSource {
|
||||
|
||||
return list;
|
||||
} catch (SQLException e) {
|
||||
System.out.println("sql :"+ sql);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.tccn.meta.MetaLink;
|
||||
import net.tccn.meta.MetaService;
|
||||
import net.tccn.meta.MetaTable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
@@ -64,20 +63,20 @@ public class ParseMysql implements Parser {
|
||||
if (sameDbFun.test(tables) || true) {
|
||||
// where 1=1 and xx=xx
|
||||
StringBuffer bufWhere = new StringBuffer();
|
||||
if (!X.isEmpty(filters)) {
|
||||
if (!Utils.isEmpty(filters)) {
|
||||
bufWhere.append(Filter.filter(filters, DbType.MYSQL));
|
||||
}
|
||||
|
||||
//select a.x, b.y, c.z
|
||||
StringBuffer bufSelect = new StringBuffer();
|
||||
bufSelect.append("select ");
|
||||
if ("export".equals(fBean.getType()) && !X.isEmpty(exports)) {
|
||||
if ("export".equals(fBean.getType()) && !Utils.isEmpty(exports)) {
|
||||
exports.forEach(x -> {
|
||||
bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',");
|
||||
});
|
||||
bufSelect.deleteCharAt(bufSelect.length() - 1);
|
||||
}
|
||||
else if ("list".equals(fBean.getType()) && !X.isEmpty(shows)) {
|
||||
else if ("list".equals(fBean.getType()) && !Utils.isEmpty(shows)) {
|
||||
shows.forEach(x -> {
|
||||
bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',");
|
||||
});
|
||||
@@ -88,13 +87,13 @@ public class ParseMysql implements Parser {
|
||||
|
||||
//from
|
||||
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()).append("`");
|
||||
//left join
|
||||
if (!X.isEmpty(links)) {
|
||||
if (!Utils.isEmpty(links)) {
|
||||
links.forEach(x -> {
|
||||
MetaTable rightTable = tables.get(metaTable.getAlias().equals(x.getTables()[0]) ? x.getTables()[1] : x.getTables()[0]);
|
||||
if (rightTable != null) {
|
||||
bufFrom.append(" left join ").append(rightTable.getCatalog()).append(".").append(rightTable.getName()).append(" ").append(rightTable.getAlias()).append(" on ");
|
||||
bufFrom.append(" left join ").append(rightTable.getCatalog()).append(".").append(rightTable.getName()).append(" `").append(rightTable.getAlias()).append("` on ");
|
||||
int tag = bufFrom.length();
|
||||
x.getLink().forEach((k, v) -> {
|
||||
if (bufFrom.length() > tag) {
|
||||
@@ -108,7 +107,7 @@ public class ParseMysql implements Parser {
|
||||
|
||||
StringBuffer bufOth = new StringBuffer();
|
||||
//order by
|
||||
if (!X.isEmpty(orders)) {
|
||||
if (!Utils.isEmpty(orders)) {
|
||||
bufOth.append(" ").append(Order.order(orders, DbType.MYSQL));
|
||||
}
|
||||
//limit
|
||||
@@ -168,18 +167,18 @@ public class ParseMysql implements Parser {
|
||||
List<String> keys = data.keySet()
|
||||
.stream()
|
||||
.filter(x ->
|
||||
x.startsWith(alias + ".") || !X.isEmpty(data.get(alias + "." + x))
|
||||
x.startsWith(alias + ".") || !Utils.isEmpty(data.get(alias + "." + x))
|
||||
).collect(Collectors.toList());
|
||||
if (pks.length == 0) {
|
||||
throw new CfgException("保存数据失败,检查业务主表[%s-%S]主键配置", mainTable.getName(), mainTable.getComment());
|
||||
} else if (keys.size() == 0) {
|
||||
throw new CfgException("保存数据失败,提交数据不能改空");
|
||||
throw new CfgException("保存数据失败,提交数据不能改空");
|
||||
}
|
||||
|
||||
|
||||
//单主键
|
||||
String pv = data.get(alias + "." + pks[0]);
|
||||
if (X.isEmpty(pv)) { //新增
|
||||
if (Utils.isEmpty(pv)) { //新增
|
||||
String sqlTpl = "INSERT INTO `%s` (%s) VALUES %s;"; // para: table、 ks、 vs
|
||||
StringBuffer ks = new StringBuffer();// `k1`,`k2`,`k3`, ...
|
||||
StringBuffer vs = new StringBuffer();// `v1`,`v2`,`v3`, ...
|
||||
|
||||
@@ -14,6 +14,7 @@ public class Field {
|
||||
private String inType;
|
||||
private String inExt;
|
||||
private Boolean pk; // 是否主键
|
||||
private Boolean notNull; // 是否主键
|
||||
|
||||
public Field() {}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.tccn.base.JBean;
|
||||
import net.tccn.base.Kv;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -16,27 +17,44 @@ import java.util.List;
|
||||
@WebServlet(value = {"/upload/*"}, comment = "测试servlet")
|
||||
public class FileServlet extends BaseServlet {
|
||||
|
||||
@Resource(name = "property.upfile.dir")
|
||||
private String dir = "";
|
||||
@Resource(name = "property.upfile.view")
|
||||
private String view = "";
|
||||
|
||||
private String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
||||
|
||||
@HttpMapping(url = "/upload/", comment = "文件上传,访问地址:/upload/x")
|
||||
public void uploadExcel(HttpRequest request, HttpResponse response) {
|
||||
JBean jBean = new JBean();
|
||||
List list = new ArrayList();
|
||||
String cate = request.getParameter("cate");
|
||||
List data = new ArrayList();
|
||||
try {
|
||||
for (MultiPart part : request.multiParts()) {
|
||||
String filePath = "u/table/" + part.getFilename();
|
||||
File destFile = new File(webroot, filePath);
|
||||
destFile.getParentFile().mkdirs();
|
||||
String name = part.getFilename();
|
||||
String suffix = name.substring(name.lastIndexOf("."));
|
||||
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||
File destFile = new File((winos ? webroot + "/tem/" : dir) + path);
|
||||
|
||||
if (!destFile.getParentFile().exists()) {
|
||||
destFile.getParentFile().mkdirs();
|
||||
}
|
||||
part.save(destFile);
|
||||
|
||||
list.add(
|
||||
Kv.of("name", part.getFilename())
|
||||
.set("filePath", filePath)
|
||||
.set("viewPath", filePath)
|
||||
);
|
||||
String viewPath = (winos ? "/tem/" : view) + path;
|
||||
if ("editor".equalsIgnoreCase(cate)) {
|
||||
data.add(viewPath);
|
||||
} else {
|
||||
data.add(Kv.of("name", part.getFilename()).set("filePath", viewPath).set("viewPath", viewPath));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
response.finish(jBean.set(0, "", list));
|
||||
if ("editor".equalsIgnoreCase(cate)) {
|
||||
response.finish(Kv.of("errno", 0).set("data", data));
|
||||
} else {
|
||||
response.finish(JBean.by(0, "", data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ public class MetadataService extends BaseService { //arango
|
||||
public JBean dbPlatUpdate(MetaTable metaTable, @RestParam(name = "platToken") String token) {
|
||||
|
||||
MetaTable _metaTable = MetaKit.getMetaTableByKey(metaTable.getKey());
|
||||
_metaTable.setName(metaTable.getName());
|
||||
_metaTable.setComment(metaTable.getComment());
|
||||
_metaTable.setCatalog(metaTable.getCatalog());
|
||||
_metaTable.setDbPlatId(metaTable.getDbPlatId());
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DataService extends BaseService {
|
||||
PageBean page = DbExecutors.findPage(fBean);
|
||||
Kv heads = MetaKit.cfgExport(fBean.getName(), token);
|
||||
|
||||
if (X.isEmpty(fileName)) {
|
||||
if (Utils.isEmpty(fileName)) {
|
||||
fileName = String.format("export_excel_%s", System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
10
src/main/java/net/tccn/tmp/QStat.java
Normal file
10
src/main/java/net/tccn/tmp/QStat.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package net.tccn.tmp;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QStat {
|
||||
private String sql;
|
||||
private List<Map<String, String>> header;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user