mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
优化
This commit is contained in:
@@ -24,10 +24,6 @@
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis-->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.aspectj.weaver.ast.Test;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
@@ -27,6 +28,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Description: 分布式锁切面
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RedisUtils {
|
||||
private static final ObjectMapper jsonMapper = new ObjectMapper();
|
||||
public RedisTemplate redisTemplate;
|
||||
|
||||
private static StringRedisTemplate stringRedisTemplate;
|
||||
@@ -219,9 +218,24 @@ public class RedisUtils {
|
||||
private static String get(String key) {
|
||||
return key == null ? null : stringRedisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public static boolean set(String key, Object value) {
|
||||
try {
|
||||
stringRedisTemplate.opsForValue().set(key, objToStr(value));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static String getStr(String key) {
|
||||
return get(key,String.class);
|
||||
return get(key, String.class);
|
||||
}
|
||||
|
||||
public static <T> T get(String key, Class<T> tClass) {
|
||||
@@ -239,11 +253,7 @@ public class RedisUtils {
|
||||
}
|
||||
|
||||
public static String objToStr(Object o) {
|
||||
try {
|
||||
return jsonMapper.writeValueAsString(o);
|
||||
} catch (Exception e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
return JsonUtils.toStr(o);
|
||||
}
|
||||
|
||||
public static <T> void mset(Map<String, T> map, long time) {
|
||||
@@ -254,22 +264,7 @@ public class RedisUtils {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public static boolean set(String key, Object value) {
|
||||
try {
|
||||
stringRedisTemplate.opsForValue().set(key, objToStr(value));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 普通缓存放入并设置时间
|
||||
|
||||
@@ -39,7 +39,7 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Override
|
||||
@RedissonLock(key = "#uid")
|
||||
@RedissonLock(key = "#uid",waitTime = 5000)//相同用户会同时发奖,需要排队不能直接拒绝
|
||||
public void acquireItem(Long uid, Long itemId, IdempotentEnum idempotentEnum, String businessId) {
|
||||
String idempotent = getIdempotent(itemId, idempotentEnum, businessId);
|
||||
UserBackpack userBackpack = userBackpackDao.getByIdp(idempotent);
|
||||
@@ -57,6 +57,7 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
|
||||
}
|
||||
//发物品
|
||||
UserBackpack insert = UserBackpack.builder()
|
||||
.uid(uid)
|
||||
.itemId(itemId)
|
||||
.status(YesOrNoEnum.NO.getStatus())
|
||||
.idempotent(idempotent)
|
||||
|
||||
@@ -12,7 +12,7 @@ mybatis-plus:
|
||||
spring:
|
||||
profiles:
|
||||
#运行的环境
|
||||
active: test
|
||||
active: my-prod
|
||||
application:
|
||||
name: mallchat
|
||||
datasource:
|
||||
|
||||
Reference in New Issue
Block a user