parent
9c408a8df8
commit
a1c2130873
@ -1,24 +0,0 @@
|
||||
package Tools.MaxKb.Util;
|
||||
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
||||
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||
|
||||
public class MaxKbDb {
|
||||
/**
|
||||
* 初始化MaxKB的数据库连接
|
||||
*/
|
||||
public static void Init() {
|
||||
String jdbcUrl = PropKit.get("jdbcUrl");
|
||||
String user = PropKit.get("user");
|
||||
String password = PropKit.get("password");
|
||||
String driverClassName = PropKit.get("driverClassName");
|
||||
//读取库
|
||||
HikariCpPlugin hp = new HikariCpPlugin(jdbcUrl, user, password, driverClassName);
|
||||
hp.start();
|
||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
||||
arp.setDialect(new PostgreSqlDialect());
|
||||
arp.start();
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package Tools.MaxKb.Util;
|
||||
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
||||
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MaxKbUtil {
|
||||
/**
|
||||
* 初始化MaxKB的数据库连接
|
||||
*/
|
||||
public static void Init() {
|
||||
String jdbcUrl = PropKit.get("jdbcUrl");
|
||||
String user = PropKit.get("user");
|
||||
String password = PropKit.get("password");
|
||||
String driverClassName = PropKit.get("driverClassName");
|
||||
//读取库
|
||||
HikariCpPlugin hp = new HikariCpPlugin(jdbcUrl, user, password, driverClassName);
|
||||
hp.start();
|
||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
||||
arp.setDialect(new PostgreSqlDialect());
|
||||
arp.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型
|
||||
*
|
||||
* @param model_name 模型名称
|
||||
* @return
|
||||
*/
|
||||
public static com.jfinal.plugin.activerecord.Record getModel(String model_name) {
|
||||
String sql = "select * from model where name=?";
|
||||
return Db.findFirst(sql, model_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用
|
||||
*
|
||||
* @param applicationName 应用名称
|
||||
* @return
|
||||
*/
|
||||
public static com.jfinal.plugin.activerecord.Record getApplication(String applicationName) {
|
||||
String sql = "select * from application where name=?";
|
||||
return Db.findFirst(sql, applicationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加应用程序
|
||||
*
|
||||
* @param sourceApplicationName 源应用名称
|
||||
* @param targetApplicationName 目标应用名称
|
||||
*/
|
||||
public static String addApplication(String sourceApplicationName, String targetApplicationName) {
|
||||
//获取应用
|
||||
com.jfinal.plugin.activerecord.Record record = getApplication(sourceApplicationName);
|
||||
if (record == null) {
|
||||
System.out.println(sourceApplicationName + "应用不存在!");
|
||||
System.exit(0);
|
||||
}
|
||||
//克隆出对象
|
||||
record = new com.jfinal.plugin.activerecord.Record().setColumns(record.getColumns());
|
||||
//生成一个uuid
|
||||
record.set("id", UUID.randomUUID());
|
||||
//名称
|
||||
record.set("name", targetApplicationName);
|
||||
//增加
|
||||
Db.save("application", "id", record);
|
||||
|
||||
return record.getStr("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据集
|
||||
*
|
||||
* @param dataset_name 数据集名称
|
||||
* @return
|
||||
*/
|
||||
public static com.jfinal.plugin.activerecord.Record getDataSet(String dataset_name) {
|
||||
String sql = "select * from dataset where name=?";
|
||||
return Db.findFirst(sql, dataset_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加数据集
|
||||
*
|
||||
* @param sourceDatasetName 数据集名称
|
||||
*/
|
||||
public static String addDataSet(String sourceDatasetName, String targetDatasetName) {
|
||||
//获取数据集
|
||||
com.jfinal.plugin.activerecord.Record record = getDataSet(sourceDatasetName);
|
||||
if (record == null) {
|
||||
System.out.println(sourceDatasetName + "数据集不存在!");
|
||||
System.exit(0);
|
||||
}
|
||||
//克隆出对象
|
||||
record = new com.jfinal.plugin.activerecord.Record().setColumns(record.getColumns());
|
||||
//生成一个uuid
|
||||
record.set("id", UUID.randomUUID());
|
||||
//名称
|
||||
record.set("name", targetDatasetName);
|
||||
record.set("desc", targetDatasetName);
|
||||
//增加
|
||||
Db.save("dataset", "id", record);
|
||||
return record.getStr("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成访问Token
|
||||
*
|
||||
* @param application_id 应用的id
|
||||
*/
|
||||
public static void addAccessToken(String application_id) {
|
||||
com.jfinal.plugin.activerecord.Record record = new Record();
|
||||
record.set("create_time", LocalDateTime.now());
|
||||
record.set("update_time", LocalDateTime.now());
|
||||
record.set("application_id", UUID.fromString(application_id));
|
||||
//生成一个16位的随机数
|
||||
record.set("access_token", UUID.randomUUID().toString().replace("-", "").substring(0, 16).toLowerCase());
|
||||
record.set("is_active", true);
|
||||
record.set("access_num", 100);
|
||||
record.set("white_active", false);
|
||||
record.set("white_list", new String[]{""});
|
||||
record.set("show_source", false);
|
||||
Db.save("application_access_token", "application_id", record);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue