From b603c6cfda6ff46e09310d724d0b7374db12496b Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 30 Nov 2022 11:40:55 +0800
Subject: [PATCH] 20221124

---
 src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java |   41 ++++++++++++++++++--
 src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java           |    8 ++++
 src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java          |    2 +
 lib/client-0.4.0.jar                                                      |    0 
 lib/utils-0.4.0.jar                                                       |    0 
 src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java |   18 +++++++--
 src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java                   |    1 
 src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java                        |    2 +
 lib/abi-0.4.0.jar                                                         |    0 
 src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java           |    9 ++++
 src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java              |   19 +++++++++
 11 files changed, 92 insertions(+), 8 deletions(-)

diff --git a/lib/abi-0.4.0.jar b/lib/abi-0.4.0.jar
new file mode 100644
index 0000000..cf65d8d
--- /dev/null
+++ b/lib/abi-0.4.0.jar
Binary files differ
diff --git a/lib/client-0.4.0.jar b/lib/client-0.4.0.jar
new file mode 100644
index 0000000..4785a17
--- /dev/null
+++ b/lib/client-0.4.0.jar
Binary files differ
diff --git a/lib/utils-0.4.0.jar b/lib/utils-0.4.0.jar
new file mode 100644
index 0000000..a8175ab
--- /dev/null
+++ b/lib/utils-0.4.0.jar
Binary files differ
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java b/src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java
index 560c568..5300a2b 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java
@@ -28,4 +28,6 @@
     void levelProfit(Long id);
     //计算是否有人出局
     void memberOut(Long id);
+    //转账拨币
+    void bnbTransfer(Long id);
 }
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
index 4b8702d..d33ade5 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -52,6 +52,7 @@
     private final DappWalletService dappWalletService;
     private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
     private final DappSystemProfitDao dappSystemProfitDao;
+    private final ChainProducer chainProducer;
 
 
     @Override
@@ -338,16 +339,20 @@
 
                 BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit).multiply(memberLevel);
 
-                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
+                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
                 dappFundFlowDao.insert(fundFlow);
+                //发送转币消息
+                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                 systemProfitTotal = systemProfitTotal.add(memberLevelProfit);
             }
         }
         //如果还有剩余给技术方
         if(levelProfitTotal.compareTo(systemProfitTotal) > 0){
             BigDecimal avaProfit = levelProfitTotal.subtract(systemProfit);
-            DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
+            DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
             dappFundFlowDao.insert(fundFlow);
+            //发送转币消息
+            chainProducer.sendBnbTransferMsg(fundFlow.getId());
         }
     }
 
@@ -401,14 +406,16 @@
         dappSystemProfitDao.updateById(dappSystemProfitNow);
 
         //todo 直接拿走0.95ge
-        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 2, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
+        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 1, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
         dappFundFlowDao.insert(fundFlowOut);
+        //发送转币消息
+        chainProducer.sendBnbTransferMsg(fundFlowOut.getId());
         //复投 成功{type: 1, txHash: result.transactionHash, id: res.data, flag: 'success', buyType: 2}
         DataDictionaryCustom investAmountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT.getType(), DataDictionaryEnum.INVEST_AMOUNT.getCode());
         BigDecimal investAmount = new BigDecimal(investAmountSet.getValue());
         //todo 直接运行转账
         String txHash = "复投";
-        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 2, BigDecimal.ZERO, txHash);
+        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 1, BigDecimal.ZERO, txHash);
         dappFundFlowDao.insert(fundFlow);
 
         TransferDto transferDto = new TransferDto();
@@ -421,6 +428,32 @@
         dappWalletService.transferAgain(transferDto);
     }
 
+    @Override
+    public void bnbTransfer(Long id) {
+        //获取对应的流水记录
+        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id);
+        if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == dappFundFlowEntity.getStatus()){
+            return;
+        }
+        //金额
+        BigDecimal amount = dappFundFlowEntity.getAmount();
+        Long memberId = dappFundFlowEntity.getMemberId();
+        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
+        if(ObjectUtil.isEmpty(dappMemberEntity)){
+            return;
+        }
+        //目标地址
+        String address = dappMemberEntity.getAddress();
+        String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(address, amount);
+        if(StrUtil.isEmpty(hash)){
+            return;
+        }
+        dappFundFlowEntity.setToHash(hash);
+        dappFundFlowEntity.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
+        dappFundFlowDao.updateById(dappFundFlowEntity);
+
+    }
+
     public static void main(String[] args) {
         String refererIds = "1,2,3,4,5," +
                             "6,7,8,9,10," +
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
index 136444d..e1615c5 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -180,13 +180,16 @@
                 DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
                 flow.setFromHash(transferDto.getTxHash());
                 flow.setSystemProfitId(dappSystemProfit.getId());
+                flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
                 dappFundFlowDao.updateById(flow);
 
                 //直接拿走0.05个BNB放入技术方
                 DataDictionaryCustom systemProfit = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode());
                 String systemProfitStr = StrUtil.isEmpty(systemProfit.getValue()) ? "0.05" : systemProfit.getValue();
-                DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
+                DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
                 dappFundFlowDao.insert(systemProfitFlow);
+                //发送转币消息
+                chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
                 //直接返利30%给直接上级
                 DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
                 String refererId = dappMemberEntity.getRefererId();
@@ -196,8 +199,10 @@
                 BigDecimal directProfitStr = new BigDecimal(StrUtil.isEmpty(directProfitSet.getValue()) ? "0.3" : directProfitSet.getValue());
                 BigDecimal directProfit = (transferDto.getAmount().subtract(new BigDecimal(systemProfitStr))).multiply(directProfitStr).setScale(BigDecimal.ROUND_DOWN, 2);
                 
-                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
+                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
                 dappFundFlowDao.insert(fundFlow);
+                //发送转币消息
+                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                 //层级奖励30%
                 chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
                 //发送一个消息,计算当前是否有人可以出局
@@ -388,13 +393,16 @@
             DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
             flow.setFromHash(transferDto.getTxHash());
             flow.setSystemProfitId(dappSystemProfit.getId());
+            flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
             dappFundFlowDao.updateById(flow);
 
             //直接拿走0.05个BNB放入技术方
             DataDictionaryCustom systemProfit = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode());
             String systemProfitStr = StrUtil.isEmpty(systemProfit.getValue()) ? "0.05" : systemProfit.getValue();
-            DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
+            DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
             dappFundFlowDao.insert(systemProfitFlow);
+            //发送转币消息
+            chainProducer.sendBnbTransferMsg(systemProfitFlow.getId());
             //直接返利30%给直接上级
             DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
             String refererId = dappMemberEntity.getRefererId();
@@ -404,8 +412,10 @@
             BigDecimal directProfitStr = new BigDecimal(StrUtil.isEmpty(directProfitSet.getValue()) ? "0.3" : directProfitSet.getValue());
             BigDecimal directProfit = (transferDto.getAmount().subtract(new BigDecimal(systemProfitStr))).multiply(directProfitStr).setScale(BigDecimal.ROUND_DOWN, 2);
 
-            DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
+            DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 1, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
             dappFundFlowDao.insert(fundFlow);
+            //发送转币消息
+            chainProducer.sendBnbTransferMsg(fundFlow.getId());
             //层级奖励30%
             chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
             //发送一个消息,计算当前是否有人可以出局
diff --git a/src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java b/src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java
index 7e7fcc4..1e9fbc3 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/QueueConstants.java
@@ -6,6 +6,7 @@
  **/
 public class QueueConstants {
 
+    public static final String QUEUE_BNB_TRANSFER = "queue_bnb_transfer";
     public static final String QUEUE_MEMBER_OUT = "queue_bnb_member_out";
     public static final String QUEUE_LEVEL_PROFIT = "queue_bnb_level_profit_transfer";
 
diff --git a/src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java b/src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java
index ad493b6..bde8845 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/QueueEnum.java
@@ -5,6 +5,8 @@
 
 @Getter
 public enum QueueEnum {
+    //转账拨币
+    BNB_TRANSFER("exchange_bnb_transfer", "route_key_bnb_transfer", "queue_bnb_transfer"),
     //计算是否有人出局
     MEMBER_OUT("exchange_bnb_member_out", "route_key_bnb_member_out", "queue_bnb_member_out"),
     //层级奖励
diff --git a/src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java b/src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java
index a8a326e..01f00dd 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/RabbitConfiguration.java
@@ -139,4 +139,23 @@
         return BindingBuilder.bind(memberOutQueue()).to(memberOutExchange()).with(QueueEnum.MEMBER_OUT.getRoute());
     }
     // === 计算是否有人出局 end ===
+
+
+
+    // === 转账拨币 start ===
+    @Bean
+    public DirectExchange bnbTransferExchange() {
+        return new DirectExchange(QueueEnum.BNB_TRANSFER.getExchange());
+    }
+
+    @Bean
+    public Queue bnbTransferQueue() {
+        return new Queue(QueueEnum.BNB_TRANSFER.getQueue());
+    }
+
+    @Bean
+    public Binding bnbTransferBind() {
+        return BindingBuilder.bind(bnbTransferQueue()).to(bnbTransferExchange()).with(QueueEnum.BNB_TRANSFER.getRoute());
+    }
+    // === 转账拨币 end ===
 }
diff --git a/src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java b/src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java
index 12910ed..ad37063 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java
@@ -60,4 +60,12 @@
     public void memberOut(Long id) {
         dappSystemService.memberOut(id);
     }
+
+    /**转账拨币
+     * @param id
+     */
+    @RabbitListener(queues = QueueConstants.QUEUE_BNB_TRANSFER)
+    public void bnbTransfer(Long id) {
+        dappSystemService.bnbTransfer(id);
+    }
 }
diff --git a/src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java b/src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java
index becb798..ff8c0b4 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java
@@ -82,4 +82,13 @@
         CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
         rabbitTemplate.convertAndSend(QueueEnum.LEVEL_PROFIT.getExchange(), QueueEnum.LEVEL_PROFIT.getRoute(), id, correlationData);
     }
+
+    /**
+     * 转账拨币
+     */
+    public void sendBnbTransferMsg(Long id) {
+        log.info("转账拨币:{}", id);
+        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+        rabbitTemplate.convertAndSend(QueueEnum.BNB_TRANSFER.getExchange(), QueueEnum.BNB_TRANSFER.getRoute(), id, correlationData);
+    }
 }

--
Gitblit v1.9.1