diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/cache/SysFunvisturlRedisOperator.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/cache/SysFunvisturlRedisOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..972b121243d804925b199e89b49957d04e1d3380 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/cache/SysFunvisturlRedisOperator.java @@ -0,0 +1,48 @@ +package tech.mhuang.interchan.sso.sysfunvisturl.cache; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import tech.mhuang.ext.interchan.auth.constant.AuthConstant; +import tech.mhuang.ext.interchan.redis.commands.IRedisExtCommands; +import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunVistUrlm; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName: SysUserRoleRedisOperator + * @Author: Ever + * @Description: 用户角色缓存类 + * @Date: 2019/12/24 19:32 + * @Version: 1.0 + */ +@Component +public class SysFunvisturlRedisOperator { + + @Autowired + private IRedisExtCommands redisExtCommands; + + + /** + * 缓存权限 + * + * @param key key + * @param dataMap value + */ + public void cacheData(String key, Map dataMap) { + redisExtCommands.hmset(key, dataMap); + } + + /** + * 根据用户ID获取缓存URL + * + * @param userId 用户ID + * @return 缓存URL + */ + public List getVistUrls(String userId) { + //检查路径与权限问题 + String cacheKey = AuthConstant.USER_VIST_URL_CACHEKEY; + return redisExtCommands.hgetList(cacheKey, userId, SyChanmgfunVistUrlm.class); + } + +} 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 0482ca4ec49b9e6ed6eae6854e3aca84b49c4e7e..f67783c53a88e7c2dd0b632896e90177326e1466 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 @@ -12,7 +12,6 @@ import tech.mhuang.core.util.StringUtil; 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.interchan.redis.commands.IRedisExtCommands; import tech.mhuang.ext.spring.util.DataUtil; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunExcludeUrlDTO; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmAddDTO; @@ -21,6 +20,7 @@ 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.sysfunvisturl.cache.SysFunvisturlRedisOperator; import tech.mhuang.interchan.sso.sysrole.entity.SysRole; import tech.mhuang.interchan.sso.sysuser.entity.SysUser; @@ -45,10 +45,10 @@ public class SyChanmgfunVistUrlService private BaseIdeable snowflake; @Autowired - private IRedisExtCommands redisExtCommands; + private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; @Autowired - private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; + private SysFunvisturlRedisOperator syChanmgfunRedisOperator; /** * @param funid @@ -133,7 +133,7 @@ public class SyChanmgfunVistUrlService if (CollectionUtil.isNotEmpty(urls)) { Map datas = urls.parallelStream().collect(Collectors.groupingBy(SyChanmgfunExcludeUrl::getType)); - this.redisExtCommands.hmset(AuthConstant.AUTH_DICT_KEY, datas); + syChanmgfunRedisOperator.cacheData(AuthConstant.AUTH_DICT_KEY, datas); } return vos; } @@ -158,9 +158,7 @@ public class SyChanmgfunVistUrlService */ @Override public void setVistUrlPower(String userid) { - //检查路径与权限问题 - String cacheKey = AuthConstant.USER_VIST_URL_CACHEKEY; - List vistUrls = this.redisExtCommands.hgetList(cacheKey, userid, SyChanmgfunVistUrlm.class); + List vistUrls = syChanmgfunRedisOperator.getVistUrls(userid); if (CollectionUtil.isEmpty(vistUrls)) { //不存在的时候设置权限 setVistUrlPowerNow(userid); @@ -175,8 +173,7 @@ public class SyChanmgfunVistUrlService Map params = urlms.parallelStream().collect(Collectors.toMap((k) -> { return userId.concat("-").concat(k.getUrl()); }, v -> v, (oldValue, newValue) -> oldValue)); - this.redisExtCommands.hmset(cacheKey, params); - + syChanmgfunRedisOperator.cacheData(cacheKey, params); } /** diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/cache/UserRedisOperator.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/cache/UserRedisOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..5bcc4454a55e3665c2b9f77fd4dd0b85808e6a3c --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/cache/UserRedisOperator.java @@ -0,0 +1,65 @@ +package tech.mhuang.interchan.sso.sysuser.cache; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import tech.mhuang.ext.interchan.redis.commands.IRedisExtCommands; +import tech.mhuang.interchan.sso.sysuser.entity.SysUser; + +/** + * @ClassName: SysUserRoleRedisOperator + * @Author: Ever + * @Description: 用户缓存类 + * @Date: 2019/12/24 19:32 + * @Version: 1.0 + */ +@Component +public class UserRedisOperator { + + @Autowired + private IRedisExtCommands redisExtCommands; + + /** + * 用户手机号RedisKey前缀 + */ + public static final String SYUSER_REDIS_MOBILE_TOUSERID_PREKEY = "syur_moblie_uid_"; + + /** + * 用户ID获取用户前缀 + */ + public static final String SYUSER_REDIS_USERID_TO_USER_PREKEY = "syur_user_uid_"; + + /** + * 根据手机号获取用户ID + * + * @param mobilePhone 手机号 + * @return 用户ID + */ + public String getUserId(String mobilePhone) { + return redisExtCommands.hget(SYUSER_REDIS_MOBILE_TOUSERID_PREKEY, mobilePhone); + } + + /** + * 根据用户ID获取用户 + * + * @param userId 用户ID + * @return 系统用户 + */ + public SysUser getSysUserByUserId(String userId) { + return redisExtCommands.hget(SYUSER_REDIS_USERID_TO_USER_PREKEY, userId, SysUser.class); + } + + /** + * 缓存用户 + * + * @param prefix 缓存前缀标识 + * @param key KEY + * @param value 用户ID VALUE + * @param seconds 缓存时间(秒) + * @return 是否成功 + */ + public boolean cacheUser(String prefix, String key, Object value, Long seconds) { + return redisExtCommands.hset(prefix, key, value, seconds); + } + + +} diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/service/impl/SysUserServiceImpl.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/service/impl/SysUserServiceImpl.java index 9f662871ab4feb6414d8af93b4765e8483c7445d..904e5d55352f6249ff16cc358eb09f23bd279616 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/service/impl/SysUserServiceImpl.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuser/service/impl/SysUserServiceImpl.java @@ -15,7 +15,6 @@ import tech.mhuang.ext.interchan.protocol.InsertInto; import tech.mhuang.ext.interchan.protocol.Result; import tech.mhuang.ext.interchan.protocol.data.Page; import tech.mhuang.ext.interchan.protocol.data.PageVO; -import tech.mhuang.ext.interchan.redis.commands.IRedisExtCommands; import tech.mhuang.ext.spring.util.DataUtil; import tech.mhuang.interchan.protocol.sso.UserDTO; import tech.mhuang.interchan.protocol.sso.sysuser.*; @@ -29,6 +28,7 @@ import tech.mhuang.interchan.sso.sysuser.entity.SysUser; import tech.mhuang.interchan.sso.sysuser.mapper.SysUserMapper; import tech.mhuang.interchan.sso.sysuser.mapper.SysUserRecordMapper; import tech.mhuang.interchan.sso.sysuser.service.ISysUserService; +import tech.mhuang.interchan.sso.sysuser.cache.UserRedisOperator; import tech.mhuang.interchan.sso.util.AES; import tech.mhuang.interchan.sso.util.MD5; @@ -48,11 +48,8 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme private BaseIdeable snowflake; @Autowired - private IRedisExtCommands redisExtCommands; + UserRedisOperator userRedisOperator; - private final static String SYUSER_REDIS_MOBILE_TOUSERID_PREKEY = "syur_moblie_uid_"; - - private final static String SYUSER_REDIS_USERID_TO_USER_PREKEY = "syur_user_uid_"; private final static Logger logger = LoggerFactory.getLogger(SysUserServiceImpl.class); @@ -86,7 +83,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme @Override public void saveUser(SysUserAddDTO sysUserAddDTO) { - String userId = redisExtCommands.hget(SYUSER_REDIS_MOBILE_TOUSERID_PREKEY, sysUserAddDTO.getMobilephone()); + String userId = userRedisOperator.getUserId(sysUserAddDTO.getMobilephone()); if (StringUtil.isNotBlank(userId)) { throw new BusinessException(Result.SYS_RESULT_FAILD, environment.getProperty("chan_mobile_repeat")); @@ -424,7 +421,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme SysUser sysuser = null; try { //从缓存中加载用户信息 - sysuser = redisExtCommands.hget(SYUSER_REDIS_USERID_TO_USER_PREKEY, userId, SysUser.class); + sysuser = userRedisOperator.getSysUserByUserId(userId); } catch (Exception e) { logger.error("使用userId从缓存中获取用户信息失败,userId为:{}", userId, e); } @@ -439,7 +436,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme */ private String getUserIdByMobileFromCache(String mobilephone) { try { - return redisExtCommands.hget(SYUSER_REDIS_MOBILE_TOUSERID_PREKEY, mobilephone); + return userRedisOperator.getUserId(mobilephone); } catch (Exception e) { logger.error("getUserIdByMobileFromCache 获取用户缓存信息失败,手机号为:{}", mobilephone, e); } @@ -452,7 +449,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme * @return: String */ public String getSyuserRedisMobileToUserIdKey(String mobilephone) { - return SYUSER_REDIS_MOBILE_TOUSERID_PREKEY + mobilephone; + return UserRedisOperator.SYUSER_REDIS_MOBILE_TOUSERID_PREKEY + mobilephone; } /** @@ -461,7 +458,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme * @return: String */ public String getSyuserRedisUserIdToUserKey(String userId) { - return SYUSER_REDIS_USERID_TO_USER_PREKEY + userId; + return UserRedisOperator.SYUSER_REDIS_USERID_TO_USER_PREKEY + userId; } /** @@ -471,8 +468,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme */ public boolean setSyuserRedisMobileToUser(String mobilephone, String userId) { try { - return redisExtCommands.hset(SYUSER_REDIS_MOBILE_TOUSERID_PREKEY, - mobilephone, userId, Global.EXPIRE_THIRTY_DAYS); + return userRedisOperator.cacheUser(UserRedisOperator.SYUSER_REDIS_MOBILE_TOUSERID_PREKEY, mobilephone, userId, Global.EXPIRE_THIRTY_DAYS); } catch (Exception e) { logger.error("setSyuserRedisMobileToUser 设置缓存信息失败,手机号为:{}", mobilephone, e); return false; @@ -487,8 +483,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme */ public boolean setSyuserRedisUserIdToUser(String userId, SysUser user) { try { - return redisExtCommands.hset(SYUSER_REDIS_USERID_TO_USER_PREKEY, - userId, user, Global.EXPIRE_THIRTY_DAYS); + return userRedisOperator.cacheUser(UserRedisOperator.SYUSER_REDIS_USERID_TO_USER_PREKEY, userId, user, Global.EXPIRE_THIRTY_DAYS); } catch (Exception e) { logger.error("setSyuserRedisUserIdToUser 设置缓存信息失败,用户ID为:{}", userId, e); return false; @@ -497,7 +492,7 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme private SysUser getSyuserRedisUserId(String userId) { try { - return redisExtCommands.hget(SYUSER_REDIS_USERID_TO_USER_PREKEY, userId, SysUser.class); + return userRedisOperator.getSysUserByUserId(userId); } catch (Exception e) { logger.error("getSyuserRedisUserId 获取缓存失败,用户ID为:{}", userId, e); return null; diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/cache/SysUserRoleRedisOperator.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/cache/SysUserRoleRedisOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..538615e65cc4346466172ac964cebd2d417392fd --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/cache/SysUserRoleRedisOperator.java @@ -0,0 +1,36 @@ +package tech.mhuang.interchan.sso.sysuserrole.cache; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import tech.mhuang.ext.interchan.redis.commands.IRedisExtCommands; +import tech.mhuang.interchan.protocol.sso.sysuserrole.SysUserRoleDTO; + +import java.util.List; + +/** + * @ClassName: SysUserRoleRedisOperator + * @Author: Ever + * @Description: 用户角色缓存类 + * @Date: 2019/12/24 19:32 + * @Version: 1.0 + */ +@Component +public class SysUserRoleRedisOperator { + + @Autowired + private IRedisExtCommands redisExtCommands; + + public static final String SYSTEM_USER_ROLE_CACHE_KEY = "SYSTEM_USER_ROLE"; + + /** + * 缓存用户角色 + * + * @param userId 用户ID key + * @param userRoles 角色与用户 + */ + public void cacheUserRole(String userId, List userRoles) { + redisExtCommands.hset(SYSTEM_USER_ROLE_CACHE_KEY, userId, userRoles); + } + + +} diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/service/impl/SysUserRoleServiceImpl.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/service/impl/SysUserRoleServiceImpl.java index c17d8083e4243ab2ac0ae09fb46e2a6d90d807fa..802e33db09b81da7c41b842caefec17a94a59709 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/service/impl/SysUserRoleServiceImpl.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysuserrole/service/impl/SysUserRoleServiceImpl.java @@ -8,12 +8,12 @@ import tech.mhuang.core.id.BaseIdeable; import tech.mhuang.core.util.StringUtil; import tech.mhuang.ext.interchan.core.service.impl.BaseServiceImpl; import tech.mhuang.ext.interchan.protocol.InsertInto; -import tech.mhuang.ext.interchan.redis.commands.IRedisExtCommands; import tech.mhuang.ext.spring.util.DataUtil; import tech.mhuang.interchan.protocol.sso.sysuserrole.*; import tech.mhuang.interchan.sso.sysuserrole.entity.SysUserRole; import tech.mhuang.interchan.sso.sysuserrole.mapper.SysUserRoleMapper; import tech.mhuang.interchan.sso.sysuserrole.service.ISysUserRoleService; +import tech.mhuang.interchan.sso.sysuserrole.cache.SysUserRoleRedisOperator; import java.util.Arrays; import java.util.Date; @@ -36,11 +36,9 @@ public class SysUserRoleServiceImpl extends BaseServiceImpl private BaseIdeable snowflake; @Autowired - private IRedisExtCommands redisExtCommands; + private SysUserRoleRedisOperator sysUserRoleRedisOperator; - public static final String SYSTEM_USER_ROLE_CACHE_KEY = "SYSTEM_USER_ROLE"; - @Autowired public void setMapper(SysUserRoleMapper sysUserRoleMapper) { this.setBaseMapper(sysUserRoleMapper); @@ -149,7 +147,7 @@ public class SysUserRoleServiceImpl extends BaseServiceImpl @Override public void setUserRoleToCache(String userId) { List userRoles = this.queryUserRole(userId); - redisExtCommands.hset(SYSTEM_USER_ROLE_CACHE_KEY, userId, userRoles); + sysUserRoleRedisOperator.cacheUserRole(userId, userRoles); } diff --git a/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/WebLoggerAspect.java b/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/WebLoggerAspect.java index 279bee1005fab3db81386a1160ae51efc10e2410..6b91ac6fe9e7ea58e382fcd1d61613ef8b5d57e8 100644 --- a/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/WebLoggerAspect.java +++ b/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/WebLoggerAspect.java @@ -133,7 +133,6 @@ public class WebLoggerAspect { esAsyncLogger.setEsOperatorLogger(esOperatorLogger); esAsyncLogger.setName(properties.getEsKey()); esAsyncLogger.setIndex(application); - esAsyncLogger.setType(application); if (StringUtil.isEmpty(esOperatorLogger.getId())) { esAsyncLogger.setOpType(ESAsyncLoggerOpType.INSERT); } else { diff --git a/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/entity/ESAsyncLogger.java b/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/entity/ESAsyncLogger.java index 0e41ba45c785673cb1e5b8d32a9ebed48026ce1a..76b5bf495b9c8ae1985ef620c68aa057e99b3088 100644 --- a/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/entity/ESAsyncLogger.java +++ b/inter-logger-common/src/main/java/tech/mhuang/interchan/logger/entity/ESAsyncLogger.java @@ -25,11 +25,6 @@ public class ESAsyncLogger { */ private String index; - /** - * es记录的索引类型 - */ - private String type; - /** * es记录的日志 */