充值寻宝-积分-按内购与非内购份额计算任务积分
This commit is contained in:
@@ -1464,8 +1464,7 @@ public enum RedisKey {
|
||||
charge_treasure_act_user_cur_score,
|
||||
charge_treasure_act_user_today_charge_gold_num,
|
||||
charge_treasure_act_user_week_charge_gold_num,
|
||||
charge_treasure_act_task_today_process,
|
||||
charge_treasure_act_task_week_process,
|
||||
charge_treasure_act_task_process,
|
||||
|
||||
user_up_mic_time,//用户上麦时间
|
||||
user_day_mic_duration,//用户在麦时长
|
||||
|
@@ -10,7 +10,6 @@ import java.util.List;
|
||||
public class ChargeTreasureActConfig {
|
||||
|
||||
private Integer price;
|
||||
private BigDecimal iapRatio;
|
||||
|
||||
private List<Task> taskList;
|
||||
|
||||
@@ -23,6 +22,7 @@ public class ChargeTreasureActConfig {
|
||||
private Integer listenTaskId;
|
||||
private Integer need;
|
||||
private Integer score;
|
||||
private Integer iapScore;
|
||||
}
|
||||
|
||||
}
|
@@ -20,6 +20,7 @@ public class ChargeTreasureActScoreRecord {
|
||||
@TableField("`desc`")
|
||||
private String desc;
|
||||
private Integer score;
|
||||
private String taskCountMap;
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
|
@@ -39,6 +39,8 @@ public class ChargeTreasureActTaskChargeListener implements ApplicationListener<
|
||||
String channel = chargeRecord.getChannel();
|
||||
Long goldNum = chargeRecord.getTotalGold();
|
||||
Date chargeTime = chargeRecord.getUpdateTime();
|
||||
actService.addChargeGoldNum(uid, channel, goldNum, chargeTime);
|
||||
|
||||
boolean isIap = Constant.ChargeChannel.google_play_billing.equals(channel) || Constant.ChargeChannel.ios_storeKitV2.equals(channel);
|
||||
actService.addChargeGoldNum(uid, isIap, goldNum, chargeTime);
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ public class ChargeTreasureActTaskTransferListener implements ApplicationListene
|
||||
return;
|
||||
}
|
||||
|
||||
actService.addChargeGoldNum(toUid, "rechargeUserTransfer", history.getDiamondNum(), history.getCreateTime());
|
||||
actService.addChargeGoldNum(toUid, false, history.getDiamondNum(), history.getCreateTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ package com.accompany.business.service.activity;
|
||||
import com.accompany.business.common.vo.ActivityRankItemVo;
|
||||
import com.accompany.business.common.vo.RewardVo;
|
||||
import com.accompany.business.dto.activity.ChargeTreasureActConfig;
|
||||
import com.accompany.business.model.activity.ChargeTreasureActDrawRecord;
|
||||
import com.accompany.business.model.activity.ChargeTreasureActScoreRecord;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.activity.*;
|
||||
@@ -19,14 +18,12 @@ import com.accompany.payment.service.RechargeUserService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.ZonedDateTime;
|
||||
@@ -187,7 +184,7 @@ public class ChargeTreasureActService {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void addChargeGoldNum(Long uid, String channel, Long originalGoldNum, Date createTime) {
|
||||
public void addChargeGoldNum(Long uid, boolean isIap, Long goldNum, Date createTime) {
|
||||
ChargeTreasureActConfig config = getConfig();
|
||||
|
||||
Users u = usersService.getNotNullUsersByUid(uid);
|
||||
@@ -197,17 +194,13 @@ public class ChargeTreasureActService {
|
||||
String today = zdt.format(DateTimeUtil.dateFormatter);
|
||||
String monday = zdt.with(DayOfWeek.MONDAY).format(DateTimeUtil.dateFormatter);
|
||||
|
||||
Long goldNum = Constant.ChargeChannel.ios_storeKitV2.equals(channel) || Constant.ChargeChannel.google_play_billing.equals(channel) ?
|
||||
BigDecimal.valueOf(originalGoldNum).multiply(config.getIapRatio()).longValue() : originalGoldNum;
|
||||
|
||||
//todo channel goldNum
|
||||
|
||||
userService.addChargeGoldNum(uid, today, monday, u.getPartitionId(), goldNum);
|
||||
taskService.processTask(config, uid, today, monday, u.getPartitionId(), goldNum);
|
||||
taskService.processTask(config, uid, today, monday, u.getPartitionId(), isIap, goldNum);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void addScore(Long uid, String monday, Integer partitionId, String desc, Integer score) {
|
||||
public void addScore(Long uid, String monday, Integer partitionId, String desc,
|
||||
Integer score, boolean isNoIap, Map<String, Integer> taskCountMap) {
|
||||
userService.addScore(uid, monday, partitionId, score);
|
||||
rankService.addWeekScore(uid, monday, partitionId, score);
|
||||
|
||||
@@ -215,9 +208,10 @@ public class ChargeTreasureActService {
|
||||
record.setUid(uid);
|
||||
record.setMonday(monday);
|
||||
record.setPartitionId(partitionId);
|
||||
record.setType(Constant.status.valid);
|
||||
record.setType(isNoIap? Constant.status.invalid: Constant.status.valid);
|
||||
record.setDesc(desc);
|
||||
record.setScore(score);
|
||||
record.setTaskCountMap(JSON.toJSONString(taskCountMap));
|
||||
record.setCreateTime(new Date());
|
||||
recordService.save(record);
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -29,19 +31,15 @@ public class ChargeTreasureActTaskService {
|
||||
|
||||
public List<ChargeTreasureActTaskVo> listTaskVo(ChargeTreasureActConfig config, Long uid, String today, String monday, Integer partitionId) {
|
||||
List<ChargeTreasureActConfig.Task> taskList = config.getTaskList();
|
||||
Set<String> weekTaskIdSet = taskList.stream().filter(task -> !Constant.status.delete.equals(task.getType())).map(task -> buildTaskId(uid, task.getId(), null)).collect(Collectors.toSet());
|
||||
Set<String> todayTaskIdSet = taskList.stream().filter(task -> Constant.status.delete.equals(task.getType())).map(task -> buildTaskId(uid, task.getId(), today)).collect(Collectors.toSet());
|
||||
|
||||
Map<String, Integer> weekProcessMap = getWeekProcessMap(monday, partitionId).getAll(weekTaskIdSet);
|
||||
Map<String, Integer> todayProcessMap = getTodayProcessMap(monday, partitionId).getAll(todayTaskIdSet);
|
||||
Set<String> taskIdSet = taskList.stream().map(task -> buildTaskId(uid, task, today)).collect(Collectors.toSet());
|
||||
Map<String, Integer> processMap = getProcessMap(monday, partitionId).getAll(taskIdSet);
|
||||
|
||||
return taskList.stream().map(task -> {
|
||||
ChargeTreasureActTaskVo vo = new ChargeTreasureActTaskVo();
|
||||
BeanUtils.copyProperties(task, vo);
|
||||
|
||||
String taskId = Constant.status.delete.equals(task.getType())?
|
||||
buildTaskId(uid, task.getId(), today) :buildTaskId(uid, task.getId(), null);
|
||||
Integer process = (Constant.status.delete.equals(task.getType())? todayProcessMap: weekProcessMap).getOrDefault(taskId, 0);
|
||||
String taskId = buildTaskId(uid, task, today);
|
||||
Integer process = processMap.getOrDefault(taskId, 0);
|
||||
if (process >= task.getNeed()){
|
||||
process = task.getNeed();
|
||||
}
|
||||
@@ -51,31 +49,64 @@ public class ChargeTreasureActTaskService {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void processTask(ChargeTreasureActConfig config, Long uid, String today, String monday, Integer partitionId, Long goldNum){
|
||||
public void processTask(ChargeTreasureActConfig config, Long uid, String today, String monday, Integer partitionId, boolean isIap, Long goldNum){
|
||||
List<ChargeTreasureActConfig.Task> taskList = config.getTaskList();
|
||||
|
||||
RMap<String, Integer> weekProcessCacheMap = getWeekProcessMap(monday, partitionId);
|
||||
RMap<String, Integer> todayProcessCacheMap = getTodayProcessMap(monday, partitionId);
|
||||
RMap<String, Integer> processMap = getProcessMap(monday, partitionId);
|
||||
|
||||
for (ChargeTreasureActConfig.Task task: taskList){
|
||||
//持续后置任务不直接加进度
|
||||
if (Constant.status.valid.equals(task.getType())){
|
||||
continue;
|
||||
}
|
||||
RMap<String, Integer> processMap = Constant.status.delete.equals(task.getType())? todayProcessCacheMap: weekProcessCacheMap;
|
||||
String taskId = Constant.status.delete.equals(task.getType())?
|
||||
buildTaskId(uid, task.getId(), today) :buildTaskId(uid, task.getId(), null);
|
||||
int after = processMap.addAndGet(taskId, goldNum.intValue());
|
||||
int before = after - goldNum.intValue();
|
||||
if (before < task.getNeed() && after >= task.getNeed()){
|
||||
finishTask(config, todayProcessCacheMap, weekProcessCacheMap, uid, today, monday, partitionId, task);
|
||||
String taskCountId = buildTaskCountId(uid, task, today, isIap);
|
||||
int thisAdd = goldNum.intValue();
|
||||
String taskId = buildTaskId(uid, task, today);
|
||||
int after = processMap.addAndGet(taskId, thisAdd);
|
||||
int before = after - thisAdd;
|
||||
|
||||
if (before >= task.getNeed()){
|
||||
continue;
|
||||
} else if (after >= task.getNeed()){
|
||||
thisAdd = task.getNeed() - before;
|
||||
int countBefore = processMap.addAndGet(taskCountId, thisAdd);
|
||||
//todo log
|
||||
|
||||
finishTask(config, processMap, uid, today, monday, partitionId, task);
|
||||
}
|
||||
|
||||
int countBefore = processMap.addAndGet(taskCountId, thisAdd);
|
||||
}
|
||||
}
|
||||
|
||||
private void finishTask(ChargeTreasureActConfig config, RMap<String, Integer> todayProcessCacheMap, RMap<String, Integer> weekProcessCacheMap,
|
||||
private void finishTask(ChargeTreasureActConfig config, RMap<String, Integer> processCacheMap,
|
||||
Long uid, String today, String monday, Integer partitionId, ChargeTreasureActConfig.Task finishTask) {
|
||||
SpringContextHolder.getBean(ChargeTreasureActService.class).addScore(uid, monday, partitionId, finishTask.getDesc(), finishTask.getScore());
|
||||
|
||||
String iapTaskCountId = buildTaskCountId(uid, finishTask, today, true);
|
||||
String noIapTaskCountId = buildTaskCountId(uid, finishTask, today, false);
|
||||
Set<String> taskCountKeySet = Set.of(iapTaskCountId, noIapTaskCountId);
|
||||
|
||||
Map<String, Integer> taskCountMap = processCacheMap.getAll(taskCountKeySet);
|
||||
int iapCount = taskCountMap.getOrDefault(iapTaskCountId, 0);
|
||||
int noIapCount = taskCountMap.getOrDefault(noIapTaskCountId, 0);
|
||||
int totalCount = iapCount + noIapCount;
|
||||
BigDecimal totalCountB = BigDecimal.valueOf(totalCount);
|
||||
BigDecimal iapTaskRatio = iapCount <= 0? BigDecimal.ZERO: BigDecimal.valueOf(iapCount).divide(totalCountB, 2, RoundingMode.DOWN);
|
||||
BigDecimal noIapTaskRatio = noIapCount <= 0? BigDecimal.ZERO: BigDecimal.valueOf(noIapCount).divide(totalCountB, 2, RoundingMode.DOWN);
|
||||
|
||||
int iapScore = iapTaskRatio.multiply(BigDecimal.valueOf(finishTask.getIapScore())).intValue();
|
||||
int noIapScore = noIapTaskRatio.multiply(BigDecimal.valueOf(finishTask.getScore())).intValue();
|
||||
int totalScore = iapScore + noIapScore;
|
||||
|
||||
String iapTaskScoreKey = String.join("_", iapTaskCountId, "score");
|
||||
taskCountMap.put(iapTaskScoreKey, iapCount);
|
||||
String noIapTaskScoreKey = String.join("_", noIapTaskCountId, "score");
|
||||
taskCountMap.put(noIapTaskScoreKey, iapCount);
|
||||
|
||||
boolean isNoIap = noIapScore > 0;
|
||||
|
||||
SpringContextHolder.getBean(ChargeTreasureActService.class).addScore(uid, monday, partitionId, finishTask.getDesc(),
|
||||
totalScore, isNoIap, taskCountMap);
|
||||
|
||||
List<ChargeTreasureActConfig.Task> taskList = config.getTaskList();
|
||||
|
||||
@@ -88,14 +119,14 @@ public class ChargeTreasureActTaskService {
|
||||
continue;
|
||||
}
|
||||
|
||||
String taskId = buildTaskId(uid, task.getId(), null);
|
||||
int taskProcess = weekProcessCacheMap.getOrDefault(taskId, 0);
|
||||
String taskId = buildTaskId(uid, task, null);
|
||||
int taskProcess = processCacheMap.getOrDefault(taskId, 0);
|
||||
|
||||
boolean prevFinish = true;
|
||||
for (int i = 0; i < taskProcess; i++) {
|
||||
String lastToday = DateTimeUtil.convertDate(DateTimeUtil.addDays(DateTimeUtil.convertStrToDate(today, DateTimeUtil.DEFAULT_DATE_PATTERN), -1), DateTimeUtil.DEFAULT_DATE_PATTERN);
|
||||
String prevTaskId = buildTaskId(uid, finishTask.getId(), lastToday);
|
||||
int prevTaskProcess = todayProcessCacheMap.getOrDefault(prevTaskId, 0);
|
||||
String prevTaskId = buildTaskId(uid, finishTask, lastToday);
|
||||
int prevTaskProcess = processCacheMap.getOrDefault(prevTaskId, 0);
|
||||
if (prevTaskProcess < task.getNeed()){
|
||||
//todo log failure
|
||||
prevFinish = false;
|
||||
@@ -108,26 +139,26 @@ public class ChargeTreasureActTaskService {
|
||||
}
|
||||
|
||||
|
||||
int after = weekProcessCacheMap.addAndGet(taskId, 1);
|
||||
int after = processCacheMap.addAndGet(taskId, 1);
|
||||
int before = after - 1;
|
||||
if (before < task.getNeed() && after >= task.getNeed()){
|
||||
finishTask(config, todayProcessCacheMap, weekProcessCacheMap, uid, today, monday, partitionId, task);
|
||||
finishTask(config, processCacheMap, uid, today, monday, partitionId, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String buildTaskId(Long uid, Integer taskId, String today){
|
||||
return StringUtils.isBlank(today)?
|
||||
String.join("_", uid.toString(), taskId.toString()):
|
||||
String.join("_", uid.toString(), taskId.toString(), today);
|
||||
public String buildTaskId(Long uid, ChargeTreasureActConfig.Task task, String today){
|
||||
return !Constant.status.delete.equals(task.getType())?
|
||||
String.join("_", uid.toString(), task.getId().toString()):
|
||||
String.join("_", uid.toString(), task.getId().toString(), today);
|
||||
}
|
||||
|
||||
private RMap<String, Integer> getTodayProcessMap(String monday, Integer partitionId) {
|
||||
return redissonClient.getMap(RedisKey.charge_treasure_act_task_today_process.getKey(monday, partitionId.toString()));
|
||||
public String buildTaskCountId(Long uid, ChargeTreasureActConfig.Task task, String today, Boolean isIap){
|
||||
return String.join("_", buildTaskId(uid, task, today), isIap.toString());
|
||||
}
|
||||
|
||||
private RMap<String, Integer> getWeekProcessMap(String monday, Integer partitionId) {
|
||||
return redissonClient.getMap(RedisKey.charge_treasure_act_task_week_process.getKey(monday, partitionId.toString()));
|
||||
private RMap<String, Integer> getProcessMap(String monday, Integer partitionId) {
|
||||
return redissonClient.getMap(RedisKey.charge_treasure_act_task_process.getKey(monday, partitionId.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user