This commit is contained in:
lu7213 committed 2026-03-03 09:39:33 +08:00
1 parent 68a2b4f68c
commit 7cd697187c
308 files changed
+30454 -75

No files matched your search

@@ -13,7 +13,7 @@ import org.springframework.context.annotation.Bean;
* @author ruoyi
*/
@SpringBootApplication(scanBasePackages = {
"com.ruoyi", "com.luqj"}, exclude = {DataSourceAutoConfiguration.class})
"com.ruoyi", "com.luqj","org.code.modules.plugins",}, exclude = {DataSourceAutoConfiguration.class})
@MapperScan({
"com.luqj.*.mapper",
"com.ruoyi.*.mapper"
@@ -0,0 +1,130 @@
package com.ruoyi.task;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.tron.trident.core.ApiWrapper;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Slf4j
@Component("AggregationTask")
public class AggregationTask {
@Autowired
private IUsdtAggregationTaskService usdtAggregationTaskService;
@Autowired
private IUsdtAggregationTaskItemService usdtAggregationTaskItemService;
@Autowired
private ITronService tronService;
@Autowired
private IUsdtFundFlowService usdtFundFlowService;
@Autowired
private IWalletAddressService walletAddressService;
@Autowired
private IWeb3WalletService web3WalletService;
@Scheduled(cron = "0 */10 * * * ?")
// @Scheduled(cron = "0/10 * * * * ?")
public void execute() {
List<UsdtAggregationTaskPlus> taskPluses = this.usdtAggregationTaskService.getListByStatusAndLtExeTime(0, new Date());
for (UsdtAggregationTaskPlus taskPlus : taskPluses) {
Web3WalletPlus web3Wallet = this.web3WalletService.getById(taskPlus.getUserId());
if (web3Wallet == null) {
web3Wallet = new Web3WalletPlus();
web3Wallet.setId(taskPlus.getUserId());
web3Wallet.setPassword(UUID.randomUUID().toString());
web3Wallet.setEthBalance(new BigDecimal(0));
web3Wallet.setTrxBalance(new BigDecimal(0));
web3Wallet.setUsdtBalance(new BigDecimal(0));
web3Wallet.setCreatedAt(new Date());
web3Wallet.setUpdatedAt(new Date());
this.web3WalletService.save(web3Wallet);
}
List<UsdtAggregationTaskItemPlus> itemPluses = this.usdtAggregationTaskItemService.getListByStatusAndParentId(0, taskPlus.getId());
int success = 0;
for (UsdtAggregationTaskItemPlus itemPlus : itemPluses) {
WalletAddressPlus walletAddressPlus = walletAddressService.getByTokenAndAppId(itemPlus.getTokenAddress(), itemPlus.getAppId());
if(walletAddressPlus.getUpdatedAt().getTime()< itemPlus.getCreatedAt().getTime()){
itemPlus.setStatus(0);
itemPlus.setRemark("等待钱包更新");
usdtAggregationTaskItemService.updateById(itemPlus);
continue;
}
ApiWrapper api = tronService.buildApiWrapper(walletAddressPlus.getTokenKey());
try {
if(walletAddressPlus.getEnergyNum() < tronService.defaultEstimateEnergy()){
itemPlus.setStatus(0);
itemPlus.setRemark("能量不足,需要手续费");
usdtAggregationTaskItemService.updateById(itemPlus);
continue;
}
long bandwidth = tronService.defaultEstimateBandwidth();
if(bandwidth > walletAddressPlus.getBandwidthNum()){
itemPlus.setStatus(0);
itemPlus.setRemark("带宽不足需要手续费");
usdtAggregationTaskItemService.updateById(itemPlus);
continue;
}
if(bandwidth > walletAddressPlus.getBandwidthStakedNum()
&& bandwidth > (walletAddressPlus.getBandwidthNum()-walletAddressPlus.getBandwidthStakedNum())){
itemPlus.setStatus(0);
itemPlus.setRemark("代理|免费带宽不足需要手续费");
usdtAggregationTaskItemService.updateById(itemPlus);
continue;
}
if(walletAddressPlus.getWithdrawUsdtBalance().subtract(itemPlus.getOpeAmount()).doubleValue() < 0){
itemPlus.setStatus(2);
itemPlus.setRemark("超额或者重复提现,请排查");
usdtAggregationTaskItemService.updateById(itemPlus);
continue;
}
String result = this.tronService.usdtTrans(api, itemPlus.getTokenAddress(), itemPlus.getDistTokenAddress(), itemPlus.getOpeAmount().toString());
//验证是否成功 TODO
if (StringUtils.isNotEmpty(result)) {
itemPlus.setStatus(1);
itemPlus.setRemark(result);
walletAddressPlus.setWithdrawUsdtBalance(walletAddressPlus.getWithdrawUsdtBalance().subtract(itemPlus.getOpeAmount()));
web3Wallet.setUsdtBalance(web3Wallet.getUsdtBalance().subtract(itemPlus.getOpeAmount()));
UsdtFundFlowPlus shFlow = new UsdtFundFlowPlus();
shFlow.setAppId(itemPlus.getAppId());
shFlow.setAmount(itemPlus.getOpeAmount());
shFlow.setOrderId(itemPlus.getId());
shFlow.setOpType(2);
shFlow.setUserId(itemPlus.getUserId());
shFlow.setToken(itemPlus.getTokenAddress());
shFlow.setRemark("归集成功");
shFlow.setCreatedAt(new Date());
shFlow.setUpdatedAt(new Date());
this.usdtFundFlowService.save(shFlow);
this.web3WalletService.updateById(web3Wallet);
this.walletAddressService.updateById(walletAddressPlus);
success++;
} else {
itemPlus.setStatus(0);
itemPlus.setRemark("归集失败");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
itemPlus.setStatus(0);
itemPlus.setRemark(e.getMessage());
}
itemPlus.setUpdatedAt(new Date());
this.usdtAggregationTaskItemService.updateById(itemPlus);
api.close();
}
if(success == itemPluses.size() && itemPluses.size() > 0){
taskPlus.setStatus(1);
this.usdtAggregationTaskService.updateById(taskPlus);
}
}
}
}
@@ -1,20 +1,13 @@
package com.ruoyi.task;
import com.ruoyi.system.domain.UsdtFundFlow;
import com.ruoyi.system.domain.UsdtFundFlowPlus;
import com.ruoyi.system.domain.UsdtOrdersPlus;
import com.ruoyi.system.domain.UsdtUserSettlementConfigurationPlus;
import com.ruoyi.system.service.IUsdtFundFlowService;
import com.ruoyi.system.service.IUsdtOrdersService;
import com.ruoyi.system.service.IUsdtUserSettlementConfigurationService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component("splitAccountsTask")
public class SplitAccountsTask {
@@ -24,14 +17,26 @@ public class SplitAccountsTask {
private IUsdtUserSettlementConfigurationService usdtUserSettlementConfigurationService;
@Autowired
private IUsdtFundFlowService usdtFundFlowService;
@Autowired
private IWalletAddressService walletAddressService;
@Autowired
private IWeb3WalletService web3WalletService;
// @Scheduled(cron = "0/10 * * * * ?")
@Scheduled(cron = "0 */10 * * * ?")
public void execute() {
List<UsdtOrdersPlus> list = usdtOrdersService.getWillSettlement(1000);
Map<Long, UsdtUserSettlementConfigurationPlus> configMap = new HashMap<Long, UsdtUserSettlementConfigurationPlus>();
List<UsdtFundFlowPlus> fundFlows = new ArrayList<UsdtFundFlowPlus>();
List<Long> ids = new ArrayList<>();
Map<Long, Web3WalletPlus> web3WalletMap = new HashMap<>();
for (UsdtOrdersPlus usdtOrdersPlus : list) {
WalletAddressPlus walletAddressPlus = walletAddressService.getByTokenAndAppId(usdtOrdersPlus.getToken(),usdtOrdersPlus.getAppId()
,WalletAddressPlus::getId,WalletAddressPlus::getWithdrawUsdtBalance);
if(walletAddressPlus.getWithdrawUsdtBalance() == null){
walletAddressPlus.setWithdrawUsdtBalance(new BigDecimal(0));
}
UsdtUserSettlementConfigurationPlus config = configMap.getOrDefault(usdtOrdersPlus.getUserId(), usdtUserSettlementConfigurationService.getByUserId(usdtOrdersPlus.getUserId()));
BigDecimal yj = usdtOrdersPlus.getActualAmount().multiply(config.getCommissionRate());
BigDecimal yj = usdtOrdersPlus.getActualAmount().multiply(config.getCommissionRate());
UsdtFundFlowPlus yjFlow = new UsdtFundFlowPlus();
yjFlow.setAppId(usdtOrdersPlus.getAppId());
yjFlow.setAmount(yj);
@@ -40,6 +45,23 @@ public class SplitAccountsTask {
yjFlow.setUserId(usdtOrdersPlus.getUserId());
yjFlow.setToken(usdtOrdersPlus.getToken());
Web3WalletPlus web3Wallet = web3WalletMap.get(usdtOrdersPlus.getUserId());
if (web3Wallet == null) {
web3Wallet = new Web3WalletPlus();
web3Wallet.setId(usdtOrdersPlus.getUserId());
web3Wallet.setPassword(UUID.randomUUID().toString());
web3Wallet.setEthBalance(new BigDecimal(0));
web3Wallet.setTrxBalance(new BigDecimal(0));
web3Wallet.setUsdtBalance(new BigDecimal(0));
web3Wallet.setCreatedAt(new Date());
web3Wallet.setUpdatedAt(new Date());
this.web3WalletService.save(web3Wallet);
} else {
web3Wallet.setUpdatedAt(new Date());
}
web3Wallet.setUsdtBalance(web3Wallet.getUsdtBalance().add(usdtOrdersPlus.getActualAmount().subtract(yj)));
web3WalletMap.put(usdtOrdersPlus.getUserId(), web3Wallet);
UsdtFundFlowPlus shFlow = new UsdtFundFlowPlus();
shFlow.setAppId(usdtOrdersPlus.getAppId());
shFlow.setAmount(usdtOrdersPlus.getActualAmount().subtract(yj));
@@ -47,16 +69,25 @@ public class SplitAccountsTask {
shFlow.setOpType(0);
shFlow.setUserId(usdtOrdersPlus.getUserId());
shFlow.setToken(usdtOrdersPlus.getToken());
walletAddressPlus.setWithdrawUsdtBalance(walletAddressPlus.getWithdrawUsdtBalance().add(shFlow.getAmount()));
fundFlows.add(yjFlow);
fundFlows.add(shFlow);
ids.add(usdtOrdersPlus.getId());
this.walletAddressService.updateWithdrawUsdtBalanceById(walletAddressPlus.getId(),walletAddressPlus.getWithdrawUsdtBalance());
}
if(!fundFlows.isEmpty()){
Iterator<Map.Entry<Long, Web3WalletPlus>> iterator = web3WalletMap.entrySet().iterator();
List<Web3WalletPlus> updates = new ArrayList<>();
while (iterator.hasNext()) {
updates.add(iterator.next().getValue());
}
if (!updates.isEmpty()) {
web3WalletService.updateBatchById(updates);
}
if (!fundFlows.isEmpty()) {
usdtFundFlowService.saveBatch(fundFlows);
}
if(ids.isEmpty()){
this.usdtOrdersService.updateSettlementStatusByIds(ids,1);
if (!ids.isEmpty()) {
this.usdtOrdersService.updateSettlementStatusByIds(ids, 1);
}
}
}
@@ -0,0 +1,74 @@
package com.ruoyi.task;
import com.ruoyi.system.domain.WalletAddressPlus;
import com.ruoyi.system.domain.vo.EnergyAndBandwidthVo;
import com.ruoyi.system.service.ITronService;
import com.ruoyi.system.service.IWalletAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.tron.trident.core.ApiWrapper;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Slf4j
@Component("WalletAddressTask")
public class WalletAddressTask {
@Autowired
private ITronService tronService;
@Autowired
private IWalletAddressService walletAddressService;
// @Scheduled(cron = "0/5 * * * * ?")
@Scheduled(cron = "0 */10 * * * ?")
public void execute() {
List<WalletAddressPlus> walletAddressPluses = walletAddressService.list();
for (WalletAddressPlus walletAddressPlus : walletAddressPluses) {
ApiWrapper api = tronService.buildApiWrapper(walletAddressPlus.getTokenKey());
BigDecimal amout = tronService.getUsdtBalance(api,walletAddressPlus.getToken());
walletAddressPlus.setUsdtBalance(amout);
amout = tronService.getTRxBalance(api,walletAddressPlus.getToken());
walletAddressPlus.setTrxBalance(amout);
EnergyAndBandwidthVo energyAndBandwidthVo = tronService.energyAndBandwidth(walletAddressPlus.getToken());
walletAddressPlus.setEnergyNum(energyAndBandwidthVo.getEnergy().longValue());
walletAddressPlus.setBandwidthNum(energyAndBandwidthVo.getBandwidth().longValue());
amout = tronService.votedBalance(api,walletAddressPlus.getToken());
walletAddressPlus.setVotedNum(amout.longValue());
amout = tronService.stakedTrxBalance(api,walletAddressPlus.getToken(),1);
walletAddressPlus.setEnergyStakedTrxNum(amout.longValue());
amout = tronService.stakedTrxBalance(api,walletAddressPlus.getToken(),0);
walletAddressPlus.setBandwidthStakedTrxNum(amout.longValue());
energyAndBandwidthVo = tronService.allDelegatedDnergyAndBandwidth(walletAddressPlus.getToken());
walletAddressPlus.setAcquiredDelegatedBandwidthValue(energyAndBandwidthVo.getAcquiredBandwidth());
walletAddressPlus.setAcquiredDelegatedEnergyValue(energyAndBandwidthVo.getAcquiredEnergy());
walletAddressPlus.setDelegatedBandwidthValue(energyAndBandwidthVo.getDelegateBandwidth());
walletAddressPlus.setDelegatedEnergyValue(energyAndBandwidthVo.getDelegateEnergy());
walletAddressPlus.setBandwidthStakedNum(energyAndBandwidthVo.getBandwidthStakedNum());
amout = tronService.delegatedStakedTrxBalance(api,walletAddressPlus.getToken(),1);
walletAddressPlus.setDelegatedEnergyTrxNum(amout.longValue());
amout = tronService.delegatedStakedTrxBalance(api,walletAddressPlus.getToken(),0);
walletAddressPlus.setDelegatedBandwidthTrxNum(amout.longValue());
amout = tronService.acquiredDelegatedStakedTrxBalance(api,walletAddressPlus.getToken(),1);
walletAddressPlus.setAcquiredDelegatedEnergyTrxNum(amout.longValue());
amout = tronService.acquiredDelegatedStakedTrxBalance(api,walletAddressPlus.getToken(),0);
walletAddressPlus.setAcquiredDelegatedBandwidthTrxNum(amout.longValue());
amout = tronService.voteBalance(api,walletAddressPlus.getToken());
walletAddressPlus.setVoteNum(amout.longValue()+walletAddressPlus.getDelegatedBandwidthTrxNum()+ walletAddressPlus.getDelegatedEnergyTrxNum());
walletAddressPlus.setStakedTrxNum(walletAddressPlus.getVoteNum());
if(walletAddressPlus.getStakedTrxNum() != energyAndBandwidthVo.getStakedTrxNum().longValue()){
log.error("please check stakedTrxNum is true");
walletAddressPlus.setStakedTrxNum(energyAndBandwidthVo.getStakedTrxNum());
walletAddressPlus.setVoteNum(walletAddressPlus.getStakedTrxNum());
}
walletAddressPlus.setUpdatedAt(new Date());
walletAddressService.updateById(walletAddressPlus);
api.close();
}
}
}