|
@@ -8,6 +8,7 @@ import com.qmth.boot.data.upgrade.service.DataUpgradeService;
|
|
|
import com.qmth.boot.data.upgrade.utils.ClassHelper;
|
|
|
import com.qmth.boot.data.upgrade.utils.VersionComparator;
|
|
|
import com.zaxxer.hikari.HikariDataSource;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
|
@@ -16,6 +17,8 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.lang.reflect.Constructor;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -47,6 +50,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
|
|
|
if (RunMode.INSTALL == properties.getRunMode()) {
|
|
|
// 首次安装模式,仅执行数据初始化
|
|
|
this.handlerInstall();
|
|
|
+ this.writeUpgradeLogFile(properties.getAppVersion());
|
|
|
// 执行完后默认退出程序
|
|
|
System.exit(0);
|
|
|
}
|
|
@@ -54,6 +58,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
|
|
|
if (RunMode.UPGRADE == properties.getRunMode()) {
|
|
|
// 升级模式,仅执行数据升级
|
|
|
this.handlerUpgrade();
|
|
|
+ this.writeUpgradeLogFile(properties.getAppVersion());
|
|
|
// 执行完后默认退出程序
|
|
|
System.exit(0);
|
|
|
}
|
|
@@ -62,10 +67,19 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
|
|
|
this.handlerStart();
|
|
|
} catch (Exception e) {
|
|
|
log.error("程序异常终止!原因:{}", e.getMessage(), e);
|
|
|
+ this.writeUpgradeLogFile("ERROR");
|
|
|
System.exit(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void writeUpgradeLogFile(String result) {
|
|
|
+ try {
|
|
|
+ FileUtils.write(new File("version.txt"), result, "UTF-8", false);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("写入升级日志文件失败!{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void handlerInstall() {
|
|
|
try (HikariDataSource dataSource = this.initDataSource()) {
|
|
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|