diff --git a/zt-dependencies/pom.xml b/zt-dependencies/pom.xml
index b5c1f76c..0883b0d9 100644
--- a/zt-dependencies/pom.xml
+++ b/zt-dependencies/pom.xml
@@ -32,6 +32,8 @@
3.4.5
2024.0.1
2023.0.3.2
+
+ 2.4.0
2.8.3
4.6.0
@@ -88,6 +90,8 @@
1.2.5
0.9.0
4.12.0
+ 11.4.7
+ 11.4.7
2.15.1
4.5.13
@@ -133,6 +137,20 @@
import
+
+
+
+
+ org.apache.seata
+ seata-all
+ ${seata.version}
+
+
+ org.apache.seata
+ seata-spring-boot-starter
+ ${seata.version}
+
+
io.github.mouzt
diff --git a/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/dal/dataobject/databus/TemplateDatabusRequestLogDO.java b/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/dal/dataobject/databus/TemplateDatabusRequestLogDO.java
index 14427fe7..3da29e68 100644
--- a/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/dal/dataobject/databus/TemplateDatabusRequestLogDO.java
+++ b/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/dal/dataobject/databus/TemplateDatabusRequestLogDO.java
@@ -45,6 +45,12 @@ public class TemplateDatabusRequestLogDO extends BaseDO {
@TableField("HTTP_METHOD")
private String httpMethod;
+ /**
+ * 发起请求的 IP。
+ */
+ @TableField("REQUEST_IP")
+ private String requestIp;
+
/**
* Query 参数 JSON。
*/
diff --git a/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/service/databus/TemplateDatabusInvokeService.java b/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/service/databus/TemplateDatabusInvokeService.java
index d0be0ddd..85a4e978 100644
--- a/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/service/databus/TemplateDatabusInvokeService.java
+++ b/zt-module-template/zt-module-template-server/src/main/java/com/zt/plat/module/template/service/databus/TemplateDatabusInvokeService.java
@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
+import java.net.InetAddress;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
@@ -51,6 +52,7 @@ public class TemplateDatabusInvokeService {
private static final String ENCRYPTION_TYPE = CryptoSignatureUtils.ENCRYPT_TYPE_AES;
private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(5);
private static final Duration READ_TIMEOUT = Duration.ofSeconds(10);
+ private static final String UNKNOWN_IP = "UNKNOWN";
private static final Map BASE_QUERY_PARAMS = Map.of(
"businessCode", "11",
"fileId", "11"
@@ -73,6 +75,7 @@ public class TemplateDatabusInvokeService {
.requestId(generateRequestId())
.httpMethod(DEFAULT_HTTP_METHOD)
.targetUrl(TARGET_URL)
+ .requestIp(resolveRequestIp())
.success(Boolean.FALSE)
.build();
Instant start = Instant.now();
@@ -301,4 +304,16 @@ public class TemplateDatabusInvokeService {
}
return value.substring(0, maxLength);
}
+
+ private String resolveRequestIp() {
+ try {
+ InetAddress localHost = InetAddress.getLocalHost();
+ if (localHost != null) {
+ return localHost.getHostAddress();
+ }
+ } catch (Exception ex) {
+ log.debug("无法获取本地请求 IP", ex);
+ }
+ return UNKNOWN_IP;
+ }
}
diff --git a/zt-module-template/zt-module-template-server/src/main/resources/sql/template_databus_request_log.sql b/zt-module-template/zt-module-template-server/src/main/resources/sql/template_databus_request_log.sql
index 5112f7b2..57b44a93 100644
--- a/zt-module-template/zt-module-template-server/src/main/resources/sql/template_databus_request_log.sql
+++ b/zt-module-template/zt-module-template-server/src/main/resources/sql/template_databus_request_log.sql
@@ -3,6 +3,7 @@ CREATE TABLE template_databus_request_log (
REQUEST_ID VARCHAR(64) NOT NULL,
TARGET_URL VARCHAR(512) NOT NULL,
HTTP_METHOD VARCHAR(16) NOT NULL,
+ REQUEST_IP VARCHAR(64),
QUERY_PARAMS TEXT,
REQUEST_HEADERS TEXT,
REQUEST_BODY TEXT,
@@ -29,6 +30,7 @@ COMMENT ON COLUMN template_databus_request_log.ID IS '主键';
COMMENT ON COLUMN template_databus_request_log.REQUEST_ID IS '请求唯一标识';
COMMENT ON COLUMN template_databus_request_log.TARGET_URL IS '目标地址(含 Query)';
COMMENT ON COLUMN template_databus_request_log.HTTP_METHOD IS 'HTTP 方法';
+COMMENT ON COLUMN template_databus_request_log.REQUEST_IP IS '发起请求的 IP';
COMMENT ON COLUMN template_databus_request_log.QUERY_PARAMS IS 'Query 参数 JSON';
COMMENT ON COLUMN template_databus_request_log.REQUEST_HEADERS IS '请求头 JSON';
COMMENT ON COLUMN template_databus_request_log.REQUEST_BODY IS '原始请求体';