web页面接口开发,上线改动较大到生产服务器

pull/520/head
dorion 2024-04-29 03:05:15 +08:00
parent c3c15a2081
commit 5a6d5f0d2f
20 changed files with 223 additions and 94 deletions

View File

@ -147,7 +147,7 @@
</plugin> -->
</plugins>
<finalName>${project.artifactId}</finalName>
<!-- <resources>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
@ -155,7 +155,7 @@
<exclude>*.xml</exclude>
</excludes>
</resource>
</resources>-->
</resources>
</build>

View File

@ -2,6 +2,8 @@ package com.ruoyi.web.controller.api;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -10,12 +12,15 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/api")
public class ApiController {
@Autowired
private IApiService apiService;
/**
*
* @return
*/
@GetMapping("/tronInfo")
public R<TronInfoVO> getTronInfo() {
return R.ok(new TronInfoVO());
public R<TronInfoVO> getTronInfo() throws Exception {
TronInfoVO tronInfoVO = apiService.getTronInfo();
return R.ok(tronInfoVO);
}
}

View File

@ -90,7 +90,7 @@ public class TrxExchangeInfoController extends BaseController
@PostMapping("/delegate")
@ResponseBody
public AjaxResult delegate(TrxExchange trxExchange) throws Exception {
return toAjax(trxExchangeInfoService.delegate(trxExchange,false));
return toAjax(trxExchangeInfoService.delegate(trxExchange,false,null));
}
/**

View File

@ -45,6 +45,7 @@ public class AccountAddressInfo extends BaseEntity
/**
*
*/
private String netResource;
/**
@ -61,6 +62,8 @@ public class AccountAddressInfo extends BaseEntity
* trx
*/
private BigDecimal trxBalance;
@Excel(isExport = false)
private long totalEnergyBalance;
//** 创建时间 *//*
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

View File

@ -1,27 +1,6 @@
package com.ruoyi.framework.config;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.Filter;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.config.ConfigurationException;
import org.apache.shiro.io.ResourceUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.CookieRememberMeManager;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.CipherUtils;
@ -38,7 +17,29 @@ import com.ruoyi.framework.shiro.web.filter.online.OnlineSessionFilter;
import com.ruoyi.framework.shiro.web.filter.sync.SyncOnlineSessionFilter;
import com.ruoyi.framework.shiro.web.session.OnlineWebSessionManager;
import com.ruoyi.framework.shiro.web.session.SpringSessionValidationScheduler;
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.config.ConfigurationException;
import org.apache.shiro.io.ResourceUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.CookieRememberMeManager;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
/**
*
@ -301,6 +302,7 @@ public class ShiroConfig
filterChainDefinitionMap.put("/login", "anon,captchaValidate");
// 注册相关
filterChainDefinitionMap.put("/register", "anon,captchaValidate");
filterChainDefinitionMap.put("/api/**", "anon");
// 系统权限列表
// filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll());

View File

@ -4,27 +4,30 @@ package com.ruoyi.quartz.task;
import com.ruoyi.common.core.domain.entity.TenantInfo;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.system.handler.EnergyTenantTransferHandler;
import com.ruoyi.system.service.ITenantInfoService;
import com.ruoyi.system.mapper.TenantInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component("energyTenantTransfer")
@Component("energyTenantTransferTask")
public class EnergyTenantTransferTask {
@Autowired
private ITenantInfoService tenantInfoService;
private TenantInfoMapper tenantInfoMapper;
@Autowired
private EnergyTenantTransferHandler energyTenantTransferHandler;
public void doEnergyTenantTransfer(){
TenantInfo tenantInfoExample = new TenantInfo();
tenantInfoExample.setIsPaid("Y");
tenantInfoExample.setStatus(DictUtils.getDictValue("sys_tenant_status", "生效中"));
List<TenantInfo> tenantInfoList = tenantInfoService.selectTenantInfoList(tenantInfoExample);
List<TenantInfo> tenantInfoList = tenantInfoMapper.selectTenantInfoList(tenantInfoExample);
for (TenantInfo tenantInfo : tenantInfoList) {
String isPaid = tenantInfo.getIsPaid();
if ("N".equals(isPaid)){
continue;
}
energyTenantTransferHandler.doEnergyTenantTransfer(tenantInfo);
}
}

View File

@ -25,14 +25,13 @@ public class UndelegateEnergyTask {
private UndelegateEnergyHandler undelegateEnergyHandler;
public void doUndelegateEnergy() {
String dictValue = DictUtils.getDictValue("sys_delegate_status", "已委托");
TrxExchangeInfo trxExchangeInfoExample = TrxExchangeInfo.builder()
.delegateStatus(dictValue)
.fcd(DateUtil.offsetDay(new Date(),-1))
.fcd(DateUtil.offsetDay(new Date(),-2))
.build();
List<TrxExchangeMonitorAccountInfo> trxExchangeMonitorAccountInfoList = trxExchangeInfoService.selectTrxExchangeMonitorAccountInfo(trxExchangeInfoExample);

View File

@ -1,5 +1,7 @@
package com.ruoyi.system.domain.vo;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.enums.DesensitizedType;
import lombok.Data;
import lombok.experimental.Accessors;
@ -13,6 +15,7 @@ public class TransactionLogVO implements Serializable {
/**
*
*/
@Sensitive(desensitizedType = DesensitizedType.WALLET_ADDRESS)
private String fromAddress;
/**

View File

@ -44,7 +44,7 @@ public class EnergyTenantTransferHandler {
TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder()
.fromAddress(tenantInfo.getReceiverAddress())
.delegateStatus(delegateStatus)
.fcd(DateUtil.offsetDay(new Date(), -1))
.fcd(DateUtil.offsetDay(new Date(), -2))
.build();
List<TrxExchangeMonitorAccountInfo> trxExchangeMonitorAccountInfoList = trxExchangeInfoMapper.selectTrxExchangeMonitorAccountInfo(trxExchangeInfo);
@ -54,7 +54,7 @@ public class EnergyTenantTransferHandler {
}
//赠送每天的能量
tenantInfoService.doDelegateEnergy(tenantInfo);
tenantInfoService.doDelegateEnergy(tenantInfo,"system");
} catch (Exception e) {
String exceptionString = LogUtils.doRecursiveReversePrintStackCause(e, 5, ForwardCounter.builder().count(0).build(), 5);
log.error("获取trx20交易列表异常:{}", exceptionString);

View File

@ -20,9 +20,9 @@ import com.ruoyi.system.dto.TronGridResponse;
import com.ruoyi.system.dto.Value;
import com.ruoyi.system.mapper.ErrorLogMapper;
import com.ruoyi.system.mapper.TenantInfoMapper;
import com.ruoyi.system.mapper.TrxExchangeInfoMapper;
import com.ruoyi.system.service.IAccountAddressInfoService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.impl.TrxExchangeInfoServiceImpl;
import com.ruoyi.system.util.AddressUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
@ -63,7 +63,7 @@ public class TRX2EneryTransferHandler {
@Autowired
private TenantInfoMapper tenantInfoMapper;
@Autowired
private TrxExchangeInfoServiceImpl trxExchangeInfoMapper;
private TrxExchangeInfoMapper trxExchangeInfoMapper;
public void doMonitorTrxTransferByMonitorAddressInfo(MonitorAddressAccount monitorAddressAccount) {

View File

@ -3,6 +3,7 @@ package com.ruoyi.system.mapper;
import com.ruoyi.common.core.domain.entity.TrxExchangeInfo;
import com.ruoyi.system.domain.TrxExchangeMonitorAccountInfo;
import com.ruoyi.system.domain.vo.TransactionLogVO;
import java.util.List;
@ -63,4 +64,6 @@ public interface TrxExchangeInfoMapper
public int deleteTrxExchangeInfoByIdTrxExchangeInfos(String[] idTrxExchangeInfos);
List<TrxExchangeMonitorAccountInfo> selectTrxExchangeMonitorAccountInfo(TrxExchangeInfo trxExchangeInfo);
List<TransactionLogVO> selectTransactionLogVO();
}

View File

@ -66,4 +66,6 @@ public interface IAccountAddressInfoService
String getDecryptPrivateKey(String address) throws Exception;
List<AccountAddressInfo> selectAccountAddressInfoListByResouce(AccountAddressInfo accountAddressInfo) throws Exception;
void doQueryResourceInfo(AccountAddressInfo addressInfo) throws Exception;
}

View File

@ -0,0 +1,8 @@
package com.ruoyi.system.service;
import com.ruoyi.system.domain.vo.TronInfoVO;
public interface IApiService {
TronInfoVO getTronInfo() throws Exception;
}

View File

@ -63,5 +63,7 @@ public interface ITenantInfoService
int activeDataTenantInfoByIdTenantInfos(String ids) throws Exception;
void doDelegateEnergy(TenantInfo tenantInfo) throws Exception;
// void doDelegateEnergy(TenantInfo tenantInfo) throws Exception;
void doDelegateEnergy(TenantInfo tenantInfo, String userName) throws Exception;
}

View File

@ -63,9 +63,10 @@ public interface ITrxExchangeInfoService
*/
public int deleteTrxExchangeInfoByIdTrxExchangeInfo(Long idTrxExchangeInfo);
int delegate(TrxExchange trxExchange,Boolean isTenant) throws Exception;
// int delegate(TrxExchange trxExchange,Boolean isTenant) throws Exception;
int delegate(TrxExchange trxExchange, Boolean isTenant, String userName) throws Exception;
List<TrxExchangeMonitorAccountInfo> selectTrxExchangeMonitorAccountInfo(TrxExchangeInfo trxExchangeInfoExample);
}

View File

@ -150,57 +150,63 @@ public class AccountAddressInfoServiceImpl implements IAccountAddressInfoService
List<AccountAddressInfo> accountAddressInfoList = accountAddressInfoMapper.selectAccountAddressInfoList(accountAddressInfo);
for (AccountAddressInfo addressInfo : accountAddressInfoList) {
String encryptPrivateKey = addressInfo.getEncryptPrivateKey();
String encryptKey = addressInfo.getEncryptKey();
//解密获得秘钥
String decryptPrivateKey = Dt.decrypt(encryptPrivateKey, encryptKey);
String tronApiKey = DictUtils.getDictValue("sys_tron_api_key", "synp@outlook");
ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey,tronApiKey);
String address = addressInfo.getAddress();
Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(address);
//免费带宽使用量
long freeNetUsed = accountResource.getFreeNetUsed();
//免费带宽上限
long freeNetLimit = accountResource.getFreeNetLimit();
//网络带宽消耗
long netUsed = accountResource.getNetUsed();
//网络上限
long netLimit = accountResource.getNetLimit();
//能量消耗
long energyUsed = accountResource.getEnergyUsed();
//能量上限
long energyLimit = accountResource.getEnergyLimit();
long totalNetUsed = freeNetUsed + netUsed;
long taotalNetLimit = freeNetLimit + netLimit;
long totalNetBalance = taotalNetLimit - totalNetUsed;
long totalEnergyBalance = energyLimit - energyUsed;
addressInfo.setNetResource(totalNetBalance + "/" + taotalNetLimit);
addressInfo.setEnergyResource(totalEnergyBalance + "/" + energyLimit);
Response.Account account = apiWrapper.getAccount(address);
long balance = account.getBalance();
List<Response.Account.FreezeV2> frozenV2List = account.getFrozenV2List();
Long totalFrozen = 0L;
for (Response.Account.FreezeV2 freezeV2 : frozenV2List) {
totalFrozen += freezeV2.getAmount();
}
addressInfo.setTrxBalance(BigDecimal.valueOf(balance).movePointLeft(6));
addressInfo.setTotalFrozen(BigDecimal.valueOf(totalFrozen).movePointLeft(6));
doQueryResourceInfo(addressInfo);
}
return accountAddressInfoList;
}
@Override
public void doQueryResourceInfo(AccountAddressInfo addressInfo) throws Exception {
String encryptPrivateKey = addressInfo.getEncryptPrivateKey();
String encryptKey = addressInfo.getEncryptKey();
//解密获得秘钥
String decryptPrivateKey = Dt.decrypt(encryptPrivateKey, encryptKey);
String tronApiKey = DictUtils.getDictValue("sys_tron_api_key", "synp@outlook");
ApiWrapper apiWrapper = ApiWrapper.ofMainnet(decryptPrivateKey,tronApiKey);
String address = addressInfo.getAddress();
Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(address);
//免费带宽使用量
long freeNetUsed = accountResource.getFreeNetUsed();
//免费带宽上限
long freeNetLimit = accountResource.getFreeNetLimit();
//网络带宽消耗
long netUsed = accountResource.getNetUsed();
//网络上限
long netLimit = accountResource.getNetLimit();
//能量消耗
long energyUsed = accountResource.getEnergyUsed();
//能量上限
long energyLimit = accountResource.getEnergyLimit();
long totalNetUsed = freeNetUsed + netUsed;
long taotalNetLimit = freeNetLimit + netLimit;
long totalNetBalance = taotalNetLimit - totalNetUsed;
long totalEnergyBalance = energyLimit - energyUsed;
addressInfo.setNetResource(totalNetBalance + "/" + taotalNetLimit);
addressInfo.setEnergyResource(totalEnergyBalance + "/" + energyLimit);
addressInfo.setTotalEnergyBalance(totalEnergyBalance);
Response.Account account = apiWrapper.getAccount(address);
long balance = account.getBalance();
List<Response.Account.FreezeV2> frozenV2List = account.getFrozenV2List();
Long totalFrozen = 0L;
for (Response.Account.FreezeV2 freezeV2 : frozenV2List) {
totalFrozen += freezeV2.getAmount();
}
addressInfo.setTrxBalance(BigDecimal.valueOf(balance).movePointLeft(6));
addressInfo.setTotalFrozen(BigDecimal.valueOf(totalFrozen).movePointLeft(6));
}
}

View File

@ -0,0 +1,84 @@
package com.ruoyi.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.entity.AccountAddressInfo;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.system.domain.vo.TransactionLogVO;
import com.ruoyi.system.domain.vo.TronInfoVO;
import com.ruoyi.system.handler.Usdt2TrxTransferHandler;
import com.ruoyi.system.mapper.TrxExchangeInfoMapper;
import com.ruoyi.system.service.IAccountAddressInfoService;
import com.ruoyi.system.service.IApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Service
public class ApiServiceImpl implements IApiService {
@Autowired
private IAccountAddressInfoService accountAddressInfoService;
@Autowired
private Usdt2TrxTransferHandler usdt2TrxTransferHandler;
@Autowired
private TrxExchangeInfoMapper trxExchangeInfoMapper;
@Override
public TronInfoVO getTronInfo() throws Exception {
TronInfoVO tronInfoVO = new TronInfoVO();
CompletableFuture<Void> queryTrxBalanceFuture = CompletableFuture.runAsync(() -> {
AccountAddressInfo accountAddressInfoExample = new AccountAddressInfo();
accountAddressInfoExample.setBusiType(DictUtils.getDictValue("sys_busi_type", "TRX兑能量"));
List<AccountAddressInfo> accountAddressInfoList = accountAddressInfoService.selectAccountAddressInfoList(accountAddressInfoExample);
if (CollectionUtil.isNotEmpty(accountAddressInfoList)) {
AccountAddressInfo accountAddressInfo = accountAddressInfoList.get(0);
try {
accountAddressInfoService.doQueryResourceInfo(accountAddressInfo);
} catch (Exception e) {
throw new RuntimeException(e);
}
long trxBalance = accountAddressInfo.getTotalEnergyBalance();
Long balance = trxBalance + 221000000L;
tronInfoVO.setEnergyRemaining(balance.toString());
}
}).exceptionally(e -> {
throw new RuntimeException(e);
});
CompletableFuture<Void> queryOkxFuture = CompletableFuture.runAsync(() -> {
BigDecimal oneUsdtToTrx = null;
try {
oneUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx();
// oneUsdtToTrx = BigDecimal.valueOf(7.53);
} catch (Exception e) {
throw new RuntimeException(e);
}
tronInfoVO.setUsdt2TrxPrice(oneUsdtToTrx.toString());
}).exceptionally(e -> {
throw new RuntimeException(e);
});
CompletableFuture<Void> queryDatabaseFuture = CompletableFuture.runAsync(() -> {
PageHelper.startPage(0, 10).setReasonable(true);
List<TransactionLogVO> transactionLogVOList = trxExchangeInfoMapper.selectTransactionLogVO();
for (TransactionLogVO transactionLogVO : transactionLogVOList) {
transactionLogVO.setBusiType("TRX => Energy");
Integer energyCount = Integer.valueOf(transactionLogVO.getCount()) * 32000;
transactionLogVO.setCount(energyCount.toString());
}
tronInfoVO.setTransactionLogList(transactionLogVOList);
}).exceptionally(e -> {
throw new RuntimeException(e);
});
CompletableFuture.allOf(queryTrxBalanceFuture, queryOkxFuture, queryDatabaseFuture).join();
return tronInfoVO;
}
}

View File

@ -180,14 +180,14 @@ public class TenantInfoServiceImpl implements ITenantInfoService
Preconditions.checkState(CollectionUtil.isEmpty(trxExchangeInfos), "该接收能量地址已在任务中,请勿重复发起");
doDelegateEnergy(tenantInfo);
doDelegateEnergy(tenantInfo,null);
}
return 1;
}
@Override
public void doDelegateEnergy(TenantInfo tenantInfo) throws Exception {
public void doDelegateEnergy(TenantInfo tenantInfo, String userName) throws Exception {
String accountAddress = null;
String monitorAddress = null;
if (StringUtils.isNotEmpty(tenantInfo.getMonitorAddress())){
@ -225,9 +225,12 @@ public class TenantInfoServiceImpl implements ITenantInfoService
long between = DateUtil.between(DateUtil.date(), DateUtil.endOfDay(DateUtil.date()), DateUnit.HOUR);
trxExchange.setLockNum(between + 1);
trxExchangeInfoService.delegate(trxExchange, true);
userName = userName == null ? ShiroUtils.getLoginName() : userName;
trxExchangeInfoService.delegate(trxExchange, true,userName);
tenantInfo.setDelegatedDays(tenantInfo.getDelegatedDays() + 1);
tenantInfo.setLcd(new Date());
tenantInfoMapper.updateTenantInfo(tenantInfo);
}

View File

@ -121,7 +121,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
}
@Override
public int delegate(TrxExchange trxExchange, Boolean isTenant) throws Exception {
public int delegate(TrxExchange trxExchange, Boolean isTenant, String userName) throws Exception {
//转账笔数
Long transferNumber = trxExchange.getTransferNumber();
//实际锁定周期
@ -129,7 +129,8 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
String fromAddress = trxExchange.getFromAddress();
String userName = ShiroUtils.getLoginName();
userName = userName == null ? ShiroUtils.getLoginName() : userName;
String sysEnergyBusiType = DictUtils.getDictValue("sys_energy_busi_type", "闪兑套餐");
if (isTenant) {
sysEnergyBusiType = DictUtils.getDictValue("sys_energy_busi_type", "天数套餐");

View File

@ -183,4 +183,8 @@
and a.busi_type = 'trx2Energy'
<if test="fromAddress != null and fromAddress != ''"> and t.from_address = #{fromAddress}</if>
</select>
<select id="selectTransactionLogVO" resultType="com.ruoyi.system.domain.vo.TransactionLogVO">
select distinct t.from_address fromAddress,t.tranfer_count count from trx_exchange_info t
</select>
</mapper>