新增代理明细列表
This commit is contained in:
1 parent
81febe2c56
commit
df5512838b
12 files changed
+266
-37
No files matched your search
+9
-9
@@ -24,19 +24,19 @@ import java.util.List;
|
||||
* @date 2026-10-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/otherToDelegation")
|
||||
@RequestMapping("/system/delegationToOther")
|
||||
public class UsdtDelegationToOtherController extends BaseController {
|
||||
@Autowired
|
||||
private IUsdtProxyToOtherService usdtProxyToOtherService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:getByIds')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:getByIds')")
|
||||
@PostMapping("/getByIds")
|
||||
public AjaxResult getByIds(@RequestBody Ids ids) {
|
||||
List<UsdtDelegationToOtherPlus> list = usdtProxyToOtherService.getByIds(ids.getLongIds(), UsdtDelegationToOtherPlus::getToken, UsdtDelegationToOtherPlus::getId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:select')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:select')")
|
||||
@GetMapping("/select")
|
||||
public AjaxResult select(String keyword) {
|
||||
List<SelectItem> list = usdtProxyToOtherService.select(keyword);
|
||||
@@ -46,7 +46,7 @@ public class UsdtDelegationToOtherController extends BaseController {
|
||||
/**
|
||||
* 查询代理给其他地址列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:list')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(UsdtDelegationToOther usdtDelegationToOther) {
|
||||
startPage();
|
||||
@@ -57,7 +57,7 @@ public class UsdtDelegationToOtherController extends BaseController {
|
||||
/**
|
||||
* 导出代理给其他地址列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:export')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:export')")
|
||||
@Log(title = "代理给其他地址", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public AjaxResult export(UsdtDelegationToOther usdtDelegationToOther) {
|
||||
@@ -69,7 +69,7 @@ public class UsdtDelegationToOtherController extends BaseController {
|
||||
/**
|
||||
* 获取代理给其他地址详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(usdtProxyToOtherService.selectUsdtDelegationToOtherById(id));
|
||||
@@ -78,7 +78,7 @@ public class UsdtDelegationToOtherController extends BaseController {
|
||||
/**
|
||||
* 新增代理给其他地址
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:add')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:add')")
|
||||
@Log(title = "代理给其他地址", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody UsdtDelegationToOther usdtDelegationToOther) {
|
||||
@@ -88,7 +88,7 @@ public class UsdtDelegationToOtherController extends BaseController {
|
||||
/**
|
||||
* 修改代理给其他地址
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:edit')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:edit')")
|
||||
@Log(title = "代理给其他地址", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody UsdtDelegationToOther usdtDelegationToOther) {
|
||||
@@ -98,7 +98,7 @@ public class UsdtDelegationToOtherController extends BaseController {
|
||||
/**
|
||||
* 删除代理给其他地址
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:remove')")
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:remove')")
|
||||
@Log(title = "代理给其他地址", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
|
||||
+9
-9
@@ -24,19 +24,19 @@ import java.util.List;
|
||||
* @date 2026-10-12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/delegationToOther")
|
||||
@RequestMapping("/system/otherToDelegation")
|
||||
public class UsdtOtherToDelegationController extends BaseController {
|
||||
@Autowired
|
||||
private IUsdtOtherToProxyService usdtOtherToProxyService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:getByIds')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:getByIds')")
|
||||
@PostMapping("/getByIds")
|
||||
public AjaxResult getByIds(@RequestBody Ids ids) {
|
||||
List<UsdtOtherToDelegationPlus> list = usdtOtherToProxyService.getByIds(ids.getLongIds(), UsdtOtherToDelegationPlus::getToken, UsdtOtherToDelegationPlus::getId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:select')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:select')")
|
||||
@GetMapping("/select")
|
||||
public AjaxResult select(String keyword) {
|
||||
List<SelectItem> list = usdtOtherToProxyService.select(keyword);
|
||||
@@ -46,7 +46,7 @@ public class UsdtOtherToDelegationController extends BaseController {
|
||||
/**
|
||||
* 查询其他地址代理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:list')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(UsdtOtherToDelegation usdtOtherToDelegation) {
|
||||
startPage();
|
||||
@@ -57,7 +57,7 @@ public class UsdtOtherToDelegationController extends BaseController {
|
||||
/**
|
||||
* 导出其他地址代理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:export')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:export')")
|
||||
@Log(title = "其他地址代理", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public AjaxResult export(UsdtOtherToDelegation usdtOtherToDelegation) {
|
||||
@@ -69,7 +69,7 @@ public class UsdtOtherToDelegationController extends BaseController {
|
||||
/**
|
||||
* 获取其他地址代理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(usdtOtherToProxyService.selectUsdtOtherToDelegationById(id));
|
||||
@@ -78,7 +78,7 @@ public class UsdtOtherToDelegationController extends BaseController {
|
||||
/**
|
||||
* 新增其他地址代理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:add')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:add')")
|
||||
@Log(title = "其他地址代理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody UsdtOtherToDelegation usdtOtherToDelegation) {
|
||||
@@ -88,7 +88,7 @@ public class UsdtOtherToDelegationController extends BaseController {
|
||||
/**
|
||||
* 修改其他地址代理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:edit')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:edit')")
|
||||
@Log(title = "其他地址代理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody UsdtOtherToDelegation usdtOtherToDelegation) {
|
||||
@@ -98,7 +98,7 @@ public class UsdtOtherToDelegationController extends BaseController {
|
||||
/**
|
||||
* 删除其他地址代理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:delegationToOther:remove')")
|
||||
@PreAuthorize("@ss.hasPermi('system:otherToDelegation:remove')")
|
||||
@Log(title = "其他地址代理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
|
||||
@@ -11,13 +11,19 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.domain.WalletAddress;
|
||||
import com.ruoyi.system.domain.WalletAddressPlus;
|
||||
import com.ruoyi.system.domain.UsdtDelegationToOther;
|
||||
import com.ruoyi.system.domain.UsdtOtherToDelegation;
|
||||
import com.ruoyi.system.service.IWalletAddressService;
|
||||
import com.ruoyi.system.service.IUsdtProxyToOtherService;
|
||||
import com.ruoyi.system.service.IUsdtOtherToProxyService;
|
||||
import com.ruoyi.system.service.WalletSigningService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import com.ruoyi.system.domain.vo.WalletOperationRequest;
|
||||
|
||||
/**
|
||||
@@ -33,6 +39,10 @@ public class WalletAddressController extends BaseController {
|
||||
private IWalletAddressService walletAddressService;
|
||||
@Autowired
|
||||
private WalletSigningService walletSigningService;
|
||||
@Autowired
|
||||
private IUsdtProxyToOtherService usdtProxyToOtherService;
|
||||
@Autowired
|
||||
private IUsdtOtherToProxyService usdtOtherToProxyService;
|
||||
|
||||
/**
|
||||
* 同步刷新并返回完整链上账户快照。
|
||||
@@ -61,6 +71,32 @@ public class WalletAddressController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回钱包的双向代理关系快照。先校验钱包归属,商户只能查看自己的钱包。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:address:query') or @ss.hasPermi('system:address:user-query')")
|
||||
@GetMapping("/{id}/delegations")
|
||||
public AjaxResult delegations(@PathVariable("id") Long id) {
|
||||
WalletAddressPlus wallet = walletAddressService.getById(id);
|
||||
if (wallet == null) {
|
||||
return AjaxResult.error("钱包不存在");
|
||||
}
|
||||
if (!SecurityUtils.isAdmin(getUserId()) && !getUserId().equals(wallet.getUserId())) {
|
||||
return AjaxResult.error("无权访问该钱包");
|
||||
}
|
||||
|
||||
UsdtDelegationToOther delegatedQuery = new UsdtDelegationToOther();
|
||||
delegatedQuery.setToken(wallet.getToken());
|
||||
UsdtOtherToDelegation acquiredQuery = new UsdtOtherToDelegation();
|
||||
acquiredQuery.setToken(wallet.getToken());
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("delegatedToOthers",
|
||||
usdtProxyToOtherService.selectUsdtDelegationToOtherList(delegatedQuery));
|
||||
result.put("acquiredFromOthers",
|
||||
usdtOtherToProxyService.selectUsdtOtherToDelegationList(acquiredQuery));
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PostMapping("/operations/transfer-trx")
|
||||
public AjaxResult transferTrx(@RequestBody WalletOperationRequest request) {
|
||||
|
||||
@@ -25,13 +25,13 @@ public class UsdtDelegationToOther extends BaseEntity
|
||||
private String token;
|
||||
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createdAt;
|
||||
|
||||
/** 更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updatedAt;
|
||||
|
||||
/** 代理的对方地址 */
|
||||
|
||||
@@ -26,12 +26,12 @@ public class UsdtDelegationToOtherPlus implements Serializable
|
||||
@Excel(name = "钱包地址")
|
||||
private String token;
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createdAt;
|
||||
/** 更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updatedAt;
|
||||
/** 代理的对方地址 */
|
||||
@Excel(name = "代理的对方地址")
|
||||
|
||||
@@ -25,13 +25,13 @@ public class UsdtOtherToDelegation extends BaseEntity
|
||||
private String token;
|
||||
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createdAt;
|
||||
|
||||
/** 更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updatedAt;
|
||||
|
||||
/** 代理的来源地址 */
|
||||
|
||||
@@ -26,12 +26,12 @@ public class UsdtOtherToDelegationPlus implements Serializable
|
||||
@Excel(name = "钱包地址")
|
||||
private String token;
|
||||
/** 创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createdAt;
|
||||
/** 更新时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updatedAt;
|
||||
/** 代理的来源地址 */
|
||||
@Excel(name = "代理的来源地址")
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.ruoyi.system.domain.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* TRON Stake 2.0 代理关系明细。
|
||||
*
|
||||
* <p>type 使用业务表约定:0 表示能量,1 表示带宽;trxNum 使用 TRX,
|
||||
* 不在业务层暴露链上的 SUN 单位。</p>
|
||||
*/
|
||||
public class DelegatedResourceDetailVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 代理关系中的对方地址。 */
|
||||
private String counterpartToken;
|
||||
|
||||
/** 代理的 TRX 本金数量。 */
|
||||
private Long trxNum;
|
||||
|
||||
/** 资源类型:0 能量,1 带宽。 */
|
||||
private Integer type;
|
||||
|
||||
public DelegatedResourceDetailVo() {
|
||||
}
|
||||
|
||||
public DelegatedResourceDetailVo(String counterpartToken, Long trxNum, Integer type) {
|
||||
this.counterpartToken = counterpartToken;
|
||||
this.trxNum = trxNum;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getCounterpartToken() {
|
||||
return counterpartToken;
|
||||
}
|
||||
|
||||
public void setCounterpartToken(String counterpartToken) {
|
||||
this.counterpartToken = counterpartToken;
|
||||
}
|
||||
|
||||
public Long getTrxNum() {
|
||||
return trxNum;
|
||||
}
|
||||
|
||||
public void setTrxNum(Long trxNum) {
|
||||
this.trxNum = trxNum;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,13 @@ import com.ruoyi.system.domain.vo.TronAccount;
|
||||
import com.ruoyi.system.domain.vo.TronAccountItem;
|
||||
import org.tron.trident.core.ApiWrapper;
|
||||
import org.tron.trident.core.exceptions.IllegalException;
|
||||
import org.tron.trident.proto.Response;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.ruoyi.system.domain.vo.DelegatedResourceDetailVo;
|
||||
|
||||
public interface ITronService {
|
||||
Integer grpcPort();
|
||||
@@ -117,6 +122,55 @@ public interface ITronService {
|
||||
return BigDecimal.valueOf(availableSun).movePointLeft(6);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前地址代理给其他地址的 Stake 2.0 明细。
|
||||
*/
|
||||
default List<DelegatedResourceDetailVo> delegatedResourceDetails(ApiWrapper api, String ownerAddr) {
|
||||
Response.DelegatedResourceAccountIndex index = api.getDelegatedResourceAccountIndexV2(ownerAddr);
|
||||
return buildDelegatedResourceDetails(api, ownerAddr, index.getToAccountsList(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询其他地址代理给当前地址的 Stake 2.0 明细。
|
||||
*/
|
||||
default List<DelegatedResourceDetailVo> acquiredDelegatedResourceDetails(ApiWrapper api,
|
||||
String ownerAddr) {
|
||||
Response.DelegatedResourceAccountIndex index = api.getDelegatedResourceAccountIndexV2(ownerAddr);
|
||||
return buildDelegatedResourceDetails(api, ownerAddr, index.getFromAccountsList(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 TRON 节点返回的 SUN 级代理本金转换为业务表使用的整 TRX 明细。
|
||||
* 数据表 type 与 SDK resourceCode 定义相反,因此这里固定转换为 0=能量、1=带宽。
|
||||
*/
|
||||
default List<DelegatedResourceDetailVo> buildDelegatedResourceDetails(ApiWrapper api,
|
||||
String ownerAddr, List<ByteString> counterpartAccounts, boolean delegatedToOther) {
|
||||
List<DelegatedResourceDetailVo> result = new ArrayList<>();
|
||||
for (ByteString account : counterpartAccounts) {
|
||||
String counterpart = org.tron.trident.utils.Base58Check.bytesToBase58(account.toByteArray());
|
||||
Response.DelegatedResourceList resources = delegatedToOther
|
||||
? api.getDelegatedResourceV2(ownerAddr, counterpart)
|
||||
: api.getDelegatedResourceV2(counterpart, ownerAddr);
|
||||
for (Response.DelegatedResource resource : resources.getDelegatedResourceList()) {
|
||||
addDelegatedResourceDetail(result, counterpart,
|
||||
resource.getFrozenBalanceForEnergy(), 0);
|
||||
addDelegatedResourceDetail(result, counterpart,
|
||||
resource.getFrozenBalanceForBandwidth(), 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 仅保存仍有代理本金的关系,避免详情页出现 0 TRX 的空记录。 */
|
||||
default void addDelegatedResourceDetail(List<DelegatedResourceDetailVo> result,
|
||||
String counterpart, long amountSun, int type) {
|
||||
if (amountSun <= 0L) {
|
||||
return;
|
||||
}
|
||||
long amountTrx = BigDecimal.valueOf(amountSun).movePointLeft(6).longValue();
|
||||
result.add(new DelegatedResourceDetailVo(counterpart, amountTrx, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取别人质押的trx的数量-代理的
|
||||
* @param ownerAddr
|
||||
|
||||
+83
-1
@@ -10,7 +10,12 @@ import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.WalletAddress;
|
||||
import com.ruoyi.system.domain.WalletAddressPlus;
|
||||
import com.ruoyi.system.domain.UsdtDelegationToOtherPlus;
|
||||
import com.ruoyi.system.domain.UsdtOtherToDelegationPlus;
|
||||
import com.ruoyi.system.domain.vo.DelegatedResourceDetailVo;
|
||||
import com.ruoyi.system.domain.vo.EnergyAndBandwidthVo;
|
||||
import com.ruoyi.system.mapper.UsdtDelegationToOtherMapper;
|
||||
import com.ruoyi.system.mapper.UsdtOtherToDelegationMapper;
|
||||
import com.ruoyi.system.mapper.WalletAddressMapper;
|
||||
import com.ruoyi.system.service.ITronService;
|
||||
import com.ruoyi.system.service.TronServiceProvider;
|
||||
@@ -18,6 +23,7 @@ import com.ruoyi.system.service.IWalletAddressService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.tron.trident.core.ApiWrapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -37,6 +43,10 @@ public class WalletAddressServiceImpl extends ServiceImpl<WalletAddressMapper, W
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
@Autowired
|
||||
private TronServiceProvider tronServiceProvider;
|
||||
@Autowired
|
||||
private UsdtDelegationToOtherMapper delegationToOtherMapper;
|
||||
@Autowired
|
||||
private UsdtOtherToDelegationMapper otherToDelegationMapper;
|
||||
@Override
|
||||
public List<WalletAddressPlus> getByIds(List<Long> ids, boolean isUser, SFunction<WalletAddressPlus, ?>... columns) {
|
||||
LambdaQueryWrapper<WalletAddressPlus> lambdaQueryWrapper = new LambdaQueryWrapper<WalletAddressPlus>()
|
||||
@@ -80,6 +90,7 @@ public class WalletAddressServiceImpl extends ServiceImpl<WalletAddressMapper, W
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateTronInfo(WalletAddressPlus walletAddressPlus) {
|
||||
ITronService tronService = tronServiceProvider.getCurrentService();
|
||||
ApiWrapper api = tronService.buildApiWrapper();
|
||||
@@ -123,14 +134,85 @@ public class WalletAddressServiceImpl extends ServiceImpl<WalletAddressMapper, W
|
||||
walletAddressPlus.setAcquiredDelegatedBandwidthTrxNum(
|
||||
tronService.acquiredDelegatedStakedTrxBalance(api, token, 0).longValue());
|
||||
|
||||
// 关系表是链上状态快照。只有所有链上查询成功后才整体替换,避免留下半份数据。
|
||||
List<DelegatedResourceDetailVo> delegatedDetails =
|
||||
tronService.delegatedResourceDetails(api, token);
|
||||
List<DelegatedResourceDetailVo> acquiredDetails =
|
||||
tronService.acquiredDelegatedResourceDetails(api, token);
|
||||
replaceDelegationDetails(token, delegatedDetails, acquiredDetails, delegated);
|
||||
|
||||
// 所有链上查询成功后再一次性更新,避免数据库保存半份快照。
|
||||
walletAddressPlus.setUpdatedAt(new Date());
|
||||
return updateById(walletAddressPlus);
|
||||
if (!updateById(walletAddressPlus)) {
|
||||
throw new IllegalStateException("钱包链上快照保存失败");
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
api.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按钱包地址重建代理关系快照。链上协议只返回每条关系的质押本金,
|
||||
* resource_amount 按同类型代理本金占链上资源汇总值的比例估算。
|
||||
*/
|
||||
private void replaceDelegationDetails(String token,
|
||||
List<DelegatedResourceDetailVo> delegatedDetails,
|
||||
List<DelegatedResourceDetailVo> acquiredDetails,
|
||||
EnergyAndBandwidthVo delegatedSummary) {
|
||||
delegationToOtherMapper.delete(new LambdaQueryWrapper<UsdtDelegationToOtherPlus>()
|
||||
.eq(UsdtDelegationToOtherPlus::getToken, token));
|
||||
otherToDelegationMapper.delete(new LambdaQueryWrapper<UsdtOtherToDelegationPlus>()
|
||||
.eq(UsdtOtherToDelegationPlus::getToken, token));
|
||||
|
||||
Date now = new Date();
|
||||
for (DelegatedResourceDetailVo detail : delegatedDetails) {
|
||||
UsdtDelegationToOtherPlus row = new UsdtDelegationToOtherPlus();
|
||||
row.setToken(token);
|
||||
row.setTargetToken(detail.getCounterpartToken());
|
||||
row.setTrxNum(detail.getTrxNum());
|
||||
row.setType(detail.getType());
|
||||
row.setResourceAmount(calculateResourceAmount(detail, delegatedDetails,
|
||||
detail.getType() == 0 ? delegatedSummary.getDelegateEnergy()
|
||||
: delegatedSummary.getDelegateBandwidth()));
|
||||
row.setCreatedAt(now);
|
||||
row.setUpdatedAt(now);
|
||||
delegationToOtherMapper.insert(row);
|
||||
}
|
||||
for (DelegatedResourceDetailVo detail : acquiredDetails) {
|
||||
UsdtOtherToDelegationPlus row = new UsdtOtherToDelegationPlus();
|
||||
row.setToken(token);
|
||||
row.setFromToken(detail.getCounterpartToken());
|
||||
row.setTrxNum(detail.getTrxNum());
|
||||
row.setType(detail.getType());
|
||||
row.setResourceAmount(calculateResourceAmount(detail, acquiredDetails,
|
||||
detail.getType() == 0 ? delegatedSummary.getAcquiredEnergy()
|
||||
: delegatedSummary.getAcquiredBandwidth()));
|
||||
row.setCreatedAt(now);
|
||||
row.setUpdatedAt(now);
|
||||
otherToDelegationMapper.insert(row);
|
||||
}
|
||||
}
|
||||
|
||||
private long calculateResourceAmount(DelegatedResourceDetailVo current,
|
||||
List<DelegatedResourceDetailVo> details, BigDecimal totalResourceAmount) {
|
||||
if (totalResourceAmount == null || totalResourceAmount.signum() <= 0) {
|
||||
return 0L;
|
||||
}
|
||||
long totalTrx = 0L;
|
||||
for (DelegatedResourceDetailVo detail : details) {
|
||||
if (current.getType().equals(detail.getType()) && detail.getTrxNum() != null) {
|
||||
totalTrx += detail.getTrxNum();
|
||||
}
|
||||
}
|
||||
if (totalTrx <= 0L) {
|
||||
return 0L;
|
||||
}
|
||||
return totalResourceAmount.multiply(BigDecimal.valueOf(current.getTrxNum()))
|
||||
.divide(BigDecimal.valueOf(totalTrx), 0, java.math.RoundingMode.HALF_UP)
|
||||
.longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SelectItem> select(String keyword, boolean isUser) {
|
||||
LambdaQueryWrapper<WalletAddressPlus> lambdaQueryWrapper = new LambdaQueryWrapper<WalletAddressPlus>()
|
||||
|
||||
Reference in new issue
Block a user