xiaoyong931011
2023-06-02 63e846810263e5abf50ed9f9a313c3de928a5739
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -677,10 +677,10 @@
                PoolEnum.USDT_A_PERCENT.getType(),
                PoolEnum.USDT_A_PERCENT.getCode()
        );
        BigDecimal usdtAPercent = new BigDecimal(StrUtil.isEmpty(usdtAPercentDic.getValue()) ? "0.9" : usdtAPercentDic.getValue());
        BigDecimal usdtAPercent = new BigDecimal(StrUtil.isEmpty(usdtAPercentDic.getValue()) ? "0.7" : usdtAPercentDic.getValue());
        BigDecimal usdtAAmount = amount.multiply(usdtAPercent).setScale(4, BigDecimal.ROUND_DOWN);
        //生成一条进行中的90%进入A币底池的资金流水记录
        //生成一条进行中的70%进入A币底池的资金流水记录
        DappFundFlowEntity fundFlowToA = new DappFundFlowEntity(
                1L,
                usdtAAmount,
@@ -692,6 +692,18 @@
        dappFundFlowDao.insert(fundFlowToA);
        //90%进入A币底池
        chainProducer.sendAntACoinInAPoolMsg(fundFlowToA.getId());
        BigDecimal usdtWAmount = amount.multiply(new BigDecimal(0.2)).setScale(4, BigDecimal.ROUND_DOWN);
        //生成一条进行中的20%进入A币底池的资金流水记录
        DappFundFlowEntity fundFlowToW = new DappFundFlowEntity(
                1L,
                usdtWAmount,
                FundFlowEnum.USDT_IN_W_POOL.getCode(),
                1,
                BigDecimal.ZERO,
                null,
                chergeRecordId);
        dappFundFlowDao.insert(fundFlowToW);
        DataDictionaryCustom usdtBPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PoolEnum.USDT_B_PERCENT.getType(),
@@ -820,7 +832,11 @@
                chergeRecordId);
        dappFundFlowDao.insert(poolAllMemberAFundFlow);
        BigDecimal poolAllMemberAPercentCntAva = nodePoolPerk(poolAllMemberAPercentCnt, MemberLevelEnum.MEMBER.getType(), FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
//        BigDecimal poolAllMemberAPercentCntAva = nodePoolPerk(poolAllMemberAPercentCnt, MemberLevelEnum.MEMBER.getType(), FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
        /**
         * 20%全网加权平分,按照个人投资占比全网的比例去平分
         */
        BigDecimal poolAllMemberAPercentCntAva = allMemberPerk(poolAllMemberAPercentCnt, FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
        DappFundFlowEntity poolAllMemberAFundFlowAva = new DappFundFlowEntity(
                1L,
                poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
@@ -986,6 +1002,60 @@
    }
    private BigDecimal allMemberPerk(BigDecimal poolAllMemberAPercentCnt, int code) {
        BigDecimal realPerkAmount = BigDecimal.ZERO;
        /**
         * 查询总业绩
         */
        List<DappChargeUsdtEntity> dappChargeUsdtEntities = dappChargeUsdtMapper.selectList(null);
        if(CollUtil.isEmpty(dappChargeUsdtEntities)){
            return realPerkAmount;
        }
        //总入金
        BigDecimal amountAll = dappChargeUsdtEntities.stream().map(DappChargeUsdtEntity::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        if(BigDecimal.ZERO.compareTo(amountAll) >= 0){
            return realPerkAmount;
        }
        /**
         * 每个人入金的总额
         */
        Map<Long, BigDecimal> amountMap = dappChargeUsdtEntities.stream().collect(
                Collectors.groupingBy(DappChargeUsdtEntity::getMemberId,
                        Collectors.reducing(BigDecimal.ZERO, DappChargeUsdtEntity::getAmount, BigDecimal::add)));
        /**
         * 入金1U分的代币个数
         */
        BigDecimal usdtOfCnt = poolAllMemberAPercentCnt.divide(amountAll, 8, BigDecimal.ROUND_DOWN);
        for (Map.Entry<Long, BigDecimal> entry : amountMap.entrySet()) {
            Long memberId = entry.getKey();
            //当前会员的入金总和
            BigDecimal amount = entry.getValue();
            if(BigDecimal.ZERO.compareTo(amount) >= 0){
                continue;
            }
            //应该平分到的数量
            BigDecimal memberCnt = amount.multiply(usdtOfCnt).setScale(8,BigDecimal.ROUND_DOWN);
            BigDecimal fundFlowToMemberFlag = this.getAndUpdateMemberPerk(memberId, memberCnt);
            if(fundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){
                //生成一条50%客户秒到的资金流水记录
                DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity(
                        memberId,
                        fundFlowToMemberFlag,
                        code,
                        2,
                        BigDecimal.ZERO);
                dappFundFlowDao.insert(fundFlowToMember);
                //用户的A币账户增加memberGetACnt数量
                dappWalletService.updateWalletMineWithLock(fundFlowToMemberFlag,memberId,1);
                realPerkAmount = realPerkAmount.add(fundFlowToMemberFlag);
            }
        }
        return realPerkAmount;
    }
    @Override
    public void AntACoinAPollInMsg(Long id) {
        log.info("{}",id);
@@ -998,6 +1068,13 @@
        BigDecimal amount = dappFundFlowEntity.getAmount();
        //目标地址
        String address = AppContants.ADDRESS_A_POOL_PEOJECT;
        if(5 == dappFundFlowEntity.getType()){
            address = AppContants.ADDRESS_A_POOL_PEOJECT;
        }else if(34 == dappFundFlowEntity.getType() ){
            address = ChainEnum.BSC_USDT_W_POOL.getAddress();
        }else{
            return;
        }
        /**
         * 发起USDT转账
         */
@@ -1011,13 +1088,13 @@
        dappFundFlowDao.updateById(dappFundFlowEntity);
    }
    public static void main(String[] args) {
        String address = AppContants.ADDRESS_A_POOL_PEOJECT;
        /**
         * 发起USDT转账
         */
        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, new BigDecimal("0.01"));
    }
//    public static void main(String[] args) {
//        String address = AppContants.ADDRESS_A_POOL_PEOJECT;
//        /**
//         * 发起USDT转账
//         */
//        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, new BigDecimal("0.01"));
//    }
    @Override
    public void AntACoinBPollInMsg(Long id) {
@@ -1684,6 +1761,19 @@
        dappAKlineEntity.setHighestPrice(coinAPrice);
        dappAKlineEntity.setClosePrice(coinAPrice);
        dappAKlineMapper.insert(dappAKlineEntity);
        List<cn.hutool.json.JSONObject> objects = new ArrayList<>();
        List<AKLineLimitVo> akLineLimitVos = dappAKlineMapper.selectListByTypeAndLimit(0, AppContants.K_LINE_LIMIT);
        if(CollUtil.isNotEmpty(akLineLimitVos)) {
            Collections.reverse(akLineLimitVos);
            for (AKLineLimitVo akLineLimitVo : akLineLimitVos) {
                cn.hutool.json.JSONObject parseObj = JSONUtil.parseObj(akLineLimitVo);
                objects.add(parseObj);
            }
            redisUtils.del(AppContants.K_LINE_NOW);
            redisUtils.set(AppContants.K_LINE_NOW, objects.toString());
        }
    }
    @Override
@@ -1912,7 +2002,7 @@
            redisKey = AppContants.K_LINE_MONTH;
        }else if(0 == type){
            createKDate();
            return;
            redisKey = AppContants.K_LINE_NOW;
        }else{
            return;
        }
@@ -1952,6 +2042,8 @@
            address = AppContants.ADDRESS_A_POOL_PEOJECT;
        }else if(6 == dappFundFlowEntity.getType()){
            address = AppContants.ADDRESS_B_POOL_PEOJECT;
        }else if(34 == dappFundFlowEntity.getType()){
            address = ChainEnum.BSC_USDT_W_POOL.getAddress();
        }else{
            return;
        }
@@ -1969,6 +2061,10 @@
    }
    public static void main(String[] args) {
        System.out.println(ChainEnum.BSC_USDT_W_POOL.getAddress());
    }
    /**
     * 生成当前分钟的k线数据,type为0
     */