| | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.enumerates.DataDicEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.dto.BatchTransferDto; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.AsyncCjService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | for (Map.Entry<Integer, DappMemberEntity> entry : objectObjectHashMap.entrySet()) { |
| | | Integer key = entry.getKey(); |
| | | DappMemberEntity refMember = entry.getValue(); |
| | | BigDecimal perkPercent = BigDecimal.ZERO; |
| | | if(key == 0){ |
| | | perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | } |
| | | if(key == 1){ |
| | | perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | } |
| | | if(key == 2){ |
| | | perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | } |
| | | if(key == 3){ |
| | | perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | } |
| | | if(key == 4){ |
| | | perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_WU.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | } |
| | | BigDecimal perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | // if(key == 0){ |
| | | // perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | // } |
| | | // if(key == 1){ |
| | | // perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | // } |
| | | // if(key == 2){ |
| | | // perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | // } |
| | | // if(key == 3){ |
| | | // perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_YI.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | // } |
| | | // if(key == 4){ |
| | | // perkPercent = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_TUAN_DUI_LEVEL_WU.getValue())).setScale(4, BigDecimal.ROUND_DOWN); |
| | | // } |
| | | BigDecimal realPerk = tuanDuiPerk.multiply(perkPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | if(BigDecimal.ZERO.compareTo(realPerk) >= 0){ |
| | | continue; |
| | |
| | | BigDecimal usdtAmount = new BigDecimal( |
| | | redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_USDT_AMOUNT.getValue()) |
| | | ).setScale(2,BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinAmount = new BigDecimal( |
| | | redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_COIN_AMOUNT.getValue()) |
| | | ).setScale(2,BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinAmount = BigDecimal.ZERO; |
| | | // BigDecimal coinAmount = new BigDecimal( |
| | | // redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_COIN_AMOUNT.getValue()) |
| | | // ).setScale(2,BigDecimal.ROUND_DOWN); |
| | | if(BigDecimal.ZERO.compareTo(usdtAmount) > 0){ |
| | | return; |
| | | } |
| | |
| | | }else if(FlowTypeEnum.DAI_BI_OUT.getValue() == type){ |
| | | //代币转账 |
| | | String transfer = ChainService.getInstance(ChainEnum.BSC_GFA.name()).transfer(dappMemberEntity.getAddress(), amount); |
| | | int retryTime = 0;//重试次数 |
| | | while (StrUtil.isEmpty(transfer)) { |
| | | // 休眠2s |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(retryTime < 3){ |
| | | transfer = ChainService.getInstance(ChainEnum.BSC_GFA.name()).transfer(dappMemberEntity.getAddress(), amount); |
| | | } |
| | | retryTime ++ ; |
| | | } |
| | | if(StrUtil.isNotEmpty(transfer)){ |
| | | dappFundFlowEntity.setFromHash(transfer); |
| | | dappFundFlowEntity.setStatus(2); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void calculateAchieve(DappAchieve achieve) { |
| | | Long id = achieve.getId(); |
| | | DappAchieve dappAchieve = dappAchieveMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappAchieve)){ |
| | | return; |
| | | } |
| | | /** |
| | | * 计算金本位和币本位 |
| | | * 金本位:数量*价格*70*产矿百分比 |
| | | * 币本位:数量*30*产矿百分比 |
| | | */ |
| | | BigDecimal achieveOut = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_ACHIEVE_OUT.getValue())).setScale(2,BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal amount = dappAchieve.getAmount(); |
| | | BigDecimal price = dappAchieve.getPrice(); |
| | | BigDecimal goldAmount = amount.multiply(price).multiply(new BigDecimal("0.7")).multiply(achieveOut).setScale(8, BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinAmount = amount.multiply(new BigDecimal("0.3")).multiply(achieveOut).setScale(8, BigDecimal.ROUND_DOWN); |
| | | dappAchieve.setGoldAmount(goldAmount); |
| | | dappAchieve.setCoinAmount(coinAmount); |
| | | dappAchieveMapper.updateById(dappAchieve); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String transfer = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer("0xCEBfd36e03BD80c7015Cbad17eFfBc33d2923FF3", new BigDecimal("0.1")); |
| | | List<BatchTransferDto> objects = new ArrayList<>(); |
| | | objects.add(new BatchTransferDto("0xCEBfd36e03BD80c7015Cbad17eFfBc33d2923FF3", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0xF9356131fD2c10B8d834E41C7aDD68E6983c35b9", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0x99dC2D688aA58b7798ebd17C163273875119cBc7", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0x32D13D3C8958c357270515560A61413f8e388b68", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0xf37780139783BeCD19118b84df277dB67B34363B", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0x2Fbd10058cDC4F5d95A593F25C8ce015dFE5779B", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0x597e5F0EDB294e7d28EB10A95aa2EEcd169a2dd7", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0xcFdbC664b8F137b3bD2Debc795bB0c5a6FdBc0bE", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0xcFdbC664b8F137b3bD2Debc795bB0c5a6FdBc0bE", new BigDecimal("0.001"))); |
| | | objects.add(new BatchTransferDto("0xcFdbC664b8F137b3bD2Debc795bB0c5a6FdBc0bE", new BigDecimal("0.001"))); |
| | | ChainService.getInstance(ChainEnum.BSC_USDT_LOCAL.name()).transferList(objects); |
| | | // BigInteger bigInteger = org.web3j.utils.Convert.toWei("35", org.web3j.utils.Convert.Unit.GWEI).toBigInteger(); |
| | | // System.out.println(bigInteger); |
| | | } |
| | |
| | | queryWrapper.eq("state",DappAchieve.STATUS_ING); |
| | | List<DappAchieve> dappAchieveSumList = dappAchieveMapper.selectList(queryWrapper); |
| | | //个人团队总业绩 |
| | | BigDecimal teamAchieveMemberSum = dappAchieveSumList.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal teamAchieveMemberSum = dappAchieveSumList.stream().map(item-> item.getAmount().multiply(item.getPrice())).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if(BigDecimal.ZERO.compareTo(teamAchieveMemberSum) >= 0){ |
| | | continue; |
| | | } |
| | |
| | | BigDecimal multiplyDivideEveryUsdt = divideEveryUsdt.multiply(selfPercentMultiply); |
| | | BigDecimal multiplyDivideEveryCoin = divideEveryCoin.multiply(selfPercentMultiply); |
| | | //当前生效中的质押总数 |
| | | BigDecimal amountMemberTotal = dappAchieves.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal amountMemberTotal = dappAchieves.stream().map(item-> item.getAmount().multiply(item.getPrice())).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if(BigDecimal.ZERO.compareTo(amountMemberTotal) >= 0){ |
| | | return; |
| | | } |
| | | |
| | | |
| | | |
| | | BigDecimal everyUsdt = multiplyDivideEveryUsdt.divide(amountMemberTotal,8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal everyCoin = multiplyDivideEveryCoin.divide(amountMemberTotal,8,BigDecimal.ROUND_DOWN); |
| | | |
| | |
| | | Set<Long> set = collect.keySet(); // 得到所有key的集合 |
| | | for (Long memberId : set) { |
| | | //当前每个人生效中的质押总数 |
| | | BigDecimal amountMember = collect.get(memberId).stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // BigDecimal amountMember = collect.get(memberId).stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal amountMember = collect.get(memberId).stream().map(item-> item.getAmount().multiply(item.getPrice())).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //这个人实际可以分到的数量USDT |
| | | BigDecimal multiplyUsdt = amountMember.multiply(everyUsdt).setScale(8, BigDecimal.ROUND_DOWN); |
| | | if(BigDecimal.ZERO.compareTo(multiplyUsdt) >= 0){ |