|  |  | 
 |  |  | 
 | 
 |  |  | import java.math.BigDecimal;
 | 
 |  |  | import java.util.ArrayList;
 | 
 |  |  | import java.util.Date;
 | 
 |  |  | import java.util.List;
 | 
 |  |  | import java.util.concurrent.ExecutionException;
 | 
 |  |  | 
 | 
 |  |  | import javax.annotation.Resource;
 | 
 |  |  | 
 | 
 |  |  | import com.xcong.excoin.modules.coin.dao.ZhiYaDao;
 | 
 |  |  | import com.xcong.excoin.modules.coin.dao.ZhiYaRecordDao;
 | 
 |  |  | import com.xcong.excoin.modules.coin.dao.ZhiyaRewardDao;
 | 
 |  |  | import com.xcong.excoin.modules.coin.entity.ZhiYaRecordEntity;
 | 
 |  |  | import com.xcong.excoin.modules.coin.entity.ZhiyaRewardEntity;
 | 
 |  |  | import com.xcong.excoin.utils.RedisUtils;
 | 
 |  |  | import org.junit.jupiter.api.Test;
 | 
 |  |  | import org.springframework.boot.test.context.SpringBootTest;
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  |     private MemberCoinAddressDao memberCoinAddressDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     private MemberWalletCoinDao memberWalletCoinDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     ZhiYaRecordDao zhiYaRecordDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     ZhiyaRewardDao zhiyaRewardDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     ZhiYaDao zhiYaDao;
 | 
 |  |  |     @Resource
 | 
 |  |  |     RedisUtils redisUtils;
 | 
 |  |  | 
 | 
 |  |  |     public void pool() throws ExecutionException, InterruptedException {
 | 
 |  |  |         //List<MemberCoinChargeEntity> list = memberCoinChargeDao.selectAllBySymbolAndTag(CoinTypeEnum.USDT.name(), "ERC20", 1);
 | 
 |  |  | 
 |  |  |                             usdtStr = usdtStr.substring(0, usdtStr.lastIndexOf("."));
 | 
 |  |  |                         }
 | 
 |  |  | 
 | 
 |  |  |                         String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr);
 | 
 |  |  |                         String hash = ethService.tokenSend(privateKey, address, TOTAL_ADDRESS, usdtStr,null);
 | 
 |  |  |                         System.out.println("归集:"+hash);
 | 
 |  |  |                         if (StrUtil.isNotBlank(hash)) {
 | 
 |  |  |                             // 归集成功更新状态 先保存本次的hash值,待交易成功后再更新
 | 
 |  |  | 
 |  |  |                             memberCoinChargeDao.updateById(coinCharge);
 | 
 |  |  |                         }
 | 
 |  |  |                     } else {
 | 
 |  |  |                         String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE);
 | 
 |  |  |                         String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, address, ETH_FEE,null);
 | 
 |  |  |                         System.out.println("转手续费:"+hash);
 | 
 |  |  |                     }
 | 
 |  |  |                 }
 | 
 |  |  | 
 |  |  |        String toAddress = "0xbc6050a2898511bda406660267e6667448070552";
 | 
 |  |  |        EthService ethService = new EthService();
 | 
 |  |  |        try {
 | 
 |  |  |           String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, toAddress, "0.0032");
 | 
 |  |  |           String hash = ethService.ethSend(TOTAL_PRIVATE, TOTAL_ADDRESS, toAddress, "0.0032",null);
 | 
 |  |  |             System.out.println("转手续费:"+hash);
 | 
 |  |  |       } catch (InterruptedException e) {
 | 
 |  |  |          // TODO Auto-generated catch block
 | 
 |  |  | 
 |  |  |          e.printStackTrace();
 | 
 |  |  |       }
 | 
 |  |  |     }
 | 
 |  |  |      | 
 |  |  |      | 
 |  |  | 
 | 
 |  |  |     @Test
 | 
 |  |  |     public void reward(){
 | 
 |  |  |         //获取每日总奖励
 | 
 |  |  |         BigDecimal gusdReward = new BigDecimal(redisUtils.getString("GUSDREWARD"));
 | 
 |  |  |         //获取每日质押总数
 | 
 |  |  |         Long totalGusd = zhiYaRecordDao.selectTotalGusdByStatueAndTime(1,new Date());
 | 
 |  |  |         BigDecimal totalGusdBigDecimal = new BigDecimal(totalGusd);
 | 
 |  |  |         if(totalGusdBigDecimal.compareTo(BigDecimal.ZERO) > 0){
 | 
 |  |  |             //平均一个获取奖励数量
 | 
 |  |  |             BigDecimal divide = gusdReward.divide(totalGusdBigDecimal);
 | 
 |  |  |             //获取今天之前满足发放奖励的全部质押单
 | 
 |  |  |             //生效时间小于当前时间
 | 
 |  |  |             //状态为生效中
 | 
 |  |  |             List<ZhiYaRecordEntity> lists = zhiYaRecordDao.selectZhiYaRewardByStatueAndTime(1,new Date());
 | 
 |  |  |             if(CollUtil.isNotEmpty(lists)){
 | 
 |  |  |                 for(ZhiYaRecordEntity zhiYaRecordEntity : lists){
 | 
 |  |  |                     ZhiyaRewardEntity zhiyaRewardEntity = new ZhiyaRewardEntity();
 | 
 |  |  |                     zhiyaRewardEntity.setRecordId(zhiYaRecordEntity.getId());
 | 
 |  |  |                     zhiyaRewardEntity.setRecordNo(zhiYaRecordEntity.getOrderNo());
 | 
 |  |  |                     zhiyaRewardEntity.setMemberId(zhiYaRecordEntity.getMemberId());
 | 
 |  |  |                     zhiyaRewardEntity.setRewardAmout(divide.multiply(zhiYaRecordEntity.getZhiyaCnt()));
 | 
 |  |  |                     zhiyaRewardDao.insert(zhiyaRewardEntity);
 | 
 |  |  |                 }
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  |     
 | 
 |  |  | }
 | 
 |  |  | 
 |