From 776124419928e07f4105e1232554e6da6ad5972f Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Dec 2024 15:01:44 +0800 Subject: [PATCH 1/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1300078306754560]接口审计优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1300078306754560 --- .../framework/restful/core/ApiComponentBase.java | 6 +++--- .../restful/core/BinaryStreamApiComponentBase.java | 8 +++++--- .../restful/core/JsonStreamApiComponentBase.java | 8 +++++--- .../framework/restful/core/RawApiComponentBase.java | 6 +++--- .../restful/dispatch/handler/AnonymousApiDispatcher.java | 8 ++++---- .../framework/restful/dispatch/handler/ApiDispatcher.java | 8 ++++---- .../restful/dispatch/handler/PublicApiDispatcher.java | 5 +++-- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/neatlogic/framework/restful/core/ApiComponentBase.java b/src/main/java/neatlogic/framework/restful/core/ApiComponentBase.java index 2158f79d7..52c1e331b 100644 --- a/src/main/java/neatlogic/framework/restful/core/ApiComponentBase.java +++ b/src/main/java/neatlogic/framework/restful/core/ApiComponentBase.java @@ -23,7 +23,7 @@ import neatlogic.framework.dto.api.CacheControlVo; import neatlogic.framework.exception.core.ApiFieldValidNotFoundException; import neatlogic.framework.exception.core.ApiRuntimeException; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentFactory; -import neatlogic.framework.restful.dao.mapper.ApiMapper; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dto.ApiVo; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -39,7 +39,7 @@ import java.lang.reflect.Method; public abstract class ApiComponentBase extends ApiValidateAndHelpBase implements MyApiComponent { @Resource - private ApiMapper apiMapper; + private ApiLongCacheMapper apiLongCacheMapper; public int needAudit() { return 0; @@ -174,7 +174,7 @@ public abstract class ApiComponentBase extends ApiValidateAndHelpBase implements } finally { long endTime = System.currentTimeMillis(); if (!apiVo.getModuleId().equals("master")) { - ApiVo apiConfigVo = apiMapper.getApiByToken(apiVo.getToken()); + ApiVo apiConfigVo = apiLongCacheMapper.getApiByToken(apiVo.getToken()); // 如果没有配置,则使用默认配置 if (apiConfigVo == null) { apiConfigVo = apiVo; diff --git a/src/main/java/neatlogic/framework/restful/core/BinaryStreamApiComponentBase.java b/src/main/java/neatlogic/framework/restful/core/BinaryStreamApiComponentBase.java index a82602712..8ed926d22 100644 --- a/src/main/java/neatlogic/framework/restful/core/BinaryStreamApiComponentBase.java +++ b/src/main/java/neatlogic/framework/restful/core/BinaryStreamApiComponentBase.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.common.constvalue.CacheControlType; import neatlogic.framework.dto.api.CacheControlVo; import neatlogic.framework.exception.core.ApiRuntimeException; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dao.mapper.ApiMapper; import neatlogic.framework.restful.dto.ApiVo; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -11,6 +12,7 @@ import org.springframework.aop.framework.AopContext; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; @@ -19,8 +21,8 @@ public abstract class BinaryStreamApiComponentBase extends ApiValidateAndHelpBas // private static Logger logger = // LoggerFactory.getLogger(BinaryStreamApiComponentBase.class); - @Autowired - private ApiMapper apiMapper; + @Resource + private ApiLongCacheMapper apiLongCacheMapper; public int needAudit() { return 0; @@ -68,7 +70,7 @@ public abstract class BinaryStreamApiComponentBase extends ApiValidateAndHelpBas throw e; } finally { long endTime = System.currentTimeMillis(); - ApiVo apiConfigVo = apiMapper.getApiByToken(apiVo.getToken()); + ApiVo apiConfigVo = apiLongCacheMapper.getApiByToken(apiVo.getToken()); // 如果没有配置,则使用默认配置 if (apiConfigVo == null) { apiConfigVo = apiVo; diff --git a/src/main/java/neatlogic/framework/restful/core/JsonStreamApiComponentBase.java b/src/main/java/neatlogic/framework/restful/core/JsonStreamApiComponentBase.java index 589ef9bd4..b6c343a7e 100644 --- a/src/main/java/neatlogic/framework/restful/core/JsonStreamApiComponentBase.java +++ b/src/main/java/neatlogic/framework/restful/core/JsonStreamApiComponentBase.java @@ -3,6 +3,7 @@ package neatlogic.framework.restful.core; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONReader; import neatlogic.framework.exception.core.ApiRuntimeException; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dao.mapper.ApiMapper; import neatlogic.framework.restful.dto.ApiVo; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -10,14 +11,15 @@ import org.springframework.aop.framework.AopContext; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.Resource; import java.lang.reflect.Method; public abstract class JsonStreamApiComponentBase extends ApiValidateAndHelpBase implements MyJsonStreamApiComponent { // private static Logger logger = // LoggerFactory.getLogger(JsonStreamApiComponentBase.class); - @Autowired - private ApiMapper apiMapper; + @Resource + private ApiLongCacheMapper apiLongCacheMapper; public int needAudit() { @@ -54,7 +56,7 @@ public abstract class JsonStreamApiComponentBase extends ApiValidateAndHelpBase throw e; } finally { long endTime = System.currentTimeMillis(); - ApiVo apiConfigVo = apiMapper.getApiByToken(apiVo.getToken()); + ApiVo apiConfigVo = apiLongCacheMapper.getApiByToken(apiVo.getToken()); // 如果没有配置,则使用默认配置 if (apiConfigVo == null) { apiConfigVo = apiVo; diff --git a/src/main/java/neatlogic/framework/restful/core/RawApiComponentBase.java b/src/main/java/neatlogic/framework/restful/core/RawApiComponentBase.java index 28d042d7f..e4bcafa7f 100644 --- a/src/main/java/neatlogic/framework/restful/core/RawApiComponentBase.java +++ b/src/main/java/neatlogic/framework/restful/core/RawApiComponentBase.java @@ -21,7 +21,7 @@ import neatlogic.framework.common.config.Config; import neatlogic.framework.dto.FieldValidResultVo; import neatlogic.framework.dto.api.CacheControlVo; import neatlogic.framework.exception.core.ApiRuntimeException; -import neatlogic.framework.restful.dao.mapper.ApiMapper; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dto.ApiVo; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -36,7 +36,7 @@ import java.lang.reflect.Method; public abstract class RawApiComponentBase extends ApiValidateAndHelpBase implements MyRawApiComponent { @Resource - private ApiMapper apiMapper; + private ApiLongCacheMapper apiLongCacheMapper; public int needAudit() { return 0; @@ -110,7 +110,7 @@ public abstract class RawApiComponentBase extends ApiValidateAndHelpBase impleme } finally { long endTime = System.currentTimeMillis(); if (!apiVo.getModuleId().equals("master")) { - ApiVo apiConfigVo = apiMapper.getApiByToken(apiVo.getToken()); + ApiVo apiConfigVo = apiLongCacheMapper.getApiByToken(apiVo.getToken()); // 如果没有配置,则使用默认配置 if (apiConfigVo == null) { apiConfigVo = apiVo; 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 771c82d83..8fbbc3dd1 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 @@ -39,7 +39,7 @@ import neatlogic.framework.restful.core.IJsonStreamApiComponent; import neatlogic.framework.restful.core.IRawApiComponent; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentFactory; import neatlogic.framework.restful.counter.ApiAccessCountUpdateThread; -import neatlogic.framework.restful.dao.mapper.ApiMapper; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dto.ApiHandlerVo; import neatlogic.framework.restful.dto.ApiVo; import neatlogic.framework.restful.enums.ApiType; @@ -74,13 +74,13 @@ public class AnonymousApiDispatcher { Logger logger = LoggerFactory.getLogger(AnonymousApiDispatcher.class); @Resource - private ApiMapper apiMapper; + private ApiLongCacheMapper apiLongCacheMapper; private void doIt(HttpServletRequest request, HttpServletResponse response, String token, boolean tokenHasEncrypted, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); RequestContext.init(request, token, response); if (interfaceVo == null) { - interfaceVo = apiMapper.getApiByToken(token); + interfaceVo = apiLongCacheMapper.getApiByToken(token); if (interfaceVo == null || !interfaceVo.getIsActive().equals(1)) { throw new ApiNotFoundException(token); } @@ -99,7 +99,7 @@ public class AnonymousApiDispatcher { throw new ComponentNotFoundException(interfaceVo.getHandler()); } Double qps = interfaceVo.getQps(); - ApiVo apiVo = apiMapper.getApiByToken(token); + ApiVo apiVo = apiLongCacheMapper.getApiByToken(token); if (apiVo != null) { qps = apiVo.getQps(); } 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 5c44c5bcf..7963d50d2 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 @@ -37,7 +37,7 @@ import neatlogic.framework.restful.core.IJsonStreamApiComponent; import neatlogic.framework.restful.core.IRawApiComponent; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentFactory; import neatlogic.framework.restful.counter.ApiAccessCountUpdateThread; -import neatlogic.framework.restful.dao.mapper.ApiMapper; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dto.ApiHandlerVo; import neatlogic.framework.restful.dto.ApiVo; import neatlogic.framework.restful.enums.ApiType; @@ -75,7 +75,7 @@ public class ApiDispatcher { static Logger logger = LoggerFactory.getLogger(ApiDispatcher.class); @Resource - private ApiMapper apiMapper; + private ApiLongCacheMapper apiLongCacheMapper; /* 给fastJson加载自定义序列化配置,序列化json时返回正确格式 @@ -103,7 +103,7 @@ public class ApiDispatcher { paramObj = new JSONObject(); } if (interfaceVo == null) { - interfaceVo = apiMapper.getApiByToken(token); + interfaceVo = apiLongCacheMapper.getApiByToken(token); if (interfaceVo == null || !interfaceVo.getIsActive().equals(1)) { throw new ApiNotFoundException(token); } @@ -122,7 +122,7 @@ public class ApiDispatcher { throw new ComponentNotFoundException(interfaceVo.getHandler()); } Double qps = interfaceVo.getQps(); - ApiVo apiVo = apiMapper.getApiByToken(token); + ApiVo apiVo = apiLongCacheMapper.getApiByToken(token); if (apiVo != null) { qps = apiVo.getQps(); } 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 f5253a5bc..afbc07f73 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 @@ -42,6 +42,7 @@ import neatlogic.framework.restful.core.IBinaryStreamApiComponent; import neatlogic.framework.restful.core.IJsonStreamApiComponent; import neatlogic.framework.restful.core.publicapi.PublicApiComponentFactory; import neatlogic.framework.restful.counter.ApiAccessCountUpdateThread; +import neatlogic.framework.restful.dao.mapper.ApiLongCacheMapper; import neatlogic.framework.restful.dao.mapper.ApiMapper; import neatlogic.framework.restful.dto.ApiHandlerVo; import neatlogic.framework.restful.dto.ApiVo; @@ -77,7 +78,7 @@ public class PublicApiDispatcher { Logger logger = LoggerFactory.getLogger(PublicApiDispatcher.class); @Resource - private ApiMapper apiMapper; + private ApiLongCacheMapper apiLongCacheMapper; @Resource @@ -131,7 +132,7 @@ public class PublicApiDispatcher { UserContext.get().setRequest(request); - ApiVo interfaceVo = apiMapper.getApiByToken(token); + ApiVo interfaceVo = apiLongCacheMapper.getApiByToken(token); String uri = request.getRequestURI(); /* 如果不是查看帮助接口,则需要校验接口已激活,且此接口对应的handler是public */ if (interfaceVo == null || (!(uri.contains("/public/api/help/") && !token.contains("/public/api/help/")) && !interfaceVo.getIsActive().equals(1)) -- Gitee From 9ef06183e36ca5be0e2cf2cee8813dea40112ea5 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Dec 2024 15:03:34 +0800 Subject: [PATCH 2/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1300078306754560]接口审计优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1300078306754560 --- .../dao/mapper/ApiLongCacheMapper.java | 23 ++++++++++ .../restful/dao/mapper/ApiLongCacheMapper.xml | 43 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.java create mode 100644 src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.xml diff --git a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.java b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.java new file mode 100644 index 000000000..113ea0bfd --- /dev/null +++ b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.java @@ -0,0 +1,23 @@ +/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.framework.restful.dao.mapper; + +import neatlogic.framework.restful.dto.ApiVo; + +public interface ApiLongCacheMapper { + + ApiVo getApiByToken(String token); +} diff --git a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.xml b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.xml new file mode 100644 index 000000000..82d45a4e1 --- /dev/null +++ b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiLongCacheMapper.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + -- Gitee From f641bc2d5d7ddec7320ed1f1776686121cc830bf Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Dec 2024 15:04:50 +0800 Subject: [PATCH 3/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1300078306754560]接口审计优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1300078306754560 --- .../framework/restful/service/ApiService.java | 26 +++++----- .../restful/service/ApiServiceImpl.java | 49 ++++++++----------- .../changelog/2024-12-03/neatlogic_tenant.sql | 2 + .../changelog/2024-12-03/version.json | 10 ++++ 4 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/neatlogic_tenant.sql create mode 100644 src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/version.json diff --git a/src/main/java/neatlogic/framework/restful/service/ApiService.java b/src/main/java/neatlogic/framework/restful/service/ApiService.java index 9e233ce5d..165e1f099 100755 --- a/src/main/java/neatlogic/framework/restful/service/ApiService.java +++ b/src/main/java/neatlogic/framework/restful/service/ApiService.java @@ -1,19 +1,15 @@ package neatlogic.framework.restful.service; -import org.springframework.transaction.annotation.Transactional; - -import neatlogic.framework.restful.dto.ApiVo; - public interface ApiService { - public ApiVo getApiByToken(String token); - /** - * - * @Time:2020年7月18日 - * @Description: 保存接口访问次数 - * @param token - * @param count - * @return int - */ - @Transactional - public int saveApiAccessCount(String token, int count); +// public ApiVo getApiByToken(String token); +// /** +// * +// * @Time:2020年7月18日 +// * @Description: 保存接口访问次数 +// * @param token +// * @param count +// * @return int +// */ +// @Transactional +// public int saveApiAccessCount(String token, long count); } diff --git a/src/main/java/neatlogic/framework/restful/service/ApiServiceImpl.java b/src/main/java/neatlogic/framework/restful/service/ApiServiceImpl.java index 59460598b..8e84339bb 100644 --- a/src/main/java/neatlogic/framework/restful/service/ApiServiceImpl.java +++ b/src/main/java/neatlogic/framework/restful/service/ApiServiceImpl.java @@ -1,33 +1,26 @@ package neatlogic.framework.restful.service; -import neatlogic.framework.restful.dao.mapper.ApiAuditMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import neatlogic.framework.restful.dao.mapper.ApiMapper; -import neatlogic.framework.restful.dto.ApiVo; - -@Service +//@Service public class ApiServiceImpl implements ApiService { - @Autowired - private ApiMapper apiMapper; - - @Autowired - private ApiAuditMapper apiAuditMapper; - - @Override - public ApiVo getApiByToken(String token) { - return apiMapper.getApiByToken(token); - } - - - @Override - public int saveApiAccessCount(String token, int count) { - if(apiAuditMapper.getApiAccessCountLockByToken(token) == null) { - return apiAuditMapper.insertApiAccessCount(token, count); - }else { - return apiAuditMapper.updateApiAccessCount(token, count); - } - } +// @Autowired +// private ApiMapper apiMapper; +// +// @Autowired +// private ApiAuditMapper apiAuditMapper; + +// @Override +// public ApiVo getApiByToken(String token) {//TODO +// return apiMapper.getApiByToken(token); +// } +// +// +// @Override +// public int saveApiAccessCount(String token, long count) { +// if(apiAuditMapper.getApiAccessCountLockByToken(token) == null) { +// return apiAuditMapper.insertApiAccessCount(token, count); +// }else { +// return apiAuditMapper.updateApiAccessCount(token, count); +// } +// } } diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/neatlogic_tenant.sql new file mode 100644 index 000000000..f795e1d45 --- /dev/null +++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/neatlogic_tenant.sql @@ -0,0 +1,2 @@ +ALTER TABLE `api_access_count` + CHANGE `count` `count` BIGINT NOT NULL COMMENT '访问次数'; \ No newline at end of file diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/version.json b/src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/version.json new file mode 100644 index 000000000..702946b9b --- /dev/null +++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-12-03/version.json @@ -0,0 +1,10 @@ +{ + "content":[ + { + "type":"功能添加", + "detail":[ + {"msg":"1.接口审计优化"} + ] + } + ] +} -- Gitee From 40705cc2b6bbd2cac5332ba080b5e8b686d54ee4 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Dec 2024 15:05:25 +0800 Subject: [PATCH 4/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1300078306754560]接口审计优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1300078306754560 --- .../framework/restful/counter/DelayedItem.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/neatlogic/framework/restful/counter/DelayedItem.java b/src/main/java/neatlogic/framework/restful/counter/DelayedItem.java index 14db53169..285d867fd 100644 --- a/src/main/java/neatlogic/framework/restful/counter/DelayedItem.java +++ b/src/main/java/neatlogic/framework/restful/counter/DelayedItem.java @@ -25,6 +25,7 @@ import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; /** * @Time:2020年7月17日 @@ -43,7 +44,7 @@ public class DelayedItem implements Delayed { /** * 缓存租户访问记录 **/ - private final ConcurrentMap> tenantAccessTokenMap = new ConcurrentHashMap<>(); + private final ConcurrentMap> tenantAccessTokenMap = new ConcurrentHashMap<>(); /** * 标记正在往当前延迟对象的缓存tenantAccessTokenMap中写数据的线程数 **/ @@ -88,7 +89,7 @@ public class DelayedItem implements Delayed { }else { String tenantUuid = TenantContext.get().getTenantUuid(); /* 从缓存中获取当前租户访问记录 **/ - ConcurrentMap accessTokenCounterMap = tenantAccessTokenMap.get(tenantUuid); + ConcurrentMap accessTokenCounterMap = tenantAccessTokenMap.get(tenantUuid); if (accessTokenCounterMap == null) { /* 初始化某个租户访问记录缓存时,必须加锁,否则会出现多个线程相互覆盖情况 **/ synchronized (this) { @@ -101,13 +102,13 @@ public class DelayedItem implements Delayed { } /* 从缓存中获取当前token访问次数 ,并累加1**/ - AtomicInteger counter = accessTokenCounterMap.get(token); + AtomicLong counter = accessTokenCounterMap.get(token); if (counter == null) { /* 初始化某个token访问次数时,必须加锁,否则会出现多个线程相互覆盖情况 **/ synchronized (accessTokenCounterMap) { counter = accessTokenCounterMap.get(token); if (counter == null) { - accessTokenCounterMap.put(token, new AtomicInteger(1)); + accessTokenCounterMap.put(token, new AtomicLong(1)); } else { counter.incrementAndGet(); } @@ -147,7 +148,7 @@ public class DelayedItem implements Delayed { } } - public ConcurrentMap> getTenantAccessTokenMap() { + public ConcurrentMap> getTenantAccessTokenMap() { return tenantAccessTokenMap; } -- Gitee From 8d00c1b6b1e5484b2ee89e14bf3629a88fbf3e6c Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Dec 2024 15:06:36 +0800 Subject: [PATCH 5/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1300078306754560]接口审计优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1300078306754560 --- .../restful/dao/mapper/ApiAuditMapper.java | 10 ++++------ .../restful/dao/mapper/ApiAuditMapper.xml | 19 +++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.java b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.java index b1899066d..a7f30292b 100644 --- a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.java +++ b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.java @@ -31,11 +31,11 @@ public interface ApiAuditMapper { List getApiAuditList(ApiAuditVo apiAuditVo); - List getApiVisitTimesListByTokenList(List tokenList); +// List getApiVisitTimesListByTokenList(List tokenList); List getApiAccessCountByTokenList(List tokenList); - String getApiAccessCountLockByToken(String token); +// String getApiAccessCountLockByToken(String token); List searchApiAuditList(ApiAuditVo apiAuditVo); @@ -56,7 +56,7 @@ public interface ApiAuditMapper { * @Time:2020年7月15日 * @Description: 插入接口访问次数 */ - int insertApiAccessCount(@Param("token") String token, @Param("count") Integer count); + int insertApiAccessCount(@Param("token") String token, @Param("count") long count); int insertAuditFile(@Param("hash") String hash, @Param("filePath") String filePath); @@ -67,9 +67,7 @@ public interface ApiAuditMapper { * @Time:2020年7月15日 * @Description: 增加接口访问次数 */ - int updateApiAccessCount(@Param("token") String token, @Param("count") Integer count); - - int updateApiNeedAuditByToken(String token); +// int updateApiAccessCount(@Param("token") String token, @Param("count") Long count); void deleteAuditByDayBefore(int dayBefore); } diff --git a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.xml b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.xml index 8d8a520d2..0623bfbee 100644 --- a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.xml +++ b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiAuditMapper.xml @@ -64,7 +64,7 @@ along with this program. If not, see .--> LIMIT #{startNum}, #{pageSize} - + --> - + --> - + INSERT INTO `api_audit` (`id`, @@ -290,6 +284,7 @@ along with this program. If not, see .--> INSERT INTO `api_access_count` (`token`, `count`) VALUES (#{token}, #{count}) + ON DUPLICATE KEY UPDATE `count` = `count` + #{count} -- Gitee From 6df2784180a28e254156ed4d51332d8cf3001aaf Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Dec 2024 15:07:30 +0800 Subject: [PATCH 6/7] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1300078306754560]接口审计优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1300078306754560 --- .../framework/restful/dao/mapper/ApiMapper.java | 6 ++++-- .../framework/restful/dao/mapper/ApiMapper.xml | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.java b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.java index 9bb8e9a37..96995816e 100644 --- a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.java +++ b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.java @@ -24,7 +24,7 @@ public interface ApiMapper { ApiVo getApiByToken(String token); - List getApiTokenList(ApiVo apiVo); +// List getApiTokenList(ApiVo apiVo); List getAllApi(); @@ -42,5 +42,7 @@ public interface ApiMapper { int insertOrUpdateNeedAuditApi(ApiVo apiVo); - int updatePasswordByToken(@Param("token")String token,@Param("password")String password); +// int updatePasswordByToken(@Param("token")String token,@Param("password")String password); + + int updateApiNeedAuditByToken(String token); } diff --git a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.xml b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.xml index fa270e0f1..1b2de270e 100644 --- a/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.xml +++ b/src/main/java/neatlogic/framework/restful/dao/mapper/ApiMapper.xml @@ -39,7 +39,7 @@ along with this program. If not, see .--> WHERE token = #{value} - + -->