幸运24-额外-记录前两天的投产
This commit is contained in:
@@ -17,9 +17,7 @@ import java.math.BigDecimal;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -30,6 +28,7 @@ public class Lucky24UserMetaService {
|
|||||||
public static final String OUTPUT_KEY = "output";
|
public static final String OUTPUT_KEY = "output";
|
||||||
|
|
||||||
private static final String TODAY = "today";
|
private static final String TODAY = "today";
|
||||||
|
private static final String TWO_DAY_AGO = "two_day_ago";
|
||||||
|
|
||||||
public static final String EXTRA_POOL_COUNT = "extra_pool_count";
|
public static final String EXTRA_POOL_COUNT = "extra_pool_count";
|
||||||
|
|
||||||
@@ -187,15 +186,71 @@ public class Lucky24UserMetaService {
|
|||||||
long userMetaToday = userMetaMap.computeIfAbsent(TODAY, k->todayStartTimeLong).longValue();
|
long userMetaToday = userMetaMap.computeIfAbsent(TODAY, k->todayStartTimeLong).longValue();
|
||||||
if (userMetaToday < todayStartTimeLong
|
if (userMetaToday < todayStartTimeLong
|
||||||
&& userMetaMap.replace(TODAY, userMetaToday, todayStartTimeLong)){
|
&& userMetaMap.replace(TODAY, userMetaToday, todayStartTimeLong)){
|
||||||
|
Map<String, Number> userMetaMapSnapshot = userMetaMap.readAllMap();
|
||||||
|
|
||||||
// 清理昨天
|
// 清理昨天
|
||||||
String oldToday = String.valueOf(userMetaToday);
|
String oldToday = String.valueOf(userMetaToday);
|
||||||
String oldTodayTimesKey = String.join("_", oldToday, TIMES_KEY);
|
String oldTodayTimesKey = String.join("_", oldToday, TIMES_KEY);
|
||||||
String oldTodayInputKey = String.join("_", oldToday, INPUT_KEY);
|
String oldTodayInputKey = String.join("_", oldToday, INPUT_KEY);
|
||||||
String oldTodayOutputKey = String.join("_", oldToday, OUTPUT_KEY);
|
String oldTodayOutputKey = String.join("_", oldToday, OUTPUT_KEY);
|
||||||
|
|
||||||
String oldTodayExtraPoolKey = String.join("_", oldToday, EXTRA_POOL_COUNT);
|
String oldTodayExtraPoolKey = String.join("_", oldToday, EXTRA_POOL_COUNT);
|
||||||
|
|
||||||
userMetaMap.fastRemove(oldTodayTimesKey, oldTodayInputKey, oldTodayOutputKey, oldTodayExtraPoolKey);
|
int oneDayAgoDiff = 2 * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
if (userMetaToday >= todayStartTimeLong - 2 * oneDayAgoDiff){
|
||||||
|
String oldDayInputKey = String.join("_", INPUT_KEY, oldToday);
|
||||||
|
long oldTodayInput = userMetaMapSnapshot.getOrDefault(oldTodayInputKey, 0L).longValue();
|
||||||
|
|
||||||
|
String oldDayOutputKey = String.join("_", OUTPUT_KEY, oldToday);
|
||||||
|
long oldTodayOutput = userMetaMapSnapshot.getOrDefault(oldTodayOutputKey, 0L).longValue();
|
||||||
|
|
||||||
|
// cache snapshot
|
||||||
|
userMetaMapSnapshot.putAll(Map.of(oldDayInputKey, oldTodayInput, oldDayOutputKey, oldTodayOutput));
|
||||||
|
|
||||||
|
Set<String> needDeleteKeySet = new HashSet<>();
|
||||||
|
for (String key : userMetaMapSnapshot.keySet()){
|
||||||
|
if (key.startsWith(INPUT_KEY) || key.startsWith(OUTPUT_KEY)){
|
||||||
|
if (key.endsWith(TWO_DAY_AGO)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
needDeleteKeySet.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long twoDayAgoInput = 0L;
|
||||||
|
long twoDayAgoOutput = 0L;
|
||||||
|
|
||||||
|
for (int i = 1; i < 3; i++){
|
||||||
|
long dateStartTimeLong = todayStartTimeLong - i * oneDayAgoDiff;
|
||||||
|
String date = String.valueOf(dateStartTimeLong);
|
||||||
|
|
||||||
|
String dayInputKey = String.join("_", INPUT_KEY, date);
|
||||||
|
long dayInput = userMetaMapSnapshot.getOrDefault(dayInputKey, 0L).longValue();
|
||||||
|
|
||||||
|
needDeleteKeySet.remove(dayInputKey);
|
||||||
|
|
||||||
|
twoDayAgoInput += dayInput;
|
||||||
|
|
||||||
|
String dayOutputKey = String.join("_", OUTPUT_KEY, date);
|
||||||
|
long dayOutput = userMetaMapSnapshot.getOrDefault(dayOutputKey, 0L).longValue();
|
||||||
|
|
||||||
|
needDeleteKeySet.remove(dayOutputKey);
|
||||||
|
|
||||||
|
twoDayAgoOutput += dayOutput;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String twoDayAgoInputKey = String.join("_", INPUT_KEY, TWO_DAY_AGO);
|
||||||
|
String twoDayAgoOutputKey = String.join("_", INPUT_KEY, TWO_DAY_AGO);
|
||||||
|
|
||||||
|
// cache
|
||||||
|
userMetaMap.putAll(Map.of(oldDayInputKey, oldTodayInput, oldDayOutputKey, oldTodayOutput,
|
||||||
|
twoDayAgoInputKey, twoDayAgoInput, twoDayAgoOutputKey, twoDayAgoOutput));
|
||||||
|
|
||||||
|
// clear key
|
||||||
|
needDeleteKeySet.addAll(List.of(oldTodayInputKey, oldTodayOutputKey, oldTodayTimesKey, oldTodayExtraPoolKey));
|
||||||
|
userMetaMap.fastRemove(needDeleteKeySet.toArray(String[]::new));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("[Lucky24] updateUserMeta uid {} times {} today {} todayTimes {}",
|
log.info("[Lucky24] updateUserMeta uid {} times {} today {} todayTimes {}",
|
||||||
|
Reference in New Issue
Block a user