release- 修复重复获取特殊任务积分bug

release-2024-04-25
pikaqiudeshujia 2 months ago
parent fa60c68b24
commit 0d1c16a3d0

@ -17,6 +17,7 @@ import com.luoo.comment.util.EmojiConverterUtil;
import com.luoo.comment.util.IpUtil; import com.luoo.comment.util.IpUtil;
import com.luoo.comment.util.MySensitiveWordReplaceUtils; import com.luoo.comment.util.MySensitiveWordReplaceUtils;
import constants.Constants; import constants.Constants;
import constants.RabbitmqConstants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import controller.BaseController; import controller.BaseController;
import dto.UserLoginDto; import dto.UserLoginDto;
@ -385,7 +386,7 @@ public class CommentController extends BaseController {
String json = objectMapper.writeValueAsString(userPointLog); String json = objectMapper.writeValueAsString(userPointLog);
System.out.println(json); System.out.println(json);
rabbitTemplate.convertAndSend("pointLog", json); rabbitTemplate.convertAndSend(RabbitmqConstants.POINT_LOG_QUEUE, json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -0,0 +1,22 @@
package constants;/**
* @Author: yawei.huang
* @Package: constants
* @Project: luoo_parent
* @Date: 2024/11/28 8:08
* @Filename: RabbitmqConstants
* @Describe:
*/
/**
* @program: luoo_parent
*
* @description:
*
* @author: yawei.huang
*
* @create: 2024-11-28 08:08
**/
public class RabbitmqConstants {
public static final String POINT_LOG_QUEUE = "pointLog_test";
}

@ -6,6 +6,7 @@ import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.service.InvitationService; import com.luoo.user.service.InvitationService;
import com.luoo.user.service.SignService; import com.luoo.user.service.SignService;
import com.luoo.user.util.DistributedLock; import com.luoo.user.util.DistributedLock;
import constants.RabbitmqConstants;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitHandler;
@ -23,7 +24,7 @@ import java.io.IOException;
* @create: 2024-07-24 13:05 * @create: 2024-07-24 13:05
**/ **/
@Component @Component
@RabbitListener(queues = "pointLog") @RabbitListener(queues = RabbitmqConstants.POINT_LOG_QUEUE)
@Slf4j @Slf4j
public class PointLogListener { public class PointLogListener {
@ -51,7 +52,6 @@ public class PointLogListener {
String key = "pointLog:"; String key = "pointLog:";
distributedLock.unlock(key);
if (distributedLock.tryLock(key, "1")) { if (distributedLock.tryLock(key, "1")) {
try { try {
// 执行需要加锁的业务逻辑 // 执行需要加锁的业务逻辑
@ -71,7 +71,7 @@ public class PointLogListener {
} }
} else { } else {
// 获取锁失败,处理相应逻辑 // 获取锁失败,处理相应逻辑
rabbitTemplate.convertAndSend("pointLog", json); rabbitTemplate.convertAndSend(RabbitmqConstants.POINT_LOG_QUEUE, json);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

@ -129,36 +129,36 @@ public class InvitationService {
Integer score = 0; Integer score = 0;
List<UserPointLog> list = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> list = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
userId, TaskPointIdConstants.NEW_USER_INVITE); userId, TaskPointIdConstants.NEW_USER_INVITE);
if (list.size() >= 3 - 1) { if (list.size() >= 3) {
String inviteUserId3 = TaskPointIdConstants.INVITE_USER_3; String inviteUserId3 = TaskPointIdConstants.INVITE_USER_3;
TaskPoint inviteUser3TaskPoint = taskPointDao.findById(inviteUserId3).get(); TaskPoint inviteUser3TaskPoint = taskPointDao.findById(inviteUserId3).get();
// 邀请人数 >= 3人并且没有获得对应的积分 // 邀请人数 >= 3人并且没有获得对应的积分
List<UserPointLog> userPointLogsByUserIdAndTaskPointId3 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> userPointLogsByUserIdAndTaskPointId3 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.INVITE_USER_3, userId); userId, TaskPointIdConstants.INVITE_USER_3);
score += doMulInvitation(userId, inviteUser3TaskPoint, userPointLogsByUserIdAndTaskPointId3); score += doMulInvitation(userId, inviteUser3TaskPoint, userPointLogsByUserIdAndTaskPointId3);
} }
if (list.size() >= 6 - 1) { if (list.size() >= 6) {
String inviteUserId6 = TaskPointIdConstants.INVITE_USER_6; String inviteUserId6 = TaskPointIdConstants.INVITE_USER_6;
TaskPoint inviteUser6TaskPoint = taskPointDao.findById(inviteUserId6).get(); TaskPoint inviteUser6TaskPoint = taskPointDao.findById(inviteUserId6).get();
// 邀请人数 >= 6人并且没有获得对应的积分 // 邀请人数 >= 6人并且没有获得对应的积分
List<UserPointLog> userPointLogsByUserIdAndTaskPointId6 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> userPointLogsByUserIdAndTaskPointId6 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.INVITE_USER_6, userId); userId, TaskPointIdConstants.INVITE_USER_6);
score += doMulInvitation(userId, inviteUser6TaskPoint, userPointLogsByUserIdAndTaskPointId6); score += doMulInvitation(userId, inviteUser6TaskPoint, userPointLogsByUserIdAndTaskPointId6);
} }
if (list.size() >= 10 - 1) { if (list.size() >= 10) {
String inviteUserId10 = TaskPointIdConstants.INVITE_USER_10; String inviteUserId10 = TaskPointIdConstants.INVITE_USER_10;
TaskPoint inviteUser10TaskPoint = taskPointDao.findById(inviteUserId10).get(); TaskPoint inviteUser10TaskPoint = taskPointDao.findById(inviteUserId10).get();
// 邀请人数 >= 10人并且没有获得对应的积分 // 邀请人数 >= 10人并且没有获得对应的积分
List<UserPointLog> userPointLogsByUserIdAndTaskPointId10 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> userPointLogsByUserIdAndTaskPointId10 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.INVITE_USER_10, userId); userId, TaskPointIdConstants.INVITE_USER_10);
score += doMulInvitation(userId, inviteUser10TaskPoint, userPointLogsByUserIdAndTaskPointId10); score += doMulInvitation(userId, inviteUser10TaskPoint, userPointLogsByUserIdAndTaskPointId10);
} }
if (list.size() >= 20 - 1) { if (list.size() >= 20) {
String inviteUserId20 = TaskPointIdConstants.INVITE_USER_20; String inviteUserId20 = TaskPointIdConstants.INVITE_USER_20;
TaskPoint inviteUser20TaskPoint = taskPointDao.findById(inviteUserId20).get(); TaskPoint inviteUser20TaskPoint = taskPointDao.findById(inviteUserId20).get();
// 邀请人数 >= 20人并且没有获得对应的积分 // 邀请人数 >= 20人并且没有获得对应的积分
List<UserPointLog> userPointLogsByUserIdAndTaskPointId20 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> userPointLogsByUserIdAndTaskPointId20 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.INVITE_USER_20, userId); userId, TaskPointIdConstants.INVITE_USER_20);
score += doMulInvitation(userId, inviteUser20TaskPoint, userPointLogsByUserIdAndTaskPointId20); score += doMulInvitation(userId, inviteUser20TaskPoint, userPointLogsByUserIdAndTaskPointId20);
} }
return score; return score;

@ -23,6 +23,7 @@ import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory;
import constants.Constants; import constants.Constants;
import constants.ErrorConstants; import constants.ErrorConstants;
import constants.RabbitmqConstants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.PointEnums; import enums.PointEnums;
@ -369,7 +370,7 @@ public class LotteryService {
String json = objectMapper.writeValueAsString(userPointLog); String json = objectMapper.writeValueAsString(userPointLog);
System.out.println(json); System.out.println(json);
rabbitTemplate.convertAndSend("pointLog", json); rabbitTemplate.convertAndSend(RabbitmqConstants.POINT_LOG_QUEUE, json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -98,7 +98,7 @@ public class SignService {
userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN, 3 - 1); userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN, 3 - 1);
if (daysByUserIdAndTaskPointId3.size() == 3 - 1) { if (daysByUserIdAndTaskPointId3.size() == 3 - 1) {
List<UserPointLog> sign3 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> sign3 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.DAILY_SIGN_3, userPointLog.getUserId()); userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN_3);
if (sign3.isEmpty()) { if (sign3.isEmpty()) {
point += executeMulSign(TaskPointIdConstants.DAILY_SIGN_3, userPointLog.getUserId()); point += executeMulSign(TaskPointIdConstants.DAILY_SIGN_3, userPointLog.getUserId());
} }
@ -109,7 +109,7 @@ public class SignService {
userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN, 7 - 1); userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN, 7 - 1);
if (daysByUserIdAndTaskPointId7.size() == 7 - 1) { if (daysByUserIdAndTaskPointId7.size() == 7 - 1) {
List<UserPointLog> sign7 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> sign7 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.DAILY_SIGN_7, userPointLog.getUserId()); userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN_7);
if (sign7.isEmpty()) { if (sign7.isEmpty()) {
point += executeMulSign(TaskPointIdConstants.DAILY_SIGN_7, userPointLog.getUserId()); point += executeMulSign(TaskPointIdConstants.DAILY_SIGN_7, userPointLog.getUserId());
} }
@ -119,7 +119,7 @@ public class SignService {
userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN, 30 - 1); userPointLog.getUserId(), TaskPointIdConstants.DAILY_SIGN, 30 - 1);
if (daysByUserIdAndTaskPointId30.size() == 30 - 1) { if (daysByUserIdAndTaskPointId30.size() == 30 - 1) {
List<UserPointLog> sign30 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId( List<UserPointLog> sign30 = userPointLogDao.findUserPointLogsByUserIdAndTaskPointId(
TaskPointIdConstants.DAILY_SIGN_30, userPointLog.getUserId()); userPointLog.getUserId(),TaskPointIdConstants.DAILY_SIGN_30);
if (sign30.isEmpty()) { if (sign30.isEmpty()) {
point += executeMulSign(TaskPointIdConstants.DAILY_SIGN_30, userPointLog.getUserId()); point += executeMulSign(TaskPointIdConstants.DAILY_SIGN_30, userPointLog.getUserId());
} }

@ -17,6 +17,7 @@ import com.luoo.user.util.NickNameUtil;
import com.luoo.user.util.NickNameUtil2; import com.luoo.user.util.NickNameUtil2;
import constants.Constants; import constants.Constants;
import constants.ErrorConstants; import constants.ErrorConstants;
import constants.RabbitmqConstants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.*; import enums.*;
@ -303,7 +304,7 @@ public class UserInfoService {
String json = objectMapper.writeValueAsString(userPointLog); String json = objectMapper.writeValueAsString(userPointLog);
System.out.println(json); System.out.println(json);
rabbitTemplate.convertAndSend("pointLog", json); rabbitTemplate.convertAndSend(RabbitmqConstants.POINT_LOG_QUEUE, json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -17,6 +17,7 @@ import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory;
import constants.ErrorConstants; import constants.ErrorConstants;
import constants.RabbitmqConstants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.PointEnums; import enums.PointEnums;
@ -144,7 +145,7 @@ public class UserPointLogService {
String json = objectMapper.writeValueAsString(userPointLog); String json = objectMapper.writeValueAsString(userPointLog);
System.out.println(json); System.out.println(json);
rabbitTemplate.convertAndSend("pointLog", json); rabbitTemplate.convertAndSend(RabbitmqConstants.POINT_LOG_QUEUE, json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -166,7 +167,7 @@ public class UserPointLogService {
String json = objectMapper.writeValueAsString(userPointLog); String json = objectMapper.writeValueAsString(userPointLog);
System.out.println(json); System.out.println(json);
rabbitTemplate.convertAndSend("pointLog", json); rabbitTemplate.convertAndSend(RabbitmqConstants.POINT_LOG_QUEUE, json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save