|
|
|
@ -17,10 +17,11 @@ import com.dsideal.base.StudentYd.Controller.StudentYdController;
|
|
|
|
|
import com.dsideal.base.Teacher.Controller.TeacherController;
|
|
|
|
|
import com.dsideal.base.TeacherYd.Controller.TeacherYdController;
|
|
|
|
|
import com.dsideal.base.Tools.Controller.excelConvertController;
|
|
|
|
|
import com.dsideal.base.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.base.Util.FileUtil;
|
|
|
|
|
import com.dsideal.base.Util.LogBackLogFactory;
|
|
|
|
|
import com.dsideal.base.Util.PkUtil;
|
|
|
|
|
import com.jfinal.config.*;
|
|
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
|
|
import com.jfinal.kit.Prop;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
@ -29,8 +30,9 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import com.jfinal.plugin.redis.RedisPlugin;
|
|
|
|
|
import com.jfinal.server.undertow.UndertowServer;
|
|
|
|
|
import com.jfinal.template.Engine;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
public class BaseApplication extends JFinalConfig {
|
|
|
|
|
|
|
|
|
|
public static String getEnvPrefix() {
|
|
|
|
@ -104,16 +106,37 @@ public class BaseApplication extends JFinalConfig {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
/**
|
|
|
|
|
* 配置插件
|
|
|
|
|
*/
|
|
|
|
|
private String connectionTestQuery = "select 1";
|
|
|
|
|
// 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
|
|
|
|
|
private int maxPoolSize = 10;
|
|
|
|
|
// 一个连接 idle 状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
|
|
|
|
|
private long idleTimeoutMs = 600000;
|
|
|
|
|
private long maxLifetimeMs = 1800000;
|
|
|
|
|
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException, 缺省:30秒
|
|
|
|
|
private long connectionTimeoutMs = 30000;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configPlugin(Plugins me) {
|
|
|
|
|
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
|
|
|
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
|
|
|
|
masterPlugin.setConnectionTestQuery(connectionTestQuery);
|
|
|
|
|
masterPlugin.setConnectionTimeout(connectionTimeoutMs);
|
|
|
|
|
masterPlugin.setIdleTimeout(idleTimeoutMs);
|
|
|
|
|
masterPlugin.setMaxLifetime(maxLifetimeMs);
|
|
|
|
|
masterPlugin.setMaximumPoolSize(maxPoolSize);
|
|
|
|
|
|
|
|
|
|
String jdbcUrlSlave = PropKit.get("mysql.jdbcUrlSlave");
|
|
|
|
|
if (StrKit.isBlank(jdbcUrlSlave)) jdbcUrlSlave = PropKit.get("mysql.jdbcUrl");
|
|
|
|
|
HikariCpPlugin slavePlugin = new HikariCpPlugin(jdbcUrlSlave, PropKit.get("mysql.user"),
|
|
|
|
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
|
|
|
|
slavePlugin.setConnectionTestQuery(connectionTestQuery);
|
|
|
|
|
slavePlugin.setConnectionTimeout(connectionTimeoutMs);
|
|
|
|
|
slavePlugin.setIdleTimeout(idleTimeoutMs);
|
|
|
|
|
slavePlugin.setMaxLifetime(maxLifetimeMs);
|
|
|
|
|
slavePlugin.setMaximumPoolSize(maxPoolSize);
|
|
|
|
|
me.add(masterPlugin);
|
|
|
|
|
me.add(slavePlugin);
|
|
|
|
|
|
|
|
|
@ -123,11 +146,17 @@ public class BaseApplication extends JFinalConfig {
|
|
|
|
|
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
|
|
|
|
|
slaveArp.setDialect(new MysqlDialect());
|
|
|
|
|
|
|
|
|
|
//加载所有的sql文件
|
|
|
|
|
List<String> list = CommonUtil.getAllSql();
|
|
|
|
|
for (String sqlFile : list) {
|
|
|
|
|
masterArp.addSqlTemplate(sqlFile);
|
|
|
|
|
slaveArp.addSqlTemplate(sqlFile);
|
|
|
|
|
//遍历sql目录下所有的sql文件
|
|
|
|
|
File sqlDir;
|
|
|
|
|
String basePath = PathKit.getRootClassPath();
|
|
|
|
|
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) {
|
|
|
|
|
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//加载
|
|
|
|
|
me.add(masterArp);
|
|
|
|
@ -193,13 +222,16 @@ public class BaseApplication extends JFinalConfig {
|
|
|
|
|
/**
|
|
|
|
|
* 在jfinal启动完成后马上执行
|
|
|
|
|
*/
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@Override
|
|
|
|
|
public void onStart() {
|
|
|
|
|
//打印 启动Logo
|
|
|
|
|
System.out.println(CommonUtil.txt2String("logo.txt"));
|
|
|
|
|
String path = BaseApplication.class.getClassLoader().getResource("logo.txt").getPath();
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
System.out.println(FileUtil.txt2String(file));
|
|
|
|
|
|
|
|
|
|
//初始化人员主键序列
|
|
|
|
|
PkUtil.InitPersonNumPk();
|
|
|
|
|
|
|
|
|
|
//初始化组织机构主键序列
|
|
|
|
|
PkUtil.InitOrgNumPk();
|
|
|
|
|
}
|
|
|
|
|