14 changed files with 446 additions and 0 deletions
			
			
		@ -0,0 +1,30 @@ | 
				
			|||
package com.epmet.resi.mine.dto.from; | 
				
			|||
 | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
import javax.validation.constraints.NotBlank; | 
				
			|||
import java.io.Serializable; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:07 上午 | 
				
			|||
 */ | 
				
			|||
@Data | 
				
			|||
public class BadgeListFormDTO implements Serializable { | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = 9082922684993474574L; | 
				
			|||
 | 
				
			|||
    public interface BadgeList{} | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 用户ID | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "用户ID不能为空",groups = {BadgeList.class}) | 
				
			|||
    private String userId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 客户ID | 
				
			|||
     */ | 
				
			|||
    @NotBlank(message = "客户ID不能为空",groups = {BadgeList.class}) | 
				
			|||
    private String customerId; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,30 @@ | 
				
			|||
package com.epmet.resi.mine.dto.result; | 
				
			|||
 | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
import java.io.Serializable; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:08 上午 | 
				
			|||
 */ | 
				
			|||
@Data | 
				
			|||
public class BadgeListResultDTO implements Serializable { | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = -6542233940679158922L; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 徽章ID | 
				
			|||
     */ | 
				
			|||
    private String badgeId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 徽章图片地址 | 
				
			|||
     */ | 
				
			|||
    private String badgeIcon; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 徽章是否点亮 | 
				
			|||
     */ | 
				
			|||
    private String isOpened; | 
				
			|||
} | 
				
			|||
@ -1,8 +1,16 @@ | 
				
			|||
package com.epmet.modules.badege.service; | 
				
			|||
 | 
				
			|||
import com.epmet.resi.mine.dto.from.BadgeListFormDTO; | 
				
			|||
import com.epmet.resi.mine.dto.result.BadgeListResultDTO; | 
				
			|||
 | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 10:52 上午 | 
				
			|||
 */ | 
				
			|||
public interface BadgeService { | 
				
			|||
 | 
				
			|||
    List<BadgeListResultDTO> getBadgeList(BadgeListFormDTO badgeListFormDTO); | 
				
			|||
 | 
				
			|||
} | 
				
			|||
 | 
				
			|||
@ -0,0 +1,15 @@ | 
				
			|||
package com.epmet.constant; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 2:45 下午 | 
				
			|||
 */ | 
				
			|||
public interface BadgeConstant { | 
				
			|||
 | 
				
			|||
    String BADGE_KEY = "epmet:badge:"; | 
				
			|||
 | 
				
			|||
    String BADGE = "badge"; | 
				
			|||
 | 
				
			|||
    String DEFAULT_CUSTOMER = "default"; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,26 @@ | 
				
			|||
package com.epmet.dto.form; | 
				
			|||
 | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
import javax.validation.constraints.NotBlank; | 
				
			|||
import java.io.Serializable; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:07 上午 | 
				
			|||
 */ | 
				
			|||
@Data | 
				
			|||
public class UserBadgeListFormDTO implements Serializable { | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = 9082922684993474574L; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 用户ID | 
				
			|||
     */ | 
				
			|||
    private String userId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 客户ID | 
				
			|||
     */ | 
				
			|||
    private String customerId; | 
				
			|||
} | 
				
			|||
@ -0,0 +1,46 @@ | 
				
			|||
package com.epmet.dto.result; | 
				
			|||
 | 
				
			|||
import com.fasterxml.jackson.annotation.JsonIgnore; | 
				
			|||
import lombok.Data; | 
				
			|||
 | 
				
			|||
import java.io.Serializable; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:08 上午 | 
				
			|||
 */ | 
				
			|||
@Data | 
				
			|||
public class UserBadgeListResultDTO implements Serializable { | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = -6542233940679158922L; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 徽章ID | 
				
			|||
     */ | 
				
			|||
    private String badgeId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 徽章图片地址 | 
				
			|||
     */ | 
				
			|||
    private String badgeIcon; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 徽章是否点亮 | 
				
			|||
     */ | 
				
			|||
    private String isOpened; | 
				
			|||
    @JsonIgnore | 
				
			|||
    private String customerId; | 
				
			|||
    @JsonIgnore | 
				
			|||
    private String badgeName; | 
				
			|||
    @JsonIgnore | 
				
			|||
    private String fixationBadgeType; | 
				
			|||
    @JsonIgnore | 
				
			|||
    private Boolean status; | 
				
			|||
 | 
				
			|||
    public UserBadgeListResultDTO() { | 
				
			|||
        this.badgeId = ""; | 
				
			|||
        this.badgeIcon = ""; | 
				
			|||
        this.isOpened = "0"; | 
				
			|||
        this.status = false; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,37 @@ | 
				
			|||
package com.epmet.controller; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.utils.Result; | 
				
			|||
import com.epmet.dto.form.UserBadgeListFormDTO; | 
				
			|||
import com.epmet.dto.result.UserBadgeListResultDTO; | 
				
			|||
import com.epmet.service.UserBadgeService; | 
				
			|||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			|||
import org.springframework.web.bind.annotation.PostMapping; | 
				
			|||
import org.springframework.web.bind.annotation.RequestBody; | 
				
			|||
import org.springframework.web.bind.annotation.RequestMapping; | 
				
			|||
import org.springframework.web.bind.annotation.RestController; | 
				
			|||
 | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:16 上午 | 
				
			|||
 */ | 
				
			|||
@RestController | 
				
			|||
@RequestMapping("badge") | 
				
			|||
public class UserBadgeController { | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private UserBadgeService userBadgeService; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @Description  查询已经点亮的徽章 | 
				
			|||
     * @Param userBadgeListFormDTO | 
				
			|||
     * @author zxc | 
				
			|||
     * @date 2020/11/3 1:33 下午 | 
				
			|||
     */ | 
				
			|||
    @PostMapping("badgelist") | 
				
			|||
    public Result<List<UserBadgeListResultDTO>> selectBadgeList(@RequestBody UserBadgeListFormDTO userBadgeListFormDTO){ | 
				
			|||
        return new Result<List<UserBadgeListResultDTO>>().ok(userBadgeService.selectBadgeList(userBadgeListFormDTO)); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,32 @@ | 
				
			|||
package com.epmet.dao; | 
				
			|||
 | 
				
			|||
import com.epmet.dto.form.UserBadgeListFormDTO; | 
				
			|||
import com.epmet.dto.result.UserBadgeListResultDTO; | 
				
			|||
import org.apache.ibatis.annotations.Mapper; | 
				
			|||
 | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 1:22 下午 | 
				
			|||
 */ | 
				
			|||
@Mapper | 
				
			|||
public interface UserBadgeDao { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @Description  查询已经点亮的徽章 | 
				
			|||
     * @Param userBadgeListFormDTO | 
				
			|||
     * @author zxc | 
				
			|||
     * @date 2020/11/3 1:33 下午 | 
				
			|||
     */ | 
				
			|||
    List<UserBadgeListResultDTO> selectBadgeList(UserBadgeListFormDTO userBadgeListFormDTO); | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @Description  查询默认徽章和改名后的徽章 | 
				
			|||
     * @Param userBadgeListFormDTO | 
				
			|||
     * @author zxc | 
				
			|||
     * @date 2020/11/3 3:11 下午 | 
				
			|||
     */ | 
				
			|||
    List<UserBadgeListResultDTO> selectAllBadge(UserBadgeListFormDTO userBadgeListFormDTO); | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,50 @@ | 
				
			|||
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<UserBadgeListResultDTO> 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<UserBadgeListResultDTO> userBadge,String customerId){ | 
				
			|||
        redisUtils.hSet(BadgeConstant.BADGE_KEY+customerId,BadgeConstant.BADGE, JSON.toJSON(userBadge).toString(),-1); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,22 @@ | 
				
			|||
package com.epmet.service; | 
				
			|||
 | 
				
			|||
import com.epmet.dto.form.UserBadgeListFormDTO; | 
				
			|||
import com.epmet.dto.result.UserBadgeListResultDTO; | 
				
			|||
 | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:18 上午 | 
				
			|||
 */ | 
				
			|||
public interface UserBadgeService { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @Description  查询已经点亮的徽章 | 
				
			|||
     * @Param userBadgeListFormDTO | 
				
			|||
     * @author zxc | 
				
			|||
     * @date 2020/11/3 1:33 下午 | 
				
			|||
     */ | 
				
			|||
    List<UserBadgeListResultDTO> selectBadgeList(UserBadgeListFormDTO userBadgeListFormDTO); | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,79 @@ | 
				
			|||
package com.epmet.service.impl; | 
				
			|||
 | 
				
			|||
import com.epmet.constant.BadgeConstant; | 
				
			|||
import com.epmet.dao.UserBadgeDao; | 
				
			|||
import com.epmet.dto.form.UserBadgeListFormDTO; | 
				
			|||
import com.epmet.dto.result.UserBadgeListResultDTO; | 
				
			|||
import com.epmet.redis.UserBadgeRedis; | 
				
			|||
import com.epmet.service.UserBadgeService; | 
				
			|||
import lombok.extern.slf4j.Slf4j; | 
				
			|||
import org.springframework.beans.BeanUtils; | 
				
			|||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			|||
import org.springframework.stereotype.Service; | 
				
			|||
import org.springframework.util.CollectionUtils; | 
				
			|||
 | 
				
			|||
import java.util.ArrayList; | 
				
			|||
import java.util.List; | 
				
			|||
import java.util.Map; | 
				
			|||
import java.util.stream.Collectors; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * @Author zxc | 
				
			|||
 * @DateTime 2020/11/3 11:18 上午 | 
				
			|||
 */ | 
				
			|||
@Service | 
				
			|||
@Slf4j | 
				
			|||
public class UserBadgeServiceImpl implements UserBadgeService { | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private UserBadgeDao userBadgeDao; | 
				
			|||
    @Autowired | 
				
			|||
    private UserBadgeRedis userBadgeRedis; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @Description  查询已经点亮的徽章 | 
				
			|||
     * @Param userBadgeListFormDTO | 
				
			|||
     * @author zxc | 
				
			|||
     * @date 2020/11/3 1:33 下午 | 
				
			|||
     */ | 
				
			|||
    @Override | 
				
			|||
    public List<UserBadgeListResultDTO> selectBadgeList(UserBadgeListFormDTO userBadgeListFormDTO) { | 
				
			|||
            List<UserBadgeListResultDTO> userBadge = userBadgeRedis.getUserBadge(userBadgeListFormDTO.getCustomerId()); | 
				
			|||
        if (CollectionUtils.isEmpty(userBadge)){ | 
				
			|||
            List<UserBadgeListResultDTO> resultUserBadge = new ArrayList<>(); | 
				
			|||
            List<UserBadgeListResultDTO> userBadgeListResultDTOS = userBadgeDao.selectAllBadge(userBadgeListFormDTO); | 
				
			|||
            if (!CollectionUtils.isEmpty(userBadgeListResultDTOS)){ | 
				
			|||
                Map<String, List<UserBadgeListResultDTO>> groupByCustomer = userBadgeListResultDTOS.stream().collect(Collectors.groupingBy(UserBadgeListResultDTO::getCustomerId)); | 
				
			|||
                resultUserBadge.addAll(groupByCustomer.get(BadgeConstant.DEFAULT_CUSTOMER)); | 
				
			|||
                List<UserBadgeListResultDTO> badgeByCustomer = groupByCustomer.get(userBadgeListFormDTO.getCustomerId()); | 
				
			|||
                resultUserBadge.forEach(r -> { | 
				
			|||
                    badgeByCustomer.forEach(b -> { | 
				
			|||
                        if (r.getBadgeId().equals(b.getBadgeId())){ | 
				
			|||
                            BeanUtils.copyProperties(b,r); | 
				
			|||
                        } | 
				
			|||
                    }); | 
				
			|||
                }); | 
				
			|||
                userBadgeRedis.setUserBadge(resultUserBadge,userBadgeListFormDTO.getCustomerId()); | 
				
			|||
            } | 
				
			|||
        } | 
				
			|||
        userBadge = userBadgeRedis.getUserBadge(userBadgeListFormDTO.getCustomerId()); | 
				
			|||
        List<UserBadgeListResultDTO> userBadgeListResultDTOS = userBadgeDao.selectBadgeList(userBadgeListFormDTO); | 
				
			|||
        if (CollectionUtils.isEmpty(userBadgeListResultDTOS)){ | 
				
			|||
            return userBadge; | 
				
			|||
        } | 
				
			|||
        userBadge.forEach(u -> { | 
				
			|||
            userBadgeListResultDTOS.forEach(badge -> { | 
				
			|||
                if (u.getBadgeId().equals(badge.getBadgeId())){ | 
				
			|||
                    badge.setBadgeIcon(u.getBadgeIcon()); | 
				
			|||
                    u.setStatus(true); | 
				
			|||
                } | 
				
			|||
            }); | 
				
			|||
        }); | 
				
			|||
        userBadge.forEach(u -> { | 
				
			|||
            if (!u.getStatus()){ | 
				
			|||
                userBadgeListResultDTOS.add(u); | 
				
			|||
            } | 
				
			|||
        }); | 
				
			|||
        return userBadgeListResultDTOS; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,37 @@ | 
				
			|||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			|||
 | 
				
			|||
<mapper namespace="com.epmet.dao.UserBadgeDao"> | 
				
			|||
 | 
				
			|||
    <!-- 查询已经点亮的徽章 --> | 
				
			|||
    <select id="selectBadgeList" resultType="com.epmet.dto.result.UserBadgeListResultDTO"> | 
				
			|||
        SELECT | 
				
			|||
            ub.BADGE_ID, | 
				
			|||
            ub.IS_OPENED | 
				
			|||
        FROM | 
				
			|||
            resi_user_badge ub | 
				
			|||
        WHERE | 
				
			|||
            ub.DEL_FLAG = 0 | 
				
			|||
            AND ub.CERTIFICATION_AUTID_STATUS = 'pass' | 
				
			|||
            AND ub.IS_OPENED = 1 | 
				
			|||
            AND ub.CUSTOMER_ID = #{customerId} | 
				
			|||
            AND ub.USER_ID = #{userId} | 
				
			|||
            ORDER BY ub.UPDATED_TIME DESC | 
				
			|||
    </select> | 
				
			|||
 | 
				
			|||
    <!-- 查询默认徽章和改名后的徽章 --> | 
				
			|||
    <select id="selectAllBadge" resultType="com.epmet.dto.result.UserBadgeListResultDTO"> | 
				
			|||
        SELECT | 
				
			|||
            id AS badgeId, | 
				
			|||
            CUSTOMER_ID, | 
				
			|||
            BADGE_NAME, | 
				
			|||
            BADGE_ICON, | 
				
			|||
            FIXATION_BADGE_TYPE | 
				
			|||
        FROM badge | 
				
			|||
        WHERE | 
				
			|||
            DEL_FLAG = '0' | 
				
			|||
            AND (CUSTOMER_ID = 'default' OR CUSTOMER_ID = 'zxc') | 
				
			|||
    </select> | 
				
			|||
 | 
				
			|||
 | 
				
			|||
</mapper> | 
				
			|||
					Loading…
					
					
				
		Reference in new issue