|
|
@@ -40,6 +40,8 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ForkJoinPool;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -379,4 +381,30 @@ public class UserBalanceService {
|
|
|
|
|
|
redisTemplate.delete("autoWithdraw::" + DateTimeUtils.format(date, "yyyyMMdd"));
|
|
|
}
|
|
|
+
|
|
|
+ public void revert() throws ExecutionException, InterruptedException {
|
|
|
+ ForkJoinPool customThreadPool = new ForkJoinPool(200);
|
|
|
+ customThreadPool.submit(() -> {
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ userBalanceRepo.findAll().parallelStream().forEach(userBalance -> {
|
|
|
+ List<BalanceRecord> balanceRecords = balanceRecordRepo.findByUserIdOrderByCreatedAt(userBalance.getUserId());
|
|
|
+ List<BalanceRecord> todayRecords = balanceRecords.stream()
|
|
|
+ .filter(b -> b.getCreatedAt().toLocalDate().equals(now)).collect(Collectors.toList());
|
|
|
+ List<BalanceRecord> oldRecords = balanceRecords.stream()
|
|
|
+ .filter(b -> !b.getCreatedAt().toLocalDate().equals(now))
|
|
|
+ .sorted(Comparator.comparing(BaseEntity::getCreatedAt))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (oldRecords.size() == 0) {
|
|
|
+ userBalanceRepo.delete(userBalance);
|
|
|
+ } else {
|
|
|
+ BalanceRecord record = oldRecords.get(oldRecords.size() - 1);
|
|
|
+ userBalance.setBalance(record.getBalance());
|
|
|
+ userBalance.setLastBalance(record.getLastBalance());
|
|
|
+ userBalanceRepo.save(userBalance);
|
|
|
+ }
|
|
|
+ balanceRecordRepo.deleteAll(todayRecords);
|
|
|
+ });
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ }
|
|
|
}
|