提交 a41869ae 作者: han

修改fastJson问题

上级 38890449
package com.mmc.iuav.user.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mmc.iuav.user.model.vo.CompanyInfoVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
......
package com.mmc.iuav.user.auth;
import com.alibaba.fastjson2.JSONObject;
import com.google.gson.Gson;
import com.mmc.iuav.auth.JwtConstant;
import com.mmc.iuav.auth.JwtUtil;
import com.mmc.iuav.user.dao.RoleDao;
......@@ -12,6 +13,7 @@ import com.mmc.iuav.user.service.CompanyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;
import java.util.HashMap;
......@@ -42,7 +44,7 @@ public class AuthHandler {
LoginSuccessDTO loginSuccessDTO = LoginSuccessDTO.builder().token(token).openId(userAccountVO.getOpenId()).userAccountId(userAccountVO.getId()).uid(userAccountVO.getId() + "")
.userName(userAccountVO.getUserName()).nickName(userAccountVO.getNickName()).phoneNum(userAccountVO.getPhoneNum()).portType(UserTypeEnums.APP.getType()).build();
stringRedisTemplate.opsForValue().set(
token, JSONObject.toJSONString(loginSuccessDTO),
token, new Gson().toJson(loginSuccessDTO),
JwtConstant.EXPIRATION, TimeUnit.MILLISECONDS);
AppUserSucVO appUserSucVO = AppUserSucVO.builder().token(token).uid(userAccountVO.getUid()).phoneNum(userAccountVO.getPhoneNum())
......@@ -57,7 +59,7 @@ public class AuthHandler {
LoginSuccessDTO loginSuccessDTO = LoginSuccessDTO.builder().token(token).userAccountId(userAccountVO.getId())
.phoneNum(userAccountVO.getPhoneNum()).portType(UserTypeEnums.APP.getType()).build();
stringRedisTemplate.opsForValue().set(
token, JSONObject.toJSONString(loginSuccessDTO),
token, new Gson().toJson(loginSuccessDTO),
JwtConstant.EXPIRATION, TimeUnit.MILLISECONDS);
WebUserSucVO webUserSucVO = WebUserSucVO.builder().token(token).phoneNum(userAccountVO.getPhoneNum())
.nickName(userAccountVO.getNickName()).userAccountId(userAccountVO.getId()).build();
......@@ -79,7 +81,7 @@ public class AuthHandler {
.companyInfoVO(companyInfoVO == null ? null : companyInfoVO)
.roleInfo(roleInfoDO.buildRoleInfoDTO()).build();
stringRedisTemplate.opsForValue().set(
token, JSONObject.toJSONString(loginSuccessDTO),
token, new Gson().toJson(loginSuccessDTO),
JwtConstant.EXPIRATION, TimeUnit.MILLISECONDS);
// 标记
stringRedisTemplate.opsForValue().set(
......
......@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
......
package com.mmc.iuav.user.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis的配置类
* 修改redis序列化对象时 key-value的序列化方式
*
* @author han
* @date 2023/08/09
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// 关联redis工厂
redisTemplate.setConnectionFactory(factory);
// 设置key的序列化方式
redisTemplate.setKeySerializer(RedisSerializer.string());
redisTemplate.setValueSerializer(RedisSerializer.json());
redisTemplate.setHashKeySerializer(stringRedisSerializer);
redisTemplate.setHashValueSerializer(stringRedisSerializer);
return redisTemplate;
}
}
......@@ -36,7 +36,7 @@ public class ScheduledTaskUtil {
private final Map<Integer, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
public void create(UserDO userDO){
long delay = 600000; // 延迟10分钟开始执行
long delay = 60000; // 延迟10分钟开始执行
MyTask task = new MyTask();
task.setUserDO(userDO);
// task.setWxService(wxService);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论