diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java index 237a40efe46ac86a5422aa99076bb734435b8354..13ebe9c658323997cf730d1d4f5d0020fd02f876 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java @@ -2,7 +2,6 @@ package tech.mhuang.interchan.sso.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import tech.mhuang.core.async.AsyncTaskService; import tech.mhuang.core.async.DefaultAsyncTaskSupport; /** @@ -16,8 +15,9 @@ import tech.mhuang.core.async.DefaultAsyncTaskSupport; public class AsyncTaskConfig { @Bean - public AsyncTaskService buildAsync() { + public DefaultAsyncTaskSupport buildAsync() { return new DefaultAsyncTaskSupport(); } + } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java new file mode 100644 index 0000000000000000000000000000000000000000..fb316a1640dfff1fd0cefae82e096c394fe325d6 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java @@ -0,0 +1,35 @@ +package tech.mhuang.interchan.sso.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import tech.mhuang.ext.spring.pool.SpringThreadPool; +import tech.mhuang.ext.spring.start.SpringContextHolder; +import tech.mhuang.interchan.sso.redis.IRedisCacheStartupService; + +/** + * @ClassName: RedisCacheThreadPool + * @Author: Ever + * @Description: redis缓存线程池 + * @Date: 2020/1/6 10:24 + * @Version: 1.0 + */ +@Configuration +public class RedisCacheThreadPool extends SpringThreadPool { + private static final String DEFAULT_NAME = "redisCacheThreadPool"; + + + public RedisCacheThreadPool() { + super(); + setBeanName(DEFAULT_NAME); + } + + @Bean("rediscacheThreadPool") + public RedisCacheThreadPool redisCacheThreadPoolFramework(IRedisCacheStartupService redisCacheStartupService, SpringContextHolder springContextHolder) { + this.initialize(); + this.execute(redisCacheStartupService); + return this; + } + + + +} diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java new file mode 100644 index 0000000000000000000000000000000000000000..c1282249cd2fb3846bba309a47b8e4384df168c1 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java @@ -0,0 +1,18 @@ +package tech.mhuang.interchan.sso.redis; + +/** + * @ClassName: IRedisCacheStartupService + * @Author: Ever + * @Description: 缓存redis + * @Date: 2020/1/6 11:53 + * @Version: 1.0 + */ +public interface IRedisCacheStartupService extends Runnable { + /** + * 缓存redis + * + * @return + */ + String redisCache(); + +} diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java index bc48d558b74595a4aa96cc2a64d67eba9836dfb8..f2fbcdcde958c9184142f2d03807a60af04c7b95 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java @@ -4,7 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Component; -import tech.mhuang.core.async.AsyncTaskService; +import tech.mhuang.core.async.DefaultAsyncTaskSupport; +import tech.mhuang.interchan.sso.config.RedisCacheThreadPool; /** * @ClassName: RedisCacheStartup @@ -18,11 +19,13 @@ import tech.mhuang.core.async.AsyncTaskService; public class RedisCacheStartup implements CommandLineRunner { @Autowired - private AsyncTaskService asyncTaskService; + private DefaultAsyncTaskSupport defaultAsyncTaskSupport; + @Autowired + private RedisCacheThreadPool redisCacheThreadPool; @Override - public void run(String... args) throws Exception { - asyncTaskService.submit(new RedisCacheStartupService()); + public void run(String... args) { + defaultAsyncTaskSupport.executor(redisCacheThreadPool); } } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java index 336185bd64353c9db7417eedf6307e1350d9fbec..74e33a8340035ac66a09e9ff076ea07a52ff57c3 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java @@ -1,16 +1,14 @@ package tech.mhuang.interchan.sso.redis; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import tech.mhuang.core.async.AsyncTask; -import tech.mhuang.core.async.AsyncTaskService; import tech.mhuang.core.util.CollectionUtil; import tech.mhuang.ext.interchan.auth.constant.AuthConstant; import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunExcludeUrl; import tech.mhuang.interchan.sso.sysfunvisturl.mapper.SyChanmgfunVistUrlmMapper; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -23,34 +21,18 @@ import java.util.stream.Collectors; * @Version: 1.0 */ @Service -@Slf4j -public class RedisCacheStartupService implements AsyncTask { - /** - * 成功 - */ - private static final String SUCCESS = "success"; +public class RedisCacheStartupService implements IRedisCacheStartupService { - @Autowired - AsyncTaskService asyncTaskService; @Autowired private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; @Autowired private SysFunvisturlRedisOperator syChanmgfunRedisOperator; - - - @Override - public void onSuccess(Object result) { - log.info("redis异步加载:{}", result); - } + Map map = new HashMap(); + private static final String SUCCESS = "success"; @Override - public void onFailed(Throwable t) { - log.error("redis异步加载:{}", t.getMessage()); - } - - @Override - public String execute() { + public String redisCache() { //查询数据库,并放入缓存中 List urls = syChanmgfunVistUrlmMapper.getExcludeUrl(); if (CollectionUtil.isNotEmpty(urls)) { @@ -61,4 +43,8 @@ public class RedisCacheStartupService implements AsyncTask { return SUCCESS; } + @Override + public void run() { + redisCache(); + } } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java index 613b94379c14888c7da4f2b647d3293f326d1969..d357d15af8bb6fcc4edffe5716c570be962e2172 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java @@ -14,7 +14,7 @@ import tech.mhuang.ext.interchan.protocol.InsertInto; import tech.mhuang.ext.spring.util.DataUtil; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmAddDTO; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmQryDTO; -import tech.mhuang.interchan.sso.redis.RedisCacheStartupService; +import tech.mhuang.interchan.sso.redis.IRedisCacheStartupService; import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunVistUrlm; import tech.mhuang.interchan.sso.sysfunvisturl.mapper.SyChanmgfunVistUrlmMapper; @@ -22,7 +22,6 @@ import tech.mhuang.interchan.sso.sysfunvisturl.service.ISyChanmgfunVistUrlServic import tech.mhuang.interchan.sso.sysrole.entity.SysRole; import tech.mhuang.interchan.sso.sysuser.entity.SysUser; - import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -50,7 +49,7 @@ public class SyChanmgfunVistUrlService private SysFunvisturlRedisOperator syChanmgfunRedisOperator; @Autowired - private RedisCacheStartupService redisCacheStartupService; + private IRedisCacheStartupService redisCacheStartupService; /** * @param funid @@ -221,7 +220,7 @@ public class SyChanmgfunVistUrlService if (StringUtil.isNotBlank(userId)) { this.setVistUrlPowerNow(userId); } else { - redisCacheStartupService.execute(); + redisCacheStartupService.redisCache(); } }