From 7077ee9414f5c827f8d7c7ba3cc09071245803d6 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 13 Dec 2022 15:43:49 +0800
Subject: [PATCH] 20221213转币
---
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java | 4 +-
src/main/resources/mapper/dapp/DappFundFlowDao.xml | 7 +++
src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java | 46 ++++++++++++++++++++++
src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java | 2 +
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java | 8 ++--
src/main/java/cc/mrbird/febs/job/BnbTransferJob.java | 14 +++---
6 files changed, 67 insertions(+), 14 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java b/src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java
index 3377b2f..db152a4 100644
--- a/src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java
+++ b/src/main/java/cc/mrbird/febs/dapp/contract/ContractMain.java
@@ -1,5 +1,15 @@
package cc.mrbird.febs.dapp.contract;
+import cc.mrbird.febs.dapp.entity.DappFundFlowEntity;
+import cc.mrbird.febs.dapp.entity.DappMemberEntity;
+import cc.mrbird.febs.dapp.entity.DappSystemProfit;
+import cc.mrbird.febs.dapp.mapper.DappFundFlowDao;
+import cc.mrbird.febs.dapp.mapper.DappMemberDao;
+import cc.mrbird.febs.dapp.mapper.DappSystemProfitDao;
+import cc.mrbird.febs.rabbit.producer.ChainProducer;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
@@ -12,10 +22,24 @@
import org.web3j.tx.gas.StaticGasProvider;
import java.math.BigInteger;
+import java.util.List;
@Component
public class ContractMain {
+
+ @Autowired
+ private DappFundFlowDao dappFundFlowDao;
+
+ @Autowired
+ private DappMemberDao dappMemberDao;
+
+ @Autowired
+ private DappSystemProfitDao dappSystemProfitDao;
+
+ @Autowired
+ private ChainProducer chainProducer;
+
private static Web3j web3;
private static Web3j getInstance() {
@@ -44,7 +68,8 @@
private static String blockchainNode = "https://data-seed-prebsc-1-s1.binance.org:8545/";
// 合约地址 TODO
- private static String contractAddr = "0x8f444b9b9C71f4Be883aE15466D71EC7699Cb5B1";
+// private static String contractAddr = "0x8f444b9b9C71f4Be883aE15466D71EC7699Cb5B1";
+ private static String contractAddr = "0x4703cfEf33b6DbcF6a3020Ef98FC6ab9C4CC06b3";
// 操作账号 合约创建者的私钥 用于操作合约内方法 TODO
private static String privateKey = "8ea073b74265f41a03138e1adf2e8a80f4f394ac5337aa2eec07562c1040a4e4";
@@ -76,6 +101,25 @@
// 投注人的地址
String from = e.from;
// TODO 业务操作逻辑代码
+ //投注人
+ 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.selectListBySystemProfitIdAndState(dappSystemProfit.getId(),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());
+ }
+ }
+ }
+ }
+
});
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java b/src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java
index d3e5311..3f73b6c 100644
--- a/src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java
+++ b/src/main/java/cc/mrbird/febs/dapp/mapper/DappFundFlowDao.java
@@ -36,4 +36,6 @@
DappFundFlowEntity selectByStateAndVersionAndFromHashLimitOne(@Param("status")int withdrawStatusAgree, @Param("version")int withdrawStatusAgree1);
DappFundFlowEntity selectBymemberIdAndType(@Param("memberId")Long id, @Param("type")int type);
+
+ List<DappFundFlowEntity> selectListBySystemProfitIdAndState(@Param("systemProfitId")Long id, @Param("status")int status);
}
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 054371f..e6999fc 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
@@ -355,7 +355,7 @@
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);
}
}
@@ -365,7 +365,7 @@
DappFundFlowEntity fundFlow = new DappFundFlowEntity(1L, 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());
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 ae6f35b..672f6f7 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
@@ -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());
//发送一个消息,计算当前是否有人可以出局
diff --git a/src/main/java/cc/mrbird/febs/job/BnbTransferJob.java b/src/main/java/cc/mrbird/febs/job/BnbTransferJob.java
index 5c75555..f691cb5 100644
--- a/src/main/java/cc/mrbird/febs/job/BnbTransferJob.java
+++ b/src/main/java/cc/mrbird/febs/job/BnbTransferJob.java
@@ -21,12 +21,12 @@
@Autowired
private ChainProducer chainProducer;
- @Scheduled(cron = "0/5 * * * * ? ")
- public void BnbTransferAgain() {
- DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectByStateAndVersionAndFromHashLimitOne(2,2);
- if(ObjectUtil.isNotEmpty(dappFundFlowEntity)){
- chainProducer.sendBnbTransferTestMsg(dappFundFlowEntity.getId());
- }
- }
+// @Scheduled(cron = "0/5 * * * * ? ")
+// public void BnbTransferAgain() {
+// DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectByStateAndVersionAndFromHashLimitOne(2,2);
+// if(ObjectUtil.isNotEmpty(dappFundFlowEntity)){
+// chainProducer.sendBnbTransferTestMsg(dappFundFlowEntity.getId());
+// }
+// }
}
diff --git a/src/main/resources/mapper/dapp/DappFundFlowDao.xml b/src/main/resources/mapper/dapp/DappFundFlowDao.xml
index f0600b7..92574b1 100644
--- a/src/main/resources/mapper/dapp/DappFundFlowDao.xml
+++ b/src/main/resources/mapper/dapp/DappFundFlowDao.xml
@@ -119,4 +119,11 @@
where member_id = #{memberId}
and type = #{type}
</select>
+
+ <select id="selectListBySystemProfitIdAndState" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
+ select *
+ from dapp_fund_flow
+ where system_profit_id = #{systemProfitId}
+ and status = #{status}
+ </select>
</mapper>
\ No newline at end of file
--
Gitblit v1.9.1