用户等级-缓存
This commit is contained in:
@@ -1469,6 +1469,8 @@ public enum RedisKey {
|
||||
user_up_mic_time,//用户上麦时间
|
||||
user_day_mic_duration,//用户在麦时长
|
||||
|
||||
user_recharge_level,
|
||||
|
||||
;
|
||||
|
||||
public String getKey() {
|
||||
|
@@ -18,4 +18,7 @@ public interface UserRechargeLevelMapper extends BaseMapper<UserRechargeLevel> {
|
||||
@Param("updateTime")Date updateTime);
|
||||
|
||||
List<Long> listUpdateUid();
|
||||
|
||||
String getLevelByUid(@Param("uid") Long uid);
|
||||
|
||||
}
|
@@ -13,6 +13,10 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class UserRechargeLevelConfigService extends ServiceImpl<UserRechargeLevelConfigMapper, UserRechargeLevelConfig> {
|
||||
|
||||
public String getDefaultLevel(){
|
||||
return "F";
|
||||
}
|
||||
|
||||
public String calLevel(boolean isRechargeUser, BigDecimal totalGold, BigDecimal last60TotalGold){
|
||||
List<UserRechargeLevelConfig> levelList = lambdaQuery()
|
||||
.orderByDesc(UserRechargeLevelConfig::getGoldThreshold, UserRechargeLevelConfig::getLast60GoldThreshold).list();
|
||||
|
@@ -1,24 +1,50 @@
|
||||
package com.accompany.payment.service;
|
||||
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.payment.mapper.ChargeRecordMapperMgr;
|
||||
import com.accompany.payment.mapper.UserRechargeLevelMapper;
|
||||
import com.accompany.payment.model.UserRechargeLevel;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.redisson.api.RMapCache;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class UserRechargeLevelService extends ServiceImpl<UserRechargeLevelMapper, UserRechargeLevel> {
|
||||
public class UserRechargeLevelService extends ServiceImpl<UserRechargeLevelMapper, UserRechargeLevel> implements InitializingBean {
|
||||
|
||||
@Autowired
|
||||
private UserRechargeLevelConfigService highRechargeLevelService;
|
||||
private UserRechargeLevelConfigService userRechargeLevelConfigService;
|
||||
@Autowired
|
||||
private ChargeRecordMapperMgr chargeRecordMapperMgr;
|
||||
@Autowired
|
||||
private RechargeUserService rechargeUserService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
private RMapCache<Long, String> cacheMap;
|
||||
|
||||
public String getLevelByUid(Long uid){
|
||||
String level = cacheMap.get(uid);
|
||||
if (StringUtils.hasText(level)){
|
||||
return level;
|
||||
}
|
||||
|
||||
level = getBaseMapper().getLevelByUid(uid);
|
||||
if (!StringUtils.hasText(level)){
|
||||
level = userRechargeLevelConfigService.getDefaultLevel();
|
||||
}
|
||||
|
||||
cacheMap.fastPut(uid, level, 1L, TimeUnit.DAYS);
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
public void statistics(Long uid, BigDecimal totalReceiveGoldNum, BigDecimal last60TotalReceiveGoldNum) {
|
||||
|
||||
@@ -44,10 +70,16 @@ public class UserRechargeLevelService extends ServiceImpl<UserRechargeLevelMappe
|
||||
|
||||
BigDecimal total = totalChargeGold.add(totalReceiveGoldNum);
|
||||
BigDecimal last60Total = last60ChargeGold.add(last60TotalReceiveGoldNum);
|
||||
String level = highRechargeLevelService.calLevel(isRechargeUser, total, last60Total);
|
||||
String level = userRechargeLevelConfigService.calLevel(isRechargeUser, total, last60Total);
|
||||
|
||||
getBaseMapper().saveOrUpdate(uid, level, isRechargeUser,
|
||||
total, totalChargeGold, totalReceiveGoldNum, last60Total, last60ChargeGold, last60TotalReceiveGoldNum, new Date());
|
||||
|
||||
cacheMap.fastRemove(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
cacheMap = redissonClient.getMapCache(RedisKey.user_recharge_level.getKey());
|
||||
}
|
||||
}
|
@@ -23,4 +23,10 @@
|
||||
where url.last_60_total_gold > 0
|
||||
</select>
|
||||
|
||||
<select id="getLevelByUid" resultType="java.lang.String">
|
||||
/* SHARDINGSPHERE_HINT: WRITE_ROUTE_ONLY=true */
|
||||
select `level` from user_recharge_level url
|
||||
where url.uid = #{uid}
|
||||
</select>
|
||||
|
||||
</mapper>
|
@@ -22,9 +22,9 @@ public class UserRechargeLevelNewUserListener implements ApplicationListener<New
|
||||
@Async
|
||||
@Override
|
||||
public void onApplicationEvent(NewUserEvent event) {
|
||||
Users user = (Users) event.getSource();
|
||||
Long uid = user.getUid();
|
||||
service.statistics(uid, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||
Users user = (Users) event.getSource();
|
||||
Long uid = user.getUid();
|
||||
service.statistics(uid, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user