代码格式化
This commit is contained in:
1 parent
e4ac32e8d7
commit
9c29db1245
2 files changed
+114
-39
No files matched your search
@@ -6,36 +6,32 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.system.domain.TelegramAuditRecord;
|
import com.ruoyi.system.domain.TelegramAuditRecord;
|
||||||
import com.ruoyi.system.mapper.TelegramAuditMapper;
|
import com.ruoyi.system.mapper.TelegramAuditMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.event.TransactionPhase;
|
import org.springframework.transaction.event.TransactionPhase;
|
||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
||||||
import org.springframework.web.client.RestClientResponseException;
|
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestClientResponseException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/** Telegram归集审核服务:只改变审核决定,不执行归集或接触钱包密钥。 */
|
/**
|
||||||
|
* Telegram归集审核服务:只改变审核决定,不执行归集或接触钱包密钥。
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class TelegramAuditService {
|
public class TelegramAuditService {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TelegramAuditService.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(TelegramAuditService.class);
|
||||||
@@ -49,12 +45,18 @@ public class TelegramAuditService {
|
|||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
@Value("${telegram.enabled:false}") private boolean enabled;
|
@Value("${telegram.enabled:false}")
|
||||||
@Value("${telegram.bot-token:}") private String botToken;
|
private boolean enabled;
|
||||||
@Value("${telegram.audit-chat-id:}") private String auditChatId;
|
@Value("${telegram.bot-token:}")
|
||||||
@Value("${telegram.webhook-secret:}") private String webhookSecret;
|
private String botToken;
|
||||||
@Value("${telegram.webhook-url:}") private String webhookUrl;
|
@Value("${telegram.audit-chat-id:}")
|
||||||
@Value("${telegram.allowed-user-ids:}") private String allowedUserIds;
|
private String auditChatId;
|
||||||
|
@Value("${telegram.webhook-secret:}")
|
||||||
|
private String webhookSecret;
|
||||||
|
@Value("${telegram.webhook-url:}")
|
||||||
|
private String webhookUrl;
|
||||||
|
@Value("${telegram.allowed-user-ids:}")
|
||||||
|
private String allowedUserIds;
|
||||||
|
|
||||||
public TelegramAuditService(TelegramAuditMapper mapper, UsdtAggregationWorkflowService workflow,
|
public TelegramAuditService(TelegramAuditMapper mapper, UsdtAggregationWorkflowService workflow,
|
||||||
PayoutOrderService payoutOrderService,
|
PayoutOrderService payoutOrderService,
|
||||||
@@ -86,7 +88,9 @@ public class TelegramAuditService {
|
|||||||
return getWebhookInfo();
|
return getWebhookInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 查询Telegram当前Webhook状态,仅返回运维所需的非敏感字段。 */
|
/**
|
||||||
|
* 查询Telegram当前Webhook状态,仅返回运维所需的非敏感字段。
|
||||||
|
*/
|
||||||
public Map<String, Object> getWebhookInfo() {
|
public Map<String, Object> getWebhookInfo() {
|
||||||
validateBotConfiguration();
|
validateBotConfiguration();
|
||||||
JSONObject response = invokeTelegramApi("getWebhookInfo", Collections.emptyMap());
|
JSONObject response = invokeTelegramApi("getWebhookInfo", Collections.emptyMap());
|
||||||
@@ -165,7 +169,9 @@ public class TelegramAuditService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建归集审核记录及持久化推送任务。业务唯一键防止重复建单。 */
|
/**
|
||||||
|
* 创建归集审核记录及持久化推送任务。业务唯一键防止重复建单。
|
||||||
|
*/
|
||||||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
|
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
|
||||||
public void onCreated(TelegramAggregationAuditEvent event) {
|
public void onCreated(TelegramAggregationAuditEvent event) {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
@@ -206,26 +212,44 @@ public class TelegramAuditService {
|
|||||||
mapper.insertPushTask(record.getAuditNo(), now, now);
|
mapper.insertPushTask(record.getAuditNo(), now, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 代付事务提交后创建审核记录,Telegram不可直接执行资金操作。 */
|
/**
|
||||||
|
* 代付事务提交后创建审核记录,Telegram不可直接执行资金操作。
|
||||||
|
*/
|
||||||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
|
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
|
||||||
public void onPayoutCreated(TelegramPayoutAuditEvent event) {
|
public void onPayoutCreated(TelegramPayoutAuditEvent event) {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
transactionTemplate.execute(status -> { createPayoutAuditRecord(event); return null; });
|
|
||||||
|
transactionTemplate.execute(status -> {
|
||||||
|
createPayoutAuditRecord(event);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPayoutAuditRecord(TelegramPayoutAuditEvent event) {
|
private void createPayoutAuditRecord(TelegramPayoutAuditEvent event) {
|
||||||
if (mapper.selectByBusiness(PAYOUT_BUSINESS_TYPE, String.valueOf(event.getId())) != null) return;
|
if (mapper.selectByBusiness(PAYOUT_BUSINESS_TYPE, String.valueOf(event.getId())) != null) return;
|
||||||
Date now = new Date(); TelegramAuditRecord record = new TelegramAuditRecord();
|
Date now = new Date();
|
||||||
|
TelegramAuditRecord record = new TelegramAuditRecord();
|
||||||
record.setAuditNo("PO-" + event.getId() + "-" + UUID.randomUUID().toString().substring(0, 8));
|
record.setAuditNo("PO-" + event.getId() + "-" + UUID.randomUUID().toString().substring(0, 8));
|
||||||
record.setBusinessType(PAYOUT_BUSINESS_TYPE); record.setBusinessId(String.valueOf(event.getId()));
|
record.setBusinessType(PAYOUT_BUSINESS_TYPE);
|
||||||
record.setTitle("应用代付审核"); record.setAuditStatus("PENDING");
|
record.setBusinessId(String.valueOf(event.getId()));
|
||||||
JSONObject payload = new JSONObject(); payload.put("orderId", event.getOrderId()); payload.put("currency", event.getCurrency());
|
record.setTitle("应用代付审核");
|
||||||
payload.put("amount", event.getAmount()); payload.put("address", event.getAddress()); payload.put("fee", event.getFee());
|
record.setAuditStatus("PENDING");
|
||||||
record.setPayload(payload.toJSONString()); record.setCreatedAt(now); record.setUpdatedAt(now);
|
JSONObject payload = new JSONObject();
|
||||||
mapper.insertRecord(record); mapper.insertPushTask(record.getAuditNo(), now, now);
|
payload.put("orderId", event.getOrderId());
|
||||||
|
payload.put("currency", event.getCurrency());
|
||||||
|
payload.put("amount", event.getAmount());
|
||||||
|
payload.put("address", event.getAddress());
|
||||||
|
payload.put("fee", event.getFee());
|
||||||
|
record.setPayload(payload.toJSONString());
|
||||||
|
record.setCreatedAt(now);
|
||||||
|
record.setUpdatedAt(now);
|
||||||
|
mapper.insertRecord(record);
|
||||||
|
mapper.insertPushTask(record.getAuditNo(), now, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** update_id先占位防重;归集审核与Telegram最终状态在同一事务内提交。 */
|
/**
|
||||||
|
* update_id先占位防重;归集审核与Telegram最终状态在同一事务内提交。
|
||||||
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void handleUpdate(JSONObject update) {
|
public void handleUpdate(JSONObject update) {
|
||||||
JSONObject callback = update == null ? null : update.getJSONObject("callback_query");
|
JSONObject callback = update == null ? null : update.getJSONObject("callback_query");
|
||||||
@@ -283,7 +307,9 @@ public class TelegramAuditService {
|
|||||||
afterCommit(callbackId, record, approved ? "审核通过" : "审核拒绝");
|
afterCommit(callbackId, record, approved ? "审核通过" : "审核拒绝");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 后台审核与Telegram审核共用最终状态,防止两个入口给出相反决定。 */
|
/**
|
||||||
|
* 后台审核与Telegram审核共用最终状态,防止两个入口给出相反决定。
|
||||||
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void reviewFromBackoffice(Long taskId, boolean approved) {
|
public void reviewFromBackoffice(Long taskId, boolean approved) {
|
||||||
workflow.approve(taskId, approved);
|
workflow.approve(taskId, approved);
|
||||||
@@ -304,15 +330,21 @@ public class TelegramAuditService {
|
|||||||
afterCommit(null, record, approved ? "审核通过" : "审核拒绝");
|
afterCommit(null, record, approved ? "审核通过" : "审核拒绝");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 后台审核代付并同步Telegram审核单状态。 */
|
/**
|
||||||
|
* 后台审核代付并同步Telegram审核单状态。
|
||||||
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void reviewPayoutFromBackoffice(Long payoutId, boolean approved, String remark) {
|
public void reviewPayoutFromBackoffice(Long payoutId, boolean approved, String remark) {
|
||||||
payoutOrderService.review(payoutId, approved, "BACKOFFICE", SecurityUtils.getUsername(), remark);
|
payoutOrderService.review(payoutId, approved, "BACKOFFICE", SecurityUtils.getUsername(), remark);
|
||||||
TelegramAuditRecord record = mapper.selectByBusiness(PAYOUT_BUSINESS_TYPE, String.valueOf(payoutId));
|
TelegramAuditRecord record = mapper.selectByBusiness(PAYOUT_BUSINESS_TYPE, String.valueOf(payoutId));
|
||||||
if (record == null || !"PENDING".equals(record.getAuditStatus())) return;
|
if (record == null || !"PENDING".equals(record.getAuditStatus())) return;
|
||||||
String status = approved ? "APPROVED" : "REJECTED"; Date now = new Date();
|
String status = approved ? "APPROVED" : "REJECTED";
|
||||||
|
Date now = new Date();
|
||||||
mapper.approve(record.getAuditNo(), status, "SYSTEM", SecurityUtils.getUsername(), now, now);
|
mapper.approve(record.getAuditNo(), status, "SYSTEM", SecurityUtils.getUsername(), now, now);
|
||||||
record.setAuditStatus(status); record.setReviewerTelegramId("SYSTEM"); record.setReviewerName(SecurityUtils.getUsername()); record.setReviewedAt(now);
|
record.setAuditStatus(status);
|
||||||
|
record.setReviewerTelegramId("SYSTEM");
|
||||||
|
record.setReviewerName(SecurityUtils.getUsername());
|
||||||
|
record.setReviewedAt(now);
|
||||||
afterCommit(null, record, approved ? "审核通过" : "审核拒绝");
|
afterCommit(null, record, approved ? "审核通过" : "审核拒绝");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +370,9 @@ public class TelegramAuditService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 按条件更新领取到期任务,支持多实例并发和PROCESSING租约恢复。 */
|
/**
|
||||||
|
* 按条件更新领取到期任务,支持多实例并发和PROCESSING租约恢复。
|
||||||
|
*/
|
||||||
@Scheduled(fixedDelayString = "${telegram.push-scan-interval-ms:10000}")
|
@Scheduled(fixedDelayString = "${telegram.push-scan-interval-ms:10000}")
|
||||||
public void retryPushTasks() {
|
public void retryPushTasks() {
|
||||||
if (!enabled || StringUtils.isBlank(botToken) || StringUtils.isBlank(auditChatId)) {
|
if (!enabled || StringUtils.isBlank(botToken) || StringUtils.isBlank(auditChatId)) {
|
||||||
@@ -395,7 +429,9 @@ public class TelegramAuditService {
|
|||||||
return response.getJSONObject("result").getLong("message_id");
|
return response.getJSONObject("result").getLong("message_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 审核完成后更新原消息并移除按钮;失败不回滚业务审核。 */
|
/**
|
||||||
|
* 审核完成后更新原消息并移除按钮;失败不回滚业务审核。
|
||||||
|
*/
|
||||||
private void editCompletedMessage(TelegramAuditRecord record) {
|
private void editCompletedMessage(TelegramAuditRecord record) {
|
||||||
if (record.getTelegramMessageId() == null || StringUtils.isBlank(record.getTelegramChatId())) {
|
if (record.getTelegramMessageId() == null || StringUtils.isBlank(record.getTelegramChatId())) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,3 +1,42 @@
|
|||||||
package com.ruoyi.system.service;
|
package com.ruoyi.system.service;
|
||||||
/** 代付订单创建后的Telegram审核事件。 */
|
|
||||||
public class TelegramPayoutAuditEvent {private final Long id;private final String orderId,currency,amount,address,fee;public TelegramPayoutAuditEvent(Long id,String orderId,String currency,String amount,String address,String fee){this.id=id;this.orderId=orderId;this.currency=currency;this.amount=amount;this.address=address;this.fee=fee;}public Long getId(){return id;}public String getOrderId(){return orderId;}public String getCurrency(){return currency;}public String getAmount(){return amount;}public String getAddress(){return address;}public String getFee(){return fee;}}
|
/**
|
||||||
|
* 代付订单创建后的Telegram审核事件。
|
||||||
|
*/
|
||||||
|
public class TelegramPayoutAuditEvent {
|
||||||
|
private final Long id;
|
||||||
|
private final String orderId, currency, amount, address, fee;
|
||||||
|
|
||||||
|
public TelegramPayoutAuditEvent(Long id, String orderId, String currency, String amount, String address, String fee) {
|
||||||
|
this.id = id;
|
||||||
|
this.orderId = orderId;
|
||||||
|
this.currency = currency;
|
||||||
|
this.amount = amount;
|
||||||
|
this.address = address;
|
||||||
|
this.fee = fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrderId() {
|
||||||
|
return orderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrency() {
|
||||||
|
return currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFee() {
|
||||||
|
return fee;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user