|
|
@@ -17,8 +17,11 @@ import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -27,6 +30,9 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ForkJoinPool;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@Service
|
|
|
@@ -42,6 +48,7 @@ public class WithdrawApplyService {
|
|
|
private UserBankCardRepo userBankCardRepo;
|
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
private Environment env;
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
public Page<WithdrawApply> all(PageQuery pageQuery) {
|
|
|
return withdrawApplyRepo.findAll(JpaUtils.toSpecification(pageQuery, WithdrawApply.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -154,4 +161,19 @@ public class WithdrawApplyService {
|
|
|
}
|
|
|
return withdrawApplyRepo.save(apply);
|
|
|
}
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @RedisLock(value = "'approveAll'", expire = 1, unit = TimeUnit.HOURS)
|
|
|
+ public void approveAll() throws ExecutionException, InterruptedException {
|
|
|
+ new ForkJoinPool(5).submit(() -> {
|
|
|
+ withdrawApplyRepo.findByCreatedAtBetweenAndStatus(LocalDate.now().minusDays(1).atStartOfDay(),
|
|
|
+ LocalDate.now().minusDays(1).atTime(LocalTime.MAX), WithdrawStatus.PENDING)
|
|
|
+ .parallelStream().forEach(withdrawApply -> {
|
|
|
+ try {
|
|
|
+ finishWithdrawApply(withdrawApply.getId(), true, null);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }).get();
|
|
|
+ }
|
|
|
}
|