update 新增算法sha3x xtm币种,后台管理系统优化钱包出入账信息

This commit is contained in:
yyb
2025-09-28 13:48:27 +08:00
parent ef395c5253
commit 2efa65222d
22 changed files with 670 additions and 92 deletions

View File

@@ -1,5 +1,6 @@
package com.m2pool.common.security.config;
import com.m2pool.common.security.interceptor.CoinInterceptor;
import com.m2pool.common.security.interceptor.HeaderInterceptor;
import com.m2pool.common.security.interceptor.OpenApiHeaderInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -25,7 +26,6 @@ public class WebMvcConfig implements WebMvcConfigurer {
"/miner/hashrate_real","/miner/hashrate_history","/miner/hashrate_last24h",
"/pool/hashrate","/pool/hashrate_history","/pool/miners_list","/pool/watch","/oapi/**"};
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(getHeaderInterceptor())
@@ -34,9 +34,14 @@ public class WebMvcConfig implements WebMvcConfigurer {
.order(-10);
registry.addInterceptor(getOpenApiHeaderInterceptor())
.addPathPatterns(matchUrls).
excludePathPatterns("/auth/**,/system/**,/pool/**")
.addPathPatterns(matchUrls)
.excludePathPatterns("/auth/**,/system/**,/pool/**")
.order(-15);
//registry.addInterceptor(getCoinInterceptor())
// .addPathPatterns("/**")
// .order(-20);
}
/**
* 自定义请求头拦截器
@@ -45,4 +50,5 @@ public class WebMvcConfig implements WebMvcConfigurer {
public OpenApiHeaderInterceptor getOpenApiHeaderInterceptor(){return new OpenApiHeaderInterceptor();}
public CoinInterceptor getCoinInterceptor(){return new CoinInterceptor();}
}

View File

@@ -2,11 +2,9 @@ package com.m2pool.manage.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@@ -19,9 +17,13 @@ import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ManageWalletOutIn {
@EqualsAndHashCode(callSuper = false)
public class ManageWalletOutIn implements Serializable {
private static final long serialVersionUID=1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private Long id;
private String coin;
@@ -29,7 +31,9 @@ public class ManageWalletOutIn {
private String address;
private LocalDateTime date;
private LocalDateTime dateIn;
private LocalDateTime dateOut;
private LocalDateTime shouldOutDate;

View File

@@ -137,6 +137,7 @@ public class ManageDocumentsServiceImpl extends ServiceImpl<ManageDocumentsMappe
@Override
public R<String> deleteDocument(ManageBaseVo manageBaseVo) {
//int i = manageDocumentsMapper.updateById(ManageDocuments.builder().id(manageBaseVo.getId()).del(true).build());
int delete = manageDocumentsMapper.deleteById(manageBaseVo.getId());
DeleteResult remove = mongoTemplate.remove(new Query(Criteria.where("id").is(manageBaseVo.getId())), "documents");
if (delete > 0){

View File

@@ -1,5 +1,6 @@
package com.m2pool.manage.task;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.m2pool.common.core.utils.DateUtils;
import com.m2pool.manage.entity.ManageWalletOutIn;
@@ -42,88 +43,88 @@ public class ManageTask {
/**
* 存储交易记录定时任务
*/
//@Scheduled(cron = "22 58 0/1 * * ?")
//@Scheduled(cron = "22 25 0/1 * * ?")
@Scheduled(cron = "0 0/1 * * * ?")
@DSTransactional
public void insertDataToWalletOutInDb(){
LocalDateTime maxDateData = manageWalletOutInMapper.getMaxDateData();
LocalDateTime startDate = null;
List<ManageWalletOutIn> manageWalletOutIns = new ArrayList<>();
if (maxDateData != null){
startDate = LocalDateTime.now().toLocalDate().atStartOfDay();
//获取startDate 后的数据,用于比对
manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper<ManageWalletOutIn>()
.ge(ManageWalletOutIn::getDate, startDate));
.ge(ManageWalletOutIn::getDateIn, maxDateData));
}
List<ManageWalletOutIn> walletIn = manageWalletOutInMapper.getWalletIn(startDate);
List<ManageWalletOutIn> walletOut = manageWalletOutInMapper.getWalletOut(startDate);
List<ManageWalletOutIn> walletIn = manageWalletOutInMapper.getWalletIn(maxDateData);
List<ManageWalletOutIn> walletOut = manageWalletOutInMapper.getWalletOut(maxDateData);
//date_in 是in表实际入账时间;in表带有预计转账时间should_out_date
Map<String, List<ManageWalletOutIn>> walletInMap = walletIn.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDate().toLocalDate().atStartOfDay()
item.getUser() + item.getCoin() + item.getShouldOutDate().toLocalDate().atStartOfDay()
));
//date_out 是out表实际转账时间
Map<String, List<ManageWalletOutIn>> walletOutMap = walletOut.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDate().toLocalDate().atStartOfDay()
item.getUser() + item.getCoin() + item.getDateOut().toLocalDate().atStartOfDay()
));
List<ManageWalletOutIn> walletInfo = new ArrayList<>();
//外层为out内层为in
// 比较 out 和 in 表的 date_out 和 date_in 以及 max_height 字段,如果都相同,则组合成一条数据
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletOutMap.entrySet()) {
String key = outEntry.getKey();
String outKey = outEntry.getKey();
List<ManageWalletOutIn> outList = outEntry.getValue();
if (walletInMap.containsKey(key)) {
List<ManageWalletOutIn> inList = walletInMap.get(key);
// 处理 outList 与 inList 匹配的项
List<ManageWalletOutIn> updatedOutList = outList.stream()
.peek(outItem -> inList.stream()
.filter(inItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight()))
.findFirst()
.ifPresent(inItem -> {
outItem.setShouldOutDate(inItem.getShouldOutDate());
outItem.setAllocationAmount(inItem.getAllocationAmount());
}))
// inList 中包含 outMap 的 key则说明有相同的数据这个时候比对 max_height
if (walletInMap.containsKey(outKey)) {
List<ManageWalletOutIn> inList = walletInMap.get(outKey);
List<ManageWalletOutIn> insertOutList = outList.stream()
.peek(outItem -> {
outItem.setDateIn(outItem.getDateOut());
inList.stream()
.filter(inItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight()))
.findFirst()
.ifPresent(inItem -> {
// 前期一些 in 表没有 should_out_date 存储为空
LocalDateTime shouldOutDate = inItem.getShouldOutDate();
outItem.setShouldOutDate(shouldOutDate != null ? shouldOutDate : outItem.getDateOut().toLocalDate().atStartOfDay());
outItem.setDateIn(inItem.getDateIn());
outItem.setAllocationAmount(inItem.getAllocationAmount());
});
})
.collect(Collectors.toList());
walletInfo.addAll(updatedOutList);
walletInfo.addAll(insertOutList);
// 处理 inList 中未匹配的项
List<ManageWalletOutIn> updatedInList = inList.stream()
// inList 中如果没有任何匹配的 outList 数据,则把 inList 数据添加到 walletInfo 中
List<ManageWalletOutIn> insertInList = inList.stream()
.filter(inItem -> outList.stream()
.noneMatch(outItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight())))
.noneMatch(outItem -> inItem.getMaxHeight().equals(outItem.getMaxHeight())))
.collect(Collectors.toList());
walletInfo.addAll(updatedInList);
walletInfo.addAll(insertInList);
} else {
List<ManageWalletOutIn> collect = outList.stream().peek(outItem -> {
if (outItem.getShouldOutDate() == null) {
outItem.setShouldOutDate(outItem.getDate().toLocalDate().atStartOfDay());
}
}).collect(Collectors.toList());
walletInfo.addAll(collect);
// 只有 walletOut没有对应的 walletIn
walletInfo.addAll(outList);
}
}
//外层为in内层为out -----新增当天只有walletIn,没有walletOut的数据
for (Map.Entry<String, List<ManageWalletOutIn>> inEntry : walletInMap.entrySet()) {
String key = inEntry.getKey();
// 当天只有 walletIn没有 walletOut 的数据
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletInMap.entrySet()) {
String key = outEntry.getKey();
if (!walletOutMap.containsKey(key)) {
walletInfo.addAll(inEntry.getValue());
walletInfo.addAll(outEntry.getValue());
}
}
List<ManageWalletOutIn> collect = walletInfo.stream().sorted(Comparator.comparing(ManageWalletOutIn::getDate)).collect(Collectors.toList());
//查询ManageWalletOutIn 数据,比对是否修改
if (!manageWalletOutIns.isEmpty()){
List<ManageWalletOutIn> updateList = new ArrayList<>();
List<ManageWalletOutIn> saveList = new ArrayList<>();
for (ManageWalletOutIn item : collect) {
for (ManageWalletOutIn item : walletInfo) {
manageWalletOutIns.stream()
.filter(dbItem -> dbItem.getCoin().equals(item.getCoin())
&& dbItem.getUser().equals(item.getUser())
&& dbItem.getMaxHeight().equals(item.getMaxHeight())
&& dbItem.getDate().toLocalDate().atStartOfDay().equals(item.getDate().toLocalDate().atStartOfDay()))
&& dbItem.getDateIn().toLocalDate().atStartOfDay().equals(item.getDateIn().toLocalDate().atStartOfDay()))
.findFirst()
.ifPresent(dbItem -> {
// 若找到匹配项,设置 id 并添加到 updateList
@@ -136,15 +137,16 @@ public class ManageTask {
}
}
if (!updateList.isEmpty()){
boolean update = manageWalletOutInService.updateBatchById(updateList);
System.out.println("walletOutIn 修改"+update);
System.out.println("walletOutIn 修改"+updateList.size());
}
if (!saveList.isEmpty()){
boolean save = manageWalletOutInService.saveBatch(saveList);
System.out.println("walletOutIn 新增"+save);
System.out.println("walletOutIn 新增"+saveList.size());
}
}else{
boolean b = manageWalletOutInService.saveBatch(collect);
boolean b = manageWalletOutInService.saveOrUpdateBatch(walletInfo);
System.out.println("初始化walletOutIn数据"+b);
}
}

View File

@@ -35,8 +35,8 @@
coin,
`user`,
address,
`date`,
COALESCE(DATE(`should_out_date`),DATE(`date`)) as shouldOutDate,
`date_in` as `date`,
COALESCE(DATE(`should_out_date`),DATE(`date_in`),DATE(`date_out`)) as shouldOutDate,
max_height,
allocation_amount as allocationAmount,
transfer_amount as transferAmount
@@ -46,10 +46,10 @@
coin = #{coin} AND `user` = #{user}
<choose>
<when test="startDate != null and endDate != null">
and DATE(`date`) >= #{startDate} and DATE(`date`) <![CDATA[ <= ]]> #{endDate}
and DATE(`date_in`) >= #{startDate} and DATE(`date_in`) <![CDATA[ <= ]]> #{endDate}
</when>
<otherwise>
and `date` >= DATE_SUB(DATE(NOW()), INTERVAL 1 MONTH)
and `date_in` >= DATE_SUB(DATE(NOW()), INTERVAL 1 MONTH)
</otherwise>
</choose>
</where>

View File

@@ -7,23 +7,18 @@
<select id="getWalletIn" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
SELECT
wi.coin,
wi.`user`,
COALESCE(wi.`should_out_date`, wi.`create_date`) as `date`,
wi.amount AS allocationAmount,
wi.should_out_date AS `shouldOutDate`,
wi.max_height AS maxHeight
coin,
`user`,
create_date as dateIn,
amount AS allocationAmount,
COALESCE(should_out_date,create_date) AS `shouldOutDate`,
max_height AS maxHeight
FROM
wallet_in wi
wallet_in
<where>
<choose>
<when test="startDate != null">
wi.`create_date` >= DATE(#{startDate})
</when>
<otherwise>
wi.`create_date` <![CDATA[ <= ]]> NOW()
</otherwise>
</choose>
<if test="startDate != null">
`create_date` >= DATE(#{startDate})
</if>
</where>
</select>
<select id="getWalletOut" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
@@ -31,16 +26,16 @@
wo.coin,
wo.`user`,
wo.address,
wo.`date`,
wo.`date` as dateIn,
wo.`date` as dateOut,
wo.max_height AS maxHeight,
wo.tx_id AS txId,
wo.amount AS transferAmount
FROM
wallet_outv2 wo
<where>
AND wo.`date` <![CDATA[ <= ]]> NOW()
<if test="startDate != null">
AND wo.`date` > #{startDate}
wo.`date` >= #{startDate}
</if>
</where>
</select>
@@ -48,6 +43,6 @@
select coin, max(max_height) as maxHeight, max(should_out_date) AS shouldOutDate, `user`, sum(amount) as needPayAmount from wallet_in where state = 2 group by coin,`user`
</select>
<select id="getMaxDateData" resultType="java.time.LocalDateTime">
select `date` from manage_wallet_out_in order by `date` desc limit 1
select DATE(`date_in`) from manage_wallet_out_in order by `date_in` desc limit 1
</select>
</mapper>

View File

@@ -18,8 +18,8 @@ public enum PoolUnits {
DGB_ODO_B20("dgb_odo_b20", "MH/s", 1000, 1000),
NEXA("nexa", "MH/s", 1000*1000, 1000),
RXD("rxd", "MH/s", 1000*1000, 1000),
ALPH("aplh", "MH/s", 1000*1000, 1000),
ENX("enx", "MH/s", 1000*1000, 1000);
ALPH("aplh", "MH/s", 1000*1000, 1000);
//ENX("enx", "MH/s", 1000*1000, 1000);
/** 币种参数名 */
private final String coin;

View File

@@ -146,7 +146,11 @@ public class AccountServiceImpl implements AccountService {
@Override
public AjaxResult getMinersList(AccountVo vo) {
PoolUnits unit = (PoolUnits) EnumUtils.get(PoolUnits.class, vo.getCoin());
if(StringUtils.isNull(unit)){
//防止coin注入异常数据
return AjaxResult.error("coin error");
}
List<MinerState> list = accountMapperMapper.getMinerListByCoinAndAccount(vo);
List<MinerStateDto> minerList = list.stream().map(e -> {
MinerStateDto dto = new MinerStateDto();
@@ -169,7 +173,13 @@ public class AccountServiceImpl implements AccountService {
@Override
public AjaxResult getWatch(AccountVo vo) {
PoolUnits unit = (PoolUnits) EnumUtils.get(PoolUnits.class, vo.getCoin());
if(StringUtils.isNull(unit)){
//防止coin注入异常数据
return AjaxResult.error("coin error");
}
MinerWatchDto dto = new MinerWatchDto();
List<MinerState> list = accountMapperMapper.getMinerListByCoinAndAccount(vo);
Map<String, Long> map = list.stream().collect(Collectors.groupingBy(
MinerState::getState,

View File

@@ -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>

View File

@@ -33,4 +33,7 @@ public class BlockInfo implements Serializable {
/** 报块实际收益 */
private BigDecimal profit;
/** 币价(目前只有xtm在使用) */
private BigDecimal price;
}

View File

@@ -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);
/** 币种参数名 */

View File

@@ -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));

View File

@@ -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;

View File

@@ -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;
/** 矿池数据单位 */

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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());
}
}

View File

@@ -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) {

View File

@@ -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);
}
}
}
}
}

View File

@@ -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{
//最新数据未入库暂不做处理
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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>