diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index d8be3d724..7b062b0ca 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -147,7 +147,7 @@ --> ${project.artifactId} - + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java index 6af5fb8fa..d0841069d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java @@ -4,16 +4,19 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.system.domain.vo.TronInfoVO; import com.ruoyi.system.service.IApiService; 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.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/api") +@CrossOrigin public class ApiController { @Autowired private IApiService apiService; + /** * 获取波场数据 * @return @@ -23,4 +26,6 @@ public class ApiController { TronInfoVO tronInfoVO = apiService.getTronInfo(); return R.ok(tronInfoVO); } + + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java index a9a03bad9..682fdf963 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/ITronApi.java @@ -1,8 +1,11 @@ package com.ruoyi.system.api; +import com.ruoyi.system.dto.AccountResourceResponse; import com.ruoyi.system.dto.TronGridResponse; public interface ITronApi { TronGridResponse getTronGridTrc20Response(String monitorAddress, boolean only_to,boolean only_from,String apiKey, Long min_timestamp); + + AccountResourceResponse getAccountResource(String address, String apiKey); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java index 8d73feebe..3f983d736 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/api/impl/TronApiImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.system.api.impl; import cn.hutool.json.JSONUtil; import com.ruoyi.common.utils.http.RestTemplateUtils; import com.ruoyi.system.api.ITronApi; +import com.ruoyi.system.dto.AccountResourceResponse; import com.ruoyi.system.dto.TronGridResponse; import com.ruoyi.system.service.ISysConfigService; import lombok.extern.slf4j.Slf4j; @@ -13,6 +14,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponentsBuilder; +import java.util.HashMap; +import java.util.Map; + @Component @Slf4j public class TronApiImpl implements ITronApi { @@ -21,7 +25,7 @@ public class TronApiImpl implements ITronApi { private ISysConfigService configService; @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(); headers.add("TRON-PRO-API-KEY", apiKey); //监听 @@ -48,6 +52,36 @@ public class TronApiImpl implements ITronApi { return tronGridResponse; } + @Override + public AccountResourceResponse getAccountResource(String address, String apiKey) { + HttpHeaders headers = new HttpHeaders(); + headers.add("TRON-PRO-API-KEY", apiKey); + + Map uriVariables = new HashMap<>(); + uriVariables.put("address", address); + uriVariables.put("visible", true); + String jsonStr = JSONUtil.toJsonStr(uriVariables); + +// ResponseEntity 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 */ private static Object getResponseEntityBody(ResponseEntity responseEntity, String address) { - if (responseEntity == null) { - log.warn("{}:responseEntity is null", address); - return null; - } - HttpStatus statusCode = responseEntity.getStatusCode(); - if (statusCode != HttpStatus.OK) { - log.error("获取trx交易信息失败:{}", address); - return null; - } + if (checkResponseBodyIsOk(responseEntity, address)) return null; Object responseEntityBody = responseEntity.getBody(); if (responseEntityBody == null) { log.warn("{}:responseEntityBody is null", address); @@ -73,4 +99,17 @@ public class TronApiImpl implements ITronApi { } 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; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java index 9607f4c75..45f70b464 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java @@ -4,11 +4,12 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -//@Component +@Component @Slf4j public class TgLongPollingBot extends TelegramLongPollingBot { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/dto/AccountResourceResponse.java b/ruoyi-system/src/main/java/com/ruoyi/system/dto/AccountResourceResponse.java new file mode 100644 index 000000000..6c6725fce --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/dto/AccountResourceResponse.java @@ -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; + private List assetNetLimit; + private Long TotalNetLimit; + private Long TotalNetWeight; + private Integer EnergyUsed; + private Long EnergyLimit; + private Long TotalEnergyLimit; + private Long TotalEnergyWeight; + + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/dto/AssetNetLimit.java b/ruoyi-system/src/main/java/com/ruoyi/system/dto/AssetNetLimit.java new file mode 100644 index 000000000..e83ffa15f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/dto/AssetNetLimit.java @@ -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; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/dto/AssetNetUsed.java b/ruoyi-system/src/main/java/com/ruoyi/system/dto/AssetNetUsed.java new file mode 100644 index 000000000..6162e2ca4 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/dto/AssetNetUsed.java @@ -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; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java index 952947f0c..9fac40017 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/EnergyTenantTransferHandler.java @@ -44,13 +44,14 @@ public class EnergyTenantTransferHandler { TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder() .fromAddress(tenantInfo.getReceiverAddress()) .delegateStatus(delegateStatus) + .energyBusiType(DictUtils.getDictValue("sys_energy_busi_type", "天数套餐")) .fcd(DateUtil.offsetDay(new Date(), -2)) .build(); List trxExchangeMonitorAccountInfoList = trxExchangeInfoMapper.selectTrxExchangeMonitorAccountInfo(trxExchangeInfo); for (TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo : trxExchangeMonitorAccountInfoList) { - undelegateEnergyHandler.doUndelegateEnergyByTrxExchangeInfo(trxExchangeMonitorAccountInfo); + undelegateEnergyHandler.unDelegateResource(trxExchangeMonitorAccountInfo); } //赠送每天的能量 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java index 97d9560fe..ec804bf15 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/UndelegateEnergyHandler.java @@ -1,6 +1,5 @@ package com.ruoyi.system.handler; -import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; 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.system.api.ITronApi; import com.ruoyi.system.domain.TrxExchangeMonitorAccountInfo; -import com.ruoyi.system.dto.Data; -import com.ruoyi.system.dto.TronGridResponse; +import com.ruoyi.system.dto.AccountResourceResponse; import com.ruoyi.system.mapper.ErrorLogMapper; import com.ruoyi.system.mapper.TenantInfoMapper; 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; - TronGridResponse tronGridResponse = tronApi.getTronGridTrc20Response(fromAddress,false,true, apiKey,fcd.getTime()); +// TronGridResponse tronGridResponse = tronApi.getTronGridTrc20Response(fromAddress,false,true, apiKey,fcd.getTime()); - List dataList = tronGridResponse.getData(); - if (CollectionUtil.isEmpty(dataList)) { +// List dataList = tronGridResponse.getData(); +// 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; } - int transActionCount = dataList.size(); - if (transActionCount < trxExchangeMonitorAccountInfo.getTranferCount()){ + long energyUsedCount = energyUsed / 30000; + if (energyUsedCount < trxExchangeMonitorAccountInfo.getTranferCount()){ return; } } - - unDelegateResource(trxExchangeMonitorAccountInfo); } - private void unDelegateResource(TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo) { + public void unDelegateResource(TrxExchangeMonitorAccountInfo trxExchangeMonitorAccountInfo) { String accountAddress = trxExchangeMonitorAccountInfo.getAccountAddress(); RLock lock = redissonClient.getLock("lock_undelegate_" + trxExchangeMonitorAccountInfo.getDelegateTxId()); try { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java index 78d0644d5..89e79db2c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java @@ -126,7 +126,7 @@ public class Usdt2TrxTransferHandler { BigDecimal transferValue = getTransferValue(data); 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 encryptPrivateKey = monitorAddressAccount.getEncryptPrivateKey(); @@ -204,11 +204,11 @@ public class Usdt2TrxTransferHandler { String sysTgGroupChatId = configService.selectConfigByKey("sys.tg.group.chat.id"); if (longPollingBot != null && StringUtils.isNotEmpty(sysUsdtTranferNotice) && StringUtils.isNotEmpty(sysTgGroupChatId)) { Map arguments = new HashMap<>(); - arguments.put("usdtAmount", transferValue); + arguments.put("usdtAmount", transferValue.setScale(2, BigDecimal.ROUND_HALF_DOWN)); arguments.put("exchangeRate", oneUsdtToTrx); arguments.put("trxAmount", trxValue); - arguments.put("FromAddress", from); - arguments.put("txId", txId); + arguments.put("FromAddress", from.replaceAll("(.{6})(.*)(.{8})", "$1********$3")); + arguments.put("txId", txId.replaceAll("(.{6})(.*)(.{8})", "$1*******************$3")); arguments.put("txTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss")); // String message = MessageFormat.format(sysUsdtTranferNotice, arguments); StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}");