From 458089fa8c522527bdbb7395122b1742073ea9cc Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Thu, 26 Jun 2025 17:15:14 +0800 Subject: [PATCH] 66688988 --- .../sa/admin/extend/fangxinqian/Base.java | 8 +- .../fangxinqian/{ => company}/Company.java | 4 +- .../module/support/redis/RedisService.java | 407 +++++++++--------- 3 files changed, 211 insertions(+), 208 deletions(-) rename sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/{ => company}/Company.java (60%) diff --git a/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Base.java b/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Base.java index 1ff751f..1752b7c 100644 --- a/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Base.java +++ b/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Base.java @@ -7,8 +7,8 @@ import cn.hutool.json.JSONUtil; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import net.lab1024.sa.common.common.exception.BusinessException; -import net.lab1024.sa.common.module.support.redis.RedisService; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import javax.annotation.Resource; import java.util.HashMap; @@ -28,7 +28,7 @@ public class Base { private static String clientUrl; @Resource - private RedisService redisService; + private RedisTemplate redisTemplate; /** * 发送 POST JSON 请求 @@ -40,7 +40,7 @@ public class Base { public String postJson(String url, String jsonData, Map headers) { // 获取token String tokenKey = "fangxinqian:" + clientId; - String token = redisService.get(tokenKey); + String token = redisTemplate.opsForValue().get(tokenKey); if (token == null) { token = getAccessToken(); } @@ -100,7 +100,7 @@ public class Base { } String tokenKey = "fangxinqian:" + clientId; - redisService.set(tokenKey,accessToken,(expiresIn - 120)); + redisTemplate.opsForValue().set(tokenKey,accessToken,(expiresIn - 120)); return accessToken; } diff --git a/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Company.java b/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/company/Company.java similarity index 60% rename from sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Company.java rename to sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/company/Company.java index 66505e6..7c6f1a8 100644 --- a/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/Company.java +++ b/sa-admin/src/main/java/net/lab1024/sa/admin/extend/fangxinqian/company/Company.java @@ -1,6 +1,7 @@ -package net.lab1024.sa.admin.extend.fangxinqian; +package net.lab1024.sa.admin.extend.fangxinqian.company; import lombok.extern.slf4j.Slf4j; +import net.lab1024.sa.admin.extend.fangxinqian.Base; import org.springframework.stereotype.Component; /** @@ -9,5 +10,4 @@ import org.springframework.stereotype.Component; @Slf4j @Component public class Company extends Base { - } diff --git a/sa-common/src/main/java/net/lab1024/sa/common/module/support/redis/RedisService.java b/sa-common/src/main/java/net/lab1024/sa/common/module/support/redis/RedisService.java index 4723113..706d5ff 100644 --- a/sa-common/src/main/java/net/lab1024/sa/common/module/support/redis/RedisService.java +++ b/sa-common/src/main/java/net/lab1024/sa/common/module/support/redis/RedisService.java @@ -9,6 +9,7 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.*; import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; @@ -19,205 +20,207 @@ import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; - -/** - * redis 一顿操作 - * - * @Author 1024创新实验室: 罗伊 - * @Date 2020/8/25 21:57 - * @Wechat zhuoda1024 - * @Email lab1024@163.com - * @Copyright 1024创新实验室 ( https://1024lab.net ) - */ -//@Component -public class RedisService { - - private static final Logger log = org.slf4j.LoggerFactory.getLogger(RedisService.class); - - @Resource - private StringRedisTemplate stringRedisTemplate; - - @Resource - private RedisTemplate redisTemplate; - - @Resource - private ValueOperations redisValueOperations; - - @Resource - private HashOperations redisHashOperations; - - @Resource - private ListOperations redisListOperations; - - @Resource - private SetOperations redisSetOperations; - - @Resource - private SystemEnvironment systemEnvironment; - - - /** - * 生成redis key - * @param prefix - * @param key - * @return - */ - public String generateRedisKey(String prefix, String key) { - SystemEnvironmentEnum currentEnvironment = systemEnvironment.getCurrentEnvironment(); - return systemEnvironment.getProjectName() + RedisKeyConst.SEPARATOR + currentEnvironment.getValue() + RedisKeyConst.SEPARATOR + prefix + key; - } - - /** - * redis key 解析成真实的内容 - * @param redisKey - * @return - */ - public static String redisKeyParse(String redisKey) { - if(SmartStringUtil.isBlank(redisKey)){ - return ""; - } - int index = redisKey.lastIndexOf(RedisKeyConst.SEPARATOR); - if(index < 1){ - return redisKey; - } - return redisKey.substring(index); - } - - public boolean getLock(String key, long expire) { - return redisValueOperations.setIfAbsent(key, String.valueOf(System.currentTimeMillis()), expire, TimeUnit.MILLISECONDS); - } - - public void unLock(String key) { - redisValueOperations.getOperations().delete(key); - } - - /** - * 指定缓存失效时间 - * - * @param key 键 - * @param time 时间(秒) - * @return - */ - public boolean expire(String key, long time) { - return redisTemplate.expire(key, time, TimeUnit.SECONDS); - } - - /** - * 获取当天剩余的秒数 - * - * @return - */ - public static long currentDaySecond() { - return ChronoUnit.SECONDS.between(LocalDateTime.now(), LocalDateTime.of(LocalDate.now(), LocalTime.MAX)); - } - - /** - * 根据key 获取过期时间 - * - * @param key 键 不能为null - * @return 时间(秒) 返回0代表为永久有效 - */ - public long getExpire(String key) { - return redisTemplate.getExpire(key, TimeUnit.SECONDS); - } - - /** - * 判断key是否存在 - * - * @param key 键 - * @return true 存在 false不存在 - */ - public boolean hasKey(String key) { - return redisTemplate.hasKey(key); - } - - /** - * 删除缓存 - * - * @param key 可以传一个值 或多个 - */ - @SuppressWarnings("unchecked") - public void delete(String... key) { - if (key != null && key.length > 0) { - if (key.length == 1) { - redisTemplate.delete(key[0]); - } else { - redisTemplate.delete((Collection) CollectionUtils.arrayToList(key)); - } - } - } - - /** - * 删除缓存 - * - * @param keyList - */ - public void delete(List keyList) { - if (CollectionUtils.isEmpty(keyList)) { - return; - } - redisTemplate.delete(keyList); - } - - //============================String============================= - - /** - * 普通缓存获取 - * - * @param key 键 - * @return 值 - */ - public String get(String key) { - return key == null ? null : redisValueOperations.get(key); - } - - public T getObject(String key, Class clazz) { - Object json = this.get(key); - if (json == null) { - return null; - } - T obj = JSON.parseObject(json.toString(), clazz); - return obj; - } - - - /** - * 普通缓存放入 - */ - public void set(String key, String value) { - redisValueOperations.set(key, value); - } - public void set(Object key, Object value) { - String jsonString = JSON.toJSONString(value); - redisValueOperations.set(key.toString(), jsonString); - } - - /** - * 普通缓存放入 - */ - public void set(String key, String value, long second) { - redisValueOperations.set(key, value, second, TimeUnit.SECONDS); - } - - /** - * 普通缓存放入并设置时间 - */ - public void set(Object key, Object value, long time) { - String jsonString = JSON.toJSONString(value); - if (time > 0) { - redisValueOperations.set(key.toString(), jsonString, time, TimeUnit.SECONDS); - } else { - set(key.toString(), jsonString); - } - } - - //============================ map ============================= - public void mset(String key, String hashKey, Object value) { - redisHashOperations.put(key, hashKey, value); - } - - public Object mget(String key, String hashKey) { - return redisHashOperations.get(key, hashKey); - } - -} \ No newline at end of file +// +///** +// * redis 一顿操作 +// * +// * @Author 1024创新实验室: 罗伊 +// * @Date 2020/8/25 21:57 +// * @Wechat zhuoda1024 +// * @Email lab1024@163.com +// * @Copyright 1024创新实验室 +// */ +//@Service +//public class RedisService { +// +// private static final Logger log = org.slf4j.LoggerFactory.getLogger(RedisService.class); +// +// @Resource +// private StringRedisTemplate stringRedisTemplate; +// +// @Resource +// private RedisTemplate redisTemplate; +// +// @Resource +// private ValueOperations redisValueOperations; +// +// @Resource +// private HashOperations redisHashOperations; +// +// @Resource +// private ListOperations redisListOperations; +// +// @Resource +// private SetOperations redisSetOperations; +// +// @Resource +// private SystemEnvironment systemEnvironment; +// +// +// /** +// * 生成redis key +// * @param prefix +// * @param key +// * @return +// */ +// public String generateRedisKey(String prefix, String key) { +// SystemEnvironmentEnum currentEnvironment = systemEnvironment.getCurrentEnvironment(); +// return systemEnvironment.getProjectName() + RedisKeyConst.SEPARATOR + currentEnvironment.getValue() + RedisKeyConst.SEPARATOR + prefix + key; +// } +// +// /** +// * redis key 解析成真实的内容 +// * @param redisKey +// * @return +// */ +// public static String redisKeyParse(String redisKey) { +// if(SmartStringUtil.isBlank(redisKey)){ +// return ""; +// } +// int index = redisKey.lastIndexOf(RedisKeyConst.SEPARATOR); +// if(index < 1){ +// return redisKey; +// } +// return redisKey.substring(index); +// } +// +// public boolean getLock(String key, long expire) { +// return redisValueOperations.setIfAbsent(key, String.valueOf(System.currentTimeMillis()), expire, TimeUnit.MILLISECONDS); +// } +// +// public void unLock(String key) { +// redisValueOperations.getOperations().delete(key); +// } +// +// /** +// * 指定缓存失效时间 +// * +// * @param key 键 +// * @param time 时间(秒) +// * @return +// */ +// public boolean expire(String key, long time) { +// return redisTemplate.expire(key, time, TimeUnit.SECONDS); +// } +// +// /** +// * 获取当天剩余的秒数 +// * +// * @return +// */ +// public static long currentDaySecond() { +// return ChronoUnit.SECONDS.between(LocalDateTime.now(), LocalDateTime.of(LocalDate.now(), LocalTime.MAX)); +// } +// +// /** +// * 根据key 获取过期时间 +// * +// * @param key 键 不能为null +// * @return 时间(秒) 返回0代表为永久有效 +// */ +// public long getExpire(String key) { +// return redisTemplate.getExpire(key, TimeUnit.SECONDS); +// } +// +// /** +// * 判断key是否存在 +// * +// * @param key 键 +// * @return true 存在 false不存在 +// */ +// public boolean hasKey(String key) { +// return redisTemplate.hasKey(key); +// } +// +// /** +// * 删除缓存 +// * +// * @param key 可以传一个值 或多个 +// */ +// @SuppressWarnings("unchecked") +// public void delete(String... key) { +// if (key != null && key.length > 0) { +// if (key.length == 1) { +// redisTemplate.delete(key[0]); +// } else { +// redisTemplate.delete((Collection) CollectionUtils.arrayToList(key)); +// } +// } +// } +// +// /** +// * 删除缓存 +// * +// * @param keyList +// */ +// public void delete(List keyList) { +// if (CollectionUtils.isEmpty(keyList)) { +// return; +// } +// redisTemplate.delete(keyList); +// } +// +// //============================String============================= +// +// /** +// * 普通缓存获取 +// * +// * @param key 键 +// * @return 值 +// */ +// public String get(String key) { +// return key == null ? null : redisValueOperations.get(key); +// } +// +// public T getObject(String key, Class clazz) { +// Object json = this.get(key); +// if (json == null) { +// return null; +// } +// T obj = JSON.parseObject(json.toString(), clazz); +// return obj; +// } +// +// +// /** +// * 普通缓存放入 +// */ +// public void set(String key, String value) { +// redisValueOperations.set(key, value); +// } +// public void set(Object key, Object value) { +// String jsonString = JSON.toJSONString(value); +// redisValueOperations.set(key.toString(), jsonString); +// } +// +// /** +// * 普通缓存放入 +// */ +// public void set(String key, String value, long second) { +// redisValueOperations.set(key, value, second, TimeUnit.SECONDS); +// } +// +// /** +// * 普通缓存放入并设置时间 +// */ +// public void set(Object key, Object value, long second) { +// String jsonString = JSON.toJSONString(value); +// if (second > 0) { +// redisValueOperations.set(key.toString(), jsonString, second, TimeUnit.SECONDS); +// } else { +// set(key.toString(), jsonString); +// } +// } +// +// //============================ map ============================= +// +// +// public void mset(String key, String hashKey, Object value) { +// redisHashOperations.put(key, hashKey, value); +// } +// +// public Object mget(String key, String hashKey) { +// return redisHashOperations.get(key, hashKey); +// } +// +//} \ No newline at end of file