diff --git a/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/task/TaskApprovalEvent.java b/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/task/TaskApprovalEvent.java index 9ef3435c..b8a91d26 100644 --- a/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/task/TaskApprovalEvent.java +++ b/rc-common-business/common-business-mq/business-mq-model/src/main/java/com/red/circle/mq/business/model/event/task/TaskApprovalEvent.java @@ -49,6 +49,11 @@ public class TaskApprovalEvent implements Serializable { */ private String day; + /** + * 数量 + */ + private Integer quantity; + private String imei; private String ip; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java index 4184676d..1bff6e3b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/LuckyGiftGiveCmdExe.java @@ -81,6 +81,7 @@ public class LuckyGiftGiveCmdExe { taskMqMessage.sendTask(TaskApprovalEvent.builder() .taskId(8) + .quantity(cmd.getQuantity()) .userId(cmd.getReqUserId()) .build()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java index e40c6b51..4229da5a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java @@ -137,10 +137,14 @@ public class TaskListener implements MessageListener { long expireSeconds = DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(); redisService.increment(redisKey, 1, expireSeconds, TimeUnit.SECONDS); } else { + int result = Integer.parseInt(inc) + 1; //大于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); } @@ -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())) { taskService.updateTaskStatus(1, event.getUserId(), Long.valueOf(event.getTaskId()), event.getDay()); + return true; } log.warn("任务已完成 {}", event); + return false; } private void handleTask3(TaskApprovalEvent eventBody) { @@ -249,16 +255,73 @@ public class TaskListener implements MessageListener { } 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) { - - + 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) { - + 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) { @@ -279,10 +342,14 @@ public class TaskListener implements MessageListener { if (StringUtils.isEmpty(inc)) { redisService.increment(redisKey, 1); } else { + int result = Integer.parseInt(inc) + 1; //大于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 { redisService.increment(redisKey, 1); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/task/TaskServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/task/TaskServiceImpl.java index d0aeb566..2a0a101b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/task/TaskServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/task/TaskServiceImpl.java @@ -1,6 +1,7 @@ package com.red.circle.other.app.service.task; 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.update.LambdaUpdateWrapper; 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) { UserTaskProgress userTaskProgress = new UserTaskProgress(); userTaskProgress.setTaskStatus(status); + if (status == 1) { + userTaskProgress.setCompletedTime(TimestampUtils.now()); + } LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(UserTaskProgress::getUserId, userId) @@ -152,8 +156,29 @@ public class TaskServiceImpl implements TaskService { if (date != null && !date.isEmpty()) { updateWrapper.eq(UserTaskProgress::getDayString, date); } - - userTaskProgressDao.update(userTaskProgress, updateWrapper); + + List 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); + } } /**