| | |
| | | import cc.mrbird.febs.dapp.utils.OnlineTransferUtil; |
| | | import cc.mrbird.febs.dapp.vo.RedisTransferPoolVo; |
| | | import cc.mrbird.febs.dapp.vo.SlipSettingVo; |
| | | import cc.mrbird.febs.job.SystemTradeJob; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | |
| | | private final DappOnlineTransferDao dappOnlineTransferDao; |
| | | private final ChainProducer chainProducer; |
| | | |
| | | private final String[] ADDRESS_PREFIX = {"T", "0x"}; |
| | | |
| | | @Override |
| | | public Map<String, Object> findTotalInComeAndList() { |
| | | DappMineDataEntity dataMine = dappSystemDao.selectMineDataForOne(); |
| | | |
| | | List<DappMemberEntity> addresses = dappMemberDao.selectList(null); |
| | | DappMemberEntity mineAddress = dappMemberDao.selectByAddress(ChainEnum.BSC_TFC.getAddress(), null); |
| | | BigDecimal coinCnt = dappMemberDao.selectAllBalance("normal"); |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("total", 6000); |
| | | result.put("addreessCnt", 1234); |
| | | result.put("coinCnt", 4000); |
| | | result.put("total", mineAddress.getBalance()); |
| | | result.put("addreessCnt", addresses.size()); |
| | | result.put("coinCnt", coinCnt); |
| | | return result; |
| | | } |
| | | |
| | |
| | | |
| | | ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | BigDecimal balance = instance.balanceOf(member.getAddress()); |
| | | |
| | | Object o = redisUtils.get(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress()); |
| | | |
| | | BigDecimal coinTotal = balance.multiply(BigDecimal.valueOf(0.3)).setScale(instance.decimals(), RoundingMode.HALF_DOWN); |
| | | BigDecimal remain; |
| | | if (o == null) { |
| | | DateTime tomorrow = DateUtil.beginOfDay(DateUtil.tomorrow()); |
| | | long time = DateUtil.between(new Date(), tomorrow, DateUnit.SECOND, true); |
| | | |
| | | remain = coinTotal; |
| | | redisUtils.set(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress(), remain); |
| | | redisUtils.set(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress(), remain, time); |
| | | } else { |
| | | remain = (BigDecimal) o; |
| | | } |
| | |
| | | |
| | | OnlineTransferUtil.addTransfer(parent.getAddress(), total, fundflow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | DappFundFlowEntity distribFlow = new DappFundFlowEntity(parent.getId(), total, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(distribFlow); |
| | | |
| | | nodeAmount = nodeAmount.subtract(total); |
| | | i++; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void mining() { |
| | | log.info("挖矿"); |
| | | ContractChainService contract = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | // 发行量 |
| | | BigInteger totalSupply = contract.totalSupply(); |
| | | |
| | | Object o = redisUtils.get(AppContants.REDIS_KEY_MINE_ALL_INTERNET_CNT); |
| | | if (o == null) { |
| | | return; |
| | | BigDecimal totalUnHold = contract.balanceOf(AppContants.DESTROY_ADDRESS); |
| | | List<DappMemberEntity> admin = dappMemberDao.selectMemberByAccountType("admin"); |
| | | for (DappMemberEntity member : admin) { |
| | | totalUnHold = totalUnHold.add(contract.balanceOf(member.getAddress())); |
| | | } |
| | | |
| | | Object transferPoolObj = redisUtils.get(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT); |
| | | |
| | | BigDecimal allInternet = (BigDecimal) o; |
| | | // 全网持币量 |
| | | BigDecimal allInternet = new BigDecimal(totalSupply).subtract(totalUnHold); |
| | | // 中转池交易量 |
| | | BigDecimal transferPoll = (BigDecimal) transferPoolObj; |
| | | |
| | | List<DappMemberEntity> allMembers = dappMemberDao.selectList(null); |
| | |
| | | continue; |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), mine, 3, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | OnlineTransferUtil.addTransfer(member.getAddress(), mine, 3, 1, ChainEnum.BSC_TFC.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | member.setBalance(balance); |
| | | dappMemberDao.updateById(member); |
| | | } |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void userBuyReward(Long id) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id); |
| | | |
| | | DappMemberEntity member = dappMemberDao.selectById(fundFlow.getMemberId()); |
| | | DappMemberEntity referer = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if (referer == null || "admin".equals(referer.getAccountType())) { |
| | | return; |
| | | } |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_USER_BUY_REWARD); |
| | | BigDecimal prop = new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP); |
| | | BigDecimal reward = fundFlow.getAmount().multiply(prop); |
| | | |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC_REWARD.name()).balanceOf(ChainEnum.BSC_TFC_REWARD.getAddress()); |
| | | if (balance.compareTo(reward) < 1) { |
| | | return; |
| | | } |
| | | |
| | | DappFundFlowEntity rewardFlow = new DappFundFlowEntity(referer.getId(), reward, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(rewardFlow); |
| | | |
| | | OnlineTransferUtil.addTransfer(referer.getAddress(), reward, 4, 1, ChainEnum.BSC_TFC_REWARD.name(), AppContants.SYMBOL_COIN, rewardFlow.getId().toString()); |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", rewardFlow.getId().toString()); |
| | | map.put("type", "batch"); |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | @Autowired |
| | | private SystemTradeJob systemTradeJob; |
| | | |
| | | @Override |
| | | public void startSystem() { |
| | | log.info("启动系统"); |
| | | |
| | | Thread thread = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | systemTradeJob.transferPoolVol(); |
| | | systemTradeJob.sourcePoolUsdtOutLimit(); |
| | | } |
| | | }); |
| | | |
| | | thread.start(); |
| | | } |
| | | } |