diff --git a/README.md b/README.md index e7f31580..80b314a5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Sonar Status -ContiNew Starter +ContiNew Starter Spring Boot @@ -210,13 +210,13 @@ public class DeptController extends BaseControllerVue | 3.4.21 | 渐进式 JavaScript 框架,易学易用,性能出色,适用场景丰富的 Web 前端框架。 | | Arco Design | 2.55.0 | 字节跳动推出的前端 UI 框架,年轻化的色彩和组件设计。 | | TypeScript | 5.0.4 | TypeScript 是微软开发的一个开源的编程语言,通过在 JavaScript 的基础上添加静态类型定义构建而成。 | | Vite | 5.1.5 | 下一代的前端工具链,为开发提供极速响应。 | -| [ContiNew Starter](https://github.com/continew-org/continew-starter) | 2.4.0 | ContiNew Starter 包含了一系列经过企业实践优化的依赖包(如 MyBatis-Plus、SaToken),可轻松集成到应用中,为开发人员减少手动引入依赖及配置的麻烦,为 Spring Boot Web 项目的灵活快速构建提供支持。 | +| [ContiNew Starter](https://github.com/continew-org/continew-starter) | 2.5.0 | ContiNew Starter 包含了一系列经过企业实践优化的依赖包(如 MyBatis-Plus、SaToken),可轻松集成到应用中,为开发人员减少手动引入依赖及配置的麻烦,为 Spring Boot Web 项目的灵活快速构建提供支持。 | | Spring Boot | 3.2.7 | 简化 Spring 应用的初始搭建和开发过程,基于“约定优于配置”的理念,使开发人员不再需要定义样板化的配置。(Spring Boot 3.0 开始,要求 Java 17 作为最低版本) | | Undertow | 2.3.13.Final | 采用 Java 开发的灵活的高性能 Web 服务器,提供包括阻塞和基于 NIO 的非堵塞机制。 | | Sa-Token + JWT | 1.38.0 | 轻量级 Java 权限认证框架,让鉴权变得简单、优雅。 | diff --git a/continew-admin-common/src/main/java/top/continew/admin/common/config/WebMvcConfiguration.java b/continew-admin-common/src/main/java/top/continew/admin/common/config/WebMvcConfiguration.java deleted file mode 100644 index fa41fd5f..00000000 --- a/continew-admin-common/src/main/java/top/continew/admin/common/config/WebMvcConfiguration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package top.continew.admin.common.config; - -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.converter.ByteArrayHttpMessageConverter; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import java.util.List; -import java.util.Objects; - -/** - * Web MVC 配置 - * - * @author Charles7c - * @since 2022/12/11 19:40 - */ -@EnableWebMvc -@Configuration -@RequiredArgsConstructor -public class WebMvcConfiguration implements WebMvcConfigurer { - - private final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter; - - /** - * 解决 Jackson2ObjectMapperBuilderCustomizer 配置不生效的问题 - *

- * MappingJackson2HttpMessageConverter 对象在程序启动时创建了多个,移除多余的,保证只有一个 - *

- */ - @Override - public void extendMessageConverters(List> converters) { - converters.removeIf(MappingJackson2HttpMessageConverter.class::isInstance); - if (Objects.isNull(mappingJackson2HttpMessageConverter)) { - converters.add(0, new MappingJackson2HttpMessageConverter()); - } else { - converters.add(0, mappingJackson2HttpMessageConverter); - } - // 自定义 converters 时,需要手动在最前面添加 ByteArrayHttpMessageConverter - // 否则 Spring Doc OpenAPI 的 /*/api-docs/**(例如:/v3/api-docs/default)接口响应内容会变为 Base64 编码后的内容,最终导致接口文档解析失败 - // 详情请参阅:https://github.com/springdoc/springdoc-openapi/issues/2143 - converters.add(0, new ByteArrayHttpMessageConverter()); - } -} diff --git a/continew-admin-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java b/continew-admin-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..a7e520d3 --- /dev/null +++ b/continew-admin-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.config.exception; + +import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.core.util.NumberUtil; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.multipart.MultipartException; +import top.continew.starter.core.exception.BadRequestException; +import top.continew.starter.core.exception.BusinessException; +import top.continew.starter.web.model.R; + +/** + * 全局异常处理器 + * + * @author Charles7c + * @since 2024/8/7 20:21 + */ +@Slf4j +@Order(99) +@RestControllerAdvice +public class GlobalExceptionHandler { + + /** + * 拦截业务异常 + */ + @ExceptionHandler(BusinessException.class) + public R handleBusinessException(BusinessException e, HttpServletRequest request) { + log.error("请求地址 [{}],发生业务异常。", request.getRequestURI(), e); + return R.fail(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()), e.getMessage()); + } + + /** + * 拦截自定义验证异常-错误请求 + */ + @ExceptionHandler(BadRequestException.class) + public R handleBadRequestException(BadRequestException e, HttpServletRequest request) { + log.warn("请求地址 [{}],自定义验证失败。", request.getRequestURI(), e); + return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), e.getMessage()); + } + + /** + * 拦截文件上传异常-超过上传大小限制 + */ + @ExceptionHandler(MultipartException.class) + public R handleRequestTooBigException(MultipartException e, HttpServletRequest request) { + String msg = e.getMessage(); + R defaultFail = R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), msg); + if (CharSequenceUtil.isBlank(msg)) { + return defaultFail; + } + String sizeLimit; + Throwable cause = e.getCause(); + if (null != cause) { + msg = msg.concat(cause.getMessage().toLowerCase()); + } + if (msg.contains("size") && msg.contains("exceed")) { + sizeLimit = CharSequenceUtil.subBetween(msg, "the maximum size ", " for"); + } else if (msg.contains("larger than")) { + sizeLimit = CharSequenceUtil.subAfter(msg, "larger than ", true); + } else { + return defaultFail; + } + String errorMsg = "请上传小于 %sKB 的文件".formatted(NumberUtil.parseLong(sizeLimit) / 1024); + log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e); + return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), errorMsg); + } +} \ No newline at end of file diff --git a/continew-admin-common/src/main/java/top/continew/admin/common/config/exception/GlobalSaTokenExceptionHandler.java b/continew-admin-common/src/main/java/top/continew/admin/common/config/exception/GlobalSaTokenExceptionHandler.java new file mode 100644 index 00000000..9b09b3fe --- /dev/null +++ b/continew-admin-common/src/main/java/top/continew/admin/common/config/exception/GlobalSaTokenExceptionHandler.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.config.exception; + +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.NotPermissionException; +import cn.dev33.satoken.exception.NotRoleException; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import top.continew.starter.web.model.R; + +/** + * 全局 SaToken 异常处理器 + * + * @author Charles7c + * @since 2024/8/7 20:21 + */ +@Slf4j +@Order(99) +@RestControllerAdvice +public class GlobalSaTokenExceptionHandler { + + /** + * 认证异常-登录认证 + */ + @ExceptionHandler(NotLoginException.class) + public R handleNotLoginException(NotLoginException e, HttpServletRequest request) { + log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e); + String errorMsg = switch (e.getType()) { + case NotLoginException.KICK_OUT -> "您已被踢下线。"; + case NotLoginException.BE_REPLACED_MESSAGE -> "您已被顶下线。"; + default -> "您的登录状态已过期,请重新登录。"; + }; + return R.fail(String.valueOf(HttpStatus.UNAUTHORIZED.value()), errorMsg); + } + + /** + * 认证异常-权限认证 + */ + @ExceptionHandler(NotPermissionException.class) + public R handleNotPermissionException(NotPermissionException e, HttpServletRequest request) { + log.error("请求地址 [{}],权限码校验失败。", request.getRequestURI(), e); + return R.fail(String.valueOf(HttpStatus.FORBIDDEN.value()), "没有访问权限,请联系管理员授权"); + } + + /** + * 认证异常-角色认证 + */ + @ExceptionHandler(NotRoleException.class) + public R handleNotRoleException(NotRoleException e, HttpServletRequest request) { + log.error("请求地址 [{}],角色权限校验失败。", request.getRequestURI(), e); + return R.fail(String.valueOf(HttpStatus.FORBIDDEN.value()), "没有访问权限,请联系管理员授权"); + } +} \ No newline at end of file diff --git a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/GeneratorService.java b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/GeneratorService.java index baad0745..b420f8eb 100644 --- a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/GeneratorService.java +++ b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/GeneratorService.java @@ -16,7 +16,6 @@ package top.continew.admin.generator.service; -import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import top.continew.admin.generator.model.entity.FieldConfigDO; import top.continew.admin.generator.model.entity.GenConfigDO; @@ -86,8 +85,7 @@ public interface GeneratorService { * 生成代码 * * @param tableNames 表明层 - * @param request 请求对象 * @param response 响应对象 */ - void generate(List tableNames, HttpServletRequest request, HttpServletResponse response); + void generate(List tableNames, HttpServletResponse response); } diff --git a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java index d95b17bd..03491145 100644 --- a/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java +++ b/continew-admin-plugins/continew-admin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java @@ -27,7 +27,6 @@ import cn.hutool.core.util.ZipUtil; import cn.hutool.db.meta.Column; import cn.hutool.system.SystemUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -281,7 +280,7 @@ public class GeneratorServiceImpl implements GeneratorService { } @Override - public void generate(List tableNames, HttpServletRequest request, HttpServletResponse response) { + public void generate(List tableNames, HttpServletResponse response) { try { String tempDir = SystemUtil.getUserInfo().getTempDir(); // 删除旧代码 @@ -296,7 +295,7 @@ public class GeneratorServiceImpl implements GeneratorService { File tempDirFile = new File(tempDir, projectProperties.getAppName()); String zipFilePath = tempDirFile.getPath() + jodd.io.ZipUtil.ZIP_EXT; ZipUtil.zip(tempDirFile.getPath(), zipFilePath); - FileUploadUtils.download(request, response, new File(zipFilePath), true); + FileUploadUtils.download(response, new File(zipFilePath)); } catch (Exception e) { log.error("Generate code of table '{}' occurred an error. {}", tableNames, e.getMessage(), e); throw new BusinessException("代码生成失败,请手动清理生成文件"); diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java index 17abd4d9..63dad64b 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java @@ -20,12 +20,14 @@ import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.img.ImgUtil; -import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.file.FileNameUtil; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.lang.UUID; import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.*; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.EnumUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.validation.ValidationUtil; import cn.hutool.http.ContentType; import cn.hutool.json.JSONUtil; @@ -77,6 +79,7 @@ import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.service.CommonUserService; import top.continew.starter.extension.crud.service.impl.BaseServiceImpl; +import top.continew.starter.web.util.FileUploadUtils; import java.io.IOException; import java.time.Duration; @@ -129,13 +132,8 @@ public class UserServiceImpl extends BaseServiceImpl - + top.continew - continew-starter-log-httptrace-pro + continew-starter-log-interceptor diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/ContiNewAdminApplication.java b/continew-admin-webapi/src/main/java/top/continew/admin/ContiNewAdminApplication.java index 79764610..54c9b512 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/ContiNewAdminApplication.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/ContiNewAdminApplication.java @@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import top.continew.starter.core.autoconfigure.project.ProjectProperties; import top.continew.starter.extension.crud.annotation.EnableCrudRestController; -import top.continew.starter.web.annotation.EnableGlobalExceptionHandler; +import top.continew.starter.web.annotation.EnableGlobalResponse; /** * 启动程序 @@ -44,13 +44,13 @@ import top.continew.starter.web.annotation.EnableGlobalExceptionHandler; * @since 2022/12/8 23:15 */ @Slf4j -@RestController @EnableFileStorage +@EnableMethodCache(basePackages = "top.continew.admin") +@EnableGlobalResponse +@EnableCrudRestController +@RestController @SpringBootApplication @RequiredArgsConstructor -@EnableCrudRestController -@EnableGlobalExceptionHandler -@EnableMethodCache(basePackages = "top.continew.admin") public class ContiNewAdminApplication implements ApplicationRunner { private final ProjectProperties projectProperties; diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/config/log/LogConfiguration.java b/continew-admin-webapi/src/main/java/top/continew/admin/config/log/LogConfiguration.java index 51428312..8a7f8f47 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/config/log/LogConfiguration.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/config/log/LogConfiguration.java @@ -21,7 +21,7 @@ import org.springframework.context.annotation.Configuration; import top.continew.admin.system.mapper.LogMapper; import top.continew.admin.system.service.UserService; import top.continew.starter.log.core.dao.LogDao; -import top.continew.starter.log.httptracepro.autoconfigure.ConditionalOnEnabledLog; +import top.continew.starter.log.interceptor.autoconfigure.ConditionalOnEnabledLog; import top.continew.starter.web.autoconfigure.trace.TraceProperties; /** diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/AuthController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/AuthController.java index 19368d06..8bccd7ba 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/AuthController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/AuthController.java @@ -43,7 +43,6 @@ import top.continew.admin.system.service.UserService; import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.validate.ValidationUtils; -import top.continew.starter.web.model.R; import top.continew.starter.log.core.annotation.Log; import java.util.List; @@ -69,7 +68,7 @@ public class AuthController { @SaIgnore @Operation(summary = "账号登录", description = "根据账号和密码进行登录认证") @PostMapping("/account") - public R accountLogin(@Validated @RequestBody AccountLoginReq loginReq, HttpServletRequest request) { + public LoginResp accountLogin(@Validated @RequestBody AccountLoginReq loginReq, HttpServletRequest request) { String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + loginReq.getUuid(); String captcha = RedisUtils.get(captchaKey); ValidationUtils.throwIfBlank(captcha, CAPTCHA_EXPIRED); @@ -79,13 +78,13 @@ public class AuthController { String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginReq.getPassword())); ValidationUtils.throwIfBlank(rawPassword, "密码解密失败"); String token = loginService.accountLogin(loginReq.getUsername(), rawPassword, request); - return R.ok(LoginResp.builder().token(token).build()); + return LoginResp.builder().token(token).build(); } @SaIgnore @Operation(summary = "手机号登录", description = "根据手机号和验证码进行登录认证") @PostMapping("/phone") - public R phoneLogin(@Validated @RequestBody PhoneLoginReq loginReq) { + public LoginResp phoneLogin(@Validated @RequestBody PhoneLoginReq loginReq) { String phone = loginReq.getPhone(); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + phone; String captcha = RedisUtils.get(captchaKey); @@ -93,13 +92,13 @@ public class AuthController { ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, CAPTCHA_ERROR); RedisUtils.delete(captchaKey); String token = loginService.phoneLogin(phone); - return R.ok(LoginResp.builder().token(token).build()); + return LoginResp.builder().token(token).build(); } @SaIgnore @Operation(summary = "邮箱登录", description = "根据邮箱和验证码进行登录认证") @PostMapping("/email") - public R emailLogin(@Validated @RequestBody EmailLoginReq loginReq) { + public LoginResp emailLogin(@Validated @RequestBody EmailLoginReq loginReq) { String email = loginReq.getEmail(); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + email; String captcha = RedisUtils.get(captchaKey); @@ -107,35 +106,35 @@ public class AuthController { ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, CAPTCHA_ERROR); RedisUtils.delete(captchaKey); String token = loginService.emailLogin(email); - return R.ok(LoginResp.builder().token(token).build()); + return LoginResp.builder().token(token).build(); } @Operation(summary = "用户退出", description = "注销用户的当前登录") @Parameter(name = "Authorization", description = "令牌", required = true, example = "Bearer xxxx-xxxx-xxxx-xxxx", in = ParameterIn.HEADER) @PostMapping("/logout") - public R logout() { + public Object logout() { Object loginId = StpUtil.getLoginId(-1L); StpUtil.logout(); - return R.ok(loginId); + return loginId; } @Log(ignore = true) @Operation(summary = "获取用户信息", description = "获取登录用户信息") @GetMapping("/user/info") - public R getUserInfo() { + public UserInfoResp getUserInfo() { LoginUser loginUser = LoginHelper.getLoginUser(); UserDetailResp userDetailResp = userService.get(loginUser.getId()); UserInfoResp userInfoResp = BeanUtil.copyProperties(userDetailResp, UserInfoResp.class); userInfoResp.setPermissions(loginUser.getPermissions()); userInfoResp.setRoles(loginUser.getRoleCodes()); userInfoResp.setPwdExpired(loginUser.isPasswordExpired()); - return R.ok(userInfoResp); + return userInfoResp; } @Log(ignore = true) @Operation(summary = "获取路由信息", description = "获取登录用户的路由信息") @GetMapping("/route") - public R> listRoute() { - return R.ok(loginService.buildRouteTree(LoginHelper.getUserId())); + public List listRoute() { + return loginService.buildRouteTree(LoginHelper.getUserId()); } } \ No newline at end of file diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/SocialAuthController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/SocialAuthController.java index 2a28e0aa..100868ab 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/SocialAuthController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/auth/SocialAuthController.java @@ -36,7 +36,6 @@ import top.continew.admin.auth.service.LoginService; import top.continew.starter.core.exception.BadRequestException; import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.log.core.annotation.Log; -import top.continew.starter.web.model.R; /** * 三方账号认证 API @@ -58,17 +57,17 @@ public class SocialAuthController { @Operation(summary = "三方账号登录授权", description = "三方账号登录授权") @Parameter(name = "source", description = "来源", example = "gitee", in = ParameterIn.PATH) @GetMapping("/{source}") - public R authorize(@PathVariable String source) { + public SocialAuthAuthorizeResp authorize(@PathVariable String source) { AuthRequest authRequest = this.getAuthRequest(source); - return R.ok(SocialAuthAuthorizeResp.builder() + return SocialAuthAuthorizeResp.builder() .authorizeUrl(authRequest.authorize(AuthStateUtils.createState())) - .build()); + .build(); } @Operation(summary = "三方账号登录", description = "三方账号登录") @Parameter(name = "source", description = "来源", example = "gitee", in = ParameterIn.PATH) @PostMapping("/{source}") - public R login(@PathVariable String source, @RequestBody AuthCallback callback) { + public LoginResp login(@PathVariable String source, @RequestBody AuthCallback callback) { if (StpUtil.isLogin()) { StpUtil.logout(); } @@ -77,7 +76,7 @@ public class SocialAuthController { ValidationUtils.throwIf(!response.ok(), response.getMsg()); AuthUser authUser = response.getData(); String token = loginService.socialLogin(authUser); - return R.ok(LoginResp.builder().token(token).build()); + return LoginResp.builder().token(token).build(); } private AuthRequest getAuthRequest(String source) { diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CaptchaController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CaptchaController.java index 164f095c..2085d9d3 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CaptchaController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CaptchaController.java @@ -90,33 +90,33 @@ public class CaptchaController { @Log(ignore = true) @Operation(summary = "获取行为验证码", description = "获取行为验证码(Base64编码)") @GetMapping("/behavior") - public R getBehaviorCaptcha(CaptchaVO captchaReq, HttpServletRequest request) { + public Object getBehaviorCaptcha(CaptchaVO captchaReq, HttpServletRequest request) { captchaReq.setBrowserInfo(JakartaServletUtil.getClientIP(request) + request.getHeader(HttpHeaders.USER_AGENT)); ResponseModel responseModel = behaviorCaptchaService.get(captchaReq); CheckUtils.throwIf(() -> !StrUtil.equals(RepCodeEnum.SUCCESS.getCode(), responseModel .getRepCode()), responseModel.getRepMsg()); - return R.ok(responseModel.getRepData()); + return responseModel.getRepData(); } @Log(ignore = true) @Operation(summary = "校验行为验证码", description = "校验行为验证码") @PostMapping("/behavior") - public R checkBehaviorCaptcha(@RequestBody CaptchaVO captchaReq, HttpServletRequest request) { + public Object checkBehaviorCaptcha(@RequestBody CaptchaVO captchaReq, HttpServletRequest request) { captchaReq.setBrowserInfo(JakartaServletUtil.getClientIP(request) + request.getHeader(HttpHeaders.USER_AGENT)); - return R.ok(behaviorCaptchaService.check(captchaReq)); + return behaviorCaptchaService.check(captchaReq); } @Log(ignore = true) @Operation(summary = "获取图片验证码", description = "获取图片验证码(Base64编码,带图片格式:data:image/gif;base64)") @GetMapping("/image") - public R getImageCaptcha() { + public CaptchaResp getImageCaptcha() { String uuid = IdUtil.fastUUID(); String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + uuid; Captcha captcha = graphicCaptchaService.getCaptcha(); long expireTime = LocalDateTimeUtil.toEpochMilli(LocalDateTime.now() .plusMinutes(captchaProperties.getExpirationInMinutes())); RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes())); - return R.ok(CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).expireTime(expireTime).build()); + return CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).expireTime(expireTime).build(); } /** @@ -140,7 +140,7 @@ public class CaptchaController { @RateLimiter(name = CacheConstants.CAPTCHA_KEY_PREFIX + "DAY'", key = "#email + ':' + T(cn.hutool.extra.spring.SpringUtil).getProperty('captcha.mail.templatePath')", rate = 20, interval = 24, unit = RateIntervalUnit.HOURS, message = "获取验证码操作太频繁,请稍后再试"), @RateLimiter(name = CacheConstants.CAPTCHA_KEY_PREFIX, key = "#email", rate = 100, interval = 24, unit = RateIntervalUnit.HOURS, message = "获取验证码操作太频繁,请稍后再试"), @RateLimiter(name = CacheConstants.CAPTCHA_KEY_PREFIX, key = "#email", rate = 30, interval = 1, unit = RateIntervalUnit.MINUTES, type = LimitType.IP, message = "获取验证码操作太频繁,请稍后再试")}) - public R getMailCaptcha(@NotBlank(message = "邮箱不能为空") @Pattern(regexp = RegexPool.EMAIL, message = "邮箱格式错误") String email) throws MessagingException { + public R getMailCaptcha(@NotBlank(message = "邮箱不能为空") @Pattern(regexp = RegexPool.EMAIL, message = "邮箱格式错误") String email) throws MessagingException { // 生成验证码 CaptchaProperties.CaptchaMail captchaMail = captchaProperties.getMail(); String captcha = RandomUtil.randomNumbers(captchaMail.getLength()); @@ -182,8 +182,8 @@ public class CaptchaController { @RateLimiter(name = CacheConstants.CAPTCHA_KEY_PREFIX + "DAY'", key = "#phone + ':' + T(cn.hutool.extra.spring.SpringUtil).getProperty('captcha.sms.templateId')", rate = 20, interval = 24, unit = RateIntervalUnit.HOURS, message = "获取验证码操作太频繁,请稍后再试"), @RateLimiter(name = CacheConstants.CAPTCHA_KEY_PREFIX, key = "#phone", rate = 100, interval = 24, unit = RateIntervalUnit.HOURS, message = "获取验证码操作太频繁,请稍后再试"), @RateLimiter(name = CacheConstants.CAPTCHA_KEY_PREFIX, key = "#phone", rate = 30, interval = 1, unit = RateIntervalUnit.MINUTES, type = LimitType.IP, message = "获取验证码操作太频繁,请稍后再试")}) - public R getSmsCaptcha(@NotBlank(message = "手机号不能为空") @Pattern(regexp = RegexPool.MOBILE, message = "手机号格式错误") String phone, - CaptchaVO captchaReq) { + public R getSmsCaptcha(@NotBlank(message = "手机号不能为空") @Pattern(regexp = RegexPool.MOBILE, message = "手机号格式错误") String phone, + CaptchaVO captchaReq) { // 行为验证码校验 ResponseModel verificationRes = behaviorCaptchaService.verification(captchaReq); ValidationUtils.throwIfNotEqual(verificationRes.getRepCode(), RepCodeEnum.SUCCESS.getCode(), verificationRes diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CommonController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CommonController.java index 7c4525fb..033c8f08 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CommonController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/CommonController.java @@ -43,7 +43,6 @@ import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.resp.LabelValueResp; import top.continew.starter.log.core.annotation.Log; -import top.continew.starter.web.model.R; import java.util.List; @@ -71,49 +70,49 @@ public class CommonController { @Operation(summary = "上传文件", description = "上传文件") @PostMapping("/file") - public R upload(@NotNull(message = "文件不能为空") MultipartFile file) { + public FileUploadResp upload(@NotNull(message = "文件不能为空") MultipartFile file) { ValidationUtils.throwIf(projectProperties.isProduction(), "演示环境不支持上传文件"); ValidationUtils.throwIf(file::isEmpty, "文件不能为空"); FileInfo fileInfo = fileService.upload(file); - return R.ok(FileUploadResp.builder().url(fileInfo.getUrl()).build()); + return FileUploadResp.builder().url(fileInfo.getUrl()).build(); } @Operation(summary = "查询部门树", description = "查询树结构的部门列表") @GetMapping("/tree/dept") - public R>> listDeptTree(DeptQuery query, SortQuery sortQuery) { - return R.ok(deptService.tree(query, sortQuery, true)); + public List> listDeptTree(DeptQuery query, SortQuery sortQuery) { + return deptService.tree(query, sortQuery, true); } @Operation(summary = "查询菜单树", description = "查询树结构的菜单列表") @GetMapping("/tree/menu") - public R>> listMenuTree(MenuQuery query, SortQuery sortQuery) { - return R.ok(menuService.tree(query, sortQuery, true)); + public List> listMenuTree(MenuQuery query, SortQuery sortQuery) { + return menuService.tree(query, sortQuery, true); } @Operation(summary = "查询角色字典", description = "查询角色字典列表") @GetMapping("/dict/role") - public R> listRoleDict(RoleQuery query, SortQuery sortQuery) { - return R.ok(roleService.listDict(query, sortQuery)); + public List listRoleDict(RoleQuery query, SortQuery sortQuery) { + return roleService.listDict(query, sortQuery); } @Operation(summary = "查询字典", description = "查询字典列表") @Parameter(name = "code", description = "字典编码", example = "notice_type", in = ParameterIn.PATH) @GetMapping("/dict/{code}") - public R> listDict(@PathVariable String code) { - return R.ok(dictItemService.listByDictCode(code)); + public List listDict(@PathVariable String code) { + return dictItemService.listByDictCode(code); } @SaIgnore @Operation(summary = "查询参数字典", description = "查询参数字典") @GetMapping("/dict/option") @Cached(key = "#category", name = CacheConstants.OPTION_KEY_PREFIX) - public R>> listOptionDict(@NotBlank(message = "类别不能为空") @RequestParam String category) { + public List> listOptionDict(@NotBlank(message = "类别不能为空") String category) { OptionQuery optionQuery = new OptionQuery(); optionQuery.setCategory(category); - return R.ok(optionService.list(optionQuery) + return optionService.list(optionQuery) .stream() .map(option -> new LabelValueResp<>(option.getCode(), StrUtil.nullToDefault(option.getValue(), option .getDefaultValue()))) - .toList()); + .toList(); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/DashboardController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/DashboardController.java index 291b4e32..5e27fa74 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/DashboardController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/common/DashboardController.java @@ -38,7 +38,6 @@ import top.continew.admin.system.model.resp.DashboardTotalResp; import top.continew.admin.system.service.DashboardService; import top.continew.admin.system.model.resp.DashboardNoticeResp; import top.continew.starter.core.util.validate.ValidationUtils; -import top.continew.starter.web.model.R; import top.continew.starter.log.core.annotation.Log; import java.util.List; @@ -61,8 +60,8 @@ public class DashboardController { @Operation(summary = "查询总计信息", description = "查询总计信息") @GetMapping("/total") - public R getTotal() { - return R.ok(dashboardService.getTotal()); + public DashboardTotalResp getTotal() { + return dashboardService.getTotal(); } @Operation(summary = "查询访问趋势信息", description = "查询访问趋势信息") @@ -71,26 +70,26 @@ public class DashboardController { @CachePenetrationProtect @CacheRefresh(refresh = 7200) @Cached(key = "#days", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true) - public R> listAccessTrend(@PathVariable Integer days) { + public List listAccessTrend(@PathVariable Integer days) { ValidationUtils.throwIf(7 != days && 30 != days, "仅支持查询近 7/30 天访问趋势信息"); - return R.ok(dashboardService.listAccessTrend(days)); + return dashboardService.listAccessTrend(days); } @Operation(summary = "查询热门模块列表", description = "查询热门模块列表") @GetMapping("/popular/module") - public R> listPopularModule() { - return R.ok(dashboardService.listPopularModule()); + public List listPopularModule() { + return dashboardService.listPopularModule(); } @Operation(summary = "查询访客地域分布信息", description = "查询访客地域分布信息") @GetMapping("/geo/distribution") - public R getGeoDistribution() { - return R.ok(dashboardService.getGeoDistribution()); + public DashboardGeoDistributionResp getGeoDistribution() { + return dashboardService.getGeoDistribution(); } @Operation(summary = "查询公告列表", description = "查询公告列表") @GetMapping("/notice") - public R> listNotice() { - return R.ok(dashboardService.listNotice()); + public List listNotice() { + return dashboardService.listNotice(); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/monitor/OnlineUserController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/monitor/OnlineUserController.java index 61e66edd..b428899b 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/monitor/OnlineUserController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/monitor/OnlineUserController.java @@ -35,7 +35,6 @@ import top.continew.admin.auth.service.OnlineUserService; import top.continew.starter.core.util.validate.CheckUtils; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.resp.PageResp; -import top.continew.starter.web.model.R; /** * 在线用户 API @@ -54,18 +53,17 @@ public class OnlineUserController { @Operation(summary = "分页查询列表", description = "分页查询列表") @SaCheckPermission("monitor:online:list") @GetMapping - public R> page(OnlineUserQuery query, @Validated PageQuery pageQuery) { - return R.ok(baseService.page(query, pageQuery)); + public PageResp page(OnlineUserQuery query, @Validated PageQuery pageQuery) { + return baseService.page(query, pageQuery); } @Operation(summary = "强退在线用户", description = "强退在线用户") @Parameter(name = "token", description = "令牌", example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiTUd6djdyOVFoeHEwdVFqdFAzV3M5YjVJRzh4YjZPSEUifQ.7q7U3ouoN7WPhH2kUEM7vPe5KF3G_qavSG-vRgIxKvE", in = ParameterIn.PATH) @SaCheckPermission("monitor:online:kickout") @DeleteMapping("/{token}") - public R kickout(@PathVariable String token) { + public void kickout(@PathVariable String token) { String currentToken = StpUtil.getTokenValue(); CheckUtils.throwIfEqual(token, currentToken, "不能强退自己"); StpUtil.kickoutByTokenValue(token); - return R.ok("强退成功"); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobController.java index 6d52f061..4b9edec7 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobController.java @@ -32,7 +32,6 @@ import top.continew.admin.job.service.JobService; import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.util.ValidateGroup; import top.continew.starter.log.core.annotation.Log; -import top.continew.starter.web.model.R; import java.util.List; @@ -55,54 +54,53 @@ public class JobController { @Operation(summary = "分页查询任务列表", description = "分页查询任务列表") @SaCheckPermission("schedule:job:list") @GetMapping - public R> page(JobQuery query) { - return R.ok(baseService.page(query)); + public PageResp page(JobQuery query) { + return baseService.page(query); } @Operation(summary = "新增任务", description = "新增任务") @SaCheckPermission("schedule:job:add") @PostMapping - public R add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody JobReq req) { - return baseService.add(req) ? R.ok() : R.fail(); + public void add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody JobReq req) { + baseService.add(req); } @Operation(summary = "修改任务", description = "修改任务") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("schedule:job:update") @PutMapping("/{id}") - public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody JobReq req, @PathVariable Long id) { - return baseService.update(req, id) ? R.ok() : R.fail(); + public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody JobReq req, @PathVariable Long id) { + baseService.update(req, id); } @Operation(summary = "修改任务状态", description = "修改任务状态") @SaCheckPermission("schedule:job:update") @PatchMapping("/{id}/status") - public R updateStatus(@Validated @RequestBody JobStatusReq req, @PathVariable Long id) { - return baseService.updateStatus(req, id) ? R.ok() : R.fail(); + public void updateStatus(@Validated @RequestBody JobStatusReq req, @PathVariable Long id) { + baseService.updateStatus(req, id); } @Operation(summary = "删除任务", description = "删除任务") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("schedule:job:delete") @DeleteMapping("/{id}") - public R delete(@PathVariable Long id) { - return baseService.delete(id) ? R.ok() : R.fail(); + public void delete(@PathVariable Long id) { + baseService.delete(id); } @Operation(summary = "执行任务", description = "执行任务") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("schedule:job:trigger") @PostMapping("/trigger/{id}") - public R trigger(@PathVariable Long id) { - return baseService.trigger(id) ? R.ok() : R.fail(); + public void trigger(@PathVariable Long id) { + baseService.trigger(id); } @Log(ignore = true) @Operation(summary = "查询任务分组列表", description = "查询任务分组列表") @SaCheckPermission("schedule:job:list") @GetMapping("/group") - public R> listGroup() { - List groupList = baseService.listGroup(); - return R.ok(groupList); + public List listGroup() { + return baseService.listGroup(); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobLogController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobLogController.java index e924e2dc..0307e55c 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobLogController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/schedule/JobLogController.java @@ -32,7 +32,6 @@ import top.continew.admin.job.model.resp.JobLogResp; import top.continew.admin.job.model.resp.JobInstanceResp; import top.continew.admin.job.service.JobLogService; import top.continew.starter.extension.crud.model.resp.PageResp; -import top.continew.starter.web.model.R; import java.util.List; @@ -55,37 +54,37 @@ public class JobLogController { @Operation(summary = "分页查询任务日志列表", description = "分页查询任务日志列表") @SaCheckPermission("schedule:log:list") @GetMapping - public R> page(JobLogQuery query) { - return R.ok(baseService.page(query)); + public PageResp page(JobLogQuery query) { + return baseService.page(query); } @Operation(summary = "停止任务", description = "停止任务") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("schedule:log:stop") @PostMapping("/stop/{id}") - public R stop(@PathVariable Long id) { - return baseService.stop(id) ? R.ok() : R.fail(); + public void stop(@PathVariable Long id) { + baseService.stop(id); } @Operation(summary = "重试任务", description = "重试任务") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("schedule:log:retry") @PostMapping("/retry/{id}") - public R retry(@PathVariable Long id) { - return baseService.retry(id) ? R.ok() : R.fail(); + public void retry(@PathVariable Long id) { + baseService.retry(id); } @Operation(summary = "查询任务实例列表", description = "查询任务实例列表") @SaCheckPermission("schedule:log:list") @GetMapping("/instance") - public R> listInstance(JobInstanceQuery query) { - return R.ok(baseService.listInstance(query)); + public List listInstance(JobInstanceQuery query) { + return baseService.listInstance(query); } @Operation(summary = "分页查询任务实例日志列表", description = "分页查询任务实例日志列表") @SaCheckPermission("schedule:log:list") @GetMapping("/instance/log") - public R pageInstanceLog(JobInstanceLogQuery query) { - return R.ok(baseService.pageInstanceLog(query)); + public JobInstanceLogPageResult pageInstanceLog(JobInstanceLogQuery query) { + return baseService.pageInstanceLog(query); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/FileController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/FileController.java index e7fb2112..10479f27 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/FileController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/FileController.java @@ -30,7 +30,6 @@ import top.continew.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.enums.Api; import top.continew.starter.log.core.annotation.Log; -import top.continew.starter.web.model.R; /** * 文件管理 API @@ -48,7 +47,7 @@ public class FileController extends BaseController statistics() { - return R.ok(baseService.statistics()); + public FileStatisticsResp statistics() { + return baseService.statistics(); } } \ No newline at end of file diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/LogController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/LogController.java index 0aad2834..4fe68f8e 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/LogController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/LogController.java @@ -17,6 +17,7 @@ package top.continew.admin.controller.system; import cn.dev33.satoken.annotation.SaCheckPermission; +import com.feiniaojin.gracefulresponse.api.ExcludeFromGracefulResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; @@ -35,7 +36,6 @@ import top.continew.admin.system.service.LogService; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.resp.PageResp; -import top.continew.starter.web.model.R; /** * 系统日志 API @@ -54,18 +54,19 @@ public class LogController { @Operation(summary = "分页查询列表", description = "分页查询列表") @SaCheckPermission("monitor:log:list") @GetMapping - public R> page(LogQuery query, @Validated PageQuery pageQuery) { - return R.ok(baseService.page(query, pageQuery)); + public PageResp page(LogQuery query, @Validated PageQuery pageQuery) { + return baseService.page(query, pageQuery); } @Operation(summary = "查询详情", description = "查询详情") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("monitor:log:list") @GetMapping("/{id}") - public R get(@PathVariable Long id) { - return R.ok(baseService.get(id)); + public LogDetailResp get(@PathVariable Long id) { + return baseService.get(id); } + @ExcludeFromGracefulResponse @Operation(summary = "导出登录日志", description = "导出登录日志") @SaCheckPermission("monitor:log:export") @GetMapping("/export/login") @@ -73,6 +74,7 @@ public class LogController { baseService.exportLoginLog(query, sortQuery, response); } + @ExcludeFromGracefulResponse @Operation(summary = "导出操作日志", description = "导出操作日志") @SaCheckPermission("monitor:log:export") @GetMapping("/export/operation") diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MenuController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MenuController.java index e7429812..d8a313de 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MenuController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MenuController.java @@ -33,8 +33,8 @@ import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.enums.Api; +import top.continew.starter.extension.crud.model.resp.BaseIdResp; import top.continew.starter.extension.crud.util.ValidateGroup; -import top.continew.starter.web.model.R; /** * 菜单管理 API @@ -48,15 +48,15 @@ import top.continew.starter.web.model.R; public class MenuController extends BaseController { @Override - public R add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody MenuReq req) { + public BaseIdResp add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody MenuReq req) { this.checkPath(req); return super.add(req); } @Override - public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody MenuReq req, @PathVariable Long id) { + public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody MenuReq req, @PathVariable Long id) { this.checkPath(req); - return super.update(req, id); + super.update(req, id); } /** diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MessageController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MessageController.java index 397b7783..a0ea5e75 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MessageController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/MessageController.java @@ -32,7 +32,6 @@ import top.continew.admin.system.service.MessageUserService; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.log.core.annotation.Log; -import top.continew.starter.web.model.R; import java.util.List; @@ -53,32 +52,30 @@ public class MessageController { @Operation(summary = "分页查询列表", description = "分页查询列表") @GetMapping - public R> page(MessageQuery query, @Validated PageQuery pageQuery) { + public PageResp page(MessageQuery query, @Validated PageQuery pageQuery) { query.setUserId(LoginHelper.getUserId()); - return R.ok(baseService.page(query, pageQuery)); + return baseService.page(query, pageQuery); } @Operation(summary = "删除数据", description = "删除数据") @Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH) @DeleteMapping("/{ids}") - public R delete(@PathVariable List ids) { + public void delete(@PathVariable List ids) { baseService.delete(ids); - return R.ok("删除成功"); } @Operation(summary = "标记已读", description = "将消息标记为已读状态") @Parameter(name = "ids", description = "消息ID列表", example = "1,2", in = ParameterIn.QUERY) @PatchMapping("/read") - public R readMessage(@RequestParam(required = false) List ids) { + public void readMessage(@RequestParam(required = false) List ids) { messageUserService.readMessage(ids); - return R.ok(); } @Log(ignore = true) @Operation(summary = "查询未读消息数量", description = "查询当前用户的未读消息数量") @Parameter(name = "isDetail", description = "是否查询详情", example = "true", in = ParameterIn.QUERY) @GetMapping("/unread") - public R countUnreadMessage(@RequestParam(required = false) Boolean detail) { - return R.ok(messageUserService.countUnreadMessageByUserId(LoginHelper.getUserId(), detail)); + public MessageUnreadResp countUnreadMessage(@RequestParam(required = false) Boolean detail) { + return messageUserService.countUnreadMessageByUserId(LoginHelper.getUserId(), detail); } } \ No newline at end of file diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java index f76f6a5b..45c38bde 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java @@ -30,8 +30,8 @@ import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.enums.Api; +import top.continew.starter.extension.crud.model.resp.BaseIdResp; import top.continew.starter.extension.crud.util.ValidateGroup; -import top.continew.starter.web.model.R; import java.time.LocalDateTime; @@ -47,16 +47,15 @@ import java.time.LocalDateTime; public class NoticeController extends BaseController { @Override - public R add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody NoticeReq req) { + public BaseIdResp add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody NoticeReq req) { this.checkTime(req); return super.add(req); } @Override - public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody NoticeReq req, - @PathVariable Long id) { + public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody NoticeReq req, @PathVariable Long id) { this.checkTime(req); - return super.update(req, id); + super.update(req, id); } /** diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/OptionController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/OptionController.java index 2d8b8181..d0836452 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/OptionController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/OptionController.java @@ -28,7 +28,6 @@ import top.continew.admin.system.model.req.OptionReq; import top.continew.admin.system.model.req.OptionResetValueReq; import top.continew.admin.system.model.resp.OptionResp; import top.continew.admin.system.service.OptionService; -import top.continew.starter.web.model.R; import java.util.List; @@ -50,23 +49,21 @@ public class OptionController { @Operation(summary = "查询参数列表", description = "查询参数列表") @SaCheckPermission("system:config:list") @GetMapping - public R> list(@Validated OptionQuery query) { - return R.ok(baseService.list(query)); + public List list(@Validated OptionQuery query) { + return baseService.list(query); } @Operation(summary = "修改参数", description = "修改参数") @SaCheckPermission("system:config:update") @PutMapping - public R update(@Valid @RequestBody List options) { + public void update(@Valid @RequestBody List options) { baseService.update(options); - return R.ok(); } @Operation(summary = "重置参数", description = "重置参数") @SaCheckPermission("system:config:reset") @PatchMapping("/value") - public R resetValue(@Validated @RequestBody OptionResetValueReq req) { + public void resetValue(@Validated @RequestBody OptionResetValueReq req) { baseService.resetValue(req); - return R.ok(); } } \ No newline at end of file diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java index 70c3398b..356c6a62 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java @@ -31,9 +31,9 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import top.continew.admin.common.constant.CacheConstants; -import top.continew.admin.system.enums.SocialSourceEnum; import top.continew.admin.common.util.SecureUtils; import top.continew.admin.common.util.helper.LoginHelper; +import top.continew.admin.system.enums.SocialSourceEnum; import top.continew.admin.system.model.entity.UserSocialDO; import top.continew.admin.system.model.req.UserBasicInfoUpdateReq; import top.continew.admin.system.model.req.UserEmailUpdateRequest; @@ -46,7 +46,6 @@ import top.continew.admin.system.service.UserSocialService; import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.validate.ValidationUtils; -import top.continew.starter.web.model.R; import java.io.IOException; import java.util.List; @@ -72,22 +71,21 @@ public class UserCenterController { @Operation(summary = "修改头像", description = "用户修改个人头像") @PostMapping("/avatar") - public R updateAvatar(@NotNull(message = "头像不能为空") MultipartFile avatarFile) throws IOException { + public AvatarResp updateAvatar(@NotNull(message = "头像不能为空") MultipartFile avatarFile) throws IOException { ValidationUtils.throwIf(avatarFile::isEmpty, "头像不能为空"); String newAvatar = userService.updateAvatar(avatarFile, LoginHelper.getUserId()); - return R.ok("修改成功", AvatarResp.builder().avatar(newAvatar).build()); + return AvatarResp.builder().avatar(newAvatar).build(); } @Operation(summary = "修改基础信息", description = "修改用户基础信息") @PatchMapping("/basic/info") - public R updateBasicInfo(@Validated @RequestBody UserBasicInfoUpdateReq req) { + public void updateBasicInfo(@Validated @RequestBody UserBasicInfoUpdateReq req) { userService.updateBasicInfo(req, LoginHelper.getUserId()); - return R.ok("修改成功"); } @Operation(summary = "修改密码", description = "修改用户登录密码") @PatchMapping("/password") - public R updatePassword(@Validated @RequestBody UserPasswordUpdateReq updateReq) { + public void updatePassword(@Validated @RequestBody UserPasswordUpdateReq updateReq) { String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq .getOldPassword())); ValidationUtils.throwIfNull(rawOldPassword, DECRYPT_FAILED); @@ -95,12 +93,11 @@ public class UserCenterController { .getNewPassword())); ValidationUtils.throwIfNull(rawNewPassword, "新密码解密失败"); userService.updatePassword(rawOldPassword, rawNewPassword, LoginHelper.getUserId()); - return R.ok("修改成功,请牢记你的新密码"); } @Operation(summary = "修改手机号", description = "修改手机号") @PatchMapping("/phone") - public R updatePhone(@Validated @RequestBody UserPhoneUpdateReq updateReq) { + public void updatePhone(@Validated @RequestBody UserPhoneUpdateReq updateReq) { String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq .getOldPassword())); ValidationUtils.throwIfBlank(rawOldPassword, DECRYPT_FAILED); @@ -110,12 +107,11 @@ public class UserCenterController { ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误"); RedisUtils.delete(captchaKey); userService.updatePhone(updateReq.getPhone(), rawOldPassword, LoginHelper.getUserId()); - return R.ok("修改成功"); } @Operation(summary = "修改邮箱", description = "修改用户邮箱") @PatchMapping("/email") - public R updateEmail(@Validated @RequestBody UserEmailUpdateRequest updateReq) { + public void updateEmail(@Validated @RequestBody UserEmailUpdateRequest updateReq) { String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq .getOldPassword())); ValidationUtils.throwIfBlank(rawOldPassword, DECRYPT_FAILED); @@ -125,40 +121,36 @@ public class UserCenterController { ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误"); RedisUtils.delete(captchaKey); userService.updateEmail(updateReq.getEmail(), rawOldPassword, LoginHelper.getUserId()); - return R.ok("修改成功"); } @Operation(summary = "查询绑定的三方账号", description = "查询绑定的三方账号") @GetMapping("/social") - public R> listSocialBind() { + public List listSocialBind() { List userSocialList = userSocialService.listByUserId(LoginHelper.getUserId()); - List userSocialBindList = userSocialList.stream().map(userSocial -> { + return userSocialList.stream().map(userSocial -> { String source = userSocial.getSource(); UserSocialBindResp userSocialBind = new UserSocialBindResp(); userSocialBind.setSource(source); userSocialBind.setDescription(SocialSourceEnum.valueOf(source).getDescription()); return userSocialBind; }).toList(); - return R.ok(userSocialBindList); } @Operation(summary = "绑定三方账号", description = "绑定三方账号") @Parameter(name = "source", description = "来源", example = "gitee", in = ParameterIn.PATH) @PostMapping("/social/{source}") - public R bindSocial(@PathVariable String source, @RequestBody AuthCallback callback) { + public void bindSocial(@PathVariable String source, @RequestBody AuthCallback callback) { AuthRequest authRequest = authRequestFactory.get(source); AuthResponse response = authRequest.login(callback); ValidationUtils.throwIf(!response.ok(), response.getMsg()); AuthUser authUser = response.getData(); userSocialService.bind(authUser, LoginHelper.getUserId()); - return R.ok("绑定成功"); } @Operation(summary = "解绑三方账号", description = "解绑三方账号") @Parameter(name = "source", description = "来源", example = "gitee", in = ParameterIn.PATH) @DeleteMapping("/social/{source}") - public R unbindSocial(@PathVariable String source) { + public void unbindSocial(@PathVariable String source) { userSocialService.deleteBySourceAndUserId(source, LoginHelper.getUserId()); - return R.ok("解绑成功"); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java index 80e75825..b5a0229e 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java @@ -43,8 +43,8 @@ import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.enums.Api; +import top.continew.starter.extension.crud.model.resp.BaseIdResp; import top.continew.starter.extension.crud.util.ValidateGroup; -import top.continew.starter.web.model.R; import java.io.IOException; @@ -64,7 +64,7 @@ public class UserController extends BaseController add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) { + public BaseIdResp add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) { String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getPassword())); ValidationUtils.throwIfNull(rawPassword, "密码解密失败"); ValidationUtils.throwIf(!ReUtil @@ -83,38 +83,36 @@ public class UserController extends BaseController parseImportUser(@NotNull(message = "文件不能为空") MultipartFile file) { + public UserImportParseResp parseImportUser(@NotNull(message = "文件不能为空") MultipartFile file) { ValidationUtils.throwIf(file::isEmpty, "文件不能为空"); - return R.ok(userService.parseImportUser(file)); + return userService.parseImportUser(file); } @Operation(summary = "导入用户", description = "导入用户") @SaCheckPermission("system:user:import") @PostMapping(value = "import") - public R importUser(@Validated @RequestBody UserImportReq req) { - return R.ok(userService.importUser(req)); + public UserImportResp importUser(@Validated @RequestBody UserImportReq req) { + return userService.importUser(req); } @Operation(summary = "重置密码", description = "重置用户登录密码") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("system:user:resetPwd") @PatchMapping("/{id}/password") - public R resetPassword(@Validated @RequestBody UserPasswordResetReq req, @PathVariable Long id) { + public void resetPassword(@Validated @RequestBody UserPasswordResetReq req, @PathVariable Long id) { String rawNewPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getNewPassword())); ValidationUtils.throwIfNull(rawNewPassword, "新密码解密失败"); ValidationUtils.throwIf(!ReUtil .isMatch(RegexConstants.PASSWORD, rawNewPassword), "密码长度为 8-32 个字符,支持大小写字母、数字、特殊字符,至少包含字母和数字"); req.setNewPassword(rawNewPassword); baseService.resetPassword(req, id); - return R.ok("重置密码成功"); } @Operation(summary = "分配角色", description = "为用户新增或移除角色") @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) @SaCheckPermission("system:user:updateRole") @PatchMapping("/{id}/role") - public R updateRole(@Validated @RequestBody UserRoleUpdateReq updateReq, @PathVariable Long id) { + public void updateRole(@Validated @RequestBody UserRoleUpdateReq updateReq, @PathVariable Long id) { baseService.updateRole(updateReq, id); - return R.ok("分配成功"); } } diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/tool/GeneratorController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/tool/GeneratorController.java index bf34f254..0d8df903 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/tool/GeneratorController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/tool/GeneratorController.java @@ -21,7 +21,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; @@ -35,7 +34,6 @@ import top.continew.admin.generator.model.resp.TableResp; import top.continew.admin.generator.service.GeneratorService; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.resp.PageResp; -import top.continew.starter.web.model.R; import java.sql.SQLException; import java.util.List; @@ -58,8 +56,8 @@ public class GeneratorController { @Operation(summary = "分页查询数据表", description = "分页查询数据表") @SaCheckPermission("tool:generator:list") @GetMapping("/table") - public R> pageTable(TableQuery query, @Validated PageQuery pageQuery) throws SQLException { - return R.ok(baseService.pageTable(query, pageQuery)); + public PageResp pageTable(TableQuery query, @Validated PageQuery pageQuery) throws SQLException { + return baseService.pageTable(query, pageQuery); } @Operation(summary = "查询字段配置列表", description = "查询字段配置列表") @@ -67,43 +65,40 @@ public class GeneratorController { @Parameter(name = "requireSync", description = "是否需要同步", example = "false", in = ParameterIn.QUERY) @SaCheckPermission("tool:generator:list") @GetMapping("/field/{tableName}") - public R> listFieldConfig(@PathVariable String tableName, - @RequestParam(required = false, defaultValue = "false") Boolean requireSync) { - return R.ok(baseService.listFieldConfig(tableName, requireSync)); + public List listFieldConfig(@PathVariable String tableName, + @RequestParam(required = false, defaultValue = "false") Boolean requireSync) { + return baseService.listFieldConfig(tableName, requireSync); } @Operation(summary = "查询生成配置信息", description = "查询生成配置信息") @Parameter(name = "tableName", description = "表名称", required = true, example = "sys_user", in = ParameterIn.PATH) @SaCheckPermission("tool:generator:list") @GetMapping("/config/{tableName}") - public R getGenConfig(@PathVariable String tableName) throws SQLException { - return R.ok(baseService.getGenConfig(tableName)); + public GenConfigDO getGenConfig(@PathVariable String tableName) throws SQLException { + return baseService.getGenConfig(tableName); } @Operation(summary = "保存配置信息", description = "保存配置信息") @Parameter(name = "tableName", description = "表名称", required = true, example = "sys_user", in = ParameterIn.PATH) @SaCheckPermission("tool:generator:list") @PostMapping("/config/{tableName}") - public R saveConfig(@Validated @RequestBody GenConfigReq req, @PathVariable String tableName) { + public void saveConfig(@Validated @RequestBody GenConfigReq req, @PathVariable String tableName) { baseService.saveConfig(req, tableName); - return R.ok("保存成功"); } @Operation(summary = "生成预览", description = "预览生成代码") @Parameter(name = "tableName", description = "表名称", required = true, example = "sys_user", in = ParameterIn.PATH) @SaCheckPermission("tool:generator:list") @GetMapping("/preview/{tableName}") - public R> preview(@PathVariable String tableName) { - return R.ok(baseService.preview(tableName)); + public List preview(@PathVariable String tableName) { + return baseService.preview(tableName); } @Operation(summary = "生成代码", description = "生成代码") @Parameter(name = "tableName", description = "表名称", required = true, example = "sys_user", in = ParameterIn.PATH) @SaCheckPermission("tool:generator:list") @PostMapping("/{tableNames}") - public void generate(@PathVariable List tableNames, - HttpServletRequest request, - HttpServletResponse response) { - baseService.generate(tableNames, request, response); + public void generate(@PathVariable List tableNames, HttpServletResponse response) { + baseService.generate(tableNames, response); } } diff --git a/continew-admin-webapi/src/main/resources/banner.txt b/continew-admin-webapi/src/main/resources/banner.txt index 29cddd83..4e611b92 100644 --- a/continew-admin-webapi/src/main/resources/banner.txt +++ b/continew-admin-webapi/src/main/resources/banner.txt @@ -5,5 +5,5 @@ \____|\___/ |_| |_| \__||_||_| \_| \___| \_/\_/ /_/ \_\\__,_||_| |_| |_||_||_| |_| :: ${project.name} :: v${project.version} - :: ContiNew Starter :: v2.4.0 + :: ContiNew Starter :: v2.5.0 :: Spring Boot :: v${spring-boot.version} diff --git a/continew-admin-webapi/src/main/resources/config/application.yml b/continew-admin-webapi/src/main/resources/config/application.yml index b05e8faa..6490131b 100644 --- a/continew-admin-webapi/src/main/resources/config/application.yml +++ b/continew-admin-webapi/src/main/resources/config/application.yml @@ -48,6 +48,20 @@ continew-starter.web: pattern: '[$spanId][$traceId]' mdc-enable: false +--- ### 全局响应配置 +continew-starter.web: + response: + # 是否开启国际化(默认:false) + i18n: false + # 自定义成功响应码(默认:0) + default-success-code: 0 + # 自定义成功提示(默认:ok) + default-success-msg: ok + # 自定义失败响应码(默认:1) + default-error-code: 1 + # 自定义失败提示(默认:error) + default-error-msg: error + --- ### 接口文档配置 springdoc: # 设置对象型参数的展示形式(设为 true 表示将对象型参数平展开,即对象内的属性直接作为参数展示而不是嵌套在对象内,默认 false) diff --git a/pom.xml b/pom.xml index 5acf7d86..bb6bb2c8 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ top.continew continew-starter - 2.4.0 + 2.5.0 top.continew