This commit is contained in:
2022-11-03 10:58:48 +08:00
parent b78a482d3b
commit b704abcece
23 changed files with 1192 additions and 62 deletions

View File

@@ -3,7 +3,7 @@ package net.tccn.base;
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.source.CacheMemorySource;
import javax.annotation.Resource;
import java.io.File;
@@ -25,8 +25,8 @@ public class BaseService implements Service {
public static boolean isWinos = System.getProperty("os.name").contains("Window");
@Resource(name = "cacheSource")
protected CacheSource cacheSource;
@Resource(name = "cache")
protected static CacheMemorySource cacheSource = new CacheMemorySource("cache");
@Resource(name = "APP_HOME")
protected File APP_HOME;

View File

@@ -5,7 +5,6 @@ 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;
@@ -15,7 +14,6 @@ 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")
@@ -38,10 +36,15 @@ public class BaseServlet extends HttpServlet {
if (sessionid != null) {
User user = userService.current(sessionid);
request.setCurrentUser(user);
/*request.setCurrentUserSupplier(() -> {
return user;
});*/
if (user != null) {
request.setCurrentUserid(user.getId());
}
}
String uri = request.getRequestURI();
if (uri.endsWith(".html")){
if (uri.endsWith(".html")) {
response.finish(new File(webroot + uri));
return;
}
@@ -51,8 +54,8 @@ public class BaseServlet extends HttpServlet {
@Override
protected void authenticate(HttpRequest request, HttpResponse response) throws IOException {
//fixme: 权限拦截
if (request.currentUser() == null) {
//fixme: 权限拦截
if (request.currentUserid(String.class) == null) {
String accept = request.getHeader("Accept");
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With")) || (accept != null && accept.contains("application/json"))) {
response.finish(JBean.by(-2, "未登陆"));

View File

@@ -2,8 +2,10 @@ package net.tccn.base;
import com.jfinal.kit.Kv;
import com.jfinal.template.Engine;
import org.redkale.convert.json.JsonConvert;
import java.io.*;
import java.lang.reflect.Type;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Files;
@@ -17,6 +19,8 @@ import static java.util.Arrays.asList;
*/
public final class FileKit {
protected static final JsonConvert convert = JsonConvert.root();
private FileKit() {
}
@@ -36,15 +40,30 @@ public final class FileKit {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try (
FileOutputStream out = new FileOutputStream(file);
) {
try (FileOutputStream out = new FileOutputStream(file)) {
out.write(entityBody.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public static void append(String str, File file) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try (FileOutputStream out = new FileOutputStream(file, true)) {
out.write(str.getBytes("UTF-8"));
if (!str.endsWith("\n")) {
out.write("\n".getBytes("UTF-8"));
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
/**
* 拷贝文件/文件目录
*
@@ -134,6 +153,27 @@ public final class FileKit {
return buf.toString();
}
public static String readAll(File file) {
StringBuffer buf = new StringBuffer();
String str;
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)))
) {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return buf.toString();
}
public static <T> T readAs(File file, Type typeToken) throws IOException {
String str = readAll(file);
return convert.convertFrom(typeToken, str);
}
/**
* 渲染模板到文件
*

View File

@@ -17,7 +17,7 @@ import org.redkale.util.Comment;
import org.redkale.util.TypeToken;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.*;
import java.util.function.BiFunction;
@@ -73,47 +73,54 @@ public final class MetaKit {
reload(t.getClass(), t.getKey());
}
public static <T extends Doc> void reload(Class<T> clazz, String key) {
public static void main(String[] args) throws IOException {
Type type = new TypeToken<List<DbAccount>>() {
}.getType();
dbPlats = FileKit.readAs(new File("D:\\Java\\meta-kit\\conf\\data\\DbAccount.json"), type);
//convert.convertFrom(type,"[{\"catalogs\":[\"test\"],\"cate\":\"mysql\",\"id\":\"db_plat/67275393\",\"key\":\"67275393\",\"name\":\"ylz测试\",\"url\":\"jdbc:mysql://119.3.106.117:3306\",\"user\":\"root\"},{\"catalogs\":[\"v09x_platf_core\"],\"cate\":\"mysql\",\"id\":\"db_plat/67275392\",\"key\":\"67275392\",\"name\":\"platf_qc\",\"url\":\"jdbc:mysql://121.196.17.55:6063\",\"user\":\"root\"},{\"catalogs\":[\"official_core\",\"official_ipci\",\"v09x_platf_core\",\"platf_quest\",\"platf_pay\",\"platf_mall\",\"platf_oth\",\"platf_im\",\"z_core\"],\"cate\":\"mysql\",\"id\":\"db_plat/67275391\",\"key\":\"67275391\",\"name\":\"platf_pro\",\"url\":\"jdbc:mysql://122.112.180.156:6033\",\"user\":\"guest\"},{\"catalogs\":[\"db_diamond\"],\"id\":\"db_plat/53533152\",\"key\":\"53533152\",\"name\":\"钻石项目\",\"url\":\"jdbc:mysql://192.168.201.51:3306/db_diamond?characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai&useSSL=false\",\"user\":\"root\"},{\"catalogs\":[\"db_diamond\"],\"id\":\"db_plat/53532996\",\"key\":\"53532996\",\"name\":\"钻石项目\",\"url\":\"jdbc:mysql://192.168.201.51:3306/db_diamond?characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai&useSSL=false\",\"user\":\"root\"},{\"catalogs\":[\"platf_im\",\"v09x_platf_core\",\"platf_oss\",\"platf_quest\",\"platf_oth\",\"sport_oss\",\"zhub\",\"cpg_core\",\"z_core\",\"z_config\",\"z_im\",\"z_mall\",\"z_quest\",\"z_oss\",\"z_oth\",\"cmt_oss\",\"cmt_depot_core\",\"cmt_core\",\"sport_core\"],\"cate\":\"mysql\",\"id\":\"db_plat/52481174\",\"key\":\"52481174\",\"name\":\"platf_dev\",\"url\":\"jdbc:mysql://47.111.150.118:6063\",\"user\":\"root\"},{\"catalogs\":[],\"cate\":\"mysql\",\"id\":\"db_plat/4375768\",\"key\":\"4375768\",\"name\":\"mysql数据库\",\"url\":\"jdbc:mysql://192.168.50.124:3306/mytest?characterEncoding=utf-8&autoReconnect=true&useSSL=false&connectTimeout=3000\",\"user\":\"root\"},{\"catalogs\":[],\"cate\":\"mysql\",\"id\":\"db_plat/4267761\",\"key\":\"4267761\",\"name\":\"测试\",\"remark\":\"sadfdsaf\",\"url\":\"123&connectTimeout=5000\",\"user\":\"root\"},{\"catalogs\":[\"db_art\",\"db_jsons_bbs\",\"db_mater\",\"db_redbbs\",\"jfly\",\"redbbs_dev\",\"meta_kit_test\"],\"cate\":\"mysql\",\"id\":\"db_plat/3321254\",\"key\":\"3321254\",\"name\":\"测试-DB【可用】\",\"url\":\"jdbc:mysql://120.24.230.60:3306/redbbs?characterEncoding=utf-8&autoReconnect=true&useSSL=false&connectTimeout=3000\",\"user\":\"guest\"},{\"catalogs\":[\"blockchain\",\"gxbii_dev\",\"gxbii_all\",\"gxbii_cmd\",\"fzexp\",\"db_fz\",\"a_test\",\"meta_xx\",\"ipsm_v4\"],\"cate\":\"mysql\",\"id\":\"db_plat/3305916\",\"key\":\"3305916\",\"name\":\"测试库-11测试库【可用】\",\"remark\":\"描述\",\"url\":\"jdbc:mysql://192.168.202.11:3306/gxbii_dev?characterEncoding=utf-8&autoReconnect=true&connectTimeout=3000\",\"user\":\"root\"},{\"catalogs\":[\"ipsm_v4\"],\"cate\":\"mysql\",\"id\":\"db_plat/32822760\",\"key\":\"32822760\",\"name\":\"ceshi1111\",\"url\":\"jdbc:mysql://192.168.202.11:3306/ipsm_v4?characterEncoding=utf-8&autoReconnect=true\",\"user\":\"root\"},{\"catalogs\":[\"zbd_v1\"],\"cate\":\"mysql\",\"id\":\"db_plat/27166384\",\"key\":\"27166384\",\"name\":\"测试1\",\"url\":\"jdbc:mysql://192.168.50.124:3306/mytest?characterEncoding=utf-8&autoReconnect=true&useSSL=false&connectTimeout=3000\",\"user\":\"root\"},{\"catalogs\":[],\"cate\":\"mysql\",\"id\":\"db_plat/25668979\",\"key\":\"25668979\",\"name\":\"测试Mysql数据库\",\"url\":\"jdbc:mysql://558cfc37a10ef.sh.cdb.myqcloud.com:3817/demo?autoReconnect=true\",\"user\":\"cdb_outerroot\"},{\"catalogs\":[],\"cate\":\"localApi\",\"id\":\"db_plat/23090860\",\"key\":\"23090860\",\"name\":\"平台本地API\"},{\"catalogs\":[],\"cate\":\"http\",\"id\":\"db_plat/21561306\",\"key\":\"21561306\",\"name\":\"http地址调用\",\"url\":\"http://127.0.0.1/plat/db_list\"},{\"catalogs\":[\"tc\",\"tc_bbs\",\"redbbs\",\"redoss\",\"material\",\"keeper_dev\",\"art123\",\"keeper\",\"db_party\"],\"cate\":\"mysql\",\"id\":\"db_plat/21558770\",\"key\":\"21558770\",\"name\":\"TX-cloud\",\"url\":\"jdbc:mysql://558cfc37a10ef.sh.cdb.myqcloud.com:3817/demo?autoReconnect=true\",\"user\":\"cdb_outerroot\"},{\"catalogs\":[\"feature_test\",\"intelligence\",\"ma\",\"mysql\",\"ma1\",\"ma2\",\"maintenance\",\"zhaobiao\",\"zhaobiao2\"],\"cate\":\"mysql\",\"id\":\"db_plat/21449811\",\"key\":\"21449811\",\"name\":\"物联网-jj【可用】\",\"url\":\"jdbc:mysql://192.168.50.21:3306/wlw?characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai\",\"user\":\"root\"},{\"catalogs\":[],\"id\":\"db_plat/20982257\",\"key\":\"20982257\",\"name\":\"数据平台abc\",\"remark\":\"sadfdsaf\",\"url\":\"123&connectTimeout=5000\",\"user\":\"root\"}]");
System.out.println(dbPlats.size());
}
public static <T extends Doc> void reload(Class<T> clazz, String key) {
try {
File file = new File(String.format("%s%s.json", dataPath, clazz.getSimpleName()));
if ("file".equals(dcate)) {
if (MetaTable.class == clazz) {
Type type = new TypeToken<List<MetaTable>>() {
}.getType();
metaTables = convert.convertFrom(type, new FileInputStream(file));
metaTables = FileKit.readAs(file, type);
} else if (MetaLink.class == clazz) {
Type type = new TypeToken<List<MetaLink>>() {
}.getType();
metaLinks = convert.convertFrom(type, new FileInputStream(file));
metaLinks = FileKit.readAs(file, type);;
} else if (MetaService.class == clazz) {
Type type = new TypeToken<List<MetaService>>() {
}.getType();
metaServices = convert.convertFrom(type, new FileInputStream(file));
metaServices = FileKit.readAs(file, type);;
} else if (DbAccount.class == clazz) {
Type type = new TypeToken<List<DbAccount>>() {
}.getType();
dbPlats = convert.convertFrom(type, new FileInputStream(file));
dbPlats = FileKit.readAs(file, type);
} else if (DbPlat.class == clazz) {
Type type = new TypeToken<List<DbAccount>>() {
}.getType();
dbPlats = convert.convertFrom(type, new FileInputStream(file));
dbPlats = FileKit.readAs(file, type);;
} else if (SysPlat.class == clazz) {
Type type = new TypeToken<List<SysPlat>>() {
}.getType();
sysPlats = convert.convertFrom(type, new FileInputStream(file));
sysPlats = FileKit.readAs(file, type);;
} else if (User.class == clazz) {
Type type = new TypeToken<List<User>>() {
}.getType();
users = convert.convertFrom(type, new FileInputStream(file));
users = FileKit.readAs(file, type);;
} else if (TaskEntity.class == clazz) {
Type type = new TypeToken<List<TaskEntity>>() {
}.getType();
taskEntities = convert.convertFrom(type, new FileInputStream(file));
taskEntities = FileKit.readAs(file, type);;
} else if (Dict.class == clazz) {
Type type = new TypeToken<List<Dict>>() {
}.getType();
dicts = convert.convertFrom(type, new FileInputStream(file));
dicts = FileKit.readAs(file, type);;
}
} else {
if (MetaTable.class == clazz) metaTables = MetaTable.dao.find();

View File

@@ -13,14 +13,14 @@ import java.util.Map;
/**
* @author: liangxianyou
*/
public class MetaRender implements HttpRender<HttpScope> {
public class MetaRender implements HttpRender {
@Override
public void init(HttpContext context, AnyValue config) {
}
@Override
public <V extends HttpScope> void renderTo(HttpRequest request, HttpResponse response, Convert convert, V scope) {
public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) {
String referid = scope.getReferid();
Map<String, Object> attr = scope.getAttributes();
if ("excel".equals(referid)) {
@@ -53,9 +53,4 @@ public class MetaRender implements HttpRender<HttpScope> {
}
}
@Override
public Class<HttpScope> getType() {
return HttpScope.class;
}
}

View File

@@ -35,6 +35,18 @@ public class DbExecutors {
List<Map> rows = listFuture.get();
Integer total = countFuture.get();
/*rows.forEach(x -> {
x.forEach((k,v) -> {
if ("[B".equals(v.getClass().getName())) {
try {
//System.out.println(k + " : " + new String((byte[]) v, "UTF-8"));
x.put(k, new String((byte[]) v, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
});
});*/
return PageBean.by(rows, total);
}

View File

@@ -2,11 +2,13 @@ package net.tccn.base.dbq.jdbc.api;
import lombok.Data;
import net.tccn.base.arango.Doc;
import org.redkale.convert.ConvertColumn;
import javax.persistence.Table;
/**
* 数据库平台
*
* @author: liangxianyou at 2018/11/14 12:58.
*/
@Data
@@ -23,6 +25,7 @@ public class DbAccount extends Doc<DbAccount> {
private String[] catalogs; //库
//----------------------------
private boolean tmp; // TODO: 处理临时连接对象
public String accountKey() {
int start = url.indexOf("//") + 2;
@@ -32,6 +35,11 @@ public class DbAccount extends Doc<DbAccount> {
endDef = url.length();
}
String host = url.substring(start, end == -1 ? url.length() : end);
return user + "@" + host;
return user + ":" + pwd + "@" + host;
}
@ConvertColumn(ignore = true)
public String getPwd() {
return pwd;
}
}

View File

@@ -1,5 +1,6 @@
package net.tccn.base.dbq.jdbc.api;
import net.tccn.base.MetaKit;
import net.tccn.base.Utils;
import java.util.List;
@@ -9,7 +10,7 @@ import java.util.concurrent.CompletableFuture;
* Db 最终执行层
* Created by liangxianyou at 2019/3/12 14:11.
*/
public class DbKit implements DbSource{
public class DbKit implements DbSource {
private DbAccount dbAccount;
private DbSource dbSource;
@@ -31,6 +32,11 @@ public class DbKit implements DbSource{
this.catalog = catalog;
try {
if (Utils.isEmpty(dbAccount.getPwd())) {
DbAccount account = MetaKit.getDbPlat(dbAccount.getKey());
dbAccount.setPwd(account.getPwd());
}
DbSource dbSource = Utils.getDbSource(DbSource.class, dbAccount.getCate());
dbSource.setDbAccount(dbAccount);
dbSource.setCatalog(catalog);
@@ -87,12 +93,15 @@ public class DbKit implements DbSource{
public <T> CompletableFuture<T> findfirstAsync(String sql, Class<T> type) {
return CompletableFuture.supplyAsync(() -> findFirst(sql, type));
}
public <T> CompletableFuture<List<T>> findListAsync(String sql, Class<T> type) {
return CompletableFuture.supplyAsync(() -> findList(sql, type));
}
public <T> CompletableFuture<T> queryColumnAsync(String sql, Class<T> type) {
return CompletableFuture.supplyAsync(() -> findColumn(sql, type));
}
public CompletableFuture<Void> exetuteAsync(String sql) {
return CompletableFuture.runAsync(() -> exetute(sql));
}

View File

@@ -336,7 +336,7 @@ public class RunTest<T> {
//@Test
public void cacheMemorySourceTest() {
CacheMemorySource source = new CacheMemorySource();
CacheMemorySource source = new CacheMemorySource("");
//MetaKit.dcate = "db";
//MetaKit.init();