fix: 简单补丁

This commit is contained in:
筱锋xiao_lfeng 2024-01-21 23:56:21 +08:00
parent dbcb984199
commit 9e8eea81b2
Signed by: XiaoLFeng
GPG Key ID: F693AA12AABBFA87
6 changed files with 104 additions and 35 deletions

View File

@ -16,12 +16,18 @@ public class RedisConstant {
/* /*
* 类型分类 * 类型分类
*/ */
public static final String TYPE_EMAIL = "mail:"; // 邮件相关 // 邮件相关
public static final String TYPE_AUTH = "auth:"; // 登陆相关 public static final String TYPE_EMAIL = "mail:";
// 登陆相关
public static final String TYPE_AUTH = "auth:";
/* /*
* 表分类 * 表分类
*/ */
public static final String TABLE_EMAIL = "code:"; // 邮箱验证码 // 邮箱验证码
public static final String TABLE_TOKEN = "token:"; // 令牌相关 public static final String TABLE_EMAIL = "code:";
// 令牌相关
public static final String TABLE_TOKEN = "token:";
// 用户相关
public static final String TABLE_USER = "user:";
} }

View File

@ -42,7 +42,7 @@ public class UserController {
* @param id 用户id * @param id 用户id
* @return {@link BaseResponse} * @return {@link BaseResponse}
*/ */
@PutMapping("/user/delete") @DeleteMapping("/user/delete")
public BaseResponse userDelete(HttpServletRequest request, @RequestParam String id) { public BaseResponse userDelete(HttpServletRequest request, @RequestParam String id) {
log.info("请求接口[PUT]: /user/delete"); log.info("请求接口[PUT]: /user/delete");
// 判断是否有参数错误 // 判断是否有参数错误

View File

@ -1,5 +1,7 @@
package com.jsl.oa.dao; package com.jsl.oa.dao;
import com.google.gson.Gson;
import com.jsl.oa.common.constant.BusinessConstants;
import com.jsl.oa.mapper.RoleMapper; import com.jsl.oa.mapper.RoleMapper;
import com.jsl.oa.mapper.UserMapper; import com.jsl.oa.mapper.UserMapper;
import com.jsl.oa.model.doData.RoleDO; import com.jsl.oa.model.doData.RoleDO;
@ -9,8 +11,10 @@ import com.jsl.oa.model.voData.UserAllCurrentVO;
import com.jsl.oa.model.voData.UserCurrentBackVO; import com.jsl.oa.model.voData.UserCurrentBackVO;
import com.jsl.oa.model.voData.UserEditProfileVO; import com.jsl.oa.model.voData.UserEditProfileVO;
import com.jsl.oa.utils.Processing; import com.jsl.oa.utils.Processing;
import com.jsl.oa.utils.redis.UserRedisUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,6 +27,8 @@ public class UserDAO {
public final UserMapper userMapper; public final UserMapper userMapper;
private final RoleMapper roleMapper; private final RoleMapper roleMapper;
private final Gson gson;
private final UserRedisUtil<String> userRedisUtil;
/** /**
* <h2>用户名获取用户信息</h2> * <h2>用户名获取用户信息</h2>
@ -46,14 +52,30 @@ public class UserDAO {
} }
/** /**
* <h2>用户id获取用户信息</h2>
* <hr/>
* 根据id判断用户是否存在 * 根据id判断用户是否存在
* *
* @param id * @param id 用户id
* @return * @return Boolean
*/ */
public Boolean isExistUser(Long id) { public Boolean isExistUser(@NotNull Long id) {
log.info("\t> 执行 DAO 层 UserDAO.isExistUser 方法"); log.info("\t> 执行 DAO 层 UserDAO.isExistUser 方法");
return userMapper.getUserById(id) != null; // Redis 获取数据
String redisData = userRedisUtil.getData(BusinessConstants.NONE, id.toString());
if (redisData != null) {
log.info("\t\t> 从 Redis 获取数据");
return true;
} else {
UserDO userDO = userMapper.getUserById(id);
log.info("\t\t> 从 MySQL 获取数据");
if (userDO != null) {
userRedisUtil.setData(BusinessConstants.NONE, userDO.getId().toString(), gson.toJson(userDO), 120);
return true;
} else {
return false;
}
}
} }
/** /**

View File

@ -53,6 +53,7 @@ public class EmailRedisUtil<R> extends RedisOperating<R> {
* @param email 邮箱 * @param email 邮箱
* @return 返回是否删除成功 * @return 返回是否删除成功
*/ */
@Override
public Boolean delData(@NotNull BusinessConstants businessConstants, String email) { public Boolean delData(@NotNull BusinessConstants businessConstants, String email) {
String key = RedisConstant.TYPE_EMAIL + RedisConstant.TABLE_EMAIL + businessConstants.getValue() + email; String key = RedisConstant.TYPE_EMAIL + RedisConstant.TABLE_EMAIL + businessConstants.getValue() + email;
return redisTemplate.delete(key); return redisTemplate.delete(key);
@ -67,6 +68,7 @@ public class EmailRedisUtil<R> extends RedisOperating<R> {
* @param email 邮箱 * @param email 邮箱
* @return 返回邮箱验证码 * @return 返回邮箱验证码
*/ */
@Override
public R getData(@NotNull BusinessConstants businessConstants, String email) { public R getData(@NotNull BusinessConstants businessConstants, String email) {
String key = RedisConstant.TYPE_EMAIL + RedisConstant.TABLE_EMAIL + businessConstants.getValue() + email; String key = RedisConstant.TYPE_EMAIL + RedisConstant.TABLE_EMAIL + businessConstants.getValue() + email;
return redisTemplate.opsForValue().get(key); return redisTemplate.opsForValue().get(key);
@ -82,6 +84,7 @@ public class EmailRedisUtil<R> extends RedisOperating<R> {
* @param value 验证码 * @param value 验证码
* @return 返回是否添加成功 * @return 返回是否添加成功
*/ */
@Override
public Boolean setData(@NotNull BusinessConstants businessConstants, String email, R value, Integer time) { public Boolean setData(@NotNull BusinessConstants businessConstants, String email, R value, Integer time) {
// 处理数据 // 处理数据
String key = RedisConstant.TYPE_EMAIL + RedisConstant.TABLE_EMAIL + businessConstants.getValue() + email; String key = RedisConstant.TYPE_EMAIL + RedisConstant.TABLE_EMAIL + businessConstants.getValue() + email;

View File

@ -0,0 +1,55 @@
package com.jsl.oa.utils.redis;
import com.jsl.oa.common.constant.BusinessConstants;
import com.jsl.oa.common.constant.RedisConstant;
import com.jsl.oa.config.redis.RedisOperating;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
* <h1>用户Redis工具类</h1>
* <hr/>
* 用户Redis工具类
*
* @param <R> 泛型
* @since v1.1.0
* @version v1.1.0
* @author xiao_lfeng
*/
@Component
public class UserRedisUtil<R> extends RedisOperating<R> {
public UserRedisUtil(RedisTemplate<String, R> redisTemplate, StringRedisTemplate stringRedisTemplate) {
super(redisTemplate, stringRedisTemplate);
}
@Override
public Long getExpiredAt(@NotNull BusinessConstants businessConstants, String field) {
String key = RedisConstant.TYPE_AUTH + RedisConstant.TABLE_USER + businessConstants.getValue() + field;
return redisTemplate.getExpire(key);
}
@Override
public Boolean delData(@NotNull BusinessConstants businessConstants, String field) {
String key = RedisConstant.TYPE_AUTH + RedisConstant.TABLE_USER + businessConstants.getValue() + field;
return redisTemplate.delete(key);
}
@Override
public R getData(@NotNull BusinessConstants businessConstants, String field) {
String key = RedisConstant.TYPE_AUTH + RedisConstant.TABLE_USER + businessConstants.getValue() + field;
return redisTemplate.opsForValue().get(key);
}
@Override
public Boolean setData(@NotNull BusinessConstants businessConstants, String field, R value, Integer time) {
// 处理数据
String key = RedisConstant.TYPE_AUTH + RedisConstant.TABLE_USER + businessConstants.getValue() + field;
redisTemplate.opsForValue().set(key, value);
redisTemplate.expire(key, time, TimeUnit.MINUTES);
return true;
}
}

View File

@ -1,35 +1,18 @@
server:
port: 8080
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306?organize_oa url: jdbc:mysql://localhost:3306
username: root username: root
password: Zrx@20041009 password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
redis: redis:
database: 0 database: 0
host: localhost host: 192.168.80.129
port: 6379 port: 6379
password: Zrx@20041009 password: 123456
mail: profiles:
default-encoding: UTF-8 active: dev
host: smtp.qiye.aliyun.com
username: wxxydeveloper@x-lf.cn
password: 114477225588Zcw
properties:
form: wxxydeveloper@x-lf.cn
mail:
smtp:
auth: true
starttls:
enable: true
ssl:
enable: true
mybatis: mybatis:
configuration: configuration:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
#logging:
# level:
# root: TRACE
# sun.rmi: OFF
# org.apache.tomcat: WARN
server:
port: 8155