|
|
|
@@ -2,6 +2,7 @@ package com.accompany.business.service.lucky;
|
|
|
|
|
|
|
|
|
|
import com.accompany.business.dto.lucky.Lucky24GiftConfig;
|
|
|
|
|
import com.accompany.business.dto.lucky.Lucky24Result;
|
|
|
|
|
import com.accompany.common.constant.Constant;
|
|
|
|
|
import com.accompany.common.redis.RedisKey;
|
|
|
|
|
import com.accompany.common.utils.DateTimeUtil;
|
|
|
|
|
import com.accompany.core.enumeration.PartitionEnum;
|
|
|
|
@@ -32,6 +33,8 @@ public class Lucky24UserMetaService {
|
|
|
|
|
|
|
|
|
|
public static final String EXTRA_POOL_COUNT = "extra_pool_count";
|
|
|
|
|
|
|
|
|
|
public static final String Y = "y";
|
|
|
|
|
|
|
|
|
|
private static final int HISTORY_QUEUE_SIZE = 40000;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@@ -143,25 +146,6 @@ public class Lucky24UserMetaService {
|
|
|
|
|
return stockResultVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateExtraUserMeta(long senderUid, Integer partitionId, long input, long output) {
|
|
|
|
|
RMap<String, Number> userMetaMap = getUserMeta(senderUid);
|
|
|
|
|
long times = userMetaMap.addAndGet(TIMES_KEY, 1L).longValue();
|
|
|
|
|
|
|
|
|
|
PartitionEnum partitionEnum = PartitionEnum.getByPartitionId(partitionId);
|
|
|
|
|
long todayStartTimeLong = DateTimeUtil.getZonedTodayTime(partitionEnum.getZoneId());
|
|
|
|
|
|
|
|
|
|
String today = String.valueOf(todayStartTimeLong);
|
|
|
|
|
String todayTimesKey = String.join("_", today, TIMES_KEY);
|
|
|
|
|
long todayTimes = userMetaMap.addAndGet(todayTimesKey, 1L).longValue();
|
|
|
|
|
String todayInputKey = String.join("_", today, INPUT_KEY);
|
|
|
|
|
long todayInput = userMetaMap.addAndGet(todayInputKey, input).longValue();
|
|
|
|
|
String todayOutputKey = String.join("_", today, OUTPUT_KEY);
|
|
|
|
|
long todayOutput = userMetaMap.addAndGet(todayOutputKey, output).longValue();
|
|
|
|
|
|
|
|
|
|
log.info("[Lucky24] updateExtraUserMeta uid {} times {} today {} todayTime {} todayInput {} todayOutput {}",
|
|
|
|
|
senderUid, times, todayStartTimeLong, todayTimes, todayInput, todayOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateUserMeta(long senderUid, int partitionId, long input, long output) {
|
|
|
|
|
RList<Lucky24Result> historyQueue = getUserHistoryQueue(senderUid);
|
|
|
|
|
historyQueue.add(0, new Lucky24Result(null, null, input, output, null));
|
|
|
|
@@ -260,10 +244,48 @@ public class Lucky24UserMetaService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Y用户
|
|
|
|
|
if (userMetaMap.containsKey(Y)){
|
|
|
|
|
String yInputKey = String.join("_", Y, INPUT_KEY);
|
|
|
|
|
long yInput = userMetaMap.addAndGet(yInputKey, input).longValue();
|
|
|
|
|
String yOutputKey = String.join("_", Y, OUTPUT_KEY);
|
|
|
|
|
long yOutput = userMetaMap.addAndGet(yOutputKey, output).longValue();
|
|
|
|
|
|
|
|
|
|
log.info("[Lucky24] updateUserMeta Y uid {} YInput {} YOutput {}", senderUid, yInput, yOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("[Lucky24] updateUserMeta uid {} times {} todayInput {} todayOutput {} today {} todayTimes {} todayIntput {} todayOutput {}",
|
|
|
|
|
senderUid, times, totalInput, totalOutput, todayStartTimeLong, todayTimes, todayInput, todayOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void dyeYUser(Long uid) {
|
|
|
|
|
RMap<String, Number> userMetaMap = getUserMeta(uid);
|
|
|
|
|
userMetaMap.putIfAbsent(Y, Constant.Yes1No0.YES);
|
|
|
|
|
log.info("[Lucky24] dyeYUser uid {}", uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean judgeYDiff(Long uid, long outputDiff) {
|
|
|
|
|
RMap<String, Number> userMetaMap = getUserMeta(uid);
|
|
|
|
|
|
|
|
|
|
String yInputKey = String.join("_", Y, INPUT_KEY);
|
|
|
|
|
long yInput = userMetaMap.getOrDefault(yInputKey, 0L).longValue();
|
|
|
|
|
String yOutputKey = String.join("_", Y, OUTPUT_KEY);
|
|
|
|
|
long yOutput = userMetaMap.getOrDefault(yOutputKey, 0L).longValue();
|
|
|
|
|
|
|
|
|
|
long judgeDiff = yInput - yOutput;
|
|
|
|
|
|
|
|
|
|
if (judgeDiff < outputDiff){
|
|
|
|
|
log.info("[Lucky24] judgeYDiff false uid {} judgeDiff {} outputDiff {}", uid, judgeDiff, outputDiff);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("[Lucky24] judgeYDiff true uid {} judgeDiff {} outputDiff {}", uid, judgeDiff, outputDiff);
|
|
|
|
|
|
|
|
|
|
userMetaMap.fastRemove(Y, yInputKey, yOutputKey);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RMap<String, Number> getUserMeta(Long uid) {
|
|
|
|
|
return redissonClient.getMap(RedisKey.lucky_24_user_meta.getKey(uid.toString()));
|
|
|
|
|
}
|
|
|
|
|