From a51aa2ae35b45f070511e42b53f01daccb455016 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 11 May 2021 17:42:33 +0800
Subject: [PATCH] Merge branch 'yunding' of http://120.27.238.55:7000/r/exchange into yunding
---
src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java | 4 ++
src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java | 87 +++++++++++++++++++++++++++++++++++++++++++
src/main/java/com/xcong/excoin/modules/yunding/entity/YdBasicSettingEntity.java | 5 ++
src/main/resources/application.yml | 1
4 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java b/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
index 1aaa265..c6ceec5 100644
--- a/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
+++ b/src/main/java/com/xcong/excoin/common/aop/ExceptionCatchAspect.java
@@ -60,6 +60,10 @@
throw ex;
}
+ if ("dev".equals(profiles)) {
+ throw ex;
+ }
+
SysExceptionDetailEntity exceptionData = new SysExceptionDetailEntity();
String exStr = printStackTraceToString(ex);
ThreadPoolUtils.EXECUTOR.execute(new Runnable(){
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 12fac7c..7e294f3 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
@@ -34,4 +34,9 @@
//24小时爆块
private BigDecimal explosiveBlock;
+ /**
+ * 当前价格
+ */
+ private BigDecimal currentPrice;
+
}
diff --git a/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java b/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
new file mode 100644
index 0000000..4014f9d
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
@@ -0,0 +1,87 @@
+package com.xcong.excoin.quartz.job;
+
+import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.xcong.excoin.modules.yunding.dao.YdBasicSettingDao;
+import com.xcong.excoin.modules.yunding.entity.YdBasicSettingEntity;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * @author xxx
+ **/
+@Slf4j
+@Component
+@ConditionalOnProperty(prefix = "app", name = "xch-job", havingValue = "true")
+public class XchBaseDataUpdateJob {
+
+ @Autowired
+ private YdBasicSettingDao ydBasicSettingDao;
+
+ @Scheduled(cron = "* */1 * * * ? ")
+ public void baseDataUpdate() {
+ // 请求价格等数据
+ String result = getUrlResponse("https://api2.chiaexplorer.com/blockchainSummary");
+ // 每t预计收益
+ String profitPerT = getUrlResponse("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
+ JSONObject jsonObject = (JSONObject) JSONObject.parse(result);
+ JSONObject perTObject = (JSONObject) JSONObject.parse(profitPerT);
+ List<YdBasicSettingEntity> list = ydBasicSettingDao.selectList(null);
+ if (CollUtil.isNotEmpty(list)) {
+ YdBasicSettingEntity settingEntity = list.get(0);
+ String netspaceStr = jsonObject.getString("netspace");
+ BigDecimal baseUnit = BigDecimal.valueOf(1024);
+ BigDecimal netspace = new BigDecimal(netspaceStr).divide(baseUnit.multiply(baseUnit.multiply(baseUnit.multiply(baseUnit.multiply(baseUnit)))), 2, BigDecimal.ROUND_DOWN);
+ settingEntity.setAllPower(netspace);
+
+ settingEntity.setCurrentPrice(new BigDecimal(jsonObject.getString("price")));
+ 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);
+ }
+ }
+
+ private String getUrlResponse(String url) {
+ BufferedReader reader = null;
+ String result = null;
+ StringBuffer sbf = new StringBuffer();
+ // 模拟浏览器
+ String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
+ try {
+ URL request = new URL(url);
+ HttpURLConnection connection = (HttpURLConnection) request.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setReadTimeout(30000);
+ connection.setConnectTimeout(30000);
+ connection.setRequestProperty("User-agent", userAgent);
+ connection.connect();
+ InputStream is = connection.getInputStream();
+ reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ String strRead = null;
+ while ((strRead = reader.readLine()) != null) {
+ sbf.append(strRead);
+ sbf.append("\r\n");
+ }
+ reader.close();
+ result = sbf.toString();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 31ee018..f38db7e 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -107,6 +107,7 @@
loop-job: false
rabbit-consumer: false
block-job: false
+ xch-job: false
aliyun:
oss:
--
Gitblit v1.9.1