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:
|
||||
|
||||
@@ -38,7 +38,7 @@ public class UserRegisterListener {
|
||||
@EventListener(classes = UserRegisterEvent.class)
|
||||
public void sendBadge(UserRegisterEvent event) {
|
||||
User user = event.getUser();
|
||||
int count = userDao.count();
|
||||
int count = userDao.count();//todo 性能瓶颈,等注册用户多了直接删掉
|
||||
if (count <= 10) {
|
||||
iUserBackpackService.acquireItem(user.getId(), ItemEnum.REG_TOP10_BADGE.getId(), IdempotentEnum.UID, user.getId().toString());
|
||||
} else if (count <= 100) {
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -30,7 +30,6 @@
|
||||
<hutool.version>5.8.18</hutool.version>
|
||||
<springfox-swagger.version>3.0.0</springfox-swagger.version>
|
||||
<swagger-models.version>1.6.0</swagger-models.version>
|
||||
<swagger-annotations.version>1.6.0</swagger-annotations.version>
|
||||
<mybatis-plus-generator.version>3.4.1</mybatis-plus-generator.version>
|
||||
<mybatis.version>3.5.10</mybatis.version>
|
||||
<mysql-connector.version>8.0.29</mysql-connector.version>
|
||||
@@ -80,11 +79,6 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>
|
||||
<!-- MyBatis-->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
|
||||
Reference in New Issue
Block a user