From 4e9d55aab6b41c7bc2f7b457c2af6ef4c48964b1 Mon Sep 17 00:00:00 2001 From: yyb <1416014977@qq.com> Date: Thu, 9 Oct 2025 14:19:38 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=96=B0=E5=A2=9E=E7=AE=97=E6=B3=95sh?= =?UTF-8?q?a3x=20xtm=E5=B8=81=E7=A7=8D=EF=BC=8C=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=E4=BC=98=E5=8C=96=E9=92=B1=E5=8C=85?= =?UTF-8?q?=E5=87=BA=E5=85=A5=E8=B4=A6=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/ManageWalletOutInMapper.java | 7 +- .../com/m2pool/manage/task/ManageTask.java | 140 +++++++++--------- .../mapper/manage/ManageWalletOutInMapper.xml | 27 ++-- .../java/com/m2pool/pool/task/NodeTask.java | 2 +- .../main/resources/mapper/pool/PoolMapper.xml | 8 +- 5 files changed, 90 insertions(+), 94 deletions(-) diff --git a/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/mapper/ManageWalletOutInMapper.java b/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/mapper/ManageWalletOutInMapper.java index 4305fcf..90c9c11 100644 --- a/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/mapper/ManageWalletOutInMapper.java +++ b/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/mapper/ManageWalletOutInMapper.java @@ -37,7 +37,6 @@ public interface ManageWalletOutInMapper extends BaseMapper { /** * 获取用户待支付汇总 - * @param coin * @return */ @DistributionDB @@ -45,10 +44,8 @@ public interface ManageWalletOutInMapper extends BaseMapper { /** - * 获取最大日期 - * @param coin + * 获取最大date_out * @return */ - LocalDateTime getMaxDateData(); - + LocalDateTime getMaxDateIn(); } diff --git a/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/task/ManageTask.java b/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/task/ManageTask.java index 621dc6e..6c40868 100644 --- a/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/task/ManageTask.java +++ b/m2pool-modules/m2pool-manage/src/main/java/com/m2pool/manage/task/ManageTask.java @@ -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 manageWalletOutIns = new ArrayList<>(); if (maxDateData != null){ //获取startDate 后的数据,用于比对 manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper() - .ge(ManageWalletOutIn::getDateIn, maxDateData)); + .ge(ManageWalletOutIn::getShouldOutDate, maxDateData.toLocalDate().atStartOfDay()) + + ); } List walletIn = manageWalletOutInMapper.getWalletIn(maxDateData); List walletOut = manageWalletOutInMapper.getWalletOut(maxDateData); - //date_in 是in表实际入账时间;in表带有预计转账时间should_out_date - Map> walletInMap = walletIn.stream() - .collect(Collectors.groupingBy(item -> - item.getUser() + item.getCoin() + item.getShouldOutDate().toLocalDate().atStartOfDay() - )); - //date_out 是out表实际转账时间 - Map> walletOutMap = walletOut.stream() - .collect(Collectors.groupingBy(item -> - item.getUser() + item.getCoin() + item.getDateOut().toLocalDate().atStartOfDay() - )); + + // 存储walletIn 和 walletOut交集 + List intersection = new ArrayList<>(); + // 存储 walletIn 的差集 + List inDifference = new ArrayList<>(walletIn); + // 存储 walletOut 的差集 + List outDifference = new ArrayList<>(walletOut); + // 用于标记 walletIn 中哪些元素在 walletOut 中找到了匹配 + Set 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 walletInfo = new ArrayList<>(); - // 比较 out 和 in 表的 date_out 和 date_in 以及 max_height 字段,如果都相同,则组合成一条数据 - for (Map.Entry> outEntry : walletOutMap.entrySet()) { - String outKey = outEntry.getKey(); - List outList = outEntry.getValue(); - // inList 中包含 outMap 的 key,则说明有相同的数据;这个时候比对 max_height - if (walletInMap.containsKey(outKey)) { - List inList = walletInMap.get(outKey); - List 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 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> 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 updateList = new ArrayList<>(); List 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); } } diff --git a/m2pool-modules/m2pool-manage/src/main/resources/mapper/manage/ManageWalletOutInMapper.xml b/m2pool-modules/m2pool-manage/src/main/resources/mapper/manage/ManageWalletOutInMapper.xml index adf4b99..577ee94 100644 --- a/m2pool-modules/m2pool-manage/src/main/resources/mapper/manage/ManageWalletOutInMapper.xml +++ b/m2pool-modules/m2pool-manage/src/main/resources/mapper/manage/ManageWalletOutInMapper.xml @@ -17,32 +17,33 @@ wallet_in - `create_date` >= DATE(#{startDate}) + `should_out_date` >= DATE(#{startDate}) - + select `date_out` from manage_wallet_out_in order by `date_out` desc limit 1 diff --git a/m2pool-modules/m2pool-pool/src/main/java/com/m2pool/pool/task/NodeTask.java b/m2pool-modules/m2pool-pool/src/main/java/com/m2pool/pool/task/NodeTask.java index 3311ccd..0eb43c2 100644 --- a/m2pool-modules/m2pool-pool/src/main/java/com/m2pool/pool/task/NodeTask.java +++ b/m2pool-modules/m2pool-pool/src/main/java/com/m2pool/pool/task/NodeTask.java @@ -855,7 +855,7 @@ public class NodeTask { //TODO @Scheduled(cron = "0 0/1 * * * ?") - public void XtmBlockInfoToRedis(){ + public void Sha3xBlockInfoToRedis(){ if(!enable){ return; } diff --git a/m2pool-modules/m2pool-pool/src/main/resources/mapper/pool/PoolMapper.xml b/m2pool-modules/m2pool-pool/src/main/resources/mapper/pool/PoolMapper.xml index e11457e..172a6a5 100644 --- a/m2pool-modules/m2pool-pool/src/main/resources/mapper/pool/PoolMapper.xml +++ b/m2pool-modules/m2pool-pool/src/main/resources/mapper/pool/PoolMapper.xml @@ -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 @@ -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" - 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}