From 2d398a2bbd4a210ffd885f0b0b0a0f99edd84707 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 25 May 2021 10:47:46 +0800
Subject: [PATCH] modify
---
src/test/java/com/xcong/excoin/XchTest.java | 23 +++++++
src/test/resources/static/xch.py | 8 ++
src/main/resources/static/xch.py | 8 ++
src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java | 73 ++++++++++++++---------
src/main/java/com/xcong/excoin/modules/yunding/entity/YdBasicSettingEntity.java | 5 +
src/main/java/com/xcong/excoin/modules/yunding/service/Impl/XchProfitServiceImpl.java | 14 ++++
6 files changed, 102 insertions(+), 29 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/yunding/entity/YdBasicSettingEntity.java b/src/main/java/com/xcong/excoin/modules/yunding/entity/YdBasicSettingEntity.java
index 87a6046..b0695ef 100644
--- a/src/main/java/com/xcong/excoin/modules/yunding/entity/YdBasicSettingEntity.java
+++ b/src/main/java/com/xcong/excoin/modules/yunding/entity/YdBasicSettingEntity.java
@@ -47,4 +47,9 @@
*/
private BigDecimal parentRatio;
+ /**
+ * 合伙人XCH收益
+ */
+ private BigDecimal partnerXchRatio;
+
}
diff --git a/src/main/java/com/xcong/excoin/modules/yunding/service/Impl/XchProfitServiceImpl.java b/src/main/java/com/xcong/excoin/modules/yunding/service/Impl/XchProfitServiceImpl.java
index ad88844..8dcf79c 100644
--- a/src/main/java/com/xcong/excoin/modules/yunding/service/Impl/XchProfitServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/yunding/service/Impl/XchProfitServiceImpl.java
@@ -279,6 +279,9 @@
BigDecimal unitProfit = totalProfit.divide(totalCount, 8, BigDecimal.ROUND_DOWN);
log.info("单位XCH收益:{}", unitProfit);
+ List<MemberEntity> partners = memberDao.selectPartnerMemberList();
+ YdBasicSettingEntity setting = ydBasicSettingDao.selectById(1L);
+
List<YdOrderEntity> orders = ydOrderDao.selectAllValidOrders();
if (CollUtil.isNotEmpty(orders)) {
for (YdOrderEntity order : orders) {
@@ -314,6 +317,17 @@
}
}
+ // 合伙人收益
+ if (CollUtil.isNotEmpty(partners)) {
+ BigDecimal partnerAmount = orderProfit.multiply(setting.getPartnerXchRatio());
+ remainProfit = remainProfit.subtract(partnerAmount);
+ BigDecimal unitPartnerAmount = partnerAmount.divide(BigDecimal.valueOf(partners.size()), 8, BigDecimal.ROUND_DOWN);
+ for (MemberEntity partner : partners) {
+ String conent = "合伙人XCH分红";
+ LogRecordUtils.insertMemberAccountMoneyChangeWithId(partner.getId(), conent, unitPartnerAmount, "XCH", 1, 10, order.getId());
+ }
+ }
+
remainProfit = remainProfit.subtract(orderProfit.multiply(order.getYdProductEntity().getManageExpense()));
String content = "XCH收益";
LogRecordUtils.insertMemberAccountMoneyChangeWithId(order.getMemberId(), content, remainProfit, "XCH", 1, 4, order.getId());
diff --git a/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java b/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
index 1f48a33..ebd0074 100644
--- a/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
+++ b/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
@@ -13,11 +13,9 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import org.springframework.util.ClassUtils;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -38,19 +36,19 @@
@Autowired
private XchProfitService xchProfitService;
-// @Scheduled(cron = "0 0 0/10 * * ? ")
- @Scheduled(cron = "0 0/1 * * * ? ")
+ // @Scheduled(cron = "0 0 0/10 * * ? ")
+ @Scheduled(cron = "0 0/20 * * * ? ")
public void baseDataUpdate() {
log.info("基础数据更新任务");
- // 请求价格等数据
- String result = execCurl("https://api2.chiaexplorer.com/blockchainSummary");
+ // 请求价格等数据 "https://api2.chiaexplorer.com/blockchainSummary"
+ String result = pyExec();
// 每t预计收益
- String profitPerT = execCurl("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
-
- String xchPrice24HStr = execCurl("https://api2.chiaexplorer.com/chart/xchPriceChart?period=24h");
+// String profitPerT = execCurl("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
+//
+// String xchPrice24HStr = execCurl("https://api2.chiaexplorer.com/chart/xchPriceChart?period=24h");
JSONObject jsonObject = (JSONObject) JSONObject.parse(result);
- JSONObject perTObject = (JSONObject) JSONObject.parse(profitPerT);
- JSONObject xchPrice24HObj = (JSONObject) JSONObject.parse(xchPrice24HStr);
+// JSONObject perTObject = (JSONObject) JSONObject.parse(profitPerT);
+// JSONObject xchPrice24HObj = (JSONObject) JSONObject.parse(xchPrice24HStr);
List<YdBasicSettingEntity> list = ydBasicSettingDao.selectList(null);
if (CollUtil.isNotEmpty(list)) {
YdBasicSettingEntity settingEntity = list.get(0);
@@ -63,14 +61,14 @@
redisUtils.set("XCH_NEW_PRICE", newPrice);
settingEntity.setCurrentPrice(newPrice);
- List<String> xchPrice24H = JSONObject.parseArray(xchPrice24HObj.getString("data"), String.class);
- BigDecimal newestPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1));
- BigDecimal lastPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1 -24));
- BigDecimal upOrDown = newestPrice.subtract(lastPrice).multiply(BigDecimal.valueOf(100)).divide(lastPrice, 2, BigDecimal.ROUND_HALF_UP);
- redisUtils.set("XCH_UP_DOWN", upOrDown);
- List<String> data = JSONObject.parseArray(perTObject.getString("data"), String.class);
- settingEntity.setPrifitT(new BigDecimal(data.get(0)));
- settingEntity.setProfitDay(new BigDecimal(data.get(0)).multiply(BigDecimal.valueOf(1024)));
+// List<String> xchPrice24H = JSONObject.parseArray(xchPrice24HObj.getString("data"), String.class);
+// BigDecimal newestPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1));
+// BigDecimal lastPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1 -24));
+// BigDecimal upOrDown = newestPrice.subtract(lastPrice).multiply(BigDecimal.valueOf(100)).divide(lastPrice, 2, BigDecimal.ROUND_HALF_UP);
+// redisUtils.set("XCH_UP_DOWN", upOrDown);
+// List<String> data = JSONObject.parseArray(perTObject.getString("data"), String.class);
+// settingEntity.setPrifitT(new BigDecimal(data.get(0)));
+// settingEntity.setProfitDay(new BigDecimal(data.get(0)).multiply(BigDecimal.valueOf(1024)));
ydBasicSettingDao.updateById(settingEntity);
}
@@ -108,20 +106,19 @@
return result;
}
-// @Scheduled(cron = "0 0 23 * * ?")
+ // @Scheduled(cron = "0 0 23 * * ?")
public void xchProfitJob() {
log.info("XCH收益返利任务");
// xchProfitService.xchProfitDistributor();
}
-// @Scheduled(cron = "0 0 22 * * ?")
+ // @Scheduled(cron = "0 0 22 * * ?")
public void usdtProfitJob() {
log.info("USDT返利任务");
// xchProfitService.agentUsdtProfitDistributor();
}
public static void main(String[] args) {
-
// System.out.println(HttpRequest.get("https://www.chiaexplorer.com").execute().body());
@@ -131,11 +128,11 @@
private 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"};
+ , "-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;
@@ -157,4 +154,22 @@
return null;
}
+ public String pyExec() {
+ String result = "";
+ String path = ClassUtils.getDefaultClassLoader().getResource("").getPath();
+ String filePath = path + "static/xch.py";
+ try {
+ Process process = Runtime.getRuntime().exec("python3 " + filePath);
+ process.waitFor();
+ InputStreamReader ir = new InputStreamReader(process.getInputStream());
+ LineNumberReader input = new LineNumberReader(ir);
+ result = input.readLine();
+ input.close();
+ ir.close();
+ } catch (IOException | InterruptedException e) {
+ log.error("python执行异常", e);
+ }
+ return result;
+ }
+
}
diff --git a/src/main/resources/static/xch.py b/src/main/resources/static/xch.py
new file mode 100644
index 0000000..ab8a24d
--- /dev/null
+++ b/src/main/resources/static/xch.py
@@ -0,0 +1,8 @@
+import urllib
+import urllib2
+import re
+
+headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
+request = urllib2.Request("https://api2.chiaexplorer.com/blockchainSummary", headers=headers)
+response = urllib2.urlopen(request)
+print response.read()
\ No newline at end of file
diff --git a/src/test/java/com/xcong/excoin/XchTest.java b/src/test/java/com/xcong/excoin/XchTest.java
index 919737c..47bc233 100644
--- a/src/test/java/com/xcong/excoin/XchTest.java
+++ b/src/test/java/com/xcong/excoin/XchTest.java
@@ -16,10 +16,12 @@
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;
@@ -138,4 +140,25 @@
}
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);
+ }
}
diff --git a/src/test/resources/static/xch.py b/src/test/resources/static/xch.py
new file mode 100644
index 0000000..ab8a24d
--- /dev/null
+++ b/src/test/resources/static/xch.py
@@ -0,0 +1,8 @@
+import urllib
+import urllib2
+import re
+
+headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
+request = urllib2.Request("https://api2.chiaexplorer.com/blockchainSummary", headers=headers)
+response = urllib2.urlopen(request)
+print response.read()
\ No newline at end of file
--
Gitblit v1.9.1