我的勋章,使用的勋章缓存,勋章管理页面
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.accompany.core.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class BaseMedalVo {
|
||||
private String picUrl;
|
||||
private String mp4Url;
|
||||
private String seq;
|
||||
}
|
@@ -12,6 +12,7 @@ import com.accompany.core.vo.vip.UserVipInfoVO;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -239,4 +240,6 @@ public class UserVo {
|
||||
|
||||
private Long inviteUid;
|
||||
private Long inviteErbanNo;
|
||||
|
||||
private List<BaseMedalVo> medalsPic = new ArrayList<>();
|
||||
}
|
||||
|
@@ -1,7 +1,22 @@
|
||||
package com.accompany.business.constant;
|
||||
|
||||
import com.accompany.common.redis.BaseRedisKey;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
|
||||
public interface MedalConstant {
|
||||
|
||||
enum RedisKey implements BaseRedisKey {
|
||||
user_use_medal,
|
||||
;
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "mdeal:" + name();
|
||||
}
|
||||
}
|
||||
|
||||
int MEDAL_SEAT_LIMIT = 3;
|
||||
|
||||
enum MedalType {
|
||||
TASK(1, "任务勋章"),
|
||||
ACTIVITY(2, "活动勋章"),
|
||||
|
@@ -43,4 +43,9 @@ public class UserMedal {
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private Date useTime;
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.accompany.business.vo.medal;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel
|
||||
@Data
|
||||
public class MedalManageVo {
|
||||
@ApiModelProperty("使用的勋章")
|
||||
private List<MedalSeriesRefVo> useMedals;
|
||||
@ApiModelProperty("vip对应的勋章席位数量(勋章佩戴管理使用)")
|
||||
private List<VipMedalSeatVo> vipMedalSeatVos;
|
||||
@ApiModelProperty("全部获得的未过期的勋章(勋章佩戴管理使用)")
|
||||
private List<MedalSeriesRefVo> allMedals;
|
||||
@ApiModelProperty("vip等级")
|
||||
private Integer vipLevel;
|
||||
@ApiModelProperty("勋章数量")
|
||||
private Long medalNum;
|
||||
}
|
@@ -9,6 +9,13 @@ import java.util.List;
|
||||
@ApiModel
|
||||
@Data
|
||||
public class MedalSeriesMineVo {
|
||||
private Long erbanNo;
|
||||
private Long uid;
|
||||
private String nick;
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty("获得的勋章数量")
|
||||
private Long medalNum;
|
||||
@ApiModelProperty("勋章系列")
|
||||
private List<MedalSeriesSquareVo> medalSeries;
|
||||
@ApiModelProperty("使用的勋章")
|
||||
|
@@ -17,6 +17,8 @@ public class MedalSeriesRefVo {
|
||||
@ApiModelProperty("勋章描述")
|
||||
@I18n(className = "Medal", fieldName = "medalDesc")
|
||||
private String medalDesc;
|
||||
@ApiModelProperty("记录id,使用勋章时使用")
|
||||
private Integer id;
|
||||
@ApiModelProperty("勋章静态图")
|
||||
@ReplaceAppDomain
|
||||
private String picUrl;
|
||||
@@ -27,4 +29,8 @@ public class MedalSeriesRefVo {
|
||||
private Integer level;
|
||||
@ApiModelProperty("是否佩戴")
|
||||
private Boolean useStatus;
|
||||
@ApiModelProperty("是否获得")
|
||||
private Boolean hasGain;
|
||||
@ApiModelProperty("过期时间,距离现在还剩多少秒")
|
||||
private Long expireSeconds;
|
||||
}
|
||||
|
@@ -18,6 +18,9 @@ public class UserMedalVo {
|
||||
//图片地址
|
||||
@ReplaceAppDomain
|
||||
private String picUrl;
|
||||
//图片地址
|
||||
@ReplaceAppDomain
|
||||
private String mp4Url;
|
||||
//排序权重
|
||||
private Integer seq;
|
||||
//领取时间
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package com.accompany.business.vo.medal;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class VipMedalSeatVo {
|
||||
private Integer vipLevel;
|
||||
private Integer medalSeatNum;
|
||||
}
|
@@ -14,4 +14,6 @@ import java.util.List;
|
||||
public interface MedalSeriesRefService extends IService<MedalSeriesRef> {
|
||||
|
||||
List<MedalSeriesRef> listBySeriesIds(List<Integer> seriesIds);
|
||||
|
||||
List<MedalSeriesRef> listByMedalIds(List<Integer> medalIds);
|
||||
}
|
||||
|
@@ -18,5 +18,5 @@ public interface MedalSeriesService extends IService<MedalSeries> {
|
||||
List<MedalSeries> listSquareValid(Integer partitionId, Integer type, Integer pageNo, Integer pageSize);
|
||||
|
||||
|
||||
List<MedalSeries> listBySeriesIds(List<Integer> seriesIds, Integer pageNo, Integer pageSize);
|
||||
List<MedalSeries> listBySeriesIds(List<Integer> seriesIds, Integer type, Integer pageNo, Integer pageSize);
|
||||
}
|
||||
|
@@ -1,25 +1,30 @@
|
||||
package com.accompany.business.service.medal;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.accompany.business.model.UserMedal;
|
||||
import com.accompany.business.model.medal.Medal;
|
||||
import com.accompany.business.model.medal.MedalSeries;
|
||||
import com.accompany.business.model.medal.MedalSeriesRef;
|
||||
import com.accompany.business.model.vip.VipAuthItem;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.medal.MedalSeriesRefVo;
|
||||
import com.accompany.business.vo.medal.MedalSeriesSquareVo;
|
||||
import com.accompany.business.vo.medal.MedalSeriesVo;
|
||||
import com.accompany.business.service.vip.VipAuthItemService;
|
||||
import com.accompany.business.util.VipUtil;
|
||||
import com.accompany.business.vo.medal.*;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.accompany.business.constant.MedalConstant.MEDAL_SEAT_LIMIT;
|
||||
import static com.accompany.common.status.BusiStatus.SERIES_CONFIG_ERROR;
|
||||
|
||||
@Service
|
||||
@@ -34,13 +39,18 @@ public class MedalSeriesSquareService {
|
||||
private MedalService medalService;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
@Autowired
|
||||
private UserMedalService userMedalService;
|
||||
@Autowired
|
||||
private VipAuthItemService vipAuthItemService;
|
||||
|
||||
public List<MedalSeriesSquareVo> seriesSquareVos(Long uid, Integer type, Integer pageNo, Integer pageSize) {
|
||||
List<MedalSeriesSquareVo> resultList = new ArrayList<>();
|
||||
Users users = usersService.getUsersByUid(uid);
|
||||
Integer partitionId = users.getPartitionId();
|
||||
|
||||
List<MedalSeriesSquareVo> resultList = new ArrayList<>();
|
||||
List<MedalSeries> medalSeries = medalSeriesService.listSquareValid(partitionId, type, pageNo, pageSize);
|
||||
|
||||
if (CollectionUtils.isEmpty(medalSeries)) {
|
||||
return resultList;
|
||||
}
|
||||
@@ -49,38 +59,187 @@ public class MedalSeriesSquareService {
|
||||
.stream()
|
||||
.map(MedalSeries::getSeriesId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MedalSeriesRef> medalSeriesRefs = medalSeriesRefService.listBySeriesIds(seriesIds);
|
||||
|
||||
if (CollectionUtils.isEmpty(medalSeriesRefs)) {
|
||||
throw new ServiceException(SERIES_CONFIG_ERROR);
|
||||
}
|
||||
|
||||
List<Integer> medalIds = medalSeriesRefs
|
||||
.stream()
|
||||
.map(MedalSeriesRef::getMedalId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<Integer, Medal> medalMap = medalService.getMedalMap(medalIds);
|
||||
|
||||
Map<Integer, List<MedalSeries>> typeMap = medalSeries
|
||||
.stream()
|
||||
Map<Integer, List<MedalSeries>> typeMap = medalSeries.stream()
|
||||
.collect(Collectors.groupingBy(MedalSeries::getType));//分类
|
||||
|
||||
Map<Integer, List<MedalSeriesRef>> refMap = medalSeriesRefs
|
||||
.stream()
|
||||
Map<Integer, List<MedalSeriesRef>> refMap = medalSeriesRefs.stream()
|
||||
.collect(Collectors.groupingBy(MedalSeriesRef::getSeriesId));//分系列
|
||||
|
||||
return typeMap.entrySet().stream()
|
||||
.map(entry -> buildSquareVo(entry.getKey(), entry.getValue(), refMap, medalMap))
|
||||
.map(entry -> buildSquareVo(entry.getKey(), entry.getValue(), refMap, medalMap, null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public MedalSeriesMineVo mine(Long uid, Integer type, Integer pageNo, Integer pageSize) {
|
||||
MedalSeriesMineVo mineVo = new MedalSeriesMineVo();
|
||||
List<MedalSeriesSquareVo> medalSeries = new ArrayList<>();
|
||||
mineVo.setMedalSeries(medalSeries);
|
||||
mineVo.setUseMedals(mineUse(uid));
|
||||
|
||||
Users users = usersService.getUsersByUid(uid);
|
||||
mineVo.setNick(users.getNick());
|
||||
mineVo.setAvatar(users.getAvatar());
|
||||
mineVo.setErbanNo(users.getErbanNo());
|
||||
mineVo.setUid(uid);
|
||||
|
||||
List<UserMedal> userMedals = userMedalService.listValidMedal(uid, -1, -1);
|
||||
if (CollectionUtils.isEmpty(userMedals)) {
|
||||
return mineVo;
|
||||
}
|
||||
|
||||
mineVo.setMedalNum(userMedalService.countValidMedal(uid));
|
||||
|
||||
Map<Integer, UserMedal> selfMedalMap = userMedals.stream()
|
||||
.collect(Collectors.toMap(UserMedal::getMedalId, x -> x));
|
||||
|
||||
List<Integer> medalIds = userMedals.stream()
|
||||
.map(UserMedal::getMedalId)
|
||||
.collect(Collectors.toList());
|
||||
List<MedalSeriesRef> seriesRefs = medalSeriesRefService.listByMedalIds(medalIds);
|
||||
|
||||
if (CollectionUtils.isEmpty(seriesRefs)) {
|
||||
return mineVo;
|
||||
}
|
||||
|
||||
List<Integer> seriesIds = seriesRefs.stream()
|
||||
.map(MedalSeriesRef::getSeriesId)
|
||||
.collect(Collectors.toList());
|
||||
List<MedalSeries> series = medalSeriesService.listBySeriesIds(seriesIds, type, pageNo, pageSize);
|
||||
|
||||
if (CollectionUtils.isEmpty(series)) {
|
||||
return mineVo;
|
||||
}
|
||||
|
||||
List<MedalSeriesRef> medalSeriesRefs = medalSeriesRefService.listBySeriesIds(seriesIds);
|
||||
if (CollectionUtils.isEmpty(medalSeriesRefs)) {
|
||||
throw new ServiceException(SERIES_CONFIG_ERROR);
|
||||
}
|
||||
List<Integer> allMedalIds = medalSeriesRefs
|
||||
.stream()
|
||||
.map(MedalSeriesRef::getMedalId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, Medal> medalMap = medalService.getMedalMap(allMedalIds);
|
||||
|
||||
Map<Integer, List<MedalSeries>> typeMap = series.stream()
|
||||
.collect(Collectors.groupingBy(MedalSeries::getType));//分类
|
||||
|
||||
Map<Integer, List<MedalSeriesRef>> refMap = medalSeriesRefs.stream()
|
||||
.collect(Collectors.groupingBy(MedalSeriesRef::getSeriesId));//分系列
|
||||
|
||||
medalSeries = typeMap.entrySet().stream()
|
||||
.map(entry -> buildSquareVo(entry.getKey(), entry.getValue(), refMap, medalMap, selfMedalMap))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
mineVo.setMedalSeries(medalSeries);
|
||||
|
||||
return mineVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用的勋章列表
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
public List<MedalSeriesRefVo> mineUse(Long uid) {
|
||||
List<MedalSeriesRefVo> resultList = new ArrayList<>();
|
||||
|
||||
List<UserMedal> userMedals = userMedalService.listUseMedal(uid);
|
||||
if (CollectionUtils.isEmpty(userMedals)) {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
List<Integer> medalIds = userMedals.stream()
|
||||
.map(UserMedal::getMedalId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, Medal> medalMap = medalService.getMedalMap(medalIds);
|
||||
for (UserMedal userMedal : userMedals) {
|
||||
Medal medal = medalMap.get(userMedal.getMedalId());
|
||||
MedalSeriesRefVo vo = new MedalSeriesRefVo();
|
||||
vo.setMedalDesc(medal.getMedalDesc());
|
||||
vo.setMedalId(medal.getId());
|
||||
vo.setPicUrl(medal.getPicUrl());
|
||||
vo.setMp4Url(medal.getMp4Url());
|
||||
vo.setName(medal.getName());
|
||||
vo.setHasGain(Boolean.TRUE);
|
||||
vo.setUseStatus(userMedal.getUseStatus() == 1);
|
||||
vo.setExpireSeconds(DateUtil.between(new Date(), userMedal.getExpireTime(), DateUnit.SECOND, false));
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户全部的的勋章列表
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
public MedalManageVo mineAll(Long uid, Integer pageNo, Integer pageSize) {
|
||||
MedalManageVo medalManageVo = new MedalManageVo();
|
||||
List<MedalSeriesRefVo> allMedals = new ArrayList<>();
|
||||
medalManageVo.setAllMedals(allMedals);
|
||||
medalManageVo.setUseMedals(this.mineUse(uid));
|
||||
medalManageVo.setVipMedalSeatVos(this.vipMedalSeatVos());
|
||||
|
||||
Integer vipLevel = VipUtil.getVipLevel(uid);
|
||||
medalManageVo.setVipLevel(vipLevel);
|
||||
medalManageVo.setMedalNum(userMedalService.countValidMedal(uid));
|
||||
List<UserMedal> userMedals = userMedalService.listValidMedal(uid, pageNo, pageSize);
|
||||
if (CollectionUtils.isEmpty(userMedals)) {
|
||||
return medalManageVo;
|
||||
}
|
||||
List<Integer> medalIds = userMedals.stream()
|
||||
.map(UserMedal::getMedalId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, Medal> medalMap = medalService.getMedalMap(medalIds);
|
||||
for (UserMedal userMedal : userMedals) {
|
||||
Medal medal = medalMap.get(userMedal.getMedalId());
|
||||
MedalSeriesRefVo vo = new MedalSeriesRefVo();
|
||||
vo.setMedalDesc(medal.getMedalDesc());
|
||||
vo.setMedalId(medal.getId());
|
||||
vo.setPicUrl(medal.getPicUrl());
|
||||
vo.setMp4Url(medal.getMp4Url());
|
||||
vo.setName(medal.getName());
|
||||
vo.setHasGain(Boolean.TRUE);
|
||||
vo.setUseStatus(userMedal.getUseStatus() == 1);
|
||||
vo.setExpireSeconds(DateUtil.between(new Date(), userMedal.getExpireTime(), DateUnit.SECOND, false));
|
||||
allMedals.add(vo);
|
||||
}
|
||||
return medalManageVo;
|
||||
}
|
||||
|
||||
public void useMedal(Long uid, Integer id, Byte useStatus) {
|
||||
Integer vipLevel = VipUtil.getVipLevel(uid);
|
||||
String vipAuthItemValue = VipUtil.getVipAuthItemValue(vipLevel, Constant.VipAuthType.MEDAL_SEAT);
|
||||
Integer medalSeatLimit = MEDAL_SEAT_LIMIT;
|
||||
if (StringUtils.isNotEmpty(vipAuthItemValue)) {
|
||||
medalSeatLimit = Integer.valueOf(vipAuthItemValue);
|
||||
}
|
||||
List<UserMedal> userMedals = userMedalService.listUseMedal(uid);
|
||||
if (Constant.StatusV2.valid.equals(useStatus) && medalSeatLimit <= userMedals.size()) {
|
||||
throw new ServiceException(BusiStatus.SERIES_MEDAL_LIMIT);
|
||||
}
|
||||
userMedalService.useMedal(uid, id, useStatus);
|
||||
}
|
||||
|
||||
private MedalSeriesSquareVo buildSquareVo(Integer type,
|
||||
List<MedalSeries> seriesList,
|
||||
Map<Integer, List<MedalSeriesRef>> refMap,
|
||||
Map<Integer, Medal> medalMap) {
|
||||
Map<Integer, Medal> medalMap,
|
||||
Map<Integer, UserMedal> selfMedalMap) {
|
||||
List<MedalSeriesVo> medalSeriesVos = seriesList.stream()
|
||||
.map(series -> buildSeriesVo(series, refMap.get(series.getSeriesId()), medalMap))
|
||||
.map(series -> buildSeriesVo(series, refMap.get(series.getSeriesId()), medalMap, selfMedalMap))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -96,13 +255,14 @@ public class MedalSeriesSquareService {
|
||||
|
||||
private MedalSeriesVo buildSeriesVo(MedalSeries series,
|
||||
List<MedalSeriesRef> seriesRefs,
|
||||
Map<Integer, Medal> medalMap) {
|
||||
Map<Integer, Medal> medalMap,
|
||||
Map<Integer, UserMedal> selfMedalMap) {
|
||||
if (CollectionUtils.isEmpty(seriesRefs)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<MedalSeriesRefVo> medalVos = seriesRefs.stream()
|
||||
.map(ref -> buildMedalVo(ref, medalMap.get(ref.getMedalId())))
|
||||
.map(ref -> buildMedalVo(ref, medalMap.get(ref.getMedalId()), selfMedalMap))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -117,7 +277,8 @@ public class MedalSeriesSquareService {
|
||||
return medalSeriesVo;
|
||||
}
|
||||
|
||||
private MedalSeriesRefVo buildMedalVo(MedalSeriesRef seriesRef, Medal medal) {
|
||||
private MedalSeriesRefVo buildMedalVo(MedalSeriesRef seriesRef, Medal medal,
|
||||
Map<Integer, UserMedal> selfMedalMap) {
|
||||
if (medal == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -129,9 +290,41 @@ public class MedalSeriesSquareService {
|
||||
vo.setPicUrl(medal.getPicUrl());
|
||||
vo.setMp4Url(medal.getMp4Url());
|
||||
vo.setName(medal.getName());
|
||||
|
||||
Optional.ofNullable(selfMedalMap)
|
||||
.map(map -> map.get(medal.getId()))
|
||||
.ifPresentOrElse(
|
||||
userMedal -> {
|
||||
vo.setHasGain(Boolean.TRUE);
|
||||
vo.setUseStatus(userMedal.getUseStatus() == 1);
|
||||
vo.setExpireSeconds(DateUtil.between(new Date(), userMedal.getExpireTime(), DateUnit.SECOND, false));
|
||||
},
|
||||
() -> {
|
||||
vo.setHasGain(Boolean.FALSE);
|
||||
vo.setUseStatus(Boolean.FALSE);
|
||||
vo.setExpireSeconds(0L);
|
||||
}
|
||||
);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private List<VipMedalSeatVo> vipMedalSeatVos() {
|
||||
List<VipMedalSeatVo> resultList = new ArrayList<>();
|
||||
|
||||
List<VipAuthItem> authItems = vipAuthItemService.listValidItemByAuthType(Constant.VipAuthType.MEDAL_SEAT);
|
||||
if (CollectionUtils.isEmpty(authItems)) {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
for (VipAuthItem authItem : authItems) {
|
||||
resultList.add(VipMedalSeatVo.builder()
|
||||
.medalSeatNum(Integer.valueOf(authItem.getItemValue()))
|
||||
.vipLevel(authItem.getVipLevel())
|
||||
.build());
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
// public final LoadingCache<Integer, List<MedalSeriesSquareVo>> squaresMedal = CacheBuilder.newBuilder()
|
||||
// .maximumSize(8)
|
||||
// .expireAfterWrite(10, TimeUnit.MINUTES) // 设置写入后10分钟过期
|
||||
|
@@ -1,10 +1,15 @@
|
||||
package com.accompany.business.service.medal;
|
||||
|
||||
import com.accompany.business.model.UserMedal;
|
||||
import com.accompany.business.model.medal.Medal;
|
||||
import com.accompany.business.vo.medal.UserDetailMedalVo;
|
||||
import com.accompany.core.vo.BaseMedalVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RList;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
@@ -13,6 +18,14 @@ import java.util.Date;
|
||||
*/
|
||||
public interface UserMedalService extends IService<UserMedal> {
|
||||
|
||||
Long countValidMedal(Long uid);
|
||||
|
||||
List<UserMedal> listValidMedal(Long uid, Integer pageNo, Integer pageSize);
|
||||
|
||||
List<UserMedal> listUseMedal(Long uid);
|
||||
|
||||
List<BaseMedalVo> loadAndCacheMedals(Long uid, Integer medalSeatNum);
|
||||
|
||||
UserDetailMedalVo getUserMedalWithDetail(Long uid);
|
||||
|
||||
void rollback(long uid, int medalId, int days);
|
||||
@@ -22,4 +35,7 @@ public interface UserMedalService extends IService<UserMedal> {
|
||||
|
||||
void sendMedal(long uid, int medalId, Date expireTime,
|
||||
Integer source, String remark, Integer adminId);
|
||||
void useMedal(Long uid, Integer id, Byte useStatus);
|
||||
|
||||
RBucket<String> cacheUseMedal(Long uid);
|
||||
}
|
||||
|
@@ -27,4 +27,11 @@ public class MedalSeriesRefServiceImpl extends ServiceImpl<MedalSeriesRefMapper,
|
||||
.orderByAsc(MedalSeriesRef::getSeriesId, MedalSeriesRef::getLevel);
|
||||
return baseMapper.selectList(refWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MedalSeriesRef> listByMedalIds(List<Integer> medalIds) {
|
||||
LambdaQueryWrapper<MedalSeriesRef> refWrapper = Wrappers.lambdaQuery();
|
||||
refWrapper.in(MedalSeriesRef::getMedalId, medalIds);
|
||||
return baseMapper.selectList(refWrapper);
|
||||
}
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ public class MedalSeriesServiceImpl extends ServiceImpl<MedalSeriesMapper, Medal
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MedalSeries> listBySeriesIds(List<Integer> seriesIds, Integer pageNo, Integer pageSize) {
|
||||
public List<MedalSeries> listBySeriesIds(List<Integer> seriesIds, Integer type, Integer pageNo, Integer pageSize) {
|
||||
LambdaQueryWrapper<MedalSeries> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.select(MedalSeries::getSeriesId,
|
||||
MedalSeries::getMedalLevel,
|
||||
@@ -51,6 +51,7 @@ public class MedalSeriesServiceImpl extends ServiceImpl<MedalSeriesMapper, Medal
|
||||
MedalSeries::getSeq,
|
||||
MedalSeries::getProgress)
|
||||
.in(MedalSeries::getSeriesId, seriesIds)
|
||||
.eq(MedalSeries::getType, type)
|
||||
.eq(MedalSeries::getStatus, Constant.StatusV2.valid)
|
||||
.orderByAsc(MedalSeries::getSeq)
|
||||
.orderByDesc(MedalSeries::getCreateTime);
|
||||
|
@@ -1,25 +1,39 @@
|
||||
package com.accompany.business.service.medal.impl;
|
||||
|
||||
import com.accompany.business.model.medal.Medal;
|
||||
import com.accompany.business.model.UserMedal;
|
||||
import com.accompany.business.model.medal.Medal;
|
||||
import com.accompany.business.mybatismapper.medal.UserMedalMapper;
|
||||
import com.accompany.business.service.medal.MedalRecordService;
|
||||
import com.accompany.business.service.medal.MedalService;
|
||||
import com.accompany.business.service.medal.UserMedalService;
|
||||
import com.accompany.business.vo.medal.UserDetailMedalVo;
|
||||
import com.accompany.business.vo.medal.UserMedalVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.vo.BaseMedalVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RList;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.accompany.business.constant.MedalConstant.RedisKey.user_use_medal;
|
||||
import static java.util.Collections.EMPTY_LIST;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/7/11 15:21
|
||||
@@ -33,14 +47,90 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
||||
private MedalService medalService;
|
||||
@Autowired
|
||||
private MedalRecordService medalRecordService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public UserDetailMedalVo getUserMedalWithDetail(Long uid) {
|
||||
@Override
|
||||
public Long countValidMedal(Long uid) {
|
||||
Date now = new Date();
|
||||
List<UserMedal> userMedals = list(Wrappers.<UserMedal>lambdaQuery()
|
||||
return count(Wrappers.<UserMedal>lambdaQuery()
|
||||
.eq(UserMedal::getUid, uid)
|
||||
.eq(UserMedal::getMedalStatus, Constant.StatusV2.valid)
|
||||
.le(UserMedal::getCreateTime, now)
|
||||
.ge(UserMedal::getExpireTime, now));
|
||||
return buildUserDetailMedalVoV2(uid, userMedals);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserMedal> listValidMedal(Long uid, Integer pageNo, Integer pageSize) {
|
||||
Date now = new Date();
|
||||
return list(new Page<>(pageNo, pageSize, false), Wrappers.<UserMedal>lambdaQuery()
|
||||
.eq(UserMedal::getUid, uid)
|
||||
.eq(UserMedal::getMedalStatus, Constant.StatusV2.valid)
|
||||
.le(UserMedal::getCreateTime, now)
|
||||
.ge(UserMedal::getExpireTime, now));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserMedal> listUseMedal(Long uid) {
|
||||
Date now = new Date();
|
||||
return list(Wrappers.<UserMedal>lambdaQuery()
|
||||
.eq(UserMedal::getUid, uid)
|
||||
.eq(UserMedal::getMedalStatus, Constant.StatusV2.valid)
|
||||
.eq(UserMedal::getUseStatus, Constant.StatusV2.valid)
|
||||
.le(UserMedal::getCreateTime, now)
|
||||
.ge(UserMedal::getExpireTime, now)
|
||||
.orderByDesc(UserMedal::getUseTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseMedalVo> loadAndCacheMedals(Long uid, Integer medalSeatNum) {
|
||||
RBucket<String> cacheUseMedal = this.cacheUseMedal(uid);
|
||||
String s = cacheUseMedal.get();
|
||||
List<BaseMedalVo> baseMedalVos;
|
||||
if (StringUtils.isNotEmpty(s)) {
|
||||
if ("[]".equals(s)) {
|
||||
return EMPTY_LIST;
|
||||
}
|
||||
baseMedalVos = JSONObject.parseObject(s, List.class);
|
||||
} else {
|
||||
List<UserMedal> userMedals = this.listUseMedal(uid);
|
||||
|
||||
if (CollectionUtils.isEmpty(userMedals)) {
|
||||
cacheUseMedal.set("[]", Duration.ofDays(7));
|
||||
return EMPTY_LIST;
|
||||
}
|
||||
|
||||
List<Integer> medalIds = userMedals.stream().map(UserMedal::getMedalId).collect(Collectors.toList());
|
||||
Map<Integer, Medal> medalMap = medalService.getMedalMap(medalIds);
|
||||
baseMedalVos = new ArrayList<>();
|
||||
for (UserMedal userMedal : userMedals) {
|
||||
Medal medal = medalMap.get(userMedal.getMedalId());
|
||||
if (medal == null) {
|
||||
continue;
|
||||
}
|
||||
baseMedalVos.add(BaseMedalVo.builder()
|
||||
.picUrl(medal.getPicUrl())
|
||||
.mp4Url(medal.getMp4Url())
|
||||
.build());
|
||||
}
|
||||
cacheUseMedal.set(JSONObject.toJSONString(baseMedalVos), Duration.ofDays(7));
|
||||
}
|
||||
if (baseMedalVos.size() > medalSeatNum) {
|
||||
return baseMedalVos.subList(0, medalSeatNum);
|
||||
}
|
||||
return baseMedalVos;
|
||||
}
|
||||
|
||||
public UserDetailMedalVo getUserMedalWithDetail(Long uid) {
|
||||
List<UserMedal> userMedals = this.listValidMedal(uid, -1, -1);
|
||||
if (CollectionUtils.isEmpty(userMedals)) {
|
||||
UserDetailMedalVo userDetailMedalVo = new UserDetailMedalVo();
|
||||
userDetailMedalVo.setMedalCount(0);
|
||||
userDetailMedalVo.setUserMedals(Collections.emptyList());
|
||||
return userDetailMedalVo;
|
||||
}
|
||||
// 转换成vo
|
||||
return transUserMedal2Vo(userMedals, uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,23 +192,21 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
||||
sendMedal(uid, medalId, days, source, remark, adminId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新版-用户勋章墙
|
||||
*
|
||||
* @param uid
|
||||
* @param userMedals
|
||||
* @return
|
||||
*/
|
||||
public UserDetailMedalVo buildUserDetailMedalVoV2(Long uid, List<UserMedal> userMedals) {
|
||||
if (CollectionUtils.isEmpty(userMedals)) {
|
||||
UserDetailMedalVo userDetailMedalVo = new UserDetailMedalVo();
|
||||
userDetailMedalVo.setMedalCount(0);
|
||||
userDetailMedalVo.setUserMedals(Collections.emptyList());
|
||||
return userDetailMedalVo;
|
||||
@Override
|
||||
public void useMedal(Long uid, Integer id, Byte useStatus) {
|
||||
UserMedal userMedal = baseMapper.selectById(id);
|
||||
if (userMedal == null) {
|
||||
throw new ServiceException(BusiStatus.SERVERBUSY);
|
||||
}
|
||||
// 转换成vo
|
||||
return transUserMedal2Vo(userMedals, uid);
|
||||
userMedal.setUseStatus(useStatus);
|
||||
userMedal.setUseTime(new Date());
|
||||
baseMapper.updateById(userMedal);
|
||||
this.cacheUseMedal(uid).delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RBucket<String> cacheUseMedal(Long uid) {
|
||||
return redissonClient.getBucket(user_use_medal.getKey(uid));
|
||||
}
|
||||
|
||||
|
||||
@@ -138,6 +226,7 @@ public class UserMedalServiceImpl extends ServiceImpl<UserMedalMapper, UserMedal
|
||||
|
||||
Medal medal = medalMap.get(userMedal.getMedalId());
|
||||
if (null != medal){
|
||||
vo.setMp4Url(medal.getMp4Url());
|
||||
vo.setMedalName(medal.getName());
|
||||
vo.setPicUrl(medal.getPicUrl());
|
||||
vo.setSeq(medal.getSeq());
|
||||
|
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
package com.accompany.business.util;
|
||||
|
||||
import com.accompany.business.constant.MedalConstant;
|
||||
import com.accompany.business.dto.vip.OpenVipConfigDTO;
|
||||
import com.accompany.business.dto.vip.VipMessageConfigDTO;
|
||||
import com.accompany.business.model.Nameplate;
|
||||
@@ -210,7 +211,7 @@ public class VipUtil {
|
||||
//无痕浏览
|
||||
userVipInfoVO.setVisitHide(getAuthItemSwitch(typeMap, Constant.VipAuthType.VISIT_HIDE.byteValue(), uid));
|
||||
|
||||
userVipInfoVO.setMedalSeat(getVipAuthItemIntValue(typeMap, Constant.VipAuthType.MEDAL_SEAT.byteValue()));
|
||||
userVipInfoVO.setMedalSeat(getVipAuthItemIntValue(typeMap, Constant.VipAuthType.MEDAL_SEAT.byteValue(), MedalConstant.MEDAL_SEAT_LIMIT));
|
||||
}
|
||||
UserVipInfo userVipInfo = SpringContextHolder.getBean(UserVipInfoService.class).getValidUserVipInfo(uid);
|
||||
if (null != userVipInfo) {
|
||||
@@ -237,7 +238,7 @@ public class VipUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getVipAuthItemIntValue(Map<Byte, List<VipAuthItem>> typeMap, Byte authType) {
|
||||
public static Integer getVipAuthItemIntValue(Map<Byte, List<VipAuthItem>> typeMap, Byte authType, Integer defaultValud) {
|
||||
List<VipAuthItem> authItems = typeMap.get(authType);
|
||||
return Optional.ofNullable(authItems)
|
||||
.filter(list -> !list.isEmpty())
|
||||
@@ -246,7 +247,7 @@ public class VipUtil {
|
||||
.filter(StringUtils::isNotEmpty)
|
||||
.map(String::trim)
|
||||
.map(Integer::valueOf)
|
||||
.orElse(0);
|
||||
.orElse(defaultValud);
|
||||
}
|
||||
|
||||
public static String getVipAuthItemValue(Integer vipLevel, Byte authType) {
|
||||
|
@@ -2,6 +2,9 @@ package com.accompany.business.controller;
|
||||
|
||||
import com.accompany.business.common.BaseController;
|
||||
import com.accompany.business.service.medal.MedalSeriesSquareService;
|
||||
import com.accompany.business.vo.medal.MedalManageVo;
|
||||
import com.accompany.business.vo.medal.MedalSeriesMineVo;
|
||||
import com.accompany.business.vo.medal.MedalSeriesRefVo;
|
||||
import com.accompany.business.vo.medal.MedalSeriesSquareVo;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -33,9 +36,46 @@ public class MedalSeriesController extends BaseController {
|
||||
})
|
||||
@GetMapping("/square")
|
||||
@ApiOperation(value = "勋章广场", httpMethod = "GET")
|
||||
public BusiResult<List<MedalSeriesSquareVo>> squares(@RequestHeader(PUB_UID) Long uid, Integer type,
|
||||
public BusiResult<List<MedalSeriesSquareVo>> squares(@RequestHeader(PUB_UID) Long uid, @RequestParam Integer type,
|
||||
@RequestParam(defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(defaultValue = "6") Integer pageSize) throws ExecutionException {
|
||||
@RequestParam(defaultValue = "6") Integer pageSize) {
|
||||
return BusiResult.success(medalSeriesSquareService.seriesSquareVos(uid, type, pageNo, pageSize));
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uid", value = "用户uid", required = true),
|
||||
@ApiImplicitParam(name = "type", value = "勋章类型 1任务勋章 活动勋章,3荣耀勋章", required = true),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码", required = true),
|
||||
@ApiImplicitParam(name = "pageSize", value = "页长", required = true)
|
||||
})
|
||||
@GetMapping("/mine")
|
||||
@ApiOperation(value = "我的勋章页面(主/客态通用)", httpMethod = "GET")
|
||||
public BusiResult<MedalSeriesMineVo> mine(@RequestParam Long uid, @RequestParam Integer type,
|
||||
@RequestParam(defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(defaultValue = "6") Integer pageSize) {
|
||||
return BusiResult.success(medalSeriesSquareService.mine(uid, type, pageNo, pageSize));
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码", required = true),
|
||||
@ApiImplicitParam(name = "pageSize", value = "页长", required = true)
|
||||
})
|
||||
@GetMapping("/mineAll")
|
||||
@ApiOperation(value = "勋章佩戴管理弹出来的列表", httpMethod = "GET")
|
||||
public BusiResult<MedalManageVo> mineAll(@RequestHeader(PUB_UID) Long uid,
|
||||
@RequestParam(defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(defaultValue = "6") Integer pageSize) {
|
||||
return BusiResult.success(medalSeriesSquareService.mineAll(uid, pageNo, pageSize));
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "Id", required = true),
|
||||
@ApiImplicitParam(name = "useStatus", value = "1-使用,0-取消使用", required = true)
|
||||
})
|
||||
@GetMapping("/useMedal")
|
||||
@ApiOperation(value = "使用勋章", httpMethod = "GET")
|
||||
public BusiResult<Void> useMedal(@RequestHeader(PUB_UID) Long uid, @RequestParam Integer id, Byte useStatus) {
|
||||
medalSeriesSquareService.useMedal(uid, id, useStatus);
|
||||
return BusiResult.success();
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import com.accompany.business.service.invite.UserInviteCodeService;
|
||||
import com.accompany.business.service.invite.UserInviteRecordService;
|
||||
import com.accompany.business.service.guild.GuildDressUpService;
|
||||
import com.accompany.business.service.label.LabelService;
|
||||
import com.accompany.business.service.medal.UserMedalService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.service.user.*;
|
||||
import com.accompany.business.util.VipUtil;
|
||||
@@ -108,6 +109,8 @@ public class UsersController extends BaseController {
|
||||
private GuildDressUpService guildDressUpService;
|
||||
@Autowired
|
||||
private NameplateMapper nameplateMapper;
|
||||
@Autowired
|
||||
private UserMedalService userMedalService;
|
||||
|
||||
private RateLimiter userGetLimiter = RateLimiter.create(1500);
|
||||
|
||||
@@ -237,6 +240,7 @@ public class UsersController extends BaseController {
|
||||
userVo.setMicCircle(userVipInfo.getMicCircle());
|
||||
userVo.setMicNickColor(userVipInfo.getMicNickColour());
|
||||
}
|
||||
userVo.setMedalsPic(userMedalService.loadAndCacheMedals(uid, userVipInfo.getMedalSeat()));
|
||||
|
||||
// 公会铭牌
|
||||
Long guildNameplateId = guildDressUpService.getNameplateId(uid, userVo.getPartitionId());
|
||||
|
Reference in New Issue
Block a user