|
|
@ -1,13 +1,26 @@ |
|
|
|
package com.epmet.redis; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.constant.BadgeConstant; |
|
|
|
import com.epmet.constant.UserRedisKeys; |
|
|
|
import com.epmet.dao.BadgeDao; |
|
|
|
import com.epmet.dto.form.UserBadgeUnitFormDTO; |
|
|
|
import com.epmet.dto.result.BadgeListResultDTO; |
|
|
|
import com.epmet.dto.result.UserBadgeListResultDTO; |
|
|
|
import com.epmet.service.UserBadgeService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import static com.epmet.commons.tools.redis.RedisUtils.MINUTE_THIRTY_EXPIRE; |
|
|
|
|
|
|
@ -16,45 +29,50 @@ import static com.epmet.commons.tools.redis.RedisUtils.MINUTE_THIRTY_EXPIRE; |
|
|
|
* @DateTime 2020/11/3 2:21 下午 |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
@Slf4j |
|
|
|
public class UserBadgeRedis { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
|
@Autowired |
|
|
|
private BadgeDao badgeDao; |
|
|
|
@Autowired |
|
|
|
private UserBadgeService badgeService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取客户徽章信息 |
|
|
|
* @Description 获取客户徽章信息 |
|
|
|
* @Param customerId |
|
|
|
* @author zxc |
|
|
|
* @date 2020/11/3 2:50 下午 |
|
|
|
*/ |
|
|
|
public Object getCustomerBadge(String customerId){ |
|
|
|
public Object getCustomerBadge(String customerId) { |
|
|
|
Object userBadge = redisUtils.hGet(BadgeConstant.BADGE_KEY + customerId, BadgeConstant.BADGE); |
|
|
|
return userBadge; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 存放客户徽章信息 |
|
|
|
* @Description 存放客户徽章信息 |
|
|
|
* @Param userBadge |
|
|
|
* @Param customerId |
|
|
|
* @author zxc |
|
|
|
* @date 2020/11/3 2:51 下午 |
|
|
|
*/ |
|
|
|
public void setCustomerBadge(List<UserBadgeListResultDTO> userBadge, String customerId){ |
|
|
|
redisUtils.hSet(BadgeConstant.BADGE_KEY+customerId,BadgeConstant.BADGE, JSON.toJSON(userBadge).toString(),-1); |
|
|
|
public void setCustomerBadge(List<UserBadgeListResultDTO> userBadge, String customerId) { |
|
|
|
redisUtils.hSet(BadgeConstant.BADGE_KEY + customerId, BadgeConstant.BADGE, JSON.toJSON(userBadge).toString(), -1); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 删除客户徽章信息 |
|
|
|
* @Description 删除客户徽章信息 |
|
|
|
* @Param customerId |
|
|
|
* @author zxc |
|
|
|
* @date 2020/11/5 3:06 下午 |
|
|
|
*/ |
|
|
|
public void delCustomerBadge(String customerId){ |
|
|
|
redisUtils.hDel(BadgeConstant.BADGE_KEY+customerId,BadgeConstant.BADGE); |
|
|
|
public void delCustomerBadge(String customerId) { |
|
|
|
redisUtils.hDel(BadgeConstant.BADGE_KEY + customerId, BadgeConstant.BADGE); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 存放徽章审核 手机验证码 |
|
|
|
* @Description 存放徽章审核 手机验证码 |
|
|
|
* @Param mobile |
|
|
|
* @author zxc |
|
|
|
* @date 2020/11/5 10:30 上午 |
|
|
@ -65,7 +83,7 @@ public class UserBadgeRedis { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取徽章审核 手机验证码 |
|
|
|
* @Description 获取徽章审核 手机验证码 |
|
|
|
* @Param mobile |
|
|
|
* @author zxc |
|
|
|
* @date 2020/11/5 10:30 上午 |
|
|
@ -76,4 +94,56 @@ public class UserBadgeRedis { |
|
|
|
return smsCode; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
* @param userId |
|
|
|
* @return java.util.List<com.epmet.dto.form.UserBadgeUnitFormDTO> |
|
|
|
* @Description 获取用户的全部勋章信息(点亮的 、 排序从前到后) |
|
|
|
* @author wangc |
|
|
|
* @date 2020.11.05 13:26 |
|
|
|
*/ |
|
|
|
public List<UserBadgeUnitFormDTO> obtainUserBadge2List(String userId) { |
|
|
|
//TODO 补偿
|
|
|
|
return redisUtils.lrange(UserRedisKeys.getResiUserKey(userId), NumConstant.ZERO, NumConstant.ONE_NEG, UserBadgeUnitFormDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用户点亮或取消徽章 |
|
|
|
* @param |
|
|
|
* @return int |
|
|
|
* @Description 入栈时使用lpush 出栈时使用lrem |
|
|
|
* @author wangc |
|
|
|
* @date 2020.11.05 13:37 |
|
|
|
*/ |
|
|
|
public long pushOrRemoveUserBadge4List(String userId, String badgeId, String customerId) { |
|
|
|
List<UserBadgeUnitFormDTO> orient = obtainUserBadge2List(userId); |
|
|
|
UserBadgeUnitFormDTO unit = null; |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(orient)) { |
|
|
|
Optional<UserBadgeUnitFormDTO> opt = orient.stream().filter(badge -> StringUtils.equals(badgeId, badge.getBadgeId())).findFirst(); |
|
|
|
if (opt.isPresent()) { |
|
|
|
unit = opt.get(); |
|
|
|
return redisUtils.lrem(UserRedisKeys.getResiUserBadgeKey(customerId, userId), NumConstant.ONE, unit); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//徽章池
|
|
|
|
List<UserBadgeListResultDTO> badgePool = |
|
|
|
Optional.ofNullable(JSON.parseArray(getCustomerBadge(customerId).toString(), UserBadgeListResultDTO.class)) |
|
|
|
.orElse(badgeDao.selectCustomerBadgePool(customerId)); |
|
|
|
if (CollectionUtils.isEmpty(badgePool)) { |
|
|
|
log.error("com.epmet.redis.UserBadgeRedis.pushOrRemoveUserBadge4List,缓存中客户{}下的徽章池为空", customerId); |
|
|
|
return NumConstant.ZERO; |
|
|
|
} |
|
|
|
|
|
|
|
if (null == unit) { |
|
|
|
Optional<UserBadgeListResultDTO> poolOpt = |
|
|
|
badgePool.stream().filter(badge -> StringUtils.equals(badge.getBadgeId(), badgeId)).findFirst(); |
|
|
|
if (poolOpt.isPresent()) unit = ConvertUtils.sourceToTarget(poolOpt.get(), UserBadgeUnitFormDTO.class); |
|
|
|
else return NumConstant.ZERO; |
|
|
|
} |
|
|
|
redisUtils.leftPush(UserRedisKeys.getResiUserBadgeKey(customerId, userId), unit); |
|
|
|
return NumConstant.ONE; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|