幸运礼物第一次赠送进度不显示调整
This commit is contained in:
parent
770a46b889
commit
ff7e5c04f8
@ -266,21 +266,25 @@ public class TaskListener implements MessageListener {
|
|||||||
|
|
||||||
private void handleTask8(TaskApprovalEvent eventBody) {
|
private void handleTask8(TaskApprovalEvent eventBody) {
|
||||||
log.warn("处理任务-8 发送10个幸运礼物: {}", eventBody);
|
log.warn("处理任务-8 发送10个幸运礼物: {}", eventBody);
|
||||||
// 增加幸运礼物发送次数(不设置过期时间)
|
|
||||||
String redisKey = "task:lucky-gift:count:" + eventBody.getUserId();
|
|
||||||
String countStr = redisService.getString(redisKey);
|
|
||||||
|
|
||||||
|
String redisKey = "task:lucky-gift:count:" + eventBody.getUserId();
|
||||||
int num = eventBody.getQuantity() == null ? 1 : eventBody.getQuantity();
|
int num = eventBody.getQuantity() == null ? 1 : eventBody.getQuantity();
|
||||||
if (StringUtils.isEmpty(countStr)) {
|
|
||||||
|
// 获取当前计数
|
||||||
|
String countStr = redisService.getString(redisKey);
|
||||||
|
int currentCount = StringUtils.isEmpty(countStr) ? 0 : Integer.parseInt(countStr);
|
||||||
|
|
||||||
|
// 计算新的计数值
|
||||||
|
int newCount = currentCount + num;
|
||||||
|
|
||||||
|
// 更新任务进度
|
||||||
|
eventBody.setTargetValue(10);
|
||||||
|
eventBody.setCompleteValue(Math.min(newCount, 10));
|
||||||
|
boolean updated = updateTaskStatus(eventBody);
|
||||||
|
|
||||||
|
// 只有任务状态更新成功才更新 Redis
|
||||||
|
if (updated) {
|
||||||
redisService.increment(redisKey, num);
|
redisService.increment(redisKey, num);
|
||||||
} else {
|
|
||||||
int result = Integer.parseInt(countStr) + num;
|
|
||||||
eventBody.setTargetValue(10);
|
|
||||||
eventBody.setCompleteValue(Math.min(result, 10));
|
|
||||||
boolean updated = updateTaskStatus(eventBody);
|
|
||||||
if (updated) {
|
|
||||||
redisService.increment(redisKey, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user