幸运24-结算
This commit is contained in:
@@ -1388,6 +1388,8 @@ public class Constant {
|
||||
public static final String ROOM_BOSS_MIC_UP_DAY_SEND_LIMIT = "room_bossMic_up_daySend_limit";//房间老板位上麦日贡献值最小限制
|
||||
|
||||
public static final String ROOM_UNIQUE_SWITCH_CONFIG = "room_unique_switch_config";
|
||||
|
||||
public static final String LUCKY_24_SEND_WEEK_RANK_REWARD_CONFIG = "lucky_24_send_week_rank_reward_config";
|
||||
}
|
||||
|
||||
public static class WithDrawStatus {
|
||||
|
@@ -1409,6 +1409,7 @@ public enum RedisKey {
|
||||
|
||||
lucky_24_send_week_rank,
|
||||
lucky_24_record_list,
|
||||
lucky_24_send_week_rank_reward_medal_count,
|
||||
;
|
||||
|
||||
public String getKey() {
|
||||
|
@@ -0,0 +1,14 @@
|
||||
package com.accompany.business.dto.lucky;
|
||||
|
||||
import com.accompany.business.common.dto.RewardDto;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Lucky24SendWeekRankRewardConfig {
|
||||
|
||||
private List<Integer> rankSettlentSizeList;
|
||||
private List<List<RewardDto>> rankRewardList;
|
||||
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
package com.accompany.business.service.lucky.rank;
|
||||
|
||||
import cn.hippo4j.common.toolkit.CollectionUtil;
|
||||
import com.accompany.business.common.constant.RewardTypeEnum;
|
||||
import com.accompany.business.common.dto.RewardDto;
|
||||
import com.accompany.business.common.vo.RewardVo;
|
||||
import com.accompany.business.dto.lucky.Lucky24SendWeekRankRewardConfig;
|
||||
import com.accompany.business.util.RewardUtil;
|
||||
import com.accompany.business.vo.lucky.Lucky24WeekRankItemVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.redisson.api.RMap;
|
||||
import org.redisson.api.RSet;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class Lucky24SendWeekRankRewardService {
|
||||
|
||||
@Autowired
|
||||
private Lucky24SendWeekRankService rankService;
|
||||
@Autowired
|
||||
private SysConfService sysConfService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private RewardUtil rewardUtil;
|
||||
|
||||
public void settlement(Integer partitionId, Date lastWeek, boolean needFlag) {
|
||||
Lucky24SendWeekRankRewardConfig rewardConfig = getConfig();
|
||||
List<Integer> settlementSizes = rewardConfig.getRankSettlentSizeList();
|
||||
if (CollectionUtils.isEmpty(settlementSizes)){
|
||||
return;
|
||||
}
|
||||
|
||||
List<List<RewardDto>> rewardConfigList = rewardConfig.getRankRewardList();
|
||||
if (CollectionUtils.isEmpty(rewardConfigList)){
|
||||
return;
|
||||
}
|
||||
|
||||
long rankSize = settlementSizes.stream().mapToLong(Integer::intValue).max().getAsLong();
|
||||
List<Lucky24WeekRankItemVo> list = rankService.listRankItem(lastWeek, rankSize, partitionId);
|
||||
if (CollectionUtil.isEmpty(list)){
|
||||
return;
|
||||
}
|
||||
|
||||
String rankKey = rankService.getRankKey(lastWeek, partitionId);
|
||||
String sendRewardFlagKey = rankKey + "_send_reward_flag";
|
||||
RSet<String> flagSet = redissonClient.getSet(sendRewardFlagKey);
|
||||
|
||||
int rankIndex = 0;
|
||||
for (Lucky24WeekRankItemVo rankItem: list) {
|
||||
Long uid = rankItem.getUid();
|
||||
|
||||
int ranking = rankIndex + 1;
|
||||
int rewardLevel = settlementSizes.stream().mapToInt(Integer::intValue).filter(level->ranking<=level).min().getAsInt();
|
||||
int rewardIndex = settlementSizes.indexOf(rewardLevel);
|
||||
List<RewardDto> rewards = rewardConfigList.get(rewardIndex);
|
||||
for (RewardDto r: rewards) {
|
||||
String uidRewardKey = uid + "_" + r.getType() + "_" + r.getRefId();
|
||||
if (needFlag && flagSet.contains(uidRewardKey)){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (needFlag){
|
||||
flagSet.add(uidRewardKey);
|
||||
}
|
||||
|
||||
if (RewardTypeEnum.MEDAL.equals(r.getType())){
|
||||
String cacheKey = RedisKey.lucky_24_send_week_rank_reward_medal_count.getKey(uid.toString());
|
||||
RMap<Integer, Integer> countMap = redissonClient.getMap(cacheKey);
|
||||
Integer count = countMap.addAndGet(r.getRefId(), 1);
|
||||
countMap.expire(DateTimeUtil.addMonth(lastWeek, 1).toInstant());
|
||||
if (count <= 1){
|
||||
//new
|
||||
countMap.clear();
|
||||
countMap.fastPut(r.getRefId(), 1);
|
||||
countMap.expire(DateTimeUtil.addMonth(lastWeek, 1).toInstant());
|
||||
} else if (count == 3) {
|
||||
RewardDto special = new RewardDto();
|
||||
BeanUtils.copyProperties(r, special);
|
||||
special.setNum(999);
|
||||
rewardUtil.sendRewardByType(uid, special, uidRewardKey);
|
||||
log.info("[lucky24SendWeekRank] {} 达到第 {} 名 已经连续三次获得 {} 勋章,奖励天数到999天", uid, ranking, r.getRefId());
|
||||
return;
|
||||
} else if (count > 3){
|
||||
log.info("[lucky24SendWeekRank] {} 达到第 {} 名 已经连续超过三次获得 {} 勋章,不发奖励", uid, ranking, r.getRefId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RewardVo rewardVo = rewardUtil.sendRewardByType(uid, r, uidRewardKey);
|
||||
log.info("[lucky24SendWeekRank] {} 达到第 {} 名 获得奖励 {}", uid, ranking, JSON.toJSONString(rewardVo));
|
||||
}
|
||||
|
||||
rankIndex++;
|
||||
}
|
||||
|
||||
Instant expireDateTime = DateTimeUtil.addMonth(lastWeek, 1).toInstant();
|
||||
flagSet.expire(expireDateTime);
|
||||
}
|
||||
|
||||
private Lucky24SendWeekRankRewardConfig getConfig(){
|
||||
String configStr = sysConfService.getSysConfValueById(Constant.SysConfId.LUCKY_24_SEND_WEEK_RANK_REWARD_CONFIG);
|
||||
if (StringUtils.isBlank(configStr)){
|
||||
throw new ServiceException(BusiStatus.ACTIVITY_PARAMETERS_NOT_CONFIGURED);
|
||||
}
|
||||
return JSON.parseObject(configStr, Lucky24SendWeekRankRewardConfig.class);
|
||||
}
|
||||
|
||||
}
|
@@ -10,17 +10,13 @@ import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.lucky.Lucky24WeekFloatingItemVo;
|
||||
import com.accompany.business.vo.lucky.Lucky24WeekRankItemVo;
|
||||
import com.accompany.business.vo.lucky.Lucky24WeekRankVo;
|
||||
import com.accompany.business.vo.room.RoomRankingVo;
|
||||
import com.accompany.common.enums.RedisZSetEnum;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.enumeration.PartitionEnum;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.accompany.core.vo.UserLevelVo;
|
||||
import com.accompany.sharding.model.Lucky24Record;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.redisson.api.RDeque;
|
||||
import org.redisson.api.RList;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,7 +27,6 @@ import java.math.BigDecimal;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -63,8 +58,8 @@ public class Lucky24SendWeekRankService extends AbstractRankService implements I
|
||||
}
|
||||
|
||||
private void addRecord(Lucky24Record record) {
|
||||
RList<Lucky24Record> recordDeque = getRecordList(record.getPartitionId());
|
||||
recordDeque.add(0, record);
|
||||
RList<Lucky24Record> recordList = getRecordList(record.getPartitionId());
|
||||
recordList.add(0, record);
|
||||
//todo 控制队列长度
|
||||
}
|
||||
|
||||
@@ -158,7 +153,7 @@ public class Lucky24SendWeekRankService extends AbstractRankService implements I
|
||||
return rankVo;
|
||||
}
|
||||
|
||||
private List<Lucky24WeekRankItemVo> listRankItem(Date date, Long size, Integer partitionId){
|
||||
public List<Lucky24WeekRankItemVo> listRankItem(Date date, Long size, Integer partitionId){
|
||||
Set<Map<String, Object>> rankSet = getRank(date, null, 0L, size - 1, partitionId);
|
||||
if (CollectionUtil.isEmpty(rankSet)){
|
||||
return Collections.emptyList();
|
||||
@@ -187,8 +182,4 @@ public class Lucky24SendWeekRankService extends AbstractRankService implements I
|
||||
return rankItemList;
|
||||
}
|
||||
|
||||
public void settlement(Integer id, ZonedDateTime hourAgo) {
|
||||
//Date lastWeek = hourAgo;
|
||||
//List<Lucky24WeekRankItemVo> list = listRankItem(lastWeek, 10L, partitionEnum.getId());
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.accompany.business.controller.lucky;
|
||||
|
||||
import com.accompany.business.service.lucky.rank.Lucky24SendWeekRankRewardService;
|
||||
import com.accompany.business.service.lucky.rank.Lucky24SendWeekRankService;
|
||||
import com.accompany.business.service.lucky.rank.LuckyBagWeekRankService;
|
||||
import com.accompany.business.vo.RankDateVo;
|
||||
@@ -18,6 +19,7 @@ import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -33,6 +35,8 @@ public class Lucky24WeekRankController {
|
||||
|
||||
@Autowired
|
||||
private Lucky24SendWeekRankService weekRankService;
|
||||
@Autowired
|
||||
private Lucky24SendWeekRankRewardService rewardService;
|
||||
|
||||
@ApiOperation("获取榜单")
|
||||
@Authorization
|
||||
@@ -52,4 +56,13 @@ public class Lucky24WeekRankController {
|
||||
return BusiResult.success(rankVo);
|
||||
}
|
||||
|
||||
@ApiOperation("结算")
|
||||
@Profile({"dev", "native"})
|
||||
@PostMapping("/settlement")
|
||||
public BusiResult<Void> settlement(Integer partitionId, String date, Boolean needFlag) {
|
||||
Date time = DateTimeUtil.convertStrToDate(date, DateTimeUtil.DEFAULT_DATE_PATTERN);
|
||||
rewardService.settlement(partitionId, time, needFlag);
|
||||
return BusiResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.accompany.scheduler.task.luckyBag;
|
||||
|
||||
import com.accompany.business.service.lucky.rank.Lucky24SendWeekRankRewardService;
|
||||
import com.accompany.business.service.lucky.rank.Lucky24SendWeekRankService;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.model.PartitionInfo;
|
||||
@@ -11,6 +12,8 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -25,7 +28,7 @@ public class Lucky24WeekRankTask {
|
||||
@Resource(name = "bizExecutor")
|
||||
private ThreadPoolExecutor bizExecutor;
|
||||
@Autowired
|
||||
private Lucky24SendWeekRankService service;
|
||||
private Lucky24SendWeekRankRewardService service;
|
||||
|
||||
@Scheduled(cron = "0 1 * * * ? ")
|
||||
public void lucky24WeekRankSettlement() {
|
||||
@@ -40,7 +43,8 @@ public class Lucky24WeekRankTask {
|
||||
continue;
|
||||
}
|
||||
bizExecutor.execute(() -> {
|
||||
service.settlement(partitionInfo.getId(), hourAgo);
|
||||
Date systemHourAgo = DateTimeUtil.converLocalDateTimeToDate(hourAgo.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime());
|
||||
service.settlement(partitionInfo.getId(), systemHourAgo, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user