财富等级缓存处理
This commit is contained in:
parent
174557924d
commit
69329507ca
@ -1,6 +1,7 @@
|
|||||||
package com.red.circle.other.infra.database.cache.service.user;
|
package com.red.circle.other.infra.database.cache.service.user;
|
||||||
|
|
||||||
import com.red.circle.other.domain.model.user.NobleAbilityCO;
|
import com.red.circle.other.domain.model.user.NobleAbilityCO;
|
||||||
|
import com.red.circle.other.infra.database.rds.entity.user.user.ConsumptionLevel;
|
||||||
import com.red.circle.other.inner.enums.material.PropsVipActualEquityEnum;
|
import com.red.circle.other.inner.enums.material.PropsVipActualEquityEnum;
|
||||||
import com.red.circle.other.infra.database.cache.entity.user.ConsumptionLevelCache;
|
import com.red.circle.other.infra.database.cache.entity.user.ConsumptionLevelCache;
|
||||||
import com.red.circle.other.infra.database.cache.key.user.UserHashKey;
|
import com.red.circle.other.infra.database.cache.key.user.UserHashKey;
|
||||||
@ -94,4 +95,9 @@ public interface UserCacheService {
|
|||||||
*/
|
*/
|
||||||
String getSVipIdentity(Long userId, Function<Long, String> orElseGet);
|
String getSVipIdentity(Long userId, Function<Long, String> orElseGet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户缓存
|
||||||
|
*/
|
||||||
|
void removeConsumptionLevel(Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
@ -131,16 +132,21 @@ public class UserCacheServiceImpl implements UserCacheService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConsumptionLevelCache getUserConsumptionLevel(Long userId, Function<Long, ConsumptionLevelCache> orElseGet) {
|
public ConsumptionLevelCache getUserConsumptionLevel(Long userId, Function<Long, ConsumptionLevelCache> orElseGet) {
|
||||||
String key = getUserHashKey(userId);
|
String key = getUserConsumptionKey(userId);
|
||||||
return Optional.ofNullable(redisService.hashGet(key, UserHashKey.CONSUMPTION_LEVEL.name(), ConsumptionLevelCache.class))
|
String cacheValue = redisService.getString(key);
|
||||||
.orElseGet(() -> {
|
return Optional.ofNullable(cacheValue)
|
||||||
ConsumptionLevelCache levelCache = orElseGet.apply(userId);
|
.map(v -> JSON.parseObject(v, ConsumptionLevelCache.class))
|
||||||
if (Objects.nonNull(levelCache)) {
|
.orElseGet(() -> {
|
||||||
redisService
|
ConsumptionLevelCache levelCache = orElseGet.apply(userId);
|
||||||
.hashPut(key, UserHashKey.CONSUMPTION_LEVEL.name(), levelCache, 1L, TimeUnit.MINUTES);
|
if (Objects.nonNull(levelCache)) {
|
||||||
}
|
redisService.setString(key, JSON.toJSONString(levelCache), 1L, TimeUnit.HOURS);
|
||||||
return levelCache;
|
}
|
||||||
});
|
return levelCache;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getUserConsumptionKey(Long userId) {
|
||||||
|
return UserHashKey.CONSUMPTION_LEVEL.name() + ":" + userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -229,6 +235,14 @@ public class UserCacheServiceImpl implements UserCacheService {
|
|||||||
return vipIdentity;
|
return vipIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除用户消费等级缓存
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void removeConsumptionLevel(Long userId) {
|
||||||
|
redisService.delete(getUserConsumptionKey(userId));
|
||||||
|
}
|
||||||
|
|
||||||
private String getUserHashKey(Long userId) {
|
private String getUserHashKey(Long userId) {
|
||||||
return UserKey.HASH.getKey(userId);
|
return UserKey.HASH.getKey(userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
|||||||
import com.red.circle.framework.dto.ResultResponse;
|
import com.red.circle.framework.dto.ResultResponse;
|
||||||
import com.red.circle.mq.business.model.event.task.TaskApprovalEvent;
|
import com.red.circle.mq.business.model.event.task.TaskApprovalEvent;
|
||||||
import com.red.circle.mq.rocket.business.producer.TaskMqMessage;
|
import com.red.circle.mq.rocket.business.producer.TaskMqMessage;
|
||||||
|
import com.red.circle.other.infra.database.cache.service.user.UserCacheService;
|
||||||
import com.red.circle.other.inner.model.dto.user.WealthAndCharmExpLevelDTO;
|
import com.red.circle.other.inner.model.dto.user.WealthAndCharmExpLevelDTO;
|
||||||
import com.red.circle.other.inner.model.dto.user.WealthAndCharmLevelDTO;
|
import com.red.circle.other.inner.model.dto.user.WealthAndCharmLevelDTO;
|
||||||
import com.red.circle.other.app.inner.service.user.user.UserLevelClientService;
|
import com.red.circle.other.app.inner.service.user.user.UserLevelClientService;
|
||||||
@ -32,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
public class UserLevelClientEndpoint implements UserLevelClientApi {
|
public class UserLevelClientEndpoint implements UserLevelClientApi {
|
||||||
|
|
||||||
private final UserLevelClientService userLevelClientService;
|
private final UserLevelClientService userLevelClientService;
|
||||||
|
private final UserCacheService userCacheService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultResponse<WealthAndCharmExpLevelDTO> getUserLevelExp(SysOriginPlatformEnum sysOrigin,
|
public ResultResponse<WealthAndCharmExpLevelDTO> getUserLevelExp(SysOriginPlatformEnum sysOrigin,
|
||||||
@ -75,12 +77,14 @@ public class UserLevelClientEndpoint implements UserLevelClientApi {
|
|||||||
@Override
|
@Override
|
||||||
public ResultResponse<Void> incrWealthExp(Long userId, BigDecimal quantity) {
|
public ResultResponse<Void> incrWealthExp(Long userId, BigDecimal quantity) {
|
||||||
userLevelClientService.incrWealthExp(userId, quantity);
|
userLevelClientService.incrWealthExp(userId, quantity);
|
||||||
|
userCacheService.removeConsumptionLevel(userId);
|
||||||
return ResultResponse.success();
|
return ResultResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultResponse<Void> incrCharmExp(Long userId, BigDecimal quantity) {
|
public ResultResponse<Void> incrCharmExp(Long userId, BigDecimal quantity) {
|
||||||
userLevelClientService.incrCharmExp(userId, quantity);
|
userLevelClientService.incrCharmExp(userId, quantity);
|
||||||
|
userCacheService.removeConsumptionLevel(userId);
|
||||||
return ResultResponse.success();
|
return ResultResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user