From 66466df71398e33dddf2317f41733f12494d4925 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Tue, 22 Jul 2025 23:41:30 +0800 Subject: [PATCH] =?UTF-8?q?:speech=5Fballoon:=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=96=87=E6=9C=AC=E5=92=8C=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/AuthenticSecurityException.java | 2 +- .../AuthenticationFailException.java | 42 +++++++++++++++++++ .../exception/MyAuthenticationException.java | 19 --------- .../model/common/result/ResultCodeEnum.java | 2 +- .../template/VmsTBaseTemplateGenerator.java | 3 ++ .../generator/model/dto/VmsArgumentDto.java | 3 ++ .../helper/VmsGeneratorPathHelper.java | 39 ++++++++++------- .../service/impl/GeneratorServiceImpl.java | 2 +- .../static/src/views/database/DatabaseForm.js | 4 ++ .../main/resources/templates/database.html | 2 + .../vms/server/controller/controller.java.vm | 5 +++ .../vms/web/api/{ => $webBasePath}/api.ts.vm | 12 +++--- .../modules/{ => $webBasePath}/store.ts.vm | 2 +- .../{ => $webBasePath}/$className/types.ts.vm | 0 .../views/$className/components/dialog.vue.vm | 4 +- .../vms/web/views/$className/index.vue.vm | 3 +- .../web/views/$className/utils/hook.tsx.vm | 6 +-- .../filter/JwtAuthenticationFilter.java | 17 +++----- .../SecurityAuthenticationEntryPoint.java | 11 +++-- .../base/controller/AuthLogController.java | 9 +++- .../base/controller/DeptController.java | 8 +++- .../base/controller/DictController.java | 8 +++- .../controller/EmailConfigController.java | 9 +++- .../controller/EmailTemplateController.java | 8 +++- .../base/controller/FileController.java | 9 +++- .../base/controller/LoginLogController.java | 8 +++- .../base/controller/MenuController.java | 8 +++- .../base/controller/MenuRoleController.java | 8 +++- .../controller/OperationLogController.java | 8 +++- .../base/controller/PermissionController.java | 8 +++- .../base/controller/RoleController.java | 8 +++- .../controller/RoleDataScopeController.java | 8 +++- .../controller/RolePermissionController.java | 8 +++- .../base/controller/UserController.java | 8 +++- .../base/controller/UserDeptController.java | 8 +++- .../base/controller/UserRoleController.java | 8 +++- 36 files changed, 234 insertions(+), 83 deletions(-) create mode 100644 auth-common/src/main/java/com/auth/common/exception/AuthenticationFailException.java delete mode 100644 auth-common/src/main/java/com/auth/common/exception/MyAuthenticationException.java rename auth-module/module-generator-code/src/main/resources/vms/web/api/{ => $webBasePath}/api.ts.vm (57%) rename auth-module/module-generator-code/src/main/resources/vms/web/store/modules/{ => $webBasePath}/store.ts.vm (96%) rename auth-module/module-generator-code/src/main/resources/vms/web/types/{ => $webBasePath}/$className/types.ts.vm (100%) diff --git a/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java b/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java index dc42d66..d52fdf0 100644 --- a/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java +++ b/auth-common/src/main/java/com/auth/common/exception/AuthenticSecurityException.java @@ -7,9 +7,9 @@ import lombok.NoArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; -@NoArgsConstructor @Getter @ToString +@NoArgsConstructor @Slf4j public class AuthenticSecurityException extends RuntimeException { // 状态码 diff --git a/auth-common/src/main/java/com/auth/common/exception/AuthenticationFailException.java b/auth-common/src/main/java/com/auth/common/exception/AuthenticationFailException.java new file mode 100644 index 0000000..a554ac1 --- /dev/null +++ b/auth-common/src/main/java/com/auth/common/exception/AuthenticationFailException.java @@ -0,0 +1,42 @@ +package com.auth.common.exception; + +import com.auth.common.model.common.result.ResultCodeEnum; +import lombok.Getter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.AuthenticationException; + +/** + * 自定义未认证异常 + */ +@Getter +@ToString +@Slf4j +public class AuthenticationFailException extends AuthenticationException { + // 状态码 + Integer code; + + // 描述信息 + String message = "服务异常"; + + // 返回结果状态 + ResultCodeEnum resultCodeEnum; + + /** + * Constructs an {@code AuthenticationException} with the specified message and root + * cause. + * + * @param msg the detail message + * @param cause the root cause + */ + public AuthenticationFailException(String msg, Throwable cause) { + super(msg, cause); + } + + public AuthenticationFailException(ResultCodeEnum codeEnum) { + super(codeEnum.getMessage()); + this.code = codeEnum.getCode(); + this.message = codeEnum.getMessage(); + this.resultCodeEnum = codeEnum; + } +} \ No newline at end of file diff --git a/auth-common/src/main/java/com/auth/common/exception/MyAuthenticationException.java b/auth-common/src/main/java/com/auth/common/exception/MyAuthenticationException.java deleted file mode 100644 index 18f4ac8..0000000 --- a/auth-common/src/main/java/com/auth/common/exception/MyAuthenticationException.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.auth.common.exception; - -import org.springframework.security.core.AuthenticationException; - -/** - * 自定义未认证异常 - */ -public class MyAuthenticationException extends AuthenticationException { - /** - * Constructs an {@code AuthenticationException} with the specified message and root - * cause. - * - * @param msg the detail message - * @param cause the root cause - */ - public MyAuthenticationException(String msg, Throwable cause) { - super(msg, cause); - } -} \ No newline at end of file diff --git a/auth-common/src/main/java/com/auth/common/model/common/result/ResultCodeEnum.java b/auth-common/src/main/java/com/auth/common/model/common/result/ResultCodeEnum.java index be7e555..b10b7d5 100644 --- a/auth-common/src/main/java/com/auth/common/model/common/result/ResultCodeEnum.java +++ b/auth-common/src/main/java/com/auth/common/model/common/result/ResultCodeEnum.java @@ -75,7 +75,7 @@ public enum ResultCodeEnum { // 系统错误 500 UNKNOWN_EXCEPTION(500, "服务异常"), - SERVICE_ERROR(500, "服务异常"), + AUTHENTICATION_FAILED(500, "身份验证失败"), UPLOAD_ERROR(500, "上传失败"), FAIL(500, "失败"), ; diff --git a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/core/template/VmsTBaseTemplateGenerator.java b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/core/template/VmsTBaseTemplateGenerator.java index fdd2493..b72d00a 100644 --- a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/core/template/VmsTBaseTemplateGenerator.java +++ b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/core/template/VmsTBaseTemplateGenerator.java @@ -77,6 +77,9 @@ public class VmsTBaseTemplateGenerator extends AbstractTemplateGenerator { // 设置包名称 context.put("package", dto.getPackageName()); + // 前端基础生成路径 + context.put("webBasePath", dto.getWebBasePath()); + // 将类名称转成小驼峰 String lowerCamelCase = CamelCaseNameConvertUtil.convertToCamelCase(cleanTableName, false); context.put("classLowercaseName", lowerCamelCase); diff --git a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/model/dto/VmsArgumentDto.java b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/model/dto/VmsArgumentDto.java index 111a793..f9eb3f9 100644 --- a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/model/dto/VmsArgumentDto.java +++ b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/model/dto/VmsArgumentDto.java @@ -30,6 +30,9 @@ public class VmsArgumentDto { @Schema(name = "tablePrefixes", description = "去除表前缀") private String tablePrefixes = ""; + @Schema(name = "webBasePath", description = "前端基础生成路径") + private String webBasePath; + @Schema(name = "path", description = "路径") @NotEmpty(message = "表名称不能为空") private List path; diff --git a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/helper/VmsGeneratorPathHelper.java b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/helper/VmsGeneratorPathHelper.java index 0d8bcac..0666901 100644 --- a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/helper/VmsGeneratorPathHelper.java +++ b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/helper/VmsGeneratorPathHelper.java @@ -1,7 +1,11 @@ package com.auth.module.generator.service.helper; +import com.auth.module.generator.model.dto.VmsArgumentDto; import com.auth.module.generator.utils.CamelCaseNameConvertUtil; import com.google.common.base.CaseFormat; +import org.apache.velocity.shaded.commons.io.FilenameUtils; + +import java.nio.file.Paths; /** * 代码生成工具类 @@ -13,23 +17,31 @@ public class VmsGeneratorPathHelper { * * @param path 原始模板路径 * @param tableName 数据库表名 + * @param dto 生成代码请求参数 * @return 处理后的文件路径 */ - public static String processVmPath(String path, String tableName) { + public static String processVmPath(String path, String tableName, VmsArgumentDto dto) { String lowerCamelCase = CamelCaseNameConvertUtil.convertToCamelCase(tableName, false); + String webBasePath = dto.getWebBasePath(); - if (lowerCamelCase != null) { - String[] pathParts = path.replace("$className", lowerCamelCase).split("/"); - // 处理文件名 - pathParts[pathParts.length - 1] = processFilename( - pathParts[pathParts.length - 1], - lowerCamelCase - ); - - return String.join("/", pathParts); + if (lowerCamelCase != null && path.contains("$className")) { + // 💡 替换文件中的 特殊名称 + path = path.replace("$className", lowerCamelCase); } - return path; + if (webBasePath != null && path.contains("$webBasePath")) { + webBasePath = webBasePath.replace("/", ""); + // 💡 替换文件中的 特殊名称 + path = path.replace("$webBasePath", webBasePath); + } + + // 获取当前路径的文件名 + String filename = Paths.get(path).getFileName().toString(); + + // 处理文件名 + String processedFilename = processFilename(filename, tableName); + + return path.replace(filename, processedFilename); } /** @@ -37,9 +49,8 @@ public class VmsGeneratorPathHelper { */ private static String processFilename(String filename, String tableName) { filename = filename.replace(".vm", ""); - String[] parts = filename.split("\\."); - String baseName = parts[0]; - String extension = parts.length > 1 ? parts[1] : ""; + String baseName = FilenameUtils.getBaseName(filename); + String extension = FilenameUtils.getExtension(filename); String upperCamelCase = CamelCaseNameConvertUtil.convertToCamelCase(tableName, true); String lowerCamelCase = CamelCaseNameConvertUtil.convertToCamelCase(tableName, false); diff --git a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/impl/GeneratorServiceImpl.java b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/impl/GeneratorServiceImpl.java index df23815..6ea6bde 100644 --- a/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/impl/GeneratorServiceImpl.java +++ b/auth-module/module-generator-code/src/main/java/com/auth/module/generator/service/impl/GeneratorServiceImpl.java @@ -154,7 +154,7 @@ public class GeneratorServiceImpl implements GeneratorService { // 生成好的模板 String code = generator.generateCode(tableMeta, columns).toString(); - String processVmPath = VmsGeneratorPathHelper.processVmPath(path, tableMeta.getCleanTableName()); + String processVmPath = VmsGeneratorPathHelper.processVmPath(path, tableMeta.getCleanTableName(), dto); return GeneratorVo.builder() .id(UUID.randomUUID().toString()) diff --git a/auth-module/module-generator-code/src/main/resources/static/src/views/database/DatabaseForm.js b/auth-module/module-generator-code/src/main/resources/static/src/views/database/DatabaseForm.js index fd84bb1..ea93c94 100644 --- a/auth-module/module-generator-code/src/main/resources/static/src/views/database/DatabaseForm.js +++ b/auth-module/module-generator-code/src/main/resources/static/src/views/database/DatabaseForm.js @@ -61,6 +61,10 @@ const DatabaseForm = {
{{ errors.tablePrefixes || '请输入去除开头前缀' }}
+ +
+ +
diff --git a/auth-module/module-generator-code/src/main/resources/templates/database.html b/auth-module/module-generator-code/src/main/resources/templates/database.html index ea27344..d26e472 100644 --- a/auth-module/module-generator-code/src/main/resources/templates/database.html +++ b/auth-module/module-generator-code/src/main/resources/templates/database.html @@ -100,6 +100,8 @@ simpleDateFormat: "yyyy-MM-dd HH:mm:ss", // 去除开头前缀 tablePrefixes: "t_,sys_,qrtz_,log_", + // 前端基础生成路径 + webBasePath: "/system", // 生成代码路径 path: [], }), diff --git a/auth-module/module-generator-code/src/main/resources/vms/server/controller/controller.java.vm b/auth-module/module-generator-code/src/main/resources/vms/server/controller/controller.java.vm index 6683bdd..3757127 100644 --- a/auth-module/module-generator-code/src/main/resources/vms/server/controller/controller.java.vm +++ b/auth-module/module-generator-code/src/main/resources/vms/server/controller/controller.java.vm @@ -34,6 +34,7 @@ public class ${classUppercaseName}Controller { private final ${classUppercaseName}Service ${classLowercaseName}Service; + @PreAuthorize("auth.decide('${classLowercaseName}:query')") @Operation(summary = "分页查询${comment}", description = "分页查询${comment}") @GetMapping() public Result> get${classUppercaseName}Page(${classUppercaseName}Dto dto) { @@ -42,6 +43,7 @@ public class ${classUppercaseName}Controller { return Result.success(pageResult); } + @PreAuthorize("auth.decide('${classLowercaseName}:query')") @Operation(summary = "根据id查询${comment}详情", description = "根据id查询${comment}详情") @GetMapping("{id}") public Result<${classUppercaseName}Vo> getById(@PathVariable("id") Long id) { @@ -50,6 +52,7 @@ public class ${classUppercaseName}Controller { return Result.success(${classLowercaseName}Vo); } + @PreAuthorize("auth.decide('${classLowercaseName}:create')") @Operation(summary = "添加${comment}", description = "添加${comment}") @PostMapping() public Result create(@Valid @RequestBody ${classUppercaseName}Dto dto) { @@ -57,6 +60,7 @@ public class ${classUppercaseName}Controller { return Result.success(ResultCodeEnum.ADD_SUCCESS); } + @PreAuthorize("auth.decide('${classLowercaseName}:update')") @Operation(summary = "更新${comment}", description = "更新${comment}") @PutMapping() public Result update(@Valid @RequestBody ${classUppercaseName}Dto dto) { @@ -64,6 +68,7 @@ public class ${classUppercaseName}Controller { return Result.success(ResultCodeEnum.UPDATE_SUCCESS); } + @PreAuthorize("auth.decide('${classLowercaseName}:delete')") @Operation(summary = "删除${comment}", description = "删除${comment}") @DeleteMapping() public Result batchDelete(@RequestBody List ids) { diff --git a/auth-module/module-generator-code/src/main/resources/vms/web/api/api.ts.vm b/auth-module/module-generator-code/src/main/resources/vms/web/api/$webBasePath/api.ts.vm similarity index 57% rename from auth-module/module-generator-code/src/main/resources/vms/web/api/api.ts.vm rename to auth-module/module-generator-code/src/main/resources/vms/web/api/$webBasePath/api.ts.vm index 52186b1..80e10b3 100644 --- a/auth-module/module-generator-code/src/main/resources/vms/web/api/api.ts.vm +++ b/auth-module/module-generator-code/src/main/resources/vms/web/api/$webBasePath/api.ts.vm @@ -1,28 +1,28 @@ import type { ResultPage, Result } from "@/types/base"; -import type { ${classUppercaseName}ListItem } from "@/types/${classLowercaseName}/${classLowercaseName}DataType.ts"; +import type { ${classUppercaseName}ListItem } from "@/types${webBasePath}/${classLowercaseName}/${classLowercaseName}DataType.ts"; import { http } from "@/utils/http"; /** ${comment}---获取${comment}列表 */ export const query${classUppercaseName}Page = (params: any) => { - return http.request>('get', `${classLowercaseName}`, {params}); + return http.request>('get', `${requestMapping}/${classLowercaseName}`, {params}); }; /** 部门表---获取${comment}详情 */ export const get${classUppercaseName}Detail = (params: any) => { - return http.request>("get", `${classLowercaseName}/${params.id}`); + return http.request>("get", `${requestMapping}/${classLowercaseName}/${params.id}`); }; /** ${comment}---添加${comment} */ export const create${classUppercaseName} = (data: any) => { - return http.request>('post', '${classLowercaseName}', {data}); + return http.request>('post', '${requestMapping}/${classLowercaseName}', {data}); }; /** ${comment}---更新${comment} */ export const update${classUppercaseName}ById = (data: any) => { - return http.request>('put', '${classLowercaseName}', {data}); + return http.request>('put', '${requestMapping}/${classLowercaseName}', {data}); }; /** ${comment}---删除${comment} */ export const batchDelete${classUppercaseName} = (data: any) => { - return http.request>('delete', '${classLowercaseName}', {data}); + return http.request>('delete', '${requestMapping}/${classLowercaseName}', {data}); }; \ No newline at end of file diff --git a/auth-module/module-generator-code/src/main/resources/vms/web/store/modules/store.ts.vm b/auth-module/module-generator-code/src/main/resources/vms/web/store/modules/$webBasePath/store.ts.vm similarity index 96% rename from auth-module/module-generator-code/src/main/resources/vms/web/store/modules/store.ts.vm rename to auth-module/module-generator-code/src/main/resources/vms/web/store/modules/$webBasePath/store.ts.vm index c870af8..225d198 100644 --- a/auth-module/module-generator-code/src/main/resources/vms/web/store/modules/store.ts.vm +++ b/auth-module/module-generator-code/src/main/resources/vms/web/store/modules/$webBasePath/store.ts.vm @@ -1,5 +1,5 @@ import {defineStore} from 'pinia'; -import {query${classUppercaseName}Page,get${classUppercaseName}Detail, create${classUppercaseName}, update${classUppercaseName}ById,batchDelete${classUppercaseName}} from '@/api/${classLowercaseName}'; +import {query${classUppercaseName}Page,get${classUppercaseName}Detail, create${classUppercaseName}, update${classUppercaseName}ById,batchDelete${classUppercaseName}} from '@/api${webBasePath}/${classLowercaseName}'; import {storeMessage} from '@/utils/message'; import { storePagination } from "@/utils/pageResultUtil"; diff --git a/auth-module/module-generator-code/src/main/resources/vms/web/types/$className/types.ts.vm b/auth-module/module-generator-code/src/main/resources/vms/web/types/$webBasePath/$className/types.ts.vm similarity index 100% rename from auth-module/module-generator-code/src/main/resources/vms/web/types/$className/types.ts.vm rename to auth-module/module-generator-code/src/main/resources/vms/web/types/$webBasePath/$className/types.ts.vm diff --git a/auth-module/module-generator-code/src/main/resources/vms/web/views/$className/components/dialog.vue.vm b/auth-module/module-generator-code/src/main/resources/vms/web/views/$className/components/dialog.vue.vm index ab4c082..9cd62c2 100644 --- a/auth-module/module-generator-code/src/main/resources/vms/web/views/$className/components/dialog.vue.vm +++ b/auth-module/module-generator-code/src/main/resources/vms/web/views/$className/components/dialog.vue.vm @@ -1,9 +1,9 @@