xiaoyong931011
2023-06-04 f922185560da4b4001268d5a32ae6319e21a903f
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,9 +832,13 @@
                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,
                294L,
                poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
                FundFlowEnum.POOL_MEMBER_A_CNT.getCode(),
                2,
@@ -831,7 +847,7 @@
                chergeRecordId);
        dappFundFlowDao.insert(poolAllMemberAFundFlowAva);
        dappWalletService.updateWalletMineWithLock(poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
                1L,1);
                294L,1);
        /**
         * 10%直推
@@ -879,7 +895,7 @@
            }
            if(directAPercentCnt.compareTo(directAPercentFundFlowToMemberFlag) > 0){
                DappFundFlowEntity directAPercentFundFlowToMemberAva = new DappFundFlowEntity(
                        1L,
                        294L,
                        directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag),
                        FundFlowEnum.DIRECT_A_PERCENT.getCode(),
                        2,
@@ -888,7 +904,7 @@
                        chergeRecordId);
                dappFundFlowDao.insert(directAPercentFundFlowToMemberAva);
                dappWalletService.updateWalletMineWithLock(directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag),
                        1L,1);
                        294L,1);
            }
        }
        /**
@@ -924,7 +940,7 @@
        if(nodeAPercentCnt.compareTo(nodeAPercentCntAva) > 0){
            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
                    1L,
                    294L,
                    nodeAPercentCnt.subtract(nodeAPercentCntAva),
                    FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode(),
                    2,
@@ -933,7 +949,7 @@
                    chergeRecordId);
            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
            dappWalletService.updateWalletMineWithLock(nodeAPercentCnt.subtract(nodeAPercentCntAva),
                    1L,1);
                    294L,1);
        }
        /**
         * 5%基金会
@@ -947,7 +963,7 @@
        //生成一条5%基金会的资金流水记录
        DappFundFlowEntity foundationAPercentFundFlow = new DappFundFlowEntity(
                1L,
                295L,
                foundationAPercentCnt,
                FundFlowEnum.FOUNDATION_A_PERCENT.getCode(),
                2,
@@ -956,7 +972,7 @@
                chergeRecordId);
        dappFundFlowDao.insert(foundationAPercentFundFlow);
        //用户的A币账户增加memberGetACnt数量
        dappWalletService.updateWalletMineWithLock(foundationAPercentCnt,1L,1);
        dappWalletService.updateWalletMineWithLock(foundationAPercentCnt,295L,1);
        /**
         * 10%级差奖
         */
@@ -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) {
@@ -1181,7 +1258,7 @@
                    //用户的A币账户增加divide数量
                    if(amountTC.compareTo(teamIncomePerkTotal) > 0){
                        DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
                                1L,
                                294L,
                                subtract,
                                FundFlowEnum.LEVEL_A_PERCENT_CNT_MEMBER.getCode(),
                                2,
@@ -1190,7 +1267,7 @@
                                systemProfitId);
                        dappFundFlowDao.insert(nodeAPercentFundFlowAva);
                        dappWalletService.updateWalletMineWithLock(subtract,
                                1L,1);
                                294L,1);
                    }
                }
            }
@@ -1211,7 +1288,7 @@
        //用户的A币账户增加divide数量
        if(averagePerkCnt.compareTo(averagePerkCntAva) > 0){
            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
                    1L,
                    294L,
                    averagePerkCnt.subtract(averagePerkCntAva),
                    FundFlowEnum.DAO_3_NODE_PERK.getCode(),
                    2,
@@ -1220,7 +1297,7 @@
                    systemProfitId);
            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
            dappWalletService.updateWalletMineWithLock(averagePerkCnt.subtract(averagePerkCntAva),
                    1L,1);
                    294L,1);
        }
        //生成流水记录
        DappFundFlowEntity nodeThreeFundFlow = new DappFundFlowEntity(
@@ -1252,7 +1329,7 @@
        //用户的A币账户增加divide数量
        if(averagePerkFourCnt.compareTo(averagePerkFourCntAva) > 0){
            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
                    1L,
                    294L,
                    averagePerkFourCnt.subtract(averagePerkFourCntAva),
                    FundFlowEnum.DAO_4_NODE_PERK.getCode(),
                    2,
@@ -1261,7 +1338,7 @@
                    systemProfitId);
            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
            dappWalletService.updateWalletMineWithLock(averagePerkFourCnt.subtract(averagePerkFourCntAva),
                    1L,1);
                    294L,1);
        }
        DappFundFlowEntity nodeFourFundFlow = new DappFundFlowEntity(
                1L,
@@ -1291,7 +1368,7 @@
        //用户的A币账户增加divide数量
        if(averagePerkFiveCnt.compareTo(averagePerkFiveCntAva) > 0){
            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
                    1L,
                    294L,
                    averagePerkFiveCnt.subtract(averagePerkFiveCntAva),
                    FundFlowEnum.DAO_5_NODE_PERK.getCode(),
                    2,
@@ -1300,7 +1377,7 @@
                    systemProfitId);
            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
            dappWalletService.updateWalletMineWithLock(averagePerkFiveCnt.subtract(averagePerkFiveCntAva),
                    1L,1);
                    294L,1);
        }
        DappFundFlowEntity nodeFiveFundFlow = new DappFundFlowEntity(
                1L,
@@ -1332,7 +1409,7 @@
        //用户的A币账户增加divide数量
        if(nodeFiveEqualsCnt.compareTo(nodeFiveEqualsCntAva) > 0){
            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
                    1L,
                    294L,
                    nodeFiveEqualsCnt.subtract(nodeFiveEqualsCntAva),
                    FundFlowEnum.DAO_5_NODE_EQUALS_PERK.getCode(),
                    2,
@@ -1341,7 +1418,7 @@
                    systemProfitId);
            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
            dappWalletService.updateWalletMineWithLock(nodeFiveEqualsCnt.subtract(nodeFiveEqualsCntAva),
                    1L,1);
                    294L,1);
        }
        DappFundFlowEntity nodeFiveEqualsFundFlow = new DappFundFlowEntity(
                1L,
@@ -1450,7 +1527,8 @@
        //获取type级别的会员
        List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectMemberByAccountTypeAnd(type);
        //每日补贴总数
        BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT);
//        BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT);
        BigDecimal nodePerk = nodeFivePoolDicCnt;
        if(CollUtil.isNotEmpty(dappMemberEntities)){
            //每人的补贴
            BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberEntities.size()), 4, BigDecimal.ROUND_DOWN);
@@ -1684,6 +1762,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 +2003,7 @@
            redisKey = AppContants.K_LINE_MONTH;
        }else if(0 == type){
            createKDate();
            return;
            redisKey = AppContants.K_LINE_NOW;
        }else{
            return;
        }
@@ -1952,6 +2043,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 +2062,10 @@
    }
    public static void main(String[] args) {
        System.out.println(ChainEnum.BSC_USDT_W_POOL.getAddress());
    }
    /**
     * 生成当前分钟的k线数据,type为0
     */