wangqifan 3 yıl önce
ebeveyn
işleme
8bb758b24c

+ 59 - 40
src/main/java/com/izouma/nineth/service/UserBalanceService.java

@@ -24,6 +24,8 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.util.TempFile;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.core.env.Environment;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -45,25 +47,42 @@ import java.util.stream.Collectors;
 
 @Service
 @Slf4j
-@AllArgsConstructor
 public class UserBalanceService {
-    private final UserBalanceRepo               userBalanceRepo;
-    private final BalanceRecordRepo             balanceRecordRepo;
-    private final OrderRepo                     orderRepo;
-    private final AssetRepo                     assetRepo;
-    private final UserBankCardRepo              userBankCardRepo;
-    private final SettleRecordRepo              settleRecordRepo;
-    private final StorageService                storageService;
-    private final ExportWithdrawRepo            exportWithdrawRepo;
-    private final AutoWithdrawRecordRepo        autoWithdrawRecordRepo;
-    private final SnowflakeIdWorker             snowflakeIdWorker;
-    private final SandPayService                sandPayService;
-    private final RedisTemplate<String, Object> redisTemplate;
-    private final RechargeOrderRepo             rechargeOrderRepo;
-    private final SysConfigService              sysConfigService;
-    private final Environment                   env;
-//    private final AirDropService                airDropService;
-//    private final UserRepo                      userRepo;
+    @Autowired
+    private UserBalanceRepo               userBalanceRepo;
+    @Autowired
+    private BalanceRecordRepo             balanceRecordRepo;
+    @Autowired
+    private OrderRepo                     orderRepo;
+    @Autowired
+    private AssetRepo                     assetRepo;
+    @Autowired
+    private UserBankCardRepo              userBankCardRepo;
+    @Autowired
+    private SettleRecordRepo              settleRecordRepo;
+    @Autowired
+    private StorageService                storageService;
+    @Autowired
+    private ExportWithdrawRepo            exportWithdrawRepo;
+    @Autowired
+    private AutoWithdrawRecordRepo        autoWithdrawRecordRepo;
+    @Autowired
+    private SnowflakeIdWorker             snowflakeIdWorker;
+    @Autowired
+    private SandPayService                sandPayService;
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+    @Autowired
+    private RechargeOrderRepo             rechargeOrderRepo;
+    @Autowired
+    private SysConfigService              sysConfigService;
+    @Autowired
+    private Environment                   env;
+    @Lazy
+    @Autowired
+    private AirDropService                airDropService;
+    @Autowired
+    private UserRepo                      userRepo;
 
     public void settle(LocalDate start, LocalDate end) {
         for (long i = 0; i <= ChronoUnit.DAYS.between(start, end); i++) {
@@ -471,30 +490,30 @@ public class UserBalanceService {
             throw new BusinessException("充值订单状态异常");
         }
 
-//        if (checkRechargeSum(rechargeOrder.getUserId(), rechargeOrder.getAmount())) {
-//            airDrop(rechargeOrder.getUserId());
-//        }
+        if (checkRechargeSum(rechargeOrder.getUserId(), rechargeOrder.getAmount())) {
+            airDrop(rechargeOrder.getUserId());
+        }
     }
 
-//    public void airDrop(Long userId) {
-//        Long collectionId = Long.valueOf(sysConfigService.getString("recharge_collectionId"));
-//        Asset asset = assetRepo.findFirstByCollectionIdAndUserIdAndSource(collectionId, userId, AssetSource.OFFICIAL);
-//        if (asset == null) {
-//            User user = userRepo.findById(userId).orElseThrow(new BusinessException("暂无该用户"));
-//            airDropService.create(AirDrop.builder()
-//                    .name("春节充值空投福卡")
-//                    .remark("recharge:" + userId)
-//                    .type(AirDropType.asset)
-//                    .userIds(Collections.singletonList(userId))
-//                    .collectionId(collectionId)
-//                    .targets(Collections
-//                            .singletonList(new DropTarget(user.getId(), user.getPhone(), user
-//                                    .getNickname(), 1)))
-//                    .auto(true)
-//                    .companyId(1L)
-//                    .build());
-//        }
-//    }
+    public void airDrop(Long userId) {
+        Long collectionId = Long.valueOf(sysConfigService.getString("recharge_collectionId"));
+        Asset asset = assetRepo.findFirstByCollectionIdAndUserIdAndSource(collectionId, userId, AssetSource.OFFICIAL);
+        if (asset == null) {
+            User user = userRepo.findById(userId).orElseThrow(new BusinessException("暂无该用户"));
+            airDropService.create(AirDrop.builder()
+                    .name("春节充值空投福卡")
+                    .remark("recharge:" + userId)
+                    .type(AirDropType.asset)
+                    .userIds(Collections.singletonList(userId))
+                    .collectionId(collectionId)
+                    .targets(Collections
+                            .singletonList(new DropTarget(user.getId(), user.getPhone(), user
+                                    .getNickname(), 1)))
+                    .auto(true)
+                    .companyId(1L)
+                    .build());
+        }
+    }
 
     public boolean checkRechargeSum(Long userId, BigDecimal recharge) {
         LocalDateTime start = LocalDateTime.of(2023, 1, 13, 0, 0, 0);