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 new file mode 100644 index 0000000000000000000000000000000000000000..237a40efe46ac86a5422aa99076bb734435b8354 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java @@ -0,0 +1,23 @@ +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; + +/** + * @ClassName: TaskConfig + * @Author: Ever + * @Description: 异步线程池 + * @Date: 2019/12/31 9:02 + * @Version: 1.0 + */ +@Configuration +public class AsyncTaskConfig { + + @Bean + public AsyncTaskService buildAsync() { + return new DefaultAsyncTaskSupport(); + } + +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..bc48d558b74595a4aa96cc2a64d67eba9836dfb8 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java @@ -0,0 +1,28 @@ +package tech.mhuang.interchan.sso.redis; + +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; + +/** + * @ClassName: RedisCacheStartup + * @Author: Ever + * @Description: Redis + * @Date: 2019/12/28 0:11 + * @Version: 1.0 + */ +@Component("redisCacheStartup") +@EnableAsync +public class RedisCacheStartup implements CommandLineRunner { + + @Autowired + private AsyncTaskService asyncTaskService; + + + @Override + public void run(String... args) throws Exception { + asyncTaskService.submit(new RedisCacheStartupService()); + } +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..336185bd64353c9db7417eedf6307e1350d9fbec --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java @@ -0,0 +1,64 @@ +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.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @ClassName: redisCacheStartupService + * @Author: Ever + * @Description: redis 异步加载 + * @Date: 2019/12/30 13:15 + * @Version: 1.0 + */ +@Service +@Slf4j +public class RedisCacheStartupService implements AsyncTask { + /** + * 成功 + */ + private static final String SUCCESS = "success"; + + @Autowired + AsyncTaskService asyncTaskService; + @Autowired + private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; + + @Autowired + private SysFunvisturlRedisOperator syChanmgfunRedisOperator; + + + @Override + public void onSuccess(Object result) { + log.info("redis异步加载:{}", result); + } + + @Override + public void onFailed(Throwable t) { + log.error("redis异步加载:{}", t.getMessage()); + } + + @Override + public String execute() { + //查询数据库,并放入缓存中 + List urls = syChanmgfunVistUrlmMapper.getExcludeUrl(); + if (CollectionUtil.isNotEmpty(urls)) { + Map datas = + urls.parallelStream().collect(Collectors.groupingBy(SyChanmgfunExcludeUrl::getType)); + syChanmgfunRedisOperator.cacheData(AuthConstant.AUTH_DICT_KEY, datas); + } + return SUCCESS; + } + +} diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/ISyChanmgfunVistUrlService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/ISyChanmgfunVistUrlService.java index f53d7f42b1a0a029966624b1e1ce1c548dbeddf1..b4bf789b952b1303c3695db4814d6ba4e99364db 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/ISyChanmgfunVistUrlService.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/ISyChanmgfunVistUrlService.java @@ -2,7 +2,6 @@ package tech.mhuang.interchan.sso.sysfunvisturl.service; import org.springframework.scheduling.annotation.Async; import tech.mhuang.ext.interchan.core.service.BaseService; -import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunExcludeUrlDTO; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmAddDTO; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmQryDTO; import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunVistUrlm; @@ -53,13 +52,6 @@ public interface ISyChanmgfunVistUrlService extends BaseService queryFunVist(String funid); - /** - * @return void - * @Title: setExcludeUrl - * @Description: 设置排除url - */ - List setExcludeUrl(); - /** * @param userid * @return void 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 1a117244f372a54ebbf48e3f0f8d38b134806414..613b94379c14888c7da4f2b647d3293f326d1969 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 @@ -1,6 +1,5 @@ package tech.mhuang.interchan.sso.sysfunvisturl.service.impl; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -13,17 +12,17 @@ import tech.mhuang.ext.interchan.auth.constant.AuthConstant; import tech.mhuang.ext.interchan.core.service.impl.BaseServiceImpl; import tech.mhuang.ext.interchan.protocol.InsertInto; import tech.mhuang.ext.spring.util.DataUtil; -import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunExcludeUrlDTO; 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.sysfunvisturl.cache.SysFunvisturlRedisOperator; -import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunExcludeUrl; import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunVistUrlm; import tech.mhuang.interchan.sso.sysfunvisturl.mapper.SyChanmgfunVistUrlmMapper; import tech.mhuang.interchan.sso.sysfunvisturl.service.ISyChanmgfunVistUrlService; 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; @@ -39,7 +38,7 @@ import java.util.stream.Collectors; @Service("syChanmgfunVistUrlService") @Transactional(readOnly = true) public class SyChanmgfunVistUrlService - extends BaseServiceImpl implements ISyChanmgfunVistUrlService, InitializingBean { + extends BaseServiceImpl implements ISyChanmgfunVistUrlService { @Autowired private BaseIdeable snowflake; @@ -50,6 +49,9 @@ public class SyChanmgfunVistUrlService @Autowired private SysFunvisturlRedisOperator syChanmgfunRedisOperator; + @Autowired + private RedisCacheStartupService redisCacheStartupService; + /** * @param funid * @return void @@ -89,7 +91,7 @@ public class SyChanmgfunVistUrlService @Transactional(propagation = Propagation.REQUIRED) @Override public void insertPowersUrl(List dtos, String userId, String seqno) { - dtos.forEach((value) -> { + dtos.forEach(value -> { SyChanmgfunVistUrlm url = DataUtil.copyTo(value, SyChanmgfunVistUrlm.class); url.setOperateTime(new Date()); url.setOperateUser(userId); @@ -120,35 +122,6 @@ public class SyChanmgfunVistUrlService return DataUtil.copyTo(urlm, SyChanmgfunVistUrlmQryDTO.class); } - /** - * @return void - * @Title: setExcludeUrl - * @Description: 设置排除地址 - */ - @Override - public List setExcludeUrl() { - List vos = null; - //查询数据库,并放入缓存中 - List urls = this.syChanmgfunVistUrlmMapper.getExcludeUrl(); - if (CollectionUtil.isNotEmpty(urls)) { - Map datas = - urls.parallelStream().collect(Collectors.groupingBy(SyChanmgfunExcludeUrl::getType)); - syChanmgfunRedisOperator.cacheData(AuthConstant.AUTH_DICT_KEY, datas); - } - return vos; - } - - /** - *

Title: afterPropertiesSet

- *

Description:

- * - * @throws Exception - * @see InitializingBean#afterPropertiesSet() - */ - @Override - public void afterPropertiesSet() throws Exception { - setExcludeUrl(); - } /** *

Title: setVistUrlPower

@@ -170,7 +143,7 @@ public class SyChanmgfunVistUrlService public void setVistUrlPowerNow(String userId) { String cacheKey = AuthConstant.USER_VIST_URL_CACHEKEY; List urlms = this.syChanmgfunVistUrlmMapper.getUserUrlPower(userId); - Map params = urlms.parallelStream().collect(Collectors.toMap((k) -> { + Map params = urlms.parallelStream().collect(Collectors.toMap(k -> { return userId.concat("-").concat(k.getUrl()); }, v -> v, (oldValue, newValue) -> oldValue)); syChanmgfunRedisOperator.cacheData(cacheKey, params); @@ -248,7 +221,7 @@ public class SyChanmgfunVistUrlService if (StringUtil.isNotBlank(userId)) { this.setVistUrlPowerNow(userId); } else { - this.setExcludeUrl(); + redisCacheStartupService.execute(); } }