From bbbc39611d232e013b900ba5e6a5a483a062e2f3 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 23 七月 2025 16:46:49 +0800 Subject: [PATCH] 实现CommonMapper中空白方法 --- se-common/src/main/java/com/terra/common/service/CommonService.java | 105 ++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 76 insertions(+), 29 deletions(-) diff --git a/se-common/src/main/java/com/terra/common/service/CommonService.java b/se-common/src/main/java/com/terra/common/service/CommonService.java index 664444b..480d31e 100644 --- a/se-common/src/main/java/com/terra/common/service/CommonService.java +++ b/se-common/src/main/java/com/terra/common/service/CommonService.java @@ -1,6 +1,8 @@ package com.terra.common.service; import com.terra.common.entity.all.RedisCacheKey; +import com.terra.common.entity.all.SettingData; +import com.terra.common.entity.all.StaticData; import com.terra.common.entity.lf.TokenPo; import com.terra.common.entity.lf.UserPo; import com.terra.common.helper.StringHelper; @@ -10,19 +12,23 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.TimeUnit; /** - * 浠ょ墝甯姪绫� + * 閫氱敤鏈嶅姟绫� * @author WWW */ @Component public class CommonService { @Resource - RedisService redisService; + CommonMapper mapper; + @Resource - CommonMapper mapper; + RedisService redisService; public UserPo getCurrentUser(HttpServletRequest req) { String token = WebHelper.getToken(req); @@ -31,27 +37,15 @@ } public UserPo getUserByToken(String token) { - if (StringHelper.isNull(token)) { - return null; - } + if (StringHelper.isNull(token)) return null; - // redis - String userKey = RedisCacheKey.signUserKey(token); - Object obj = redisService.get(userKey); - if (obj instanceof UserPo) { - return (UserPo) obj; - } + TokenPo tokenPo = getTokenPo(token); + if (null == tokenPo) return null; - // db - UserPo po = mapper.selectByToken(token); - if (null != po) { - getEntityByToken(token); - } - - return po; + return getUser(token); } - public TokenPo getEntityByToken(String token) { + public TokenPo getTokenPo(String token) { String tokenKey = RedisCacheKey.signTokenKey(token); // redis @@ -61,18 +55,71 @@ } // db - TokenPo te = mapper.selectOneByToken(token); - if (null != te) { - long min = StringHelper.getMinuteDifference(te.getExpire()); - if (min > 0) { - redisService.put(tokenKey, te, min, TimeUnit.MINUTES); - } + TokenPo po = mapper.selectOneByToken(token); + if (null != po) { + long min = StringHelper.getMinuteDifference(po.getExpire()); + redisService.put(tokenKey, po, min, TimeUnit.MINUTES); } - return te; + return po; } - public static String getCurrentUserName() { - return null; + public UserPo getUser(String token) { + String userKey = RedisCacheKey.signUserKey(token); + + // redis + Object obj = redisService.get(userKey); + if (obj instanceof UserPo) { + return (UserPo) obj; + } + + // db + UserPo po = mapper.selectByToken(token); + if (null != po) { + redisService.put(userKey, po, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); + } + + return po; + } + + /** + * 鐢ㄦ埛ID鏄�/鍚︾鐢� + */ + public boolean isUidDisable(UserPo ue) { + String key = RedisCacheKey.signPwdError(ue.getUid()); + Object objCount = redisService.get(key); + + return null != objCount && (int) objCount >= SettingData.PWD_ERR_COUNT; + } + + public List<String> selectIpList(Integer type) { + String key = RedisCacheKey.blacklistKey(type.toString()); + + Object obj = redisService.get(key); + if (obj instanceof List<?>) { + return (List<String>) obj; + } + + List<String> list = mapper.selectIpList(type); + if (list != null && !list.isEmpty()) { + redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); + } + + return list; + } + + public List<String> selectPerms(String uid) { + String key = RedisCacheKey.permsPermsKey(uid); + Object obj = redisService.get(key); + if (obj instanceof List<?>) { + return (List<String>) obj; + } + + List<String> list = mapper.selectPerms(uid); + if (list != null && !list.isEmpty()) { + redisService.put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); + } + + return list; } } -- Gitblit v1.9.3