| | |
| | | import cc.mrbird.febs.mall.quartz.OrderSettlementJob; |
| | | import cc.mrbird.febs.mall.service.*; |
| | | import cc.mrbird.febs.mall.vo.ApiMallSubsidyAmountInfoVo; |
| | | import cc.mrbird.febs.mall.vo.MallOrderInfoTestVo; |
| | | import cc.mrbird.febs.pay.model.*; |
| | | import cc.mrbird.febs.pay.service.UnipayService; |
| | | import cc.mrbird.febs.rabbit.consumer.AgentConsumer; |
| | |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.web3j.crypto.Credentials; |
| | | import org.web3j.crypto.WalletUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | |
| | | @Autowired |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Autowired |
| | | private IApiMallMemberWalletService walletService; |
| | | |
| | | @Autowired |
| | | private MallMemberWalletMapper mallMemberWalletMapper; |
| | | |
| | | @Test |
| | | public void retrunOrder(){ |
| | | /** |
| | | * 查询出当天下过单的人数 |
| | | * 比对单数是否超过最大值,超过最大值的订单回退资金,删除数据 |
| | | */ |
| | | String dateStr = "2023-04-01"; |
| | | //获取某一天下单人的全部单数 |
| | | List<MallOrderInfoTestVo> mallOrderInfoTestVos = mallOrderInfoMapper.selectOrderCntByDate(dateStr); |
| | | if(CollUtil.isNotEmpty(mallOrderInfoTestVos)){ |
| | | List<MallOrderInfoTestVo> collect = mallOrderInfoTestVos |
| | | .stream() |
| | | .filter(mallOrderInfoTestVo -> mallOrderInfoTestVo.getOrderCnt() > 2) |
| | | .collect(Collectors.toList()); |
| | | List<Long> collectMemberId = collect.stream().map(MallOrderInfoTestVo::getMemberId).collect(Collectors.toList()); |
| | | if(CollUtil.isNotEmpty(collectMemberId)){ |
| | | for(Long memberId : collectMemberId){ |
| | | List<MallOrderInfo> mallOrderInfos = mallOrderInfoMapper.selectByMemberIdAndDate(memberId,dateStr); |
| | | if(CollUtil.isNotEmpty(mallOrderInfos)){ |
| | | int size = mallOrderInfos.size(); |
| | | for(int i = 2; i < size; i++){ |
| | | MallOrderInfo mallOrderInfo = mallOrderInfos.get(i); |
| | | String orderNo = mallOrderInfo.getOrderNo(); |
| | | List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectMoneyFlowByOrderNo(orderNo); |
| | | for(MallMoneyFlow mallMoneyFlow : mallMoneyFlows){ |
| | | Long rtMemberId = mallMoneyFlow.getRtMemberId(); |
| | | BigDecimal amount = mallMoneyFlow.getAmount(); |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(rtMemberId); |
| | | if(mallMemberWallet.getBalance().compareTo(amount) >= 0){ |
| | | walletService.reduceBalance(amount, rtMemberId); |
| | | } |
| | | } |
| | | mallMoneyFlowMapper.deleteByOrderNo(orderNo); |
| | | mallOrderInfoMapper.deleteById(mallOrderInfo.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void retrunOrderMemberId(){ |
| | | String dateStr = "2023-04-02"; |
| | | Long memberId = 702L; |
| | | List<MallOrderInfo> mallOrderInfos = mallOrderInfoMapper.selectByMemberIdAndDate(memberId,dateStr); |
| | | if(CollUtil.isNotEmpty(mallOrderInfos)){ |
| | | int size = mallOrderInfos.size(); |
| | | for(int i = 2; i < size; i++){ |
| | | MallOrderInfo mallOrderInfo = mallOrderInfos.get(i); |
| | | String orderNo = mallOrderInfo.getOrderNo(); |
| | | List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectMoneyFlowByOrderNo(orderNo); |
| | | for(MallMoneyFlow mallMoneyFlow : mallMoneyFlows){ |
| | | Long rtMemberId = mallMoneyFlow.getRtMemberId(); |
| | | BigDecimal amount = mallMoneyFlow.getAmount(); |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(rtMemberId); |
| | | if(mallMemberWallet.getBalance().compareTo(amount) >= 0){ |
| | | walletService.reduceBalance(amount, rtMemberId); |
| | | } |
| | | } |
| | | mallMoneyFlowMapper.deleteByOrderNo(orderNo); |
| | | mallOrderInfoMapper.deleteById(mallOrderInfo.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void tetstgetPrikey(){ |
| | | Map<String, String> wallet = new HashMap<String, String>(); |
| | | try { |
| | | String walletPassword = "secr3t"; |
| | | // 文件路径 |
| | | String walletDirectory = "E:\\address"; |
| | | String walletName = "UTC--2023-01-13T08-03-47.600000000Z--aec294ac13f0a64c57a7b9ddb3aee5e791cff06a.json"; |
| | | |
| | | // String walletName = WalletUtils.generateNewWalletFile(walletPassword, new File(walletDirectory)); |
| | | // System.out.println("wallet location: " + walletDirectory + "/" + walletName); |
| | | Credentials credentials = WalletUtils.loadCredentials(walletPassword, walletDirectory + "/" + walletName); |
| | | String accountAddress = credentials.getAddress(); |
| | | String privateKey = credentials.getEcKeyPair().getPrivateKey().toString(16); |
| | | // 钱包地址 |
| | | wallet.put("address", accountAddress); |
| | | // 钱包私钥 |
| | | wallet.put("privateKey", privateKey); |
| | | System.out.println(accountAddress); |
| | | System.out.println(privateKey); |
| | | // 产生的钱包文件地址 |
| | | wallet.put("walletLocation", walletDirectory + "/" + walletName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void directorProfitTest() { |
| | |
| | | @Test |
| | | public void scorePool(){ |
| | | |
| | | String next = "0xc1be17a02127e5cc1e6b2298436e8b467531f798"; |
| | | MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbolTag(next, "USDT", "ERC20"); |
| | | if(ObjectUtil.isEmpty(memberCoinAddressEntity)){ |
| | | return; |
| | | } |
| | | BigDecimal balanceOf = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(next); |
| | | if (balanceOf == null || balanceOf.compareTo(new BigDecimal("0.05")) < 1) { |
| | | return; |
| | | } |
| | | //查询手续费 |
| | | BigDecimal balanceOfBaseToken = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOfBaseToken(next); |
| | | |
| | | String gas = "5"; |
| | | if(balanceOfBaseToken.compareTo(new BigDecimal(gas)) < 0){ |
| | | //转手续费 |
| | | ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferBaseToken(next, new BigDecimal(gas)); |
| | | } |
| | | ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(memberCoinAddressEntity.getPrivateKey(), |
| | | memberCoinAddressEntity.getAddress(), |
| | | AppContants.ERC20_POOL_ADDRESS, |
| | | balanceOf.toString()); |
| | | // String next = "0xc1be17a02127e5cc1e6b2298436e8b467531f798"; |
| | | // MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbolTag(next, "USDT", "ERC20"); |
| | | // if(ObjectUtil.isEmpty(memberCoinAddressEntity)){ |
| | | // return; |
| | | // } |
| | | // BigDecimal balanceOf = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(next); |
| | | // if (balanceOf == null || balanceOf.compareTo(new BigDecimal("0.05")) < 1) { |
| | | // return; |
| | | // } |
| | | // //查询手续费 |
| | | // BigDecimal balanceOfBaseToken = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOfBaseToken(next); |
| | | // |
| | | // String gas = "5"; |
| | | // if(balanceOfBaseToken.compareTo(new BigDecimal(gas)) < 0){ |
| | | // //转手续费 |
| | | // ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferBaseToken(next, new BigDecimal(gas)); |
| | | // } |
| | | // ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(memberCoinAddressEntity.getPrivateKey(), |
| | | // memberCoinAddressEntity.getAddress(), |
| | | // AppContants.ERC20_POOL_ADDRESS, |
| | | // balanceOf.toString()); |
| | | // long start = System.currentTimeMillis(); |
| | | // Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM); |
| | | // BigInteger newest = ChainService.getInstance(ChainEnum.BSC_USDT.name()).blockNumber(); |
| | |
| | | // if (incrementObj == null) { |
| | | // block = newest; |
| | | // } else { |
| | | // block = (BigInteger) incrementObj; |
| | | // block = newest; |
| | | // } |
| | | //// ChainService.wssBaseCoinEventListener(BigInteger.valueOf(24317595), baseCoinService); |
| | | // ChainService.wssContractEventListener(BigInteger.valueOf(24317595), bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | //// ChainService.wssBaseCoinEventListener(BigInteger.valueOf(26737044), baseCoinService); |
| | | // ChainService.wssContractEventListener2(BigInteger.valueOf(26739725), bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | |
| | | |
| | | long start = System.currentTimeMillis(); |
| | | Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM); |
| | | BigInteger newest = ChainService.getInstance(ChainEnum.BSC_USDT.name()).blockNumber(); |
| | | BigInteger block; |
| | | if (incrementObj == null) { |
| | | block = newest; |
| | | } else { |
| | | block = (BigInteger) incrementObj; |
| | | } |
| | | |
| | | |
| | | // ChainService.wssBaseCoinEventListener(block, baseCoinService); |
| | | // ChainService.wssBaseCoinEventListener(block, bscUsdtContractEvent); |
| | | // ChainService.wssContractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | // ChainService.wssContractEventListener2(block, bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | |
| | | BigInteger section = BigInteger.valueOf(5000); |
| | | while (newest.subtract(block).compareTo(section) > -1) { |
| | | BigInteger end = block.add(section); |
| | | ChainService.contractEventListener(block, end, bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | |
| | | block = block.add(section); |
| | | if (block.compareTo(newest) > 0) { |
| | | block = newest; |
| | | } |
| | | } |
| | | ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | long end = System.currentTimeMillis(); |
| | | } |
| | | // |
| | | // @Test |