update 新增算法sha3x xtm币种,后台管理系统优化钱包出入账信息
This commit is contained in:
@@ -150,6 +150,12 @@
|
||||
<version>1.70</version> <!-- 请使用最新版本 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
||||
@@ -33,4 +33,7 @@ public class BlockInfo implements Serializable {
|
||||
/** 报块实际收益 */
|
||||
private BigDecimal profit;
|
||||
|
||||
/** 币价(目前只有xtm在使用) */
|
||||
private BigDecimal price;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ public enum PoolAmount {
|
||||
NEXA("nexa", 10000),
|
||||
RXD("rxd", 100),
|
||||
ALPH("alph", 1),
|
||||
SHA3X("sha3x", 10000),
|
||||
MONERO("monero", 0.1),
|
||||
ENX("enx", 5000);
|
||||
|
||||
/** 币种参数名 */
|
||||
|
||||
@@ -22,6 +22,7 @@ public enum PoolCalParamConfig {
|
||||
RXD("rxd", BigDecimal.valueOf(Math.pow(2,32)), BigDecimal.valueOf(288),BigDecimal.valueOf(0.01)),
|
||||
ALPH("alph", BigDecimal.valueOf(Math.pow(2,32)), BigDecimal.valueOf(5400),BigDecimal.valueOf(0.01)),
|
||||
ENX("enx", BigDecimal.valueOf(Math.pow(2,32)), BigDecimal.valueOf(86400),BigDecimal.valueOf(0.00)),
|
||||
SHA3X("sha3x", BigDecimal.valueOf(1),BigDecimal.valueOf(240) ,BigDecimal.valueOf(0.01)),
|
||||
MONERO("monero", BigDecimal.valueOf(1),BigDecimal.valueOf(720) ,BigDecimal.valueOf(0.01));
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ public enum PoolProfitScale {
|
||||
RXD("rxd", 2),
|
||||
ALPH("alph", 2),
|
||||
ENX("enx", 2),
|
||||
MONERO("monero",2);
|
||||
MONERO("monero",2),
|
||||
SHA3X("sha3x",2);
|
||||
|
||||
/** 币种参数名 */
|
||||
private final String coin;
|
||||
|
||||
@@ -20,7 +20,8 @@ public enum PoolUnits {
|
||||
RXD("rxd", "MH/s", 1000*1000, 1000),
|
||||
ALPH("alph", "MH/s", 1000*1000, 1000),
|
||||
ENX("enx", "MH/s", 1000*1000, 1000),
|
||||
MONERO("monero", "MH/s", 1000*1000, 1000);
|
||||
MONERO("monero", "MH/s", 1000*1000, 1000),
|
||||
SHA3X("sha3x", "MH/s", 1000*1000, 1000);
|
||||
/** 币种参数名 */
|
||||
private final String coin;
|
||||
/** 矿池数据单位 */
|
||||
|
||||
@@ -20,7 +20,9 @@ public enum Pools {
|
||||
RXD("rxd", "Radiant", "Sha512256D", "rxd_pool_blkstats", "rxd_mhs", "rxd_pool","rxd.png",0.985,300),
|
||||
ALPH("alph", "Alephium", "Blake3", "alph_pool_blkstats", "alph_mhs", "alph_pool","alph.svg",0.985,0),
|
||||
ENX("enx", "entropyx", "kHeavyHash", "enx_pool_blkstats", "enx_mhs", "enx_pool","enx.svg",0.985,0),
|
||||
MONERO("monero", "monero", "randomx", "monero_pool_blkstats", "monero_mhs", "monero_pool","xmr.png",0.985,0);
|
||||
MONERO("monero", "monero", "randomx", "monero_pool_blkstats", "monero_mhs", "monero_pool","xmr.png",0.985,0),
|
||||
SHA3X("sha3x", "sha3x", "sha3x", "sha3x_pool_blkstats", "sha3x_mhs", "sha3x_pool","xtm.svg",0.985,0);
|
||||
|
||||
|
||||
/** 币种参数名 */
|
||||
private final String coin;
|
||||
|
||||
@@ -65,6 +65,8 @@ public interface PoolMapper {
|
||||
|
||||
public List<BlockInfoDto> getMONEROBlockInfoList();
|
||||
|
||||
public List<BlockInfoDto> getXtmBlockInfoList();
|
||||
|
||||
@DistributionDB
|
||||
public List<BlockInfoDto> getNewNEXABlockInfoList(@Param("date") String date);
|
||||
|
||||
@@ -95,6 +97,9 @@ public interface PoolMapper {
|
||||
@DistributionDB
|
||||
public List<BlockInfoDto> getNewMONEROBlockInfoList(@Param("date") String date);
|
||||
|
||||
@DistributionDB
|
||||
public List<BlockInfoDto> getNewXtmBlockInfoList(@Param("date") String date);
|
||||
|
||||
|
||||
@HashRateDB
|
||||
public List<MinerDataDto> getMinerInfoList(@Param("table") String table);
|
||||
@@ -271,12 +276,16 @@ public interface PoolMapper {
|
||||
*/
|
||||
BlockInfo getMoneroBlockInfo();
|
||||
|
||||
BlockInfo getXtmBlockInfo();
|
||||
|
||||
int insertXtmBlockInfo(@Param("blockInfo") BlockInfo blockInfo);
|
||||
|
||||
|
||||
int deleteMhs30m(@Param("coin") String coin,@Param("date") String date);
|
||||
|
||||
|
||||
int deletePool30m(@Param("coin") String coin,@Param("date") String date);
|
||||
|
||||
int deleteUsers30m(@Param("coin") String coin,@Param("date") String date);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4762,4 +4762,259 @@ public class DataTask {
|
||||
dto.getLuck3d(),dto.getLuck7d(),dto.getLuck30d(),dto.getLuck90d());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Scheduled(cron = "0 1,3,5 0 * * ?")
|
||||
public void XtmDailyDataToDB(){
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
String nowStr = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD);
|
||||
Date now = DateUtils.parseDate( nowStr);
|
||||
|
||||
//检查二级表是否有当前时间数据
|
||||
int count = poolMapper.getLastDataTime(Pools.SHA3X.getMhs() + "24h", nowStr);
|
||||
|
||||
if(count == 0) {
|
||||
List<MinerDataDto> list = poolMapper.getDailyMinerDataList(Pools.SHA3X.getMhs()+"_realv2", nowStr);
|
||||
if(list.size() > 0){
|
||||
list.stream().forEach(e -> {
|
||||
if(StringUtils.isNotNull(e.getMhs())){
|
||||
e.setMhs(e.getMhs() * Pools.SHA3X.getFac());
|
||||
}
|
||||
});
|
||||
list = filterList(list,now);
|
||||
//list.stream().forEach(e ->{
|
||||
// e.setDate(DateUtils.addDays(e.getDate(),-1));
|
||||
//});
|
||||
boolean result = poolMapper.batchInsertMhsDataToDB(Pools.SHA3X.getMhs() + "24h", getToDailyDBListByMinerDataList(list));
|
||||
//todo 统计矿池数据写入矿池数据库 $coin_pool_24h
|
||||
Map<Date, List<MinerDataDto>> map = list.stream().collect(Collectors.groupingBy(MinerDataDto::getDate));
|
||||
map.forEach((date,dList) -> {
|
||||
PoolPower poolPower = new PoolPower();
|
||||
//poolPower.setDate(date);
|
||||
poolPower.setDateStr(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||
Map<String, Long> stateCount = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getState, Collectors.counting()));
|
||||
poolPower.setMhs(dList.stream().map(e -> BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().stripTrailingZeros());
|
||||
poolPower.setMiners(dList.size());
|
||||
poolPower.setOnline(Convert.toInt(stateCount.get("online"),0));
|
||||
poolPower.setOffline(Convert.toInt(stateCount.get("offline"),0));
|
||||
|
||||
boolean poolResult = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_24h", poolPower);
|
||||
int time =0;
|
||||
while (!poolResult){
|
||||
poolResult = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_24h", poolPower);
|
||||
if (time > 5) {
|
||||
break;
|
||||
}
|
||||
time ++;
|
||||
}
|
||||
|
||||
//写入数据到coin_users表中
|
||||
Map<String, List<MinerDataDto>> userMap = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getUser));
|
||||
List<MinerDataInsertDBDto> userList = new ArrayList<>();
|
||||
userMap.forEach((user,uList)->{
|
||||
MinerDataInsertDBDto uDto = new MinerDataInsertDBDto();
|
||||
uDto.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||
uDto.setUser(user);
|
||||
uDto.setMhs(uList.stream().map(e->BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().doubleValue());
|
||||
userList.add(uDto);
|
||||
} );
|
||||
|
||||
boolean userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_24h", userList);
|
||||
int uTime =0;
|
||||
while (!userResult){
|
||||
userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_24h", userList);
|
||||
if (uTime > 5) {
|
||||
break;
|
||||
}
|
||||
uTime ++;
|
||||
}
|
||||
});
|
||||
if(result){
|
||||
System.out.println(DateUtils.dateTimeNow()+"XTM 每日存入数据成功");
|
||||
}else {
|
||||
System.out.println(DateUtils.dateTimeNow()+"XTM 每日存入数据失败");
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
CompletableFuture.runAsync(()->{
|
||||
System.out.println("XTM 每日矿池定时任务执行失败 延时一分钟时间重新查询");
|
||||
System.out.println("延迟后使用的查询时间:"+now);
|
||||
System.out.println("延迟后 格式化后的时间:"+nowStr);
|
||||
|
||||
//检查二级表是否有当前时间数据
|
||||
int newCount = poolMapper.getLastDataTime(Pools.SHA3X.getMhs() + "24h", nowStr);
|
||||
if(newCount == 0){
|
||||
List<MinerDataDto> newList = poolMapper.getDailyMinerDataList(Pools.SHA3X.getMhs()+"_realv2", nowStr);
|
||||
if(newList.size() > 0){
|
||||
|
||||
newList.stream().forEach(e -> {
|
||||
if(StringUtils.isNotNull(e.getMhs())){
|
||||
e.setMhs(e.getMhs() * Pools.SHA3X.getFac());
|
||||
}
|
||||
});
|
||||
|
||||
newList = filterList(newList,now);
|
||||
|
||||
boolean newResult = poolMapper.batchInsertMhsDataToDB(Pools.SHA3X.getMhs() + "24h", getToDailyDBListByMinerDataList(newList));
|
||||
|
||||
Map<Date, List<MinerDataDto>> map2 = newList.stream().collect(Collectors.groupingBy(MinerDataDto::getDate));
|
||||
map2.forEach((date,dList) -> {
|
||||
PoolPower poolPower = new PoolPower();
|
||||
//poolPower.setDate(date);
|
||||
poolPower.setDateStr(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||
Map<String, Long> stateCount = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getState, Collectors.counting()));
|
||||
poolPower.setMhs(dList.stream().map(e -> BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().stripTrailingZeros());
|
||||
poolPower.setMiners(dList.size());
|
||||
poolPower.setOnline(Convert.toInt(stateCount.get("online"),0));
|
||||
poolPower.setOffline(Convert.toInt(stateCount.get("offline"),0));
|
||||
|
||||
boolean poolResult2 = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_24h", poolPower);
|
||||
int time =0;
|
||||
while (!poolResult2){
|
||||
poolResult2 = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_24h", poolPower);
|
||||
if (time > 5) {
|
||||
break;
|
||||
}
|
||||
time ++;
|
||||
}
|
||||
|
||||
Map<String, List<MinerDataDto>> userMap = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getUser));
|
||||
List<MinerDataInsertDBDto> userList = new ArrayList<>();
|
||||
userMap.forEach((user,uList)->{
|
||||
MinerDataInsertDBDto uDto = new MinerDataInsertDBDto();
|
||||
uDto.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||
uDto.setUser(user);
|
||||
uDto.setMhs(uList.stream().map(e->BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().doubleValue());
|
||||
userList.add(uDto);
|
||||
} );
|
||||
|
||||
boolean userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_24h", userList);
|
||||
int uTime =0;
|
||||
while (!userResult){
|
||||
userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_24h", userList);
|
||||
if (uTime > 5) {
|
||||
break;
|
||||
}
|
||||
uTime ++;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}else {
|
||||
PoolPower poolPower = new PoolPower();
|
||||
poolPower.setDate(now);
|
||||
poolPower.setMhs(BigDecimal.ZERO);
|
||||
poolPower.setMiners(0);
|
||||
poolPower.setOnline(0);
|
||||
poolPower.setOffline(0);
|
||||
boolean poolResult = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_24h", poolPower);
|
||||
System.out.println("延时任务未查到 构造0数据入库,结果:"+poolPower);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "50 0,1,30,31 * * * ?")
|
||||
public void XtmUserPowerRatioDataToDB(){
|
||||
//String nowStr = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:00");
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
Date now = new Date();
|
||||
now.setHours(0);
|
||||
now.setMinutes(0);
|
||||
now.setSeconds(0);
|
||||
String nowStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
|
||||
|
||||
BigDecimal poolMhs = poolMapper.getPoolTodayTotalPower("sha3x", nowStr);
|
||||
List<UserPowerDto> userMhsList = poolMapper.getUserTodayTotalPower("sha3x", nowStr);
|
||||
HashMap<String,BigDecimal> map = new HashMap<>();
|
||||
userMhsList.stream().forEach(e ->{
|
||||
map.put(e.getUser(),e.getMhs().divide(poolMhs,8,BigDecimal.ROUND_HALF_UP));
|
||||
});
|
||||
|
||||
if(map.size() >0){
|
||||
redisService.deleteObject("sha3xUserPowerRatio");
|
||||
redisService.setCacheMap("sha3xUserPowerRatio",map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Scheduled(cron = "30 3 0/1 * * ?")
|
||||
//@Scheduled(cron = "0 0/2 * * * ?")
|
||||
public void XtmLuckyDataToDB(){
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
log.info("sha3x 幸运值---定时任务开始");
|
||||
LuckDto dto = new LuckDto();
|
||||
Date end = DateUtils.parseDate(DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS));
|
||||
//幸运值 = 矿池实际报块/矿池理论报块
|
||||
//矿池实际报块 = distribution数据库查询表名为 币名_blkreportprofitv2
|
||||
//矿池理论报块 = (矿池过去N段时间的平均算力 / 全网过去N段时间平均算力) * 全网过去N段时间实际报块
|
||||
Date start3d = DateUtils.addDays(end,-3);
|
||||
Date start7d = DateUtils.addDays(end,-7);
|
||||
Date start30d = DateUtils.addDays(end,-30);
|
||||
Date start90d = DateUtils.addDays(end,-90);
|
||||
|
||||
//获取全网实际90天内的报块数(v2)
|
||||
List<BlockInfoDto> blockPerDays = poolMapper.selectNetBlock("sha3x_net_block");
|
||||
boolean useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start3d);
|
||||
//获取3天内全网的实际报块数
|
||||
BlockTimeAndNumberDto blockData = blockDataContext.getBlockData("sha3x",start3d, end,blockPerDays, useAggregated);
|
||||
//3天矿池理论报块数
|
||||
BigDecimal throreticalBlocks = getTheoreticalBlocks("sha3x",PoolUnits.SHA3X.gethRate(),start3d, end, blockData);
|
||||
//3天矿池实际报块数
|
||||
int actualBlocks = poolMapper.selectPoolBlock(start3d, end,"sha3x",3);
|
||||
log.info("sha3x 3天实际报块数{},理论报块数{},全网实际报块数{},开始时间{},结束时间{}",actualBlocks,throreticalBlocks,blockData.getHeight(),start3d,end);
|
||||
//3天幸运值
|
||||
if(!BigDecimal.ZERO.equals(throreticalBlocks)){
|
||||
dto.setLuck3d(BigDecimal.valueOf(actualBlocks).multiply(BigDecimal.valueOf(100)).divide(throreticalBlocks,2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
//7天幸运值
|
||||
useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start7d);
|
||||
|
||||
blockData = blockDataContext.getBlockData("sha3x",start7d, end,blockPerDays, useAggregated);
|
||||
throreticalBlocks= getTheoreticalBlocks("sha3x",PoolUnits.SHA3X.gethRate(),start7d, end, blockData);
|
||||
actualBlocks = poolMapper.selectPoolBlock(start7d, end,"sha3x",7);
|
||||
log.info("sha3x 7天实际报块数{},理论报块数{}",actualBlocks,throreticalBlocks);
|
||||
if(!BigDecimal.ZERO.equals(throreticalBlocks)){
|
||||
dto.setLuck7d(BigDecimal.valueOf(actualBlocks).multiply(BigDecimal.valueOf(100)).divide(throreticalBlocks,2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
|
||||
//30天幸运值
|
||||
useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start30d);
|
||||
|
||||
blockData = blockDataContext.getBlockData("sha3x",start30d, end,blockPerDays, useAggregated);
|
||||
throreticalBlocks= getTheoreticalBlocks("sha3x",PoolUnits.SHA3X.gethRate(),start30d, end, blockData);
|
||||
actualBlocks = poolMapper.selectPoolBlock(start30d, end,"sha3x",30);
|
||||
log.info("sha3x 30天实际报块数{},理论报块数{}",actualBlocks,throreticalBlocks);
|
||||
if(!BigDecimal.ZERO.equals(throreticalBlocks)){
|
||||
dto.setLuck30d(BigDecimal.valueOf(actualBlocks).multiply(BigDecimal.valueOf(100)).divide(throreticalBlocks,2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
|
||||
//90天幸运值
|
||||
useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start90d);
|
||||
|
||||
blockData = blockDataContext.getBlockData("sha3x",start90d, end,blockPerDays, useAggregated);
|
||||
throreticalBlocks= getTheoreticalBlocks("sha3x",PoolUnits.SHA3X.gethRate(),start90d, end, blockData);
|
||||
actualBlocks = poolMapper.selectPoolBlock(start90d, end,"sha3x",90);
|
||||
log.info("sha3x 90天实际报块数{},理论报块数{}",actualBlocks,throreticalBlocks);
|
||||
if(!BigDecimal.ZERO.equals(throreticalBlocks)){
|
||||
dto.setLuck90d(BigDecimal.valueOf(actualBlocks).multiply(BigDecimal.valueOf(100)).divide(throreticalBlocks,2, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
|
||||
redisService.deleteObject("SHA3XLuck");
|
||||
redisService.setCacheObject("SHA3XLuck",dto);
|
||||
log.info("sha3x 幸运值入库完成---幸运值3天:{},幸运值7天:{},幸运值30天:{},幸运值90天:{},",
|
||||
dto.getLuck3d(),dto.getLuck7d(),dto.getLuck30d(),dto.getLuck90d());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.m2pool.common.core.utils.DateUtils;
|
||||
import com.m2pool.common.core.utils.StringUtils;
|
||||
import com.m2pool.common.redis.service.RedisService;
|
||||
import com.m2pool.pool.entity.BlockInfo;
|
||||
import com.m2pool.pool.mapper.PoolMapper;
|
||||
import com.m2pool.pool.utils.NodeRpc;
|
||||
import com.m2pool.pool.vo.DateValueVo;
|
||||
import lombok.Data;
|
||||
import org.apache.http.HttpHeaders;
|
||||
@@ -22,6 +22,8 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.m2pool.pool.utils.dome4j.getSha3xBlockInfoForXml;
|
||||
|
||||
/**
|
||||
* @Description nexa 币价定时任务 每小时定时从CoinMarketCap拿
|
||||
* @Date 2024/6/14 14:03
|
||||
@@ -49,10 +51,10 @@ public class NeaxPriceTask {
|
||||
|
||||
//@Scheduled(cron = "0 0/1 * * * ?")
|
||||
@Scheduled(cron = "0 0,3,30,33 * * * ?")
|
||||
public void NEXAPriceToRedis()
|
||||
public void PriceToRedisAndDb()
|
||||
{
|
||||
if(!enable){
|
||||
System.out.println("NeaxPriceTask 定时任务已关闭,请在nacos修改配置");
|
||||
System.out.println("PriceTask 定时任务已关闭,请在nacos修改配置");
|
||||
return;
|
||||
}
|
||||
Map<String, BigDecimal> map = getResultFromNetByAllCoins();
|
||||
@@ -64,6 +66,7 @@ public class NeaxPriceTask {
|
||||
|| StringUtils.isNull(map.get("rxd"))
|
||||
|| StringUtils.isNull(map.get("alph"))
|
||||
|| StringUtils.isNull(map.get("monero"))
|
||||
|| StringUtils.isNull(map.get("sha3x"))
|
||||
){
|
||||
if(count >= 10){
|
||||
break;
|
||||
@@ -237,6 +240,18 @@ public class NeaxPriceTask {
|
||||
moneroVo.setValue(monero);
|
||||
poolMapper.insertPrice("monero_price",date , moneroVo);
|
||||
}
|
||||
|
||||
|
||||
//处理xtm
|
||||
BigDecimal sha3x = map.get("sha3x");
|
||||
if(StringUtils.isNotNull(sha3x)){
|
||||
redisService.setCacheObject("sha3x_price",sha3x);
|
||||
//存入数据库
|
||||
DateValueVo xtmVo = new DateValueVo();
|
||||
xtmVo.setDate(now);
|
||||
xtmVo.setValue(sha3x);
|
||||
poolMapper.insertPrice("sha3x_price",date , xtmVo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,6 +490,11 @@ public class NeaxPriceTask {
|
||||
map.put("alph",alphPrice);
|
||||
map.put("monero",moneroPrice);
|
||||
|
||||
//xtm 不通过coinmarketcap 获取币价
|
||||
BlockInfo sha3xBlockInfoForXml = getSha3xBlockInfoForXml();
|
||||
if (StringUtils.isNotNull(sha3xBlockInfoForXml)){
|
||||
map.put("sha3x",sha3xBlockInfoForXml.getPrice());
|
||||
}
|
||||
return map;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -663,9 +663,7 @@ public class NodeTask {
|
||||
//总高度 - 上次的总高度 然后循环遍历这些块高度,来判断该块的算法类型,
|
||||
for (int i = Integer.parseInt(height) ; i > lastHeight ; i--){
|
||||
String hashBlock = NodeRpc.getBlockInfoByHeight("dgbq", i);
|
||||
System.out.println("dgb 总高度hashBlock:"+hashBlock);
|
||||
String dgbType = NodeRpc.getBlockInfoByHash("dgbq", hashBlock);
|
||||
System.out.println("dgb 总高度dgbType:"+dgbType);
|
||||
if("qubit".equals(dgbType)){
|
||||
dgbqIncrement++;
|
||||
}else if ("odo".equals(dgbType)){
|
||||
@@ -719,7 +717,6 @@ public class NodeTask {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public BlockInfo getMONEROBlock() {
|
||||
BlockInfo moneroBlockInfo = poolMapper.getMoneroBlockInfo();
|
||||
System.out.println("moneroBlockInfo"+moneroBlockInfo);
|
||||
@@ -802,4 +799,88 @@ public class NodeTask {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BlockInfo getSha3xOBlock() {
|
||||
BlockInfo sha3xBlockInfo = poolMapper.getXtmBlockInfo();
|
||||
System.out.println("sha3xBlockInfo"+sha3xBlockInfo);
|
||||
if(StringUtils.isNull(sha3xBlockInfo)){
|
||||
return null;
|
||||
}
|
||||
BigDecimal moreroBlocks = PoolCalParamConfig.getCoinCount("sha3x");
|
||||
BigDecimal profit = sha3xBlockInfo.getReward();
|
||||
|
||||
// 保留两位小数
|
||||
profit = profit.setScale(1, RoundingMode.HALF_UP);
|
||||
sha3xBlockInfo.setProfit(profit);
|
||||
|
||||
return sha3xBlockInfo;
|
||||
}
|
||||
|
||||
//TODO
|
||||
@Scheduled(cron = "50 0,30 * * * ?")
|
||||
public void Sha3xBlockInfoToRedisAndDB(){
|
||||
System.out.println("执行全网算力入库sha3x");
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
BlockInfo blockInfo = getSha3xOBlock();
|
||||
|
||||
int count = 1;
|
||||
while (StringUtils.isNull(blockInfo)){
|
||||
if(count >= 10){
|
||||
break;
|
||||
}
|
||||
blockInfo = getSha3xOBlock();
|
||||
count++;
|
||||
}
|
||||
System.out.println("sha3x blockInfo 的信息"+blockInfo);
|
||||
if(StringUtils.isNotNull(blockInfo)){
|
||||
if(StringUtils.isNotNull(blockInfo.getPower())){
|
||||
redisService.setCacheObject("sha3x_block",blockInfo);
|
||||
//存入数据库
|
||||
DateValueVo vo = new DateValueVo();
|
||||
Date now = new Date();
|
||||
int minute = (now.getMinutes() / 30) * 30;
|
||||
now.setMinutes( minute);
|
||||
now.setSeconds(0);
|
||||
vo.setDate(now);
|
||||
String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
|
||||
System.out.println("sha3x全网算力数据入库时间:"+date);
|
||||
vo.setValue(blockInfo.getPower());
|
||||
poolMapper.insertNetPower("sha3x_net_power",date,vo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO
|
||||
@Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void XtmBlockInfoToRedis(){
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
BlockInfo blockInfo = getSha3xOBlock();
|
||||
int count = 0;
|
||||
while (StringUtils.isNull(blockInfo)){
|
||||
if(count >= 3){
|
||||
break;
|
||||
}
|
||||
blockInfo = getSha3xOBlock();
|
||||
count++;
|
||||
}
|
||||
|
||||
if(StringUtils.isNotNull(blockInfo)){
|
||||
if(StringUtils.isNotNull(blockInfo.getPower())){
|
||||
|
||||
if (redisService.hasKey("sha3x_block")){
|
||||
redisService.deleteObject("sha3x_block");
|
||||
redisService.setCacheObject("sha3x_block",blockInfo);
|
||||
}else {
|
||||
redisService.setCacheObject("sha3x_block",blockInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -850,5 +850,89 @@ public class OffLineNoticeTask {
|
||||
|
||||
}
|
||||
|
||||
@Scheduled(cron = "25 26,46 * * * ?")
|
||||
public void Sha3x30mDataToDB(){
|
||||
//String nowStr = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:00");
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
Date now = new Date();
|
||||
int minute = (now.getMinutes() / 30) * 30;
|
||||
now.setMinutes( minute);
|
||||
now.setSeconds(0);
|
||||
String nowStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
|
||||
|
||||
System.out.println("SHA3X 预警定时任务执行时间:"+now);
|
||||
|
||||
//检查二级表是否有当前时间数据
|
||||
int count = poolMapper.getLastDataTime(Pools.SHA3X.getMhs() + "30m", nowStr);
|
||||
System.out.println("count:"+count);
|
||||
|
||||
if(count > 0) {
|
||||
//查询离线矿机数和离线矿机 按挖矿账户分
|
||||
List<OfflineUserMinerDto> list = poolMapper.getOfflineList(Pools.SHA3X.getMhs() + "30m", nowStr);
|
||||
|
||||
System.out.println("查询到离线矿机结果 "+list.size()+"条");
|
||||
if(StringUtils.isNotEmpty(list)){
|
||||
//list不为空才处理
|
||||
|
||||
//先获取通知列表 TODO 这里查询notice_info为空,notice_info 里面存的从哪里来?
|
||||
List<NoticeMinerCoinListDto> nmcList = noticeMapper.getNoticeEmailListByMinerAndCoin(list, Pools.SHA3X.getCoin());
|
||||
System.out.println("查询到离线通知列表"+nmcList);
|
||||
Map<String, List<String>> userEmails = nmcList.stream().
|
||||
collect(Collectors.groupingBy(
|
||||
NoticeMinerCoinListDto::getMiner,
|
||||
Collectors.mapping(NoticeMinerCoinListDto::getEmail, Collectors.toList())
|
||||
));
|
||||
|
||||
|
||||
if(StringUtils.isNotEmpty(userEmails)){
|
||||
//获取上一次离线矿机数 可能为null 要做处理 如果没有redis记录 则上次离线数设置为0 若有redis但是key没有此挖矿账户也设置上次离线数为0 TODO 这里也没看到redis里面存储的位置
|
||||
Map<String, Long> map = redisService.getCacheMap("SHA3X_USERS_OFFLINE");
|
||||
list.stream().forEach(e -> {
|
||||
long lastOff = 0;
|
||||
if(StringUtils.isNotNull(map)){
|
||||
lastOff =map.getOrDefault(e.getUser(),0L);
|
||||
}
|
||||
if(e.getOffline() > lastOff){
|
||||
//对比redis中该挖矿账户上一次离线矿机数 上一次不存在则设上一次离线数为0来进行比较
|
||||
//仅当本次离线数大于上次离线数时才通知
|
||||
//执行通知
|
||||
List<String> emails = userEmails.getOrDefault(e.getUser(), null);
|
||||
if(StringUtils.isNotNull(emails)){
|
||||
String text = "您的"+Pools.SHA3X.getCoin()+"下挖矿账户: "+e.getUser()+"有矿机离线!离线矿机列表如下:\n" +
|
||||
e.getMiners() + " \n"+
|
||||
"若您的矿机是因异常断开,请及时处理!";
|
||||
emails.stream().forEach(email ->{
|
||||
System.out.println("用户"+e.getUser()+"矿机离线通知到"+email);
|
||||
EmailEntity entity = new EmailEntity();
|
||||
entity.setSubject("[M2Pool] 矿机离线提示");
|
||||
entity.setEmail(email);
|
||||
entity.setText(text);
|
||||
mailService.sendTextMail(entity);
|
||||
});
|
||||
}else {
|
||||
System.out.println("该用户未添加离线通知 :"+userEmails.toString());
|
||||
}
|
||||
|
||||
}else {
|
||||
//不满足通知条件 不通知
|
||||
System.out.println("挖矿账户"+e.getUser()+"本次无需通知,本次离线为"+e.getOffline()+",上次离线数"+
|
||||
map.getOrDefault(e.getUser(),0L));
|
||||
}
|
||||
});
|
||||
}else {
|
||||
System.out.println("未获取到SHA3X下相关的离线告警订阅信息");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
//最新数据未入库暂不做处理
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -217,6 +217,24 @@ public class PoolBlkStatsTask {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@Scheduled(cron = "50 0/2 * * * ?")
|
||||
public void XTMBlockInfoToRedis(){
|
||||
if(!enable){
|
||||
return;
|
||||
}
|
||||
|
||||
boolean result = XTMBlockInfo();
|
||||
|
||||
int count = 1;
|
||||
//执行失败返回false 再次执行
|
||||
while (!result){
|
||||
if(count >= 3){
|
||||
break;
|
||||
}
|
||||
result = XTMBlockInfo();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean NEXABlockInfo(){
|
||||
try {
|
||||
@@ -559,4 +577,37 @@ public class PoolBlkStatsTask {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean XTMBlockInfo(){
|
||||
try {
|
||||
String lastDate= "";
|
||||
|
||||
if(redisService.hasKey("sha3x_pool_last_date")){
|
||||
lastDate = (String) redisService.getCacheObject("sha3x_pool_last_date");
|
||||
System.out.println("redis中的lastDate:"+lastDate);
|
||||
}else {
|
||||
List<BlockInfoDto> list = poolMapper.getXtmBlockInfoList();
|
||||
if (list.size() > 0){
|
||||
lastDate =DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,list.get(0).getDate());
|
||||
}else {
|
||||
lastDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,new Date());
|
||||
}
|
||||
}
|
||||
System.out.println("最终的lastDate:"+lastDate);
|
||||
|
||||
List<BlockInfoDto> list = poolMapper.getNewXtmBlockInfoList(lastDate);
|
||||
|
||||
if(!list.isEmpty()){
|
||||
//存入数据库
|
||||
poolMapper.batchInsertNexaPoolBlkToDB(list);
|
||||
//把最大时间存入redis
|
||||
String maxDate =DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,list.get(list.size()-1).getDate());
|
||||
redisService.setCacheObject("sha3x_pool_last_date",maxDate);
|
||||
}
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
System.out.println("出错内容:"+e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -584,6 +584,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
order by `date` desc
|
||||
</select>
|
||||
|
||||
<select id="getXtmBlockInfoList" resultType="com.m2pool.pool.dto.BlockInfoDto">
|
||||
select
|
||||
height,
|
||||
`date`,
|
||||
hash,
|
||||
reward,
|
||||
fees
|
||||
from
|
||||
xtm_pool_blkstats
|
||||
order by `date` desc
|
||||
</select>
|
||||
|
||||
<select id="getNewALPHBlockInfoList" resultType="com.m2pool.pool.dto.BlockInfoDto">
|
||||
select
|
||||
height,
|
||||
@@ -626,6 +638,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
order by `date`
|
||||
</select>
|
||||
|
||||
<select id="getNewXtmBlockInfoList" resultType="com.m2pool.pool.dto.BlockInfoDto">
|
||||
select
|
||||
height,
|
||||
`date`,
|
||||
hash,
|
||||
reward,
|
||||
fees
|
||||
from
|
||||
tari_blkreportprofitv2
|
||||
where
|
||||
`date` > #{date}
|
||||
order by `date`
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<insert id="batchInsertMhsDataToDB" statementType="STATEMENT">
|
||||
insert into ${table}(
|
||||
@@ -959,6 +986,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
insert into dgb_total_block (`height`) values(#{height}) ON DUPLICATE KEY UPDATE `height` = VALUES(`height`)
|
||||
</insert>
|
||||
|
||||
|
||||
<select id="selectNetBlock" resultType="com.m2pool.pool.dto.BlockInfoDto">
|
||||
SELECT `date`,height FROM ${tableName} WHERE `date` >= DATE_SUB(now(),INTERVAL 90 DAY) ORDER BY `date` DESC
|
||||
</select>
|
||||
@@ -986,6 +1014,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select height,difficulty,power,reward,fees,profit from monero_block_info order by id desc limit 1;
|
||||
</select>
|
||||
|
||||
<select id="getXtmBlockInfo" resultType="com.m2pool.pool.entity.BlockInfo">
|
||||
select height,difficulty,power,reward,fees,profit from xtm_block_info order by id desc limit 1;
|
||||
</select>
|
||||
|
||||
<insert id="insertXtmBlockInfo">
|
||||
insert into xtm_block_info (height,difficulty,power,reward,fees,profit,price)
|
||||
values(#{blockInfo.height}
|
||||
,#{blockInfo.difficulty}
|
||||
,#{blockInfo.power}
|
||||
,#{blockInfo.reward}
|
||||
,#{blockInfo.fees}
|
||||
,#{blockInfo.profit}
|
||||
,#{blockInfo.price})
|
||||
</insert>
|
||||
|
||||
|
||||
<delete id="deleteMhs30m">delete from ${coin}_mhs30m where `date` = #{date} </delete>
|
||||
<delete id="deletePool30m">delete from ${coin}_pool_30m where `date` = #{date}</delete>
|
||||
<delete id="deleteUsers30m">delete from ${coin}_users_30m where `date` = #{date}</delete>
|
||||
|
||||
Reference in New Issue
Block a user