فهرست منبع

update 代码细节优化 分离 ServletUtils 独立 WebFluxUtils 解耦

疯狂的狮子li 4 سال پیش
والد
کامیت
f35dbc9241

+ 0 - 1
.github/FUNDING.yml

@@ -1 +0,0 @@
-custom: http://doc.ruoyi.vip/ruoyi-cloud/other/donate.html

+ 1 - 1
config/dev/ruoyi-system.yml

@@ -40,7 +40,7 @@ xxl:
     executor:
       # 执行器AppName:执行器心跳注册分组依据;为空则关闭自动注册
       appname: ${spring.application.name}-executor
-      # 执行器端口号 执行器从19201开始往后写
+      # 执行器端口号 执行器从19901开始往后写
       port: 9901
       # 执行器注册:默认IP:PORT
       address:

+ 0 - 60
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java

@@ -2,16 +2,9 @@ package com.ruoyi.common.core.utils;
 
 import cn.hutool.core.convert.Convert;
 import com.ruoyi.common.core.constant.Constants;
-import com.ruoyi.common.core.domain.R;
-import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.server.reactive.ServerHttpResponse;
 import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
-import reactor.core.publisher.Mono;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -206,57 +199,4 @@ public class ServletUtils {
         }
     }
 
-    /**
-     * 设置webflux模型响应
-     *
-     * @param response ServerHttpResponse
-     * @param value    响应内容
-     * @return Mono<Void>
-     */
-    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value) {
-        return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL);
-    }
-
-    /**
-     * 设置webflux模型响应
-     *
-     * @param response ServerHttpResponse
-     * @param code     响应状态码
-     * @param value    响应内容
-     * @return Mono<Void>
-     */
-    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code) {
-        return webFluxResponseWriter(response, HttpStatus.OK, value, code);
-    }
-
-    /**
-     * 设置webflux模型响应
-     *
-     * @param response ServerHttpResponse
-     * @param status   http状态码
-     * @param code     响应状态码
-     * @param value    响应内容
-     * @return Mono<Void>
-     */
-    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code) {
-        return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code);
-    }
-
-    /**
-     * 设置webflux模型响应
-     *
-     * @param response    ServerHttpResponse
-     * @param contentType content-type
-     * @param status      http状态码
-     * @param code        响应状态码
-     * @param value       响应内容
-     * @return Mono<Void>
-     */
-    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code) {
-        response.setStatusCode(status);
-        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
-        R<?> result = R.fail(code, value.toString());
-        DataBuffer dataBuffer = response.bufferFactory().wrap(JsonUtils.toJsonString(result).getBytes());
-        return response.writeWith(Mono.just(dataBuffer));
-    }
 }

+ 5 - 5
ruoyi-common/ruoyi-common-security/pom.xml

@@ -34,11 +34,11 @@
             <artifactId>ruoyi-common-redis</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-common-dubbo</artifactId>
-            <scope>provided</scope>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>com.ruoyi</groupId>-->
+<!--            <artifactId>ruoyi-common-dubbo</artifactId>-->
+<!--            <scope>provided</scope>-->
+<!--        </dependency>-->
 
     </dependencies>
 

+ 2 - 1
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.core.utils.ServletUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.redis.utils.RedisUtils;
 import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties;
+import com.ruoyi.gateway.utils.WebFluxUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -87,7 +88,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
 
     private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) {
         log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
-        return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
+        return WebFluxUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
     }
 
     /**

+ 2 - 2
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/BlackListUrlFilter.java

@@ -1,6 +1,6 @@
 package com.ruoyi.gateway.filter;
 
-import com.ruoyi.common.core.utils.ServletUtils;
+import com.ruoyi.gateway.utils.WebFluxUtils;
 import org.springframework.cloud.gateway.filter.GatewayFilter;
 import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
 import org.springframework.stereotype.Component;
@@ -22,7 +22,7 @@ public class BlackListUrlFilter extends AbstractGatewayFilterFactory<BlackListUr
 
             String url = exchange.getRequest().getURI().getPath();
             if (config.matchBlacklist(url)) {
-                return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求地址不允许访问");
+                return WebFluxUtils.webFluxResponseWriter(exchange.getResponse(), "请求地址不允许访问");
             }
 
             return chain.filter(exchange);

+ 2 - 2
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/ValidateCodeFilter.java

@@ -1,10 +1,10 @@
 package com.ruoyi.gateway.filter;
 
 import com.ruoyi.common.core.utils.JsonUtils;
-import com.ruoyi.common.core.utils.ServletUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.gateway.config.properties.CaptchaProperties;
 import com.ruoyi.gateway.service.ValidateCodeService;
+import com.ruoyi.gateway.utils.WebFluxUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cloud.gateway.filter.GatewayFilter;
 import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
@@ -53,7 +53,7 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
                 Map<String, String> obj = JsonUtils.parseMap(rspStr);
                 validateCodeService.checkCapcha(obj.get(CODE), obj.get(UUID));
             } catch (Exception e) {
-                return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage());
+                return WebFluxUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage());
             }
             return chain.filter(exchange);
         };

+ 2 - 2
ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/GatewayExceptionHandler.java

@@ -1,6 +1,6 @@
 package com.ruoyi.gateway.handler;
 
-import com.ruoyi.common.core.utils.ServletUtils;
+import com.ruoyi.gateway.utils.WebFluxUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
 import org.springframework.cloud.gateway.support.NotFoundException;
@@ -42,6 +42,6 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
 
         log.error("[网关异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), ex.getMessage());
 
-        return ServletUtils.webFluxResponseWriter(response, msg);
+        return WebFluxUtils.webFluxResponseWriter(response, msg);
     }
 }

+ 2 - 2
ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java

@@ -2,7 +2,7 @@ package com.ruoyi.gateway.handler;
 
 import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
 import com.alibaba.csp.sentinel.slots.block.BlockException;
-import com.ruoyi.common.core.utils.ServletUtils;
+import com.ruoyi.gateway.utils.WebFluxUtils;
 import org.springframework.web.reactive.function.server.ServerResponse;
 import org.springframework.web.server.ServerWebExchange;
 import org.springframework.web.server.WebExceptionHandler;
@@ -15,7 +15,7 @@ import reactor.core.publisher.Mono;
  */
 public class SentinelFallbackHandler implements WebExceptionHandler {
     private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
-        return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试");
+        return WebFluxUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍候再试");
     }
 
     @Override

+ 72 - 0
ruoyi-gateway/src/main/java/com/ruoyi/gateway/utils/WebFluxUtils.java

@@ -0,0 +1,72 @@
+package com.ruoyi.gateway.utils;
+
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.JsonUtils;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import reactor.core.publisher.Mono;
+
+/**
+ * WebFlux 工具类
+ *
+ * @author Lion Li
+ */
+public class WebFluxUtils {
+
+    /**
+     * 设置webflux模型响应
+     *
+     * @param response ServerHttpResponse
+     * @param value    响应内容
+     * @return Mono<Void>
+     */
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value) {
+        return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL);
+    }
+
+    /**
+     * 设置webflux模型响应
+     *
+     * @param response ServerHttpResponse
+     * @param code     响应状态码
+     * @param value    响应内容
+     * @return Mono<Void>
+     */
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code) {
+        return webFluxResponseWriter(response, HttpStatus.OK, value, code);
+    }
+
+    /**
+     * 设置webflux模型响应
+     *
+     * @param response ServerHttpResponse
+     * @param status   http状态码
+     * @param code     响应状态码
+     * @param value    响应内容
+     * @return Mono<Void>
+     */
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code) {
+        return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code);
+    }
+
+    /**
+     * 设置webflux模型响应
+     *
+     * @param response    ServerHttpResponse
+     * @param contentType content-type
+     * @param status      http状态码
+     * @param code        响应状态码
+     * @param value       响应内容
+     * @return Mono<Void>
+     */
+    public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code) {
+        response.setStatusCode(status);
+        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
+        R<?> result = R.fail(code, value.toString());
+        DataBuffer dataBuffer = response.bufferFactory().wrap(JsonUtils.toJsonString(result).getBytes());
+        return response.writeWith(Mono.just(dataBuffer));
+    }
+}

+ 0 - 40
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java

@@ -1,7 +1,6 @@
 package com.ruoyi.system.controller;
 
 import com.ruoyi.common.core.constant.UserConstants;
-import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.web.controller.BaseController;
@@ -9,12 +8,10 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.core.web.page.TableDataInfo;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
-import com.ruoyi.common.security.annotation.InnerAuth;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
 import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.system.api.domain.SysRole;
 import com.ruoyi.system.api.domain.SysUser;
-import com.ruoyi.system.api.model.LoginUser;
 import com.ruoyi.system.service.*;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.ArrayUtils;
@@ -82,43 +79,6 @@ public class SysUserController extends BaseController {
         util.importTemplateExcel(response, "用户数据");
     }
 
-    /**
-     * 获取当前用户信息
-     */
-    @InnerAuth
-    @GetMapping("/info/{username}")
-    public R<LoginUser> info(@PathVariable("username") String username) {
-        SysUser sysUser = userService.selectUserByUserName(username);
-        if (StringUtils.isNull(sysUser)) {
-            return R.fail("用户名或密码错误");
-        }
-        // 角色集合
-        Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
-        // 权限集合
-        Set<String> permissions = permissionService.getMenuPermission(sysUser.getUserId());
-        LoginUser sysUserVo = new LoginUser();
-        sysUserVo.setSysUser(sysUser);
-        sysUserVo.setRoles(roles);
-        sysUserVo.setPermissions(permissions);
-        return R.ok(sysUserVo);
-    }
-
-    /**
-     * 注册用户信息
-     */
-    @InnerAuth
-    @PostMapping("/register")
-    public R<Boolean> register(@RequestBody SysUser sysUser) {
-        String username = sysUser.getUserName();
-        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
-            return R.fail("当前系统没有开启注册功能!");
-        }
-        if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) {
-            return R.fail("保存用户'" + username + "'失败,注册账号已存在");
-        }
-        return R.ok(userService.registerUser(sysUser));
-    }
-
     /**
      * 获取用户信息
      *