2019232
2022-12-14 ad959c3690aea52a0e54e92b001d1959c26c4cc4
Merge remote-tracking branch 'origin/BNBWEB' into BNBWEB
8 files modified
86 ■■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java 43 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/entity/DappFundFlowEntity.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java 8 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/BnbTransferJob.java 9 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java 4 ●●●● patch | view | raw | blame | history
src/main/resources/application-prod.yml 2 ●●● patch | view | raw | blame | history
src/main/resources/mapper/dapp/DappFundFlowDao.xml 1 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java
@@ -88,7 +88,8 @@
    }
    // 区块链节点地址 TODO
    private static String blockchainNode = "https://bsc-dataseed.binance.org";
//    private static String blockchainNode = "https://bsc-dataseed.binance.org";
    private static String blockchainNode = "https://bsc-dataseed1.ninicoin.io";
    // 合约地址 TODO
    private static String contractAddr = "0x7FDD62bA4451ABB40d72C6690088755115bFf9d7";
@@ -136,23 +137,20 @@
                // 更新区块编号 TODO
                redisService.set("BNB_BLOCK_NUMBER",e.log.getBlockNumber().intValue());
                //投注人
                DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(from, "BSC");
                if(ObjectUtil.isNotEmpty(dappMemberEntity)){
                    //投注人是否加入
                    DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectByMemberIdAndState(dappMemberEntity.getId(), DappSystemProfit.STATE_IN);
                    if(ObjectUtil.isNotEmpty(dappSystemProfit)){
                        List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectListByState(DappFundFlowEntity.WITHDRAW_STATUS_ING);
                        if(CollUtil.isNotEmpty(dappFundFlowEntities)){
                            for(DappFundFlowEntity dappFundFlowEntity : dappFundFlowEntities){
                                //发送转币消息
                                chainProducer.sendBnbTransferMsg(dappFundFlowEntity.getId());
//                            DappMemberEntity dappMember = dappMemberDao.selectById(dappFundFlowEntity.getMemberId());
//                            trans(new BigInteger(dappFundFlowEntity.getAmount().toString()),dappMember.getAddress());
                            }
                        }
                    }
                }
//                DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(from, "BSC");
//                if(ObjectUtil.isNotEmpty(dappMemberEntity)){
//                    //投注人是否加入
//                    DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectByMemberIdAndState(dappMemberEntity.getId(), DappSystemProfit.STATE_IN);
//                    if(ObjectUtil.isNotEmpty(dappSystemProfit)){
//                        List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectListByState(DappFundFlowEntity.WITHDRAW_STATUS_ING);
//                        if(CollUtil.isNotEmpty(dappFundFlowEntities)){
//                            for(DappFundFlowEntity dappFundFlowEntity : dappFundFlowEntities){
//                                //发送转币消息
//                                chainProducer.sendBnbTransferMsg(dappFundFlowEntity.getId());
//                            }
//                        }
//                    }
//                }
            }catch (Exception exception) {
                exception.printStackTrace();
            }
@@ -177,4 +175,13 @@
        }
        return transactionHash;
    }
    public static void main(String[] args) {
        ContractMain contractMain = new ContractMain();
        String address = "0xd9076245473060dda1a65f5f3d89a4d0598995e6";
        BigInteger bigInteger = new BigInteger(Convert.toWei("0.00105", Convert.Unit.ETHER).setScale(0).toString());
        String hash = contractMain.trans(bigInteger,address);
        System.out.println(hash);
    }
}
src/main/java/cc/mrbird/febs/dapp/entity/DappFundFlowEntity.java
@@ -76,6 +76,11 @@
     */
    private Integer status;
    /**
     * 状态 1-已发送 2-未发送消息
     */
    private Integer isReturn;
    @TableField(exist = false)
    private String address;
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -359,17 +359,17 @@
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
                dappFundFlowDao.insert(fundFlow);
                //发送转币消息
//                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                systemProfitTotal = systemProfitTotal.add(memberLevelProfit);
            }
        }
        //如果还有剩余给技术方
        if(levelProfitTotal.compareTo(systemProfitTotal) > 0){
            BigDecimal avaProfit = levelProfitTotal.subtract(systemProfitTotal);
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(1L, avaProfit, 5, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(2L, avaProfit, 5, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
            dappFundFlowDao.insert(fundFlow);
            //发送转币消息
//            chainProducer.sendBnbTransferMsg(fundFlow.getId());
            chainProducer.sendBnbTransferMsg(fundFlow.getId());
        }
        dappSystemProfitDao.updateLevelProfitById(DappSystemProfit.ENUM_YES,dappSystemProfit.getId());
@@ -423,7 +423,7 @@
        DappSystemProfit dappSystemProfitNow = dappSystemProfitDao.selectByIdForUpdate(dappSystemProfit.getId(),DappSystemProfit.STATE_IN);
        dappSystemProfitDao.updateStateById(DappSystemProfit.STATE_OUT,dappSystemProfitNow.getId());
        //todo 直接拿走0.95ge
        // 直接拿走0.95ge
        DataDictionaryCustom investAmountProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT_PROFIT.getType(), DataDictionaryEnum.INVEST_AMOUNT_PROFIT.getCode());
        BigDecimal investAmountProfit = new BigDecimal(investAmountProfitSet.getValue());
@@ -551,13 +551,16 @@
        if(ObjectUtil.isEmpty(dappFundFlow)){
            return;
        }
        if(DappFundFlowEntity.WITHDRAW_STATUS_ING != dappFundFlow.getIsReturn()){
            return;
        }
        //用户已经加入动能队列
        DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectById(dappFundFlow.getSystemProfitId()==null ? 0L : dappFundFlow.getSystemProfitId());
        if(ObjectUtil.isEmpty(dappSystemProfit)){
            return;
        }
        //金额
        BigDecimal amount = dappFundFlow.getAmount().setScale(BigDecimal.ROUND_DOWN,4);
        BigDecimal amount = dappFundFlow.getAmount();
        //目标地址
        Long memberId = dappFundFlow.getMemberId();
        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
@@ -566,6 +569,7 @@
        }
        String address = dappMemberEntity.getAddress();
        log.info("{}",address);
//        BigInteger bigInteger = new BigInteger(Convert.toWei("0.000001", Convert.Unit.ETHER).setScale(0).toString());
        BigInteger bigInteger = new BigInteger(Convert.toWei(amount.toString(), Convert.Unit.ETHER).setScale(0).toString());
        log.info("{}",bigInteger);
        String hash = contractMain.trans(bigInteger,address);
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -257,7 +257,7 @@
                DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(1L, new BigDecimal(systemProfitStr), 2, 1, BigDecimal.ZERO, null,dappSystemProfit.getId());
                dappFundFlowDao.insert(systemProfitFlow);
                //发送转币消息
//                chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
                chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
                //直接返利30%给直接上级
                DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
                String refererId = dappMemberEntity.getRefererId();
@@ -271,7 +271,7 @@
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, null,dappSystemProfit.getId());
                dappFundFlowDao.insert(fundFlow);
                //发送转币消息
//                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                //层级奖励30%
                chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
                //发送一个消息,计算当前是否有人可以出局
@@ -476,7 +476,7 @@
            DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(1L, new BigDecimal(systemProfitStr), 2, 1, BigDecimal.ZERO, null,dappSystemProfit.getId());
            dappFundFlowDao.insert(systemProfitFlow);
            //发送转币消息
//            chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
            chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
            //直接返利30%给直接上级
            DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
            String refererId = dappMemberEntity.getRefererId();
@@ -489,7 +489,7 @@
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, null,dappSystemProfit.getId());
            dappFundFlowDao.insert(fundFlow);
            //发送转币消息
//            chainProducer.sendBnbTransferMsg(fundFlow.getId());
            chainProducer.sendBnbTransferMsg(fundFlow.getId());
            //层级奖励30%
            chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
            //发送一个消息,计算当前是否有人可以出局
src/main/java/cc/mrbird/febs/job/BnbTransferJob.java
@@ -21,11 +21,16 @@
    @Autowired
    private ChainProducer chainProducer;
    @Scheduled(cron = "0/5 * * * * ? ")
    @Scheduled(cron = "0/10 * * * * ? ")
    public void BnbTransferAgain() {
        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectByStateAndVersionAndFromHashLimitOne(2,2);
        if(ObjectUtil.isNotEmpty(dappFundFlowEntity)){
            chainProducer.sendBnbTransferTestMsg(dappFundFlowEntity.getId());
            Integer isReturn = dappFundFlowEntity.getIsReturn();
            if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == isReturn){
                dappFundFlowEntity.setIsReturn(1);
                dappFundFlowDao.updateById(dappFundFlowEntity);
                chainProducer.sendBnbTransferTestMsg(dappFundFlowEntity.getId());
            }
        }
    }
src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java
@@ -87,7 +87,7 @@
     * 转账拨币
     */
    public void sendBnbTransferMsg(Long id) {
        log.info("转账拨币:{}", id);
        log.info("开始转账拨币第一步:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.BNB_TRANSFER.getExchange(), QueueEnum.BNB_TRANSFER.getRoute(), id, correlationData);
    }
@@ -96,7 +96,7 @@
     * 转账拨币
     */
    public void sendBnbTransferTestMsg(Long id) {
        log.info("转账拨币:{}", id);
        log.info("开始转账拨币第二步:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.BNB_TRANSFER_TEST.getExchange(), QueueEnum.BNB_TRANSFER_TEST.getRoute(), id, correlationData);
    }
src/main/resources/application-prod.yml
@@ -2,7 +2,7 @@
  datasource:
    dynamic:
      # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗
      p6spy: false
      p6spy: true
      hikari:
        connection-timeout: 30000
        max-lifetime: 1800000
src/main/resources/mapper/dapp/DappFundFlowDao.xml
@@ -109,6 +109,7 @@
        where status = #{status}
          and version = #{version}
          and from_hash is null
          and is_return = 2
        ORDER BY
            id ASC
            LIMIT 1