定时人物迁移
This commit is contained in:
1 parent
c0868f9d8f
commit
32e7466615
2 files changed
+5
-4
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package com.ruoyi.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.system.domain.UsdtOrdersPlus;
|
||||
import com.ruoyi.system.service.IUsdtOrdersService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/** 支付订单生命周期任务:先处理过期订单,链上入账由独立扫描器补充。 */
|
||||
@Component
|
||||
public class PaymentOrderExpireTask {
|
||||
@Autowired private IUsdtOrdersService orders;
|
||||
|
||||
@Scheduled(fixedDelay = 30000L)
|
||||
public void expireOrders() {
|
||||
LambdaQueryWrapper<UsdtOrdersPlus> query = new LambdaQueryWrapper<UsdtOrdersPlus>()
|
||||
.eq(UsdtOrdersPlus::getStatus, 1)
|
||||
.isNotNull(UsdtOrdersPlus::getCreatedAt)
|
||||
.lt(UsdtOrdersPlus::getCreatedAt, new Date(System.currentTimeMillis() - 30 * 60 * 1000L));
|
||||
for (UsdtOrdersPlus order : orders.list(query)) {
|
||||
order.setStatus(3L);
|
||||
order.setUpdatedAt(new Date());
|
||||
orders.updateById(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.ruoyi.task;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.system.domain.UsdtOrdersPlus;
|
||||
import com.ruoyi.system.service.ITronService;
|
||||
import com.ruoyi.system.service.IUsdtOrdersService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 轮询已确认 TRC20 转账,按地址、六位金额和唯一交易哈希入账。
|
||||
*/
|
||||
@Component
|
||||
public class TronPaymentTask {
|
||||
@Autowired
|
||||
private IUsdtOrdersService orders;
|
||||
@Autowired
|
||||
private ITronService tron;
|
||||
private final RestTemplate http = new RestTemplate();
|
||||
|
||||
@Scheduled(fixedDelay = 30000L)
|
||||
public void scan() {
|
||||
for (UsdtOrdersPlus order : orders.list(new LambdaQueryWrapper<UsdtOrdersPlus>().eq(UsdtOrdersPlus::getStatus, 1))) {
|
||||
if (order.getToken() == null || order.getActualAmount() == null) continue;
|
||||
try {
|
||||
String url = tron.tronscanApiUrl() + "/v1/accounts/" + order.getToken() + "/transactions/trc20?limit=200&only_confirmed=true&contract_address=" + tron.contractAddress();
|
||||
JSONObject root = JSON.parseObject(http.getForObject(url, String.class));
|
||||
JSONArray data = root == null ? null : root.getJSONArray("data");
|
||||
if (data == null) continue;
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject tx = data.getJSONObject(i);
|
||||
if (!order.getToken().equals(tx.getString("to"))) continue;
|
||||
BigDecimal value = new BigDecimal(tx.getString("value")).movePointLeft(6).setScale(6, RoundingMode.DOWN);
|
||||
if (value.compareTo(order.getActualAmount().setScale(6, RoundingMode.DOWN)) != 0) continue;
|
||||
String hash = tx.getString("transaction_id");
|
||||
if (hash == null || hash.trim().isEmpty()) continue;
|
||||
if (orders.count(new LambdaQueryWrapper<UsdtOrdersPlus>().eq(UsdtOrdersPlus::getBlockTransactionId, hash)) > 0)
|
||||
continue;
|
||||
order.setBlockTransactionId(hash);
|
||||
order.setStatus(2L);
|
||||
order.setUpdatedAt(new Date());
|
||||
orders.updateById(order);
|
||||
break;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user