1、重构代码将数据处理全部交给 repository 来操作
2、升级支持免 Db启动提供服务
This commit is contained in:
@@ -12,13 +12,22 @@ import net.tccn.meta.MetaService;
|
||||
import net.tccn.meta.MetaTable;
|
||||
import net.tccn.plat.DbPlat;
|
||||
import net.tccn.plat.SysPlat;
|
||||
import net.tccn.user.User;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
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;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
*
|
||||
* Created by liangxianyou at 2019/1/7 13:31.
|
||||
@@ -31,19 +40,23 @@ public final class MetaKit {
|
||||
private static List<MetaLink> metaLinks;
|
||||
@Getter
|
||||
private static List<MetaService> metaServices;
|
||||
|
||||
@Getter
|
||||
private static List<DbAccount> dbPlats;
|
||||
@Getter
|
||||
private static List<SysPlat> sysPlats;
|
||||
@Getter
|
||||
private static List<User> users;
|
||||
|
||||
static {
|
||||
metaTables = MetaTable.dao.find();
|
||||
metaLinks = MetaLink.dao.find();
|
||||
metaServices = MetaService.dao.find();
|
||||
|
||||
dbPlats = DbAccount.dao.find();
|
||||
sysPlats = SysPlat.dao.find();
|
||||
protected static String dcate;
|
||||
private static final JsonConvert convert = JsonConvert.root();
|
||||
// -----------------------------------
|
||||
protected static void init() {
|
||||
reload(MetaTable.class);
|
||||
reload(MetaLink.class);
|
||||
reload(MetaService.class);
|
||||
reload(DbAccount.class);
|
||||
reload(SysPlat.class);
|
||||
reload(User.class);
|
||||
}
|
||||
|
||||
public static <T extends Doc> void reload(Class<T> clazz) {
|
||||
@@ -54,13 +67,80 @@ public final class MetaKit {
|
||||
}
|
||||
public static <T extends Doc> void reload(Class<T> clazz, String key) {
|
||||
|
||||
if (MetaTable.class == clazz) metaTables = MetaTable.dao.find();
|
||||
else if (MetaLink.class == clazz) metaLinks = MetaLink.dao.find();
|
||||
else if (MetaService.class == clazz) metaServices = MetaService.dao.find();
|
||||
else if (DbAccount.class == clazz) dbPlats = DbAccount.dao.find();
|
||||
else if (DbPlat.class == clazz) dbPlats = DbAccount.dao.find();
|
||||
else if (SysPlat.class == clazz) sysPlats = SysPlat.dao.find();
|
||||
// todo: 按照key 查询更新内存
|
||||
try {
|
||||
File file = new File(String.format("tmp/%s.json", clazz.getSimpleName()));
|
||||
if ("file".equals(dcate)) {
|
||||
if (MetaTable.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaTable>>() {}.getType();
|
||||
metaTables = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (MetaLink.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaLink>>() {}.getType();
|
||||
metaLinks = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (MetaService.class == clazz) {
|
||||
Type type = new TypeToken<List<MetaService>>() {}.getType();
|
||||
metaServices = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (DbAccount.class == clazz) {
|
||||
Type type = new TypeToken<List<DbAccount>>() {}.getType();
|
||||
dbPlats = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (DbPlat.class == clazz) {
|
||||
Type type = new TypeToken<List<DbAccount>>() {}.getType();
|
||||
dbPlats = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (SysPlat.class == clazz) {
|
||||
Type type = new TypeToken<List<SysPlat>>() {}.getType();
|
||||
sysPlats = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
else if (User.class == clazz) {
|
||||
Type type = new TypeToken<List<User>>() {}.getType();
|
||||
users = convert.convertFrom(type, new FileInputStream(file));
|
||||
}
|
||||
} else {
|
||||
if (MetaTable.class == clazz) metaTables = MetaTable.dao.find();
|
||||
else if (MetaLink.class == clazz) metaLinks = MetaLink.dao.find();
|
||||
else if (MetaService.class == clazz) metaServices = MetaService.dao.find();
|
||||
else if (DbAccount.class == clazz) dbPlats = DbAccount.dao.find();
|
||||
else if (DbPlat.class == clazz) dbPlats = DbAccount.dao.find();
|
||||
else if (SysPlat.class == clazz) sysPlats = SysPlat.dao.find();
|
||||
else if (User.class == clazz) users = User.dao.find();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void cacheSave() {
|
||||
cacheSave(MetaLink.class);
|
||||
cacheSave(MetaService.class);
|
||||
cacheSave(DbAccount.class);
|
||||
cacheSave(DbPlat.class);
|
||||
cacheSave(SysPlat.class);
|
||||
cacheSave(User.class);
|
||||
}
|
||||
|
||||
private static void cacheSave(Class clazz) {
|
||||
List list = null;
|
||||
if (MetaTable.class == clazz) list = metaTables;
|
||||
else if (MetaLink.class == clazz) list = metaLinks;
|
||||
else if (MetaService.class == clazz) list = metaServices;
|
||||
else if (DbAccount.class == clazz) list = dbPlats;
|
||||
else if (DbPlat.class == clazz) list = dbPlats;
|
||||
else if (SysPlat.class == clazz) list = sysPlats;
|
||||
else if (User.class == clazz) list = users;
|
||||
|
||||
if (list == null || list.size() == 0) return;
|
||||
|
||||
File file = new File(String.format("tmp/%s.json", list.get(0).getClass().getSimpleName()));
|
||||
file.getParentFile().mkdirs();
|
||||
try {
|
||||
FileKit.strToFile(MetaKit.convert.convertTo(list), file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
@@ -83,39 +163,10 @@ public final class MetaKit {
|
||||
return any.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 MetaLink[] 得到 MetaTable{}
|
||||
* @param links
|
||||
* @return {alias:table}
|
||||
*/
|
||||
private static Map<String, MetaTable> metaTables(List<MetaLink> links) {
|
||||
Map map = new HashMap();
|
||||
List<String> tables = links.stream().map(MetaLink::getTables).flatMap(Arrays::stream).distinct().collect(Collectors.toList());//tables
|
||||
metaTables.stream().filter(x -> tables.contains(x.getAlias())).forEach(x -> {
|
||||
map.put(x.getAlias(), x);
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 link._key 得到 MetaLink[]
|
||||
* @param links
|
||||
* @return
|
||||
*/
|
||||
private static List<MetaLink> metaLinks(List<String> links) {
|
||||
if (links == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return metaLinks.stream().filter(x -> links.contains(x.getKey())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建完整的 MetaService
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static MetaService getMetaService(String name, String token) {
|
||||
Optional<MetaService> service = metaServices.stream().filter(x -> x.getName().equals(name)).findAny();
|
||||
Optional<MetaService> service = metaServices.stream()
|
||||
.filter(x -> x.getName().equals(name) && x.getSysPlatId().equals(getPlatId(token)))
|
||||
.findAny();
|
||||
return service.orElse(null);
|
||||
}
|
||||
|
||||
@@ -258,7 +309,7 @@ public final class MetaKit {
|
||||
.set("details", _details);
|
||||
}
|
||||
|
||||
@Comment("业务导出表头配置")
|
||||
@Comment("获取导出excel表头配置k-v")
|
||||
public static Kv cfgExport(String name, String token) {
|
||||
MetaService metaService = getMetaService(name, token);
|
||||
List<Map<String,String>> exports = metaService.getExports();
|
||||
@@ -399,11 +450,8 @@ public final class MetaKit {
|
||||
public static String lastAlias;
|
||||
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);
|
||||
String aql = TplKit.use(true).getTpl("metaTable.lastAlias");
|
||||
lastAlias = MetaTable.dao.findFirst(aql, String.class);
|
||||
}
|
||||
return lastAlias = next(lastAlias, "");
|
||||
}
|
||||
@@ -422,4 +470,51 @@ public final class MetaKit {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> tableExist(String[] tableArr, String token) {
|
||||
List<String> _tableArr = asList(tableArr);
|
||||
List<String> hv = metaTables.stream()
|
||||
.filter(x -> _tableArr.contains(x.getName()) && x.getSysPlatId().equals(getPlatId(token)))
|
||||
.map(MetaTable::getName)
|
||||
.collect(Collectors.toList());
|
||||
return hv;
|
||||
}
|
||||
|
||||
// ---------------------- repository -------------------
|
||||
public static <T extends Doc> void save(T ... ts) {
|
||||
Set<Class<T>> clazzs = new HashSet<>();
|
||||
for (T t : ts) {
|
||||
if (t.getKey() == null) {
|
||||
t.save();
|
||||
} else {
|
||||
t.update();
|
||||
}
|
||||
|
||||
clazzs.add((Class<T>) t.getClass());
|
||||
}
|
||||
clazzs.forEach(x -> reload(x));
|
||||
}
|
||||
|
||||
public static <T extends Doc> T findFirst(T t) {
|
||||
Objects.nonNull(t);
|
||||
|
||||
List<T> list = asList();
|
||||
Map doc = t.toDoc();
|
||||
if (t instanceof User) {
|
||||
list = (List<T>) users;
|
||||
}
|
||||
|
||||
Optional any = list.stream().filter(x -> {
|
||||
Map map = x.toDoc();
|
||||
Set<String> keySet = doc.keySet();
|
||||
for (String k : keySet) {
|
||||
if (doc.get(k) != null && (doc.get(k) instanceof String && doc.get(k).equals(map.get(k)))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}).findAny();
|
||||
|
||||
return (T) any.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
35
src/main/java/net/tccn/base/MetaListenter.java
Normal file
35
src/main/java/net/tccn/base/MetaListenter.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package net.tccn.base;
|
||||
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ApplicationListener;
|
||||
import org.redkale.util.ResourceFactory;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou
|
||||
*/
|
||||
public class MetaListenter implements ApplicationListener {
|
||||
|
||||
@Resource(name = "property.dcate")
|
||||
private String dcate;
|
||||
@Resource(name = "property.tplPath")
|
||||
private String tplPath;
|
||||
|
||||
@Override
|
||||
public void preStart(Application application) {
|
||||
ResourceFactory rf = application.getResourceFactory();
|
||||
rf.inject(this);
|
||||
|
||||
MetaKit.dcate = dcate;
|
||||
MetaKit.init();
|
||||
TplKit.use(true).addTpl(new File(FileKit.rootPath(), tplPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preShutdown(Application application) {
|
||||
MetaKit.cacheSave();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -159,9 +159,13 @@ public abstract class Doc<T extends Doc> {
|
||||
sourceName = source.name();
|
||||
}
|
||||
|
||||
arangoSource = ArangoSource.use(sourceName);
|
||||
this.db = arangoSource.db(table.catalog());
|
||||
this.collection = arangoSource.collection(this);
|
||||
try {
|
||||
arangoSource = ArangoSource.use(sourceName);
|
||||
this.db = arangoSource.db(table.catalog());
|
||||
this.collection = arangoSource.collection(this);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
protected final static <T extends Doc> T dao(Class<T> type) {
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.tccn.dbq.jdbc.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2019/3/12 14:11.
|
||||
@@ -58,4 +59,18 @@ public class DbKit implements DbSource{
|
||||
public void exetute(String sql) {
|
||||
dbSource.exetute(sql);
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
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(() -> queryColumn(sql, type));
|
||||
}
|
||||
public CompletableFuture<Void> exetuteAsync(String sql) {
|
||||
return CompletableFuture.runAsync(() -> exetute(sql));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.tccn.service;
|
||||
|
||||
import com.arangodb.Predicate;
|
||||
import net.tccn.base.FileKit;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.base.TplKit;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
@@ -56,9 +55,6 @@ public class BaseService implements Service {
|
||||
@Resource(name = "APP_HOME")
|
||||
protected File APP_HOME;
|
||||
|
||||
@Resource(name = "property.tplPath")
|
||||
private String tplPath;
|
||||
|
||||
public static Properties prop = new Properties();
|
||||
protected static TplKit tplKit = TplKit.use(true);
|
||||
|
||||
@@ -78,7 +74,7 @@ public class BaseService implements Service {
|
||||
try {
|
||||
if (!tplInit) {
|
||||
tplInit = true;
|
||||
tplKit.addTpl(new File(FileKit.rootPath(), tplPath));
|
||||
//tplKit.addTpl(new File(FileKit.rootPath(), tplPath));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -97,14 +97,10 @@ public class MetadataService extends BaseService { //arango
|
||||
break;
|
||||
}
|
||||
|
||||
if (service.getKey() != null) {
|
||||
service.update();
|
||||
} else {
|
||||
if (service.getKey() == null) {
|
||||
service.setSysPlatId(platId(token));
|
||||
service.save();
|
||||
}
|
||||
MetaKit.reload(MetaService.class);
|
||||
|
||||
MetaKit.save(service);
|
||||
} while (false);
|
||||
return jBean;
|
||||
}
|
||||
@@ -125,13 +121,14 @@ public class MetadataService extends BaseService { //arango
|
||||
|
||||
//修改item的排序
|
||||
@RestMapping(name = "itemsort", comment = "字段排序")
|
||||
public String[] itemSortSave(String alias , String[] items, @RestParam(name = "platToken") String token) {
|
||||
public JBean itemSortSave(String alias , String[] items, @RestParam(name = "platToken") String token) {
|
||||
|
||||
MetaTable metaTable = MetaKit.getMetaTableByAlias(alias);
|
||||
|
||||
MetaKit.sortItem.apply(metaTable, items);
|
||||
metaTable.update();
|
||||
return items;
|
||||
|
||||
MetaKit.save(metaTable);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@RestMapping(name = "itemupdate", comment = "字段修改")
|
||||
@@ -139,8 +136,7 @@ public class MetadataService extends BaseService { //arango
|
||||
MetaTable metaTable = MetaKit.getMetaTableByAlias(alias);
|
||||
|
||||
MetaKit.itemUpdate.apply(metaTable, items);
|
||||
metaTable.update();
|
||||
MetaKit.reload(metaTable);
|
||||
MetaKit.save(metaTable);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@@ -149,10 +145,8 @@ public class MetadataService extends BaseService { //arango
|
||||
if (shows == null || shows.size() == 0) return null;
|
||||
|
||||
MetaService metaService = MetaKit.getMetaService(name, token);
|
||||
|
||||
metaService.setShows(shows);
|
||||
metaService.update();
|
||||
MetaKit.reload(metaService);
|
||||
MetaKit.save(metaService);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@@ -162,20 +156,20 @@ public class MetadataService extends BaseService { //arango
|
||||
|
||||
MetaService metaService = MetaKit.getMetaService(name, token);
|
||||
metaService.setExports(exports);
|
||||
metaService.update();
|
||||
|
||||
MetaKit.reload(metaService);
|
||||
MetaKit.save(metaService);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@RestMapping(name = "importsort", comment = "导入字段保存")
|
||||
public List<String> importSort(String serviceKey , List<String> items, @RestParam(name = "platToken") String token) {
|
||||
public JBean importSort(String serviceKey , List<String> items, @RestParam(name = "platToken") String token) {
|
||||
if (isEmpty.test(items)) return null;
|
||||
|
||||
MetaTable metaTable = MetaKit.getMetaTable(serviceKey, token);
|
||||
//fixme: metaTable.setImports(items);
|
||||
metaTable.update();
|
||||
return items;
|
||||
|
||||
MetaKit.save(metaTable);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@RestMapping(name = "dbplatupdate", comment = "数据平台修改")
|
||||
@@ -187,8 +181,8 @@ public class MetadataService extends BaseService { //arango
|
||||
_metaTable.setDbPlatId(metaTable.getDbPlatId());
|
||||
_metaTable.setCatalog(metaTable.getCatalog());
|
||||
|
||||
_metaTable.update();
|
||||
return JBean.by(0, "");
|
||||
MetaKit.save(_metaTable);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@RestMapping(name = "filter_update", comment = "查询配置修改")
|
||||
@@ -196,18 +190,17 @@ public class MetadataService extends BaseService { //arango
|
||||
MetaService metaService = MetaKit.getMetaService(name, token);
|
||||
metaService.setFilters(filters);
|
||||
|
||||
metaService.update();
|
||||
return JBean.by(0, "");
|
||||
MetaKit.save(metaService);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@RestMapping(name = "table_link_list", comment = "实体表,包含link信息的列表,(metalink 管理页面使用)")
|
||||
public JBean tableLinkList(@RestParam(name = "platToken") String token) {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
List<Kv> list =
|
||||
MetaKit.getMetaTables().stream().filter(x ->
|
||||
(isEmpty.test(token) || x.getSysPlatId().equals(platId(token)))
|
||||
).map(x -> {
|
||||
List<Kv> list = MetaKit.getMetaTables().stream()
|
||||
.filter(x -> (isEmpty.test(token) || x.getSysPlatId().equals(platId(token))))
|
||||
.map(x -> {
|
||||
Kv kv = Kv.of("name", x.getName())
|
||||
.set("comment", x.getComment())
|
||||
.set("alias", x.getAlias())
|
||||
@@ -265,12 +258,10 @@ public class MetadataService extends BaseService { //arango
|
||||
public JBean linkSave(MetaLink link, @RestParam(name = "platToken") String token) {
|
||||
if (link.getKey() != null) {
|
||||
link.find(String.format("UPDATE '%s' WITH { link:null } IN MetaLink", link.getKey()), Map.class); //避免删除属性无效
|
||||
link.update();
|
||||
} else {
|
||||
link.save();
|
||||
// fixme: 将逻辑迁移到 MetaKit中:
|
||||
}
|
||||
MetaKit.reload(MetaLink.class);
|
||||
|
||||
MetaKit.save(link);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@@ -278,19 +269,17 @@ public class MetadataService extends BaseService { //arango
|
||||
@RestMapping(name = "plat_list", comment = "平台列表")
|
||||
public JBean platList() {
|
||||
JBean jBean = new JBean();
|
||||
List<SysPlat> plats = SysPlat.dao.find();
|
||||
List<SysPlat> plats = MetaKit.getSysPlats();
|
||||
|
||||
jBean.setBody(plats);
|
||||
return jBean;
|
||||
return jBean.setBody(plats);
|
||||
}
|
||||
|
||||
// ------------------------------------ 对外服务 --------------------------------------
|
||||
@RestMapping(name = "cfg", auth = false, comment = " 功能配置")
|
||||
public JBean cfg(String name, @RestParam(name = "platToken") String token) {
|
||||
JBean jBean = JBean.by(0, "");
|
||||
JBean jBean = new JBean();
|
||||
Map cfg = MetaKit.cfg(name, token);
|
||||
|
||||
jBean.set(0, "", MetaKit.cfg(name, token));
|
||||
|
||||
return jBean;
|
||||
return jBean.setBody(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,8 @@ public class PlatService extends BaseService {
|
||||
|
||||
@Comment("平台信息保存")
|
||||
public JBean save(SysPlat plat) {
|
||||
if (plat.getKey() == null) {
|
||||
plat.save();
|
||||
} else {
|
||||
plat.update();
|
||||
}
|
||||
|
||||
return new JBean();
|
||||
MetaKit.save(plat);
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
@RestMapping(name = "info", comment = "平台详情")
|
||||
@@ -49,8 +44,6 @@ public class PlatService extends BaseService {
|
||||
public JBean dbList(DbPlat plat, Flipper flipper) {
|
||||
JBean jBean = new JBean();
|
||||
|
||||
//PageBean<DbPlat> page = DbPlat.dao.findPage(plat, flipper);
|
||||
|
||||
List<DbAccount> list = MetaKit.getDbPlats();
|
||||
PageBean page = PageBean.by(list, list.size());
|
||||
|
||||
@@ -59,16 +52,9 @@ public class PlatService extends BaseService {
|
||||
|
||||
@RestMapping(name = "db_save", comment = "数据源信息保存")
|
||||
public JBean dbSave(DbPlat plat) {
|
||||
//DbAccount dbPlat = MetaKit.getDbPlat(plat.getKey());
|
||||
MetaKit.save(plat);
|
||||
|
||||
if (plat.getKey() == null) {
|
||||
plat.save();
|
||||
} else {
|
||||
plat.update();
|
||||
}
|
||||
MetaKit.reload(DbPlat.class);
|
||||
|
||||
return new JBean();
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.tccn.service;
|
||||
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.MetaKit;
|
||||
import net.tccn.user.User;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
@@ -19,7 +20,7 @@ public class UserService extends BaseService {
|
||||
User bean = new User();
|
||||
bean.setUsername(username);
|
||||
|
||||
User user = User.dao.findFirst(bean);
|
||||
User user = MetaKit.findFirst(bean);
|
||||
if (user == null) {
|
||||
return JBean.by(-1, "登陆失败:账号无效");
|
||||
}
|
||||
@@ -30,7 +31,7 @@ public class UserService extends BaseService {
|
||||
|
||||
user.setSessionid(sessionid);
|
||||
user.setLoginTime(System.currentTimeMillis());
|
||||
user.update();
|
||||
MetaKit.save(user);
|
||||
}
|
||||
|
||||
return jBean;
|
||||
@@ -38,19 +39,19 @@ public class UserService extends BaseService {
|
||||
|
||||
@RestMapping(name = "current")
|
||||
public User current(@RestSessionid String sessionid) {
|
||||
return getT("user_" + sessionid, User.class, () -> User.dao.findFirst(new User(sessionid)));
|
||||
return getT("user_" + sessionid, User.class, () -> MetaKit.findFirst(new User(sessionid)));
|
||||
}
|
||||
|
||||
@RestMapping(name = "logout", comment = "退出登陆")
|
||||
public JBean logout(@RestSessionid String sessionid) {
|
||||
User user = User.dao.findFirst(new User(sessionid));
|
||||
User user = MetaKit.findFirst(new User(sessionid));
|
||||
if (user != null) {
|
||||
user.setSessionid("");
|
||||
user.update();
|
||||
MetaKit.save(user);
|
||||
}
|
||||
cacheSource.removeAsync("user_" + sessionid);
|
||||
|
||||
return new JBean();
|
||||
return JBean.OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ public class _DbService extends BaseService {
|
||||
String sql = tplKit.getTpl("db.table_list", Kv.of("table", tableName));
|
||||
String columnSql = String.format("SHOW FULL COLUMNS FROM %s.`%s`", catalog, tableName);
|
||||
|
||||
CompletableFuture<Table> tableFuture = CompletableFuture.supplyAsync(() -> dbKit.findfirst(sql, Table.class));
|
||||
CompletableFuture<List<Column>> columnFuture = CompletableFuture.supplyAsync(() -> dbKit.findList(columnSql, Column.class));
|
||||
CompletableFuture<Table> tableFuture = dbKit.findfirstAsync(sql, Table.class);
|
||||
CompletableFuture<List<Column>> columnFuture = dbKit.findListAsync(columnSql, Column.class);
|
||||
|
||||
try {
|
||||
Table table = tableFuture.get();
|
||||
|
||||
@@ -75,7 +75,6 @@ public class _FileService extends BaseService {
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
buf.append("] and d.sysPlatId=='" + platId(token) + "'\n" +
|
||||
" return d.name");
|
||||
|
||||
List<String> hv = MetaTable.dao.find(buf.toString(), String.class);
|
||||
|
||||
Kv res = Kv.of();
|
||||
|
||||
@@ -8,13 +8,10 @@ import net.tccn.meta.MetaTable;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.util.Comment;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* 元数据实体管理
|
||||
@@ -26,9 +23,9 @@ import java.util.concurrent.ExecutionException;
|
||||
public class _TableService extends BaseService {
|
||||
|
||||
@Resource
|
||||
_FileService fileService;
|
||||
private _FileService fileService;
|
||||
@Resource
|
||||
_DbService dbService;
|
||||
private _DbService dbService;
|
||||
|
||||
|
||||
@RestMapping(name = "sheets", comment = "导入选择列表数据准备")
|
||||
@@ -49,26 +46,20 @@ public class _TableService extends BaseService {
|
||||
List<Table> list = dbService.tableList(dbPlatId, catalog, null);
|
||||
|
||||
String[] tableArr = list.stream().map(Table::getName).toArray(String[]::new);
|
||||
CompletableFuture<List<String>> hvFuture = tableExist(tableArr, token);
|
||||
List<String> hv = MetaKit.tableExist(tableArr, token);
|
||||
|
||||
try {
|
||||
List<String> _hv = hvFuture.get();
|
||||
List<MetaTable> sheets = new ArrayList<>();
|
||||
list.forEach(x -> {
|
||||
MetaTable bean = MetaTable.toAs(x);
|
||||
bean.setHv(hv.contains(x.getName()) ? 1 : 0);
|
||||
sheets.add(bean);
|
||||
});
|
||||
|
||||
List<MetaTable> sheets = new ArrayList<>();
|
||||
list.forEach(x -> {
|
||||
MetaTable bean = MetaTable.toAs(x);
|
||||
bean.setHv(_hv.contains(x.getName()) ? 1 : 0);
|
||||
sheets.add(bean);
|
||||
});
|
||||
//对数据分组后返回
|
||||
Kv<String, MetaTable> data = Kv.of();
|
||||
sheets.forEach(x -> data.set(x.getName(), x));
|
||||
|
||||
//对数据分组后返回
|
||||
Kv<String, MetaTable> data = Kv.of();
|
||||
sheets.forEach(x -> data.set(x.getName(), x));
|
||||
|
||||
jBean.setBody(data);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
jBean.setBody(data);
|
||||
}
|
||||
|
||||
return jBean;
|
||||
@@ -89,31 +80,24 @@ public class _TableService extends BaseService {
|
||||
String[] tableArr,
|
||||
@RestParam(name = "platToken") String token) {
|
||||
|
||||
CompletableFuture<List<String>> hvfuture = tableExist(tableArr, token);
|
||||
List<String> hv = MetaKit.tableExist(tableArr, token);
|
||||
List<Table> tables = dbService.tableInfoList(dbPlatId, catalog, tableArr);
|
||||
|
||||
try {
|
||||
List<String> hvs = hvfuture.get();
|
||||
tables.forEach(t -> {
|
||||
if (!hvs.contains(t.getName())) {
|
||||
MetaTable[] metaTables = tables.stream()
|
||||
.filter(t -> !hv.contains(t.getName())) // 去除同名
|
||||
.map(t -> {
|
||||
MetaTable metaTable = MetaTable.toAs(t);
|
||||
metaTable.setCatalog(catalog);
|
||||
metaTable.setDbPlatId(dbPlatId);
|
||||
metaTable.setAlias(MetaKit.nextAlias());//todo: 表别名
|
||||
metaTable.setAlias(MetaKit.nextAlias());// 表别名
|
||||
metaTable.setSysPlatId(platId(token));
|
||||
return metaTable;
|
||||
}).toArray(MetaTable[]::new);
|
||||
|
||||
//保存数据到元数据表
|
||||
metaTable.save();
|
||||
}
|
||||
});
|
||||
MetaKit.reload(MetaTable.class);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
MetaKit.save(metaTables);
|
||||
}
|
||||
|
||||
@Comment("查询元数据中存在的表")
|
||||
/*@Comment("查询元数据中存在的表")
|
||||
private CompletableFuture<List<String>> tableExist(String[] tableArr, String token) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
@@ -128,5 +112,5 @@ public class _TableService extends BaseService {
|
||||
List<String> hv = MetaTable.dao.find(buf.toString(), String.class); //在元数据中已经存在的sheet
|
||||
return hv;
|
||||
});
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.tccn.user;
|
||||
import lombok.Data;
|
||||
import net.tccn.base.JBean;
|
||||
import net.tccn.base.arango.Doc;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.ConvertType;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import javax.persistence.Table;
|
||||
@@ -18,7 +16,7 @@ public class User extends Doc<User> {
|
||||
public static User dao = dao(User.class);
|
||||
|
||||
private String username;
|
||||
@ConvertColumn(ignore = true,type = ConvertType.JSON)
|
||||
//@ConvertColumn(ignore = true,type = ConvertType.JSON)
|
||||
private String pwd;
|
||||
private Long createTime;
|
||||
private Long loginTime;
|
||||
@@ -43,6 +41,9 @@ public class User extends Doc<User> {
|
||||
public JBean checkLogin(String pwd) {
|
||||
JBean jBean = JBean.by(0, "");
|
||||
|
||||
if (this.pwd == null || this.pwd.isEmpty()) {
|
||||
jBean.set(-1, "密码错误");
|
||||
}
|
||||
if (!this.pwd.equalsIgnoreCase(md5IfNeed(pwd))) {
|
||||
jBean.set(-1, "密码错误");
|
||||
} else if (status != 1) {
|
||||
|
||||
Reference in New Issue
Block a user