记得上下班打卡 | git大法好,push需谨慎

Commit 0018358e authored by wangyifan's avatar wangyifan

缓存改造- sweet:user:applet:unionid 增加缓存过期时间

parent d6016455
...@@ -25,4 +25,10 @@ public class RedisKeyExpireConst { ...@@ -25,4 +25,10 @@ public class RedisKeyExpireConst {
// adam:identity:mobile 过期时间为30天 // adam:identity:mobile 过期时间为30天
public static final long ADAM_IDENTITY_MOBILE_EXPIRE = 30 * 24 * 60 * 60; public static final long ADAM_IDENTITY_MOBILE_EXPIRE = 30 * 24 * 60 * 60;
// sweet:user:applet:unionid 过期时间30天
public static final long SWEET_USER_APPLET_UNIONID_EXPIRE = 30 * 24 * 60 * 60;
// sweet:user:applet:mobile 过期时间30天
public static final long SWEET_USER_APPLET_MOBILE_EXPIRE = 30 * 24 * 60 * 60;
} }
package com.liquidnet.service.sweet.utils; package com.liquidnet.service.sweet.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.base.constant.RedisKeyExpireConst;
import com.liquidnet.service.sweet.constant.SweetConstant; import com.liquidnet.service.sweet.constant.SweetConstant;
import com.liquidnet.service.sweet.entity.SweetAppletUsers;
import com.liquidnet.service.sweet.mapper.SweetAppletUsersMapper;
import com.liquidnet.service.sweet.vo.SweetAppletUsersVo; import com.liquidnet.service.sweet.vo.SweetAppletUsersVo;
import com.liquidnet.service.sweet.vo.SweetMaoDengVo; import com.liquidnet.service.sweet.vo.SweetMaoDengVo;
import com.liquidnet.service.sweet.vo.SweetWechatUsersVo; import com.liquidnet.service.sweet.vo.SweetWechatUsersVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Component @Component
@Slf4j @Slf4j
...@@ -15,6 +24,8 @@ public class WechatUsersRedisUtils { ...@@ -15,6 +24,8 @@ public class WechatUsersRedisUtils {
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private SweetAppletUsersMapper sweetAppletUsersMapper;
public SweetWechatUsersVo getSweetWechatUsersOfUnionId(String unionId, Integer type) { public SweetWechatUsersVo getSweetWechatUsersOfUnionId(String unionId, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_UNIONID.concat(unionId) String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_UNIONID.concat(unionId)
...@@ -75,7 +86,20 @@ public class WechatUsersRedisUtils { ...@@ -75,7 +86,20 @@ public class WechatUsersRedisUtils {
String redisKey = SweetConstant.REDIS_KEY_SWEET_APPLET_USERS_UNIONID.concat(unionId); String redisKey = SweetConstant.REDIS_KEY_SWEET_APPLET_USERS_UNIONID.concat(unionId);
Object obj = redisUtil.get(redisKey); Object obj = redisUtil.get(redisKey);
if (null == obj) { if (null == obj) {
// 从MySQL数据库查询
LambdaQueryWrapper<SweetAppletUsers> lambda = new QueryWrapper<SweetAppletUsers>()
.lambda()
.eq(SweetAppletUsers::getUnionId, unionId)
.orderByDesc(SweetAppletUsers::getUpdatedAt);
List<SweetAppletUsers> sweetAppletUsers = sweetAppletUsersMapper.selectList(lambda);
if (!CollectionUtils.isEmpty(sweetAppletUsers)) {
SweetAppletUsersVo usersVo = SweetAppletUsersVo.getNew();
BeanUtils.copyProperties(sweetAppletUsers.get(0), usersVo);
setSweetAppletUsers(usersVo);
return usersVo;
} else {
return null; return null;
}
} else { } else {
SweetAppletUsersVo sweetAppletUsersVo = (SweetAppletUsersVo) obj; SweetAppletUsersVo sweetAppletUsersVo = (SweetAppletUsersVo) obj;
return sweetAppletUsersVo; return sweetAppletUsersVo;
...@@ -87,7 +111,7 @@ public class WechatUsersRedisUtils { ...@@ -87,7 +111,7 @@ public class WechatUsersRedisUtils {
redisUtil.set(redisKey, sweetAppletUsersVo); redisUtil.set(redisKey, sweetAppletUsersVo);
String redisKeyU = SweetConstant.REDIS_KEY_SWEET_APPLET_USERS_UNIONID.concat(sweetAppletUsersVo.getUnionId()); String redisKeyU = SweetConstant.REDIS_KEY_SWEET_APPLET_USERS_UNIONID.concat(sweetAppletUsersVo.getUnionId());
redisUtil.set(redisKeyU, sweetAppletUsersVo); redisUtil.set(redisKeyU, sweetAppletUsersVo, RedisKeyExpireConst.SWEET_USER_APPLET_UNIONID_EXPIRE);
} }
public void setStrawberryPosterClick(String openId, long time) { public void setStrawberryPosterClick(String openId, long time) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment