周星榜-分区隔离合并礼物榜单

This commit is contained in:
khalil
2024-08-28 20:27:49 +08:00
parent e1ecf59175
commit 76b546132b
12 changed files with 199 additions and 269 deletions

View File

@@ -87,6 +87,7 @@ public enum RedisKey {
room_total_rankings, // 房间总榜
week_star_config, // 周星榜配置
week_star_list, // 周星榜列表
week_star_rank, // 周星榜列表
gift_notify_level,
gift_notify_config,

View File

@@ -1,61 +0,0 @@
package com.accompany.business.model;
import com.accompany.common.annotation.ReplaceAppDomain;
public class WeekStar {
private Long erbanNo;
private String nick;
@ReplaceAppDomain
private String avatar;
private long totalCount;
private int seqNo;
private Long uid;
public Long getErbanNo() {
return erbanNo;
}
public void setErbanNo(Long erbanNo) {
this.erbanNo = erbanNo;
}
public String getNick() {
return nick;
}
public void setNick(String nick) {
this.nick = nick;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public long getTotalCount() {
return totalCount;
}
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
}
public int getSeqNo() {
return seqNo;
}
public void setSeqNo(int seqNo) {
this.seqNo = seqNo;
}
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
}

View File

@@ -30,4 +30,6 @@ public class WeekStarConfig {
private String charmAward;
private String levelAward;
private Integer partitionFlag;
}

View File

@@ -1,5 +1,6 @@
package com.accompany.business.vo.activity.weekstar;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.List;
@@ -9,14 +10,13 @@ import java.util.List;
* @since 2020-05-28
* 周星榜数据
*/
@ApiModel
@Data
public class WeekStarParentVo {
private List<WeekStarVo> lastWeekStarList;
private WeekStarVo lastWeekStar;
private List<WeekStarVo> weekStarRankList;
private List<WeekStarAwardVo> award;
private WeekStarVo weekStarRank;
/**
* 本场次结束时间戳

View File

@@ -15,21 +15,25 @@ public interface WeekStarMapper {
/**
* 获取周星榜-豪气榜数据
*
* @param giftIdList
* @param startDate
* @param endDate
* @param partitionId
* @return
*/
List<WeekStarStatis> getWeekStarLevelStatis(@Param("giftIdList") List<Integer> giftIdList, @Param("startDate") Date startDate,
@Param("endDate") Date endDate);
@Param("endDate") Date endDate, @Param("partitionId") Integer partitionId);
/**
* 获取周星榜-魅力榜数据
*
* @param giftIdList
* @param startDate
* @param endDate
* @param partitionId
* @return
*/
List<WeekStarStatis> getWeekStarCharmStatis(@Param("giftIdList") List<Integer> giftIdList, @Param("startDate") Date startDate,
@Param("endDate") Date endDate);
@Param("endDate") Date endDate, @Param("partitionId") Integer partitionId);
}

View File

@@ -40,18 +40,6 @@ public class WeekStarConfigService extends BaseService {
return config;
}
public List<Integer> getCurrentWeekStarGiftIds() {
Date date = Calendar.getInstance().getTime();
Date currentWeek = WeekUtil.getFirstDayOfWeek(date);
String currentKey = DateTimeUtil.convertDate(currentWeek,DateTimeUtil.DEFAULT_DATE_PATTERN_);
WeekStarConfig config = getWeekStarConfig(currentKey);
if (config == null) {
return new ArrayList<>();
}
String giftStr = config.getGiftIdList();
return JSON.parseArray(giftStr,Integer.class);
}
public WeekStarConfig buildWeekStarConfig(String id,Date startDate, Date endDate, String desc, String giftList,
String charmAward, String levelAward){
WeekStarConfig weekStarConfig = new WeekStarConfig();

View File

@@ -3,7 +3,6 @@ package com.accompany.business.service.activity;
import com.accompany.business.constant.activities.WeekStarRankTypeEnum;
import com.accompany.business.message.PrizeEntity;
import com.accompany.business.model.Gift;
import com.accompany.business.model.WeekStarConfig;
import com.accompany.business.mybatismapper.weekstar.WeekStarMapper;
import com.accompany.business.service.prize.PrizeContext;
@@ -17,9 +16,11 @@ import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.common.utils.WeekUtil;
import com.accompany.core.exception.ServiceException;
import com.accompany.core.model.PartitionInfo;
import com.accompany.core.model.Users;
import com.accompany.core.service.base.BaseService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.partition.PartitionInfoService;
import com.accompany.core.util.BeanUtils;
import com.accompany.core.util.StringUtils;
import com.alibaba.fastjson.JSON;
@@ -31,6 +32,10 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.DayOfWeek;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -57,6 +62,8 @@ public class WeekStarService extends BaseService {
private ActivityPackService activityPackService;
@Autowired
private PrizeStrategyFactory prizeStrategyFactory;
@Autowired
private PartitionInfoService partitionInfoService;
/**
* 获取周星榜
@@ -64,26 +71,27 @@ public class WeekStarService extends BaseService {
* @return
*/
public WeekStarParentVo getWeekStarList(Long uid, Byte rankType){
Users users = usersService.getUsersByUid(uid);
if(users == null){
throw new ServiceException(BusiStatus.USERNOTEXISTS);
}
WeekStarParentVo weekStarParentVo = new WeekStarParentVo();
Date date = Calendar.getInstance().getTime();
Date currentWeek = WeekUtil.getFirstDayOfWeek(date);
Date lastWeek = WeekUtil.getFirstDayOfLastWeek(date);
String currentKey = DateTimeUtil.convertDate(currentWeek,DateTimeUtil.DEFAULT_DATE_PATTERN_);
String lastKey = DateTimeUtil.convertDate(lastWeek,DateTimeUtil.DEFAULT_DATE_PATTERN_);
Users u = usersService.getNotNullUsersByUid(uid);
PartitionInfo partitionInfo = partitionInfoService.getById(u.getPartitionId());
String zoneId = null != partitionInfo? partitionInfo.getZoneId(): ZoneId.systemDefault().getId();
ZonedDateTime zdt = DateTimeUtil.getDateTimeByZoneId(zoneId);
ZonedDateTime monday = zdt.with(DayOfWeek.MONDAY);
String currentKey = monday.format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
String lastKey = monday.minusWeeks(1L).format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
WeekStarConfig currentConfig = weekStarConfigService.getWeekStarConfig(currentKey);
WeekStarConfig lastConfig = weekStarConfigService.getWeekStarConfig(lastKey);
WeekStarParentVo weekStarParentVo = new WeekStarParentVo();
//获取上周的礼物排行
weekStarParentVo.setLastWeekStarList(getWeekStarVoList(lastConfig,rankType,users));
weekStarParentVo.setLastWeekStar(getWeekStarVo(lastConfig,false, u.getPartitionId(), rankType, u, zoneId));
//获取本周的礼物排行
weekStarParentVo.setWeekStarRankList(getWeekStarVoList(currentConfig,rankType,users));
weekStarParentVo.setWeekStarRank(getWeekStarVo(currentConfig,true, u.getPartitionId(), rankType, u, zoneId));
//获取奖励(礼物图片包含动态图片,暂时写死)
//weekStarParentVo.setAward(getWeekStarAwardVo(currentConfig,rankType));
//本场次结束时间戳
weekStarParentVo.setEndTime(currentConfig.getEndDate().getTime());
ZonedDateTime endTime = currentConfig.getEndDate().toInstant().atZone(ZoneId.of(zoneId));
weekStarParentVo.setEndTime(endTime.toInstant().getEpochSecond());
return weekStarParentVo;
}
@@ -91,12 +99,14 @@ public class WeekStarService extends BaseService {
* 获取周星榜奖励
* @return
*/
public List<WeekStarAwardList> getWeekStarAward(){
List<WeekStarAwardList> weekStarAwardLists = Lists.newArrayList();
Date date = Calendar.getInstance().getTime();
Date currentWeek = WeekUtil.getFirstDayOfWeek(date);
String currentKey = DateTimeUtil.convertDate(currentWeek,DateTimeUtil.DEFAULT_DATE_PATTERN_);
public List<WeekStarAwardList> getWeekStarAward(Long uid){
Users u = usersService.getNotNullUsersByUid(uid);
PartitionInfo partitionInfo = partitionInfoService.getById(u.getPartitionId());
ZonedDateTime zdt = DateTimeUtil.getDateTimeByZoneId(partitionInfo.getZoneId());
String currentKey = zdt.with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
WeekStarConfig currentConfig = weekStarConfigService.getWeekStarConfig(currentKey);
List<WeekStarAwardList> weekStarAwardLists = Lists.newArrayList();
List<WeekStarRankTypeEnum> rankTypeList = Arrays.asList(WeekStarRankTypeEnum.values());
rankTypeList.stream().forEach(weekStarRankTypeEnum -> {
WeekStarAwardList weekStarAwardList = new WeekStarAwardList();
@@ -110,61 +120,59 @@ public class WeekStarService extends BaseService {
/**
* 赠送周星榜礼物
* @param date
*
* @param partitionIdList
*/
public void sendWeekStarAward(Date date){
Date week = WeekUtil.getFirstDayOfLastWeek(date);
String configId = DateTimeUtil.convertDate(week,DateTimeUtil.DEFAULT_DATE_PATTERN_);
WeekStarConfig config = weekStarConfigService.getWeekStarConfig(configId);
//赠送魅力榜礼物
sendWeekStarAwardByRankType(config,WeekStarRankTypeEnum.CHARM.getValue());
//发送豪气榜礼物
sendWeekStarAwardByRankType(config,WeekStarRankTypeEnum.LEVEL.getValue());
public void sendWeekStarAward(List<Integer> partitionIdList){
for (Integer partitionId : partitionIdList){
PartitionInfo partitionInfo = partitionInfoService.getById(partitionId);
ZonedDateTime now = DateTimeUtil.getDateTimeByZoneId(partitionInfo.getZoneId());
String lastWeekStr = now.with(DayOfWeek.MONDAY).minusWeeks(1L).format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
WeekStarConfig config = weekStarConfigService.getWeekStarConfig(lastWeekStr);
//赠送魅力榜礼物
sendWeekStarAwardByRankType(config,WeekStarRankTypeEnum.CHARM.getValue(),partitionId, partitionInfo.getZoneId());
//发送豪气榜礼物
sendWeekStarAwardByRankType(config,WeekStarRankTypeEnum.LEVEL.getValue(),partitionId, partitionInfo.getZoneId());
}
}
/**
* 获取周星榜各个礼物榜单数据
*
* @param config
* @param rankType
* @param users
* @param zoneId
* @return
*/
private List<WeekStarVo> getWeekStarVoList(WeekStarConfig config, Byte rankType, Users users){
private WeekStarVo getWeekStarVo(WeekStarConfig config, boolean isCurrentWeek, Integer partitionId, Byte rankType, Users users, String zoneId){
if(config == null){
return Lists.newArrayList();
return null;
}
Date date = Calendar.getInstance().getTime();
String giftStr = config.getGiftIdList();
if(StringUtils.isBlank(giftStr)){
throw new ServiceException(BusiStatus.WEEK_STAR_HAS_NO_GIFT);
}
List<Integer> giftIdList = JSON.parseArray(giftStr,Integer.class);
//如果是本周周星榜配置,从数据库获取最新数据
if(date.compareTo(config.getEndDate()) < 0){
return getWeekStarList(giftIdList,rankType,config.getStartDate(),config.getEndDate(),users,20);
}
String weekStarVo = jedisService.hget(RedisKey.week_star_list.getKey(rankType.toString()), config.getId());
if(StringUtils.isNotEmpty(weekStarVo)){
List<WeekStarVo> weekStarVoList = gson.fromJson(weekStarVo, new TypeToken<List<WeekStarVo>>(){}.getType());
// 重新从数据库读取礼物信息
List<Gift> giftList = giftService.getGiftByIdsFromDb(giftIdList);
Map<Integer,Gift> giftMap = giftList.stream().collect(Collectors.toMap(Gift::getGiftId,gift -> gift));
weekStarVoList.stream().forEach(vo -> vo.setGift(giftMap.get(vo.getGift().getGiftId())));
// 设置当前用户排名
for (WeekStarVo vo : weekStarVoList) {
vo.setGift(giftMap.get(vo.getGift().getGiftId()));
List<WeekStarStatis> statisList = vo.getWeekStarRankList();
// 刷新用户的排名信息
if(users != null) {
vo.setMineRank(getRankMineVo(statisList, users));
}
}
return weekStarVoList;
ZonedDateTime startTime = config.getStartDate().toInstant().atZone(ZoneId.of(zoneId));
ZonedDateTime endTime = config.getEndDate().toInstant().atZone(ZoneId.of(zoneId));
//如果是本周周星榜配置,从数据库获取最新数据
if(isCurrentWeek){
return getWeekStar(giftIdList, rankType, partitionId, Date.from(startTime.toInstant()), Date.from(endTime.toInstant()), users,20);
}
List<WeekStarVo> list = getWeekStarList(giftIdList,rankType,config.getStartDate(),config.getEndDate(),users,20);
jedisService.hset(RedisKey.week_star_list.getKey(rankType.toString()), config.getId(), gson.toJson(list));
return list;
String weekStarVoStr = jedisService.hget(RedisKey.week_star_rank.getKey(rankType.toString(), partitionId.toString()), config.getId());
if (StringUtils.isBlank(weekStarVoStr)){
WeekStarVo rank = getWeekStar(giftIdList, rankType, partitionId, Date.from(startTime.toInstant()), Date.from(endTime.toInstant()), users,20);
jedisService.hset(RedisKey.week_star_rank.getKey(rankType.toString()), config.getId(), gson.toJson(rank));
return rank;
}
WeekStarVo weekStarVo = gson.fromJson(weekStarVoStr, new TypeToken<WeekStarVo>(){}.getType());
if (null != users){
weekStarVo.setMineRank(getRankMineVo(weekStarVo.getWeekStarRankList(), users));
}
return weekStarVo;
}
/**
@@ -174,40 +182,25 @@ public class WeekStarService extends BaseService {
* @param endDate
* @return
*/
public List<WeekStarVo> getWeekStarList(List<Integer> giftIdList, Byte rankType, Date beginDate, Date endDate, Users users,
Integer amount){
List<WeekStarVo> weekStarVos = Lists.newArrayList();
List<Gift> giftList = giftService.getGiftByIdsFromDb(giftIdList);
Map<Integer,Gift> giftMap = giftList.stream().collect(Collectors.toMap(Gift::getGiftId,gift -> gift));
List<WeekStarStatis> list;
if(rankType.byteValue() == WeekStarRankTypeEnum.LEVEL.getValue()) {
list = weekStarMapper.getWeekStarLevelStatis(giftIdList, beginDate, endDate);
}else if(rankType.byteValue() == WeekStarRankTypeEnum.CHARM.getValue()){
list = weekStarMapper.getWeekStarCharmStatis(giftIdList, beginDate, endDate);
}else {
throw new ServiceException(BusiStatus.UNKNOWN_RANK_TYPE);
public WeekStarVo getWeekStar(List<Integer> giftIdList, Byte rankType, Integer partitionId, Date beginDate, Date endDate, Users users,
Integer size){
WeekStarVo vo = new WeekStarVo();
List<WeekStarStatis> list = WeekStarRankTypeEnum.LEVEL.getValue() == rankType.byteValue()?
weekStarMapper.getWeekStarLevelStatis(giftIdList, beginDate, endDate, partitionId):
weekStarMapper.getWeekStarCharmStatis(giftIdList, beginDate, endDate, partitionId);
if (CollectionUtils.isEmpty(list)){
return vo;
}
//周星榜数据按礼物分组
Map<Integer,List<WeekStarStatis>> weekStarMap = list.stream().collect(Collectors.groupingBy(WeekStarStatis::getGiftId));
giftIdList.stream().forEach(giftId -> {
WeekStarVo weekStarVo = new WeekStarVo();
weekStarVo.setGift(giftMap.get(giftId));
List<WeekStarStatis> statisList = weekStarMap.get(giftId);
//按照魅力值/豪气值排序(防止分组的时候排序出问题)
if(!CollectionUtils.isEmpty(statisList)) {
statisList = statisList.stream().sorted(Comparator.comparing(WeekStarStatis::getAmount)
.reversed()).collect(Collectors.toList());
}else {
statisList = Lists.newArrayList();
}
//只取前几名
weekStarVo.setWeekStarRankList(statisList.size() > amount ? statisList.subList(0,amount) : statisList);
if(users != null) {
weekStarVo.setMineRank(getRankMineVo(statisList, users));
}
weekStarVos.add(weekStarVo);
});
return weekStarVos;
list = list.stream()
.sorted(Comparator.comparing(WeekStarStatis::getAmount).reversed())
.limit(size).collect(Collectors.toList());
vo.setWeekStarRankList(list);
if(null != users) {
vo.setMineRank(getRankMineVo(list, users));
}
return vo;
}
/**
@@ -277,35 +270,41 @@ public class WeekStarService extends BaseService {
/**
* 赠送不同榜单的周星榜礼物
*
* @param config
* @param rankType
* @param zoneId
*/
private void sendWeekStarAwardByRankType(WeekStarConfig config, Byte rankType){
private void sendWeekStarAwardByRankType(WeekStarConfig config, Byte rankType, Integer partitionId, String zoneId){
String giftStr = config.getGiftIdList();
if(StringUtils.isBlank(giftStr)){
throw new ServiceException(BusiStatus.WEEK_STAR_HAS_NO_GIFT);
}
List<Integer> giftIdList = JSON.parseArray(giftStr,Integer.class);
List<WeekStarVo> weekStarVos = getWeekStarList(giftIdList,rankType,
config.getStartDate(),config.getEndDate(),null,10);
List<Integer> giftIdList = JSON.parseArray(giftStr, Integer.class);
List<WeekStarAwardVo> award = getWeekStarAwardVo(config,rankType);
Map<Integer,List<ActivityPackAwardItem>> itemTypes = award.stream().
collect(Collectors.toMap(WeekStarAwardVo::getLevel, weekStarAwardVo -> weekStarAwardVo.getAwardItems()));
weekStarVos.stream().forEach(weekStarVo -> {
List<WeekStarStatis> weekStarStatis = weekStarVo.getWeekStarRankList();
if(CollectionUtils.isEmpty(weekStarStatis)){
return ;
collect(Collectors.toMap(WeekStarAwardVo::getLevel, WeekStarAwardVo::getAwardItems));
ZonedDateTime startTime = config.getStartDate().toInstant().atZone(ZoneId.of(zoneId));
ZonedDateTime endTime = config.getEndDate().toInstant().atZone(ZoneId.of(zoneId));
WeekStarVo weekStarVo = getWeekStar(giftIdList, rankType, partitionId,
Date.from(startTime.toInstant()), Date.from(endTime.toInstant()), null,10);
if (CollectionUtils.isEmpty(weekStarVo.getWeekStarRankList())){
return;
}
int i = 0;
for (WeekStarStatis rankItem : weekStarVo.getWeekStarRankList()) {
int level = ++i;
if(i > 3 && i < 10){
//第四名到第十名全部发等级四的礼物
level = 4;
}
for(int i= 0; i < weekStarStatis.size(); i++){
int level = i + 1;
if(i > 3 && i < 10){
//第四名到第十名全部发等级四的礼物
level = 4;
}
List<ActivityPackAwardItem> items = itemTypes.get(level);
sendAwardToUsers(weekStarStatis.get(i).getUid(),items);
}
});
List<ActivityPackAwardItem> items = itemTypes.get(level);
sendAwardToUsers(rankItem.getUid(), items);
}
}
/**
@@ -352,18 +351,18 @@ public class WeekStarService extends BaseService {
* 将本周周星榜礼物 与 上周周星榜礼物 关联 并设置魅力榜第一用户昵称 和 豪气榜第一用户昵称
* @return
*/
public List<WeekStarGiftRelationVo> getWeekStarGiftRelationList() {
List<WeekStarGiftRelationVo> vos = new ArrayList<>();
Date date = Calendar.getInstance().getTime();
Date currentWeek = WeekUtil.getFirstDayOfWeek(date);
Date lastWeek = WeekUtil.getFirstDayOfLastWeek(date);
String currentKey = DateTimeUtil.convertDate(currentWeek,DateTimeUtil.DEFAULT_DATE_PATTERN_);
String lastKey = DateTimeUtil.convertDate(lastWeek,DateTimeUtil.DEFAULT_DATE_PATTERN_);
public WeekStarGiftRelationVo getWeekStarGiftRelationList(Integer partitionId, String zoneId) {
WeekStarGiftRelationVo vo = new WeekStarGiftRelationVo();
ZonedDateTime monday = ZonedDateTime.now(ZoneId.of(zoneId)).with(DayOfWeek.MONDAY);
String currentKey = monday.format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
String lastKey = monday.minusWeeks(1L).format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
WeekStarConfig currentConfig = weekStarConfigService.getWeekStarConfig(currentKey);
WeekStarConfig lastConfig = weekStarConfigService.getWeekStarConfig(lastKey);
if (currentConfig == null || lastConfig == null) {
return new ArrayList<>();
return vo;
}
// 获取周星榜的礼物id配置
@@ -371,47 +370,19 @@ public class WeekStarService extends BaseService {
List<Integer> giftIds = JSON.parseArray(currentConfig.getGiftIdList(), Integer.class);
// 周星榜配置为空,则不建立关联关系
if (CollectionUtils.isEmpty(lastGiftIds) || CollectionUtils.isEmpty(giftIds)) {
return new ArrayList<>();
return vo;
}
// 获取上周的周星榜中 魅力榜&豪气榜 第一名的数据
// List<WeekStarVo> charmWeekStarList = getWeekStarList(JSON.parseArray(lastConfig.getGiftIdList(), Integer.class), WeekStarRankTypeEnum.CHARM.getValue(), lastConfig.getStartDate(), lastConfig.getEndDate(), null, 1);
// List<WeekStarVo> levelWeekStarList = getWeekStarList(JSON.parseArray(lastConfig.getGiftIdList(), Integer.class), WeekStarRankTypeEnum.LEVEL.getValue(), lastConfig.getStartDate(), lastConfig.getEndDate(), null, 1);
// 获取上周的周星榜中 魅力榜&豪气榜 前二十名的数据
List<WeekStarVo> charmWeekStarList = getWeekStarVoList(lastConfig, WeekStarRankTypeEnum.CHARM.getValue(), null);
List<WeekStarVo> levelWeekStarList = getWeekStarVoList(lastConfig, WeekStarRankTypeEnum.LEVEL.getValue(), null);
Map<Integer, WeekStarVo> charmWeekStarMap = charmWeekStarList.stream().collect(Collectors.toMap(it -> it.getGift().getGiftId(), a->a));
Map<Integer, WeekStarVo> levelWeekStarMap = levelWeekStarList.stream().collect(Collectors.toMap(it -> it.getGift().getGiftId(), a->a));
WeekStarVo charmWeekStarVo = getWeekStarVo(lastConfig, false, partitionId, WeekStarRankTypeEnum.CHARM.getValue(), null, zoneId);
WeekStarVo levelWeekStarVo = getWeekStarVo(lastConfig, false, partitionId, WeekStarRankTypeEnum.LEVEL.getValue(), null, zoneId);
for (int i=0; i<giftIds.size(); i++) {
WeekStarGiftRelationVo vo = new WeekStarGiftRelationVo();
Integer nowGiftId = giftIds.get(i);
// 避免 上周周星榜的礼物数量 比 本周少 的情况 => 直接返回
if(lastGiftIds.size() < i + 1) {
continue;
}
Integer lastGiftId = lastGiftIds.get(i);
vo.setGiftId(nowGiftId);
vo.setLastGiftId(lastGiftId);
WeekStarVo charmVo = charmWeekStarMap.get(lastGiftId);
WeekStarVo levelVo = levelWeekStarMap.get(lastGiftId);
if (charmVo == null || levelVo == null) {
continue;
}
List<WeekStarStatis> charmRankList = charmVo.getWeekStarRankList();
List<WeekStarStatis> levelRankList = levelVo.getWeekStarRankList();
if ( !CollectionUtils.isEmpty(charmRankList)) {
vo.setFirstCharmRankUser(charmRankList.get(0));
}
if ( !CollectionUtils.isEmpty(levelRankList)) {
vo.setFirstLevelRankUser(levelRankList.get(0));
}
vos.add(vo);
if (null != charmWeekStarVo && !CollectionUtils.isEmpty(charmWeekStarVo.getWeekStarRankList())) {
vo.setFirstCharmRankUser(charmWeekStarVo.getWeekStarRankList().get(0));
}
return vos;
if (null != levelWeekStarVo && !CollectionUtils.isEmpty(levelWeekStarVo.getWeekStarRankList())) {
vo.setFirstLevelRankUser(levelWeekStarVo.getWeekStarRankList().get(0));
}
return vo;
}
}

View File

@@ -93,7 +93,7 @@ public class GiftListService extends BaseService {
public Map<String, List<GiftVo>> listGiftV5(Long uid, Integer partitionId, Long roomUid) {
List<GiftVo> giftVoList = listGiftVoByRoomUid(partitionId, roomUid);
return giftTabService.buildPanel(uid, giftVoList, tabV5List);
return giftTabService.buildPanel(uid, partitionId, giftVoList, tabV5List);
}
public Map<String, List<GiftVo>> listByTabList(Long uid, Integer partitionId, Long roomUid,
@@ -103,6 +103,6 @@ public class GiftListService extends BaseService {
//常驻
tabList.add(Constant.GiftPanelTab.LUCKY_POOL);
return giftTabService.buildPanel(uid, giftVoList, tabList);
return giftTabService.buildPanel(uid, partitionId, giftVoList, tabList);
}
}

View File

@@ -2,6 +2,7 @@ package com.accompany.business.service.gift;
import cn.hutool.core.collection.CollectionUtil;
import com.accompany.business.dto.lucky.SuperLuckyGiftConfig;
import com.accompany.business.model.WeekStarConfig;
import com.accompany.business.service.activity.WeekStarConfigService;
import com.accompany.business.service.activity.WeekStarService;
import com.accompany.business.vo.GiftVo;
@@ -9,6 +10,10 @@ import com.accompany.business.vo.SuperLuckyGiftVo;
import com.accompany.business.vo.WeekStarGiftVo;
import com.accompany.business.vo.activity.weekstar.WeekStarGiftRelationVo;
import com.accompany.common.constant.Constant;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.model.PartitionInfo;
import com.accompany.core.service.partition.PartitionInfoService;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@@ -18,6 +23,10 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.DayOfWeek;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@@ -30,6 +39,7 @@ public class GiftTabService implements InitializingBean {
class UserContext {
private Long uid;
private Locale locale;
private PartitionInfo partitionInfo;
}
@Autowired
@@ -40,13 +50,18 @@ public class GiftTabService implements InitializingBean {
private WeekStarService weekStarService;
@Autowired
private SuperLuckyGiftSendService superLuckyGiftSendService;
@Autowired
private PartitionInfoService partitionInfoService;
private final Map<String, BiFunction<UserContext, List<GiftVo>, List<GiftVo>>> tabFuncMap = new HashMap<>();
public Map<String, List<GiftVo>> buildPanel(Long uid, List<GiftVo> giftVoList, List<String> tabList) {
public Map<String, List<GiftVo>> buildPanel(Long uid, Integer partitionId, List<GiftVo> giftVoList, List<String> tabList) {
PartitionInfo partitionInfo = partitionInfoService.getById(partitionId);
UserContext userContext = new UserContext();
userContext.setUid(uid);
userContext.setLocale(LocaleContextHolder.getLocale());
userContext.setPartitionInfo(partitionInfo);
return tabList.parallelStream().filter(Objects::nonNull).collect(Collectors.toMap(tab -> tab, tab -> {
if (!tabFuncMap.containsKey(tab)) {
@@ -153,29 +168,29 @@ public class GiftTabService implements InitializingBean {
private BiFunction<UserContext, List<GiftVo>, List<GiftVo>> weekStarGiftFunc() {
return (userContext, giftVoList) -> {
List<Integer> giftIds = weekStarConfigService.getCurrentWeekStarGiftIds();
ZonedDateTime week = ZonedDateTime.now().withZoneSameInstant(ZoneId.of(userContext.getPartitionInfo().getZoneId()));
String weekStr = week.with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern(DateTimeUtil.DEFAULT_DATE_PATTERN_));
WeekStarConfig config = weekStarConfigService.getWeekStarConfig(weekStr);
if (config == null) {
return Collections.emptyList();
}
List<Integer> giftIds = JSON.parseArray(config.getGiftIdList(), Integer.class);;
if (CollectionUtils.isEmpty(giftIds)) {
return Collections.emptyList();
}
List<GiftVo> weekStarGiftVos = giftVoList.stream()
.filter(giftVo -> Constant.GiftType.WEEK_STAR_GIFT == giftVo.getGiftType() && giftIds.contains(giftVo.getGiftId()))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(giftVoList)) {
return new ArrayList<>();
if (CollectionUtils.isEmpty(weekStarGiftVos)) {
return Collections.emptyList();
}
List<WeekStarGiftRelationVo> relationList = weekStarService.getWeekStarGiftRelationList();
if (CollectionUtils.isEmpty(relationList)) {
return giftVoList;
}
Map<Integer, WeekStarGiftRelationVo> weekStarGiftRelationMap = relationList.stream().collect(Collectors.toMap(WeekStarGiftRelationVo::getGiftId, a -> a));
WeekStarGiftRelationVo relationVo = weekStarService.getWeekStarGiftRelationList(userContext.getPartitionInfo().getId(), userContext.getPartitionInfo().getZoneId());
return weekStarGiftVos.stream().map(giftVo -> {
WeekStarGiftVo vo = new WeekStarGiftVo();
BeanUtils.copyProperties(giftVo, vo);
WeekStarGiftRelationVo relationVo = weekStarGiftRelationMap.get(giftVo.getGiftId());
if (relationVo != null) {
vo.setLastGiftId(relationVo.getLastGiftId());
vo.setFirstCharmRankUser(relationVo.getFirstCharmRankUser());
vo.setFirstLevelRankUser(relationVo.getFirstLevelRankUser());
}

View File

@@ -3,26 +3,28 @@
<mapper namespace="com.accompany.business.mybatismapper.weekstar.WeekStarMapper" >
<select id="getWeekStarLevelStatis" resultType="com.accompany.business.vo.activity.weekstar.WeekStarStatis" >
select gsr.gift_id as giftId, gsr.uid as uid, u.erban_no as erbanNo, u.nick as nick, u.avatar as avatar,
select gsr.uid as uid, u.erban_no as erbanNo, u.nick as nick, u.avatar as avatar,
sum(gsr.total_gold_num) as amount from gift_send_record gsr
left join users u on u.uid = gsr.uid
where gsr.gift_id in
where gsr.create_time BETWEEN #{startDate} and #{endDate}
and gsr.gift_id in
<foreach collection="giftIdList" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
and gsr.create_time BETWEEN #{startDate} and #{endDate}
GROUP BY gsr.gift_id,gsr.uid ORDER BY gsr.gift_id, sum(gsr.total_gold_num) desc
and u.partition_id = #{partitionId}
GROUP BY gsr.uid
</select>
<select id="getWeekStarCharmStatis" resultType="com.accompany.business.vo.activity.weekstar.WeekStarStatis" >
select gsr.gift_id as giftId, gsr.recive_uid as uid, u.erban_no as erbanNo, u.nick as nick, u.avatar as avatar,
select gsr.recive_uid as uid, u.erban_no as erbanNo, u.nick as nick, u.avatar as avatar,
sum(gsr.total_gold_num) as amount from gift_send_record gsr
left join users u on u.uid = gsr.recive_uid
where gsr.gift_id in
where gsr.create_time BETWEEN #{startDate} and #{endDate}
and gsr.gift_id in
<foreach collection="giftIdList" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
and gsr.create_time BETWEEN #{startDate} and #{endDate}
GROUP BY gsr.gift_id,gsr.recive_uid ORDER BY gsr.gift_id, sum(gsr.total_gold_num) desc
and u.partition_id = #{partitionId}
GROUP BY gsr.recive_uid
</select>
</mapper>

View File

@@ -3,10 +3,13 @@ package com.accompany.business.controller.activity;
import com.accompany.business.common.BaseController;
import com.accompany.business.service.activity.WeekStarService;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.activity.weekstar.WeekStarAwardList;
import com.accompany.business.vo.activity.weekstar.WeekStarParentVo;
import com.accompany.common.annotation.Authorization;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.base.UidContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -14,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
* @Author yuanyi
@@ -26,30 +30,24 @@ import java.util.Date;
public class WeekStarController extends BaseController{
@Autowired
UsersService usersService;
@Autowired
WeekStarService weekStarService;
private WeekStarService weekStarService;
@ApiOperation(value = "获取周星榜榜单")
@Authorization
@GetMapping(value = "/getWeekStarList")
public BusiResult getWeekStarList(@RequestParam(value = "uid") Long uid, @RequestParam(value = "rankType") Byte rankType){
return new BusiResult(weekStarService.getWeekStarList(uid,rankType));
public BusiResult<WeekStarParentVo> getWeekStarList(@RequestParam(value = "rankType") Byte rankType){
Long uid = UidContextHolder.get();
WeekStarParentVo vo = weekStarService.getWeekStarList(uid, rankType);
return BusiResult.success(vo);
}
@ApiOperation(value = "获取周星榜奖励列表")
@Authorization
@GetMapping(value = "/getWeekStarAward")
public BusiResult getWeekStarAward(){
return new BusiResult(weekStarService.getWeekStarAward());
public BusiResult<List<WeekStarAwardList>> getWeekStarAward(){
Long uid = UidContextHolder.get();
List<WeekStarAwardList> voList = weekStarService.getWeekStarAward(uid);
return BusiResult.success(voList);
}
@Authorization
@PostMapping(value = "/sendWeekStarAward")
public BusiResult sendWeekStarAward(@RequestParam(value = "date") String date){
Date weekDay = DateTimeUtil.convertStrToDate(date);
weekStarService.sendWeekStarAward(weekDay);
return new BusiResult(BusiStatus.SUCCESS);
}
}

View File

@@ -1,6 +1,7 @@
package com.accompany.scheduler.task.weekstar;
import com.accompany.business.service.activity.WeekStarService;
import com.accompany.core.enumeration.PartitionEnum;
import com.accompany.scheduler.base.BaseTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +10,7 @@ import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @Author: yangming
@@ -28,8 +30,16 @@ public class WeekStarAwardTask extends BaseTask {
@Scheduled(cron = "0 1 0 ? * MON")
public void sendWeekStarAward(){
log.info("send WeekStar Award begin");
Date date = Calendar.getInstance().getTime();
weekStarService.sendWeekStarAward(date);
List<Integer> partitionIdList = List.of(PartitionEnum.ENGLISH.getId(), PartitionEnum.CHINESS.getId());
weekStarService.sendWeekStarAward(partitionIdList);
log.info("send WeekStar Award end");
}
@Scheduled(cron = "0 1 0 ? * MON", zone = "Asia/Riyadh")
public void sendWeekStarAwardArab(){
log.info("send WeekStar Award begin");
List<Integer> partitionIdList = List.of(PartitionEnum.ARAB.getId());
weekStarService.sendWeekStarAward(partitionIdList);
log.info("send WeekStar Award end");
}
}