From ae58de235378a3bcc2ee78c7d54eff3f3309c245 Mon Sep 17 00:00:00 2001 From: zxq171 Date: Sat, 28 Dec 2019 00:59:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=8A=A0=E8=BD=BDRedis=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E5=8A=A0=E8=BD=BD=E5=8F=AF=E8=AE=BF=E9=97=AE=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=8A=BD=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ISyChanmgfunVistUrlService.java | 8 ---- .../impl/SyChanmgfunVistUrlService.java | 48 +++++-------------- .../interchan/sso/util/RedisCacheStartup.java | 43 +++++++++++++++++ 3 files changed, 54 insertions(+), 45 deletions(-) create mode 100644 inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/util/RedisCacheStartup.java 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 f53d7f4..b4bf789 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 f67783c..16443d8 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,6 @@ package tech.mhuang.interchan.sso.sysfunvisturl.service.impl; -import org.springframework.beans.factory.InitializingBean; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -13,14 +13,13 @@ 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.sysfunvisturl.entity.SyChanmgfunExcludeUrl; +import tech.mhuang.interchan.sso.util.RedisCacheStartup; +import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; 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.sysfunvisturl.cache.SysFunvisturlRedisOperator; import tech.mhuang.interchan.sso.sysrole.entity.SysRole; import tech.mhuang.interchan.sso.sysuser.entity.SysUser; @@ -38,8 +37,9 @@ import java.util.stream.Collectors; */ @Service("syChanmgfunVistUrlService") @Transactional(readOnly = true) +@Slf4j public class SyChanmgfunVistUrlService - extends BaseServiceImpl implements ISyChanmgfunVistUrlService, InitializingBean { + extends BaseServiceImpl implements ISyChanmgfunVistUrlService { @Autowired private BaseIdeable snowflake; @@ -50,6 +50,9 @@ public class SyChanmgfunVistUrlService @Autowired private SysFunvisturlRedisOperator syChanmgfunRedisOperator; + @Autowired + private RedisCacheStartup redisCacheStartup; + /** * @param funid * @return void @@ -89,7 +92,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 +123,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 +144,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 +222,7 @@ public class SyChanmgfunVistUrlService if (StringUtil.isNotBlank(userId)) { this.setVistUrlPowerNow(userId); } else { - this.setExcludeUrl(); + redisCacheStartup.afterPropertiesSet(); } } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/util/RedisCacheStartup.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/util/RedisCacheStartup.java new file mode 100644 index 0000000..168f102 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/util/RedisCacheStartup.java @@ -0,0 +1,43 @@ +package tech.mhuang.interchan.sso.util; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +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: RedisCacheStartup + * @Author: Ever + * @Description: Redis + * @Date: 2019/12/28 0:11 + * @Version: 1.0 + */ +@Component("redisCacheStartup") +public class RedisCacheStartup implements InitializingBean { + + @Autowired + private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; + + @Autowired + private SysFunvisturlRedisOperator syChanmgfunRedisOperator; + + + @Override + public void afterPropertiesSet() { + //查询数据库,并放入缓存中 + 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); + } + } +} -- Gitee From e2609b71d65c60ea23ba7c245bf83bc524d71158 Mon Sep 17 00:00:00 2001 From: zxq171 Date: Sat, 28 Dec 2019 01:04:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?remove=E6=9A=82=E6=97=B6=E4=B8=8D=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 16443d8..5c19b42 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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -15,13 +14,13 @@ 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.util.RedisCacheStartup; import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; 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 tech.mhuang.interchan.sso.util.RedisCacheStartup; import java.util.ArrayList; import java.util.Date; @@ -37,7 +36,6 @@ import java.util.stream.Collectors; */ @Service("syChanmgfunVistUrlService") @Transactional(readOnly = true) -@Slf4j public class SyChanmgfunVistUrlService extends BaseServiceImpl implements ISyChanmgfunVistUrlService { -- Gitee