cpList_fixed
This commit is contained in:
@@ -16,6 +16,7 @@ public enum ActivityH5RedisKey implements BaseRedisKey {
|
||||
activity_qywx_message,//企业微信推送key
|
||||
activity_charge_last_user,//上月最高充值用户
|
||||
activity_reward_sign,//活动奖励发放标识
|
||||
cp_rank_last_send_time,//cp榜单最后送礼时间
|
||||
;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
public class ActivityH5CpRankVo {
|
||||
|
||||
private List<CpUserVo> topCpList;
|
||||
private List<CpUserVo> squareCpList;
|
||||
private List<SquareCpUserVo> squareCpList;
|
||||
private List<CpUserVo> thisWeekCpRank;
|
||||
private CpUserVo myCpRank;
|
||||
private Long endTime;
|
||||
|
||||
@@ -23,4 +23,5 @@ public class CpUserVo {
|
||||
private BigDecimal totalNum;
|
||||
private Integer rank;
|
||||
private String uidAppend;
|
||||
private Long lastSendTime;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.accompany.business.vo.activity.h5;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SquareCpUserVo {
|
||||
private Long beginDate;
|
||||
private Long endDate;
|
||||
private List<CpUserVo> cpUserVos;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public interface ActivityH5AwardRecordService extends IService<ActivityH5AwardRe
|
||||
* @param activitySkipType
|
||||
*/
|
||||
void sendAward(ActivityType activityType,Long uid, Integer level, String date, ActivitySkipType activitySkipType);
|
||||
void sendAwardCheckSend(ActivityType activityType,Long uid, Integer level, String date, ActivitySkipType activitySkipType, Long statusCacheDay);
|
||||
void sendAwardCheckSend(ActivityType activityType, Long uid, Integer level, String date, ActivitySkipType activitySkipType, Long statusCacheDay);
|
||||
void sendAward(ActivityType activityType,Long uid, Integer level, String date, ActivitySkipType activitySkipType,String msg);
|
||||
void delLoopCoinQywxMessage(ActivityType activityType);
|
||||
String getRecitalCoinLoopQywxMessage(ActivityType activityType, Long uid, ActivityH5LevelAward award, Integer level);
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
package com.accompany.business.service.activity.h5;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.accompany.business.constant.activity.ActivityH5RedisKey;
|
||||
import com.accompany.business.constant.activity.ActivitySkipType;
|
||||
import com.accompany.business.constant.activity.ActivityType;
|
||||
import com.accompany.business.model.relation.RelationUser;
|
||||
import com.accompany.business.service.relation.RelationUserService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.activity.h5.ActivityH5CpRankVo;
|
||||
import com.accompany.business.vo.activity.h5.CpUserVo;
|
||||
import com.accompany.business.vo.activity.h5.SquareCpUserVo;
|
||||
import com.accompany.business.vo.relation.RelationUserVO;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.common.utils.NumberUtils;
|
||||
import com.accompany.core.enumeration.PartitionEnum;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.accompany.core.util.StringUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RMap;
|
||||
import org.redisson.api.RScoredSortedSet;
|
||||
import org.redisson.api.RSet;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.client.RedisClient;
|
||||
import org.redisson.client.codec.LongCodec;
|
||||
import org.redisson.client.codec.StringCodec;
|
||||
import org.redisson.client.protocol.ScoredEntry;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -20,9 +33,13 @@ import org.springframework.util.CollectionUtils;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ActivityOfCpService {
|
||||
@@ -32,20 +49,24 @@ public class ActivityOfCpService {
|
||||
@Autowired
|
||||
private ActivityH5AwardRecordService activityH5AwardRecordService;
|
||||
@Autowired
|
||||
private ActivityH5RecordService activityH5RecordService;
|
||||
@Autowired
|
||||
private ActivityRankRuleService activityRankRuleService;
|
||||
@Autowired
|
||||
private RelationUserService relationUserService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
private ActivityType activityType(){
|
||||
return ActivityType.ACTIVITY_CP;
|
||||
}
|
||||
|
||||
public void addTotalNumDate(Long uid, Long reciveUid, Integer partitionId, Double totalNum, String currentDate) {
|
||||
public void testAddTotalNumDate(Long uid, Long reciveUid, Integer partitionId, Double totalNum, String currentDate) {
|
||||
String uidAppend = NumberUtils.appendByAsc(uid, reciveUid);
|
||||
activityRankRuleService.addTotalNum4String(activityType(), uidAppend, totalNum, currentDate, partitionId.toString());
|
||||
//发送第一的横幅 to-do
|
||||
RMap<String, String> lastSendTimeMap = lastSendTimeMap(currentDate);
|
||||
lastSendTimeMap.put(uidAppend, String.valueOf(Calendar.getInstance().getTimeInMillis()));
|
||||
lastSendTimeMap.expire(90, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
public void addTotalNum(Long uid, Long reciveUid, Integer partitionId, Double totalNum) {
|
||||
@@ -53,10 +74,12 @@ public class ActivityOfCpService {
|
||||
ZonedDateTime zonedDateTime = activityRankRuleService.getCurrentZoneDate(partitionId);
|
||||
String currentDate = activityRankRuleService.getCurrentWeekBeginKey(zonedDateTime);
|
||||
activityRankRuleService.addTotalNum4String(activityType(), uidAppend, totalNum, currentDate, partitionId.toString());
|
||||
RMap<String, String> lastSendTimeMap = lastSendTimeMap(currentDate);
|
||||
lastSendTimeMap.put(uidAppend, String.valueOf(zonedDateTime.toInstant().toEpochMilli()));
|
||||
lastSendTimeMap.expire(90, TimeUnit.DAYS);
|
||||
//发送第一的横幅 to-do
|
||||
}
|
||||
|
||||
|
||||
public ActivityH5CpRankVo rank(Long uid) {
|
||||
Users users = userService.getUsersByUid(uid);
|
||||
//获取等级和差值
|
||||
@@ -65,7 +88,7 @@ public class ActivityOfCpService {
|
||||
String currentDate = activityRankRuleService.getCurrentWeekBeginKey(zonedDateTime);
|
||||
|
||||
List<CpUserVo> topCpList = topCpList(zonedDateTime, partitionId, 6);
|
||||
List<CpUserVo> squareCpList = topCpList(zonedDateTime, partitionId, 10);
|
||||
List<SquareCpUserVo> squareCpList = squareCpList(zonedDateTime, partitionId, 10);
|
||||
List<CpUserVo> thisWeekCpRank = thisWeekCpRank(currentDate, partitionId, 29);
|
||||
//获取本轮活动结束时间
|
||||
Long endDate = getEndDate(zonedDateTime).toInstant().toEpochMilli();
|
||||
@@ -85,76 +108,13 @@ public class ActivityOfCpService {
|
||||
return activityRankRuleService.getWeekEndDateTime(dateTime);
|
||||
}
|
||||
|
||||
// public void sendRankAward() {
|
||||
// List<QywxMessageDto> acQywxMessageDtos = new ArrayList<>();
|
||||
// Map<Integer,QywxMessageDto> qywxMessageDtosMap = new HashMap<>();
|
||||
// Map<String,QywxMessageDto> stringQywxMessageDtoMap = new HashMap<>();
|
||||
// for (AreaInfoConstant.Region value : AreaInfoConstant.Region.values()) {
|
||||
// String markByRegion = AreaInfoConstant.Region.getMarkByRegion(value.region);
|
||||
// Byte region = value.region;
|
||||
// Date beginTime = DateTimeUtil.getBeginTimeOfCurrentWeek();
|
||||
// Date startTime = DateTimeUtil.addDays(beginTime, -7);
|
||||
// String startDate = DateTimeUtil.convertShortDate(startTime);
|
||||
// Date endTime = DateTimeUtil.addDays(startTime, 6);
|
||||
// String endDate = DateTimeUtil.convertShortDate(endTime);
|
||||
// List<CpUserVo> weekCpRank = getWeekCpRank(region, startDate);
|
||||
// activityH5AwardRecordService.delQywxMessage(activityType());
|
||||
// for (CpUserVo cpUserVo : weekCpRank) {
|
||||
// activityH5AwardRecordService.sendAward(activityType(), cpUserVo.getLeftUid(), cpUserVo.getRank(),startDate, ActivitySkipType.normal);
|
||||
// activityH5AwardRecordService.sendAward(activityType(), cpUserVo.getRightUid(), cpUserVo.getRank(),startDate, ActivitySkipType.normal);
|
||||
// if (cpUserVo.getRank().equals(1)){
|
||||
// sendThreeMedal(cpUserVo,region,startDate);
|
||||
// }
|
||||
// ActivityH5CpRecord activityH5CpRecord = new ActivityH5CpRecord();
|
||||
// activityH5CpRecord.setLevel(cpUserVo.getRank());
|
||||
// activityH5CpRecord.setRegion(region);
|
||||
// activityH5CpRecord.setStartTime(startDate);
|
||||
// activityH5CpRecord.setEndTime(endDate);
|
||||
// activityH5CpRecord.setDate(startDate);
|
||||
// activityH5CpRecord.setUidAppend(cpUserVo.getUidAppend());
|
||||
// activityH5CpRecord.setType(activityType().getType());
|
||||
// activityH5CpRecordService.save(activityH5CpRecord);
|
||||
//
|
||||
// if (cpUserVo.getRank() >=3){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// List<QywxMessageDto> qywxMessageDtos = activityH5AwardRecordService.getQywxMessageDtos(activityType(), startDate);
|
||||
// for (QywxMessageDto qywxMessageDto : qywxMessageDtos) {
|
||||
//
|
||||
// QywxMessageDto dto = qywxMessageDtosMap.get(qywxMessageDto.getAwardLevel());
|
||||
// if (dto == null){
|
||||
// dto = new QywxMessageDto();
|
||||
// dto.setDesc(qywxMessageDto.getDesc());
|
||||
// dto.setAwardName(qywxMessageDto.getAwardName());
|
||||
// dto.setTitle(qywxMessageDto.getTitle());
|
||||
// dto.setMarkRegion(markByRegion);
|
||||
// dto.setCpErbanNos(qywxMessageDto.getErbanNo() + "");
|
||||
// qywxMessageDtosMap.put(qywxMessageDto.getAwardLevel(), dto);
|
||||
// }else {
|
||||
// dto.setCpErbanNos(dto.getCpErbanNos() + " " + qywxMessageDto.getErbanNo() );
|
||||
// }
|
||||
// stringQywxMessageDtoMap.put(markByRegion,dto);
|
||||
// }
|
||||
// qywxMessageDtosMap = new HashMap<>();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// Collection<QywxMessageDto> values = stringQywxMessageDtoMap.values();
|
||||
//
|
||||
// activityH5AwardRecordService.sendCpQywxMessage(activityType(),values);
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
private List<CpUserVo> topCpList(ZonedDateTime zonedDateTime, Integer partitionId, Integer weekSize) {
|
||||
List<CpUserVo> cpUserVos = new ArrayList<>();
|
||||
while (weekSize > 0) {
|
||||
weekSize--;
|
||||
zonedDateTime = zonedDateTime.minusDays(7);
|
||||
String weekBeginKey = activityRankRuleService.getCurrentWeekBeginKey(zonedDateTime);
|
||||
List<CpUserVo> userVos = thisWeekCpRank(weekBeginKey, partitionId, 1);
|
||||
List<CpUserVo> userVos = thisWeekCpRank(weekBeginKey, partitionId, 0);
|
||||
if (CollectionUtils.isEmpty(userVos)) {
|
||||
continue;
|
||||
}
|
||||
@@ -163,6 +123,31 @@ public class ActivityOfCpService {
|
||||
return cpUserVos;
|
||||
}
|
||||
|
||||
private List<SquareCpUserVo> squareCpList(ZonedDateTime zonedDateTime, Integer partitionId, Integer weekSize) {
|
||||
List<SquareCpUserVo> squareCpUserVos = new ArrayList<>();
|
||||
while (weekSize > 0) {
|
||||
SquareCpUserVo squareCpUserVo = new SquareCpUserVo();
|
||||
List<CpUserVo> cpUserVos = new ArrayList<>();
|
||||
weekSize--;
|
||||
squareCpUserVo.setCpUserVos(cpUserVos);
|
||||
zonedDateTime = zonedDateTime.minusDays(7);
|
||||
squareCpUserVo.setBeginDate(activityRankRuleService.getWeekBeginDateTime(zonedDateTime).toInstant().toEpochMilli());
|
||||
squareCpUserVo.setEndDate(activityRankRuleService.getWeekEndDateTime(zonedDateTime).toInstant().toEpochMilli());
|
||||
String weekBeginKey = activityRankRuleService.getCurrentWeekBeginKey(zonedDateTime);
|
||||
List<CpUserVo> userVos = thisWeekCpRank(weekBeginKey, partitionId, 2);
|
||||
if (CollectionUtils.isEmpty(userVos)) {
|
||||
continue;
|
||||
}
|
||||
cpUserVos.addAll(userVos);
|
||||
squareCpUserVos.add(squareCpUserVo);
|
||||
}
|
||||
return squareCpUserVos;
|
||||
}
|
||||
|
||||
private RMap<String, String> lastSendTimeMap(String currentDate) {
|
||||
return redissonClient.getMap(ActivityH5RedisKey.cp_rank_last_send_time.getKey(currentDate), StringCodec.INSTANCE.INSTANCE);
|
||||
}
|
||||
|
||||
|
||||
private CpUserVo getMyRanking(List<CpUserVo> cpUserVoList, String currentDate, Integer partitionId, Long uid) {
|
||||
List<RelationUser> cpList = relationUserService.getOrgCPList(uid, 1, 1);
|
||||
@@ -199,6 +184,8 @@ public class ActivityOfCpService {
|
||||
if (CollectionUtils.isEmpty(typedTuples)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
RMap<String, String> lastSendTimeMap = lastSendTimeMap(date);
|
||||
Map<String, String> longMap = lastSendTimeMap.readAllMap();
|
||||
List<CpUserVo> cpUserVos = new ArrayList<>();
|
||||
int rank = 1;
|
||||
if (!CollectionUtils.isEmpty(typedTuples)){
|
||||
@@ -209,12 +196,19 @@ public class ActivityOfCpService {
|
||||
if (cpUserVoByUidAppend == null) {
|
||||
continue;
|
||||
}
|
||||
cpUserVoByUidAppend.setRank(rank++);
|
||||
cpUserVoByUidAppend.setTotalNum(BigDecimal.valueOf(score).setScale(2, RoundingMode.HALF_UP));
|
||||
cpUserVoByUidAppend.setUidAppend(uidAppend);
|
||||
Long lastSendTime = Long.valueOf(longMap.getOrDefault(uidAppend, "0"));
|
||||
lastSendTime = lastSendTime == null ? 0L : lastSendTime;
|
||||
cpUserVoByUidAppend.setLastSendTime(lastSendTime);
|
||||
cpUserVos.add(cpUserVoByUidAppend);
|
||||
}
|
||||
addCpRankAvatarAndNick(cpUserVos);
|
||||
cpUserVos.sort(Comparator.comparing(CpUserVo::getTotalNum).reversed().thenComparing(CpUserVo::getLastSendTime));
|
||||
for (CpUserVo cpUserVo : cpUserVos) {
|
||||
cpUserVo.setRank(rank++);
|
||||
cpUserVo.setLastSendTime(null);
|
||||
}
|
||||
}
|
||||
return cpUserVos;
|
||||
}
|
||||
@@ -258,4 +252,26 @@ public class ActivityOfCpService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void task(Date date, PartitionEnum partitionEnum) {
|
||||
try {
|
||||
ZonedDateTime zonedDateTime = DateTimeUtil.convertWithZoneId(date, partitionEnum.getZoneId()).minusDays(7);
|
||||
String format = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
log.info("ActivityOfCpService.task:partitionId:{},date:{},zonedDateTime:{}", partitionEnum.name(), DateUtil.formatDateTime(date), format);
|
||||
String weekBeginKey = activityRankRuleService.getCurrentWeekBeginKey(zonedDateTime);
|
||||
List<CpUserVo> cpUserVos = thisWeekCpRank(weekBeginKey, partitionEnum.getId(), 2);
|
||||
if (CollectionUtils.isEmpty(cpUserVos)) {
|
||||
log.info("ActivityOfCpService.task:emptyList");
|
||||
return;
|
||||
}
|
||||
for (CpUserVo cpUserVo : cpUserVos) {
|
||||
Integer rank = cpUserVo.getRank();
|
||||
activityH5AwardRecordService.sendAwardCheckSend(activityType(), cpUserVo.getLeftUid(), rank, weekBeginKey, ActivitySkipType.normal, activityRankRuleService.expire);
|
||||
activityH5AwardRecordService.sendAwardCheckSend(activityType(), cpUserVo.getRightUid(), rank, weekBeginKey, ActivitySkipType.normal, activityRankRuleService.expire);
|
||||
}
|
||||
log.info("ActivityOfCpService.task:list:{}", JSONObject.toJSONString(cpUserVos));
|
||||
} catch (Exception e) {
|
||||
log.error("ActivityOfCpService.task,e:{}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ActivityRankRuleService {
|
||||
/**
|
||||
* redis key 过期时间 单位天
|
||||
*/
|
||||
private final int expire = 90;
|
||||
public final long expire = 90L;
|
||||
|
||||
|
||||
/**
|
||||
@@ -277,7 +277,7 @@ public class ActivityRankRuleService {
|
||||
*/
|
||||
private List<ActivityH5UserVo> getRankUserVos(ActivityType activityType, Integer limit, String... customKey) {
|
||||
RScoredSortedSet<Long> scoredSortedSet = this.getRankKey(activityType, customKey);
|
||||
Collection<ScoredEntry<Long>> typedTuples = scoredSortedSet.entryRange(0, limit);
|
||||
Collection<ScoredEntry<Long>> typedTuples = scoredSortedSet.entryRangeReversed(0, limit);
|
||||
|
||||
if (CollectionUtils.isEmpty(typedTuples)) {
|
||||
return new ArrayList<>();
|
||||
|
||||
@@ -276,6 +276,7 @@ public class RewardUtil {
|
||||
|
||||
vo.setName(vipInfo.getVipName());
|
||||
vo.setPic(vipInfo.getVipIcon());
|
||||
break;
|
||||
case MEDAL:
|
||||
Medal medal = medalService.getById(refId);
|
||||
if (null == medal){
|
||||
@@ -292,6 +293,7 @@ public class RewardUtil {
|
||||
|
||||
vo.setName(medal.getName());
|
||||
vo.setPic(medal.getPicUrl());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
package com.accompany.business.controller.activity.h5;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.accompany.business.service.activity.h5.ActivityOfCpService;
|
||||
import com.accompany.business.vo.activity.h5.ActivityH5CpRankVo;
|
||||
import com.accompany.core.enumeration.PartitionEnum;
|
||||
import com.accompany.core.vo.BaseResponseVO;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static com.accompany.common.constant.ApplicationConstant.PublicParameters.PUB_UID;
|
||||
|
||||
/**
|
||||
@@ -30,13 +35,13 @@ public class ActivityOfCpController {
|
||||
|
||||
@GetMapping(value = "/cp/add")
|
||||
public BaseResponseVO<Void> addTotalNum(Double goldNum, Long uid, Long reciveUid, Integer partitionId, String yyyymmdd) {
|
||||
activityOfCpService.addTotalNumDate(uid, reciveUid, partitionId, goldNum, yyyymmdd);
|
||||
activityOfCpService.testAddTotalNumDate(uid, reciveUid, partitionId, goldNum, yyyymmdd);
|
||||
return BaseResponseVO.success();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/cp/task")
|
||||
public BaseResponseVO<Void> sendRankAward(String date, Integer partitionId) {
|
||||
activityOfCpService.task(DateUtil.parseDateTime(date), PartitionEnum.getByPartitionId(partitionId));
|
||||
return BaseResponseVO.success();
|
||||
}
|
||||
//
|
||||
// @GetMapping(value = "/cp/task")
|
||||
// public BaseResponseVO<Void> sendRankAward() {
|
||||
// activityOfCpService.sendRankAward();
|
||||
// return BaseResponseVO.success();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.accompany.scheduler.task.activity;
|
||||
|
||||
import com.accompany.business.service.activity.h5.ActivityOfCpService;
|
||||
import com.accompany.core.enumeration.PartitionEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ActivityOfCpTask {
|
||||
|
||||
@Autowired
|
||||
private ActivityOfCpService activityOfCpService;
|
||||
|
||||
@Scheduled(cron = "0 5 0 ? * MON", zone = "Etc/GMT-3")
|
||||
public void taskAbr() {
|
||||
activityOfCpService.task(new Date(), PartitionEnum.ARAB);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 5 0 ? * MON", zone = "Etc/GMT-8")
|
||||
public void taskEC() {
|
||||
activityOfCpService.task(new Date(), PartitionEnum.ENGLISH);
|
||||
activityOfCpService.task(new Date(), PartitionEnum.CHINESS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user