address和USDTmanage/address token管理页面,参考归集任务页面布局和功能,添加统计功能,优化页面布局。 商户和管理员都去掉删除和修改,商户的详情页面去掉对地址的各种金额操作,只保留刷新链上数据功能
This commit is contained in:
1 parent
37754f3af0
commit
c516124eff
5 files changed
+127
-11
No files matched your search
+26
-8
@@ -40,6 +40,24 @@ import com.ruoyi.system.domain.vo.WalletOperationRequest;
|
||||
public class WalletAddressController extends BaseController {
|
||||
@Autowired
|
||||
private IWalletAddressService walletAddressService;
|
||||
|
||||
@Autowired
|
||||
private com.ruoyi.system.mapper.WalletAddressMapper walletAddressMapper;
|
||||
|
||||
/** 统计数据库钱包快照,不额外触发链上请求;复用列表权限和筛选条件。 */
|
||||
@PreAuthorize("@ss.hasPermi('system:address:list')")
|
||||
@GetMapping("/statistics")
|
||||
public AjaxResult statistics(WalletAddress filter) {
|
||||
return AjaxResult.success(walletAddressMapper.selectWalletStatistics(filter));
|
||||
}
|
||||
|
||||
/** 商户统计在服务端强制指定用户,不能使用请求中的 userId 扩大范围。 */
|
||||
@PreAuthorize("@ss.hasPermi('system:address:user-list')")
|
||||
@GetMapping("/user/statistics")
|
||||
public AjaxResult userStatistics(WalletAddress filter) {
|
||||
filter.setUserId(SecurityUtils.getUserId());
|
||||
return AjaxResult.success(walletAddressMapper.selectWalletStatistics(filter));
|
||||
}
|
||||
@Autowired
|
||||
private WalletSigningService walletSigningService;
|
||||
@Autowired
|
||||
@@ -104,7 +122,7 @@ public class WalletAddressController extends BaseController {
|
||||
}
|
||||
|
||||
/** 计算操作所需能量、带宽、安全冗余及预计燃烧的 TRX。 */
|
||||
@PreAuthorize("@ss.hasPermi('system:address:query') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/{type}/estimate")
|
||||
public AjaxResult estimate(@PathVariable("type") String type,
|
||||
@RequestBody WalletOperationRequest request) {
|
||||
@@ -113,7 +131,7 @@ public class WalletAddressController extends BaseController {
|
||||
return AjaxResult.success(walletOperationEstimateService.estimate(type, wallet, request));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/transfer-trx")
|
||||
public AjaxResult transferTrx(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
@@ -124,7 +142,7 @@ public class WalletAddressController extends BaseController {
|
||||
tron.trxTrans(api, current.getToken(), request.getToAddress().trim(), request.getAmount()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/transfer-usdt")
|
||||
public AjaxResult transferUsdt(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
@@ -136,7 +154,7 @@ public class WalletAddressController extends BaseController {
|
||||
request.getAmount().toPlainString()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/stake")
|
||||
public AjaxResult stake(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
@@ -147,7 +165,7 @@ public class WalletAddressController extends BaseController {
|
||||
tron.stakeTrxBalance(api, current.getToken(), request.getAmount(), request.getResourceCode()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/unstake")
|
||||
public AjaxResult unstake(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
@@ -158,7 +176,7 @@ public class WalletAddressController extends BaseController {
|
||||
tron.unstakeTrxBalance(api, current.getToken(), request.getAmount(), request.getResourceCode()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/delegate")
|
||||
public AjaxResult delegate(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
@@ -175,7 +193,7 @@ public class WalletAddressController extends BaseController {
|
||||
request.getAmount(), request.getResourceCode()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/undelegate")
|
||||
public AjaxResult undelegate(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
@@ -188,7 +206,7 @@ public class WalletAddressController extends BaseController {
|
||||
request.getAmount(), request.getResourceCode()));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate') or @ss.hasPermi('system:address:user-query')")
|
||||
@PreAuthorize("@ss.hasPermi('system:address:operate')")
|
||||
@PostMapping("/operations/cancel-unstake")
|
||||
public AjaxResult cancelUnstake(@RequestBody WalletOperationRequest request) {
|
||||
final WalletAddressPlus wallet = requireWallet(request);
|
||||
|
||||
@@ -15,6 +15,9 @@ import com.ruoyi.system.domain.WalletAddressPlus;
|
||||
*/
|
||||
public interface WalletAddressMapper extends BaseMapper<WalletAddressPlus>
|
||||
{
|
||||
/** 按钱包列表相同条件聚合快照,余额保持 DECIMAL 精度且不受分页影响。 */
|
||||
java.util.Map<String, Object> selectWalletStatistics(WalletAddress filter);
|
||||
|
||||
/**
|
||||
* 查询钱包
|
||||
*
|
||||
|
||||
@@ -59,9 +59,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select id, token, status, created_at, updated_at, deleted_at, app_id, user_id, wallet_user_name, token_index, usdt_balance, trx_balance, energy_num, energy_all_num, energy_used_num, bandwidth_num, delegated_energy_trx_num, delegated_energy_value, acquired_delegated_energy_trx_num, acquired_delegated_energy_value, delegated_bandwidth_trx_num, delegated_bandwidth_value, acquired_delegated_bandwidth_trx_num, acquired_delegated_bandwidth_value, staked_trx_num, energy_staked_trx_num, bandwidth_staked_trx_num, bandwidth_staked_delegated_num, energy_staked_delegated_num, vote_num, voted_num, bandwidth_staked_num, bandwidth_staked_all_num, bandwidth_free_num, bandwidth_free_all_num from wallet_address
|
||||
</sql>
|
||||
|
||||
<select id="selectWalletAddressList" parameterType="WalletAddress" resultMap="WalletAddressResult">
|
||||
<include refid="selectWalletAddressVo"/>
|
||||
<where>
|
||||
<sql id="walletQueryWhere">
|
||||
<where>
|
||||
and deleted_at is null
|
||||
<if test="token != null and token != ''"> and token = #{token}</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
<if test="createdAt != null "> and created_at = #{createdAt}</if>
|
||||
@@ -98,6 +98,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="bandwidthFreeAllNum != null "> and bandwidth_free_all_num = #{bandwidthFreeAllNum}</if>
|
||||
and wallet_user_name is not null
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="selectWalletAddressList" parameterType="WalletAddress" resultMap="WalletAddressResult">
|
||||
<include refid="selectWalletAddressVo"/>
|
||||
<include refid="walletQueryWhere"/>
|
||||
order by created_at desc, id desc
|
||||
</select>
|
||||
|
||||
<select id="selectWalletStatistics" parameterType="WalletAddress" resultType="java.util.LinkedHashMap">
|
||||
select count(*) as total,
|
||||
coalesce(sum(case when status = 1 then 1 else 0 end), 0) as enabled,
|
||||
cast(coalesce(sum(usdt_balance), 0) as char) as usdtBalance,
|
||||
cast(coalesce(sum(trx_balance), 0) as char) as trxBalance,
|
||||
cast(coalesce(sum(greatest(0, coalesce(energy_num, 0))), 0) as char) as energy,
|
||||
cast(coalesce(sum(greatest(0, coalesce(bandwidth_num, 0))), 0) as char) as bandwidth
|
||||
from wallet_address
|
||||
<include refid="walletQueryWhere"/>
|
||||
</select>
|
||||
|
||||
<select id="selectWalletAddressById" parameterType="Long" resultMap="WalletAddressResult">
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.system.domain.vo.WalletOperationRequest;
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** 防止商户只读权限再次被误加入私钥操作的授权表达式。 */
|
||||
public class WalletAddressPermissionTest {
|
||||
|
||||
@Test
|
||||
public void merchantReadPermissionCannotEstimateOrBroadcast() throws Exception {
|
||||
String[] methods = {"transferTrx", "transferUsdt", "stake", "unstake",
|
||||
"delegate", "undelegate", "cancelUnstake"};
|
||||
for (String name : methods) {
|
||||
Method method = WalletAddressController.class.getMethod(name, WalletOperationRequest.class);
|
||||
assertFalse(name, allowed(method, false));
|
||||
assertTrue(name, allowed(method, true));
|
||||
}
|
||||
Method estimate = WalletAddressController.class.getMethod("estimate", String.class, WalletOperationRequest.class);
|
||||
assertFalse(allowed(estimate, false));
|
||||
assertTrue(allowed(estimate, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void merchantReadPermissionStillAllowsChainRefresh() throws Exception {
|
||||
assertTrue(allowed(WalletAddressController.class.getMethod("chain", Long.class), false));
|
||||
assertTrue(allowed(WalletAddressController.class.getMethod("delegations", Long.class), false));
|
||||
}
|
||||
|
||||
private boolean allowed(Method method, boolean operator) {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setBeanResolver((evaluationContext, beanName) -> new PermissionStub(operator));
|
||||
return Boolean.TRUE.equals(new SpelExpressionParser()
|
||||
.parseExpression(method.getAnnotation(PreAuthorize.class).value())
|
||||
.getValue(context, Boolean.class));
|
||||
}
|
||||
|
||||
public static class PermissionStub {
|
||||
private final boolean operator;
|
||||
|
||||
public PermissionStub(boolean operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public boolean hasPermi(String permission) {
|
||||
return operator ? "system:address:operate".equals(permission)
|
||||
: "system:address:user-query".equals(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user