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