|
@@ -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;
|
|
|
}
|
|
|
|