From caa9e2216c35d3b84cbbaa6067a0625698f7fe8b Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 29 May 2025 18:59:22 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=9D=A5=E6=BA=90=E6=94=B9=E6=88=90=E4=BB=8E?= =?UTF-8?q?=E8=AF=B7=E6=B1=82header=E7=9A=84source=E4=B8=AD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1432003780509696]工单操作来源改成从请求header的source中获取 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1432003780509696 --- .../asynchronization/threadlocal/RequestContext.java | 3 ++- .../framework/common/constvalue/InputFrom.java | 2 ++ .../dispatch/handler/AnonymousApiDispatcher.java | 11 +++++++++++ .../restful/dispatch/handler/ApiDispatcher.java | 10 +++++++++- .../restful/dispatch/handler/PublicApiDispatcher.java | 10 +++++++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java b/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java index d2092a2cc..70529a64a 100644 --- a/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java +++ b/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java @@ -15,6 +15,7 @@ along with this program. If not, see .*/ package neatlogic.framework.asynchronization.threadlocal; +import neatlogic.framework.common.util.IpUtil; import neatlogic.framework.dto.healthcheck.SqlAuditVo; import neatlogic.framework.restful.constvalue.RejectSource; import org.apache.commons.lang3.StringUtils; @@ -126,7 +127,7 @@ public class RequestContext implements Serializable { } HttpServletRequest request = _requestContext.getRequest(); if (request != null) { - String remoteAddr = request.getRemoteAddr(); + String remoteAddr = IpUtil.getIpAddr(request); if (StringUtils.isNotBlank(remoteAddr)) { tempUrl += "(" + remoteAddr + ")"; } diff --git a/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java b/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java index 76b69288b..304880d9d 100644 --- a/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java +++ b/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java @@ -24,6 +24,8 @@ import java.util.List; public enum InputFrom implements IEnum { PAGE("page", "nfcc.inputfrom.page"), + PC("pc", "nfcc.inputfrom.pc"), + MOBILE("mobile", "nfcc.inputfrom.mobile"), IMPORT("import", "nfcc.inputfrom.excel"), RESTFUL("restful", "nfcc.inputfrom.api"), ITSM("itsm", "nfcc.inputfrom.itsm"), diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java index 7e8066542..7fc34b901 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java @@ -19,10 +19,12 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONReader; import com.alibaba.fastjson.serializer.SerializerFeature; +import neatlogic.framework.asynchronization.threadlocal.InputFromContext; import neatlogic.framework.asynchronization.threadlocal.RequestContext; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.common.config.Config; +import neatlogic.framework.common.constvalue.InputFrom; import neatlogic.framework.common.constvalue.ResponseCode; import neatlogic.framework.common.constvalue.systemuser.SystemUser; import neatlogic.framework.common.util.RC4Util; @@ -80,6 +82,15 @@ public class AnonymousApiDispatcher { private ApiAccessCountService apiAccessCountService; private void doIt(HttpServletRequest request, HttpServletResponse response, String token, boolean tokenHasEncrypted, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { + InputFrom inputFrom = null; + String source = request.getHeader("source"); + if (StringUtils.isNotBlank(source)) { + inputFrom = InputFrom.get(source); + } + if (inputFrom == null) { + inputFrom = InputFrom.UNKNOWN; + } + InputFromContext.init(inputFrom); ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); RequestContext.init(request, token, response); ApiVo dbApiVo = apiMapper.getApiByToken(token); diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java index 1019733c2..16bf750c0 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java @@ -99,7 +99,15 @@ public class ApiDispatcher { private void doIt(HttpServletRequest request, HttpServletResponse response, String token, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { - InputFromContext.init(InputFrom.PAGE); + InputFrom inputFrom = null; + String source = request.getHeader("source"); + if (StringUtils.isNotBlank(source)) { + inputFrom = InputFrom.get(source); + } + if (inputFrom == null) { + inputFrom = InputFrom.UNKNOWN; + } + InputFromContext.init(inputFrom); RequestContext.init(request, token, response); ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); if (paramObj == null) { diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java index 2a56b8be6..aaba52402 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java @@ -91,7 +91,15 @@ public class PublicApiDispatcher { private void doIt(HttpServletRequest request, HttpServletResponse response, String token, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { - InputFromContext.init(InputFrom.RESTFUL); + InputFrom inputFrom = null; + String source = request.getHeader("source"); + if (StringUtils.isNotBlank(source)) { + inputFrom = InputFrom.get(source); + } + if (inputFrom == null) { + inputFrom = InputFrom.UNKNOWN; + } + InputFromContext.init(inputFrom); RequestContext.init(request, token, response); //初始化时区 Cookie[] cookies = request.getCookies(); -- Gitee