fix: 优化收益计算、地址校验和提现逻辑
- 修正收益计算将月收益改为日收益,格式化显示为'(币种)' - 统一NEXA地址校验规则,必须带'nexa:'前缀 - 修复提现金额计算逻辑,改为从余额中减去提现金额和手续费 - 优化SQL查询,使用ROW_NUMBER替代变量排序 - 添加用户权限校验,算力保留两位小数并添加单位字段 - 添加空字符串校验和调试日志输出 - 启用提现队列监听功能
This commit is contained in:
@@ -6,6 +6,7 @@ import cn.hutool.json.JSONUtil;
|
||||
import com.m2pool.lease.annotation.EncryptedField;
|
||||
import com.m2pool.lease.exception.RSAException;
|
||||
import com.m2pool.lease.utils.RsaUtils;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
@@ -13,6 +14,7 @@ import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Parameter;
|
||||
@@ -84,6 +86,9 @@ public class DecryptAspect {
|
||||
Object value = field.get(obj);
|
||||
if (value != null) {
|
||||
String encryptedValue = value.toString();
|
||||
if(StringUtils.isEmpty(encryptedValue)){
|
||||
return;
|
||||
}
|
||||
System.out.println("加密前地址:"+value +"类型"+(value instanceof String));
|
||||
String decryptedValue = RsaUtils.decrypt(encryptedValue);
|
||||
field.set(obj, decryptedValue);
|
||||
|
||||
@@ -70,7 +70,7 @@ public class OperationLogAspect {
|
||||
Field field = tagFields.poll();
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
if (!tagFields.isEmpty() || tag.length() > 0) { // 如果不是第一个元素或者address不为空,才加"--"
|
||||
if ( tag.length() > 0) { // 如果不是第一个元素或者address不为空,才加"--"
|
||||
tag.append("--");
|
||||
}
|
||||
tag.append((String) field.get(arg));
|
||||
@@ -85,8 +85,9 @@ public class OperationLogAspect {
|
||||
getExtraLogParam(ledgerLog);
|
||||
//文件追加用户邮箱和用户id(文件名格式:地址--邮箱--用户id)
|
||||
String username = SecurityUtils.getUsername();
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (username != null){
|
||||
tag.append("--").append(username).append("--").append(SecurityUtils.getUserId());
|
||||
tag.append("--").append(username).append("--").append(userId);
|
||||
}
|
||||
// 记录日志
|
||||
ledgerLogService.logOperation(tag.toString(), annotation.value(), ledgerLog.toString());
|
||||
|
||||
@@ -71,6 +71,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
String userEmail = JwtUtils.getUserName(token);
|
||||
String getUserId = JwtUtils.getUserId(token);
|
||||
System.out.println("本地线程:用户ID"+getUserId + "用户邮箱"+userEmail);
|
||||
//1.把userEmail存入ThreadLocal 本地线程变量中
|
||||
SecurityUtils.setUserEmail(userEmail);
|
||||
SecurityUtils.setUserId(Long.valueOf(getUserId));
|
||||
|
||||
@@ -93,7 +93,7 @@ public class PageResult<T> implements Serializable
|
||||
|
||||
columns.add(TableHeadersDto.builder()
|
||||
.key("monthIncome")
|
||||
.label("最大月收益")
|
||||
.label("最大日收益")
|
||||
.type("amount")
|
||||
.currency("USDT")
|
||||
.period("MONTH")
|
||||
|
||||
@@ -49,7 +49,7 @@ public class MachineInfoDto {
|
||||
private Integer maxLeaseDays;
|
||||
|
||||
@ApiModelProperty(value = "最大月收益 usdt")
|
||||
private BigDecimal monthIncome;
|
||||
private String monthIncome;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "最大收益币种算法")
|
||||
|
||||
@@ -33,4 +33,7 @@ public class MiningHashrateInfoDto {
|
||||
|
||||
@ApiModelProperty(value = "矿工号")
|
||||
private String miner;
|
||||
|
||||
@ApiModelProperty(value = "算力单位")
|
||||
private String unit;
|
||||
}
|
||||
|
||||
@@ -53,4 +53,7 @@ public class PurchasedMachineDto {
|
||||
@ApiModelProperty(value = "最近实时算力记录时间")
|
||||
private LocalDateTime recordTime;
|
||||
|
||||
@ApiModelProperty(value = "币种单位")
|
||||
private String unit;
|
||||
|
||||
}
|
||||
|
||||
@@ -94,5 +94,5 @@ public interface LeaseOrderMiningMapper extends BaseMapper<LeaseOrderMining> {
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
List<PurchasedMachineDto> getPurchasedMachineInfo(@Param("info") MiningConfigInfoDto info);
|
||||
List<PurchasedMachineDto> getPurchasedMachineInfo(@Param("info") MiningConfigInfoDto info,@Param("authId") Long authId);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,9 @@ import com.m2pool.lease.constant.RabbitmqConstant;
|
||||
import com.m2pool.lease.entity.*;
|
||||
import com.m2pool.lease.exception.PayRechargeException;
|
||||
import com.m2pool.lease.mapper.*;
|
||||
import com.m2pool.lease.mq.message.RabbitmqDeleteWalletReturnMessage;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayAutoReturnMessage;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayRechargeReturnMessage;
|
||||
import com.m2pool.lease.mq.message.RabbitmqPayWithdrawReturnMessage;
|
||||
import com.m2pool.lease.mq.message.*;
|
||||
import com.m2pool.lease.service.LeaseOrderItemService;
|
||||
import com.m2pool.lease.utils.UuidGeneratorUtil;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
@@ -341,6 +339,7 @@ public class MessageReceiver {
|
||||
LeasePayWithdrawMessage leasePayWithdrawMessage = handlerBuyerWithdraw(payWithdrawReturnMessage, leasePayWithdrawMessageList);
|
||||
if (leasePayWithdrawMessage != null){
|
||||
LeaseShopConfig leaseShopConfig = leaseShopConfigMapper.selectOne(new LambdaQueryWrapper<LeaseShopConfig>()
|
||||
.select(LeaseShopConfig::getId, LeaseShopConfig::getBalance)
|
||||
.eq(LeaseShopConfig::getPayAddress, leasePayWithdrawMessage.getFromAddress())
|
||||
.eq(LeaseShopConfig::getChain, leasePayWithdrawMessage.getFromChain())
|
||||
.eq(LeaseShopConfig::getPayCoin, leasePayWithdrawMessage.getFromSymbol())
|
||||
@@ -350,18 +349,20 @@ public class MessageReceiver {
|
||||
if (leasePayWithdrawMessage.getStatus() == 1 && payWithdrawReturnMessage.getStatus() == 1){
|
||||
return;
|
||||
}
|
||||
if (payWithdrawReturnMessage.getStatus() == 1){
|
||||
leaseShopConfig.setBalance(leaseShopConfig.getBalance()
|
||||
.add(leasePayWithdrawMessage.getAmount())
|
||||
.add(leasePayWithdrawMessage.getServiceCharge()));
|
||||
leaseShopConfigMapper.updateById(leaseShopConfig);
|
||||
}
|
||||
leasePayWithdrawMessageMapper.updateById(LeasePayWithdrawMessage.builder()
|
||||
|
||||
LeasePayWithdrawMessage build = LeasePayWithdrawMessage.builder()
|
||||
.id(leasePayWithdrawMessage.getId())
|
||||
.status(payWithdrawReturnMessage.getStatus())
|
||||
.txHash(payWithdrawReturnMessage.getTx_hash())
|
||||
.blockHeight(payWithdrawReturnMessage.getBlock_height())
|
||||
.build());
|
||||
.build();
|
||||
if (payWithdrawReturnMessage.getStatus() == 1){
|
||||
leaseShopConfig.setBalance(leaseShopConfig.getBalance()
|
||||
.subtract(payWithdrawReturnMessage.getAmount())
|
||||
.subtract(payWithdrawReturnMessage.getFee()));
|
||||
leaseShopConfigMapper.updateById(leaseShopConfig);
|
||||
build.setTxHash(payWithdrawReturnMessage.getTx_hash());
|
||||
build.setBlockHeight(payWithdrawReturnMessage.getBlock_height());
|
||||
}
|
||||
leasePayWithdrawMessageMapper.updateById(build);
|
||||
//TODO 修改leaseShopConfig 金额(暂时不修改,提现申请的时候就修改了)
|
||||
}
|
||||
}
|
||||
@@ -580,22 +581,22 @@ public class MessageReceiver {
|
||||
|
||||
|
||||
//提现
|
||||
//@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())
|
||||
// .from_address(payAutoReturnMessage.getFrom_address())
|
||||
// .tx_hash(UuidGeneratorUtil.generateUuidWithoutHyphen())
|
||||
// .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())
|
||||
.from_address(payAutoReturnMessage.getFrom_address())
|
||||
.tx_hash(UuidGeneratorUtil.generateUuidWithoutHyphen())
|
||||
.fee(payAutoReturnMessage.getFee())
|
||||
.build();
|
||||
rabbitTemplate.convertAndSend(RabbitmqConstant.PAY_WITHDRAW_RETURN_QUEUE,rabbitmqPayRechargeReturnMessage);
|
||||
}
|
||||
|
||||
|
||||
////测试 开发环境 删除钱包测试
|
||||
|
||||
@@ -440,9 +440,10 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ClientMess
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
String ip = getIPString(ctx);
|
||||
System.out.println("tcp心跳:"+ ip);
|
||||
String id = ChannelManager.getIdByChannel(ip);
|
||||
if (event.state() == IdleState.READER_IDLE) {
|
||||
System.out.println(id+"用户写超时,接受pong"+System.currentTimeMillis());
|
||||
System.out.println(id+"用户读超时,接受pong"+System.currentTimeMillis());
|
||||
//System.out.println(id+"用户读超时,断开连接");
|
||||
ChannelManager.removeChannel(ip);
|
||||
ctx.disconnect();//断开
|
||||
|
||||
@@ -128,6 +128,7 @@ public class LeaseMachineServiceImpl extends ServiceImpl<LeaseMachineMapper, Lea
|
||||
.collect(Collectors.groupingBy(PowerIncomeInfoDto::getMachineId));
|
||||
for (MachineInfoDto machineInfo : machineInfoDtoList) {
|
||||
machineInfo.setPriceList(machinePriceMap.get(machineInfo.getId()));
|
||||
machineInfo.setMonthIncome("$"+machineInfo.getMonthIncome()+"("+machineInfo.getCoin()+")");
|
||||
List<PowerIncomeInfoDto> powerIncomeInfoDtoList = collect.get(machineInfo.getId());
|
||||
for (int i = 0; i < powerIncomeInfoDtoList.size(); i++) {
|
||||
PowerIncomeInfoDto powerIncomeInfoDto = powerIncomeInfoDtoList.get(i);
|
||||
|
||||
@@ -1022,9 +1022,6 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
for (OrderMiningInfoDto addressInfo : orderMiningInfoDtoList) {
|
||||
String coin = addressInfo.getCoin();
|
||||
String walletAddress = addressInfo.getWalletAddress();
|
||||
if(coin.equalsIgnoreCase("NEXA") && walletAddress.startsWith("nexa:")){
|
||||
addressInfo.setWalletAddress(walletAddress.substring(5));
|
||||
}
|
||||
if (!WalletRuleCheckUtils.checkAddress(coin,walletAddress)){
|
||||
addressVerify = addressInfo.getWalletAddress() + "钱包地址格式错误";
|
||||
break;
|
||||
@@ -1140,9 +1137,11 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
@Override
|
||||
@DSTransactional
|
||||
public Result<MiningConfigInfoDto> getPurchasedInfo(BaseVo baseVo) {
|
||||
Long authId = SecurityUtils.getUserId();
|
||||
|
||||
//找到miner 和钱包 ,pool 矿池名
|
||||
MiningConfigInfoDto info = leaseOrderMiningMapper.getPurchasedInfo(baseVo.getId());
|
||||
List<PurchasedMachineDto> list = leaseOrderMiningMapper.getPurchasedMachineInfo(info);
|
||||
List<PurchasedMachineDto> list = leaseOrderMiningMapper.getPurchasedMachineInfo(info,authId);
|
||||
|
||||
|
||||
//根据钱包 + 币种 + 矿工号 查询 pool 库 pool.kryptex 表 中对应 算力
|
||||
@@ -1153,7 +1152,8 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
MiningHashrateInfoDto miningHashrateInfoDto = recentlyHashRateMap.get(purchasedMachineDto.getWorkerId());
|
||||
if (miningHashrateInfoDto != null){
|
||||
purchasedMachineDto.setRecordTime(miningHashrateInfoDto.getRecordTime());
|
||||
purchasedMachineDto.setPower(miningHashrateInfoDto.getPower());
|
||||
purchasedMachineDto.setPower(miningHashrateInfoDto.getPower().setScale(2, RoundingMode.HALF_UP));
|
||||
purchasedMachineDto.setUnit(miningHashrateInfoDto.getUnit());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class GpuRequestApiTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算月收入
|
||||
* 计算月收入(月收益现在改成日收益)
|
||||
* @param leaseGpuConfig
|
||||
* @param coinPower
|
||||
* @return
|
||||
@@ -89,7 +89,8 @@ public class GpuRequestApiTask {
|
||||
.divide(coinPower.getHashrate().divide(BigDecimal.valueOf(1000 * 1000), 8, RoundingMode.HALF_UP), 8, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(24 * 60 * 60)
|
||||
.divide(coinPower.getBlockInterval(), 8, RoundingMode.HALF_UP))
|
||||
.multiply(coinPower.getBlockReward()).multiply(BigDecimal.valueOf(30))
|
||||
.multiply(coinPower.getBlockReward())
|
||||
//.multiply(BigDecimal.valueOf(30))
|
||||
.multiply(coinPower.getPrice())
|
||||
;
|
||||
}
|
||||
|
||||
@@ -152,11 +152,12 @@ public class WalletRuleCheckUtils {
|
||||
private static final Pattern NEXA_PATTERN = Pattern.compile("^nexa:[0-9a-zA-Z]{48}$");
|
||||
private static final Pattern NEXA_PATTERN2 = Pattern.compile("^[0-9a-zA-Z]{48}$");
|
||||
public static boolean checkNEXA(String address) {
|
||||
if (address.startsWith("nexa:")){
|
||||
return StringUtils.isNotEmpty(address) && NEXA_PATTERN.matcher(address).matches();
|
||||
}else{
|
||||
return StringUtils.isNotEmpty(address) && NEXA_PATTERN2.matcher(address).matches();
|
||||
}
|
||||
//if (address.startsWith("nexa:")){
|
||||
// return StringUtils.isNotEmpty(address) && NEXA_PATTERN.matcher(address).matches();
|
||||
//}else{
|
||||
// return StringUtils.isNotEmpty(address) && NEXA_PATTERN2.matcher(address).matches();
|
||||
//}
|
||||
return StringUtils.isNotEmpty(address) && NEXA_PATTERN.matcher(address).matches();
|
||||
}
|
||||
|
||||
// ---------------XNA校验-------------------
|
||||
|
||||
Reference in New Issue
Block a user