Pārlūkot izejas kodu

data-upgrade updates

deason 3 mēneši atpakaļ
vecāks
revīzija
fac9c36ecf

+ 15 - 11
data-upgrade/src/main/java/com/qmth/boot/data/upgrade/config/DataUpgradeListener.java

@@ -32,6 +32,11 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
     private static final Logger log = LoggerFactory.getLogger(DataUpgradeListener.class);
 
+    /**
+     * 数据库“应用信息表”表名
+     */
+    private static final String APP_INFO_TABLE = "boot_app_info";
+
     private DataUpgradeProperties properties;
 
     @Override
@@ -138,7 +143,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
             try {
                 for (String version : versionKeys) {
-                    log.warn("*************** version:{} data upgrade start ***************", version);
+                    log.warn("*************** data upgrade start version:{} ***************", version);
                     serviceMaps.get(version).process(jdbcTemplate);
                 }
             } catch (Exception e) {
@@ -168,11 +173,10 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
                 throw new RuntimeException("【应用信息表】版本数据未找到!appCode:" + properties.getAppCode());
             }
 
-            log.warn("配置应用码:{} 配置应用版本号:{} 当前应用码:{} 当前应用版本号:{}", properties.getAppCode(),
-                    properties.getAppVersion(), appInfo.getAppCode(), appInfo.getAppVersion());
-
             int compareValue = new VersionComparator().compare(appInfo.getAppVersion(), properties.getAppVersion());
             if (compareValue != 0) {
+                log.warn("配置应用码:{} 配置应用版本号:{} 当前应用码:{} 当前应用版本号:{}", properties.getAppCode(),
+                        properties.getAppVersion(), appInfo.getAppCode(), appInfo.getAppVersion());
                 throw new RuntimeException("配置中的版本号与数据库中的应用版本号不一致!");
             }
         }
@@ -231,7 +235,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
     private boolean tryLock(JdbcTemplate jdbcTemplate, String appCode) {
         try {
-            return jdbcTemplate.update("update boot_app_info set locked = 1 where app_code = ? and locked = 0", appCode) > 0;
+            return jdbcTemplate.update("update " + APP_INFO_TABLE + " set locked = 1 where app_code = ? and locked = 0", appCode) > 0;
         } catch (Exception e) {
             throw new RuntimeException("升级获取锁失败!appCode:" + appCode, e);
         }
@@ -239,7 +243,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
     private void unLock(JdbcTemplate jdbcTemplate, String appCode) {
         try {
-            jdbcTemplate.update("update boot_app_info set locked = 0 where app_code = ?", appCode);
+            jdbcTemplate.update("update " + APP_INFO_TABLE + " set locked = 0 where app_code = ?", appCode);
         } catch (Exception e) {
             throw new RuntimeException("升级解锁失败!appCode:" + appCode, e);
         }
@@ -247,7 +251,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
     private void updateBootAppInfo(JdbcTemplate jdbcTemplate, String appCode, String appVersion) {
         try {
-            jdbcTemplate.update("update boot_app_info set app_version = ? where app_code = ?", appVersion, appCode);
+            jdbcTemplate.update("update " + APP_INFO_TABLE + " set app_version = ? where app_code = ?", appVersion, appCode);
         } catch (Exception e) {
             throw new RuntimeException("更新应用版本号失败!appCode:" + appCode, e);
         }
@@ -255,7 +259,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
     private BootAppInfo queryBootAppInfo(JdbcTemplate jdbcTemplate, String appCode) {
         try {
-            List<BootAppInfo> list = jdbcTemplate.query("select app_code,app_version,locked from boot_app_info where app_code = ?",
+            List<BootAppInfo> list = jdbcTemplate.query("select app_code,app_version,locked from " + APP_INFO_TABLE + " where app_code = ?",
                     new String[]{appCode}, new BeanPropertyRowMapper<>(BootAppInfo.class));
             return list.isEmpty() ? null : list.get(0);
         } catch (Exception e) {
@@ -265,7 +269,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
 
     private void initBootAppInfo(JdbcTemplate jdbcTemplate, String appCode, String appVersion) {
         try {
-            String createTableSql = "create table if not exists boot_app_info (" +
+            String createTableSql = "create table if not exists " + APP_INFO_TABLE + " (" +
                     " app_code varchar(20) not null," +
                     " app_version varchar(10) not null," +
                     " locked bit(1) not null default 0," +
@@ -273,7 +277,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
                     ")";
             jdbcTemplate.execute(createTableSql);
 
-            jdbcTemplate.update("insert into boot_app_info (app_code,app_version) values(?,?)", appCode, appVersion);
+            jdbcTemplate.update("insert into " + APP_INFO_TABLE + " (app_code,app_version) values(?,?)", appCode, appVersion);
         } catch (Exception e) {
             throw new RuntimeException("初始应用信息表失败!appCode:" + appCode, e);
         }
@@ -282,7 +286,7 @@ public class DataUpgradeListener implements ApplicationListener<ApplicationPrepa
     private boolean existBootAppInfo(JdbcTemplate jdbcTemplate) {
         try {
             // 是否存在应用信息表
-            List<String> exists = jdbcTemplate.queryForList("SHOW TABLES LIKE 'boot_app_info'", String.class);
+            List<String> exists = jdbcTemplate.queryForList("SHOW TABLES LIKE '" + APP_INFO_TABLE + "'", String.class);
             return !exists.isEmpty();
         } catch (Exception e) {
             throw new RuntimeException("查询应用信息表失败!", e);