You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
5.2 KiB
158 lines
5.2 KiB
1 month ago
|
package com.dsideal.Ai;
|
||
10 months ago
|
|
||
2 months ago
|
import cn.hutool.core.io.FileUtil;
|
||
2 months ago
|
import com.dsideal.Config.PropKit;
|
||
1 month ago
|
import com.dsideal.Ai.Base.Controller.BaseController;
|
||
|
import com.dsideal.Ai.Index.IndexController;
|
||
|
import com.dsideal.Ai.Interceptor.*;
|
||
|
import com.dsideal.Ai.Milvus.Controller.MilvusDemoController;
|
||
|
import com.dsideal.Ai.Model._MappingKit;
|
||
|
import com.dsideal.Ai.Neo4j.Controller.Neo4jDemoController;
|
||
|
import com.dsideal.Ai.Plugin.MilvusPlugin;
|
||
|
import com.dsideal.Ai.Plugin.Neo4jPlugin;
|
||
|
import com.dsideal.Ai.Res.Controller.ResourceController;
|
||
|
import com.dsideal.Ai.Util.LogBackLogFactory;
|
||
10 months ago
|
import com.jfinal.config.*;
|
||
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
||
3 months ago
|
import com.jfinal.plugin.druid.DruidPlugin;
|
||
10 months ago
|
import com.jfinal.plugin.redis.RedisPlugin;
|
||
|
import com.jfinal.server.undertow.UndertowServer;
|
||
|
import com.jfinal.template.Engine;
|
||
2 months ago
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
10 months ago
|
|
||
|
import java.io.File;
|
||
|
|
||
|
public class ResApplication extends JFinalConfig {
|
||
2 months ago
|
private static final Logger logger = LoggerFactory.getLogger(ResApplication.class);
|
||
|
|
||
10 months ago
|
public static void main(String[] args) {
|
||
2 months ago
|
System.out.println("当前环境: " + PropKit.getEnvPrefix());
|
||
3 months ago
|
UndertowServer.create(ResApplication.class, "undertow.properties").start();
|
||
10 months ago
|
}
|
||
|
|
||
|
|
||
3 months ago
|
@Override
|
||
|
public void configConstant(Constants me) {
|
||
|
//使用LogBack
|
||
|
me.setLogFactory(new LogBackLogFactory());
|
||
10 months ago
|
}
|
||
|
|
||
|
/**
|
||
|
* 配置路由
|
||
|
*/
|
||
|
@Override
|
||
|
public void configRoute(Routes me) {
|
||
|
//默认页面
|
||
10 months ago
|
me.add("/", IndexController.class);
|
||
10 months ago
|
//资源基础管理
|
||
|
me.add("/base", BaseController.class);
|
||
9 months ago
|
//资源管理
|
||
|
me.add("/res", ResourceController.class);
|
||
2 months ago
|
//Neo4j测试
|
||
2 months ago
|
me.add("/neo4j", Neo4jDemoController.class);
|
||
2 months ago
|
//Milvus测试
|
||
2 months ago
|
me.add("/milvus", MilvusDemoController.class);
|
||
10 months ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public void configEngine(Engine engine) {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void configPlugin(Plugins me) {
|
||
3 months ago
|
DruidPlugin plugin = new DruidPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
||
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
||
9 months ago
|
me.add(plugin);
|
||
10 months ago
|
|
||
|
// 配置ActiveRecord插件
|
||
9 months ago
|
ActiveRecordPlugin arp = new ActiveRecordPlugin("master", plugin);
|
||
|
arp.setDialect(new MysqlDialect());
|
||
2 months ago
|
//加入ORM配置
|
||
|
_MappingKit.mapping(arp);
|
||
|
|
||
10 months ago
|
|
||
9 months ago
|
//遍历sql目录下所有的sql文件
|
||
|
File sqlDir;
|
||
|
String basePath = ResApplication.class.getResource("/").getPath();
|
||
|
sqlDir = new File(basePath + "/Sql");
|
||
|
File[] sqlFiles = sqlDir.listFiles();
|
||
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
||
|
//只加载.sql文件
|
||
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
||
9 months ago
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
||
9 months ago
|
}
|
||
10 months ago
|
}
|
||
|
//加载
|
||
9 months ago
|
me.add(arp);
|
||
2 months ago
|
|
||
|
// 配置 Redis
|
||
2 months ago
|
RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis.ip"),
|
||
|
PropKit.getInt("redis.port"), 10 * 1000, null);
|
||
10 months ago
|
//启动redis组件
|
||
|
me.add(redis);
|
||
2 months ago
|
|
||
|
// 配置 Neo4j
|
||
2 months ago
|
String url = PropKit.get("neo4j.url");
|
||
|
String username = PropKit.get("neo4j.username");
|
||
|
String password = PropKit.get("neo4j.password");
|
||
|
logger.info("正在初始化Neo4j连接: url={}, username={},password={}", url, username, password);
|
||
|
Neo4jPlugin neo4jPlugin = Neo4jPlugin.getInstance();
|
||
|
neo4jPlugin.setConfig(url, username, password); // 设置Neo4j连接配置
|
||
|
me.add(neo4jPlugin); // 添加Neo4j插件
|
||
|
|
||
2 months ago
|
// 配置 Milvus
|
||
2 months ago
|
String host = PropKit.get("milvus.ms_host");
|
||
|
int port = PropKit.getInt("milvus.ms_port");
|
||
|
int maxConnections = PropKit.getInt("milvus.ms_max_connections");
|
||
|
logger.info("正在初始化Milvus连接: host={}, port={}", host, port);
|
||
|
MilvusPlugin milvusPlugin = MilvusPlugin.getInstance();
|
||
|
milvusPlugin.setConfig(host, port, maxConnections); // 设置Milvus连接配置
|
||
|
me.add(milvusPlugin); // 添加Milvus插件
|
||
10 months ago
|
}
|
||
|
|
||
|
/**
|
||
|
* 配置全局拦截器
|
||
|
*/
|
||
|
@Override
|
||
|
public void configInterceptor(Interceptors me) {
|
||
|
//注册参数数字检查器
|
||
|
me.add(new IsNumbericInterceptor());
|
||
|
|
||
|
//注册非空拦截器
|
||
|
me.add(new EmptyInterceptor());
|
||
|
|
||
|
//注册Ids检查是不是数字的检查器
|
||
|
me.add(new CheckIdsInterceptor());
|
||
|
|
||
|
//注册一个GUID号的检查器
|
||
|
me.add(new IsGuidInterceptor());
|
||
|
|
||
|
//检查是不是系统管理员
|
||
|
me.add(new IsSysAdminInterceptor());
|
||
|
|
||
|
//注册一个检查输入文本长度的拦截器
|
||
|
me.add(new LengthInterceptor());
|
||
9 months ago
|
|
||
10 months ago
|
}
|
||
|
|
||
|
/**
|
||
|
* 配置处理器
|
||
|
*/
|
||
|
@Override
|
||
|
public void configHandler(Handlers me) {
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 在jfinal启动完成后马上执行
|
||
|
*/
|
||
|
@Override
|
||
|
public void onStart() {
|
||
|
//打印 启动Logo
|
||
2 months ago
|
System.out.println(FileUtil.readUtf8String("logo.txt"));
|
||
2 months ago
|
}
|
||
10 months ago
|
}
|