From a456ea774310038d5bcb88803e5d8be8151829cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Mon, 6 Mar 2023 15:11:32 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91OnlineInterceptor?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/OnlineInterceptor.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/interceptor/OnlineInterceptor.java b/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/interceptor/OnlineInterceptor.java index 6afdd924..f950bb47 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/interceptor/OnlineInterceptor.java +++ b/jero-boot/jero-boot-base/jero-boot-base-generater/src/main/java/com/jero/generater/interceptor/OnlineInterceptor.java @@ -1,13 +1,6 @@ package com.jero.generater.interceptor; import com.alibaba.fastjson.JSON; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import com.jero.common.api.dto.OnlineAuthDTO; import com.jero.common.api.vo.Result; import com.jero.common.aspect.annotation.OnlineAuth; @@ -20,25 +13,32 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + @Slf4j public class OnlineInterceptor implements HandlerInterceptor { - private IOnlineBaseAPI b; + private IOnlineBaseAPI iOnlineBaseAPI; private ISysBaseAPI sysBaseAPI; - private static final String d = "/online/cgform"; - private static final String[] e = new String[]{"/online/cgformInnerTableList", + private static final String CG_FORM_CONSTANT = "/online/cgform"; + private static final String[] ONLINE_CONSTANT = new String[]{"/online/cgformInnerTableList", "/online/cgformErpList", "/online/cgformList", "/online/cgformTreeList", "/online/cgformTabList"}; - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { boolean bool = handler.getClass().isAssignableFrom(HandlerMethod.class); if (bool) { - OnlineAuth onlineAuth = (OnlineAuth) ((HandlerMethod) handler).getMethodAnnotation(OnlineAuth.class); + OnlineAuth onlineAuth = ((HandlerMethod) handler).getMethodAnnotation(OnlineAuth.class); if (onlineAuth != null) { log.debug("===== online 菜单访问拦截器 ====="); @@ -53,26 +53,26 @@ public class OnlineInterceptor implements HandlerInterceptor { } String str4 = request.getParameter("tabletype"); - if (this.b == null) { - this.b = (IOnlineBaseAPI) SpringContextUtils.getBean(IOnlineBaseAPI.class); + if (this.iOnlineBaseAPI == null) { + this.iOnlineBaseAPI = SpringContextUtils.getBean(IOnlineBaseAPI.class); } - str3 = this.b.getOnlineErpCode(str3, str4); + str3 = this.iOnlineBaseAPI.getOnlineErpCode(str3, str4); - ArrayList arrayList = new ArrayList(); + ArrayList arrayList = new ArrayList<>(); - for (String str : e) { + for (String str : ONLINE_CONSTANT) { arrayList.add(str + str3); } if (this.sysBaseAPI == null) { - this.sysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class); + this.sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class); } String str5 = JwtUtil.getUserNameByToken(request); - OnlineAuthDTO onlineAuthDTO = new OnlineAuthDTO(str5, arrayList, "/online/cgform"); + OnlineAuthDTO onlineAuthDTO = new OnlineAuthDTO(str5, arrayList, CG_FORM_CONSTANT); boolean bool1 = this.sysBaseAPI.hasOnlineAuth(onlineAuthDTO); @@ -91,7 +91,7 @@ public class OnlineInterceptor implements HandlerInterceptor { if (oConvertUtils.isNotEmpty(paramString)) { str = paramString.replace("\\", "/") .replace("//", "/"); - if (str.indexOf("//") >= 0) { + if (str.contains("//")) { str = a(str); } } @@ -114,8 +114,9 @@ public class OnlineInterceptor implements HandlerInterceptor { } catch (IOException iOException) { log.error(iOException.getMessage()); } finally { - if (printWriter != null) - printWriter.close(); + if (printWriter != null) { + printWriter.close(); + } } } -} \ No newline at end of file +}