Sfoglia il codice sorgente

项目启动优化

zhanghaijun 2 anni fa
parent
commit
6a1ae50d35

+ 2 - 0
.gitignore

@@ -2,6 +2,8 @@
 /store/
 /train-server/store
 target/
+
+**/logs
 !.mvn/wrapper/maven-wrapper.jar
 !**/src/main/**/target/
 !**/src/test/**/target/

+ 76 - 1
pom.xml

@@ -17,6 +17,7 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <maven.test.skip>true</maven.test.skip>
+        <resource.delimiter>@</resource.delimiter>
         <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
         <!-- 依赖 -->
         <hutool.version>5.8.16</hutool.version>
@@ -79,7 +80,7 @@
         <resources>
             <resource>
                 <directory>src/main/resources</directory>
-                <filtering>false</filtering>
+                <filtering>true</filtering>
             </resource>
         </resources>
         <plugins>
@@ -109,7 +110,81 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <configuration>
+                    <delimiters>
+                        <delimiter>${resource.delimiter}</delimiter>
+                    </delimiters>
+                    <useDefaultDelimiters>false</useDefaultDelimiters>
+                </configuration>
+            </plugin>
         </plugins>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-maven-plugin</artifactId>
+                    <configuration>
+                        <executable>true</executable>
+                        <layout>ZIP</layout>
+                        <includes>
+                            <include>
+                                <groupId>null</groupId>
+                                <artifactId>null</artifactId>
+                            </include>
+                        </includes>
+                        <excludes>
+                            <exclude>
+                                <groupId>org.projectlombok</groupId>
+                                <artifactId>lombok</artifactId>
+                            </exclude>
+                        </excludes>
+                    </configuration>
+                </plugin>
+                <!--拷贝依赖到jar外面的lib目录-->
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-dependency-plugin</artifactId>
+                    <executions>
+                        <execution>
+                            <id>copy</id>
+                            <phase>package</phase>
+                            <goals>
+                                <goal>copy-dependencies</goal>
+                            </goals>
+                            <configuration>
+                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                                <excludeTransitive>false</excludeTransitive>
+                                <stripVersion>false</stripVersion>
+                                <silent>true</silent>
+                            </configuration>
+                        </execution>
+                    </executions>
+                </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-assembly-plugin</artifactId>
+                    <version>3.3.0</version>
+                    <configuration>
+                        <appendAssemblyId>false</appendAssemblyId>
+                        <descriptors>
+                            <descriptor>src/assembly/assembly.xml</descriptor>
+                        </descriptors>
+                        <outputDirectory>target</outputDirectory>
+                    </configuration>
+                    <executions>
+                        <execution>
+                            <phase>package</phase>
+                            <goals>
+                                <goal>single</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </pluginManagement>
     </build>
     <repositories>
         <repository>

+ 32 - 9
train-server/pom.xml

@@ -18,7 +18,15 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
@@ -57,6 +65,21 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-json</artifactId>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/org.redisson/redisson-spring-boot-starter -->
+        <dependency>
+            <groupId>org.redisson</groupId>
+            <artifactId>redisson-spring-boot-starter</artifactId>
+            <version>3.17.1</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -64,14 +87,14 @@
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
-                <configuration>
-                    <excludes>
-                        <exclude>
-                            <groupId>org.projectlombok</groupId>
-                            <artifactId>lombok</artifactId>
-                        </exclude>
-                    </excludes>
-                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
             </plugin>
         </plugins>
     </build>

+ 57 - 0
train-server/src/assembly/assembly.xml

@@ -0,0 +1,57 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+    <id>package</id>
+    <formats>
+        <format>zip</format>
+    </formats>
+    <includeBaseDirectory>true</includeBaseDirectory>
+    <fileSets>
+        <!--
+            0755-> 即用户具有读/写/执行权限,组用户和其它用户具有读写权限;
+            0644-> 即用户具有读写权限,组用户和其它用户具有只读权限;
+        -->
+        <fileSet>
+            <directory>src/assembly/bin</directory>
+            <outputDirectory>bin</outputDirectory>
+            <fileMode>0755</fileMode>
+            <lineEnding>unix</lineEnding>
+            <filtered>true</filtered>
+            <includes>
+                <include>*.sh</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>src/assembly/bin</directory>
+            <outputDirectory>bin</outputDirectory>
+            <filtered>true</filtered>
+            <includes>
+                <include>*.bat</include>
+                <include>*.vbs</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>${project.build.directory}/classes</directory>
+            <outputDirectory>/conf</outputDirectory>
+            <includes>
+                <include>application.*</include>
+                <include>*.yml</include>
+                <include>*.properties</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>${project.build.directory}</directory>
+            <outputDirectory>/</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+        </fileSet>
+    </fileSets>
+    <dependencySets>
+        <dependencySet>
+            <useProjectArtifact>false</useProjectArtifact>
+            <outputDirectory>lib</outputDirectory>
+            <outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
+        </dependencySet>
+    </dependencySets>
+</assembly>

+ 33 - 0
train-server/src/assembly/bin/date.bat

@@ -0,0 +1,33 @@
+@echo off
+chcp 65001 > nul
+setlocal EnableDelayedExpansion
+
+rem 设置目标日期和时间
+set "targetDateTime=2023-10-09 23:59:59"
+rem 设置要显示的消息,使用 vbNewLine 来表示换行
+set "message=这是第一行消息" & vbNewLine & "这是第二行消息"
+
+rem 获取当前日期和时间
+for /f "delims=" %%a in ('wmic os get LocalDateTime ^| find "."') do set currentDateTime=%%a
+
+rem 比较日期和时间
+if "%currentDateTime%" gtr "%targetDateTime%" (
+    echo 授权已过期,请联系管理员
+    pause
+) else (
+    echo 授权尚未过期
+    rem 在这里执行授权未过期时的操作
+)
+
+rem 比较日期和时间
+if "%currentDateTime%" gtr "%targetDateTime%" (
+    echo 授权已过期,请联系管理员
+    cscript msgbox.vbs "轨道交通插件 & 授权已过期,请联系管理员"
+) else (
+    echo 授权尚未过期
+    cscript msgbox.vbs "轨道交通插件 & 授权已过期,请联系管理员"
+
+    rem 在这里执行授权未过期时的操作
+)
+
+endlocal

+ 3 - 0
train-server/src/assembly/bin/msgbox.vbs

@@ -0,0 +1,3 @@
+Set objShell = CreateObject("WScript.Shell")
+strMessage = WScript.Arguments(0)
+objShell.Popup strMessage, 0, "提示", 48

+ 12 - 0
train-server/src/assembly/bin/run.bat

@@ -0,0 +1,12 @@
+@echo off
+chcp 65001
+
+:: Get the directory of the script
+for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
+:: Change directory to the parent directory of the script
+cd /d "%SCRIPT_DIR%"
+
+start /B /MIN cmd /C stop.bat 8080
+timeout /t 1 /nobreak
+start /MIN cmd /C start.bat > NUL 2>&1
+echo Jar程序已在后台运行。

+ 34 - 0
train-server/src/assembly/bin/start-dev.bat

@@ -0,0 +1,34 @@
+@echo off
+chcp 65001
+
+:: Get the directory of the script
+for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
+:: Change directory to the parent directory of the script
+cd /d "%SCRIPT_DIR%\.."
+
+:: Check if Java is installed
+REM set "javaPath=C:\path\to\java\bin\java.exe"
+set "javaPath=java"
+set "plugin.dev=true"
+%javaPath% -version >nul 2>&1
+if errorlevel 1 (
+    echo Java is not installed or not found.
+    echo Please install Java and try again.
+    exit /b 1
+)
+if not exist "plugins.jar" (
+    echo The file plugins.jar does not exist.
+    exit /b 1
+)
+if not exist "./conf/application.yml" (
+    echo The file config/application.yml does not exist.
+    exit /b 1
+)
+if not exist "lib" (
+    echo The directory lib does not exist.
+    exit /b 1
+)
+:: rest of your script
+%javaPath% -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar plugins.jar --spring.config.location=./conf/application.yml
+
+pause

+ 34 - 0
train-server/src/assembly/bin/start.bat

@@ -0,0 +1,34 @@
+@echo off
+chcp 65001
+
+:: Get the directory of the script
+for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
+:: Change directory to the parent directory of the script
+cd /d "%SCRIPT_DIR%\.."
+
+:: Check if Java is installed
+REM set "javaPath=C:\path\to\java\bin\java.exe"
+set "javaPath=java"
+set "plugin.dev=false"
+%javaPath% -version >nul 2>&1
+if errorlevel 1 (
+    echo Java is not installed or not found.
+    echo Please install Java and try again.
+    exit /b 1
+)
+if not exist "plugins.jar" (
+    echo The file plugins.jar does not exist.
+    exit /b 1
+)
+if not exist "./conf/application.yml" (
+    echo The file config/application.yml does not exist.
+    exit /b 1
+)
+if not exist "lib" (
+    echo The directory lib does not exist.
+    exit /b 1
+)
+:: rest of your script
+%javaPath% -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar plugins.jar --spring.config.location=./conf/application.yml
+
+pause

+ 35 - 0
train-server/src/assembly/bin/start.sh

@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# Get the directory of the script
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Change directory to the parent directory of the script
+cd "$SCRIPT_DIR/.."
+
+# Check if Java is installed
+if ! type java >/dev/null 2>&1; then
+    echo Java is not installed or not found.
+    echo Please install Java and try again.
+    exit 1
+fi
+
+# Check if plugins.jar file exists
+if [ ! -f "plugins.jar" ]; then
+    echo The file plugins.jar does not exist.
+    exit 1
+fi
+
+# Check if application.yml file exists
+if [ ! -f "./conf/application.yml" ]; then
+    echo The file config/application.yml does not exist.
+    exit 1
+fi
+
+# Check if lib directory exists
+if [ ! -d "lib" ]; then
+    echo The directory lib does not exist.
+    exit 1
+fi
+
+JAVA_OPTS=" -server -Xmx2g -Xms2g -Xmn256m"
+exec java $JAVA_OPTS -Duser.timezone=Asia/Shanghai -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar plugins.jar --spring.config.location=./conf/application.yml

+ 25 - 0
train-server/src/assembly/bin/stop.bat

@@ -0,0 +1,25 @@
+@echo off
+chcp 65001
+
+setlocal
+
+REM 设置默认端口号
+set "port=%1"
+if "%port%"=="" (
+    set "port=8080"
+)
+echo 检测端口:%port%
+REM 使用 netstat 和 findstr 命令获取占用特定端口的进程信息
+set "pid="
+for /f "tokens=5" %%a in ('netstat -ano ^| findstr "\[::\]:%port%"') do (
+    set "pid=%%a"
+)
+REM 显示找到的PID
+if not "%pid%"=="" (
+	echo 端口(%port%)已经被线程(%pid%)占用。
+	taskkill /F /PID %pid%
+) else (
+    echo No process found on port %port%.
+)
+
+endlocal

+ 178 - 0
train-server/src/assembly/bin/wait-for-it.sh

@@ -0,0 +1,178 @@
+#!/bin/bash
+# Use this script to test if a given TCP host/port are available
+## https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh
+
+WAITFORIT_cmdname=${0##*/}
+
+echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi; }
+
+usage() {
+	cat <<USAGE >&2
+Usage:
+    $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
+    -h HOST | --host=HOST       Host or IP under test
+    -p PORT | --port=PORT       TCP port under test
+                                Alternatively, you specify the host and port as host:port
+    -s | --strict               Only execute subcommand if the test succeeds
+    -q | --quiet                Don't output any status messages
+    -t TIMEOUT | --timeout=TIMEOUT
+                                Timeout in seconds, zero for no timeout
+    -- COMMAND ARGS             Execute command with args after the test finishes
+USAGE
+	exit 1
+}
+
+wait_for() {
+	if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
+		echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
+	else
+		echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
+	fi
+	WAITFORIT_start_ts=$(date +%s)
+	while :; do
+		if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
+			nc -z $WAITFORIT_HOST $WAITFORIT_PORT
+			WAITFORIT_result=$?
+		else
+			(echo -n >/dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
+			WAITFORIT_result=$?
+		fi
+		if [[ $WAITFORIT_result -eq 0 ]]; then
+			WAITFORIT_end_ts=$(date +%s)
+			echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
+			break
+		fi
+		sleep 1
+	done
+	return $WAITFORIT_result
+}
+
+wait_for_wrapper() {
+	# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
+	if [[ $WAITFORIT_QUIET -eq 1 ]]; then
+		timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
+	else
+		timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
+	fi
+	WAITFORIT_PID=$!
+	trap "kill -INT -$WAITFORIT_PID" INT
+	wait $WAITFORIT_PID
+	WAITFORIT_RESULT=$?
+	if [[ $WAITFORIT_RESULT -ne 0 ]]; then
+		echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
+	fi
+	return $WAITFORIT_RESULT
+}
+
+# process arguments
+while [[ $# -gt 0 ]]; do
+	case "$1" in
+	*:*)
+		WAITFORIT_hostport=(${1//:/ })
+		WAITFORIT_HOST=${WAITFORIT_hostport[0]}
+		WAITFORIT_PORT=${WAITFORIT_hostport[1]}
+		shift 1
+		;;
+	--child)
+		WAITFORIT_CHILD=1
+		shift 1
+		;;
+	-q | --quiet)
+		WAITFORIT_QUIET=1
+		shift 1
+		;;
+	-s | --strict)
+		WAITFORIT_STRICT=1
+		shift 1
+		;;
+	-h)
+		WAITFORIT_HOST="$2"
+		if [[ $WAITFORIT_HOST == "" ]]; then break; fi
+		shift 2
+		;;
+	--host=*)
+		WAITFORIT_HOST="${1#*=}"
+		shift 1
+		;;
+	-p)
+		WAITFORIT_PORT="$2"
+		if [[ $WAITFORIT_PORT == "" ]]; then break; fi
+		shift 2
+		;;
+	--port=*)
+		WAITFORIT_PORT="${1#*=}"
+		shift 1
+		;;
+	-t)
+		WAITFORIT_TIMEOUT="$2"
+		if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
+		shift 2
+		;;
+	--timeout=*)
+		WAITFORIT_TIMEOUT="${1#*=}"
+		shift 1
+		;;
+	--)
+		shift
+		WAITFORIT_CLI=("$@")
+		break
+		;;
+	--help)
+		usage
+		;;
+	*)
+		echoerr "Unknown argument: $1"
+		usage
+		;;
+	esac
+done
+
+if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
+	echoerr "Error: you need to provide a host and port to test."
+	usage
+fi
+
+WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-20}
+WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
+WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
+WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
+
+# Check to see if timeout is from busybox?
+WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
+WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
+
+WAITFORIT_BUSYTIMEFLAG=""
+if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
+	WAITFORIT_ISBUSY=1
+	# Check if busybox timeout uses -t flag
+	# (recent Alpine versions don't support -t anymore)
+	if timeout &>/dev/stdout | grep -q -e '-t '; then
+		WAITFORIT_BUSYTIMEFLAG="-t"
+	fi
+else
+	WAITFORIT_ISBUSY=0
+fi
+
+if [[ $WAITFORIT_CHILD -gt 0 ]]; then
+	wait_for
+	WAITFORIT_RESULT=$?
+	exit $WAITFORIT_RESULT
+else
+	if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
+		wait_for_wrapper
+		WAITFORIT_RESULT=$?
+	else
+		wait_for
+		WAITFORIT_RESULT=$?
+	fi
+fi
+
+if [[ $WAITFORIT_CLI != "" ]]; then
+	if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
+		echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
+		exit $WAITFORIT_RESULT
+	fi
+	exec "${WAITFORIT_CLI[@]}"
+else
+	exit $WAITFORIT_RESULT
+fi

+ 74 - 0
train-server/src/main/java/top/haijunit/train/common/config/RunnerLog.java

@@ -0,0 +1,74 @@
+package top.haijunit.train.common.config;
+
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
+import jakarta.annotation.PreDestroy;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Component;
+import top.haijunit.train.common.server.LicenseService;
+import top.haijunit.train.common.server.LicenseUtil;
+
+import java.lang.management.ManagementFactory;
+import java.util.Date;
+import java.util.Optional;
+
+/**
+ * @author zhanghaijun
+ * @date 2023/11/7 12:10
+ * @description 初始化日志输出
+ */
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class RunnerLog implements ApplicationRunner {
+    private final ApplicationContext ctx;
+    private final LicenseService licenseService;
+
+    @Override
+    public void run(ApplicationArguments args) {
+        if (licenseService.licenseExpired()) {
+            LicenseUtil.runVbsExpired();
+            log.info("\033[1;33m {} \033[0m", String.format("\n ========== 启动服务 =========="
+                + "\n\t 授权时间已过期,请来及时联系管理员"
+                + "\n\t 授权时间至:\t%s"
+                + "\n\t 授权已过期:\t%s天"
+                + "\n ============================", licenseService.getLicenseUntilStr(), licenseService.licenseRemaining()));
+            System.exit(SpringApplication.exit(ctx));
+        }
+        String appJvmName = ManagementFactory.getRuntimeMXBean().getName();
+        String path = Optional.ofNullable(ctx.getEnvironment().getProperty("server.servlet.context-path")).orElse("");
+        String httpPort = ctx.getEnvironment().getProperty("server.port");
+        String httpHost = ctx.getEnvironment().getProperty("project.plugin.ip-address");
+        String httpUrl = "http://" + Optional.ofNullable(httpHost).orElse("127.0.0.1") + ":" + Optional.ofNullable(httpPort).orElse("8080") + path;
+        String format = String.format("\n ========== 启动服务 =========="
+                + "\n\t 服务名称:\t%s"
+                + "\n\t 授权时间至:\t%s"
+                + "\n\t 授权剩余:\t%s天"
+                + "\n\t 进程ID: \t%s"
+                + "\n\t 启动时间:\t%s"
+                + "\n\t 访问路径:\t%s"
+                + "\n ============================",
+            ctx.getEnvironment().getProperty("spring.application.name"),
+            licenseService.getLicenseUntilStr(), licenseService.licenseRemaining(),
+            appJvmName.split("@")[0],
+            DateUtil.format(new Date(ctx.getStartupDate()), DatePattern.NORM_DATETIME_MS_PATTERN),
+            httpUrl
+        );
+        log.info("\033[1;33m {} \033[0m", format);
+    }
+
+    @PreDestroy
+    public void destroy() {
+        String format = String.format("\n ========== 暂停服务 =========="
+                + "\n\t 服务名称:\t%s"
+                + "\n\t 暂停时间:\t%s"
+                + "\n============================",
+            ctx.getEnvironment().getProperty("spring.application.name"), DateUtil.now());
+        log.info("\033[1;33m {} \033[0m", format);
+    }
+}

+ 37 - 0
train-server/src/main/java/top/haijunit/train/common/server/LicenseService.java

@@ -0,0 +1,37 @@
+package top.haijunit.train.common.server;
+
+import cn.hutool.core.date.DateUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+/**
+ * @author zhanghaijun
+ * @date 2023/11/7 12:12
+ * @description 授权控制
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class LicenseService {
+
+    public Date getLicenseUntil() {
+        return DateUtil.endOfDay(new GregorianCalendar(2025, Calendar.DECEMBER, 20)).getTime();
+    }
+
+    public boolean licenseExpired() {
+        return DateUtil.compare(DateUtil.date(), getLicenseUntil()) > 0;
+    }
+
+    public String getLicenseUntilStr() {
+        return DateUtil.formatDateTime(getLicenseUntil());
+    }
+
+    public long licenseRemaining() {
+        return DateUtil.betweenDay(getLicenseUntil(), DateUtil.date(), true);
+    }
+}

+ 48 - 0
train-server/src/main/java/top/haijunit/train/common/server/LicenseUtil.java

@@ -0,0 +1,48 @@
+package top.haijunit.train.common.server;
+
+import cn.hutool.core.io.FileUtil;
+import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author zhanghaijun
+ * @date 2023/11/7 12:15
+ * @description 授权工具类
+ */
+@Slf4j
+@UtilityClass
+public class LicenseUtil {
+
+    public boolean isWindows() {
+        return System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOWS");
+    }
+
+    public void runVbsExpired() {
+        try {
+            if (!isWindows()) {
+                return;
+            }
+            if (!FileUtil.exist("C:\\Windows\\System32\\wscript.exe")) {
+                return;
+            }
+            File file = new File("bin\\msgbox.vbs");
+            if (file.exists()) {
+                Runtime.getRuntime().exec(new String[]{"C:\\Windows\\System32\\wscript.exe", file.getAbsolutePath(), "轨道交通插件 & 授权已过期,请联系管理员"});
+                return;
+            } else {
+                log.error("vbs 运行异常:文件未找到:{}", file.getAbsolutePath());
+            }
+            file = new File("src\\assembly\\bin\\msgbox.vbs");
+            if (file.exists()) {
+                Runtime.getRuntime().exec(new String[]{"C:\\Windows\\System32\\wscript.exe", file.getAbsolutePath(), "轨道交通插件 & 授权已过期,请联系管理员"});
+            } else {
+                log.error("vbs 运行异常:文件未找到:{}", file.getAbsolutePath());
+            }
+        } catch (IOException e) {
+            log.error("vbs 运行异常:{}", e.getMessage());
+        }
+    }
+}

+ 26 - 1
train-server/src/main/resources/application.yml

@@ -8,6 +8,22 @@ server:
 spring:
   application:
     name: train-server
+  profiles:
+    active: @profiles.active@
+  servlet:
+    multipart:
+      max-file-size: 10MB
+      max-request-size: 20MB
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    serialization:
+      indent_output: false
+      fail_on_empty_beans: false
+    deserialization:
+      fail_on_unknown_properties: false
+  mvc:
+    format:
+      date-time: yyyy-MM-dd HH:mm:ss
   liquibase:
     enabled: true
     change-log: classpath:/db/changelog/db-server.xml
@@ -38,6 +54,15 @@ spring:
     expose-request-attributes: true
     expose-session-attributes: true
     expose-spring-macro-helpers: true
+  h2:
+    console:
+      enabled: true
+      path: /h2
+      settings:
+        trace: false
+        web-allow-others: true
 logging:
   level:
-    top.haijunit: debug
+    top.haijunit: @logging.level@
+    org.springframework: warn
+  config: classpath:logback.xml

+ 95 - 3
train-server/src/main/resources/logback.xml

@@ -1,14 +1,106 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-    <property name="log.path" value="./logs"/>
+<configuration scan="true" scanPeriod="60 seconds" debug="false">
+    <!-- 日志存放路径 -->
+    <property name="log.path" value="logs"/>
+    <property name="console.log.pattern" value="%red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) - %msg%n"/>
     <property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"/>
 
     <!-- 控制台输出 -->
     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
         <encoder>
-            <pattern>%red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}%n) - %msg%n</pattern>
+            <pattern>${console.log.pattern}</pattern>
             <charset>utf-8</charset>
         </encoder>
     </appender>
+    <!-- 控制台输出 -->
+    <appender name="file_console" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}/console.log</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+            <fileNamePattern>${log.path}/%d{yyyy-MM-dd}/console.log</fileNamePattern>
+            <!-- 日志最大 7天 -->
+            <maxHistory>7</maxHistory>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <charset>utf-8</charset>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+            <!-- 过滤的级别 -->
+            <level>INFO</level>
+        </filter>
+    </appender>
+
+    <!-- 系统日志输出 -->
+    <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}/info.log</file>
+        <!-- 循环政策:基于时间创建日志文件 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+            <fileNamePattern>${log.path}/%d{yyyy-MM-dd}/info.log</fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>60</maxHistory>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <!-- 过滤的级别 -->
+            <level>INFO</level>
+            <!-- 匹配时的操作:接收(记录) -->
+            <onMatch>ACCEPT</onMatch>
+            <!-- 不匹配时的操作:拒绝(不记录) -->
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+    <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}/error.log</file>
+        <!-- 循环政策:基于时间创建日志文件 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+            <fileNamePattern>${log.path}/%d{yyyy-MM-dd}/error.log</fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>60</maxHistory>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <!-- 过滤的级别 -->
+            <level>ERROR</level>
+            <!-- 匹配时的操作:接收(记录) -->
+            <onMatch>ACCEPT</onMatch>
+            <!-- 不匹配时的操作:拒绝(不记录) -->
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+
+    <!-- info异步输出 -->
+    <appender name="async_info" class="ch.qos.logback.classic.AsyncAppender">
+        <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
+        <discardingThreshold>0</discardingThreshold>
+        <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
+        <queueSize>512</queueSize>
+        <!-- 添加附加的appender,最多只能添加一个 -->
+        <appender-ref ref="file_info"/>
+    </appender>
+
+    <!-- error异步输出 -->
+    <appender name="async_error" class="ch.qos.logback.classic.AsyncAppender">
+        <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
+        <discardingThreshold>0</discardingThreshold>
+        <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
+        <queueSize>512</queueSize>
+        <!-- 添加附加的appender,最多只能添加一个 -->
+        <appender-ref ref="file_error"/>
+    </appender>
 
+    <!--系统操作日志-->
+    <root level="info">
+        <appender-ref ref="console"/>
+        <appender-ref ref="async_info"/>
+        <appender-ref ref="async_error"/>
+        <appender-ref ref="file_console"/>
+    </root>
 </configuration>