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

This commit is contained in:
yyb
2025-10-09 14:19:38 +08:00
parent 2efa65222d
commit 4e9d55aab6
5 changed files with 90 additions and 94 deletions

View File

@@ -37,7 +37,6 @@ public interface ManageWalletOutInMapper extends BaseMapper<ManageWalletOutIn> {
/**
* 获取用户待支付汇总
* @param coin
* @return
*/
@DistributionDB
@@ -45,10 +44,8 @@ public interface ManageWalletOutInMapper extends BaseMapper<ManageWalletOutIn> {
/**
* 获取最大日期
* @param coin
* 获取最大date_out
* @return
*/
LocalDateTime getMaxDateData();
LocalDateTime getMaxDateIn();
}

View File

@@ -43,96 +43,94 @@ public class ManageTask {
/**
* 存储交易记录定时任务
*/
//@Scheduled(cron = "22 25 0/1 * * ?")
@Scheduled(cron = "0 0/1 * * * ?")
@Scheduled(cron = "22 25 0/1 * * ?")
//@Scheduled(cron = "0 0/1 * * * ?")
@DSTransactional
public void insertDataToWalletOutInDb(){
LocalDateTime maxDateData = manageWalletOutInMapper.getMaxDateData();
LocalDateTime maxDateData = manageWalletOutInMapper.getMaxDateIn();
List<ManageWalletOutIn> manageWalletOutIns = new ArrayList<>();
if (maxDateData != null){
//获取startDate 后的数据,用于比对
manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper<ManageWalletOutIn>()
.ge(ManageWalletOutIn::getDateIn, maxDateData));
.ge(ManageWalletOutIn::getShouldOutDate, maxDateData.toLocalDate().atStartOfDay())
);
}
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.getShouldOutDate().toLocalDate().atStartOfDay()
));
//date_out 是out表实际转账时间
Map<String, List<ManageWalletOutIn>> walletOutMap = walletOut.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDateOut().toLocalDate().atStartOfDay()
));
// 存储walletIn 和 walletOut交集
List<ManageWalletOutIn> intersection = new ArrayList<>();
// 存储 walletIn 的差集
List<ManageWalletOutIn> inDifference = new ArrayList<>(walletIn);
// 存储 walletOut 的差集
List<ManageWalletOutIn> outDifference = new ArrayList<>(walletOut);
// 用于标记 walletIn 中哪些元素在 walletOut 中找到了匹配
Set<ManageWalletOutIn> matchedInItems = new HashSet<>();
for (ManageWalletOutIn in : walletIn) {
for (ManageWalletOutIn out : walletOut) {
//日期
LocalDateTime dateIn = in.getShouldOutDate().toLocalDate().atStartOfDay();
LocalDateTime dateOut = out.getShouldOutDate().toLocalDate().atStartOfDay();
//挖矿账户
String userIn = in.getUser();
String userOut = out.getUser();
//币种
String coinIn = in.getCoin();
String coinOut = out.getCoin();
//最大高度
Integer maxHeightIn = in.getMaxHeight();
Integer maxHeightOut = out.getMaxHeight();
if (coinIn.equals(coinOut) && userIn.equals(userOut) &&
dateIn.equals(dateOut) && maxHeightIn.equals(maxHeightOut)) {
//找到交集元素后 in 中设置 out的独有的几个数据字段
in.setDateOut(out.getDateOut());
in.setTransferAmount(out.getTransferAmount());
in.setTxId(out.getTxId());
in.setAddress(out.getAddress());
// 找到交集元素
intersection.add(in);
//标记存在交集的in
matchedInItems.add(in);
//移除 walletOut 中已经在交集里的元素,得到差集
outDifference.remove(out);
}
}
}
// 移除 walletIn 中已经在交集里的元素,得到差集
inDifference.removeAll(matchedInItems);
List<ManageWalletOutIn> walletInfo = new ArrayList<>();
// 比较 out 和 in 表的 date_out 和 date_in 以及 max_height 字段,如果都相同,则组合成一条数据
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletOutMap.entrySet()) {
String outKey = outEntry.getKey();
List<ManageWalletOutIn> outList = outEntry.getValue();
// 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(insertOutList);
// inList 中如果没有任何匹配的 outList 数据,则把 inList 数据添加到 walletInfo 中
List<ManageWalletOutIn> insertInList = inList.stream()
.filter(inItem -> outList.stream()
.noneMatch(outItem -> inItem.getMaxHeight().equals(outItem.getMaxHeight())))
.collect(Collectors.toList());
walletInfo.addAll(insertInList);
} else {
// 只有 walletOut没有对应的 walletIn
walletInfo.addAll(outList);
}
}
// 当天只有 walletIn没有 walletOut 的数据
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletInMap.entrySet()) {
String key = outEntry.getKey();
if (!walletOutMap.containsKey(key)) {
walletInfo.addAll(outEntry.getValue());
}
}
walletInfo.addAll(intersection);
walletInfo.addAll(inDifference);
walletInfo.addAll(outDifference);
System.out.println("交集数量: " + intersection.size());
System.out.println("walletIn 差集数量: " + inDifference.size());
System.out.println("walletOut 差集数量: " + outDifference.size());
//查询ManageWalletOutIn 数据,比对是否修改
if (!manageWalletOutIns.isEmpty()){
List<ManageWalletOutIn> updateList = new ArrayList<>();
List<ManageWalletOutIn> saveList = new ArrayList<>();
for (ManageWalletOutIn item : walletInfo) {
manageWalletOutIns.stream()
.filter(dbItem -> dbItem.getCoin().equals(item.getCoin())
&& dbItem.getUser().equals(item.getUser())
&& dbItem.getMaxHeight().equals(item.getMaxHeight())
&& dbItem.getDateIn().toLocalDate().atStartOfDay().equals(item.getDateIn().toLocalDate().atStartOfDay()))
.findFirst()
.ifPresent(dbItem -> {
// 若找到匹配项,设置 id 并添加到 updateList
item.setId(dbItem.getId());
updateList.add(item);
});
for (ManageWalletOutIn dbItem : manageWalletOutIns) {
if (dbItem.getCoin().equals(item.getCoin())
&& dbItem.getUser().equals(item.getUser())
&& dbItem.getMaxHeight().equals(item.getMaxHeight())
&& dbItem.getShouldOutDate().toLocalDate().atStartOfDay().equals(item.getShouldOutDate().toLocalDate().atStartOfDay())) {
// 若找到匹配项,设置 id 并添加到 updateList
item.setId(dbItem.getId());
updateList.add(item);
break;
}
}
if (item.getId() == null){
if (item.getId() == null) {
saveList.add(item);
}
}

View File

@@ -17,32 +17,33 @@
wallet_in
<where>
<if test="startDate != null">
`create_date` >= DATE(#{startDate})
`should_out_date` >= DATE(#{startDate})
</if>
</where>
</select>
<select id="getWalletOut" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
SELECT
wo.coin,
wo.`user`,
wo.address,
wo.`date` as dateIn,
wo.`date` as dateOut,
wo.max_height AS maxHeight,
wo.tx_id AS txId,
wo.amount AS transferAmount
coin,
`user`,
address,
DATE(`date`) as dateIn,
DATE(`date`) as shouldOutDate,
`date` as dateOut,
max_height AS maxHeight,
tx_id AS txId,
amount AS transferAmount
FROM
wallet_outv2 wo
wallet_outv2
<where>
<if test="startDate != null">
wo.`date` >= #{startDate}
`date` > #{startDate}
</if>
</where>
</select>
<select id="summaryOfPendingPayments" resultType="com.m2pool.manage.dto.SummaryOfPendingPaymentsDto">
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(`date_in`) from manage_wallet_out_in order by `date_in` desc limit 1
<select id="getMaxDateIn" resultType="java.time.LocalDateTime">
select `date_out` from manage_wallet_out_in order by `date_out` desc limit 1
</select>
</mapper>

View File

@@ -855,7 +855,7 @@ public class NodeTask {
//TODO
@Scheduled(cron = "0 0/1 * * * ?")
public void XtmBlockInfoToRedis(){
public void Sha3xBlockInfoToRedis(){
if(!enable){
return;
}

View File

@@ -592,7 +592,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
reward,
fees
from
xtm_pool_blkstats
sha3x_pool_blkstats
order by `date` desc
</select>
@@ -646,7 +646,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
reward,
fees
from
tari_blkreportprofitv2
sha3x_blkreportprofitv2
where
`date` > #{date}
order by `date`
@@ -1015,11 +1015,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</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 height,difficulty,power,reward,fees,profit from sha3x_block_info order by id desc limit 1;
</select>
<insert id="insertXtmBlockInfo">
insert into xtm_block_info (height,difficulty,power,reward,fees,profit,price)
insert into sha3x_block_info (height,difficulty,power,reward,fees,profit,price)
values(#{blockInfo.height}
,#{blockInfo.difficulty}
,#{blockInfo.power}