update 解决定时任务cpu飙升问题
This commit is contained in:
parent
b43e8f9965
commit
00c490d28f
|
@ -17,14 +17,14 @@ public interface ManageDocumentsMapper extends BaseMapper<ManageDocuments> {
|
|||
* 分页查询所有文档(中文)
|
||||
* @return
|
||||
*/
|
||||
List<ManageDocumentDto> getListDataByPage(@Param("keyword") String keyword);
|
||||
List<ManageDocumentDto> getListDataByPage(@Param("keyword") String keyword,@Param("type") Integer type);
|
||||
|
||||
/**
|
||||
* 查询所有文档(英文)
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
List<ManageDocumentDto> getListDataEnByPage(@Param("keyword") String keyword);
|
||||
List<ManageDocumentDto> getListDataEnByPage(@Param("keyword") String keyword,@Param("type") Integer type);
|
||||
|
||||
/**
|
||||
* 查询所有文档类型对应的文章列表
|
||||
|
|
|
@ -39,9 +39,9 @@ public class ManageDocumentsServiceImpl extends ServiceImpl<ManageDocumentsMappe
|
|||
PageHelper.startPage(manageSearchDocumentVo.getPageNum(), manageSearchDocumentVo.getPageSize());
|
||||
List<ManageDocumentDto> listDataByPage;
|
||||
if (CountryConstant.EN.equals(manageSearchDocumentVo.getLang())){
|
||||
listDataByPage = manageDocumentsMapper.getListDataByPage(manageSearchDocumentVo.getKeyword());
|
||||
listDataByPage = manageDocumentsMapper.getListDataEnByPage(manageSearchDocumentVo.getKeyword(),manageSearchDocumentVo.getType());
|
||||
}else{
|
||||
listDataByPage = manageDocumentsMapper.getListDataByPage(manageSearchDocumentVo.getKeyword());
|
||||
listDataByPage = manageDocumentsMapper.getListDataByPage(manageSearchDocumentVo.getKeyword(),manageSearchDocumentVo.getType());
|
||||
}
|
||||
return getDataTable(listDataByPage);
|
||||
}
|
||||
|
@ -111,7 +111,6 @@ public class ManageDocumentsServiceImpl extends ServiceImpl<ManageDocumentsMappe
|
|||
.updateUser(SecurityUtils.getUsername())
|
||||
.build();
|
||||
}
|
||||
|
||||
int insert = manageDocumentsMapper.insert(build);
|
||||
if (insert > 0){
|
||||
return R.success("添加文章成功");
|
||||
|
@ -182,6 +181,7 @@ public class ManageDocumentsServiceImpl extends ServiceImpl<ManageDocumentsMappe
|
|||
.updateUser(documents.getUpdateUser())
|
||||
.updateTime(documents.getUpdateTime())
|
||||
.createTime(documents.getCreateTime())
|
||||
.type(documents.getType())
|
||||
.build();
|
||||
if (CountryConstant.EN.equals(manageBaseVo.getLang())){
|
||||
build.setTitle(documents.getTitleEn());
|
||||
|
@ -205,9 +205,9 @@ public class ManageDocumentsServiceImpl extends ServiceImpl<ManageDocumentsMappe
|
|||
PageHelper.startPage(manageSearchDocumentVo.getPageNum(), manageSearchDocumentVo.getPageSize());
|
||||
List<ManageDocumentDto> listDataByPage;
|
||||
if (CountryConstant.EN.equals(manageSearchDocumentVo.getLang())){
|
||||
listDataByPage = manageDocumentsMapper.getListDataEnByPage(manageSearchDocumentVo.getKeyword());
|
||||
listDataByPage = manageDocumentsMapper.getListDataEnByPage(manageSearchDocumentVo.getKeyword(), manageSearchDocumentVo.getType());
|
||||
}else{
|
||||
listDataByPage = manageDocumentsMapper.getListDataByPage(manageSearchDocumentVo.getKeyword());
|
||||
listDataByPage = manageDocumentsMapper.getListDataByPage(manageSearchDocumentVo.getKeyword(), manageSearchDocumentVo.getType());
|
||||
}
|
||||
|
||||
return getDataTable(listDataByPage);
|
||||
|
|
|
@ -17,4 +17,7 @@ public class ManageSearchDocumentVo extends PageVo{
|
|||
|
||||
@ApiModelProperty(value = "语言",example = "zh")
|
||||
private String lang;
|
||||
|
||||
@ApiModelProperty(value = "文档类型",example = "1 挖矿教程 2常见问题 3公告中心 0其他")
|
||||
private Integer type;
|
||||
}
|
||||
|
|
|
@ -19,14 +19,39 @@ SELECT
|
|||
type
|
||||
FROM
|
||||
manage_documents
|
||||
<where>
|
||||
del = false
|
||||
<if test="keyword != null">
|
||||
AND title like CONCAT('%',#{keyword},'%') OR sub_title like CONCAT('%',#{keyword},'%') OR content like CONCAT('%',#{keyword},'%')
|
||||
</if>
|
||||
</where>
|
||||
<where>
|
||||
del = false
|
||||
<choose>
|
||||
<when test="type != null">
|
||||
AND type = #{type}
|
||||
<if test="keyword != null">
|
||||
AND (<include refid="keywordSearch"/>)
|
||||
</if>
|
||||
</when>
|
||||
<when test="keyword != null">
|
||||
AND (<include refid="keywordSearch"/>)
|
||||
</when>
|
||||
</choose>
|
||||
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
|
||||
<sql id="keywordSearch">
|
||||
title like CONCAT('%',#{keyword},'%')
|
||||
OR sub_title like CONCAT('%',#{keyword},'%')
|
||||
OR content like CONCAT('%',#{keyword},'%')
|
||||
</sql>
|
||||
|
||||
|
||||
<sql id="keywordSearchEn">
|
||||
title_en like CONCAT('%',#{keyword},'%')
|
||||
OR sub_title_en like CONCAT('%',#{keyword},'%')
|
||||
OR content_en like CONCAT('%',#{keyword},'%')
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="getListDataEnByPage" resultType="com.m2pool.manage.dto.ManageDocumentDto">
|
||||
SELECT
|
||||
id,
|
||||
|
@ -42,9 +67,18 @@ FROM
|
|||
manage_documents
|
||||
<where>
|
||||
del = false
|
||||
<if test="keyword != null">
|
||||
AND title_en like CONCAT('%',#{keyword},'%') OR sub_title_en like CONCAT('%',#{keyword},'%') OR content_en like CONCAT('%',#{keyword},'%')
|
||||
</if>
|
||||
<choose>
|
||||
<when test="type != null">
|
||||
AND type = #{type}
|
||||
<if test="keyword != null">
|
||||
AND (<include refid="keywordSearchEn"/>)
|
||||
</if>
|
||||
</when>
|
||||
<when test="keyword != null">
|
||||
AND (<include refid="keywordSearchEn"/>)
|
||||
</when>
|
||||
</choose>
|
||||
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.6.2</version>
|
||||
<version>5.8.24</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package com.m2pool.pool.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.config.Registry;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.ssl.TrustStrategy;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Apache HttpClient 连接池工具类
|
||||
*/
|
||||
public class ApacheHttpClientPoolUtil {
|
||||
|
||||
// 连接池管理器
|
||||
private static final PoolingHttpClientConnectionManager connectionManager;
|
||||
// 请求配置
|
||||
private static final RequestConfig requestConfig;
|
||||
// 单例的 CloseableHttpClient
|
||||
private static final CloseableHttpClient httpClient;
|
||||
|
||||
// 最大连接数
|
||||
private static final int MAX_TOTAL = 100;
|
||||
// 每个路由的最大连接数
|
||||
private static final int MAX_PER_ROUTE = 10;
|
||||
// 连接超时时间,单位毫秒
|
||||
private static final int CONNECT_TIMEOUT = 3000;
|
||||
// 请求获取数据的超时时间,单位毫秒
|
||||
private static final int SOCKET_TIMEOUT = 5000;
|
||||
// 从连接池获取连接的超时时间,单位毫秒
|
||||
private static final int CONNECTION_REQUEST_TIMEOUT = 3000;
|
||||
|
||||
static {
|
||||
try {
|
||||
// 初始化连接池管理器
|
||||
connectionManager = new PoolingHttpClientConnectionManager(
|
||||
getSocketFactoryRegistry(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
30, TimeUnit.SECONDS
|
||||
);
|
||||
// 设置最大连接数
|
||||
connectionManager.setMaxTotal(MAX_TOTAL);
|
||||
// 设置每个路由的最大连接数
|
||||
connectionManager.setDefaultMaxPerRoute(MAX_PER_ROUTE);
|
||||
|
||||
// 初始化请求配置
|
||||
requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(CONNECT_TIMEOUT)
|
||||
.setSocketTimeout(SOCKET_TIMEOUT)
|
||||
.setConnectionRequestTimeout(CONNECTION_REQUEST_TIMEOUT)
|
||||
.build();
|
||||
|
||||
// 初始化单例的 CloseableHttpClient
|
||||
httpClient = HttpClients.custom()
|
||||
.setConnectionManager(connectionManager)
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.evictIdleConnections(60, TimeUnit.SECONDS)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("初始化 HttpClient 连接池失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支持 HTTP 和 HTTPS 的 Socket 工厂注册器
|
||||
* @return Socket 工厂注册器
|
||||
* @throws NoSuchAlgorithmException 当指定的算法不可用时抛出
|
||||
* @throws KeyManagementException 当密钥管理操作失败时抛出
|
||||
* @throws KeyStoreException 当密钥库操作失败时抛出
|
||||
*/
|
||||
private static Registry<ConnectionSocketFactory> getSocketFactoryRegistry()
|
||||
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
|
||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
||||
@Override
|
||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
return true;
|
||||
}
|
||||
}).build();
|
||||
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
|
||||
sslContext, NoopHostnameVerifier.INSTANCE);
|
||||
|
||||
return RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", PlainConnectionSocketFactory.getSocketFactory())
|
||||
.register("https", sslSocketFactory)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例的 CloseableHttpClient 实例
|
||||
* @return CloseableHttpClient 实例
|
||||
*/
|
||||
public static CloseableHttpClient getHttpClient() {
|
||||
return httpClient;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @Description scheduler配置类
|
||||
* @Date 2024/10/25 10:26
|
||||
|
@ -15,7 +17,7 @@ public class ScheduledTaskConfig implements SchedulingConfigurer {
|
|||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
taskScheduler.setPoolSize(8);
|
||||
taskScheduler.setPoolSize(20);
|
||||
taskScheduler.initialize();
|
||||
taskRegistrar.setTaskScheduler(taskScheduler);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Deprecated
|
||||
@Configuration
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public enum NodeConfig {
|
|||
DGB_SKEIN_A10("dgb_skein_a10", "127.0.0.1", "3306", "user", "pwd"),
|
||||
DGB_ODO_B20("dgb_odo_b20", "127.0.0.1", "3306", "user", "pwd"),
|
||||
NEXA("nexa", "18.139.85.190", "7227", "test", "test"),
|
||||
RXD("rxd", "13.214.176.64", "7332", "test", "test"),
|
||||
RXD("rxd", "18.141.161.129", "7332", "test", "test"),
|
||||
ALPH("alph", "18.141.161.129", "12973", "test", "test"),
|
||||
ENX("enx", "13.214.6.253", "12973", "test", "test");
|
||||
|
||||
|
|
|
@ -401,7 +401,7 @@ public class PoolServiceImpl implements PoolService {
|
|||
|
||||
|
||||
List<PowerLineDto> list = poolMapper.getHourNetPowerList(pool.getCoin());
|
||||
|
||||
System.out.println("list----yyb-1"+list);
|
||||
if("1h".equals(vo.getInterval()) || "rt".equals(vo.getInterval())){
|
||||
PageHelper.clearPage();
|
||||
//30m数据 限制条数为最近1天的条数 即1*48=48
|
||||
|
@ -415,6 +415,8 @@ public class PoolServiceImpl implements PoolService {
|
|||
//
|
||||
//}
|
||||
PowerUnitUtils.NetPowerUnit powerUnit = PowerUnitUtils.getPowerUnit(maxPv.getPv());
|
||||
|
||||
|
||||
list = changeUnit(powerUnit, list, pool,BigDecimal.valueOf(1));
|
||||
Collections.reverse(list);
|
||||
return AjaxResult.success(list);
|
||||
|
|
|
@ -2993,8 +2993,6 @@ public class DataTask {
|
|||
|
||||
boolean useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start3d);
|
||||
//获取3天内全网的实际报块数
|
||||
|
||||
|
||||
BlockTimeAndNumberDto blockData = blockDataContext.getBlockData("rxd",start3d, end,blockPerDays, useAggregated);
|
||||
//3天矿池理论报块数
|
||||
BigDecimal throreticalBlocks= getTheoreticalBlocks("rxd",PoolUnits.RXD.gethRate(),start3d, end, blockData);
|
||||
|
@ -3384,7 +3382,7 @@ public class DataTask {
|
|||
}
|
||||
|
||||
//@Scheduled(cron = "30 2,7 0,12 * * ?")
|
||||
@Scheduled(cron = "41 2,5 0/12 * * ?")
|
||||
//@Scheduled(cron = "41 2,5 0/12 * * ?")
|
||||
public void ENXLuckyDataToDB(){
|
||||
if(!enable){
|
||||
return;
|
||||
|
@ -3405,7 +3403,7 @@ public class DataTask {
|
|||
int hRate = PoolUnits.ENX.gethRate();
|
||||
//先把矿池算力单位转换为H/s 再除以全网算力 得到比值 再乘以每日全网出块数 得到矿池每日应出块数
|
||||
List<DateBigDecimalDto> netPowerList = poolMapper.getDailyNetPower("enx");
|
||||
if(netPowerList.size() < 1){
|
||||
if(netPowerList.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3414,7 +3412,7 @@ public class DataTask {
|
|||
//拿报块list 筛选实际出块数
|
||||
List<BlockInfoDto> list = poolMapper.getENXBlockInfoList();
|
||||
|
||||
if (list.size() < 1){
|
||||
if (list.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3433,7 +3431,7 @@ public class DataTask {
|
|||
BigDecimal pPow3d = poolPowerList.stream()
|
||||
.filter(e -> (e.getPDate().before(end)))
|
||||
.filter(e -> (e.getPDate().after(start3d) || e.getPDate().equals(start3d)))
|
||||
.map(e -> e.getValue()).reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.map(DateBigDecimalDto::getValue).reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.multiply(BigDecimal.valueOf(hRate));
|
||||
|
||||
long nDay3d = netPowerList.stream()
|
||||
|
@ -3443,7 +3441,7 @@ public class DataTask {
|
|||
BigDecimal nPow3d = netPowerList.stream()
|
||||
.filter(e -> (e.getPDate().before(end)))
|
||||
.filter(e -> (e.getPDate().after(start3d) || e.getPDate().equals(start3d)))
|
||||
.map(e -> e.getValue()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
.map(DateBigDecimalDto::getValue).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
if(pDay3d == 0 || nDay3d == 0){
|
||||
continue;
|
||||
|
|
|
@ -8,12 +8,18 @@ import com.alibaba.fastjson.JSONArray;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.m2pool.common.core.text.Convert;
|
||||
import com.m2pool.common.core.utils.StringUtils;
|
||||
import com.m2pool.pool.config.ApacheHttpClientPoolUtil;
|
||||
import com.m2pool.pool.entity.BlockInfo;
|
||||
import com.m2pool.pool.entity.BlockNewInfo;
|
||||
import com.m2pool.pool.enums.NodeConfig;
|
||||
import com.m2pool.pool.enums.NodeConstant;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
|
@ -34,46 +40,92 @@ public class NodeRpc{
|
|||
|
||||
String auth =config.getUser()+":"+config.getPwd();
|
||||
|
||||
// 构建请求体
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.put("jsonrpc", "1.0");
|
||||
requestBody.put("id", "testnet");
|
||||
requestBody.put("method", method);
|
||||
if(config.getCoin() != "nexa"){
|
||||
requestBody.put("params",params);
|
||||
if ("nexa".equals(config.getCoin())) {
|
||||
requestBody.put("params", params);
|
||||
}
|
||||
|
||||
|
||||
// 创建 HttpPost 请求
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
// 设置请求头
|
||||
httpPost.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()));
|
||||
httpPost.setHeader("Content-Type", "application/json");
|
||||
// 设置请求体
|
||||
StringEntity entity = null;
|
||||
try {
|
||||
String body = HttpRequest
|
||||
.post(uri)
|
||||
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()))
|
||||
.header("Content-Type","application/json")
|
||||
.body(requestBody.toString())
|
||||
.timeout(3000)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
|
||||
String result = jsonObject.getString("result");
|
||||
String error = jsonObject.getString("error");
|
||||
|
||||
if (StringUtils.isNull(result) && StringUtils.isNotBlank(error)){
|
||||
System.out.println("error:"+JSON.parseObject(error).getString("message"));
|
||||
return "error:"+JSON.parseObject(error).getString("message");
|
||||
}
|
||||
if(StringUtils.isNull(result) && StringUtils.isBlank(error)){
|
||||
System.out.println("result和error为空");
|
||||
return "error:connection failed";
|
||||
}
|
||||
return result;
|
||||
}catch (IORuntimeException e){
|
||||
return "error:connection failed by IORuntimeException" +e;
|
||||
}catch (Exception e){
|
||||
return "error:connection failed by Exception"+e;
|
||||
entity = new StringEntity(requestBody.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return "error:connection failed by UnsupportedEncodingException"+e;
|
||||
}
|
||||
httpPost.setEntity(entity);
|
||||
//从连接池获取连接不要放到下面try with resource中,否则连接池会关闭
|
||||
CloseableHttpClient httpClient = ApacheHttpClientPoolUtil.getHttpClient();
|
||||
//发起请求
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||
// 获取响应实体
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
if (responseEntity != null) {
|
||||
String body = EntityUtils.toString(responseEntity);
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
|
||||
String result = jsonObject.getString("result");
|
||||
String error = jsonObject.getString("error");
|
||||
if (StringUtils.isNull(result) && StringUtils.isNotBlank(error)){
|
||||
System.out.println("error:"+JSON.parseObject(error).getString("message"));
|
||||
return "error:"+JSON.parseObject(error).getString("message");
|
||||
}
|
||||
if(StringUtils.isNull(result) && StringUtils.isBlank(error)){
|
||||
System.out.println("result和error为空");
|
||||
return "error:connection failed";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return "error:result is null";
|
||||
}catch (Exception e){
|
||||
System.out.println("报错了"+e);
|
||||
return "error:connection failed by IOException"+e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//JSONObject requestBody = new JSONObject();
|
||||
//requestBody.put("jsonrpc", "1.0");
|
||||
//requestBody.put("id", "testnet");
|
||||
//requestBody.put("method", method);
|
||||
//if("nexa".equals(config.getCoin())){
|
||||
// requestBody.put("params",params);
|
||||
//}
|
||||
//try (HttpResponse response = HttpUtil.createPost(uri)
|
||||
// .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()))
|
||||
// .header("Content-Type", "application/json")
|
||||
// .body(requestBody.toString())
|
||||
// .timeout(3000)
|
||||
// .execute()) {
|
||||
// String body = response.body();
|
||||
// System.out.println(body);
|
||||
// JSONObject jsonObject = JSON.parseObject(body);
|
||||
//
|
||||
// String result = jsonObject.getString("result");
|
||||
// String error = jsonObject.getString("error");
|
||||
//
|
||||
// if (StringUtils.isNull(result) && StringUtils.isNotBlank(error)){
|
||||
// System.out.println("error:"+JSON.parseObject(error).getString("message"));
|
||||
// return "error:"+JSON.parseObject(error).getString("message");
|
||||
// }
|
||||
// if(StringUtils.isNull(result) && StringUtils.isBlank(error)){
|
||||
// System.out.println("result和error为空");
|
||||
// return "error:connection failed";
|
||||
// }
|
||||
// return result;
|
||||
//}catch (IORuntimeException e){
|
||||
// return "error:connection failed by IORuntimeException" +e;
|
||||
//}catch (Exception e){
|
||||
// return "error:connection failed by Exception"+e;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
@ -85,43 +137,82 @@ public class NodeRpc{
|
|||
|
||||
String auth =config.getUser()+":"+config.getPwd();
|
||||
|
||||
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.put("jsonrpc", "1.0");
|
||||
requestBody.put("id", "testnet");
|
||||
requestBody.put("method", method);//getblockcount
|
||||
requestBody.put("params",params);
|
||||
|
||||
// 创建 HttpPost 请求
|
||||
HttpPost httpPost = new HttpPost(uri);
|
||||
// 设置请求头
|
||||
httpPost.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()));
|
||||
httpPost.setHeader("Content-Type", "application/json");
|
||||
// 设置请求体
|
||||
StringEntity entity = null;
|
||||
try {
|
||||
String body = HttpRequest
|
||||
.post(uri)
|
||||
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()))
|
||||
.header("Content-Type","application/json")
|
||||
.body(requestBody.toString())
|
||||
.timeout(3000)
|
||||
.execute()
|
||||
.body();
|
||||
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
|
||||
|
||||
String result = jsonObject.getString("result");
|
||||
String error = jsonObject.getString("error");
|
||||
|
||||
if (StringUtils.isNull(result) && StringUtils.isNotBlank(error)){
|
||||
System.out.println("error:"+JSON.parseObject(error).getString("message"));
|
||||
return "error:"+JSON.parseObject(error).getString("message");
|
||||
}
|
||||
if(StringUtils.isNull(result) && StringUtils.isBlank(error)){
|
||||
System.out.println("result和error为空");
|
||||
return "error:connection failed";
|
||||
}
|
||||
return result;
|
||||
}catch (IORuntimeException e){
|
||||
return "error:connection failed by IORuntimeException" +e;
|
||||
}catch (Exception e){
|
||||
return "error:connection failed by Exception"+e;
|
||||
entity = new StringEntity(requestBody.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return "error:connection failed by UnsupportedEncodingException"+e;
|
||||
}
|
||||
httpPost.setEntity(entity);
|
||||
//从连接池获取连接不要放到下面try with resource中,否则连接池会关闭
|
||||
CloseableHttpClient httpClient = ApacheHttpClientPoolUtil.getHttpClient();
|
||||
//发起请求
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
||||
|
||||
// 获取响应实体
|
||||
HttpEntity responseEntity = response.getEntity();
|
||||
if (responseEntity != null) {
|
||||
String body = EntityUtils.toString(responseEntity);
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
|
||||
String result = jsonObject.getString("result");
|
||||
String error = jsonObject.getString("error");
|
||||
if (StringUtils.isNull(result) && StringUtils.isNotBlank(error)){
|
||||
System.out.println("error:"+JSON.parseObject(error).getString("message"));
|
||||
return "error:"+JSON.parseObject(error).getString("message");
|
||||
}
|
||||
if(StringUtils.isNull(result) && StringUtils.isBlank(error)){
|
||||
System.out.println("result和error为空");
|
||||
return "error:connection failed";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return "error:result is null";
|
||||
}catch (Exception e){
|
||||
System.out.println("报错了"+e);
|
||||
return "error:connection failed by IOException"+e;
|
||||
}
|
||||
|
||||
//
|
||||
//try (HttpResponse response = HttpUtil.createPost(uri)
|
||||
// .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.getBytes()))
|
||||
// .header("Content-Type", "application/json")
|
||||
// .body(requestBody.toString())
|
||||
// .timeout(3000)
|
||||
// .execute()) {
|
||||
// String body = response.body();
|
||||
// System.out.println(body);
|
||||
// JSONObject jsonObject = JSON.parseObject(body);
|
||||
//
|
||||
// String result = jsonObject.getString("result");
|
||||
// String error = jsonObject.getString("error");
|
||||
//
|
||||
// if (StringUtils.isNull(result) && StringUtils.isNotBlank(error)){
|
||||
// System.out.println("error:"+JSON.parseObject(error).getString("message"));
|
||||
// return "error:"+JSON.parseObject(error).getString("message");
|
||||
// }
|
||||
// if(StringUtils.isNull(result) && StringUtils.isBlank(error)){
|
||||
// System.out.println("result和error为空");
|
||||
// return "error:connection failed";
|
||||
// }
|
||||
// return result;
|
||||
//}catch (IORuntimeException e){
|
||||
// return "error:connection failed by IORuntimeException" +e;
|
||||
//}catch (Exception e){
|
||||
// return "error:connection failed by Exception"+e;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
@ -194,7 +285,7 @@ public class NodeRpc{
|
|||
}
|
||||
|
||||
if(result.contains("error:")){
|
||||
System.out.println(coin+"获取高度失败");
|
||||
System.out.println(coin+result+"获取高度失败");
|
||||
return "error: height get failed";
|
||||
}else {
|
||||
try {
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.m2pool.pool.utils;
|
|||
|
||||
import com.m2pool.common.core.utils.StringUtils;
|
||||
import com.m2pool.pool.enums.PoolProfitScale;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
@ -133,6 +135,8 @@ public class PowerUnitUtils {
|
|||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class NetPowerUnit{
|
||||
private String unit;
|
||||
private BigDecimal unitValue;
|
||||
|
|
|
@ -38,10 +38,9 @@ public class SocketDemo {
|
|||
//JSONObject jsonObject = JSONObject.parseObject(s);
|
||||
//int currentHeight = jsonObject.getIntValue("currentHeight");
|
||||
|
||||
Date endDate = DateUtils.getPreviousHalfHourOrFullHour(new Date());
|
||||
Date startDate = DateUtils.getOneMonthAgo(endDate);
|
||||
System.out.println(startDate+" "+endDate);
|
||||
|
||||
//Date endDate = DateUtils.getPreviousHalfHourOrFullHour(new Date());
|
||||
//Date startDate = DateUtils.getOneMonthAgo(endDate);
|
||||
//System.out.println(startDate+" "+endDate);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -374,8 +374,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="getHourNetPowerList" resultType="com.m2pool.pool.dto.PowerLineDto">
|
||||
select
|
||||
p.date `date`,
|
||||
p.value price,
|
||||
np.value pv
|
||||
COALESCE(p.value,0) price,
|
||||
COALESCE(np.value,0) pv
|
||||
from
|
||||
${table}_price p
|
||||
left join ${table}_net_power np on p.date = np.date
|
||||
|
@ -420,11 +420,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<select id="getDailyPoolPower" resultType="com.m2pool.pool.dto.DateBigDecimalDto">
|
||||
select DATE(`date`) as pDate,avg(mhs) `value` from ${coin}_pool_30m group by pDate order by pDate
|
||||
select DATE(`date`) as pDate,avg(mhs) `value` from ${coin}_pool_30m where `date` >= DATE_SUB(NOW(), INTERVAL 90 DAY) group by pDate order by pDate
|
||||
</select>
|
||||
|
||||
<select id="getDailyNetPower" resultType="com.m2pool.pool.dto.DateBigDecimalDto">
|
||||
select DATE(`date`) as pDate,avg(`value`) `value` from ${coin}_net_power group by pDate order by pDate
|
||||
select DATE(`date`) as pDate,avg(`value`) `value` from ${coin}_net_power where `date` >= DATE_SUB(NOW(), INTERVAL 90 DAY) group by pDate order by pDate
|
||||
</select>
|
||||
|
||||
<select id="getNewGRSBlockInfoList" resultType="com.m2pool.pool.dto.BlockInfoDto">
|
||||
|
|
Loading…
Reference in New Issue