address和USDTmanage/address token管理页面,参考归集任务页面布局和功能,添加统计功能,优化页面布局。 商户和管理员都去掉删除和修改,商户的详情页面去掉对地址的各种金额操作,只保留刷新链上数据功能。

This commit is contained in:
lu7213 committed 2026-10-19 05:33:31 -04:00
1 parent c516124eff
commit e4ac32e8d7
4 files changed
+141 -10

No files matched your search

@@ -0,0 +1,98 @@
package com.ruoyi.system.service;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.system.domain.Apps;
import com.ruoyi.system.domain.AppsBalanceLedger;
import com.ruoyi.system.domain.vo.AppUsdtBalanceAdjustmentRequest;
import com.ruoyi.system.mapper.AppsMapper;
import com.ruoyi.system.mapper.AppsBalanceLedgerMapper;
import com.ruoyi.system.service.impl.AppsServiceImpl;
import org.junit.After;
import org.junit.Test;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
/** 人工 TRX 调整的账务边界测试;Mapper 使用隔离替身,不访问生产数据库。 */
public class AppsTrxAdjustmentTest {
@After
public void clearLogin() { SecurityContextHolder.clearContext(); }
@Test
public void trxAdjustmentKeepsOtherCurrencyAndFrozenBalances() throws Exception {
List<AppsBalanceLedger> entries = new ArrayList<>();
AppsServiceImpl service = service("10", entries);
service.adjustTrxBalance(1L, request("ADD", "2.123456"));
AppsBalanceLedger entry = entries.get(0);
assertEquals("TRX", entry.getCurrency());
assertEquals("ADMIN_BALANCE_ADD", entry.getBusinessType());
assertEquals(0, entry.getAvailableBefore().compareTo(new BigDecimal("10")));
assertEquals(0, entry.getAvailableAfter().compareTo(new BigDecimal("12.123456")));
assertEquals(0, entry.getFrozenBefore().compareTo(new BigDecimal("3")));
assertEquals(entry.getFrozenBefore(), entry.getFrozenAfter());
service.adjustTrxBalance(1L, request("SUBTRACT", "1"));
assertEquals("ADMIN_BALANCE_SUBTRACT", entries.get(1).getBusinessType());
assertEquals(entry.getAvailableAfter(), entries.get(1).getAvailableBefore());
}
@Test
public void insufficientTrxCannotWriteLedger() throws Exception {
List<AppsBalanceLedger> entries = new ArrayList<>();
try {
service("1", entries).adjustTrxBalance(1L, request("SUBTRACT", "2"));
fail("Should reject insufficient balance");
} catch (CustomException expected) {
assertTrue(entries.isEmpty());
}
}
@Test
public void negativeFeeBalanceCanBeReplenished() throws Exception {
List<AppsBalanceLedger> entries = new ArrayList<>();
Apps app = service("-10", entries).adjustTrxBalance(1L, request("ADD", "2"));
assertEquals(0, app.getTrxBalance().compareTo(new BigDecimal("-8")));
assertEquals(1, entries.size());
}
private AppsServiceImpl service(String trx, List<AppsBalanceLedger> entries) throws Exception {
SysUser user = new SysUser(); user.setUserId(1L); user.setUserName("finance");
LoginUser login = new LoginUser(); login.setUser(user);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(login, null));
Apps app = new Apps(); app.setId(1L); app.setUserId(2L);
app.setUsdtBalance(new BigDecimal("100")); app.setTrxBalance(new BigDecimal(trx));
app.setTrxFrozenBalance(new BigDecimal("3"));
AppsServiceImpl service = new AppsServiceImpl();
inject(service, "appsMapper", Proxy.newProxyInstance(AppsMapper.class.getClassLoader(), new Class[]{AppsMapper.class}, (proxy, method, args) -> {
if ("selectAppsByIdForUpdate".equals(method.getName())) return app;
if ("updateAvailableBalances".equals(method.getName())) {
assertEquals(app.getUsdtBalance(), args[1]);
return 1;
}
throw new UnsupportedOperationException(method.getName());
}));
inject(service, "appsBalanceLedgerMapper", Proxy.newProxyInstance(AppsBalanceLedgerMapper.class.getClassLoader(), new Class[]{AppsBalanceLedgerMapper.class}, (proxy, method, args) -> {
if ("insertAppsBalanceLedger".equals(method.getName())) { entries.add((AppsBalanceLedger) args[0]); return 1; }
throw new UnsupportedOperationException(method.getName());
}));
return service;
}
private void inject(Object target, String name, Object value) throws Exception {
Field field = target.getClass().getDeclaredField(name); field.setAccessible(true); field.set(target, value);
}
private AppUsdtBalanceAdjustmentRequest request(String type, String amount) {
AppUsdtBalanceAdjustmentRequest request = new AppUsdtBalanceAdjustmentRequest();
request.setType(type); request.setAmount(new BigDecimal(amount)); request.setRemark("财务调整测试");
return request;
}
}