From c360be33d74b6cc7e396663e4d9073aa9961d464 Mon Sep 17 00:00:00 2001 From: yyb <1416014977@qq.com> Date: Mon, 2 Feb 2026 15:47:53 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=96=B0=E5=A2=9E=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=89=8B=E7=BB=AD=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lease/entity/LeaseSystemWallet.java | 76 +++++++++++ .../entity/LeaseSystemWalletTransaction.java | 121 ++++++++++++++++++ .../lease/mapper/LeaseSystemWalletMapper.java | 39 ++++++ .../LeaseSystemWalletTransactionMapper.java | 27 ++++ .../impl/LeaseOrderInfoServiceImpl.java | 14 +- .../hashrate/HashrateFetchStrategy.java | 3 +- .../m2pool/lease/task/OrderAndPayTask.java | 94 +++++++++++++- .../mapper/lease/LeaseSystemWalletMapper.xml | 35 +++++ .../LeaseSystemWalletTransactionMapper.xml | 40 ++++++ 9 files changed, 440 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/m2pool/lease/entity/LeaseSystemWallet.java create mode 100644 src/main/java/com/m2pool/lease/entity/LeaseSystemWalletTransaction.java create mode 100644 src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletMapper.java create mode 100644 src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletTransactionMapper.java create mode 100644 src/main/resources/mapper/lease/LeaseSystemWalletMapper.xml create mode 100644 src/main/resources/mapper/lease/LeaseSystemWalletTransactionMapper.xml diff --git a/src/main/java/com/m2pool/lease/entity/LeaseSystemWallet.java b/src/main/java/com/m2pool/lease/entity/LeaseSystemWallet.java new file mode 100644 index 0000000..84c836b --- /dev/null +++ b/src/main/java/com/m2pool/lease/entity/LeaseSystemWallet.java @@ -0,0 +1,76 @@ +package com.m2pool.lease.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + *

+ * 系统钱包表 + *

+ * + * @author yyb + * @since 2026-02-02 + */ +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +@TableName("lease_system_wallet") +public class LeaseSystemWallet implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 卖家地址 + */ + private String address; + + /** + * 币种名称 + */ + private String symbol; + + /** + * 余额 + */ + private BigDecimal balance; + + /** + * 冻结余额 + */ + private BigDecimal blcokBalance; + + /** + * 链名称 + */ + private String chain; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; + + /** + * 逻辑删除字段 + */ + private Boolean del; +} diff --git a/src/main/java/com/m2pool/lease/entity/LeaseSystemWalletTransaction.java b/src/main/java/com/m2pool/lease/entity/LeaseSystemWalletTransaction.java new file mode 100644 index 0000000..29f6082 --- /dev/null +++ b/src/main/java/com/m2pool/lease/entity/LeaseSystemWalletTransaction.java @@ -0,0 +1,121 @@ +package com.m2pool.lease.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + *

+ * 系统钱包交易信息表(提现+卖家的手续费收款记录) + *

+ * + * @author yyb + * @since 2026-02-02 + */ +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +@TableName("lease_system_wallet_transaction") +public class LeaseSystemWalletTransaction implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 消息ID + */ + private String queueId; + + /** + * 卖家地址 + */ + private String sellerAddress; + + /** + * 买家地址 + */ + private String buyerAddress; + + /** + * 系统地址(手续费入账地址) + */ + private String systemAddress; + + /** + * 订单号 + */ + private String orderId; + + /** + * 卖方--商铺ID + */ + private Long shopId; + + /** + * 买方--邮箱 + */ + private String userId; + + /** + * 卖方--手续费率 + */ + private BigDecimal feeRate; + + /** + * 卖方--收款金额(未扣手续费) + */ + private BigDecimal amount; + + /** + * 卖方--实收金额(已扣手续费) + */ + private BigDecimal receivedAmount; + + /** + * 卖方--手续费 + */ + private BigDecimal fee; + + /** + * 币种名称 + */ + private String symbol; + + /** + * 链名称 + */ + private String chain; + + /** + * 交易id + */ + private String txHash; + + /** + * 支付时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; + + /** + * 逻辑删除字段 + */ + private Boolean del; +} diff --git a/src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletMapper.java b/src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletMapper.java new file mode 100644 index 0000000..58216d0 --- /dev/null +++ b/src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletMapper.java @@ -0,0 +1,39 @@ +package com.m2pool.lease.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.m2pool.lease.entity.LeaseSystemWallet; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; +import java.util.List; + +/** + *

+ * 系统钱包 Mapper 接口 + *

+ * + * @author yyb + * @since 2026-02-02 + */ +@Mapper +public interface LeaseSystemWalletMapper extends BaseMapper { + + /** + * 根据地址、币种和链查询系统钱包 + * @param address 地址 + * @param symbol 币种 + * @param chain 链 + * @return 系统钱包 + */ + LeaseSystemWallet selectByAddressAndSymbolAndChain(@Param("address") String address, + @Param("symbol") String symbol, + @Param("chain") String chain); + + /** + * 批量更新系统钱包余额 + * @param list 系统钱包更新列表 + * @return 更新数量 + */ + int updateBalanceById(@Param("list") List list); +} \ No newline at end of file diff --git a/src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletTransactionMapper.java b/src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletTransactionMapper.java new file mode 100644 index 0000000..3dd7dc2 --- /dev/null +++ b/src/main/java/com/m2pool/lease/mapper/LeaseSystemWalletTransactionMapper.java @@ -0,0 +1,27 @@ +package com.m2pool.lease.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.m2pool.lease.entity.LeaseSystemWalletTransaction; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

+ * 系统钱包交易信息表 Mapper 接口 + *

+ * + * @author yyb + * @since 2026-02-02 + */ +@Mapper +public interface LeaseSystemWalletTransactionMapper extends BaseMapper { + + /** + * 批量插入系统手续费交易记录 + * @param list 交易记录列表 + * @return 插入数量 + */ + int insertBatch(@Param("list") List list); +} \ No newline at end of file diff --git a/src/main/java/com/m2pool/lease/service/impl/LeaseOrderInfoServiceImpl.java b/src/main/java/com/m2pool/lease/service/impl/LeaseOrderInfoServiceImpl.java index 103f3c2..ccfc651 100644 --- a/src/main/java/com/m2pool/lease/service/impl/LeaseOrderInfoServiceImpl.java +++ b/src/main/java/com/m2pool/lease/service/impl/LeaseOrderInfoServiceImpl.java @@ -765,9 +765,9 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl>> chainAndCoinMap = new HashMap<>(); Map orderTotalPriceGroupByChainAndCoin = leaseMachinePriceMapper.getOrderTotalPriceGroupByChainAndCoin(orderInfoVoList); @@ -960,9 +960,9 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl 0 || sellerUpdate > 0){ for (LeasePayRecordMessage item : reocrdList) { @@ -992,6 +997,93 @@ public class OrderAndPayTask { return sellerWallets; } + /** + * 处理系统手续费交易记录和系统钱包余额更新 + * @param recordList 支付记录列表 + */ + private void handleSystemFeeTransaction(List recordList) { + if (recordList == null || recordList.isEmpty()) { + return; + } + + // 获取系统钱包列表 + List systemWalletList = leaseSystemWalletMapper.selectList(new LambdaQueryWrapper() + .eq(LeaseSystemWallet::getDel, false)); + if (systemWalletList.isEmpty()) { + return; + } + + // 构建系统钱包Map:key = symbol_chain + Map systemWalletMap = systemWalletList.stream() + .collect(Collectors.toMap( + wallet -> wallet.getSymbol() + "_" + wallet.getChain(), + Function.identity() + )); + + // 1. 为每个订单创建系统手续费交易记录 + List systemTransactions = new ArrayList<>(); + Map walletIdToUpdateMap = new HashMap<>(); + + for (LeasePayRecordMessage record : recordList) { + // 计算手续费:实收金额 - 手续费 = 卖家实收金额 + // 卖家收款金额(未扣手续费)= record.getRealAmount() + // 卖家实收金额(已扣手续费)= record.getReceivedAmount() + // 手续费 = record.getRealAmount() - record.getReceivedAmount() + BigDecimal fee = record.getRealAmount().subtract(record.getReceivedAmount()); + + if (fee.compareTo(BigDecimal.ZERO) > 0) { + // 查找对应的系统钱包 + String walletKey = record.getFromSymbol() + "_" + record.getFromChain(); + LeaseSystemWallet systemWallet = systemWalletMap.get(walletKey); + + if (systemWallet != null) { + // 构建系统手续费交易记录 + LeaseSystemWalletTransaction transaction = LeaseSystemWalletTransaction.builder() + .queueId(record.getQueueId()) + .sellerAddress(record.getToAddress()) + .buyerAddress(record.getFromAddress()) + .systemAddress(systemWallet.getAddress()) + .orderId(record.getOrderId()) + .shopId(record.getShopId()) + .userId(record.getUserId()) + .feeRate(record.getFeeRate()) + .amount(record.getRealAmount()) + .receivedAmount(record.getReceivedAmount()) + .fee(fee) + .symbol(record.getFromSymbol()) + .chain(record.getFromChain()) + .txHash(record.getTxHash()) + .build(); + systemTransactions.add(transaction); + + // 累计需要更新的系统钱包余额 + walletIdToUpdateMap.compute(systemWallet.getId(), (id, wallet) -> { + if (wallet == null) { + return LeaseSystemWallet.builder() + .id(systemWallet.getId()) + .balance(fee) + .build(); + } else { + wallet.setBalance(wallet.getBalance().add(fee)); + return wallet; + } + }); + } + } + } + + // 2. 批量插入系统手续费交易记录 + if (!systemTransactions.isEmpty()) { + leaseSystemWalletTransactionMapper.insertBatch(systemTransactions); + } + + // 3. 批量更新系统钱包余额 + if (!walletIdToUpdateMap.isEmpty()) { + List systemWalletsToUpdate = new ArrayList<>(walletIdToUpdateMap.values()); + leaseSystemWalletMapper.updateBalanceById(systemWalletsToUpdate); + } + } + /** * 记录日志 * @param item diff --git a/src/main/resources/mapper/lease/LeaseSystemWalletMapper.xml b/src/main/resources/mapper/lease/LeaseSystemWalletMapper.xml new file mode 100644 index 0000000..4635c37 --- /dev/null +++ b/src/main/resources/mapper/lease/LeaseSystemWalletMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + UPDATE lease_system_wallet + SET balance = balance + #{item.balance} + WHERE id = #{item.id} + AND del = 0 + + + + diff --git a/src/main/resources/mapper/lease/LeaseSystemWalletTransactionMapper.xml b/src/main/resources/mapper/lease/LeaseSystemWalletTransactionMapper.xml new file mode 100644 index 0000000..cf674a2 --- /dev/null +++ b/src/main/resources/mapper/lease/LeaseSystemWalletTransactionMapper.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO lease_system_wallet_transaction ( + queue_id, seller_address, buyer_address, system_address, order_id, shop_id, user_id, + fee_rate, amount, received_amount, fee, symbol, chain + ) VALUES + + ( + #{item.queueId}, #{item.sellerAddress}, #{item.buyerAddress}, #{item.systemAddress}, + #{item.orderId}, #{item.shopId}, #{item.userId}, #{item.feeRate}, #{item.amount}, + #{item.receivedAmount}, #{item.fee}, #{item.symbol}, #{item.chain} + ) + + + +