From 80f1a8c384fa8f1478784ec8e411857a92f763ca Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Thu, 14 Jul 2022 14:16:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/nl/AppRun.java | 5 ---- .../nl/modules/cache/BothCacheManager.java | 19 --------------- .../org/nl/modules/cache/CacheConfig.java | 23 ------------------ .../nl/modules/cache/LocalCacheManager.java | 19 --------------- .../org/nl/modules/cache/NlCacheManager.java | 13 ---------- .../nl/modules/cache/RemoteCacheManager.java | 24 ------------------- .../rest/AuthorizationController.java | 16 +++---------- 7 files changed, 3 insertions(+), 116 deletions(-) delete mode 100644 nladmin-system/src/main/java/org/nl/modules/cache/BothCacheManager.java delete mode 100644 nladmin-system/src/main/java/org/nl/modules/cache/CacheConfig.java delete mode 100644 nladmin-system/src/main/java/org/nl/modules/cache/LocalCacheManager.java delete mode 100644 nladmin-system/src/main/java/org/nl/modules/cache/NlCacheManager.java delete mode 100644 nladmin-system/src/main/java/org/nl/modules/cache/RemoteCacheManager.java diff --git a/nladmin-system/src/main/java/org/nl/AppRun.java b/nladmin-system/src/main/java/org/nl/AppRun.java index 8e59e4c..ae2ca24 100644 --- a/nladmin-system/src/main/java/org/nl/AppRun.java +++ b/nladmin-system/src/main/java/org/nl/AppRun.java @@ -1,6 +1,5 @@ package org.nl; -import com.alicp.jetcache.Cache; import io.swagger.annotations.Api; import org.nl.annotation.rest.AnonymousGetMapping; import org.nl.utils.SpringContextHolder; @@ -32,11 +31,7 @@ import org.springframework.web.bind.annotation.RestController; @ServletComponentScan @EnableTransactionManagement @EnableJpaAuditing(auditorAwareRef = "auditorAware") - public class AppRun implements CommandLineRunner { - - private Cache userCache; - public static void main(String[] args) { SpringApplication.run(AppRun.class, args); diff --git a/nladmin-system/src/main/java/org/nl/modules/cache/BothCacheManager.java b/nladmin-system/src/main/java/org/nl/modules/cache/BothCacheManager.java deleted file mode 100644 index e90a29b..0000000 --- a/nladmin-system/src/main/java/org/nl/modules/cache/BothCacheManager.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.nl.modules.cache; - -import com.alicp.jetcache.Cache; -import com.alicp.jetcache.anno.CacheType; -import com.alicp.jetcache.anno.CreateCache; -import lombok.Data; - -@Data -public class BothCacheManager extends NlCacheManager { - /** - * 使用 @CreateCache 注解创建Cache实例; - * 未定义默认值的参数,将使用yml中指定的全局配置; - * 缓存在 Local,也可以配置成 both 开启两级缓存 - */ - @CreateCache(expire = 5 * 60, cacheType = CacheType.BOTH, localLimit = 10) - private Cache defaultCache; - @CreateCache(expire = 5 * 60, cacheType = CacheType.BOTH, localLimit = 10) - private Cache systemCache; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/cache/CacheConfig.java b/nladmin-system/src/main/java/org/nl/modules/cache/CacheConfig.java deleted file mode 100644 index 9e7e7cf..0000000 --- a/nladmin-system/src/main/java/org/nl/modules/cache/CacheConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.nl.modules.cache; - -import com.alicp.jetcache.anno.CacheConsts; -import com.alicp.jetcache.anno.CacheType; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class CacheConfig { - @Value("${jetcache.defaultCacheType}") - private String cacheType; - - @Bean(name = "sysCacheManager") - public NlCacheManager sysCacheManager() { - CacheConsts.isUndefined(2); - if (CacheType.BOTH.name().equals(cacheType)) return new BothCacheManager(); - if (CacheType.LOCAL.name().equals(cacheType)) return new LocalCacheManager(); - if (CacheType.REMOTE.name().equals(cacheType)) return new RemoteCacheManager(); - return new LocalCacheManager(); - } - -} diff --git a/nladmin-system/src/main/java/org/nl/modules/cache/LocalCacheManager.java b/nladmin-system/src/main/java/org/nl/modules/cache/LocalCacheManager.java deleted file mode 100644 index a719e03..0000000 --- a/nladmin-system/src/main/java/org/nl/modules/cache/LocalCacheManager.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.nl.modules.cache; - -import com.alicp.jetcache.Cache; -import com.alicp.jetcache.anno.CacheType; -import com.alicp.jetcache.anno.CreateCache; -import lombok.Data; - -@Data -public class LocalCacheManager extends NlCacheManager { - /** - * 使用 @CreateCache 注解创建Cache实例; - * 未定义默认值的参数,将使用yml中指定的全局配置; - * 缓存在 Local,也可以配置成 both 开启两级缓存 - */ - @CreateCache(expire = 5 * 60, cacheType = CacheType.LOCAL, localLimit = 10) - private Cache defaultCache; - @CreateCache(expire = 5 * 60, cacheType = CacheType.LOCAL, localLimit = 10) - private Cache systemCache; -} diff --git a/nladmin-system/src/main/java/org/nl/modules/cache/NlCacheManager.java b/nladmin-system/src/main/java/org/nl/modules/cache/NlCacheManager.java deleted file mode 100644 index 0a74664..0000000 --- a/nladmin-system/src/main/java/org/nl/modules/cache/NlCacheManager.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.nl.modules.cache; - -import com.alicp.jetcache.Cache; -import lombok.Data; - -@Data -public abstract class NlCacheManager { - private Cache defaultCache; - private Cache systemCache; - public void test(){ - System.out.println(this.getClass().getName()); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/cache/RemoteCacheManager.java b/nladmin-system/src/main/java/org/nl/modules/cache/RemoteCacheManager.java deleted file mode 100644 index 54347a8..0000000 --- a/nladmin-system/src/main/java/org/nl/modules/cache/RemoteCacheManager.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.nl.modules.cache; - -import com.alicp.jetcache.Cache; -import com.alicp.jetcache.anno.CacheType; -import com.alicp.jetcache.anno.CreateCache; -import lombok.Data; - -@Data -public class RemoteCacheManager extends NlCacheManager { - /** - * 使用 @CreateCache 注解创建Cache实例; - * 未定义默认值的参数,将使用yml中指定的全局配置; - * 缓存在 Local,也可以配置成 both 开启两级缓存 - */ - @CreateCache(expire = 5 * 60, cacheType = CacheType.REMOTE, localLimit = 10) - private Cache defaultCache; - @CreateCache(expire = 5 * 60, cacheType = CacheType.REMOTE, localLimit = 10) - private Cache systemCache; - - @Override - public void test() { - System.out.println(this.getClass().getName()); - } -} diff --git a/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java b/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java index 6fad2a5..f162a7d 100644 --- a/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java +++ b/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java @@ -17,9 +17,6 @@ package org.nl.modules.security.rest; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; -import com.alicp.jetcache.Cache; -import com.alicp.jetcache.anno.CacheType; -import com.alicp.jetcache.anno.CreateCache; import com.wf.captcha.base.Captcha; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -77,21 +74,15 @@ public class AuthorizationController { @Resource private LoginProperties loginProperties; - - @CreateCache(cacheType = CacheType.LOCAL) - private Cache authCache; - @ApiOperation("登录授权") @AnonymousPostMapping(value = "/login") public ResponseEntity login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { // 密码解密 String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); // 查询验证码 - // String code = (String) redisUtils.get(authUser.getUuid()); - String code = (String) authCache.get(authUser.getUuid()); + String code = (String) redisUtils.get(authUser.getUuid()); // 清除验证码 - // redisUtils.del(authUser.getUuid()); - authCache.remove(authUser.getUuid()); + redisUtils.del(authUser.getUuid()); if (StrUtil.isEmpty(code)) { throw new BadRequestException("验证码不存在或已过期"); } @@ -137,8 +128,7 @@ public class AuthorizationController { captchaValue = captchaValue.split("\\.")[0]; } // 保存 - // redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES); - authCache.put(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES); + redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES); // 验证码信息 Map imgResult = new HashMap(2) {{ put("img", captcha.toBase64());