|
|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.nineth.web;
|
|
|
|
|
|
import com.izouma.nineth.domain.WithdrawApply;
|
|
|
+import com.izouma.nineth.repo.UserBalanceRepo;
|
|
|
import com.izouma.nineth.service.WithdrawApplyService;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
@@ -9,22 +10,27 @@ import com.izouma.nineth.utils.ObjUtils;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import com.izouma.nineth.utils.excel.ExcelUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/withdrawApply")
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class WithdrawApplyController extends BaseController {
|
|
|
private WithdrawApplyService withdrawApplyService;
|
|
|
private WithdrawApplyRepo withdrawApplyRepo;
|
|
|
+ private UserBalanceRepo userBalanceRepo;
|
|
|
|
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/all")
|
|
|
@@ -67,5 +73,20 @@ public class WithdrawApplyController extends BaseController {
|
|
|
public void fixCharge() throws ExecutionException, InterruptedException {
|
|
|
withdrawApplyService.fixCharge();
|
|
|
}
|
|
|
+
|
|
|
+ @PreAuthorize("hasRole('ADMIN')")
|
|
|
+ @PostMapping("/applyAll")
|
|
|
+ @Scheduled(cron = "0 0 8 * * ?")
|
|
|
+ public void applyAll() {
|
|
|
+ userBalanceRepo.findAll().parallelStream().forEach(userBalance -> {
|
|
|
+ LocalDateTime time = LocalDateTime.now().minusDays(14);
|
|
|
+ if (userBalance.getCreatedAt() != null && userBalance.getCreatedAt().isBefore(time)
|
|
|
+ && userBalance.getBalance().compareTo(new BigDecimal("100")) >= 0
|
|
|
+ && withdrawApplyRepo.countByUserIdAndCreatedAtAfter(userBalance.getUserId(), time) <= 0) {
|
|
|
+ log.info("apply withdraw for user {}", userBalance.getUserId());
|
|
|
+ withdrawApplyService.apply(userBalance.getUserId(), userBalance.getBalance());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|