package com.xcong.excoin; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpRequest; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xcong.excoin.modules.coin.parameter.dto.CoinInListDto; import com.xcong.excoin.modules.coin.service.CoinService; import com.xcong.excoin.modules.yunding.dao.YdOrderDao; import com.xcong.excoin.modules.yunding.entity.YdOrderEntity; import com.xcong.excoin.modules.yunding.service.XchProfitService; import com.xcong.excoin.quartz.job.YdPowerJob; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.util.ClassUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.math.BigDecimal; import java.util.Date; import java.util.List; @SpringBootTest public class XchTest { @Autowired private XchProfitService xchProfitService; @Autowired private YdOrderDao ydOrderDao; @Test public void usdtReturnTest() { xchProfitService.agentUsdtProfitDistributor(); } @Test public void becomeDy() { xchProfitService.autoBeAgent(447L); } @Test public void dateUtilTest() { String day1 = "2021-05-12 22:00:00"; String day2 = "2021-05-12 23:00:00"; System.out.println(DateUtil.compare(DateUtil.parse(day1, "yyyy-MM-dd HH:mm:ss"), DateUtil.parse(day2, "yyyy-MM-dd HH:mm:ss"))); } @Test public void orderWork() { QueryWrapper objectQueryWrapper = new QueryWrapper<>(); objectQueryWrapper.eq("state",YdOrderEntity.ORDER_STATE_READY); objectQueryWrapper.eq("type",YdOrderEntity.PRODUCT_ORDER); List ydOrderEntities = ydOrderDao.selectList(objectQueryWrapper); Date date = new Date(); if(CollUtil.isNotEmpty(ydOrderEntities)){ for(YdOrderEntity ydOrderEntity : ydOrderEntities){ Date workTime = ydOrderEntity.getWorkTime(); if(ObjectUtil.isNotEmpty(workTime) && DateUtil.compare(date, workTime) > -1){ Long id = ydOrderEntity.getId(); ydOrderDao.UpdateByIdAndState(id,YdOrderEntity.ORDER_STATE_WORK); } } } } @Test public void orderUsdtProfitTest() { xchProfitService.usdtProfitDistributorByOrderId(17L); } // // @Autowired // private YdPowerJob ydPowerJob; // // @Test // public void ydPowerTest() { // ydPowerJob.orderWork(); // } @Test public void orderTest() { YdOrderEntity orderEntity = new YdOrderEntity(); orderEntity.setType(YdOrderEntity.AGENT_ORDER); orderEntity.setMemberId(40L); orderEntity.setAmount(BigDecimal.TEN); ydOrderDao.insert(orderEntity); } @Test public void xchProfitTest() { xchProfitService.xchProfitDistributor(BigDecimal.valueOf(1)); } @Autowired private CoinService coinService; @Test public void coinTest() { CoinInListDto coin = new CoinInListDto(); coin.setType(4); coin.setPageNum(1); coin.setPageSize(10); coinService.coinInList(coin); } public static void main(String[] args) { // String s = execCurl("https://api2.chiaexplorer.com/blockchainSummary"); // System.out.println(s); String body = HttpRequest.get("https://api2.chiaexplorer.com/blockchainSummary").execute().body(); System.out.println(body); } private static String execCurl(String url) { String[] cmds = {"curl", url , "-H", "sec-ch-ua: \" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"" ,"-H", "Accept: application/json, text/plain, */*" ,"-H", "Referer: https://www.chiaexplorer.com/" ,"-H", "sec-ch-ua-mobile: ?0" ,"-H", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" ," --compressed"}; ProcessBuilder process = new ProcessBuilder(cmds); Process p; try { p = process.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line); builder.append(System.getProperty("line.separator")); } return builder.toString(); } catch (IOException e) { System.out.print("error"); e.printStackTrace(); } return null; } @Test public void pyExec() { String result = ""; String path = ClassUtils.getDefaultClassLoader().getResource("").getPath(); String filePath = path + "static/xch.py"; System.out.println(filePath); try { Process process = Runtime.getRuntime().exec("python " + filePath); process.waitFor(); InputStreamReader ir = new InputStreamReader(process.getInputStream()); LineNumberReader input = new LineNumberReader(ir); result = input.readLine(); input.close(); ir.close(); // process.waitFor(); } catch (IOException | InterruptedException e) { System.out.println(11); } System.out.println(result); } }