main
黄海 9 months ago
parent fd0938b336
commit 18f6d363cc

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>dsProject</artifactId>
<groupId>com.dsideal</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dsBase</artifactId>
<name>dsBase</name>
<version>1.0</version>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.sql</include>
<include>**/*.class</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<finalName>dsRes</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>21</source>
<target>21</target>
<encoding>UTF-8</encoding>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>dsRes</finalName>
<transformers>
<transformer>
<mainClass>com.demo.common.DemoConfig</mainClass>
</transformer>
<transformer>
<resources />
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

@ -2,7 +2,7 @@
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/main/resource" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
</content>
</component>
</module>

@ -5,6 +5,10 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>dsBase</artifactId>
<version>1.0</version>
<name>dsBase</name>
<packaging>jar</packaging>
<parent>
<groupId>com.dsideal</groupId>
<artifactId>dsProject</artifactId>
@ -18,11 +22,6 @@
</properties>
<dependencies>
<!-- <dependency>-->
<!-- <groupId>com.dsideal</groupId>-->
<!-- <artifactId>dsUtils</artifactId>-->
<!-- <version>1.0</version>-->
<!-- </dependency>-->
<!--jfinal主框架-->
<dependency>
<groupId>com.jfinal</groupId>
@ -238,14 +237,23 @@
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal-undertow</artifactId>
<version>3.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>dsRes</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.sql</include>
<include>**/*.class</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -259,6 +267,30 @@
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.dsideal.base.BaseApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -17,7 +17,7 @@ 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.FileUtil;
import com.dsideal.base.Util.CommonUtil;
import com.dsideal.base.Util.LogBackLogFactory;
import com.dsideal.base.Util.PkUtil;
import com.jfinal.config.*;
@ -29,9 +29,8 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
import java.io.File;
import lombok.SneakyThrows;
import java.util.List;
public class BaseApplication extends JFinalConfig {
public static String getEnvPrefix() {
@ -117,6 +116,7 @@ public class BaseApplication extends JFinalConfig {
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException 缺省:30秒
private long connectionTimeoutMs = 30000;
@SneakyThrows
@Override
public void configPlugin(Plugins me) {
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
@ -145,17 +145,11 @@ public class BaseApplication extends JFinalConfig {
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
slaveArp.setDialect(new MysqlDialect());
//遍历sql目录下所有的sql文件
File sqlDir;
String basePath = BaseApplication.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) {
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
}
//加载所有的sql文件
List<String> list = CommonUtil.getAllSql();
for (String sqlFile : list) {
masterArp.addSqlTemplate(sqlFile);
slaveArp.addSqlTemplate(sqlFile);
}
//加载
me.add(masterArp);
@ -221,16 +215,13 @@ public class BaseApplication extends JFinalConfig {
/**
* jfinal
*/
@SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
String path = BaseApplication.class.getClassLoader().getResource("logo.txt").getPath();
File file = new File(path);
System.out.println(FileUtil.txt2String(file));
System.out.println(CommonUtil.txt2String("logo.txt"));
//初始化人员主键序列
PkUtil.InitPersonNumPk();
//初始化组织机构主键序列
PkUtil.InitOrgNumPk();
}

@ -2,6 +2,8 @@ package com.dsideal.base.Util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.base.BaseApplication;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
@ -11,9 +13,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -22,6 +30,84 @@ public class CommonUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
private static final Logger log = LoggerFactory.getLogger(CommonUtil.class);
/**
* jar
*
* @return /
*/
public static boolean isRunInJar() {
String resourcePath = "/" + CommonUtil.class.getPackageName().replace(".", "/");
URL url = CommonUtil.class.getResource(resourcePath);
if (url.getProtocol().equals("jar")) {
return true;
}
return false;
}
/**
* jar
*
* @param path
* @return
* @throws IOException
*/
public static String txt2String(String path) throws IOException {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
BufferedInputStream bis = null;
StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(is);
byte[] temp = new byte[1024];
int len;
while ((len = bis.read(temp)) != -1) {
sb.append(new String(temp, 0, len, StandardCharsets.UTF_8));
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
return sb.toString();
}
/**
* sqllist
*
* @return
*/
public static List<String> getAllSql() throws IOException {
List<String> list = new ArrayList<>();
if (isRunInJar()) {
URL url = BaseApplication.class.getClassLoader().getResource("Sql/");
String jarPath = url.toString().substring(0, url.toString().indexOf("!/") + 2);
URL jarURL = new URL(jarPath);
JarURLConnection jarCon = (JarURLConnection) jarURL.openConnection();
JarFile jarFile = jarCon.getJarFile();
Enumeration<JarEntry> jarEntrys = jarFile.entries();
while (jarEntrys.hasMoreElements()) {
JarEntry entry = jarEntrys.nextElement();
String name = entry.getName();
if (name.startsWith("Sql/") && !entry.isDirectory()) {
list.add(name);
}
}
} else {//如果运行在文件系统中直接加载sql文件
//遍历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]) {
if (sqlFile.getName().indexOf(".sql") > 0) {//只加载.sql文件
list.add("Sql/"+sqlFile.getName());
}
}
}
return list;
}
/**
*

Loading…
Cancel
Save