From 475dbd3e5fb71f81c54fd5224eeebbf60212952f Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Tue, 21 Jan 2020 02:50:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81task?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: efcb6b7b2643a3d396256be9c17916c51b583211 --- .../SpringBoot/java/config/ActionConfig.java | 3 ++ .../java/config/ScheduleConfig.java | 2 +- .../java/frame/schedule/RunSqlTask.java | 33 +++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java b/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java index dc7ed949..98ae33c2 100644 --- a/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/ActionConfig.java @@ -59,6 +59,7 @@ public class ActionConfig implements BeanDefinitionRegistryPostProcessor { private int registryScreen(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); + classPathBeanDefinitionScanner.resetFilters(false); classPathBeanDefinitionScanner.addIncludeFilter(new AssignableTypeFilter(Screen.class)); classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() { @Override @@ -74,6 +75,7 @@ public class ActionConfig implements BeanDefinitionRegistryPostProcessor { private int registryControl(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); + classPathBeanDefinitionScanner.resetFilters(false); classPathBeanDefinitionScanner.addIncludeFilter(new AssignableTypeFilter(Control.class)); classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() { @Override @@ -89,6 +91,7 @@ public class ActionConfig implements BeanDefinitionRegistryPostProcessor { private int registryAjax(String basePackage, BeanDefinitionRegistry beanDefinitionRegistry) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry); + classPathBeanDefinitionScanner.resetFilters(false); classPathBeanDefinitionScanner.addIncludeFilter(new TypeFilter() { @Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { diff --git a/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java b/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java index af6f90c5..b21bb794 100644 --- a/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/ScheduleConfig.java @@ -58,7 +58,7 @@ public class ScheduleConfig extends ThreadPoolTaskScheduler implements BeanDefin Matcher matcher = compile.matcher(aPackage); if (matcher.find()) { String basePackage = matcher.group(1); - registryTask(basePackage + ".task", beanDefinitionRegistry); + registryTask(basePackage, beanDefinitionRegistry); } } diff --git a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java index 3074e6da..38762eb7 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java +++ b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java @@ -1,11 +1,40 @@ package ${basePackage}.frame.schedule; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import ${basePackage}.frame.auth.LocalData; +import ${basePackage}.frame.utils.LogUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + public abstract class RunSqlTask extends RunFixRepeatTask { - public abstract String getSql(); + private Connection connection; @Override public void run() { - //exec sql + try { + if (connection == null || connection.isClosed()) { + SqlSessionFactory factory = LocalData.getBean(SqlSessionFactory.class); + SqlSession sqlSession = factory.openSession(true); + connection = sqlSession.getConnection(); + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.e("schedule: get connection failed!"); + return; + } + try { + PreparedStatement preparedStatement = connection.prepareStatement(getSql()); + preparedStatement.execute(); + preparedStatement.close(); + } catch (SQLException e) { + e.printStackTrace(); + LogUtil.e("RunSqlTask exec failed! SQL:[" + getSql() + "]"); + } } + + public abstract String getSql(); }