package com.izouma.nineth.service;

import com.alibaba.fastjson.JSONObject;
import com.izouma.nineth.ApplicationTests;
import com.izouma.nineth.dto.UserBankCard;
import com.izouma.nineth.enums.WithdrawStatus;
import com.izouma.nineth.repo.UserBankCardRepo;
import com.izouma.nineth.repo.WithdrawApplyRepo;
import com.izouma.nineth.utils.SnowflakeIdWorker;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.*;

@AllArgsConstructor
class WithdrawApplyServiceTest extends ApplicationTests {
    private WithdrawApplyRepo withdrawApplyRepo;
    private UserBankCardRepo  userBankCardRepo;
    private SandPayService    sandPayService;
    private SnowflakeIdWorker snowflakeIdWorker;

    public void fixCharge() {
        withdrawApplyRepo.findByStatusAndAmountLessThanEqual(WithdrawStatus.SUCCESS, new BigDecimal("1000"))
                .parallelStream().forEach(apply -> {
                    UserBankCard bankCard = userBankCardRepo.findByUserId(apply.getUserId())
                            .stream().findFirst()
                            .orElse(null);
                    JSONObject res = sandPayService.transfer(snowflakeIdWorker.nextId() + "", bankCard.getRealName(),
                            bankCard.getBankNo(), new BigDecimal("6"));
                });
    }
}