| New file | 
 |  |  | 
 |  |  | package com.xcong.excoin;
 | 
 |  |  | 
 | 
 |  |  | import java.math.BigDecimal;
 | 
 |  |  | import java.util.ArrayList;
 | 
 |  |  | import java.util.List;
 | 
 |  |  | import java.util.concurrent.ExecutionException;
 | 
 |  |  | 
 | 
 |  |  | import javax.annotation.Resource;
 | 
 |  |  | 
 | 
 |  |  | import org.junit.jupiter.api.Test;
 | 
 |  |  | import org.springframework.boot.test.context.SpringBootTest;
 | 
 |  |  | 
 | 
 |  |  | import com.xcong.excoin.common.enumerates.CoinTypeEnum;
 | 
 |  |  | import com.xcong.excoin.modules.blackchain.service.EthService;
 | 
 |  |  | import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao;
 | 
 |  |  | import com.xcong.excoin.modules.member.dao.MemberCoinChargeDao;
 | 
 |  |  | import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
 | 
 |  |  | import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity;
 | 
 |  |  | import com.xcong.excoin.modules.member.entity.MemberCoinChargeEntity;
 | 
 |  |  | 
 | 
 |  |  | import cn.hutool.core.collection.CollUtil;
 | 
 |  |  | import cn.hutool.core.util.StrUtil;
 | 
 |  |  | import lombok.extern.slf4j.Slf4j;
 | 
 |  |  | 
 | 
 |  |  | @Slf4j
 | 
 |  |  | @SpringBootTest
 | 
 |  |  | public class GuijiTest {
 | 
 |  |  | 	 | 
 |  |  |     private static final BigDecimal LIMIT = new BigDecimal("50");
 | 
 |  |  |     private static final BigDecimal FEE = new BigDecimal("0.0044");
 | 
 |  |  | 
 | 
 |  |  |     public static String ETH_FEE = "0.0044";
 | 
 |  |  | 
 | 
 |  |  |     public static final String TOTAL_ADDRESS = "0x067b4bE5d7B05560AE539Fc8f10597D854ae056D";
 | 
 |  |  |     public static final String TOTAL_PRIVATE = "1fb7288c8c88c37d6f79e9617822bffc8d3635bf2d808c5f6afdee9bb326e49c";
 | 
 |  |  | 
 | 
 |  |  |     @Resource
 | 
 |  |  |     private MemberCoinChargeDao memberCoinChargeDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     private MemberCoinAddressDao memberCoinAddressDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     private MemberWalletCoinDao memberWalletCoinDao;
 | 
 |  |  | 
 | 
 |  |  |     @Test
 | 
 |  |  |     public void pool() throws ExecutionException, InterruptedException {
 | 
 |  |  |         //List<MemberCoinChargeEntity> list = memberCoinChargeDao.selectAllBySymbolAndTag(CoinTypeEnum.USDT.name(), "ERC20", 1);
 | 
 |  |  |         List<MemberCoinChargeEntity> list = new ArrayList<MemberCoinChargeEntity>();
 | 
 |  |  |         MemberCoinChargeEntity coin = new MemberCoinChargeEntity();
 | 
 |  |  |         coin.setAddress("0x4b859f7ba68e2757ae935f9e7426da0c73f63a68");
 | 
 |  |  |         coin.setMemberId(184L);
 | 
 |  |  |         coin.setLastAmount(new BigDecimal(70.83975901));
 | 
 |  |  |         list.add(coin);
 | 
 |  |  |         if (CollUtil.isNotEmpty(list)) {
 | 
 |  |  |             EthService ethService = new EthService();
 | 
 |  |  | 
 | 
 |  |  |             for (MemberCoinChargeEntity coinCharge : list) {
 | 
 |  |  |                 // 首先根据每个地址查询其是否有ETH 如果没有就充值ETH并设置1 表示初始状态 status=2(待充值)3:表示已提过
 | 
 |  |  |                 String address = coinCharge.getAddress();
 | 
 |  |  |                 Long memberId = coinCharge.getMemberId();
 | 
 |  |  |                 BigDecimal lastAmount = coinCharge.getLastAmount();
 | 
 |  |  |                 if (lastAmount == null || lastAmount.compareTo(LIMIT) < 0) {
 | 
 |  |  |                     continue;
 | 
 |  |  |                 }
 | 
 |  |  | 
 | 
 |  |  |                 BigDecimal usdt = ethService.tokenGetBalance(address);
 | 
 |  |  |                 System.out.println("地址:{}, 金额:{}"+address+"    usdt="+usdt);
 | 
 |  |  |                 if (usdt != null && usdt.compareTo(LIMIT) > 0) {
 | 
 |  |  |                     usdt = usdt.subtract(new BigDecimal("0.01"));
 | 
 |  |  | 
 | 
 |  |  |                     // 查询eth是否足够
 | 
 |  |  |                     BigDecimal eth = EthService.getEthBlance(address);
 | 
 |  |  |                     System.out.println("地址:"+address+"   eth = "+eth);
 | 
 |  |  |                     if (eth != null && eth.compareTo(FEE) >= 0) {
 | 
 |  |  |                         MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectBlockAddressWithTag(memberId, CoinTypeEnum.USDT.name(), "ERC20");
 | 
 |  |  |                         if (memberCoinAddressEntity == null) {
 | 
 |  |  |                             continue;
 | 
 |  |  |                         }
 | 
 |  |  | 
 | 
 |  |  |                         String privateKey = memberCoinAddressEntity.getPrivateKey();
 | 
 |  |  | 
 | 
 |  |  |                         usdt = usdt.multiply(new BigDecimal("1000000"));
 | 
 |  |  |                         String usdtStr = usdt.toPlainString();
 | 
 |  |  |                         if (usdtStr.contains(".")) {
 | 
 |  |  |                             usdtStr = usdtStr.substring(0, usdtStr.lastIndexOf("."));
 | 
 |  |  |                         }
 | 
 |  |  | 
 | 
 |  |  |                         String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr);
 | 
 |  |  |                         System.out.println("归集:"+hash);
 | 
 |  |  |                         if (StrUtil.isNotBlank(hash)) {
 | 
 |  |  |                             // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新
 | 
 |  |  |                             coinCharge.setHash(hash);
 | 
 |  |  |                             memberCoinChargeDao.updateById(coinCharge);
 | 
 |  |  |                         }
 | 
 |  |  |                     } else {
 | 
 |  |  |                         String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE);
 | 
 |  |  |                         System.out.println("转手续费:"+hash);
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  |      | 
 |  |  |      | 
 |  |  |      | 
 |  |  | }
 | 
 |  |  | 
 |