|
|
|
@ -2,15 +2,9 @@ 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.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class MaxKbUtil {
|
|
|
|
|
/**
|
|
|
|
|
* 初始化MaxKB的数据库连接
|
|
|
|
@ -27,134 +21,4 @@ public class MaxKbUtil {
|
|
|
|
|
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);
|
|
|
|
|
//描述
|
|
|
|
|
record.set("desc","【代码生成】");
|
|
|
|
|
//增加
|
|
|
|
|
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 Record().setColumns(record.getColumns());
|
|
|
|
|
//生成一个uuid
|
|
|
|
|
record.set("id", UUID.randomUUID());
|
|
|
|
|
//名称
|
|
|
|
|
record.set("name", targetDatasetName);
|
|
|
|
|
//描述
|
|
|
|
|
record.set("desc","【代码生成】");
|
|
|
|
|
//增加
|
|
|
|
|
Db.save("dataset", "id", record);
|
|
|
|
|
return record.getStr("id");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成访问Token
|
|
|
|
|
*
|
|
|
|
|
* @param application_id 应用的id
|
|
|
|
|
*/
|
|
|
|
|
public static String 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);
|
|
|
|
|
return record.getStr("access_token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除代码生成的数据
|
|
|
|
|
*/
|
|
|
|
|
public static void delCodeGenerateApplicationDataSet(){
|
|
|
|
|
//通过SQL查询出所有desc=【代码生成】的数据
|
|
|
|
|
String sql = "select * from application where \"desc\"='【代码生成】'";
|
|
|
|
|
List<Record> list = Db.find(sql);
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
String application_id = record.getStr("id");
|
|
|
|
|
//删除应用与知识库的关联
|
|
|
|
|
sql = "delete from application_dataset_mapping where application_id=?";
|
|
|
|
|
Db.update(sql, UUID.fromString(application_id));
|
|
|
|
|
|
|
|
|
|
sql="delete from application_access_token where application_id=?";
|
|
|
|
|
Db.update(sql, UUID.fromString(application_id));
|
|
|
|
|
|
|
|
|
|
//删除应用
|
|
|
|
|
sql = "delete from application where id=?";
|
|
|
|
|
Db.update(sql, UUID.fromString(application_id));
|
|
|
|
|
}
|
|
|
|
|
sql = "delete from dataset where \"desc\"='【代码生成】'";
|
|
|
|
|
Db.update(sql);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|