每日任务功能时间计算调整
This commit is contained in:
parent
628176078a
commit
8230d69120
@ -49,6 +49,11 @@ public class TaskApprovalEvent implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String day;
|
private String day;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数量
|
||||||
|
*/
|
||||||
|
private Integer quantity;
|
||||||
|
|
||||||
private String imei;
|
private String imei;
|
||||||
private String ip;
|
private String ip;
|
||||||
|
|
||||||
|
|||||||
@ -81,6 +81,7 @@ public class LuckyGiftGiveCmdExe {
|
|||||||
|
|
||||||
taskMqMessage.sendTask(TaskApprovalEvent.builder()
|
taskMqMessage.sendTask(TaskApprovalEvent.builder()
|
||||||
.taskId(8)
|
.taskId(8)
|
||||||
|
.quantity(cmd.getQuantity())
|
||||||
.userId(cmd.getReqUserId())
|
.userId(cmd.getReqUserId())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
|||||||
@ -137,10 +137,14 @@ public class TaskListener implements MessageListener {
|
|||||||
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||||
redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS);
|
redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
|
int result = Integer.parseInt(inc) + 1;
|
||||||
//大于10次发一个消息
|
//大于10次发一个消息
|
||||||
if ("10".equals(inc) || Integer.parseInt(inc) >= 10) {
|
if (result >= 10) {
|
||||||
// 更新任务状态的逻辑 直接更新
|
// 更新任务状态的逻辑 直接更新
|
||||||
updateTaskStatus(eventBody);
|
boolean updated = updateTaskStatus(eventBody);
|
||||||
|
if (updated) {
|
||||||
|
redisService.increment(redisKey, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
redisService.increment(redisKey, 1);
|
redisService.increment(redisKey, 1);
|
||||||
}
|
}
|
||||||
@ -235,11 +239,13 @@ public class TaskListener implements MessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 日常任务 更新任务状态的方法示例
|
// 日常任务 更新任务状态的方法示例
|
||||||
private void updateTaskStatus(TaskApprovalEvent event) {
|
private boolean updateTaskStatus(TaskApprovalEvent event) {
|
||||||
if (taskService.checkTaskStatus(event.getUserId(), Long.valueOf(event.getTaskId()), event.getDay())) {
|
if (taskService.checkTaskStatus(event.getUserId(), Long.valueOf(event.getTaskId()), event.getDay())) {
|
||||||
taskService.updateTaskStatus(1, event.getUserId(), Long.valueOf(event.getTaskId()), event.getDay());
|
taskService.updateTaskStatus(1, event.getUserId(), Long.valueOf(event.getTaskId()), event.getDay());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
log.warn("任务已完成 {}", event);
|
log.warn("任务已完成 {}", event);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTask3(TaskApprovalEvent eventBody) {
|
private void handleTask3(TaskApprovalEvent eventBody) {
|
||||||
@ -249,16 +255,73 @@ public class TaskListener implements MessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleTask8(TaskApprovalEvent eventBody) {
|
private void handleTask8(TaskApprovalEvent eventBody) {
|
||||||
|
log.warn("处理任务-8 发送10个幸运礼物: {}", eventBody);
|
||||||
|
// 增加幸运礼物发送次数(不设置过期时间)
|
||||||
|
String redisKey = "task:lucky-gift:count:" + eventBody.getUserId();
|
||||||
|
String countStr = redisService.getString(redisKey);
|
||||||
|
|
||||||
|
int num = eventBody.getQuantity() == null ? 1 : eventBody.getQuantity();
|
||||||
|
if (StringUtils.isEmpty(countStr)) {
|
||||||
|
redisService.increment(redisKey, num);
|
||||||
|
} else {
|
||||||
|
int result = Integer.parseInt(countStr) + num;
|
||||||
|
// 大于等于10次完成任务
|
||||||
|
if (result >= 10) {
|
||||||
|
// 更新任务状态的逻辑 直接更新
|
||||||
|
boolean updated = updateTaskStatus(eventBody);
|
||||||
|
if (updated) {
|
||||||
|
redisService.increment(redisKey, num);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
redisService.increment(redisKey, num);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTask9(TaskApprovalEvent eventBody) {
|
private void handleTask9(TaskApprovalEvent eventBody) {
|
||||||
|
log.warn("处理任务-9 关注一个用户: {}", eventBody);
|
||||||
|
// 关注用户计数,每日过期
|
||||||
|
String redisKey = "task:follow-user:" + eventBody.getUserId();
|
||||||
|
String countStr = redisService.getString(redisKey);
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(countStr)) {
|
||||||
|
// 计算到凌晨的过期时间(秒)
|
||||||
|
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||||
|
redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS);
|
||||||
|
// 第一次关注就完成任务
|
||||||
|
updateTaskStatus(eventBody);
|
||||||
|
} else {
|
||||||
|
// 已经完成过了
|
||||||
|
if (Integer.parseInt(countStr) >= 1) {
|
||||||
|
updateTaskStatus(eventBody);
|
||||||
|
} else {
|
||||||
|
redisService.increment(redisKey, 1);
|
||||||
|
updateTaskStatus(eventBody);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTask10(TaskApprovalEvent eventBody) {
|
private void handleTask10(TaskApprovalEvent eventBody) {
|
||||||
|
log.warn("处理任务-10 关注一个房间: {}", eventBody);
|
||||||
|
// 关注房间计数,每日过期
|
||||||
|
String redisKey = "task:follow-room:" + eventBody.getUserId();
|
||||||
|
String countStr = redisService.getString(redisKey);
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(countStr)) {
|
||||||
|
// 计算到凌晨的过期时间(秒)
|
||||||
|
long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight();
|
||||||
|
redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS);
|
||||||
|
// 第一次关注就完成任务
|
||||||
|
updateTaskStatus(eventBody);
|
||||||
|
} else {
|
||||||
|
// 已经完成过了
|
||||||
|
if (Integer.parseInt(countStr) >= 1) {
|
||||||
|
updateTaskStatus(eventBody);
|
||||||
|
} else {
|
||||||
|
redisService.increment(redisKey, 1);
|
||||||
|
updateTaskStatus(eventBody);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealRechargeCommission(TaskApprovalEvent eventBody) {
|
private void dealRechargeCommission(TaskApprovalEvent eventBody) {
|
||||||
@ -279,10 +342,14 @@ public class TaskListener implements MessageListener {
|
|||||||
if (StringUtils.isEmpty(inc)) {
|
if (StringUtils.isEmpty(inc)) {
|
||||||
redisService.increment(redisKey, 1);
|
redisService.increment(redisKey, 1);
|
||||||
} else {
|
} else {
|
||||||
|
int result = Integer.parseInt(inc) + 1;
|
||||||
//大于3次完成
|
//大于3次完成
|
||||||
if ("3".equals(inc) || Integer.parseInt(inc) >= 3) {
|
if (result >= 3) {
|
||||||
// 更新任务状态的逻辑 直接更新
|
// 更新任务状态的逻辑 直接更新
|
||||||
updateTaskStatus(eventBody);
|
boolean updated = updateTaskStatus(eventBody);
|
||||||
|
if (updated) {
|
||||||
|
redisService.increment(redisKey, 1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
redisService.increment(redisKey, 1);
|
redisService.increment(redisKey, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.red.circle.other.app.service.task;
|
package com.red.circle.other.app.service.task;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||||
@ -143,6 +144,9 @@ public class TaskServiceImpl implements TaskService {
|
|||||||
public void updateTaskStatus(Integer status, Long userId, Long taskId, String date) {
|
public void updateTaskStatus(Integer status, Long userId, Long taskId, String date) {
|
||||||
UserTaskProgress userTaskProgress = new UserTaskProgress();
|
UserTaskProgress userTaskProgress = new UserTaskProgress();
|
||||||
userTaskProgress.setTaskStatus(status);
|
userTaskProgress.setTaskStatus(status);
|
||||||
|
if (status == 1) {
|
||||||
|
userTaskProgress.setCompletedTime(TimestampUtils.now());
|
||||||
|
}
|
||||||
|
|
||||||
LambdaUpdateWrapper<UserTaskProgress> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<UserTaskProgress> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
updateWrapper.eq(UserTaskProgress::getUserId, userId)
|
updateWrapper.eq(UserTaskProgress::getUserId, userId)
|
||||||
@ -152,8 +156,29 @@ public class TaskServiceImpl implements TaskService {
|
|||||||
if (date != null && !date.isEmpty()) {
|
if (date != null && !date.isEmpty()) {
|
||||||
updateWrapper.eq(UserTaskProgress::getDayString, date);
|
updateWrapper.eq(UserTaskProgress::getDayString, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
userTaskProgressDao.update(userTaskProgress, updateWrapper);
|
List<UserTaskProgress> userTaskProgresses = userTaskProgressDao.selectList(updateWrapper);
|
||||||
|
if (CollectionUtils.isEmpty(userTaskProgresses)) {
|
||||||
|
|
||||||
|
UserTaskProgress progress = new UserTaskProgress();
|
||||||
|
progress.setId(IdWorkerUtils.getId());
|
||||||
|
progress.setUserId(userId);
|
||||||
|
progress.setTaskId(taskId);
|
||||||
|
progress.setIsRewardCollected(0);
|
||||||
|
progress.setTaskStatus(status);
|
||||||
|
progress.setCreateTimestamp(TimestampUtils.now());
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(date)) {
|
||||||
|
progress.setDayString(date);
|
||||||
|
progress.setTaskType(1);
|
||||||
|
} else {
|
||||||
|
progress.setTaskType(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
userTaskProgressDao.insert(progress);
|
||||||
|
} else {
|
||||||
|
userTaskProgressDao.update(userTaskProgress, updateWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user