mirror of https://gitee.com/y_project/RuoYi.git
监控对方交易笔数改为对方能量使用数取整计算
parent
5a6d5f0d2f
commit
0cb2018931
|
@ -147,7 +147,7 @@
|
||||||
</plugin> -->
|
</plugin> -->
|
||||||
</plugins>
|
</plugins>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<resources>
|
<!-- <resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<excludes>
|
<excludes>
|
||||||
|
@ -155,7 +155,7 @@
|
||||||
<exclude>*.xml</exclude>
|
<exclude>*.xml</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>-->
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,19 @@ import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.domain.vo.TronInfoVO;
|
import com.ruoyi.system.domain.vo.TronInfoVO;
|
||||||
import com.ruoyi.system.service.IApiService;
|
import com.ruoyi.system.service.IApiService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
|
@CrossOrigin
|
||||||
public class ApiController {
|
public class ApiController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IApiService apiService;
|
private IApiService apiService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取波场数据
|
* 获取波场数据
|
||||||
* @return
|
* @return
|
||||||
|
@ -23,4 +26,6 @@ public class ApiController {
|
||||||
TronInfoVO tronInfoVO = apiService.getTronInfo();
|
TronInfoVO tronInfoVO = apiService.getTronInfo();
|
||||||
return R.ok(tronInfoVO);
|
return R.ok(tronInfoVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.ruoyi.system.api;
|
package com.ruoyi.system.api;
|
||||||
|
|
||||||
|
import com.ruoyi.system.dto.AccountResourceResponse;
|
||||||
import com.ruoyi.system.dto.TronGridResponse;
|
import com.ruoyi.system.dto.TronGridResponse;
|
||||||
|
|
||||||
public interface ITronApi {
|
public interface ITronApi {
|
||||||
|
|
||||||
TronGridResponse getTronGridTrc20Response(String monitorAddress, boolean only_to,boolean only_from,String apiKey, Long min_timestamp);
|
TronGridResponse getTronGridTrc20Response(String monitorAddress, boolean only_to,boolean only_from,String apiKey, Long min_timestamp);
|
||||||
|
|
||||||
|
AccountResourceResponse getAccountResource(String address, String apiKey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.ruoyi.system.api.impl;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.ruoyi.common.utils.http.RestTemplateUtils;
|
import com.ruoyi.common.utils.http.RestTemplateUtils;
|
||||||
import com.ruoyi.system.api.ITronApi;
|
import com.ruoyi.system.api.ITronApi;
|
||||||
|
import com.ruoyi.system.dto.AccountResourceResponse;
|
||||||
import com.ruoyi.system.dto.TronGridResponse;
|
import com.ruoyi.system.dto.TronGridResponse;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -13,6 +14,9 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TronApiImpl implements ITronApi {
|
public class TronApiImpl implements ITronApi {
|
||||||
|
@ -21,7 +25,7 @@ public class TronApiImpl implements ITronApi {
|
||||||
private ISysConfigService configService;
|
private ISysConfigService configService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TronGridResponse getTronGridTrc20Response(String monitorAddress, boolean only_to,boolean only_from, String apiKey,Long min_timestamp) {
|
public TronGridResponse getTronGridTrc20Response(String monitorAddress, boolean only_to, boolean only_from, String apiKey, Long min_timestamp) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.add("TRON-PRO-API-KEY", apiKey);
|
headers.add("TRON-PRO-API-KEY", apiKey);
|
||||||
//监听
|
//监听
|
||||||
|
@ -48,6 +52,36 @@ public class TronApiImpl implements ITronApi {
|
||||||
return tronGridResponse;
|
return tronGridResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccountResourceResponse getAccountResource(String address, String apiKey) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("TRON-PRO-API-KEY", apiKey);
|
||||||
|
|
||||||
|
Map<String, Object> uriVariables = new HashMap<>();
|
||||||
|
uriVariables.put("address", address);
|
||||||
|
uriVariables.put("visible", true);
|
||||||
|
String jsonStr = JSONUtil.toJsonStr(uriVariables);
|
||||||
|
|
||||||
|
// ResponseEntity<AccountResourceResponse> responseEntity = RestTemplateUtils.post("https://api.trongrid.io/wallet/getaccountresource", headers, jsonStr, AccountResourceResponse.class);
|
||||||
|
ResponseEntity responseEntity = RestTemplateUtils.post("https://api.trongrid.io/wallet/getaccountresource", headers, jsonStr, String.class);
|
||||||
|
|
||||||
|
// Object body = responseEntity1.getBody();
|
||||||
|
// log.info("body:{}", body);
|
||||||
|
// if (checkResponseBodyIsOk(responseEntity, address)) return null;
|
||||||
|
//
|
||||||
|
// AccountResourceResponse accountResourceResponse = responseEntity.getBody();
|
||||||
|
|
||||||
|
Object responseEntityBody = getResponseEntityBody(responseEntity,address);
|
||||||
|
if (responseEntityBody == null) return null;
|
||||||
|
|
||||||
|
AccountResourceResponse accountResourceResponse = JSONUtil.toBean((String) responseEntityBody, AccountResourceResponse.class);
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.info("{}responseEntityBody:{}", address, JSONUtil.toJsonStr(accountResourceResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountResourceResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取响应体
|
* 获取响应体
|
||||||
|
@ -57,15 +91,7 @@ public class TronApiImpl implements ITronApi {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static Object getResponseEntityBody(ResponseEntity responseEntity, String address) {
|
private static Object getResponseEntityBody(ResponseEntity responseEntity, String address) {
|
||||||
if (responseEntity == null) {
|
if (checkResponseBodyIsOk(responseEntity, address)) return null;
|
||||||
log.warn("{}:responseEntity is null", address);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
HttpStatus statusCode = responseEntity.getStatusCode();
|
|
||||||
if (statusCode != HttpStatus.OK) {
|
|
||||||
log.error("获取trx交易信息失败:{}", address);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Object responseEntityBody = responseEntity.getBody();
|
Object responseEntityBody = responseEntity.getBody();
|
||||||
if (responseEntityBody == null) {
|
if (responseEntityBody == null) {
|
||||||
log.warn("{}:responseEntityBody is null", address);
|
log.warn("{}:responseEntityBody is null", address);
|
||||||
|
@ -73,4 +99,17 @@ public class TronApiImpl implements ITronApi {
|
||||||
}
|
}
|
||||||
return responseEntityBody;
|
return responseEntityBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean checkResponseBodyIsOk(ResponseEntity responseEntity, String address) {
|
||||||
|
if (responseEntity == null) {
|
||||||
|
log.warn("{}:responseEntity is null", address);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
HttpStatus statusCode = responseEntity.getStatusCode();
|
||||||
|
if (statusCode != HttpStatus.OK) {
|
||||||
|
log.error("获取trx交易信息失败:{}", address);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,12 @@ import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
|
|
||||||
//@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TgLongPollingBot extends TelegramLongPollingBot {
|
public class TgLongPollingBot extends TelegramLongPollingBot {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ruoyi.system.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AccountResourceResponse implements Serializable {
|
||||||
|
|
||||||
|
private static final Long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer freeNetUsed;
|
||||||
|
private Integer freeNetLimit;
|
||||||
|
private List<AssetNetUsed> assetNetUsed;
|
||||||
|
private List<AssetNetLimit> assetNetLimit;
|
||||||
|
private Long TotalNetLimit;
|
||||||
|
private Long TotalNetWeight;
|
||||||
|
private Integer EnergyUsed;
|
||||||
|
private Long EnergyLimit;
|
||||||
|
private Long TotalEnergyLimit;
|
||||||
|
private Long TotalEnergyWeight;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.ruoyi.system.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
@Data
|
||||||
|
public class AssetNetLimit implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String key;
|
||||||
|
private Integer value;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.ruoyi.system.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
@Data
|
||||||
|
public class AssetNetUsed implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String key;
|
||||||
|
private Integer value;
|
||||||
|
}
|
|
@ -44,13 +44,14 @@ public class EnergyTenantTransferHandler {
|
||||||
TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder()
|
TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder()
|
||||||
.fromAddress(tenantInfo.getReceiverAddress())
|
.fromAddress(tenantInfo.getReceiverAddress())
|
||||||
.delegateStatus(delegateStatus)
|
.delegateStatus(delegateStatus)
|
||||||
|
.energyBusiType(DictUtils.getDictValue("sys_energy_busi_type", "天数套餐"))
|
||||||
.fcd(DateUtil.offsetDay(new Date(), -2))
|
.fcd(DateUtil.offsetDay(new Date(), -2))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
List<TrxExchangeMonitorAccountInfo> trxExchangeMonitorAccountInfoList = trxExchangeInfoMapper.selectTrxExchangeMonitorAccountInfo(trxExchangeInfo);
|
List<TrxExchangeMonitorAccountInfo> trxExchangeMonitorAccountInfoList = trxExchangeInfoMapper.selectTrxExchangeMonitorAccountInfo(trxExchangeInfo);
|
||||||
|
|
||||||
for (TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo : trxExchangeMonitorAccountInfoList) {
|
for (TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo : trxExchangeMonitorAccountInfoList) {
|
||||||
undelegateEnergyHandler.doUndelegateEnergyByTrxExchangeInfo(trxExchangeMonitorAccountInfo);
|
undelegateEnergyHandler.unDelegateResource(trxExchangeMonitorAccountInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//赠送每天的能量
|
//赠送每天的能量
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.ruoyi.system.handler;
|
package com.ruoyi.system.handler;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
@ -12,8 +11,7 @@ import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.encrpt.Dt;
|
import com.ruoyi.common.utils.encrpt.Dt;
|
||||||
import com.ruoyi.system.api.ITronApi;
|
import com.ruoyi.system.api.ITronApi;
|
||||||
import com.ruoyi.system.domain.TrxExchangeMonitorAccountInfo;
|
import com.ruoyi.system.domain.TrxExchangeMonitorAccountInfo;
|
||||||
import com.ruoyi.system.dto.Data;
|
import com.ruoyi.system.dto.AccountResourceResponse;
|
||||||
import com.ruoyi.system.dto.TronGridResponse;
|
|
||||||
import com.ruoyi.system.mapper.ErrorLogMapper;
|
import com.ruoyi.system.mapper.ErrorLogMapper;
|
||||||
import com.ruoyi.system.mapper.TenantInfoMapper;
|
import com.ruoyi.system.mapper.TenantInfoMapper;
|
||||||
import com.ruoyi.system.mapper.TrxExchangeInfoMapper;
|
import com.ruoyi.system.mapper.TrxExchangeInfoMapper;
|
||||||
|
@ -69,27 +67,39 @@ public class UndelegateEnergyHandler {
|
||||||
|
|
||||||
apiKey = StringUtils.isEmpty(apiKey) ? DictUtils.getDictValue("sys_tron_api_key", "synp@outlook") : apiKey;
|
apiKey = StringUtils.isEmpty(apiKey) ? DictUtils.getDictValue("sys_tron_api_key", "synp@outlook") : apiKey;
|
||||||
|
|
||||||
TronGridResponse tronGridResponse = tronApi.getTronGridTrc20Response(fromAddress,false,true, apiKey,fcd.getTime());
|
// TronGridResponse tronGridResponse = tronApi.getTronGridTrc20Response(fromAddress,false,true, apiKey,fcd.getTime());
|
||||||
|
|
||||||
List<Data> dataList = tronGridResponse.getData();
|
// List<Data> dataList = tronGridResponse.getData();
|
||||||
if (CollectionUtil.isEmpty(dataList)) {
|
// if (CollectionUtil.isEmpty(dataList)) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// int transActionCount = dataList.size();
|
||||||
|
// if (transActionCount < trxExchangeMonitorAccountInfo.getTranferCount()){
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
AccountResourceResponse accountResource = tronApi.getAccountResource(fromAddress, apiKey);
|
||||||
|
if (accountResource == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Integer energyUsed = accountResource.getEnergyUsed();
|
||||||
|
if (energyUsed == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int transActionCount = dataList.size();
|
long energyUsedCount = energyUsed / 30000;
|
||||||
if (transActionCount < trxExchangeMonitorAccountInfo.getTranferCount()){
|
if (energyUsedCount < trxExchangeMonitorAccountInfo.getTranferCount()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unDelegateResource(trxExchangeMonitorAccountInfo);
|
unDelegateResource(trxExchangeMonitorAccountInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unDelegateResource(TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo) {
|
public void unDelegateResource(TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo) {
|
||||||
String accountAddress = trxExchangeMonitorAccountInfo.getAccountAddress();
|
String accountAddress = trxExchangeMonitorAccountInfo.getAccountAddress();
|
||||||
RLock lock = redissonClient.getLock("lock_undelegate_" + trxExchangeMonitorAccountInfo.getDelegateTxId());
|
RLock lock = redissonClient.getLock("lock_undelegate_" + trxExchangeMonitorAccountInfo.getDelegateTxId());
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class Usdt2TrxTransferHandler {
|
||||||
BigDecimal transferValue = getTransferValue(data);
|
BigDecimal transferValue = getTransferValue(data);
|
||||||
if (transferValue == null) return;
|
if (transferValue == null) return;
|
||||||
|
|
||||||
BigDecimal trxValue = transferValue.multiply(oneUsdtToTrx);
|
BigDecimal trxValue = transferValue.multiply(oneUsdtToTrx).setScale(6, BigDecimal.ROUND_HALF_DOWN);
|
||||||
|
|
||||||
String accountAddress = monitorAddressAccount.getAccountAddress();
|
String accountAddress = monitorAddressAccount.getAccountAddress();
|
||||||
String encryptPrivateKey = monitorAddressAccount.getEncryptPrivateKey();
|
String encryptPrivateKey = monitorAddressAccount.getEncryptPrivateKey();
|
||||||
|
@ -204,11 +204,11 @@ public class Usdt2TrxTransferHandler {
|
||||||
String sysTgGroupChatId = configService.selectConfigByKey("sys.tg.group.chat.id");
|
String sysTgGroupChatId = configService.selectConfigByKey("sys.tg.group.chat.id");
|
||||||
if (longPollingBot != null && StringUtils.isNotEmpty(sysUsdtTranferNotice) && StringUtils.isNotEmpty(sysTgGroupChatId)) {
|
if (longPollingBot != null && StringUtils.isNotEmpty(sysUsdtTranferNotice) && StringUtils.isNotEmpty(sysTgGroupChatId)) {
|
||||||
Map<String, Object> arguments = new HashMap<>();
|
Map<String, Object> arguments = new HashMap<>();
|
||||||
arguments.put("usdtAmount", transferValue);
|
arguments.put("usdtAmount", transferValue.setScale(2, BigDecimal.ROUND_HALF_DOWN));
|
||||||
arguments.put("exchangeRate", oneUsdtToTrx);
|
arguments.put("exchangeRate", oneUsdtToTrx);
|
||||||
arguments.put("trxAmount", trxValue);
|
arguments.put("trxAmount", trxValue);
|
||||||
arguments.put("FromAddress", from);
|
arguments.put("FromAddress", from.replaceAll("(.{6})(.*)(.{8})", "$1********$3"));
|
||||||
arguments.put("txId", txId);
|
arguments.put("txId", txId.replaceAll("(.{6})(.*)(.{8})", "$1*******************$3"));
|
||||||
arguments.put("txTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
arguments.put("txTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
||||||
// String message = MessageFormat.format(sysUsdtTranferNotice, arguments);
|
// String message = MessageFormat.format(sysUsdtTranferNotice, arguments);
|
||||||
StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}");
|
StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}");
|
||||||
|
|
Loading…
Reference in New Issue