xiongzhu 3 rokov pred
rodič
commit
4f56b48047

+ 0 - 1
src/main/java/com/izouma/nineth/repo/UserBalanceRepo.java

@@ -1,7 +1,6 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.UserBalance;
-import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;

+ 4 - 0
src/main/java/com/izouma/nineth/repo/WithdrawApplyRepo.java

@@ -1,6 +1,7 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.WithdrawApply;
+import com.izouma.nineth.enums.WithdrawStatus;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -8,6 +9,7 @@ import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
 import java.time.LocalDateTime;
+import java.util.List;
 
 public interface WithdrawApplyRepo extends JpaRepository<WithdrawApply, Long>, JpaSpecificationExecutor<WithdrawApply> {
     @Query("update WithdrawApply t set t.del = true where t.id = ?1")
@@ -16,4 +18,6 @@ public interface WithdrawApplyRepo extends JpaRepository<WithdrawApply, Long>, J
     void softDelete(Long id);
 
     int countByUserIdAndCreatedAtBetween(Long userId, LocalDateTime start, LocalDateTime end);
+
+    List<WithdrawApply> findByCreatedAtBetweenAndStatus(LocalDateTime start, LocalDateTime end, WithdrawStatus status);
 }

+ 2 - 0
src/main/java/com/izouma/nineth/service/UserBalanceService.java

@@ -39,6 +39,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
@@ -527,6 +528,7 @@ public class UserBalanceService {
         }
         BalanceRecord record = balanceRecordRepo.findByOrderIdAndType(order.getId(), BalanceType.SELL);
         if (record != null) {
+            log.info("此订单已结算 orderId={}", order.getId());
             return;
         }
         log.info("结算订单 orderId={}", order.getId());

+ 9 - 9
src/main/java/com/izouma/nineth/service/UserService.java

@@ -899,15 +899,15 @@ public class UserService {
         if (identityAuth == null) {
             throw new BusinessException("请先完成实名认证");
         }
-        long age = ChronoUnit.YEARS.between(LocalDate.parse(identityAuth.getIdNo().substring(6, 14),
-                DateTimeFormatter.ofPattern("yyyyMMdd")), LocalDate.now());
-        if (!((age >= 22 && age <= 55))) {
-            throw new BusinessException("仅22至55周岁藏家可申请绿魔卡");
-        }
-        BigDecimal amount = sysConfigService.getBigDecimal("wallet_enable_amount");
-        if (Optional.ofNullable(orderRepo.sumUserPrice(userId)).orElse(BigDecimal.ZERO).compareTo(amount) < 0) {
-            throw new BusinessException("申请绿魔卡需满" + amount + "绿洲石");
-        }
+//        long age = ChronoUnit.YEARS.between(LocalDate.parse(identityAuth.getIdNo().substring(6, 14),
+//                DateTimeFormatter.ofPattern("yyyyMMdd")), LocalDate.now());
+//        if (!((age >= 22 && age <= 55))) {
+//            throw new BusinessException("仅22至55周岁藏家可申请绿魔卡");
+//        }
+//        BigDecimal amount = sysConfigService.getBigDecimal("wallet_enable_amount");
+//        if (Optional.ofNullable(orderRepo.sumUserPrice(userId)).orElse(BigDecimal.ZERO).compareTo(amount) < 0) {
+//            throw new BusinessException("申请绿魔卡需满" + amount + "绿洲石");
+//        }
         user.setWalletEnabled(true);
         save(user);
     }

+ 22 - 0
src/main/java/com/izouma/nineth/service/WithdrawApplyService.java

@@ -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();
+    }
 }

+ 7 - 0
src/main/java/com/izouma/nineth/web/WithdrawApplyController.java

@@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 
 @RestController
 @RequestMapping("/withdrawApply")
@@ -54,5 +55,11 @@ public class WithdrawApplyController extends BaseController {
     public WithdrawApply finish(@RequestParam Long id, @RequestParam boolean approve, String reason) {
         return withdrawApplyService.finishWithdrawApply(id, approve, reason);
     }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @PostMapping("/approveAll")
+    public void approveAll() throws ExecutionException, InterruptedException {
+        withdrawApplyService.approveAll();
+    }
 }
 

+ 13 - 0
src/main/vue/src/views/WithdrawApplyList.vue

@@ -12,6 +12,9 @@
             </el-button>
         </page-title>
         <div class="filters-container">
+            <template v-if="$store.state.userInfo && $store.state.userInfo.username === 'xiong'">
+                <el-button class="filter-item" type="primary" @click="approveAll" size="mini"> 全部通过 </el-button>
+            </template>
             <el-input
                 placeholder="搜索..."
                 v-model="search"
@@ -191,6 +194,16 @@ export default {
                         this.$message.error(e.error || '操作失败');
                     }
                 });
+        },
+        approveAll() {
+            this.$http
+                .post('/withdrawApply/approveAll')
+                .then(res => {
+                    this.$message.success('操作成功');
+                })
+                .catch(e => {
+                    this.$message.error(e.error || '操作失败');
+                });
         }
     }
 };