Răsfoiți Sursa

生产分支

李进 2 ani în urmă
părinte
comite
98e132b0a8

+ 13 - 6
device-api-service/src/main/java/com/xy/config/MysqlSyncConfig.java

@@ -2,7 +2,7 @@ package com.xy.config;
 
 import com.xy.utils.DataTime;
 import lombok.AllArgsConstructor;
-import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Bean;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
@@ -15,6 +15,7 @@ import javax.sql.DataSource;
 /**
  * 执行sql脚本
  */
+@Slf4j
 @Service
 @AllArgsConstructor
 public class MysqlSyncConfig {
@@ -22,12 +23,18 @@ public class MysqlSyncConfig {
     private DataSource dataSource;
 
     @Bean
-    @SneakyThrows
     public Boolean syncSql() {
-        String time = DataTime.getSring("yyyyMMdd");
-        Resource classPathResource = new ClassPathResource(String.format("prod/%s.sql", time));
-        EncodedResource encodedResource = new EncodedResource(classPathResource, "utf-8");
-        ScriptUtils.executeSqlScript(dataSource.getConnection(), encodedResource);
+        try {
+            String time = DataTime.getSring("yyyyMMdd");
+            Resource classPathResource = new ClassPathResource(String.format("prod/%s.sql", time));
+            if (classPathResource.exists()) {
+                EncodedResource encodedResource = new EncodedResource(classPathResource, "utf-8");
+                ScriptUtils.executeSqlScript(dataSource.getConnection(), encodedResource);
+            }
+        } catch (Exception e) {
+            log.error("", e);
+            System.exit(1);
+        }
         return true;
     }