|
@@ -1,41 +0,0 @@
|
|
-package com.xy.config;
|
|
|
|
-
|
|
|
|
-import com.xy.utils.DataTime;
|
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
|
-import org.springframework.core.io.ClassPathResource;
|
|
|
|
-import org.springframework.core.io.Resource;
|
|
|
|
-import org.springframework.core.io.support.EncodedResource;
|
|
|
|
-import org.springframework.jdbc.datasource.init.ScriptUtils;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
-import javax.sql.DataSource;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 执行sql脚本
|
|
|
|
- */
|
|
|
|
-@Slf4j
|
|
|
|
-@Service
|
|
|
|
-@AllArgsConstructor
|
|
|
|
-public class MysqlSyncConfig {
|
|
|
|
-
|
|
|
|
- private DataSource dataSource;
|
|
|
|
-
|
|
|
|
- @Bean
|
|
|
|
- public Boolean syncSql() {
|
|
|
|
- try {
|
|
|
|
- String time = DataTime.getSring("yyyyMMdd");
|
|
|
|
- Resource classPathResource = new ClassPathResource(String.format("doc/%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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|