update 租赁系统业务完成(待测试)
This commit is contained in:
@@ -3,6 +3,7 @@ package com.m2pool.lease.constant;
|
||||
import com.m2pool.lease.dto.ChargeDto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,22 +14,24 @@ import java.util.List;
|
||||
*/
|
||||
public enum CoinCharge {
|
||||
|
||||
ETH_USDT("ETH","USDT", BigDecimal.valueOf(1)),
|
||||
ETH_ETH("ETH","USDT", BigDecimal.valueOf(0.0001)),
|
||||
TRON_USDT("TRON","USDT", BigDecimal.valueOf(1)),
|
||||
TRON_NEXA("TRON","NEXA", BigDecimal.valueOf(1000));
|
||||
ETH_USDT("ETH","USDT", BigDecimal.valueOf(1), BigDecimal.valueOf(1)),
|
||||
ETH_ETH("ETH","ETH", BigDecimal.valueOf(0.00005),BigDecimal.valueOf(0.01)),
|
||||
TRON_USDT("TRON","USDT", BigDecimal.valueOf(1),BigDecimal.valueOf(1)),
|
||||
TRON_NEXA("TRON","NEXA", BigDecimal.valueOf(1000),BigDecimal.valueOf(0.1));
|
||||
|
||||
private final String chain;
|
||||
/** 币种参数名 */
|
||||
private final String coin;
|
||||
/** 手续费 */
|
||||
private final BigDecimal amount;
|
||||
/** 费率 */
|
||||
private final BigDecimal feeRate;
|
||||
|
||||
|
||||
CoinCharge(String chain, String coin, BigDecimal amount) {
|
||||
CoinCharge(String chain, String coin, BigDecimal amount, BigDecimal feeRate) {
|
||||
this.chain = chain;
|
||||
this.coin = coin;
|
||||
this.amount = amount;
|
||||
this.feeRate = feeRate;
|
||||
}
|
||||
/**
|
||||
* 根据 chain 和 coin 查找对应的手续费,未找到则返回 1
|
||||
@@ -45,6 +48,28 @@ public enum CoinCharge {
|
||||
return BigDecimal.ONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 chain 和 coin 找到手续费和费率,然后比较totalPrice是否小于 费率/手续费
|
||||
* @param chain 链名
|
||||
* @param coin 币种名
|
||||
* @return 对应的手续费,未找到返回 1
|
||||
*/
|
||||
public static BigDecimal getFee(String chain, String coin, BigDecimal totalPrice) {
|
||||
BigDecimal fee = BigDecimal.ONE;
|
||||
for (CoinCharge charge : CoinCharge.values()) {
|
||||
if (charge.chain.equals(chain) && charge.coin.equals(coin)) {
|
||||
BigDecimal feeRate = charge.feeRate;
|
||||
BigDecimal deductible= feeRate.divide(charge.amount, 4, RoundingMode.HALF_UP);
|
||||
if(deductible.compareTo(totalPrice) < 0){
|
||||
fee = BigDecimal.ZERO;
|
||||
}else{
|
||||
fee = charge.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fee;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取枚举类中所有枚举,并封装成 List<ChargeDto>
|
||||
@@ -56,7 +81,8 @@ public enum CoinCharge {
|
||||
chargeDtoList.add(new ChargeDto(
|
||||
charge.amount,
|
||||
charge.chain,
|
||||
charge.coin
|
||||
charge.coin,
|
||||
charge.feeRate
|
||||
));
|
||||
}
|
||||
return chargeDtoList;
|
||||
|
||||
@@ -33,5 +33,7 @@ public class ChargeDto {
|
||||
@ApiModelProperty(value = "币种",required = true)
|
||||
private String coin;
|
||||
|
||||
@ApiModelProperty(value = "手续费率",required = true)
|
||||
private BigDecimal feeRate;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 店铺商品配置返回对象
|
||||
@@ -43,4 +45,7 @@ public class PayConfigDto {
|
||||
|
||||
|
||||
private Long shopId;
|
||||
|
||||
@ApiModelProperty(value = "起付金额")
|
||||
private BigDecimal deductibleAmount;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,10 @@ public class LeaseOrderInfo implements Serializable {
|
||||
*/
|
||||
private BigDecimal fee;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String chainAndCoinAndShopIdKey;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String chainAndCoinKey;
|
||||
|
||||
|
||||
@@ -38,4 +38,6 @@ public class LeaseProductMachinePrice implements Serializable {
|
||||
private String coin;
|
||||
|
||||
private String chain;
|
||||
|
||||
private Boolean del;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,14 @@ public interface LeaseProductMachineMapper extends BaseMapper<LeaseProductMachin
|
||||
List<Long> getIdsForProductId(@Param("productId")Long productId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取店铺对应的机器ID集合
|
||||
*
|
||||
* @param productId 商品ID
|
||||
* @return 机器ID集合
|
||||
*/
|
||||
List<Long> getIdsForShopId(@Param("shopId")Long shopId);
|
||||
|
||||
/**
|
||||
* 根据价格范围,功耗范围,算力范围 获取商品对应的机器
|
||||
*
|
||||
|
||||
@@ -93,70 +93,54 @@ public class MessageReceiver {
|
||||
public void listenerPayBalanceStatusQueueMessage(@Payload RabbitmqPayAutoReturnMessage payAutoReturnMessage) {
|
||||
System.out.println("支付消费者"+JSONUtil.toJsonPrettyStr(payAutoReturnMessage));
|
||||
//查找到数据库对应的支付记录
|
||||
List<LeasePayRecordMessage> leasePayRecordMessages = leasePayRecordMessageMapper.selectList(new LambdaQueryWrapper<LeasePayRecordMessage>()
|
||||
List<LeasePayRecordMessage> leasePayRecordMessagesList = leasePayRecordMessageMapper.selectList(new LambdaQueryWrapper<LeasePayRecordMessage>()
|
||||
.eq(LeasePayRecordMessage::getQueueId, payAutoReturnMessage.getQueue_id()));
|
||||
Map<String, List<LeasePayRecordMessage>> recordMap = leasePayRecordMessages.stream()
|
||||
.collect(Collectors.groupingBy(item -> item.getToAddress() + "-" + item.getToChain()));
|
||||
//买家钱包
|
||||
Map<String,RabbitmqPayAutoReturnInfoMessage> transactions = payAutoReturnMessage.getTransactions();
|
||||
LeasePayRecordMessage leasePayRecordMessage1 = leasePayRecordMessages.get(0);
|
||||
LeasePayRecordMessage payRecordMessage = leasePayRecordMessagesList.get(0);
|
||||
LeaseUserWalletData buyer = leaseUserWalletDataMapper.selectOne(new LambdaQueryWrapper<LeaseUserWalletData>()
|
||||
.eq(LeaseUserWalletData::getFromAddress,leasePayRecordMessage1.getFromAddress())
|
||||
.eq(LeaseUserWalletData::getFromChain, leasePayRecordMessage1.getFromChain())
|
||||
.eq(LeaseUserWalletData::getFromSymbol, leasePayRecordMessage1.getFromSymbol())
|
||||
.eq(LeaseUserWalletData::getFromAddress,payRecordMessage.getFromAddress())
|
||||
.eq(LeaseUserWalletData::getFromChain, payRecordMessage.getFromChain())
|
||||
.eq(LeaseUserWalletData::getFromSymbol, payRecordMessage.getFromSymbol())
|
||||
.eq(LeaseUserWalletData::getDel, false)
|
||||
);
|
||||
//获取初始余额和冻结余额
|
||||
BigDecimal initBalance = buyer.getBalance();
|
||||
BigDecimal initBlockBalance = buyer.getBlockedBalance();
|
||||
BigDecimal balance = buyer.getBalance().subtract(payAutoReturnMessage.getAmount());
|
||||
|
||||
//支付成功修改order_item表实际支付金额
|
||||
transactions.forEach((key,transaction) -> {
|
||||
String key1 = transaction.getTo_address() + "-" + payAutoReturnMessage.getChain();
|
||||
List<LeasePayRecordMessage> leasePayRecordMessageList = recordMap.get(key1);
|
||||
if (leasePayRecordMessageList != null){
|
||||
for (LeasePayRecordMessage leasePayRecordMessage : leasePayRecordMessageList) {
|
||||
BigDecimal balance = buyer.getBalance().subtract(transaction.getAmount());
|
||||
BigDecimal blockBalance = buyer.getBlockedBalance().subtract(leasePayRecordMessage.getBlockAmount())
|
||||
.subtract(leasePayRecordMessage.getNeedAmount());
|
||||
|
||||
leasePayRecordMessage.setUpdateTime(LocalDateTime.now());
|
||||
leasePayRecordMessage.setBlockHeight(transaction.getBlock_height());
|
||||
leasePayRecordMessage.setRealAmount(transaction.getAmount());
|
||||
//当天已存在支付的信息
|
||||
leasePayRecordMessage.setStatus(transaction.getStatus());
|
||||
leasePayRecordMessage.setTxHash(transaction.getTx_hash());
|
||||
List<LeaseOrderItem> needUpdateOrderItem = leaseOrderItemMapper.getNeedUpdateOrderItem(Long.valueOf(leasePayRecordMessage.getOrderId()));
|
||||
if(transaction.getStatus() == 1){
|
||||
//支付成功 买家 钱包总余额 + 冻结余额 减少 卖家 钱包总余额增加
|
||||
buyer.setBalance(balance);
|
||||
buyer.setBlockedBalance(blockBalance);
|
||||
needUpdateOrderItem = needUpdateOrderItem.stream().peek(item ->{
|
||||
item.setAlreadyPayRealAmount(item.getAlreadyPayRealAmount().add(item.getSettlePayRealAmount()));
|
||||
item.setSettlePayRealAmount(BigDecimal.ZERO);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
if (transaction.getStatus() == 0){
|
||||
buyer.setBlockedBalance(blockBalance);
|
||||
needUpdateOrderItem = needUpdateOrderItem.stream().peek(item ->{
|
||||
item.setSettlePayRealAmount(BigDecimal.ZERO);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
//修改支付记录状态
|
||||
System.out.println("支付成功1"+JSONUtil.toJsonPrettyStr(leasePayRecordMessage));
|
||||
int i = leasePayRecordMessageMapper.updateById(leasePayRecordMessage);
|
||||
//支付成功修改order_item表实际支付金额
|
||||
System.out.println("支付成功2"+JSONUtil.toJsonPrettyStr(needUpdateOrderItem));
|
||||
boolean b = leaseOrderItemService.updateBatchById(needUpdateOrderItem);
|
||||
|
||||
System.out.println("支付成功修改order_item表实际支付金额"+ b +"----"+ i);
|
||||
if (i < 1 || !b){
|
||||
throw new PayRechargeException("支付失败,该支付记录已修改,消息重试!!!");
|
||||
}
|
||||
}
|
||||
|
||||
for (LeasePayRecordMessage leasePayRecordMessage : leasePayRecordMessagesList) {
|
||||
BigDecimal blockBalance = buyer.getBlockedBalance().subtract(leasePayRecordMessage.getBlockAmount());
|
||||
leasePayRecordMessage.setUpdateTime(LocalDateTime.now());
|
||||
leasePayRecordMessage.setBlockHeight(payAutoReturnMessage.getBlock_height());
|
||||
leasePayRecordMessage.setRealAmount(payAutoReturnMessage.getAmount());
|
||||
//当天已存在支付的信息
|
||||
leasePayRecordMessage.setStatus(payAutoReturnMessage.getStatus());
|
||||
leasePayRecordMessage.setTxHash(payAutoReturnMessage.getTx_hash());
|
||||
List<LeaseOrderItem> needUpdateOrderItem = leaseOrderItemMapper.getNeedUpdateOrderItem(Long.valueOf(leasePayRecordMessage.getOrderId()));
|
||||
if(payAutoReturnMessage.getStatus() == 1){
|
||||
//支付成功 买家 钱包总余额 + 冻结余额 减少 卖家 钱包总余额增加
|
||||
buyer.setBalance(balance);
|
||||
buyer.setBlockedBalance(blockBalance);
|
||||
needUpdateOrderItem = needUpdateOrderItem.stream().peek(item ->{
|
||||
item.setAlreadyPayRealAmount(item.getAlreadyPayRealAmount().add(item.getSettlePayRealAmount()));
|
||||
item.setSettlePayRealAmount(BigDecimal.ZERO);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
});
|
||||
if (payAutoReturnMessage.getStatus() == 0){
|
||||
buyer.setBlockedBalance(blockBalance);
|
||||
needUpdateOrderItem = needUpdateOrderItem.stream().peek(item ->{
|
||||
item.setSettlePayRealAmount(BigDecimal.ZERO);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
//修改支付记录状态
|
||||
int i = leasePayRecordMessageMapper.updateById(leasePayRecordMessage);
|
||||
//支付成功修改order_item表实际支付金额
|
||||
boolean b = leaseOrderItemService.updateBatchById(needUpdateOrderItem);
|
||||
if (i < 1 || !b){
|
||||
throw new PayRechargeException("支付失败,该支付记录已修改,消息重试!!!");
|
||||
}
|
||||
}
|
||||
//使用乐观锁防止余额少减少
|
||||
int update = leaseUserWalletDataMapper.update(buyer, new LambdaQueryWrapper<LeaseUserWalletData>()
|
||||
.eq(LeaseUserWalletData::getId, buyer.getId())
|
||||
@@ -168,6 +152,86 @@ public class MessageReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
//@RabbitListener(queues = RabbitmqConstant.PAY_AUTO_RETURN_QUEUE,containerFactory ="rabbitListenerContainerFactory")
|
||||
//@Transactional(rollbackFor = Exception.class)
|
||||
//public void listenerPayBalanceStatusQueueMessage(@Payload RabbitmqPayAutoReturnMessage payAutoReturnMessage) {
|
||||
// System.out.println("支付消费者"+JSONUtil.toJsonPrettyStr(payAutoReturnMessage));
|
||||
// //查找到数据库对应的支付记录
|
||||
// List<LeasePayRecordMessage> leasePayRecordMessages = leasePayRecordMessageMapper.selectList(new LambdaQueryWrapper<LeasePayRecordMessage>()
|
||||
// .eq(LeasePayRecordMessage::getQueueId, payAutoReturnMessage.getQueue_id()));
|
||||
// Map<String, List<LeasePayRecordMessage>> recordMap = leasePayRecordMessages.stream()
|
||||
// .collect(Collectors.groupingBy(item -> item.getToAddress() + "-" + item.getToChain()));
|
||||
// //买家钱包
|
||||
// Map<String,RabbitmqPayAutoReturnInfoMessage> transactions = payAutoReturnMessage.getTransactions();
|
||||
// LeasePayRecordMessage leasePayRecordMessage1 = leasePayRecordMessages.get(0);
|
||||
// LeaseUserWalletData buyer = leaseUserWalletDataMapper.selectOne(new LambdaQueryWrapper<LeaseUserWalletData>()
|
||||
// .eq(LeaseUserWalletData::getFromAddress,leasePayRecordMessage1.getFromAddress())
|
||||
// .eq(LeaseUserWalletData::getFromChain, leasePayRecordMessage1.getFromChain())
|
||||
// .eq(LeaseUserWalletData::getFromSymbol, leasePayRecordMessage1.getFromSymbol())
|
||||
// .eq(LeaseUserWalletData::getDel, false)
|
||||
// );
|
||||
// //获取初始余额和冻结余额
|
||||
// BigDecimal initBalance = buyer.getBalance();
|
||||
// BigDecimal initBlockBalance = buyer.getBlockedBalance();
|
||||
// //支付成功修改order_item表实际支付金额
|
||||
// transactions.forEach((key,transaction) -> {
|
||||
// String key1 = transaction.getTo_address() + "-" + payAutoReturnMessage.getChain();
|
||||
// List<LeasePayRecordMessage> leasePayRecordMessageList = recordMap.get(key1);
|
||||
// if (leasePayRecordMessageList != null){
|
||||
// for (LeasePayRecordMessage leasePayRecordMessage : leasePayRecordMessageList) {
|
||||
// BigDecimal balance = buyer.getBalance().subtract(transaction.getAmount());
|
||||
// BigDecimal blockBalance = buyer.getBlockedBalance().subtract(leasePayRecordMessage.getBlockAmount())
|
||||
// .subtract(leasePayRecordMessage.getNeedAmount());
|
||||
//
|
||||
// leasePayRecordMessage.setUpdateTime(LocalDateTime.now());
|
||||
// leasePayRecordMessage.setBlockHeight(transaction.getBlock_height());
|
||||
// leasePayRecordMessage.setRealAmount(transaction.getAmount());
|
||||
// //当天已存在支付的信息
|
||||
// leasePayRecordMessage.setStatus(transaction.getStatus());
|
||||
// leasePayRecordMessage.setTxHash(transaction.getTx_hash());
|
||||
// List<LeaseOrderItem> needUpdateOrderItem = leaseOrderItemMapper.getNeedUpdateOrderItem(Long.valueOf(leasePayRecordMessage.getOrderId()));
|
||||
// if(transaction.getStatus() == 1){
|
||||
// //支付成功 买家 钱包总余额 + 冻结余额 减少 卖家 钱包总余额增加
|
||||
// buyer.setBalance(balance);
|
||||
// buyer.setBlockedBalance(blockBalance);
|
||||
// needUpdateOrderItem = needUpdateOrderItem.stream().peek(item ->{
|
||||
// item.setAlreadyPayRealAmount(item.getAlreadyPayRealAmount().add(item.getSettlePayRealAmount()));
|
||||
// item.setSettlePayRealAmount(BigDecimal.ZERO);
|
||||
// }).collect(Collectors.toList());
|
||||
// }
|
||||
// if (transaction.getStatus() == 0){
|
||||
// buyer.setBlockedBalance(blockBalance);
|
||||
// needUpdateOrderItem = needUpdateOrderItem.stream().peek(item ->{
|
||||
// item.setSettlePayRealAmount(BigDecimal.ZERO);
|
||||
// }).collect(Collectors.toList());
|
||||
// }
|
||||
// //修改支付记录状态
|
||||
// System.out.println("支付成功1"+JSONUtil.toJsonPrettyStr(leasePayRecordMessage));
|
||||
// int i = leasePayRecordMessageMapper.updateById(leasePayRecordMessage);
|
||||
// //支付成功修改order_item表实际支付金额
|
||||
// System.out.println("支付成功2"+JSONUtil.toJsonPrettyStr(needUpdateOrderItem));
|
||||
// boolean b = leaseOrderItemService.updateBatchById(needUpdateOrderItem);
|
||||
//
|
||||
// System.out.println("支付成功修改order_item表实际支付金额"+ b +"----"+ i);
|
||||
// if (i < 1 || !b){
|
||||
// throw new PayRechargeException("支付失败,该支付记录已修改,消息重试!!!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// //使用乐观锁防止余额少减少
|
||||
// int update = leaseUserWalletDataMapper.update(buyer, new LambdaQueryWrapper<LeaseUserWalletData>()
|
||||
// .eq(LeaseUserWalletData::getId, buyer.getId())
|
||||
// .eq(LeaseUserWalletData::getBalance, initBalance)
|
||||
// .eq(LeaseUserWalletData::getBlockedBalance, initBlockBalance)
|
||||
// );
|
||||
// if (update < 1){
|
||||
// throw new PayRechargeException("支付失败,余额金额错误,消息重试!!!");
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -414,76 +478,70 @@ public class MessageReceiver {
|
||||
public void listenerPayBalanceStatusQueueMessage(@Payload RabbitmqPayAutoMessage payAutoReturnMessage) {
|
||||
//消费消息
|
||||
System.out.println("自动支付功能queueId"+payAutoReturnMessage.getQueue_id());
|
||||
Map<String, RabbitmqPayAutoInfoMessage> transactions = payAutoReturnMessage.getTransactions();
|
||||
Map<String,RabbitmqPayAutoReturnInfoMessage> collect = new HashMap<>();
|
||||
transactions.forEach((k, transaction) -> {
|
||||
collect.put(k,RabbitmqPayAutoReturnInfoMessage.builder()
|
||||
.to_address(transaction.getTo_address())
|
||||
.amount(transaction.getAmount())
|
||||
.tx_hash(payAutoReturnMessage.getQueue_id()+"第一笔")
|
||||
.block_height(10000L)
|
||||
.status(1)
|
||||
.build());
|
||||
});
|
||||
|
||||
RabbitmqPayAutoReturnMessage rabbitmqPayAutoReturnMessage = RabbitmqPayAutoReturnMessage.builder()
|
||||
.queue_id(payAutoReturnMessage.getQueue_id())
|
||||
.from_address(payAutoReturnMessage.getFrom_address())
|
||||
.pay_status(1)
|
||||
.to_address(payAutoReturnMessage.getTo_address())
|
||||
.chain(payAutoReturnMessage.getChain())
|
||||
.symbol(payAutoReturnMessage.getSymbol())
|
||||
.transactions(collect)
|
||||
.fee(payAutoReturnMessage.getFee())
|
||||
.amount(payAutoReturnMessage.getAmount())
|
||||
.status(1)
|
||||
.tx_hash(payAutoReturnMessage.getQueue_id())
|
||||
.block_height(1000L)
|
||||
.order_id(payAutoReturnMessage.getOrder_id())
|
||||
.build();
|
||||
|
||||
rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_AUTO_RETURN_QUEUE,rabbitmqPayAutoReturnMessage);
|
||||
}
|
||||
|
||||
////测试 开发环境 充值测试
|
||||
//@RabbitListener(queues = RabbitmqConstant.PAY_RECHARGE_QUEUE,containerFactory ="rabbitListenerContainerFactory")
|
||||
//@Transactional(rollbackFor = Exception.class)
|
||||
//public void listenerPayRechargeQueueMessage(@Payload RabbitmqPayRechargeMessage payAutoReturnMessage) {
|
||||
// //发送充值消息
|
||||
// RabbitmqPayRechargeReturnMessage rabbitmqPayRechargeReturnMessage = RabbitmqPayRechargeReturnMessage.builder()
|
||||
// .queue_id(payAutoReturnMessage.getQueue_id())
|
||||
// .status(2)
|
||||
// .amount(BigDecimal.valueOf(20))
|
||||
// .chain(payAutoReturnMessage.getChain())
|
||||
// .symbol(payAutoReturnMessage.getSymbol())
|
||||
// .address(payAutoReturnMessage.getAddress())
|
||||
// .tx_hash(payAutoReturnMessage.getQueue_id()+"第四笔")
|
||||
// .build();
|
||||
// rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_RECHARGE_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage);
|
||||
//
|
||||
//
|
||||
// //发送充值消息
|
||||
// RabbitmqPayRechargeReturnMessage rabbitmqPayRechargeReturnMessage1 = RabbitmqPayRechargeReturnMessage.builder()
|
||||
// .queue_id(payAutoReturnMessage.getQueue_id())
|
||||
// .status(1)
|
||||
// .amount(BigDecimal.valueOf(20))
|
||||
// .chain(payAutoReturnMessage.getChain())
|
||||
// .symbol(payAutoReturnMessage.getSymbol())
|
||||
// .address(payAutoReturnMessage.getAddress())
|
||||
// .tx_hash(payAutoReturnMessage.getQueue_id()+"第四笔")
|
||||
// .build();
|
||||
// rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_RECHARGE_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage1);
|
||||
//}
|
||||
//测试 开发环境 充值测试
|
||||
@RabbitListener(queues = RabbitmqConstant.PAY_RECHARGE_QUEUE,containerFactory ="rabbitListenerContainerFactory")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void listenerPayRechargeQueueMessage(@Payload RabbitmqPayRechargeMessage payAutoReturnMessage) {
|
||||
//发送充值消息
|
||||
RabbitmqPayRechargeReturnMessage rabbitmqPayRechargeReturnMessage = RabbitmqPayRechargeReturnMessage.builder()
|
||||
.queue_id(payAutoReturnMessage.getQueue_id())
|
||||
.status(2)
|
||||
.amount(BigDecimal.valueOf(20))
|
||||
.chain(payAutoReturnMessage.getChain())
|
||||
.symbol(payAutoReturnMessage.getSymbol())
|
||||
.address(payAutoReturnMessage.getAddress())
|
||||
.tx_hash(payAutoReturnMessage.getQueue_id()+"第四笔")
|
||||
.build();
|
||||
rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_RECHARGE_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage);
|
||||
|
||||
////提现
|
||||
//@RabbitListener(queues = RabbitmqConstant.PAY_WITHDRAW_QUEUE,containerFactory ="rabbitListenerContainerFactory")
|
||||
//@Transactional(rollbackFor = Exception.class)
|
||||
//public void listenerWithdrawQueueMessage(@Payload RabbitmqPayWithdrawMessage payAutoReturnMessage) {
|
||||
// //发送充值消息
|
||||
// RabbitmqPayWithdrawReturnMessage rabbitmqPayRechargeReturnMessage = RabbitmqPayWithdrawReturnMessage.builder()
|
||||
// .queue_id(payAutoReturnMessage.getQueue_id())
|
||||
// .status(1)
|
||||
// .amount(payAutoReturnMessage.getAmount())
|
||||
// .chain(payAutoReturnMessage.getChain())
|
||||
// .symbol(payAutoReturnMessage.getSymbol())
|
||||
// .tx_hash(payAutoReturnMessage.getQueue_id()+"第一笔")
|
||||
// .fee(payAutoReturnMessage.getFee())
|
||||
// .build();
|
||||
// rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_WITHDRAW_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage);
|
||||
//}
|
||||
|
||||
//发送充值消息
|
||||
RabbitmqPayRechargeReturnMessage rabbitmqPayRechargeReturnMessage1 = RabbitmqPayRechargeReturnMessage.builder()
|
||||
.queue_id(payAutoReturnMessage.getQueue_id())
|
||||
.status(1)
|
||||
.amount(BigDecimal.valueOf(20))
|
||||
.chain(payAutoReturnMessage.getChain())
|
||||
.symbol(payAutoReturnMessage.getSymbol())
|
||||
.address(payAutoReturnMessage.getAddress())
|
||||
.tx_hash(payAutoReturnMessage.getQueue_id()+"第四笔")
|
||||
.build();
|
||||
rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_RECHARGE_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage1);
|
||||
}
|
||||
|
||||
//提现
|
||||
@RabbitListener(queues = RabbitmqConstant.PAY_WITHDRAW_QUEUE,containerFactory ="rabbitListenerContainerFactory")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void listenerWithdrawQueueMessage(@Payload RabbitmqPayWithdrawMessage payAutoReturnMessage) {
|
||||
//发送充值消息
|
||||
RabbitmqPayWithdrawReturnMessage rabbitmqPayRechargeReturnMessage = RabbitmqPayWithdrawReturnMessage.builder()
|
||||
.queue_id(payAutoReturnMessage.getQueue_id())
|
||||
.status(1)
|
||||
.amount(payAutoReturnMessage.getAmount())
|
||||
.chain(payAutoReturnMessage.getChain())
|
||||
.symbol(payAutoReturnMessage.getSymbol())
|
||||
.tx_hash(payAutoReturnMessage.getQueue_id()+"第一笔")
|
||||
.fee(payAutoReturnMessage.getFee())
|
||||
.build();
|
||||
rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_WITHDRAW_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage);
|
||||
}
|
||||
|
||||
|
||||
////测试 开发环境 删除钱包测试
|
||||
|
||||
@@ -19,16 +19,34 @@ import java.util.Map;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RabbitmqPayAutoMessage {
|
||||
|
||||
/**
|
||||
* 消息ID
|
||||
*/
|
||||
private String queue_id;
|
||||
|
||||
/**
|
||||
* 买家充值地址
|
||||
* 用户支付地址
|
||||
*/
|
||||
private String from_address;
|
||||
|
||||
/**
|
||||
* 收款地址(用户自定义)
|
||||
*/
|
||||
private String to_address;
|
||||
|
||||
|
||||
/**
|
||||
* 支付金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private BigDecimal fee;
|
||||
|
||||
|
||||
/**
|
||||
* 链名称
|
||||
*/
|
||||
@@ -39,29 +57,93 @@ public class RabbitmqPayAutoMessage {
|
||||
*/
|
||||
private String symbol;
|
||||
|
||||
/**
|
||||
* 订单总金额
|
||||
*/
|
||||
private BigDecimal total_amount;
|
||||
|
||||
/**
|
||||
* 订单总手续费
|
||||
*/
|
||||
private BigDecimal total_fee;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp;
|
||||
|
||||
|
||||
/**
|
||||
* 签名 时间戳+m2pool
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 收款方信息
|
||||
* 订单号(该字段不再传递 一个fromAddress 可以对应多个订单)
|
||||
*/
|
||||
private Map<String,RabbitmqPayAutoInfoMessage> transactions;
|
||||
private String order_id;
|
||||
//下面五个不需要传输,只存数据库
|
||||
/**
|
||||
* 买方钱包冻结金额
|
||||
*/
|
||||
private BigDecimal blockAmount;
|
||||
|
||||
/**
|
||||
* 实际应支付金额
|
||||
*/
|
||||
private BigDecimal needAmount;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
|
||||
|
||||
///**
|
||||
// * 消息ID
|
||||
// */
|
||||
//private String queue_id;
|
||||
//
|
||||
///**
|
||||
// * 买家充值地址
|
||||
// */
|
||||
//private String from_address;
|
||||
//
|
||||
///**
|
||||
// * 链名称
|
||||
// */
|
||||
//private String chain;
|
||||
//
|
||||
///**
|
||||
// * 币种
|
||||
// */
|
||||
//private String symbol;
|
||||
//
|
||||
///**
|
||||
// * 订单总金额
|
||||
// */
|
||||
//private BigDecimal total_amount;
|
||||
//
|
||||
///**
|
||||
// * 订单总手续费
|
||||
// */
|
||||
//private BigDecimal total_fee;
|
||||
//
|
||||
///**
|
||||
// * 时间戳
|
||||
// */
|
||||
//private Long timestamp;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 签名 时间戳+m2pool
|
||||
// */
|
||||
//private String sign;
|
||||
///**
|
||||
// * 收款方信息
|
||||
// */
|
||||
//private Map<String,RabbitmqPayAutoInfoMessage> transactions;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,15 +27,6 @@ public class RabbitmqPayAutoReturnMessage{
|
||||
*/
|
||||
private String queue_id;
|
||||
|
||||
/**
|
||||
* 支付结果
|
||||
*/
|
||||
private Integer pay_status;
|
||||
|
||||
/**
|
||||
* 买家支付地址
|
||||
*/
|
||||
private String from_address;
|
||||
/**
|
||||
* 链名称
|
||||
*/
|
||||
@@ -46,8 +37,78 @@ public class RabbitmqPayAutoReturnMessage{
|
||||
*/
|
||||
private String symbol;
|
||||
|
||||
|
||||
/**
|
||||
* 收款方信息
|
||||
* 支付结果
|
||||
*/
|
||||
private Map<String,RabbitmqPayAutoReturnInfoMessage> transactions;
|
||||
private Integer status;
|
||||
|
||||
|
||||
/**
|
||||
* 支付金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private BigDecimal fee;
|
||||
|
||||
|
||||
/**
|
||||
* 交易hash
|
||||
*/
|
||||
private String tx_hash;
|
||||
|
||||
/**
|
||||
* 块高
|
||||
*/
|
||||
private Long block_height;
|
||||
|
||||
|
||||
/**
|
||||
* 买家支付地址
|
||||
*/
|
||||
private String from_address;
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String order_id;
|
||||
|
||||
|
||||
/**
|
||||
* 卖家
|
||||
*/
|
||||
private String to_address;
|
||||
|
||||
|
||||
///**
|
||||
// * 消息ID
|
||||
// */
|
||||
//private String queue_id;
|
||||
//
|
||||
///**
|
||||
// * 支付结果
|
||||
// */
|
||||
//private Integer pay_status;
|
||||
//
|
||||
///**
|
||||
// * 买家支付地址
|
||||
// */
|
||||
//private String from_address;
|
||||
///**
|
||||
// * 链名称
|
||||
// */
|
||||
//private String chain;
|
||||
//
|
||||
///**
|
||||
// * 币种
|
||||
// */
|
||||
//private String symbol;
|
||||
//
|
||||
///**
|
||||
// * 收款方信息
|
||||
// */
|
||||
//private Map<String,RabbitmqPayAutoReturnInfoMessage> transactions;
|
||||
}
|
||||
|
||||
@@ -16,15 +16,16 @@ import com.m2pool.lease.dto.*;
|
||||
import com.m2pool.lease.entity.*;
|
||||
import com.m2pool.lease.exception.OrderException;
|
||||
import com.m2pool.lease.mapper.*;
|
||||
import com.m2pool.lease.service.*;
|
||||
import com.m2pool.lease.utils.QrCodeUtils;
|
||||
import com.m2pool.lease.service.LeaseOrderInfoService;
|
||||
import com.m2pool.lease.service.LeaseOrderItemService;
|
||||
import com.m2pool.lease.service.LeaseProductService;
|
||||
import com.m2pool.lease.service.LeaseUserOwnedProductService;
|
||||
import com.m2pool.lease.utils.UuidGeneratorUtil;
|
||||
import com.m2pool.lease.vo.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -84,9 +85,6 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
@Resource
|
||||
private LeaseProductMachinePriceMapper leaseProductMachinePriceMapper;
|
||||
|
||||
@Resource
|
||||
private LeaseOrderFeeMapper leaseOrderFeeMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -105,14 +103,15 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
//}
|
||||
|
||||
List<OrderInfoVo> orderInfoVoList = orderAndCodeVo.getOrderInfoVoList();
|
||||
//存储根据chain和coin去重后的set集合
|
||||
Set<ChainAndCoinDto> chainAndCoinSet = new HashSet<>();
|
||||
Set<ChainAndCoinDto> chainAndCoinAndShopIdSet = new HashSet<>();
|
||||
|
||||
//存储相同链和币种的map集合
|
||||
Map<String, Map<String, List<OrderInfoVo>>> chainAndCoinMap = new HashMap<>();
|
||||
Map<Long, LeaseProductMachinePrice> orderTotalPriceGroupByChainAndCoin = leaseProductMachinePriceMapper.getOrderTotalPriceGroupByChainAndCoin(orderInfoVoList);
|
||||
//chain + coin 钱包 对应的总价
|
||||
Map<String, BigDecimal> totalPriceMap = new HashMap<>();
|
||||
//存储根据chain和coin去重后的set集合
|
||||
Set<ChainAndCoinDto> chainAndCoinSet = new HashSet<>();
|
||||
Set<ChainAndCoinDto> chainAndCoinAndShopIdSet = new HashSet<>();
|
||||
//其他
|
||||
Map<Long, OrderInfoVo> machineMap = new HashMap<>();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
@@ -121,7 +120,8 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
for (OrderInfoVo vo : orderInfoVoList) {
|
||||
String chain = vo.getChain();
|
||||
String coin = vo.getCoin();
|
||||
String key = chain +"-"+ coin;
|
||||
Long shopId = vo.getShopId();
|
||||
String key = chain +"-"+ coin+"-"+shopId;
|
||||
chainAndCoinSet.add(new ChainAndCoinDto(coin, chain));
|
||||
chainAndCoinAndShopIdSet.add(new ChainAndCoinDto(coin, chain,vo.getShopId()));
|
||||
chainAndCoinMap.computeIfAbsent(chain, k -> new HashMap<>());
|
||||
@@ -148,6 +148,25 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
return Result.fail("下单失败!订单选择的支付方式中对应钱包您还未绑定并充值!");
|
||||
}
|
||||
|
||||
Map<String, LeaseUserWalletData> fromAddressMap = walletDataList.stream().collect(Collectors.toMap(item -> item.getFromChain() + "-" + item.getFromSymbol(), Function.identity()));
|
||||
//封装订单主表信息
|
||||
List<LeaseOrderInfo> leaseOrderInfoList = new ArrayList<>();
|
||||
totalPriceMap.forEach((key, totalPrice)->{
|
||||
String[] split = key.split("-");
|
||||
String coin = split[1];
|
||||
String chain = split[0];
|
||||
BigDecimal fee = CoinCharge.getFee(chain, coin, totalPrice);
|
||||
leaseOrderInfoList.add(LeaseOrderInfo.builder()
|
||||
.chainAndCoinAndShopIdKey(key)
|
||||
.chainAndCoinKey(chain+"-"+coin)
|
||||
.orderNumber(UuidGeneratorUtil.generateUuidWithoutHyphen())
|
||||
.userId(userEmail)
|
||||
.fee(fee)
|
||||
.totalPrice(totalPrice)
|
||||
.createTime(now)
|
||||
.build());
|
||||
});
|
||||
|
||||
//删除购物车中矿机
|
||||
LeaseShoppingCart leaseShoppingCart = leaseShoppingCartMapper.selectOne(new LambdaQueryWrapper<LeaseShoppingCart>()
|
||||
.eq(LeaseShoppingCart::getUserId, SecurityUtils.getUsername()));
|
||||
@@ -173,38 +192,12 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
configMap.put(key, leaseShopConfig);
|
||||
feeMap.computeIfAbsent(leaseShopConfig.getChain() + "-" + leaseShopConfig.getPayCoin(), k -> new HashSet<>()).add(leaseShopConfig.getPayAddress());
|
||||
}
|
||||
//根据买方钱包的 chain和coin 设置要生成的订单个数 以及对应的订单总价
|
||||
List<LeaseOrderInfo> leaseOrderInfoList = new ArrayList<>();
|
||||
Map<String, BigDecimal> totalFeeMap = new HashMap<>();
|
||||
Map<String, LeaseUserWalletData> walletDataMap = new HashMap<>();
|
||||
for (LeaseUserWalletData leaseUserWalletData : walletDataList) {
|
||||
String key = leaseUserWalletData.getFromChain() + "-" + leaseUserWalletData.getFromSymbol();
|
||||
BigDecimal totalAmount = totalPriceMap.get(key);
|
||||
String orderNumber = UuidGeneratorUtil.generateUuidWithoutHyphen();
|
||||
Set<String> toAddressList = feeMap.get(key);
|
||||
int size = toAddressList.size();
|
||||
BigDecimal charge = CoinCharge.getChargeByChainAndCoin(leaseUserWalletData.getFromChain(), leaseUserWalletData.getFromSymbol());
|
||||
BigDecimal fee = charge.multiply(BigDecimal.valueOf(size));
|
||||
leaseOrderInfoList.add(LeaseOrderInfo.builder()
|
||||
.chainAndCoinKey(key)
|
||||
.orderNumber(orderNumber)
|
||||
.userId(userEmail)
|
||||
.fee(fee)
|
||||
.totalPrice(totalAmount)
|
||||
.createTime(now)
|
||||
.build());
|
||||
totalFeeMap.put(key, fee);
|
||||
walletDataMap.put(key, leaseUserWalletData);
|
||||
}
|
||||
boolean save = saveBatch(leaseOrderInfoList);
|
||||
if (!save){
|
||||
return Result.fail("生成订单失败");
|
||||
}
|
||||
for (LeaseOrderInfo leaseOrderInfo : leaseOrderInfoList) {
|
||||
|
||||
}
|
||||
Map<String, LeaseOrderInfo> orderInfoMap = leaseOrderInfoList.stream()
|
||||
.collect(Collectors.toMap(LeaseOrderInfo::getChainAndCoinKey, Function.identity()));
|
||||
.collect(Collectors.toMap(LeaseOrderInfo::getChainAndCoinAndShopIdKey, Function.identity()));
|
||||
|
||||
//订单详情表业务
|
||||
List<LeaseProduct> leaseProducts = leaseProductMapper.selectBatchIds(productIds);
|
||||
@@ -217,13 +210,14 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
String chain = orderInfoVo.getChain();
|
||||
String coin = orderInfoVo.getCoin();
|
||||
Long shopId = orderInfoVo.getShopId();
|
||||
String key = chain + "-" + coin + "-" + shopId;
|
||||
LeaseProductMachinePrice leaseProductMachinePrice = orderTotalPriceGroupByChainAndCoin.get(machineId);
|
||||
LeaseShopConfig leaseShopConfig = configMap.get(chain + "-" +coin +"-"+ shopId);
|
||||
LeaseUserWalletData walletInfo = walletDataMap.get(chain + "-" + coin);
|
||||
LeaseShopConfig leaseShopConfig = configMap.get(key);
|
||||
LeaseUserWalletData walletInfo = fromAddressMap.get(chain + "-" + coin);
|
||||
if (leaseShopConfig == null){
|
||||
throw new OrderException("选择的卖家收款钱包不存在,请重行选择支付方法");
|
||||
}
|
||||
LeaseOrderInfo leaseOrderInfo = orderInfoMap.get(chain + "-" + coin);
|
||||
LeaseOrderInfo leaseOrderInfo = orderInfoMap.get(key);
|
||||
//设置销售数量
|
||||
LeaseProduct leaseProduct = productMap.get(leaseProductMachine.getProductId());
|
||||
leaseProduct.setSaleNumber(leaseProduct.getSaleNumber() + 1);
|
||||
@@ -260,7 +254,7 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
|
||||
//开始生成支付订单并返回
|
||||
if (a && b && c){
|
||||
checkBalanceAndSetBlockBalance(walletDataMap,totalPriceMap,totalFeeMap);
|
||||
checkBalanceAndSetBlockBalance(fromAddressMap,leaseOrderInfoList);
|
||||
//修改商品矿机售出状态 以商品机器sale_state作为乐观锁
|
||||
int i = leaseProductMachineMapper.updateLockState(machineIds);
|
||||
if (i != machineIds.size()){
|
||||
@@ -276,19 +270,19 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
* 检测钱包余额是否充足 余额充足则将余额冻结
|
||||
* @return
|
||||
*/
|
||||
public void checkBalanceAndSetBlockBalance(Map<String, LeaseUserWalletData> walletDataMap,Map<String, BigDecimal> totalPriceMap,Map<String, BigDecimal> feeMap){
|
||||
public void checkBalanceAndSetBlockBalance(Map<String, LeaseUserWalletData> fromAddressMap,List<LeaseOrderInfo> leaseOrderInfoList){
|
||||
Map<String, List<LeaseOrderInfo>> collect = leaseOrderInfoList.stream().collect(Collectors.groupingBy(LeaseOrderInfo::getChainAndCoinKey));
|
||||
|
||||
totalPriceMap.forEach((chainAndCoinKey, totalAmount) -> {
|
||||
LeaseUserWalletData walletData = walletDataMap.get(chainAndCoinKey);
|
||||
BigDecimal fee = feeMap.get(chainAndCoinKey);
|
||||
if (walletData == null){
|
||||
throw new OrderException("下单失败,买家不存在"+chainAndCoinKey+"类型钱包");
|
||||
fromAddressMap.forEach((chainAndCoinKey, leaseUserWalletData) -> {
|
||||
List<LeaseOrderInfo> leaseOrderInfos = collect.get(chainAndCoinKey);
|
||||
BigDecimal totalAmount = leaseOrderInfos.stream().map(LeaseOrderInfo::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalFee = leaseOrderInfos.stream().map(LeaseOrderInfo::getFee).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
if (leaseUserWalletData.getBalance().subtract(leaseUserWalletData.getBlockedBalance()).compareTo(totalAmount.add(totalFee)) < 0){
|
||||
throw new OrderException("下单失败,买家"+chainAndCoinKey+"钱包余额不足,缺少" + (totalAmount.add(totalFee).subtract(leaseUserWalletData.getBalance().subtract(leaseUserWalletData.getBlockedBalance()))) +"满足支付需求");
|
||||
}
|
||||
if (walletData.getBalance().subtract(walletData.getBlockedBalance()).compareTo(totalAmount) < 0){
|
||||
throw new OrderException("下单失败,买家"+chainAndCoinKey+"钱包余额不足,缺少" + (totalAmount.subtract(walletData.getBalance().subtract(walletData.getBlockedBalance()))) +"满足支付需求");
|
||||
}
|
||||
walletData.setBlockedBalance(walletData.getBlockedBalance().add(totalAmount).add(fee));
|
||||
leaseUserWalletDataMapper.updateById(walletData);
|
||||
leaseUserWalletData.setBlockedBalance(leaseUserWalletData.getBlockedBalance().add(totalAmount).add(totalFee));
|
||||
leaseUserWalletDataMapper.updateById(leaseUserWalletData);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class LeaseProductMachineServiceImpl extends ServiceImpl<LeaseProductMach
|
||||
String userId = SecurityUtils.getUsername();
|
||||
|
||||
//开发环境
|
||||
//userId = "Eudora.law@outlook.com";
|
||||
userId = "Eudora.law@outlook.com";
|
||||
List<UserMinerDto> userMinersList = leaseProductMachineMapper.getUserMinersList(userId,userMinerVo.getCoin());
|
||||
Map<String, List<UserMinerDto>> collect = userMinersList.stream().collect(Collectors.groupingBy(UserMinerDto::getCoin));
|
||||
return Result.success(collect);
|
||||
@@ -325,7 +325,7 @@ public class LeaseProductMachineServiceImpl extends ServiceImpl<LeaseProductMach
|
||||
if (b){
|
||||
updatePriceRange(leaseProductMachine.getProductId());
|
||||
//删除售价
|
||||
leaseProductMachinePriceService.removeById(baseVo.getId());
|
||||
leaseProductMachinePriceService.updateById(LeaseProductMachinePrice.builder().id(baseVo.getId()).del(true).build());
|
||||
return Result.success("删除成功");
|
||||
}
|
||||
return Result.fail("删除失败");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.m2pool.lease.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -11,6 +10,7 @@ import com.m2pool.common.redis.service.RedisService;
|
||||
import com.m2pool.common.security.utils.SecurityUtils;
|
||||
import com.m2pool.lease.constant.Algorithm;
|
||||
import com.m2pool.lease.constant.BlockInterval;
|
||||
import com.m2pool.lease.constant.PowerUnit;
|
||||
import com.m2pool.lease.constant.RedisKey;
|
||||
import com.m2pool.lease.dto.*;
|
||||
import com.m2pool.lease.entity.*;
|
||||
@@ -34,7 +34,6 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -138,12 +137,8 @@ public class LeaseProductServiceImpl extends ServiceImpl<LeaseProductMapper, Lea
|
||||
Long productId = productMachineVo.getId();
|
||||
LeaseProduct product = getById(productId);
|
||||
List<PayConfigDto> shopWalletInfo = leaseShopMapper.getShopWalletInfo(product.getShopId());
|
||||
PayConfigDto payConfigDto = shopWalletInfo.get(0);
|
||||
PageHelper.startPage(productMachineVo.getPageNum(), productMachineVo.getPageSize());
|
||||
if (StringUtils.isEmpty(productMachineVo.getChain()) && StringUtils.isEmpty(productMachineVo.getCoin())){
|
||||
productMachineVo.setChain(payConfigDto.getPayChain());
|
||||
productMachineVo.setCoin(payConfigDto.getPayCoin());
|
||||
}
|
||||
productMachineVo = buildQuery(productMachineVo,shopWalletInfo.get(0));
|
||||
List<ProductMachineDto> productMachineDtoList = leaseProductMachineMapper.getMachinesByPriceAndPowerAndDissipation(productMachineVo, product.getCoin());
|
||||
PageInfo<ProductMachineDto> pageInfo = new PageInfo<>(productMachineDtoList);
|
||||
|
||||
@@ -187,6 +182,36 @@ public class LeaseProductServiceImpl extends ServiceImpl<LeaseProductMapper, Lea
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
* @param productMachineVo
|
||||
* @param payConfigDto
|
||||
* @return
|
||||
*/
|
||||
public ProductMachineVo buildQuery(ProductMachineVo productMachineVo,PayConfigDto payConfigDto){
|
||||
if (StringUtils.isEmpty(productMachineVo.getChain()) && StringUtils.isEmpty(productMachineVo.getCoin())){
|
||||
productMachineVo.setChain(payConfigDto.getPayChain());
|
||||
productMachineVo.setCoin(payConfigDto.getPayCoin());
|
||||
}
|
||||
//算力设置
|
||||
if (productMachineVo.getMaxPower().compareTo(productMachineVo.getMinPower()) < 0){
|
||||
productMachineVo.setMaxPower(productMachineVo.getMinPower());
|
||||
productMachineVo.setMinPower(productMachineVo.getMaxPower());
|
||||
}
|
||||
//功耗设置
|
||||
if (productMachineVo.getMaxPowerDissipation().compareTo(productMachineVo.getMinPowerDissipation()) < 0){
|
||||
productMachineVo.setMaxPowerDissipation(productMachineVo.getMinPowerDissipation());
|
||||
productMachineVo.setMinPowerDissipation(productMachineVo.getMaxPowerDissipation());
|
||||
}
|
||||
//价格设置
|
||||
if (productMachineVo.getMaxPrice().compareTo(productMachineVo.getMinPrice()) < 0){
|
||||
BigDecimal power = PowerUnit.getPower(productMachineVo.getUnit()).divide(BigDecimal.valueOf(1000 * 1000),2,RoundingMode.HALF_UP);
|
||||
productMachineVo.setMaxPrice(productMachineVo.getMinPrice().multiply(power));
|
||||
productMachineVo.setMinPrice(productMachineVo.getMaxPrice().multiply(power));
|
||||
}
|
||||
return productMachineVo;
|
||||
}
|
||||
|
||||
public List<ProductMachineDto> sorted(List<ProductMachineDto> productMachineDtoList,ProductMachineVo productMachineVo){
|
||||
|
||||
if (productMachineVo.getPriceSort() != null) {
|
||||
@@ -226,68 +251,68 @@ public class LeaseProductServiceImpl extends ServiceImpl<LeaseProductMapper, Lea
|
||||
return Result.success(shopWalletInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算每个价格分组中商品机器的功耗、理论算力、实际算力范围,并返回对应的范围信息对象
|
||||
* @param productMachineDtoMap 按价格分组的商品机器列表
|
||||
* @return 每个价格对应的商品机器范围信息
|
||||
*/
|
||||
public static Map<BigDecimal, ProductMachineRangeGroupDto> calculateRanges(Map<BigDecimal, List<ProductMachineDto>> productMachineDtoMap) {
|
||||
// 使用 AtomicInteger 来实现 onlyKey 递增
|
||||
AtomicInteger onlyKey = new AtomicInteger(0);
|
||||
return productMachineDtoMap.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
entry -> {
|
||||
List<ProductMachineDto> productMachines = entry.getValue();
|
||||
int number = productMachines.size();
|
||||
BigDecimal price = entry.getKey();
|
||||
|
||||
// 计算功耗范围
|
||||
BigDecimal minPower = productMachines.stream()
|
||||
.map(ProductMachineDto::getPowerDissipation)
|
||||
.min(BigDecimal::compareTo)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
BigDecimal maxPower = productMachines.stream()
|
||||
.map(ProductMachineDto::getPowerDissipation)
|
||||
.max(BigDecimal::compareTo)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
String powerRange = minPower.equals(maxPower) ? String.valueOf(minPower) : minPower + " - " + maxPower;
|
||||
|
||||
// 计算理论算力范围
|
||||
BigDecimal minTheoryPower = productMachines.stream()
|
||||
.map(ProductMachineDto::getTheoryPower)
|
||||
.min(BigDecimal::compareTo)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
BigDecimal maxTheoryPower = productMachines.stream()
|
||||
.map(ProductMachineDto::getTheoryPower)
|
||||
.max(BigDecimal::compareTo)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
String theoryPowerRange = minTheoryPower.equals(maxTheoryPower) ? String.valueOf(minTheoryPower) : minTheoryPower + " - " + maxTheoryPower;
|
||||
|
||||
// 计算实际算力范围
|
||||
BigDecimal minComputingPower = productMachines.stream()
|
||||
.map(ProductMachineDto::getComputingPower)
|
||||
.min(BigDecimal::compareTo)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
BigDecimal maxComputingPower = productMachines.stream()
|
||||
.map(ProductMachineDto::getComputingPower)
|
||||
.max(BigDecimal::compareTo)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
String computingPowerRange = minComputingPower.equals(maxComputingPower) ? String.valueOf(minComputingPower) : minComputingPower + " - " + maxComputingPower;
|
||||
String unit = productMachines.get(0).getUnit();
|
||||
int onlyKey1 = onlyKey.incrementAndGet();
|
||||
return ProductMachineRangeGroupDto.builder()
|
||||
.onlyKey(onlyKey1)
|
||||
.powerRange(powerRange)
|
||||
.theoryPowerRange(theoryPowerRange)
|
||||
.computingPowerRange(computingPowerRange)
|
||||
.number(number)
|
||||
.price(price)
|
||||
.unit(unit)
|
||||
.build();
|
||||
}
|
||||
));
|
||||
}
|
||||
///**
|
||||
// * 计算每个价格分组中商品机器的功耗、理论算力、实际算力范围,并返回对应的范围信息对象
|
||||
// * @param productMachineDtoMap 按价格分组的商品机器列表
|
||||
// * @return 每个价格对应的商品机器范围信息
|
||||
// */
|
||||
//public static Map<BigDecimal, ProductMachineRangeGroupDto> calculateRanges(Map<BigDecimal, List<ProductMachineDto>> productMachineDtoMap) {
|
||||
// // 使用 AtomicInteger 来实现 onlyKey 递增
|
||||
// AtomicInteger onlyKey = new AtomicInteger(0);
|
||||
// return productMachineDtoMap.entrySet().stream()
|
||||
// .collect(Collectors.toMap(
|
||||
// Map.Entry::getKey,
|
||||
// entry -> {
|
||||
// List<ProductMachineDto> productMachines = entry.getValue();
|
||||
// int number = productMachines.size();
|
||||
// BigDecimal price = entry.getKey();
|
||||
//
|
||||
// // 计算功耗范围
|
||||
// BigDecimal minPower = productMachines.stream()
|
||||
// .map(ProductMachineDto::getPowerDissipation)
|
||||
// .min(BigDecimal::compareTo)
|
||||
// .orElse(BigDecimal.ZERO);
|
||||
// BigDecimal maxPower = productMachines.stream()
|
||||
// .map(ProductMachineDto::getPowerDissipation)
|
||||
// .max(BigDecimal::compareTo)
|
||||
// .orElse(BigDecimal.ZERO);
|
||||
// String powerRange = minPower.equals(maxPower) ? String.valueOf(minPower) : minPower + " - " + maxPower;
|
||||
//
|
||||
// // 计算理论算力范围
|
||||
// BigDecimal minTheoryPower = productMachines.stream()
|
||||
// .map(ProductMachineDto::getTheoryPower)
|
||||
// .min(BigDecimal::compareTo)
|
||||
// .orElse(BigDecimal.ZERO);
|
||||
// BigDecimal maxTheoryPower = productMachines.stream()
|
||||
// .map(ProductMachineDto::getTheoryPower)
|
||||
// .max(BigDecimal::compareTo)
|
||||
// .orElse(BigDecimal.ZERO);
|
||||
// String theoryPowerRange = minTheoryPower.equals(maxTheoryPower) ? String.valueOf(minTheoryPower) : minTheoryPower + " - " + maxTheoryPower;
|
||||
//
|
||||
// // 计算实际算力范围
|
||||
// BigDecimal minComputingPower = productMachines.stream()
|
||||
// .map(ProductMachineDto::getComputingPower)
|
||||
// .min(BigDecimal::compareTo)
|
||||
// .orElse(BigDecimal.ZERO);
|
||||
// BigDecimal maxComputingPower = productMachines.stream()
|
||||
// .map(ProductMachineDto::getComputingPower)
|
||||
// .max(BigDecimal::compareTo)
|
||||
// .orElse(BigDecimal.ZERO);
|
||||
// String computingPowerRange = minComputingPower.equals(maxComputingPower) ? String.valueOf(minComputingPower) : minComputingPower + " - " + maxComputingPower;
|
||||
// String unit = productMachines.get(0).getUnit();
|
||||
// int onlyKey1 = onlyKey.incrementAndGet();
|
||||
// return ProductMachineRangeGroupDto.builder()
|
||||
// .onlyKey(onlyKey1)
|
||||
// .powerRange(powerRange)
|
||||
// .theoryPowerRange(theoryPowerRange)
|
||||
// .computingPowerRange(computingPowerRange)
|
||||
// .number(number)
|
||||
// .price(price)
|
||||
// .unit(unit)
|
||||
// .build();
|
||||
// }
|
||||
// ));
|
||||
//}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -325,7 +350,7 @@ public class LeaseProductServiceImpl extends ServiceImpl<LeaseProductMapper, Lea
|
||||
public Result<String> updateProduct(ProductURDVo productURDVo) {;
|
||||
PriceDto priceDto = leaseProductMachineMapper.getPriceRange(productURDVo.getId());
|
||||
BigDecimal maxPrice = BigDecimal.ZERO;
|
||||
BigDecimal minPrice = BigDecimal.ZERO;;
|
||||
BigDecimal minPrice = BigDecimal.ZERO;
|
||||
if (priceDto != null){
|
||||
maxPrice = priceDto.getPriceMax();
|
||||
minPrice = priceDto.getPriceMin();
|
||||
@@ -373,8 +398,7 @@ public class LeaseProductServiceImpl extends ServiceImpl<LeaseProductMapper, Lea
|
||||
leaseProductMachineMapper.update(LeaseProductMachine.builder().del(true).build(),
|
||||
new LambdaQueryWrapper<LeaseProductMachine>().in(LeaseProductMachine::getId, machineIds));
|
||||
//删除矿机对应的售价
|
||||
leaseProductMachinePriceService.remove(new LambdaUpdateWrapper<LeaseProductMachinePrice>()
|
||||
.in(LeaseProductMachinePrice::getProductMachineId, machineIds));
|
||||
leaseProductMachinePriceService.update(LeaseProductMachinePrice.builder().del(true).build(),new LambdaUpdateWrapper<LeaseProductMachinePrice>().in(LeaseProductMachinePrice::getProductMachineId, machineIds));
|
||||
}
|
||||
|
||||
return Result.success("删除成功");
|
||||
|
||||
@@ -53,6 +53,9 @@ public class LeaseShopServiceImpl extends ServiceImpl<LeaseShopMapper, LeaseShop
|
||||
@Resource
|
||||
private LeaseProductMachineMapper leaseProductMachineMapper;
|
||||
|
||||
@Resource
|
||||
private LeaseProductMachinePriceMapper leaseProductMachinePriceMapper;
|
||||
|
||||
@Override
|
||||
public Result<String> addShop(ShopVo shopVo) {
|
||||
LeaseShop leaseShop1 = leaseShopMapper.selectOne(new LambdaQueryWrapper<LeaseShop>()
|
||||
@@ -366,6 +369,8 @@ public class LeaseShopServiceImpl extends ServiceImpl<LeaseShopMapper, LeaseShop
|
||||
LeaseShopConfig config = leaseShopConfigMapper.selectById(baseVo.getId());
|
||||
Long configNums = leaseShopConfigMapper.selectCount(new LambdaQueryWrapper<LeaseShopConfig>()
|
||||
.eq(LeaseShopConfig::getShopId, config.getShopId()).eq(LeaseShopConfig::getDel, false));
|
||||
|
||||
List<Long> ids = leaseProductMachineMapper.getIdsForShopId(config.getShopId());
|
||||
Long productNums = leaseProductMapper.selectCount(new LambdaQueryWrapper<LeaseProduct>()
|
||||
.eq(LeaseProduct::getShopId, config.getShopId())
|
||||
.eq(LeaseProduct::getDel, false));
|
||||
@@ -374,14 +379,12 @@ public class LeaseShopServiceImpl extends ServiceImpl<LeaseShopMapper, LeaseShop
|
||||
}
|
||||
//校验是否能够删除
|
||||
Long l = leaseOrderItemMapper.selectCount(new LambdaQueryWrapper<LeaseOrderItem>()
|
||||
.eq(LeaseOrderItem::getPayCoin, config.getPayCoin())
|
||||
.eq(LeaseOrderItem::getChain, config.getChain())
|
||||
.ne(LeaseOrderItem::getStatus, 0)
|
||||
);
|
||||
if (l > 0){
|
||||
return Result.fail("删除钱包失败,该钱包存在交易中的订单");
|
||||
}
|
||||
|
||||
List<LeaseShopConfig> leaseShopConfigs = leaseShopConfigMapper.selectList(new LambdaQueryWrapper<LeaseShopConfig>()
|
||||
.eq(LeaseShopConfig::getShopId, config.getShopId())
|
||||
.eq(LeaseShopConfig::getChain, config.getChain())
|
||||
@@ -389,6 +392,11 @@ public class LeaseShopServiceImpl extends ServiceImpl<LeaseShopMapper, LeaseShop
|
||||
List<LeaseShopConfig> collect = leaseShopConfigs.stream().peek(leaseShopConfig -> leaseShopConfig.setDel(true)).collect(Collectors.toList());
|
||||
boolean b = leaseShopConfigService.updateBatchById(collect);
|
||||
if (b){
|
||||
leaseProductMachinePriceMapper.update(LeaseProductMachinePrice.builder().del(true).build(),
|
||||
new LambdaQueryWrapper<LeaseProductMachinePrice>()
|
||||
.eq(LeaseProductMachinePrice::getChain, config.getChain())
|
||||
.in(LeaseProductMachinePrice::getProductMachineId,ids)
|
||||
);
|
||||
return Result.success("删除成功");
|
||||
}
|
||||
return Result.fail("删除失败");
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.github.pagehelper.PageInfo;
|
||||
import com.m2pool.common.redis.service.RedisService;
|
||||
import com.m2pool.common.security.utils.SecurityUtils;
|
||||
import com.m2pool.lease.constant.BlockInterval;
|
||||
import com.m2pool.lease.constant.CoinCharge;
|
||||
import com.m2pool.lease.constant.PowerUnit;
|
||||
import com.m2pool.lease.constant.RedisKey;
|
||||
import com.m2pool.lease.dto.*;
|
||||
@@ -277,7 +278,13 @@ public class LeaseShoppingCartServiceImpl extends ServiceImpl<LeaseShoppingCartM
|
||||
|
||||
//获取商铺钱包配置信息
|
||||
List<PayConfigDto> shopWalletInfo = leaseShopMapper.getShopWalletInfoList(shopIds);
|
||||
Map<Long, List<PayConfigDto>> payConfigMap = shopWalletInfo.stream().collect(Collectors.groupingBy(PayConfigDto::getShopId));
|
||||
|
||||
Map<Long, List<PayConfigDto>> payConfigMap = shopWalletInfo.stream()
|
||||
.map(payConfigDto->{
|
||||
payConfigDto.setDeductibleAmount(CoinCharge.getChargeByChainAndCoin(payConfigDto.getPayChain(), payConfigDto.getPayCoin()));
|
||||
return payConfigDto;
|
||||
})
|
||||
.collect(Collectors.groupingBy(PayConfigDto::getShopId));
|
||||
//组合返回对象
|
||||
List<ShopCartDto> shopCartList = leaseShops.stream().map(leaseShop -> {
|
||||
List<ProductMachineDto> productMachineList = shopIdAndMachineInfoMap.get(leaseShop.getId());
|
||||
@@ -309,7 +316,6 @@ public class LeaseShoppingCartServiceImpl extends ServiceImpl<LeaseShoppingCartM
|
||||
totalPriceDtoMap.put(key,new MachineTotalPriceDto(BigDecimal.ZERO, machinePayTypeDto.getChain(), machinePayTypeDto.getCoin()));
|
||||
}
|
||||
}
|
||||
;
|
||||
totalPriceDtoMap.forEach((key, value) -> {
|
||||
value.setPrice(totalPriceMap.get(key));
|
||||
});
|
||||
|
||||
@@ -130,9 +130,12 @@ public class LeaseUserOwnedProductServiceImpl extends ServiceImpl<LeaseUserOwned
|
||||
.user(leaseUserOwnedProduct.getUser())
|
||||
.miner(leaseUserOwnedProduct.getMiner())
|
||||
.build());
|
||||
BigDecimal price = redisService.getCacheBigDecimal(RedisKey.getPiceKey(leaseUserOwnedProduct.getCoin()));
|
||||
//获取实时算力
|
||||
List<ProductMachineDto> recentlyFiveMinutesData = leaseProductMachineMapper.getRecentlyFiveMinutesData(leaseProductMachines, leaseUserOwnedProduct.getCoin());
|
||||
|
||||
Integer status = leaseUserOwnedProduct.getStatus();
|
||||
BigDecimal currentIncome = status == 0 ? leaseUserOwnedProduct.getSettleIncome() : leaseUserOwnedProduct.getCurrentIncome();
|
||||
BigDecimal currentUsdtIncome = currentIncome.multiply(price);
|
||||
UserOwnedProductDto build = UserOwnedProductDto.builder()
|
||||
.id(leaseUserOwnedProduct.getId())
|
||||
.userId(leaseUserOwnedProduct.getUserId())
|
||||
@@ -141,12 +144,12 @@ public class LeaseUserOwnedProductServiceImpl extends ServiceImpl<LeaseUserOwned
|
||||
.startTime(leaseUserOwnedProduct.getStartTime())
|
||||
.productMachineId(leaseUserOwnedProduct.getProductMachineId())
|
||||
.endTime(leaseUserOwnedProduct.getEndTime())
|
||||
.currentIncome(leaseUserOwnedProduct.getCurrentIncome())
|
||||
.estimatedEndIncome(leaseUserOwnedProduct.getEstimatedEndIncome())
|
||||
.currentUsdtIncome(leaseUserOwnedProduct.getCurrentUsdtIncome())
|
||||
.estimatedEndUsdtIncome(leaseUserOwnedProduct.getEstimatedEndUsdtIncome())
|
||||
.purchasedComputingPower(leaseUserOwnedProduct.getPurchasedComputingPower())
|
||||
.status(leaseUserOwnedProduct.getStatus())
|
||||
.currentIncome(currentIncome)
|
||||
.currentUsdtIncome(currentUsdtIncome)
|
||||
.status(status)
|
||||
.type(leaseUserOwnedProduct.getType())
|
||||
.createTime(leaseUserOwnedProduct.getCreateTime())
|
||||
.build();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.m2pool.lease.task;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@@ -9,13 +7,13 @@ import com.m2pool.lease.constant.PowerUnit;
|
||||
import com.m2pool.lease.dto.*;
|
||||
import com.m2pool.lease.entity.*;
|
||||
import com.m2pool.lease.mapper.*;
|
||||
import com.m2pool.lease.mq.message.*;
|
||||
import com.m2pool.lease.mq.message.RabbitmqDeleteWalletMessage;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayAutoMessage;
|
||||
import com.m2pool.lease.service.LeaseOrderItemService;
|
||||
import com.m2pool.lease.service.LeasePayRecordMessageService;
|
||||
import com.m2pool.lease.service.LeaseProductService;
|
||||
import com.m2pool.lease.service.LeaseUserOwnedProductService;
|
||||
import com.m2pool.lease.utils.HashUtils;
|
||||
import com.m2pool.lease.utils.UuidGeneratorUtil;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@@ -26,13 +24,12 @@ import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.m2pool.lease.constant.RabbitmqConstant.*;
|
||||
import static com.m2pool.lease.constant.RabbitmqConstant.DELETE_WALLET_QUEUE;
|
||||
import static com.m2pool.lease.constant.RabbitmqConstant.PAY_AUTO_QUEUE;
|
||||
|
||||
/**
|
||||
* @Description 订单超时 定时任务
|
||||
@@ -128,7 +125,7 @@ public class OrderAndPayTask {
|
||||
* 支付 定时任务
|
||||
*/
|
||||
//@Scheduled(cron = "0 5 0 * * ? ")
|
||||
@Scheduled(cron = "0 0/1 * * * ? ")
|
||||
@Scheduled(cron = "0 0/2 * * * ? ")
|
||||
@DSTransactional
|
||||
public void paymentTask(){
|
||||
// 获取当天 0 点的 时间
|
||||
@@ -194,34 +191,25 @@ public class OrderAndPayTask {
|
||||
//买方信息
|
||||
RabbitmqPayAutoMessage build = RabbitmqPayAutoMessage.builder()
|
||||
.queue_id(queueId)
|
||||
.order_id(String.valueOf(orderId))
|
||||
.chain(leaseOrderItem.getChain())
|
||||
.symbol(leaseOrderItem.getSymbol())
|
||||
.total_fee(orderInfo.getFee())
|
||||
.fee(orderInfo.getFee())
|
||||
.userId(leaseOrderItem.getUserId())
|
||||
.from_address(leaseOrderItem.getFromAddress())
|
||||
.total_amount(BigDecimal.ZERO)
|
||||
.to_address(leaseOrderItem.getAddress())
|
||||
.amount(BigDecimal.ZERO)
|
||||
.blockAmount(BigDecimal.ZERO)
|
||||
.needAmount(BigDecimal.ZERO)
|
||||
.timestamp(timestamp)
|
||||
.sign(HashUtils.sha256(timestamp))
|
||||
.build();
|
||||
//封装卖方收款信息
|
||||
Map<String,RabbitmqPayAutoInfoMessage> sellerPayInfoMessages = new HashMap<>();
|
||||
//买方收款信息 相同订单最后整合成一个卖方信息
|
||||
Map<String, List<LeaseOrderItem>> orderIdsMap = items.stream().collect(Collectors.groupingBy(LeaseOrderItem::getAddress));
|
||||
orderIdsMap.forEach((toAddress, orderItemList) -> {
|
||||
LeaseOrderItem orderItem = orderItemList.get(0);
|
||||
RabbitmqPayAutoInfoMessage sellInfo = RabbitmqPayAutoInfoMessage.builder()
|
||||
.order_id(orderItem.getOrderId().toString())
|
||||
.to_address(toAddress)
|
||||
.amount(BigDecimal.ZERO)
|
||||
.blockAmount(BigDecimal.ZERO)
|
||||
.needAmount(BigDecimal.ZERO)
|
||||
.shopId(orderItem.getShopId())
|
||||
.userId(orderItem.getUserId())
|
||||
.build();
|
||||
for (LeaseOrderItem item : orderItemList) {
|
||||
|
||||
for (LeaseOrderItem item : items) {
|
||||
orderInfoIdAndIsComplete.putIfAbsent(item.getOrderId(), true);
|
||||
LocalDateTime expireTime = item.getCreateTime().plusDays(1).toLocalDate().atStartOfDay().plusDays(item.getLeaseTime());
|
||||
//开发环境
|
||||
LocalDateTime a = item.getCreateTime().plusMinutes(item.getLeaseTime());
|
||||
LocalDateTime a = item.getCreateTime().plusMinutes(item.getLeaseTime() * 2);
|
||||
// 租期已过
|
||||
if (startOfDay.isAfter(expireTime) /**开发环境*/|| now.isAfter(a)) {
|
||||
item.setStatus(0);
|
||||
@@ -232,8 +220,8 @@ public class OrderAndPayTask {
|
||||
String key = item.getUser() + "-" + item.getMiner();
|
||||
LeaseProductMachine machine = idAndMachineMap.get(item.getProductMachineId());
|
||||
ProductMachineDto productMachineDto = machineDtoMap.get(key);
|
||||
sellInfo.setNeedAmount(sellInfo.getNeedAmount().add(item.getPrice()));
|
||||
sellInfo.setBlockAmount(sellInfo.getBlockAmount().add(item.getPrice()));
|
||||
build.setNeedAmount(build.getNeedAmount().add(item.getPrice()));
|
||||
build.setBlockAmount(build.getBlockAmount().add(item.getPrice()));
|
||||
if (productMachineDto != null){
|
||||
//理论算力
|
||||
BigDecimal theoryPower = machine.getTheoryPower().multiply(PowerUnit.getPower(machine.getUnit()))
|
||||
@@ -246,14 +234,12 @@ public class OrderAndPayTask {
|
||||
//设置实际需要发送消息去支付的各订单金额和总金额
|
||||
if (divide.compareTo(BigDecimal.valueOf(0.05)) > 0){
|
||||
BigDecimal add = item.getPrice().multiply(BigDecimal.ONE.subtract(divide));
|
||||
item.setSettlePayRealAmount(add);
|
||||
sellInfo.setAmount(sellInfo.getAmount().add(add));
|
||||
build.setTotal_amount(build.getTotal_amount().add(add));
|
||||
item.setSettlePayRealAmount(item.getSettlePayRealAmount().add(add));
|
||||
build.setAmount(build.getAmount().add(add));
|
||||
}else{
|
||||
BigDecimal add = item.getPrice();
|
||||
item.setSettlePayRealAmount(add);
|
||||
build.setTotal_amount(build.getTotal_amount().add(add));
|
||||
sellInfo.setAmount(sellInfo.getAmount().add(add));
|
||||
item.setSettlePayRealAmount(item.getSettlePayRealAmount().add(add));
|
||||
build.setAmount(build.getAmount().add(add));
|
||||
}
|
||||
}
|
||||
item.setAlreadyPayAmount(item.getAlreadyPayAmount().add(item.getPrice()));
|
||||
@@ -261,11 +247,73 @@ public class OrderAndPayTask {
|
||||
saleIngList.add(item);
|
||||
}
|
||||
}
|
||||
sellerPayInfoMessages.put(sellInfo.getTo_address(), sellInfo);
|
||||
|
||||
});
|
||||
build.setTransactions(sellerPayInfoMessages);
|
||||
if (build.getTotal_amount().compareTo(BigDecimal.ZERO) > 0){
|
||||
|
||||
////TODO 下面这个是一个订单 一个买家对应多个卖家(多个收款地址)的情况
|
||||
////封装卖方收款信息
|
||||
//Map<String,RabbitmqPayAutoInfoMessage> sellerPayInfoMessages = new HashMap<>();
|
||||
////买方收款信息 相同订单最后整合成一个卖方信息
|
||||
//Map<String, List<LeaseOrderItem>> orderIdsMap = items.stream().collect(Collectors.groupingBy(LeaseOrderItem::getAddress));
|
||||
//orderIdsMap.forEach((toAddress, orderItemList) -> {
|
||||
// LeaseOrderItem orderItem = orderItemList.get(0);
|
||||
// RabbitmqPayAutoInfoMessage sellInfo = RabbitmqPayAutoInfoMessage.builder()
|
||||
// .order_id(orderItem.getOrderId().toString())
|
||||
// .to_address(toAddress)
|
||||
// .amount(BigDecimal.ZERO)
|
||||
// .blockAmount(BigDecimal.ZERO)
|
||||
// .needAmount(BigDecimal.ZERO)
|
||||
// .shopId(orderItem.getShopId())
|
||||
// .userId(orderItem.getUserId())
|
||||
// .build();
|
||||
// for (LeaseOrderItem item : orderItemList) {
|
||||
// orderInfoIdAndIsComplete.putIfAbsent(item.getOrderId(), true);
|
||||
// LocalDateTime expireTime = item.getCreateTime().plusDays(1).toLocalDate().atStartOfDay().plusDays(item.getLeaseTime());
|
||||
// //开发环境
|
||||
// LocalDateTime a = item.getCreateTime().plusMinutes(item.getLeaseTime() * 2);
|
||||
// // 租期已过
|
||||
// if (startOfDay.isAfter(expireTime) /**开发环境*/|| now.isAfter(a)) {
|
||||
// item.setStatus(0);
|
||||
// expire.add(item);
|
||||
// }else{
|
||||
// orderInfoIdAndIsComplete.put(item.getOrderId(), false);
|
||||
// //根据算力波动实时计算需支付金额
|
||||
// String key = item.getUser() + "-" + item.getMiner();
|
||||
// LeaseProductMachine machine = idAndMachineMap.get(item.getProductMachineId());
|
||||
// ProductMachineDto productMachineDto = machineDtoMap.get(key);
|
||||
// sellInfo.setNeedAmount(sellInfo.getNeedAmount().add(item.getPrice()));
|
||||
// sellInfo.setBlockAmount(sellInfo.getBlockAmount().add(item.getPrice()));
|
||||
// if (productMachineDto != null){
|
||||
// //理论算力
|
||||
// BigDecimal theoryPower = machine.getTheoryPower().multiply(PowerUnit.getPower(machine.getUnit()))
|
||||
// .divide(BigDecimal.valueOf(1000 * 1000),2,RoundingMode.HALF_UP);
|
||||
// //实际算力
|
||||
// BigDecimal realPower = productMachineDto.getComputingPower()
|
||||
// .divide(BigDecimal.valueOf(24 * 60 * 60), 6, RoundingMode.HALF_UP);
|
||||
// //设置实际支付金额
|
||||
// BigDecimal divide = theoryPower.subtract(realPower).divide(theoryPower, 10, RoundingMode.HALF_UP);
|
||||
// //设置实际需要发送消息去支付的各订单金额和总金额
|
||||
// if (divide.compareTo(BigDecimal.valueOf(0.05)) > 0){
|
||||
// BigDecimal add = item.getPrice().multiply(BigDecimal.ONE.subtract(divide));
|
||||
// item.setSettlePayRealAmount(add);
|
||||
// sellInfo.setAmount(sellInfo.getAmount().add(add));
|
||||
// build.setTotal_amount(build.getTotal_amount().add(add));
|
||||
// }else{
|
||||
// BigDecimal add = item.getPrice();
|
||||
// item.setSettlePayRealAmount(add);
|
||||
// build.setTotal_amount(build.getTotal_amount().add(add));
|
||||
// sellInfo.setAmount(sellInfo.getAmount().add(add));
|
||||
// }
|
||||
// }
|
||||
// item.setAlreadyPayAmount(item.getAlreadyPayAmount().add(item.getPrice()));
|
||||
//
|
||||
// saleIngList.add(item);
|
||||
// }
|
||||
// }
|
||||
// sellerPayInfoMessages.put(sellInfo.getTo_address(), sellInfo);
|
||||
//
|
||||
//});
|
||||
//build.setTransactions(sellerPayInfoMessages);
|
||||
if (build.getAmount().compareTo(BigDecimal.ZERO) > 0){
|
||||
rabbitmqPayAutoMessages.add(build);
|
||||
}
|
||||
expireProductList.addAll(expire);
|
||||
@@ -286,17 +334,25 @@ public class OrderAndPayTask {
|
||||
leaseProductMachineMapper.update(LeaseProductMachine.builder().saleState(0).build(), new LambdaUpdateWrapper<LeaseProductMachine>()
|
||||
.in(LeaseProductMachine::getId, machineIds));
|
||||
//4.3 修改用户已购矿机表状态为 1 套餐已过期
|
||||
leaseUserOwnedProductService.update(LeaseUserOwnedProduct.builder().status(1).build(),new LambdaUpdateWrapper<LeaseUserOwnedProduct>()
|
||||
.in(LeaseUserOwnedProduct::getProductMachineId, machineIds));
|
||||
List<LeaseUserOwnedProduct> list = leaseUserOwnedProductService.list(new LambdaQueryWrapper<LeaseUserOwnedProduct>()
|
||||
.select(LeaseUserOwnedProduct::getId,LeaseUserOwnedProduct::getSettleIncome,LeaseUserOwnedProduct::getCurrentIncome).in(LeaseUserOwnedProduct::getProductMachineId, machineIds));
|
||||
List<LeaseUserOwnedProduct> collect = list.stream().map(item -> {
|
||||
item.setCurrentIncome(item.getSettleIncome());
|
||||
item.setSettleIncome(BigDecimal.ZERO);
|
||||
//item.setDel(true);
|
||||
item.setStatus(1);
|
||||
return item;
|
||||
}).collect(Collectors.toList());
|
||||
leaseUserOwnedProductService.updateBatchById(collect);
|
||||
|
||||
//4.4 矿机对应商品 销售量修改
|
||||
Map<Long, Long> productIdAndCountMap = expireProductList.stream().collect(Collectors.groupingBy(LeaseOrderItem::getProductId, Collectors.counting()));
|
||||
Set<Long> longs = productIdAndCountMap.keySet();
|
||||
List<LeaseProduct> leaseProducts = leaseProductService.list(new LambdaQueryWrapper<LeaseProduct>().in(LeaseProduct::getId, longs));
|
||||
leaseProducts.forEach(leaseProduct -> {
|
||||
leaseProduct.setSaleNumber(leaseProduct.getSaleNumber() - productIdAndCountMap.get(leaseProduct.getId()).intValue());
|
||||
});
|
||||
leaseProductService.updateBatchById(leaseProducts);
|
||||
//Map<Long, Long> productIdAndCountMap = expireProductList.stream().collect(Collectors.groupingBy(LeaseOrderItem::getProductId, Collectors.counting()));
|
||||
//Set<Long> longs = productIdAndCountMap.keySet();
|
||||
//List<LeaseProduct> leaseProducts = leaseProductService.list(new LambdaQueryWrapper<LeaseProduct>().in(LeaseProduct::getId, longs));
|
||||
//leaseProducts.forEach(leaseProduct -> {
|
||||
// leaseProduct.setSaleNumber(leaseProduct.getSaleNumber() - productIdAndCountMap.get(leaseProduct.getId()).intValue());
|
||||
//});
|
||||
//leaseProductService.updateBatchById(leaseProducts);
|
||||
|
||||
//4.5 找到详情表所有状态为0 租约已过期 ,并且订单info表订单状态为7 进行中的订单 并改为状态8 订单已完成 ; 并且发送支付消息
|
||||
List<Long> orderIds = orderInfoIdAndIsComplete.entrySet().stream()
|
||||
@@ -306,7 +362,7 @@ public class OrderAndPayTask {
|
||||
if(!orderIds.isEmpty()){
|
||||
//订单状态改为已完成
|
||||
leaseOrderInfoMapper.update(LeaseOrderInfo.builder().status(8).build(), new LambdaQueryWrapper<LeaseOrderInfo>().in(LeaseOrderInfo::getId, orderIds));
|
||||
// TODO 发送支付消息
|
||||
//发送支付消息
|
||||
sendMessageToMq(orderIds);
|
||||
}
|
||||
|
||||
@@ -318,38 +374,23 @@ public class OrderAndPayTask {
|
||||
if (!rabbitmqPayAutoMessages.isEmpty()){
|
||||
List<LeasePayRecordMessage> collect = new ArrayList<>();
|
||||
for (RabbitmqPayAutoMessage rabbitmqPayAutoMessage : rabbitmqPayAutoMessages) {
|
||||
List<LeasePayRecordMessage> list = new ArrayList<>();
|
||||
for (RabbitmqPayAutoInfoMessage transaction : rabbitmqPayAutoMessage.getTransactions().values()) {
|
||||
list.add(LeasePayRecordMessage.builder()
|
||||
.orderId(transaction.getOrder_id())
|
||||
.orderNumber(rabbitmqPayAutoMessage.getQueue_id())
|
||||
.queueId(rabbitmqPayAutoMessage.getQueue_id())
|
||||
.fromAddress(rabbitmqPayAutoMessage.getFrom_address())
|
||||
.toAddress(transaction.getTo_address())
|
||||
.amount(transaction.getNeedAmount())
|
||||
.realAmount(transaction.getAmount())
|
||||
.needAmount(transaction.getAmount())
|
||||
.fromChain(rabbitmqPayAutoMessage.getChain())
|
||||
.fromSymbol(rabbitmqPayAutoMessage.getSymbol())
|
||||
.blockAmount(transaction.getBlockAmount())
|
||||
.shopId(transaction.getShopId())
|
||||
.userId(transaction.getUserId())
|
||||
.toChain(rabbitmqPayAutoMessage.getChain())
|
||||
.toSymbol(rabbitmqPayAutoMessage.getSymbol())
|
||||
.build());
|
||||
}
|
||||
collect.addAll(list);
|
||||
//TODO 订单金额
|
||||
//try{
|
||||
// rabbitTemplate.convertAndSend(PAY_AUTO_QUEUE, rabbitmqPayAutoMessage);
|
||||
// System.out.println("支付消息发送成功:"+rabbitmqPayAutoMessage);
|
||||
//}catch (Exception e){
|
||||
// //一般出现在rabbitmq服务出现故障时出现,状态改为三,状态为三后续消息重试
|
||||
// list = list.stream().peek(item->item.setStatus(3)).collect(Collectors.toList());
|
||||
// System.out.println("消息发送失败:"+e.getMessage());
|
||||
//}finally {
|
||||
//
|
||||
//}
|
||||
collect.add( LeasePayRecordMessage.builder()
|
||||
.orderId(rabbitmqPayAutoMessage.getOrder_id())
|
||||
.orderNumber(rabbitmqPayAutoMessage.getQueue_id())
|
||||
.queueId(rabbitmqPayAutoMessage.getQueue_id())
|
||||
.fromAddress(rabbitmqPayAutoMessage.getFrom_address())
|
||||
.toAddress(rabbitmqPayAutoMessage.getTo_address())
|
||||
.amount(rabbitmqPayAutoMessage.getNeedAmount())
|
||||
.realAmount(rabbitmqPayAutoMessage.getAmount())
|
||||
.needAmount(rabbitmqPayAutoMessage.getAmount())
|
||||
.fromChain(rabbitmqPayAutoMessage.getChain())
|
||||
.fromSymbol(rabbitmqPayAutoMessage.getSymbol())
|
||||
.blockAmount(rabbitmqPayAutoMessage.getBlockAmount())
|
||||
.shopId(rabbitmqPayAutoMessage.getShopId())
|
||||
.userId(rabbitmqPayAutoMessage.getUserId())
|
||||
.toChain(rabbitmqPayAutoMessage.getChain())
|
||||
.toSymbol(rabbitmqPayAutoMessage.getSymbol())
|
||||
.build());
|
||||
}
|
||||
leasePayRecordMessageService.saveBatch(collect);
|
||||
}
|
||||
@@ -390,56 +431,114 @@ public class OrderAndPayTask {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单完成后---发送支付消息到mq
|
||||
* 订单完成后---发送支付消息到mq 一个买家对应一个卖家
|
||||
* @param orderIds
|
||||
*/
|
||||
public void sendMessageToMq(List<Long> orderIds){
|
||||
List<LeasePayRecordMessage> leasePayRecordMessages = leasePayRecordMessageMapper.selectList(new LambdaQueryWrapper<LeasePayRecordMessage>()
|
||||
.in(LeasePayRecordMessage::getOrderId, orderIds));
|
||||
Map<String, Map<String, List<LeasePayRecordMessage>>> collect = leasePayRecordMessages.stream()
|
||||
.collect(Collectors.groupingBy(LeasePayRecordMessage::getOrderId, Collectors.groupingBy(LeasePayRecordMessage::getToAddress)));
|
||||
//遍历按订单id分组后的map
|
||||
collect.forEach((orderId, payRecordMessagesMap) -> {
|
||||
List<LeaseOrderInfo> leaseOrderInfos = leaseOrderInfoMapper.selectList(new LambdaQueryWrapper<LeaseOrderInfo>()
|
||||
.select(LeaseOrderInfo::getFee,LeaseOrderInfo::getOrderNumber)
|
||||
.in(LeaseOrderInfo::getId, orderIds));
|
||||
Map<String, BigDecimal> feeMap = leaseOrderInfos.stream()
|
||||
.collect(Collectors.toMap(LeaseOrderInfo::getOrderNumber, LeaseOrderInfo::getFee));
|
||||
sendMessageToMq(leasePayRecordMessages,feeMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*订单完成后---发送支付消息到mq 一个买家对应一个卖家
|
||||
* @param leasePayRecordMessages
|
||||
* @param feeMap
|
||||
*/
|
||||
public void sendMessageToMq(List<LeasePayRecordMessage> leasePayRecordMessages,Map<String, BigDecimal> feeMap){
|
||||
Map<String, List<LeasePayRecordMessage>> collect = leasePayRecordMessages.stream()
|
||||
.collect(Collectors.groupingBy(LeasePayRecordMessage::getOrderId));
|
||||
//遍历按订单id分组后的map
|
||||
collect.forEach((orderId, payRecordMessagesList) -> {
|
||||
long timestamp = System.currentTimeMillis()/1000;
|
||||
List<LeasePayRecordMessage> orDefault = payRecordMessagesMap.getOrDefault(payRecordMessagesMap.keySet().iterator().next(), new ArrayList<>());
|
||||
LeasePayRecordMessage initForm = orDefault.get(0);
|
||||
LeasePayRecordMessage initForm = payRecordMessagesList.get(0);
|
||||
RabbitmqPayAutoMessage build = RabbitmqPayAutoMessage.builder()
|
||||
.queue_id(initForm.getQueueId())
|
||||
.from_address(initForm.getFromAddress())
|
||||
.chain(initForm.getFromChain())
|
||||
.symbol(initForm.getFromSymbol())
|
||||
.total_amount(BigDecimal.ZERO)
|
||||
.fee(feeMap.get(orderId))
|
||||
.from_address(initForm.getFromAddress())
|
||||
.to_address(initForm.getToAddress())
|
||||
.amount(BigDecimal.ZERO)
|
||||
.blockAmount(BigDecimal.ZERO)
|
||||
.needAmount(BigDecimal.ZERO)
|
||||
.timestamp(timestamp)
|
||||
.sign(HashUtils.sha256(timestamp))
|
||||
.build();
|
||||
|
||||
Map<String, RabbitmqPayAutoInfoMessage> transactions = new HashMap<>();
|
||||
//遍历按toAddress 分组后的map
|
||||
payRecordMessagesMap.forEach((toAddress,payRecordMessageList) -> {
|
||||
LeasePayRecordMessage init = payRecordMessageList.get(0);
|
||||
RabbitmqPayAutoInfoMessage sellInfo = RabbitmqPayAutoInfoMessage.builder()
|
||||
.to_address(init.getToAddress())
|
||||
.amount(BigDecimal.ZERO)
|
||||
.blockAmount(BigDecimal.ZERO)
|
||||
.needAmount(BigDecimal.ZERO)
|
||||
.shopId(init.getShopId())
|
||||
.userId(init.getUserId())
|
||||
.build();
|
||||
for (LeasePayRecordMessage leasePayRecordMessage : payRecordMessageList) {
|
||||
sellInfo.setAmount(sellInfo.getAmount().add(leasePayRecordMessage.getRealAmount()));
|
||||
sellInfo.setBlockAmount(sellInfo.getBlockAmount().add(leasePayRecordMessage.getBlockAmount()));
|
||||
sellInfo.setNeedAmount(sellInfo.getNeedAmount().add(leasePayRecordMessage.getNeedAmount()));
|
||||
}
|
||||
build.setTotal_amount(build.getTotal_amount().add(sellInfo.getAmount()));
|
||||
transactions.put(toAddress,sellInfo);
|
||||
});
|
||||
build.setTransactions(transactions);
|
||||
rabbitTemplate.convertAndSend(PAY_AUTO_QUEUE, build);
|
||||
for (LeasePayRecordMessage leasePayRecordMessage : payRecordMessagesList) {
|
||||
build.setAmount(build.getAmount().add(leasePayRecordMessage.getRealAmount()));
|
||||
build.setBlockAmount(build.getBlockAmount().add(leasePayRecordMessage.getBlockAmount()));
|
||||
build.setNeedAmount(build.getNeedAmount().add(leasePayRecordMessage.getNeedAmount()));
|
||||
}
|
||||
try {
|
||||
rabbitTemplate.convertAndSend(PAY_AUTO_QUEUE, build);
|
||||
}catch (Exception e){
|
||||
System.out.println("消息发送失败(5分)"+e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
///**
|
||||
// * 订单完成后---发送支付消息到mq 一个买家对应多个卖家
|
||||
// * @param orderIds
|
||||
// */
|
||||
//public void sendMessageToMq(List<Long> orderIds){
|
||||
// List<LeasePayRecordMessage> leasePayRecordMessages = leasePayRecordMessageMapper.selectList(new LambdaQueryWrapper<LeasePayRecordMessage>()
|
||||
// .in(LeasePayRecordMessage::getOrderId, orderIds));
|
||||
// Map<String, Map<String, List<LeasePayRecordMessage>>> collect = leasePayRecordMessages.stream()
|
||||
// .collect(Collectors.groupingBy(LeasePayRecordMessage::getOrderId, Collectors.groupingBy(LeasePayRecordMessage::getToAddress)));
|
||||
// //遍历按订单id分组后的map
|
||||
// collect.forEach((orderId, payRecordMessagesMap) -> {
|
||||
//
|
||||
// long timestamp = System.currentTimeMillis()/1000;
|
||||
// List<LeasePayRecordMessage> orDefault = payRecordMessagesMap.getOrDefault(payRecordMessagesMap.keySet().iterator().next(), new ArrayList<>());
|
||||
// LeasePayRecordMessage initForm = orDefault.get(0);
|
||||
// RabbitmqPayAutoMessage build = RabbitmqPayAutoMessage.builder()
|
||||
// .queue_id(initForm.getQueueId())
|
||||
// .from_address(initForm.getFromAddress())
|
||||
// .chain(initForm.getFromChain())
|
||||
// .symbol(initForm.getFromSymbol())
|
||||
// .total_amount(BigDecimal.ZERO)
|
||||
// .timestamp(timestamp)
|
||||
// .sign(HashUtils.sha256(timestamp))
|
||||
// .build();
|
||||
//
|
||||
//
|
||||
// Map<String, RabbitmqPayAutoInfoMessage> transactions = new HashMap<>();
|
||||
// //遍历按toAddress 分组后的map
|
||||
// payRecordMessagesMap.forEach((toAddress,payRecordMessageList) -> {
|
||||
// LeasePayRecordMessage init = payRecordMessageList.get(0);
|
||||
// RabbitmqPayAutoInfoMessage sellInfo = RabbitmqPayAutoInfoMessage.builder()
|
||||
// .to_address(init.getToAddress())
|
||||
// .amount(BigDecimal.ZERO)
|
||||
// .blockAmount(BigDecimal.ZERO)
|
||||
// .needAmount(BigDecimal.ZERO)
|
||||
// .shopId(init.getShopId())
|
||||
// .userId(init.getUserId())
|
||||
// .build();
|
||||
// for (LeasePayRecordMessage leasePayRecordMessage : payRecordMessageList) {
|
||||
// sellInfo.setAmount(sellInfo.getAmount().add(leasePayRecordMessage.getRealAmount()));
|
||||
// sellInfo.setBlockAmount(sellInfo.getBlockAmount().add(leasePayRecordMessage.getBlockAmount()));
|
||||
// sellInfo.setNeedAmount(sellInfo.getNeedAmount().add(leasePayRecordMessage.getNeedAmount()));
|
||||
// }
|
||||
// build.setTotal_amount(build.getTotal_amount().add(sellInfo.getAmount()));
|
||||
// transactions.put(toAddress,sellInfo);
|
||||
// });
|
||||
// build.setTransactions(transactions);
|
||||
// rabbitTemplate.convertAndSend(PAY_AUTO_QUEUE, build);
|
||||
// });
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* 一些校验失败的支付消息需要重新发送
|
||||
@@ -451,44 +550,11 @@ public class OrderAndPayTask {
|
||||
List<LeasePayRecordMessage> list = leasePayRecordMessageService.list(new LambdaQueryWrapper<LeasePayRecordMessage>()
|
||||
.eq(LeasePayRecordMessage::getStatus, 3)
|
||||
.ge(LeasePayRecordMessage::getCreateTime, LocalDateTime.now().minusHours(3)));
|
||||
System.out.println("开始重新发送支付消息"+ JSON.toJSONString(list));
|
||||
List<LeasePayRecordMessage> updateList = new ArrayList<>();
|
||||
Map<String, List<LeasePayRecordMessage>> collect = list.stream().collect(Collectors.groupingBy(LeasePayRecordMessage::getQueueId));
|
||||
collect.forEach((queueId, itemList)->{
|
||||
LeasePayRecordMessage item = itemList.get(0);
|
||||
long l = System.currentTimeMillis()/1000;
|
||||
RabbitmqPayAutoMessage build = RabbitmqPayAutoMessage.builder()
|
||||
.queue_id(item.getQueueId())
|
||||
.chain(item.getToChain())
|
||||
.symbol(item.getFromSymbol())
|
||||
.from_address(item.getFromAddress())
|
||||
.sign(HashUtils.sha256(l))
|
||||
.timestamp(l)
|
||||
.build();
|
||||
Map<String, RabbitmqPayAutoInfoMessage> payMap = itemList.stream()
|
||||
.map(orderInfo -> RabbitmqPayAutoInfoMessage.builder()
|
||||
.to_address(orderInfo.getToAddress())
|
||||
.amount(orderInfo.getAmount())
|
||||
.blockAmount(orderInfo.getBlockAmount())
|
||||
.shopId(orderInfo.getShopId())
|
||||
.userId(orderInfo.getUserId())
|
||||
.build())
|
||||
.collect(Collectors.toMap(RabbitmqPayAutoInfoMessage::getTo_address, Function.identity()));
|
||||
build.setTransactions(payMap);
|
||||
try {
|
||||
rabbitTemplate.convertAndSend(PAY_AUTO_QUEUE, build);
|
||||
List<LeasePayRecordMessage> updates = itemList.stream().peek(record -> record.setStatus(2)).collect(Collectors.toList());
|
||||
updateList.addAll(updates);
|
||||
}catch (Exception e){
|
||||
List<LeasePayRecordMessage> updates = itemList.stream().peek(record -> record.setStatus(3)).collect(Collectors.toList());
|
||||
updateList.addAll(updates);
|
||||
System.out.println("消息发送失败(5分)"+e.getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
if (!updateList.isEmpty()){
|
||||
leasePayRecordMessageService.updateBatchById(updateList);
|
||||
if (list.isEmpty()){
|
||||
return;
|
||||
}
|
||||
List<Long> orderIds = list.stream().map(leasePayRecordMessage-> Long.valueOf(leasePayRecordMessage.getOrderId())).distinct().collect(Collectors.toList());
|
||||
sendMessageToMq(orderIds);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -63,7 +64,7 @@ public class OwnProductTask {
|
||||
|
||||
private static final int THREAD_POOL_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
private static final int BATCH_SIZE = 1000;
|
||||
private final ExecutorService executorService = java.util.concurrent.Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
|
||||
/**
|
||||
* 修改已购表租约过期状态为1 已过期 + 机器表状态为0 未售出 + 修改租约到期订单状态为已完成
|
||||
*/
|
||||
@@ -137,9 +138,9 @@ public class OwnProductTask {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//开发
|
||||
//@Scheduled(cron = "0 35 0/1 * * ? ")
|
||||
@Scheduled(cron = "30 0/5 * * * ? ")
|
||||
@Scheduled(cron = "30 0/2 * * * ? ")
|
||||
@DSTransactional
|
||||
public void updateNexaIncomeTask(){
|
||||
List<LeaseUserOwnedProduct> updateList = computeIncome("nexa");
|
||||
@@ -149,7 +150,7 @@ public class OwnProductTask {
|
||||
}
|
||||
|
||||
//@Scheduled(cron = "10 35 0/1 * * ? ")
|
||||
@Scheduled(cron = "30 0/5 * * * ? ")
|
||||
@Scheduled(cron = "30 0/2 * * * ? ")
|
||||
@DSTransactional
|
||||
public void updateGrsIncomeTask(){
|
||||
List<LeaseUserOwnedProduct> updateList = computeIncome("grs");
|
||||
@@ -158,7 +159,7 @@ public class OwnProductTask {
|
||||
}
|
||||
|
||||
//@Scheduled(cron = "20 35 0/1 * * ? ")
|
||||
@Scheduled(cron = "30 0/5 * * * ? ")
|
||||
@Scheduled(cron = "30 0/2 * * * ? ")
|
||||
@DSTransactional
|
||||
public void updateRxdIncomeTask(){
|
||||
List<LeaseUserOwnedProduct> updateList = computeIncome("rxd");
|
||||
@@ -167,7 +168,7 @@ public class OwnProductTask {
|
||||
}
|
||||
|
||||
//@Scheduled(cron = "30 35 0/1 * * ? ")
|
||||
@Scheduled(cron = "30 0/5 * * * ? ")
|
||||
@Scheduled(cron = "30 0/2 * * * ? ")
|
||||
@DSTransactional
|
||||
public void updateMonaIncomeTask(){
|
||||
List<LeaseUserOwnedProduct> updateList = computeIncome("mona");
|
||||
@@ -184,7 +185,7 @@ public class OwnProductTask {
|
||||
//获取当前时间整点时间
|
||||
LocalDateTime now = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
|
||||
//获取当天开始时间
|
||||
LocalDateTime startOfDay = now.with(LocalTime.MIN);
|
||||
//LocalDateTime startOfDay = now.with(LocalTime.MIN);
|
||||
LocalDateTime end = now.minusHours(1);
|
||||
LocalDateTime start = now.minusHours(2);
|
||||
//1. 查询在有效期内的已购机器
|
||||
@@ -192,57 +193,93 @@ public class OwnProductTask {
|
||||
.eq(LeaseUserOwnedProduct::getCoin, coin)
|
||||
.eq(LeaseUserOwnedProduct::getStatus, 0);
|
||||
List<LeaseUserOwnedProduct> leaseUserOwnedProducts = leaseUserOwnedProductMapper.selectList(wrapper);
|
||||
System.out.println("个人收益--矿机: " + JSONUtil.toJsonPrettyStr(leaseUserOwnedProducts));
|
||||
|
||||
//2.获取近一个小时矿机的收益 + 并计算实时收益
|
||||
List<LeaseUserOwnedProduct> updateList = new ArrayList<>();
|
||||
if (!leaseUserOwnedProducts.isEmpty()){
|
||||
Map<String, LeaseUserOwnedProduct> collect = new HashMap<>();
|
||||
Set<Long> orderInfoIds = new HashSet<>();
|
||||
for (LeaseUserOwnedProduct item : leaseUserOwnedProducts) {
|
||||
collect.put(item.getUser() + "-" + item.getMiner() + "-" + item.getCoin(), item);
|
||||
orderInfoIds.add(item.getOrderId());
|
||||
}
|
||||
|
||||
//2.1 查询当天已支付订单
|
||||
//查询订单详情对应的信息formAddress + fromChain + fromSymbol + toAddress + toChain + toSymbol
|
||||
List<LeaseOrderItem> leaseOrderItems = leaseOrderItemMapper.getOrderItemByOrderIds(orderInfoIds);
|
||||
Map<String, LeaseOrderItem> collect1 = leaseOrderItems.stream().collect(Collectors.toMap(item -> item.getUser() + "-" + item.getMiner() + "-" + item.getCoin(), Function.identity()));
|
||||
|
||||
List<HourIncomeDto> incomeDtos = leaseUserOwnedProductMapper.getHourIncomeList(leaseUserOwnedProducts,coin, start, end);
|
||||
Map<String, LeaseUserOwnedProduct> collect = leaseUserOwnedProducts.stream()
|
||||
.collect(Collectors.toMap(item-> item.getUser() + "-" + item.getMiner()+ "-" + item.getCoin(),Function.identity()));
|
||||
for (HourIncomeDto hourIncomeDto : incomeDtos) {
|
||||
String key = hourIncomeDto.getUser() + "-" + hourIncomeDto.getMiner()+ "-" + coin;
|
||||
System.out.println("个人收益--矿机详情: " + key);
|
||||
LeaseUserOwnedProduct leaseUserOwnedProduct = collect.get(key) ;
|
||||
LeaseOrderItem leaseOrderItem = collect1.get(key);
|
||||
System.out.println("个人收益--订单详情: " + JSONUtil.toJsonPrettyStr(leaseOrderItem));
|
||||
if (leaseOrderItem != null && leaseOrderItem.getStatus() == 1){
|
||||
BigDecimal coinIncome = hourIncomeDto.getIncome().add(leaseUserOwnedProduct.getCurrentIncome());
|
||||
BigDecimal usdtIncome = hourIncomeDto.getUsdtIncome().add(leaseUserOwnedProduct.getCurrentUsdtIncome());
|
||||
//当日待结算收益不为0,把待结算收益加到当前收益中
|
||||
if (leaseUserOwnedProduct.getSettleIncome().compareTo(BigDecimal.ZERO) > 0){
|
||||
coinIncome = coinIncome.add(leaseUserOwnedProduct.getSettleIncome());
|
||||
usdtIncome = usdtIncome.add(leaseUserOwnedProduct.getSettleUsdtIncome());
|
||||
leaseUserOwnedProduct.setSettleIncome(BigDecimal.ZERO);
|
||||
leaseUserOwnedProduct.setSettleUsdtIncome(BigDecimal.ZERO);
|
||||
}
|
||||
leaseUserOwnedProduct.setCurrentIncome(coinIncome);
|
||||
leaseUserOwnedProduct.setCurrentUsdtIncome(usdtIncome);
|
||||
|
||||
}else{
|
||||
leaseUserOwnedProduct.setSettleIncome(hourIncomeDto.getIncome().add(leaseUserOwnedProduct.getSettleIncome()));
|
||||
leaseUserOwnedProduct.setSettleUsdtIncome(hourIncomeDto.getUsdtIncome().add(leaseUserOwnedProduct.getSettleUsdtIncome()));
|
||||
}
|
||||
if (now.equals(startOfDay)){
|
||||
leaseUserOwnedProduct.setSettleIncome(BigDecimal.ZERO);
|
||||
leaseUserOwnedProduct.setSettleUsdtIncome(BigDecimal.ZERO) ;
|
||||
}
|
||||
|
||||
updateList.add(leaseUserOwnedProduct);
|
||||
LeaseUserOwnedProduct leaseUserOwnedProduct = collect.get(key) ;
|
||||
leaseUserOwnedProduct.setSettleIncome(hourIncomeDto.getIncome().add(leaseUserOwnedProduct.getSettleIncome()));
|
||||
//leaseUserOwnedProduct.setSettleUsdtIncome(hourIncomeDto.getUsdtIncome().add(leaseUserOwnedProduct.getSettleUsdtIncome()));
|
||||
updateList.add(leaseUserOwnedProduct);
|
||||
}
|
||||
|
||||
}
|
||||
return updateList;
|
||||
}
|
||||
|
||||
|
||||
///**
|
||||
// * 计算已购生效机器过去一小时收益
|
||||
// * @param coin
|
||||
// */
|
||||
//public List<LeaseUserOwnedProduct> computeIncome(String coin){
|
||||
// //获取当前时间整点时间
|
||||
// LocalDateTime now = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
|
||||
// //获取当天开始时间
|
||||
// LocalDateTime startOfDay = now.with(LocalTime.MIN);
|
||||
// LocalDateTime end = now.minusHours(1);
|
||||
// LocalDateTime start = now.minusHours(2);
|
||||
// //1. 查询在有效期内的已购机器
|
||||
// LambdaQueryWrapper<LeaseUserOwnedProduct> wrapper = new LambdaQueryWrapper<LeaseUserOwnedProduct>()
|
||||
// .eq(LeaseUserOwnedProduct::getCoin, coin)
|
||||
// .eq(LeaseUserOwnedProduct::getStatus, 0);
|
||||
// List<LeaseUserOwnedProduct> leaseUserOwnedProducts = leaseUserOwnedProductMapper.selectList(wrapper);
|
||||
// System.out.println("个人收益--矿机: " + JSONUtil.toJsonPrettyStr(leaseUserOwnedProducts));
|
||||
// //2.获取近一个小时矿机的收益 + 并计算实时收益
|
||||
// List<LeaseUserOwnedProduct> updateList = new ArrayList<>();
|
||||
// if (!leaseUserOwnedProducts.isEmpty()){
|
||||
// Map<String, LeaseUserOwnedProduct> collect = new HashMap<>();
|
||||
// Set<Long> orderInfoIds = new HashSet<>();
|
||||
// for (LeaseUserOwnedProduct item : leaseUserOwnedProducts) {
|
||||
// collect.put(item.getUser() + "-" + item.getMiner() + "-" + item.getCoin(), item);
|
||||
// orderInfoIds.add(item.getOrderId());
|
||||
// }
|
||||
//
|
||||
// //2.1 查询当天已支付订单
|
||||
// //查询订单详情对应的信息formAddress + fromChain + fromSymbol + toAddress + toChain + toSymbol
|
||||
// List<LeaseOrderItem> leaseOrderItems = leaseOrderItemMapper.getOrderItemByOrderIds(orderInfoIds);
|
||||
// Map<String, LeaseOrderItem> collect1 = leaseOrderItems.stream().collect(Collectors.toMap(item -> item.getUser() + "-" + item.getMiner() + "-" + item.getCoin(), Function.identity()));
|
||||
//
|
||||
// List<HourIncomeDto> incomeDtos = leaseUserOwnedProductMapper.getHourIncomeList(leaseUserOwnedProducts,coin, start, end);
|
||||
// for (HourIncomeDto hourIncomeDto : incomeDtos) {
|
||||
// String key = hourIncomeDto.getUser() + "-" + hourIncomeDto.getMiner()+ "-" + coin;
|
||||
// System.out.println("个人收益--矿机详情: " + key);
|
||||
// LeaseUserOwnedProduct leaseUserOwnedProduct = collect.get(key) ;
|
||||
// LeaseOrderItem leaseOrderItem = collect1.get(key);
|
||||
// System.out.println("个人收益--订单详情: " + JSONUtil.toJsonPrettyStr(leaseOrderItem));
|
||||
// if (leaseOrderItem != null && leaseOrderItem.getStatus() == 1){
|
||||
// BigDecimal coinIncome = hourIncomeDto.getIncome().add(leaseUserOwnedProduct.getCurrentIncome());
|
||||
// BigDecimal usdtIncome = hourIncomeDto.getUsdtIncome().add(leaseUserOwnedProduct.getCurrentUsdtIncome());
|
||||
// //当日待结算收益不为0,把待结算收益加到当前收益中
|
||||
// if (leaseUserOwnedProduct.getSettleIncome().compareTo(BigDecimal.ZERO) > 0){
|
||||
// coinIncome = coinIncome.add(leaseUserOwnedProduct.getSettleIncome());
|
||||
// usdtIncome = usdtIncome.add(leaseUserOwnedProduct.getSettleUsdtIncome());
|
||||
// leaseUserOwnedProduct.setSettleIncome(BigDecimal.ZERO);
|
||||
// leaseUserOwnedProduct.setSettleUsdtIncome(BigDecimal.ZERO);
|
||||
// }
|
||||
// leaseUserOwnedProduct.setCurrentIncome(coinIncome);
|
||||
// leaseUserOwnedProduct.setCurrentUsdtIncome(usdtIncome);
|
||||
//
|
||||
// }else{
|
||||
// leaseUserOwnedProduct.setSettleIncome(hourIncomeDto.getIncome().add(leaseUserOwnedProduct.getSettleIncome()));
|
||||
// leaseUserOwnedProduct.setSettleUsdtIncome(hourIncomeDto.getUsdtIncome().add(leaseUserOwnedProduct.getSettleUsdtIncome()));
|
||||
// }
|
||||
// if (now.equals(startOfDay)){
|
||||
// leaseUserOwnedProduct.setSettleIncome(BigDecimal.ZERO);
|
||||
// leaseUserOwnedProduct.setSettleUsdtIncome(BigDecimal.ZERO) ;
|
||||
// }
|
||||
//
|
||||
// updateList.add(leaseUserOwnedProduct);
|
||||
// }
|
||||
// }
|
||||
// return updateList;
|
||||
//}
|
||||
|
||||
/**
|
||||
* 批量修改已购机器的收益
|
||||
* @param updateList
|
||||
@@ -258,7 +295,9 @@ public class OwnProductTask {
|
||||
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
leaseUserOwnedProductMapper.updateBatchIncome(subList);
|
||||
if (!subList.isEmpty()){
|
||||
leaseUserOwnedProductMapper.updateBatchIncome(subList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
exceptionRef.set(e);
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.time.LocalDateTime;
|
||||
* @author yyb
|
||||
* @since 2025-07-23
|
||||
*/
|
||||
@Builder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -30,23 +29,23 @@ public class ProductMachineVo extends PageVo{
|
||||
|
||||
|
||||
@ApiModelProperty(value = "最大实际算力")
|
||||
private BigDecimal maxPower;
|
||||
private BigDecimal maxPower = BigDecimal.ZERO;
|
||||
|
||||
@ApiModelProperty(value = "最小实际算力")
|
||||
private BigDecimal minPower;
|
||||
private BigDecimal minPower = BigDecimal.ZERO;
|
||||
|
||||
@ApiModelProperty(value = "最大功耗 单位kw/h",example = "10")
|
||||
private BigDecimal maxPowerDissipation;
|
||||
private BigDecimal maxPowerDissipation = BigDecimal.ZERO;
|
||||
|
||||
@ApiModelProperty(value = "最小功耗 单位kw/h",example = "10")
|
||||
private BigDecimal minPowerDissipation;
|
||||
private BigDecimal minPowerDissipation = BigDecimal.ZERO;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "最大单价")
|
||||
private BigDecimal maxPrice;
|
||||
private BigDecimal maxPrice = BigDecimal.ZERO;
|
||||
|
||||
@ApiModelProperty(value = "最小单价")
|
||||
private BigDecimal minPrice;
|
||||
private BigDecimal minPrice = BigDecimal.ZERO;
|
||||
|
||||
@ApiModelProperty(value = "币种")
|
||||
private String coin;
|
||||
@@ -63,5 +62,8 @@ public class ProductMachineVo extends PageVo{
|
||||
@ApiModelProperty(value = "功耗排序方式 true:降序 false:升序")
|
||||
private Boolean powerDissipationSort;
|
||||
|
||||
@ApiModelProperty(value = "币种单位")
|
||||
private String unit;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ from lease_pay_recharge_message
|
||||
(address = #{item.fromAddress} AND `chain` = #{item.fromChain} AND symbol = #{item.fromSymbol})
|
||||
</foreach>)
|
||||
</where>
|
||||
order by update_time desc
|
||||
order by create_time desc
|
||||
</select>
|
||||
<select id="getRecentlyTransaction" resultType="com.m2pool.lease.dto.RecentlyTransactionDto">
|
||||
select
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
(from_address = #{item.fromAddress} AND `from_chain` = #{item.fromChain} AND from_symbol = #{item.fromSymbol})
|
||||
</foreach>)
|
||||
</where>
|
||||
order by update_time desc
|
||||
order by create_time desc
|
||||
</select>
|
||||
<select id="getRecentlyTransaction" resultType="com.m2pool.lease.dto.RecentlyTransactionDto">
|
||||
select
|
||||
|
||||
@@ -88,7 +88,7 @@ FROM lease_pay_withdraw_message
|
||||
AND from_symbol = #{item.fromSymbol})
|
||||
</foreach>)
|
||||
</where>
|
||||
order by update_time desc
|
||||
order by create_time desc
|
||||
</select>
|
||||
<select id="getRecentlyTransaction" resultType="com.m2pool.lease.dto.RecentlyTransactionDto">
|
||||
select
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
FROM
|
||||
lease_product_machine_price
|
||||
WHERE
|
||||
product_machine_id IN
|
||||
del = false and product_machine_id IN
|
||||
<foreach item="id" collection="list" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
@@ -237,31 +237,22 @@ WHERE
|
||||
FROM
|
||||
lease_product_machine pm
|
||||
LEFT JOIN lease_product_machine_price pmp
|
||||
ON pm.id = pmp.product_machine_id AND pmp.coin = #{productMachineVo.coin} AND pmp.chain = #{productMachineVo.chain}
|
||||
ON pm.id = pmp.product_machine_id AND pmp.coin = #{productMachineVo.coin} AND pmp.chain = #{productMachineVo.chain} AND pmp.del = false
|
||||
LEFT JOIN ${coin}_real_power rp
|
||||
ON pm.user = rp.user AND rp.miner = pm.miner
|
||||
WHERE
|
||||
pm.del = false AND pm.`state` = 0 AND pm.product_id = #{productMachineVo.id}
|
||||
<!-- 实际算力范围筛选 -->
|
||||
<if test="productMachineVo.minPower != null">
|
||||
AND rp.power >= #{productMachineVo.minPower}
|
||||
</if>
|
||||
<if test="productMachineVo.maxPower != null">
|
||||
AND rp.power <![CDATA[<=]]> #{productMachineVo.maxPower}
|
||||
<if test="productMachineVo.minPower != 0 or productMachineVo.maxPower != 0">
|
||||
AND rp.power >= #{productMachineVo.minPower} AND rp.power <![CDATA[<=]]> #{productMachineVo.maxPower}
|
||||
</if>
|
||||
<!-- 功耗范围筛选 -->
|
||||
<if test="productMachineVo.minPowerDissipation != null">
|
||||
AND power_dissipation >= #{productMachineVo.minPowerDissipation}
|
||||
</if>
|
||||
<if test="productMachineVo.maxPowerDissipation != null">
|
||||
AND power_dissipation <![CDATA[<=]]> #{productMachineVo.maxPowerDissipation}
|
||||
<if test="productMachineVo.minPowerDissipation != 0 or productMachineVo.maxPowerDissipation != 0">
|
||||
AND power_dissipation >= #{productMachineVo.minPowerDissipation} AND power_dissipation <![CDATA[<=]]> #{productMachineVo.maxPowerDissipation}
|
||||
</if>
|
||||
<!-- 单价范围筛选 -->
|
||||
<if test="productMachineVo.minPrice != null">
|
||||
AND pmp.price >= #{productMachineVo.minPrice}
|
||||
</if>
|
||||
<if test="productMachineVo.maxPrice != null">
|
||||
AND pmp.price <![CDATA[<=]]> #{productMachineVo.maxPrice}
|
||||
<if test="productMachineVo.minPrice != 0 or productMachineVo.maxPrice != 0">
|
||||
AND pmp.price >= #{productMachineVo.minPrice} AND pmp.price <![CDATA[<=]]> #{productMachineVo.maxPrice}
|
||||
</if>
|
||||
<!-- <if test="productMachineVo.priceSort != null">-->
|
||||
<!-- ORDER BY-->
|
||||
@@ -300,4 +291,13 @@ WHERE
|
||||
<!-- </choose>-->
|
||||
<!-- </if>-->
|
||||
</select>
|
||||
<select id="getIdsForShopId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
lease_product_machine
|
||||
WHERE
|
||||
shop_id = #{shopId}
|
||||
and `del` = 0
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
from lease_product_machine_price
|
||||
where
|
||||
<foreach collection="list" item="item" separator="OR">
|
||||
(`product_machine_id` = #{item})
|
||||
(`product_machine_id` = #{item} AND del = false)
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getPriceByOrderItems" resultType="java.util.Map">
|
||||
|
||||
@@ -64,11 +64,11 @@
|
||||
FROM
|
||||
lease_product
|
||||
WHERE
|
||||
product_id IN
|
||||
id IN
|
||||
<foreach collection="productIds" item="productId" open="(" separator="," close=")">
|
||||
#{productId}
|
||||
</foreach>
|
||||
and del = 0
|
||||
|
||||
</select>
|
||||
<select id="getShopNameMapByIds" resultType="com.m2pool.lease.entity.LeaseShop">
|
||||
SELECT
|
||||
|
||||
@@ -95,19 +95,15 @@
|
||||
WHERE sub.rn = 1;
|
||||
</select>
|
||||
<update id="updateBatchIncome">
|
||||
UPDATE lease_user_owned_product
|
||||
SET
|
||||
current_income =
|
||||
<foreach collection="list" item="item" open="CASE id" separator="" close="END">
|
||||
WHEN #{item.id} THEN #{item.currentIncome}
|
||||
</foreach>,
|
||||
current_usdt_income =
|
||||
<foreach collection="list" item="item" open="CASE id" separator="" close="END">
|
||||
WHEN #{item.id} THEN #{item.currentUsdtIncome}
|
||||
</foreach>
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||
#{item.id}
|
||||
INSERT INTO lease_user_owned_product (id, settle_income, settle_usdt_income,start_time, end_time)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator="," open="(" close=")">
|
||||
#{item.id}, #{item.settleIncome}, #{item.settleUsdtIncome}, #{item.startTime}, #{item.endTime}
|
||||
</foreach>
|
||||
ON DUPLICATE KEY UPDATE
|
||||
settle_income = VALUES(settle_income),
|
||||
settle_usdt_income = VALUES(settle_usdt_income),
|
||||
start_time = VALUES(start_time),
|
||||
end_time = VALUES(end_time)
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
@@ -92,20 +92,11 @@
|
||||
<select id="selectWalletByChainAndCoinAndUsername" resultType="com.m2pool.lease.entity.LeaseUserWalletData">
|
||||
SELECT
|
||||
id,
|
||||
-- user_id as userId,
|
||||
from_address as fromAddress,
|
||||
balance,
|
||||
blocked_balance as blockedBalance,
|
||||
|
||||
from_symbol as fromSymbol,
|
||||
from_chain as fromChain
|
||||
-- qrcode,
|
||||
-- to_address as toAddress,
|
||||
-- to_symbol as toSymbol,
|
||||
-- to_chain as toChain,
|
||||
-- create_time as createTime,
|
||||
-- queue_id as queueId
|
||||
|
||||
FROM lease_user_wallet_data
|
||||
WHERE del = 0 AND user_id = #{username} AND (
|
||||
<foreach collection="list" item="item" separator="OR">
|
||||
|
||||
Reference in New Issue
Block a user