mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix:
1.翻页条数限制失败bug 2.消息标记的事务方法重写失效问题
This commit is contained in:
@@ -93,9 +93,8 @@
|
||||
<version>2.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>6.0.1.Final</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.abin.mallchat.common.common.exception;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
@@ -23,6 +24,18 @@ public class GlobalExceptionHandler {
|
||||
return ApiResult.fail(-1, message.substring(0, message.length() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* validation参数校验异常
|
||||
*/
|
||||
@ExceptionHandler(value = BindException.class)
|
||||
public ApiResult bindException(BindException e) {
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
e.getBindingResult().getFieldErrors().forEach(x -> errorMsg.append(x.getField()).append(x.getDefaultMessage()).append(","));
|
||||
String message = errorMsg.toString();
|
||||
log.info("validation parameters error!The reason is:{}", message);
|
||||
return ApiResult.fail(-1, message.substring(0, message.length() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理空指针的异常
|
||||
*/
|
||||
|
||||
@@ -22,11 +22,10 @@ import java.util.List;
|
||||
public class UserBackpackDao extends ServiceImpl<UserBackpackMapper, UserBackpack> {
|
||||
|
||||
public Integer getCountByValidItemId(Long uid, Long itemId) {
|
||||
LambdaQueryWrapper<UserBackpack> wrapper = new QueryWrapper<UserBackpack>().lambda()
|
||||
.eq(UserBackpack::getUid, uid)
|
||||
return lambdaQuery().eq(UserBackpack::getUid, uid)
|
||||
.eq(UserBackpack::getItemId, itemId)
|
||||
.eq(UserBackpack::getStatus, YesOrNoEnum.NO.getStatus());
|
||||
return count(wrapper);
|
||||
.eq(UserBackpack::getStatus, YesOrNoEnum.NO.getStatus())
|
||||
.count();
|
||||
}
|
||||
|
||||
public UserBackpack getFirstValidItem(Long uid, Long itemId) {
|
||||
|
||||
@@ -20,6 +20,7 @@ public enum ItemEnum {
|
||||
LIKE_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
|
||||
REG_TOP10_BADGE(3L, ItemTypeEnum.BADGE, "前十注册徽章"),
|
||||
REG_TOP100_BADGE(4L, ItemTypeEnum.BADGE, "前100注册徽章"),
|
||||
PLANET(5L, ItemTypeEnum.BADGE, "知识星球"),
|
||||
;
|
||||
|
||||
private final Long id;
|
||||
|
||||
@@ -35,11 +35,18 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
|
||||
private ItemCache itemCache;
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
@Autowired
|
||||
private UserBackpackServiceImpl userBackpackService;
|
||||
|
||||
@Override
|
||||
@RedissonLock(key = "#uid", waitTime = 5000)//相同用户会同时发奖,需要排队不能直接拒绝
|
||||
public void acquireItem(Long uid, Long itemId, IdempotentEnum idempotentEnum, String businessId) {
|
||||
//组装幂等号
|
||||
String idempotent = getIdempotent(itemId, idempotentEnum, businessId);
|
||||
userBackpackService.doAcquireItem(uid, itemId, idempotent);
|
||||
}
|
||||
|
||||
@RedissonLock(key = "#idempotent", waitTime = 5000)//相同幂等如果同时发奖,需要排队等上一个执行完,取出之前数据返回
|
||||
public void doAcquireItem(Long uid, Long itemId, String idempotent) {
|
||||
UserBackpack userBackpack = userBackpackDao.getByIdp(idempotent);
|
||||
//幂等检查
|
||||
if (Objects.nonNull(userBackpack)) {
|
||||
|
||||
Reference in New Issue
Block a user