package com.epmet.redis; import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.constant.BadgeConstant; import com.epmet.dto.result.UserBadgeListResultDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @Author zxc * @DateTime 2020/11/3 2:21 下午 */ @Component public class UserBadgeRedis { @Autowired private RedisUtils redisUtils; /** * @Description 获取徽章信息 * @Param customerId * @author zxc * @date 2020/11/3 2:50 下午 */ public List getUserBadge(String customerId){ Object userBadge = redisUtils.hGet(BadgeConstant.BADGE_KEY + customerId, BadgeConstant.BADGE); if (null == userBadge){ return new ArrayList<>(); } return JSON.parseArray(userBadge.toString(), UserBadgeListResultDTO.class); } /** * @Description 存放徽章信息 * @Param userBadge * @Param customerId * @author zxc * @date 2020/11/3 2:51 下午 */ public void setUserBadge(List userBadge,String customerId){ redisUtils.hSet(BadgeConstant.BADGE_KEY+customerId,BadgeConstant.BADGE, JSON.toJSON(userBadge).toString(),-1); } }