From 5dfd5cc8d5db5606b87c2a127c270f810ad02277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Mon, 30 Mar 2026 21:12:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9D=83=E9=99=90=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 org_company_permission 表及 CompanyPermission 模块(PO/VO/Mapper/Service/Controller) - PermissionCheckServiceImpl 增加公司级权限校验(平台→公司→职位 三级) - PermissionAspect 增加 company 角色处理 - UserMenuServiceImpl 修正 member 角色菜单查询(取公司菜单与职位菜单交集) - 所有 Controller 方法加 @RequirePermission 注解,覆盖: * system:* 系统管理权限 * org:* 组织管理权限 * ecom:* 电商业务权限 * data:* 数据管理权限 - SQL 脚本:新增 org_company_permission 表,完整权限码体系INSERT语句 --- ...permission_code_and_company_permission.sql | 124 ++++++++++++++ .../common/aspect/PermissionAspect.java | 16 +- .../controller/BrushOrderController.java | 13 +- .../controller/ImportFieldDefController.java | 15 +- .../controller/ImportMappingController.java | 11 +- .../controller/ImportTaskController.java | 7 +- .../controller/ImportTaskSseController.java | 5 +- .../order/controller/OrderController.java | 14 +- .../controller/OrderStatusController.java | 13 +- .../controller/CompanyOverviewController.java | 5 +- .../overview/controller/ExportController.java | 10 +- .../product/controller/ProductController.java | 10 +- .../controller/ProductSpecController.java | 16 +- .../controller/PromotionFeeController.java | 12 +- .../PromotionFeeTypeController.java | 8 + .../ecom/shop/controller/ShopController.java | 18 +- .../ShopMonthlyTargetController.java | 13 +- .../account/controller/AccountController.java | 9 +- .../controller/SuperAccountController.java | 12 +- .../company/controller/CompanyController.java | 14 +- .../controller/CompanyMemberController.java | 14 +- .../controller/CompanyMenuController.java | 10 +- .../CompanyPermissionController.java | 66 ++++++++ .../mapper/CompanyPermissionMapper.java | 31 ++++ .../dto/BatchAssignCompanyPermissionDTO.java | 25 +++ .../model/po/CompanyPermissionPO.java | 47 ++++++ .../model/vo/CompanyPermissionVO.java | 19 +++ .../service/CompanyPermissionService.java | 55 ++++++ .../impl/CompanyPermissionServiceImpl.java | 156 ++++++++++++++++++ .../controller/DepartmentController.java | 14 +- .../DepartmentMemberController.java | 10 +- .../controller/PositionController.java | 10 +- .../PositionPermissionController.java | 12 +- ...ositionPermissionManagementController.java | 10 ++ .../sub/plan/controller/PlanController.java | 5 + .../controller/PlanPricingController.java | 5 + .../controller/SubscriptionController.java | 5 + .../sys/menu/controller/MenuController.java | 8 + .../service/impl/UserMenuServiceImpl.java | 15 +- .../controller/MenuPermissionController.java | 3 + .../controller/PermissionController.java | 7 + .../impl/PermissionCheckServiceImpl.java | 40 +++-- .../sys/user/controller/UserController.java | 4 + .../CompanyPermissionMapper.xml | 29 ++++ 44 files changed, 797 insertions(+), 148 deletions(-) create mode 100644 ecom-dmb-backend/sql/V20260330__permission_code_and_company_permission.sql create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/controller/CompanyPermissionController.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/mapper/CompanyPermissionMapper.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/dto/BatchAssignCompanyPermissionDTO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/po/CompanyPermissionPO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/vo/CompanyPermissionVO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/CompanyPermissionService.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/impl/CompanyPermissionServiceImpl.java create mode 100644 ecom-dmb-backend/src/main/resources/mapper/companypermission/CompanyPermissionMapper.xml diff --git a/ecom-dmb-backend/sql/V20260330__permission_code_and_company_permission.sql b/ecom-dmb-backend/sql/V20260330__permission_code_and_company_permission.sql new file mode 100644 index 00000000..6e5cfff5 --- /dev/null +++ b/ecom-dmb-backend/sql/V20260330__permission_code_and_company_permission.sql @@ -0,0 +1,124 @@ +-- ======================================== +-- 权限系统完整改造 SQL +-- 执行时间:2026-03-30 +-- 变更内容: +-- 1. 新增 org_company_permission 表(平台分配给公司的权限) +-- 2. 重新设计 sys_permission 完整权限码体系 +-- 3. 建立 sys_menu_permission 参考关系 +-- ======================================== + +-- ------------------------------------------------ +-- 1. 新增 org_company_permission 表(平台分配权限给公司) +-- ------------------------------------------------ +CREATE TABLE IF NOT EXISTS `org_company_permission` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `company_id` bigint unsigned NOT NULL COMMENT '公司ID', + `permission_id` bigint unsigned NOT NULL COMMENT '权限ID', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_org_company_permission_company_permission` (`company_id`, `permission_id`), + KEY `fk_org_company_permission_company` (`company_id`), + KEY `fk_org_company_permission_permission` (`permission_id`), + CONSTRAINT `fk_org_company_permission_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_org_company_permission_permission` FOREIGN KEY (`permission_id`) REFERENCES `sys_permission` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='公司权限配置表(平台分配给公司的权限)'; + +-- ------------------------------------------------ +-- 2. 重新设计 sys_permission 完整权限码体系 +-- 先删除旧的 menu:update/create/delete 权限数据,重新插入完整体系 +-- ------------------------------------------------ + +-- 删除旧的权限数据(保留 id=1,2,3 的记录是之前的 menu 权限,如果需要可清理) +-- 注意:执行前请确认 sys_menu_permission 和 org_position_permission 表中没有引用这些权限 +-- DELETE FROM sys_permission WHERE code IN ('menu:update', 'menu:create', 'menu:delete', 'menu:read'); + +-- 重新插入完整权限码体系(先确保 id 从 10 开始以避免冲突) +INSERT INTO `sys_permission` (`code`, `name`, `type`, `status`, `remark`) VALUES +-- 系统管理 (system:*) +('system:user:read', '用户查看', 'api', 1, '系统管理-用户查看'), +('system:user:create', '用户创建', 'api', 1, '系统管理-用户创建'), +('system:user:update', '用户更新', 'api', 1, '系统管理-用户更新'), +('system:user:delete', '用户删除', 'api', 1, '系统管理-用户删除'), +('system:menu:read', '菜单查看', 'api', 1, '系统管理-菜单查看'), +('system:menu:create', '菜单创建', 'api', 1, '系统管理-菜单创建'), +('system:menu:update', '菜单更新', 'api', 1, '系统管理-菜单更新'), +('system:menu:delete', '菜单删除', 'api', 1, '系统管理-菜单删除'), +('system:permission:read', '权限查看', 'api', 1, '系统管理-权限查看'), +('system:position:manage', '职位管理', 'api', 1, '系统管理-职位管理'), +('system:company:manage', '公司管理', 'api', 1, '系统管理-公司管理'), + +-- 组织管理 (org:*) +('org:company:read', '公司查看', 'api', 1, '组织管理-公司查看'), +('org:company:create', '公司创建', 'api', 1, '组织管理-公司创建'), +('org:company:update', '公司更新', 'api', 1, '组织管理-公司更新'), +('org:company:delete', '公司删除', 'api', 1, '组织管理-公司删除'), +('org:department:read', '部门查看', 'api', 1, '组织管理-部门查看'), +('org:department:manage', '部门管理', 'api', 1, '组织管理-部门管理'), +('org:position:read', '职位查看', 'api', 1, '组织管理-职位查看'), +('org:position:manage', '职位管理', 'api', 1, '组织管理-职位管理'), +('org:member:read', '成员查看', 'api', 1, '组织管理-成员查看'), +('org:member:manage', '成员管理', 'api', 1, '组织管理-成员管理'), +('org:company-menu:assign', '公司菜单分配', 'api', 1, '组织管理-公司菜单分配'), +('org:company-permission:assign', '公司权限分配', 'api', 1, '组织管理-公司权限分配'), +('org:position-menu:assign', '职位菜单分配', 'api', 1, '组织管理-职位菜单分配'), +('org:position-permission:assign', '职位权限分配', 'api', 1, '组织管理-职位权限分配'), + +-- 电商业务 (ecom:*) +('ecom:order:read', '订单查看', 'api', 1, '电商业务-订单查看'), +('ecom:order:create', '订单创建', 'api', 1, '电商业务-订单创建'), +('ecom:order:update', '订单更新', 'api', 1, '电商业务-订单更新'), +('ecom:order:delete', '订单删除', 'api', 1, '电商业务-订单删除'), +('ecom:order:import', '订单导入', 'api', 1, '电商业务-订单导入'), +('ecom:order:export', '订单导出', 'api', 1, '电商业务-订单导出'), +('ecom:product:read', '商品查看', 'api', 1, '电商业务-商品查看'), +('ecom:product:create', '商品创建', 'api', 1, '电商业务-商品创建'), +('ecom:product:update', '商品更新', 'api', 1, '电商业务-商品更新'), +('ecom:product:delete', '商品删除', 'api', 1, '电商业务-商品删除'), +('ecom:shop:read', '店铺查看', 'api', 1, '电商业务-店铺查看'), +('ecom:shop:manage', '店铺管理', 'api', 1, '电商业务-店铺管理'), + +-- 数据管理 (data:*) +('data:import', '数据导入', 'api', 1, '数据管理-数据导入'), +('data:export', '数据导出', 'api', 1, '数据管理-数据导出'); + +-- ------------------------------------------------ +-- 3. 建立 sys_menu_permission 参考关系 +-- 将主要菜单与对应权限关联(仅供参考信息,非分配关系) +-- 注意:需先确认 sys_menu 中的菜单 ID,以下为示例映射 +-- 请根据实际菜单数据调整 menu_id +-- ------------------------------------------------ + +-- 菜单-权限关联(参考关系) +-- 格式:INSERT INTO sys_menu_permission (menu_id, permission_id) VALUES (菜单ID, 权限ID); + +-- 示例:用户管理菜单 -> system:user:* +-- INSERT INTO sys_menu_permission (menu_id, permission_id) +-- SELECT m.id, p.id FROM sys_menu m, sys_permission p +-- WHERE m.name = '用户管理' AND p.code LIKE 'system:user:%'; + +-- 示例:订单管理菜单 -> ecom:order:* +-- INSERT INTO sys_menu_permission (menu_id, permission_id) +-- SELECT m.id, p.id FROM sys_menu m, sys_permission p +-- WHERE m.name = '订单管理' AND p.code LIKE 'ecom:order:%'; + +-- 通用:根据菜单名称模糊匹配建立关联 +-- 请根据 sys_menu 表实际数据调整以下语句 +/* +INSERT INTO sys_menu_permission (menu_id, permission_id) +SELECT m.id, p.id FROM sys_menu m +JOIN sys_permission p ON + (m.name LIKE '%用户%' AND p.code LIKE 'system:user:%') OR + (m.name LIKE '%菜单%' AND p.code LIKE 'system:menu:%') OR + (m.name LIKE '%权限%' AND p.code LIKE 'system:permission:%') OR + (m.name LIKE '%公司%' AND p.code LIKE 'org:company:%') OR + (m.name LIKE '%部门%' AND p.code LIKE 'org:department:%') OR + (m.name LIKE '%职位%' AND p.code LIKE 'org:position:%') OR + (m.name LIKE '%成员%' AND p.code LIKE 'org:member:%') OR + (m.name LIKE '%订单%' AND p.code LIKE 'ecom:order:%') OR + (m.name LIKE '%商品%' AND p.code LIKE 'ecom:product:%') OR + (m.name LIKE '%店铺%' AND p.code LIKE 'ecom:shop:%') OR + (m.name LIKE '%导入%' AND p.code LIKE 'data:import%') OR + (m.name LIKE '%导出%' AND p.code LIKE 'data:export%') +ON DUPLICATE KEY UPDATE menu_id = menu_id; +*/ diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java index e21a3555..ea08e885 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java @@ -19,7 +19,8 @@ import java.lang.reflect.Method; * * 权限判定逻辑: * - super 角色:直接放行(拥有所有权限) - * - user 角色:从 org_position_permission 表查询岗位拥有的权限码进行判定 + * - company 角色:检查公司是否有该权限(同 user 逻辑,但只做公司级校验) + * - user 角色:从 org_position_permission 表查询岗位拥有的权限码进行判定,同时需要公司有该权限 */ @Aspect @Component @@ -65,8 +66,21 @@ public class PermissionAspect { // 超级管理员拥有所有权限 hasPermission = annotation.allowSuper(); break; + case "company": + // 公司管理员角色,检查公司是否有该权限 + // company 角色实际上是 member 中的 owner,有公司级权限 + // 走 user 逻辑,使用 positionId + if (positionId != null) { + hasPermission = permissionCheckService.hasPermissionByPosition( + positionId, annotation.value(), companyId); + } else { + // 如果没有职位,至少检查公司是否有权限 + hasPermission = false; + } + break; case "user": // 普通用户从 org_position_permission 表查询权限码进行判定 + // 同时需要公司有该权限(两级校验) hasPermission = permissionCheckService.hasPermissionByPosition( positionId, annotation.value(), companyId); break; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/brushorder/controller/BrushOrderController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/brushorder/controller/BrushOrderController.java index 17404ad7..9dd52eb9 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/brushorder/controller/BrushOrderController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/brushorder/controller/BrushOrderController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,7 +31,7 @@ public class BrushOrderController { @Operation(summary = "创建刷单记录", description = "创建新的刷单记录") @PostMapping("/create") - @RequireRole(description = "创建刷单记录", allowUser = false) + @RequirePermission(value = "ecom:order:create", description = "创建刷单记录", allowSuper = true) public ApiResponse createBrushOrder(@Valid @RequestBody CreateBrushOrderDTO createBrushOrderDTO) { BrushOrderVO brushOrderVO = brushOrderService.createBrushOrder(createBrushOrderDTO); return ApiResponse.success(brushOrderVO); @@ -39,7 +39,7 @@ public class BrushOrderController { @Operation(summary = "更新刷单记录", description = "更新现有刷单记录信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新刷单记录", allowUser = false) + @RequirePermission(value = "ecom:order:update", description = "更新刷单记录", allowSuper = true) public ApiResponse updateBrushOrder(@Valid @RequestBody UpdateBrushOrderDTO updateBrushOrderDTO, @Parameter(description = "刷单记录ID") @PathVariable Long id) { BrushOrderVO brushOrderVO = brushOrderService.updateBrushOrder(updateBrushOrderDTO, id); @@ -48,7 +48,7 @@ public class BrushOrderController { @Operation(summary = "删除刷单记录", description = "删除指定刷单记录") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除刷单记录", allowUser = false) + @RequirePermission(value = "ecom:order:delete", description = "删除刷单记录", allowSuper = true) public ApiResponse deleteBrushOrder( @Parameter(description = "刷单记录ID") @PathVariable Long id) { brushOrderService.deleteBrushOrder(id); @@ -57,7 +57,7 @@ public class BrushOrderController { @Operation(summary = "分页获取刷单记录列表", description = "分页获取刷单记录列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询刷单记录列表", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询刷单记录列表", allowSuper = true) public ApiResponse> getBrushOrderPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = brushOrderService.getBrushOrderPage(pageQueryDTO); @@ -66,11 +66,10 @@ public class BrushOrderController { @Operation(summary = "获取刷单记录详情", description = "根据ID获取刷单记录详情") @GetMapping("/detail/{id}") - @RequireRole(description = "查询刷单记录详情", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询刷单记录详情", allowSuper = true) public ApiResponse getBrushOrderById( @Parameter(description = "刷单记录ID") @PathVariable Long id) { BrushOrderVO brushOrderVO = brushOrderService.getBrushOrderById(id); return ApiResponse.success(brushOrderVO); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importfielddef/controller/ImportFieldDefController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importfielddef/controller/ImportFieldDefController.java index c4e1b388..9cb84bf6 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importfielddef/controller/ImportFieldDefController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importfielddef/controller/ImportFieldDefController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -34,7 +34,7 @@ public class ImportFieldDefController { @Operation(summary = "创建导入字段定义", description = "创建新的导入字段定义") @PostMapping("/create") - @RequireRole(description = "创建导入字段定义", allowUser = false) + @RequirePermission(value = "data:import", description = "创建导入字段定义", allowSuper = true) public ApiResponse createImportFieldDef(@Valid @RequestBody CreateImportFieldDefDTO createImportFieldDefDTO) { ImportFieldDefVO importFieldDefVO = importFieldDefService.createImportFieldDef(createImportFieldDefDTO); return ApiResponse.success(importFieldDefVO); @@ -42,7 +42,7 @@ public class ImportFieldDefController { @Operation(summary = "更新导入字段定义", description = "更新现有导入字段定义") @PutMapping("/update/{id}") - @RequireRole(description = "更新导入字段定义", allowUser = false) + @RequirePermission(value = "data:import", description = "更新导入字段定义", allowSuper = true) public ApiResponse updateImportFieldDef( @Valid @RequestBody UpdateImportFieldDefDTO updateImportFieldDefDTO, @Parameter(description = "字段定义ID") @PathVariable Long id) { @@ -52,7 +52,7 @@ public class ImportFieldDefController { @Operation(summary = "删除导入字段定义", description = "删除指定导入字段定义") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除导入字段定义", allowUser = false) + @RequirePermission(value = "data:import", description = "删除导入字段定义", allowSuper = true) public ApiResponse deleteImportFieldDef( @Parameter(description = "字段定义ID") @PathVariable Long id) { importFieldDefService.deleteImportFieldDef(id); @@ -61,7 +61,7 @@ public class ImportFieldDefController { @Operation(summary = "获取指定类型所有字段列表", description = "根据导入类型获取所有字段定义列表") @GetMapping("/all/{type}") - @RequireRole(description = "获取字段定义列表", allowUser = true) + @RequirePermission(value = "data:import", description = "获取字段定义列表", allowSuper = true) public ApiResponse> getFieldDefsByType( @Parameter(description = "导入类型", example = "product") @PathVariable String type) { List fieldDefVOs = importFieldDefService.getFieldDefsByType(type); @@ -70,7 +70,7 @@ public class ImportFieldDefController { @Operation(summary = "分页查询导入字段定义", description = "分页查询导入字段定义,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询导入字段定义列表", allowUser = true) + @RequirePermission(value = "data:import", description = "查询导入字段定义列表", allowSuper = true) public ApiResponse> getImportFieldDefPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = importFieldDefService.getImportFieldDefPage(pageQueryDTO); @@ -79,10 +79,9 @@ public class ImportFieldDefController { @Operation(summary = "批量排序导入字段定义", description = "批量更新导入字段定义的排序值") @PostMapping("/batch-sort") - @RequireRole(description = "批量排序导入字段定义", allowUser = false) + @RequirePermission(value = "data:import", description = "批量排序导入字段定义", allowSuper = true) public ApiResponse batchSortImportFieldDef(@Valid @RequestBody BatchSortImportFieldDefDTO batchSortDTO) { importFieldDefService.batchSortImportFieldDef(batchSortDTO); return ApiResponse.success(); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importmapping/controller/ImportMappingController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importmapping/controller/ImportMappingController.java index 2440cdbc..95eec0a2 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importmapping/controller/ImportMappingController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importmapping/controller/ImportMappingController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,7 +31,7 @@ public class ImportMappingController { @Operation(summary = "创建导入映射模板", description = "创建新的导入映射模板") @PostMapping("/create") - @RequireRole(description = "创建导入映射模板", allowUser = false) + @RequirePermission(value = "data:import", description = "创建导入映射模板", allowSuper = true) public ApiResponse createImportMapping(@Valid @RequestBody CreateImportMappingDTO createImportMappingDTO) { ImportMappingVO importMappingVO = importMappingService.createImportMapping(createImportMappingDTO); return ApiResponse.success(importMappingVO); @@ -39,7 +39,7 @@ public class ImportMappingController { @Operation(summary = "更新导入映射模板", description = "更新现有导入映射模板") @PutMapping("/update/{id}") - @RequireRole(description = "更新导入映射模板", allowUser = false) + @RequirePermission(value = "data:import", description = "更新导入映射模板", allowSuper = true) public ApiResponse updateImportMapping( @Valid @RequestBody UpdateImportMappingDTO updateImportMappingDTO, @Parameter(description = "模板ID") @PathVariable Long id) { @@ -49,7 +49,7 @@ public class ImportMappingController { @Operation(summary = "删除导入映射模板", description = "删除指定导入映射模板") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除导入映射模板", allowUser = false) + @RequirePermission(value = "data:import", description = "删除导入映射模板", allowSuper = true) public ApiResponse deleteImportMapping( @Parameter(description = "模板ID") @PathVariable Long id) { importMappingService.deleteImportMapping(id); @@ -58,11 +58,10 @@ public class ImportMappingController { @Operation(summary = "分页获取导入映射模板列表", description = "分页获取导入映射模板列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询导入映射模板列表", allowUser = true) + @RequirePermission(value = "data:import", description = "查询导入映射模板列表", allowSuper = true) public ApiResponse> getImportMappingPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = importMappingService.getImportMappingPage(pageQueryDTO); return ApiResponse.success(result); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskController.java index 4457478c..d9178cc6 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskController.java @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -29,7 +29,7 @@ public class ImportTaskController { @Operation(summary = "创建导入任务", description = "创建新的导入任务") @PostMapping("/create") - @RequireRole(description = "创建导入任务", allowUser = false) + @RequirePermission(value = "data:import", description = "创建导入任务", allowSuper = true) public ApiResponse createImportTask(@Valid @RequestBody CreateImportTaskDTO createImportTaskDTO) { ImportTaskVO importTaskVO = importTaskService.createImportTask(createImportTaskDTO); return ApiResponse.success(importTaskVO); @@ -37,11 +37,10 @@ public class ImportTaskController { @Operation(summary = "分页获取导入任务列表", description = "分页获取导入任务列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询导入任务列表", allowUser = true) + @RequirePermission(value = "data:import", description = "查询导入任务列表", allowSuper = true) public ApiResponse> getImportTaskPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = importTaskService.getImportTaskPage(pageQueryDTO); return ApiResponse.success(result); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskSseController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskSseController.java index e6aa77b6..9e28726c 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskSseController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/importtask/controller/ImportTaskSseController.java @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.SseNotificationService; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; @@ -30,10 +30,9 @@ public class ImportTaskSseController { @Operation(summary = "建立SSE连接", description = "前端在创建任务前建立SSE连接,用于接收任务进度推送") @GetMapping(value = "/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE) - @RequireRole(description = "建立SSE连接", allowUser = true) + @RequirePermission(value = "data:import", description = "建立SSE连接", allowSuper = true) public SseEmitter connect() { Long userId = currentUserContext.getCurrentUserId(); return sseNotificationService.createConnection(userId); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/controller/OrderController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/controller/OrderController.java index aefeebbc..9aa30971 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/controller/OrderController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/controller/OrderController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -33,7 +33,7 @@ public class OrderController { @Operation(summary = "创建订单", description = "创建新的订单") @PostMapping("/create") - @RequireRole(description = "创建订单", allowUser = false) + @RequirePermission(value = "ecom:order:create", description = "创建订单", allowSuper = true) public ApiResponse createOrder(@Valid @RequestBody CreateOrderDTO createOrderDTO) { OrderVO orderVO = orderService.createOrder(createOrderDTO); return ApiResponse.success(orderVO); @@ -41,7 +41,7 @@ public class OrderController { @Operation(summary = "更新订单", description = "更新现有订单信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新订单", allowUser = false) + @RequirePermission(value = "ecom:order:update", description = "更新订单", allowSuper = true) public ApiResponse updateOrder(@Valid @RequestBody UpdateOrderDTO updateOrderDTO, @Parameter(description = "订单ID") @PathVariable Long id) { OrderVO orderVO = orderService.updateOrder(updateOrderDTO, id); @@ -50,7 +50,7 @@ public class OrderController { @Operation(summary = "删除订单", description = "删除指定订单") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除订单", allowUser = false) + @RequirePermission(value = "ecom:order:delete", description = "删除订单", allowSuper = true) public ApiResponse deleteOrder( @Parameter(description = "订单ID") @PathVariable Long id) { orderService.deleteOrder(id); @@ -59,7 +59,7 @@ public class OrderController { @Operation(summary = "分页获取订单列表", description = "分页获取订单列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询订单列表", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询订单列表", allowSuper = true) public ApiResponse> getOrderPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = orderService.getOrderPage(pageQueryDTO); @@ -68,7 +68,7 @@ public class OrderController { @Operation(summary = "获取订单详情", description = "根据ID获取订单详情") @GetMapping("/detail/{id}") - @RequireRole(description = "查询订单详情", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询订单详情", allowSuper = true) public ApiResponse getOrderById( @Parameter(description = "订单ID") @PathVariable Long id) { OrderVO orderVO = orderService.getOrderById(id); @@ -77,7 +77,7 @@ public class OrderController { @Operation(summary = "批量导入订单", description = "批量导入订单数据,支持部分成功部分失败") @PostMapping("/batch-import") - @RequireRole(description = "批量导入订单", allowUser = false) + @RequirePermission(value = "ecom:order:import", description = "批量导入订单", allowSuper = true) public ApiResponse batchImportOrders(@Valid @RequestBody BatchImportOrderDTO batchImportOrderDTO) { BatchImportResultVO result = orderService.batchImportOrders(batchImportOrderDTO); return ApiResponse.success(result); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/orderstatus/controller/OrderStatusController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/orderstatus/controller/OrderStatusController.java index 56a6eddf..2fe581ef 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/orderstatus/controller/OrderStatusController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/orderstatus/controller/OrderStatusController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.ecom.orderstatus.model.dto.CreateOrderStatusDTO; import top.xyquan.ecomdmbbackend.modules.ecom.orderstatus.model.dto.UpdateOrderStatusDTO; @@ -30,7 +30,7 @@ public class OrderStatusController { @Operation(summary = "创建订单状态", description = "创建新的订单状态") @PostMapping("/create") - @RequireRole(description = "创建订单状态", allowUser = false) + @RequirePermission(value = "ecom:order:manage", description = "创建订单状态", allowSuper = true) public ApiResponse createOrderStatus(@Valid @RequestBody CreateOrderStatusDTO createOrderStatusDTO) { OrderStatusVO orderStatusVO = orderStatusService.createOrderStatus(createOrderStatusDTO); return ApiResponse.success(orderStatusVO); @@ -38,7 +38,7 @@ public class OrderStatusController { @Operation(summary = "更新订单状态", description = "更新现有订单状态信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新订单状态", allowUser = false) + @RequirePermission(value = "ecom:order:manage", description = "更新订单状态", allowSuper = true) public ApiResponse updateOrderStatus(@Valid @RequestBody UpdateOrderStatusDTO updateOrderStatusDTO, @Parameter(description = "订单状态ID") @PathVariable Long id) { OrderStatusVO orderStatusVO = orderStatusService.updateOrderStatus(updateOrderStatusDTO, id); @@ -47,7 +47,7 @@ public class OrderStatusController { @Operation(summary = "删除订单状态", description = "删除指定订单状态") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除订单状态", allowUser = false) + @RequirePermission(value = "ecom:order:manage", description = "删除订单状态", allowSuper = true) public ApiResponse deleteOrderStatus( @Parameter(description = "订单状态ID") @PathVariable Long id) { orderStatusService.deleteOrderStatus(id); @@ -56,7 +56,7 @@ public class OrderStatusController { @Operation(summary = "获取所有订单状态", description = "获取当前公司的所有订单状态列表") @GetMapping("/list") - @RequireRole(description = "查询订单状态列表", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询订单状态列表", allowSuper = true) public ApiResponse> getAllOrderStatuses() { List result = orderStatusService.getAllOrderStatuses(); return ApiResponse.success(result); @@ -64,11 +64,10 @@ public class OrderStatusController { @Operation(summary = "获取订单状态详情", description = "根据ID获取订单状态详情") @GetMapping("/detail/{id}") - @RequireRole(description = "查询订单状态详情", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询订单状态详情", allowSuper = true) public ApiResponse getOrderStatusById( @Parameter(description = "订单状态ID") @PathVariable Long id) { OrderStatusVO orderStatusVO = orderStatusService.getOrderStatusById(id); return ApiResponse.success(orderStatusVO); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/CompanyOverviewController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/CompanyOverviewController.java index 231247e0..e84d10b0 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/CompanyOverviewController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/CompanyOverviewController.java @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyOverviewQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO; @@ -26,10 +26,9 @@ public class CompanyOverviewController { @Operation(summary = "获取全店铺概览统计数据", description = "获取当前公司所有店铺的概览统计数据,包括销售额、单量、推广费、利润、ROI等") @PostMapping("/statistics") - @RequireRole(description = "查询全店铺概览", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询全店铺概览", allowSuper = true) public ApiResponse getCompanyOverview(@Valid @RequestBody CompanyOverviewQueryDTO queryDTO) { CompanyOverviewVO overviewVO = companyOverviewService.getCompanyOverview(queryDTO); return ApiResponse.success(overviewVO); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/ExportController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/ExportController.java index cb5a1902..fe1e63a1 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/ExportController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/controller/ExportController.java @@ -2,18 +2,16 @@ package top.xyquan.ecomdmbbackend.modules.ecom.overview.controller; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyExportDTO; import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopExportDTO; import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.ExportService; -import java.time.LocalDate; +import jakarta.servlet.http.HttpServletResponse; import java.time.format.DateTimeFormatter; /** @@ -34,7 +32,7 @@ public class ExportController { @Operation(summary = "导出公司概览Excel", description = "导出全店铺概览数据为Excel文件") @PostMapping("/company-overview/export") - @RequireRole(description = "导出公司概览", allowUser = true) + @RequirePermission(value = "data:export", description = "导出公司概览", allowSuper = true) public void exportCompanyOverview(@Valid @RequestBody CompanyExportDTO dto, HttpServletResponse response) { byte[] data = exportService.exportCompanyOverview(dto); String dateRange = dto.getDateRange().get(0).format(FILE_NAME_FMT) + "-" + @@ -45,7 +43,7 @@ public class ExportController { @Operation(summary = "导出店铺概览Excel", description = "导出单店铺概览数据为Excel文件") @PostMapping("/shop/export-overview") - @RequireRole(description = "导出店铺概览", allowUser = true) + @RequirePermission(value = "data:export", description = "导出店铺概览", allowSuper = true) public void exportShopOverview(@Valid @RequestBody ShopExportDTO dto, HttpServletResponse response) { byte[] data = exportService.exportShopOverview(dto); String dateRange = dto.getDateRange().get(0).format(FILE_NAME_FMT) + "-" + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java index f9e6f541..db1b0b42 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,7 +31,7 @@ public class ProductController { @Operation(summary = "创建商品", description = "创建新的商品") @PostMapping("/create") - @RequireRole(description = "创建商品", allowUser = false) + @RequirePermission(value = "ecom:product:create", description = "创建商品", allowSuper = true) public ApiResponse createProduct(@Valid @RequestBody CreateProductDTO createProductDTO) { ProductVO productVO = productService.createProduct(createProductDTO); return ApiResponse.success(productVO); @@ -39,7 +39,7 @@ public class ProductController { @Operation(summary = "更新商品", description = "更新现有商品信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新商品", allowUser = false) + @RequirePermission(value = "ecom:product:update", description = "更新商品", allowSuper = true) public ApiResponse updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO, @Parameter(description = "商品ID") @PathVariable Long id) { ProductVO productVO = productService.updateProduct(updateProductDTO, id); @@ -48,7 +48,7 @@ public class ProductController { @Operation(summary = "删除商品", description = "删除指定商品") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除商品", allowUser = false) + @RequirePermission(value = "ecom:product:delete", description = "删除商品", allowSuper = true) public ApiResponse deleteProduct( @Parameter(description = "商品ID") @PathVariable Long id) { productService.deleteProduct(id); @@ -57,7 +57,7 @@ public class ProductController { @Operation(summary = "分页获取商品列表", description = "分页获取商品列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询商品列表", allowUser = true) + @RequirePermission(value = "ecom:product:read", description = "查询商品列表", allowSuper = true) public ApiResponse> getProductPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = productService.getProductPage(pageQueryDTO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java index ec37fd4f..082358db 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java @@ -7,7 +7,7 @@ import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import java.util.List; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -35,7 +35,7 @@ public class ProductSpecController { @Operation(summary = "创建商品规格", description = "创建新的商品规格") @PostMapping("/create") - @RequireRole(description = "创建商品规格", allowUser = false) + @RequirePermission(value = "ecom:product:create", description = "创建商品规格", allowSuper = true) public ApiResponse createProductSpec(@Valid @RequestBody CreateProductSpecDTO createProductSpecDTO) { ProductSpecVO productSpecVO = productSpecService.createProductSpec(createProductSpecDTO); return ApiResponse.success(productSpecVO); @@ -43,7 +43,7 @@ public class ProductSpecController { @Operation(summary = "更新商品规格", description = "更新现有商品规格信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新商品规格", allowUser = false) + @RequirePermission(value = "ecom:product:update", description = "更新商品规格", allowSuper = true) public ApiResponse updateProductSpec(@Valid @RequestBody UpdateProductSpecDTO updateProductSpecDTO, @Parameter(description = "商品规格ID") @PathVariable Long id) { ProductSpecVO productSpecVO = productSpecService.updateProductSpec(updateProductSpecDTO, id); @@ -52,7 +52,7 @@ public class ProductSpecController { @Operation(summary = "删除商品规格", description = "删除指定商品规格") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除商品规格", allowUser = false) + @RequirePermission(value = "ecom:product:delete", description = "删除商品规格", allowSuper = true) public ApiResponse deleteProductSpec( @Parameter(description = "商品规格ID") @PathVariable Long id) { productSpecService.deleteProductSpec(id); @@ -61,7 +61,7 @@ public class ProductSpecController { @Operation(summary = "分页获取商品规格列表", description = "分页获取商品规格列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询商品规格列表", allowUser = true) + @RequirePermission(value = "ecom:product:read", description = "查询商品规格列表", allowSuper = true) public ApiResponse> getProductSpecPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = productSpecService.getProductSpecPage(pageQueryDTO); @@ -70,7 +70,7 @@ public class ProductSpecController { @Operation(summary = "根据商品名称和规格编码精准查询商品规格", description = "根据商品名称和规格编码精准查询商品规格信息,用于数据导入") @GetMapping("/find-by-product-and-spec/{productName}/{specCode}") - @RequireRole(description = "根据商品名称和规格编码查询商品规格", allowUser = true) + @RequirePermission(value = "ecom:product:read", description = "根据商品名称和规格编码查询商品规格", allowSuper = true) public ApiResponse getProductSpecByProductAndSpec( @Parameter(description = "商品名称") @PathVariable String productName, @Parameter(description = "规格编码") @PathVariable String specCode) { @@ -80,10 +80,10 @@ public class ProductSpecController { @Operation(summary = "批量根据商品名称和规格编码查询商品规格", description = "批量根据商品名称和规格编码精准查询商品规格信息,用于数据导入") @PostMapping("/find-by-product-and-specs") - @RequireRole(description = "批量根据商品名称和规格编码查询商品规格", allowUser = true) + @RequirePermission(value = "ecom:product:read", description = "批量根据商品名称和规格编码查询商品规格", allowSuper = true) public ApiResponse> getProductSpecsByProductAndSpecs(@RequestBody List queries) { List productVOs = productSpecService.getProductSpecsByProductAndSpecs(queries); return ApiResponse.success(productVOs); } -} \ No newline at end of file +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeController.java index 97b37e53..deec0262 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeController.java @@ -6,7 +6,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -29,7 +29,7 @@ public class PromotionFeeController { @PostMapping @Operation(summary = "创建推广费记录", description = "创建新的推广费记录") - @RequireRole(description = "创建推广费记录", allowUser = false) + @RequirePermission(value = "ecom:order:create", description = "创建推广费记录", allowSuper = true) public ApiResponse createPromotionFee(@Valid @RequestBody CreatePromotionFeeDTO dto) { Long id = promotionFeeService.createPromotionFee(dto); return ApiResponse.success(id); @@ -37,7 +37,7 @@ public class PromotionFeeController { @PutMapping @Operation(summary = "更新推广费记录", description = "更新推广费记录信息") - @RequireRole(description = "更新推广费记录", allowUser = false) + @RequirePermission(value = "ecom:order:update", description = "更新推广费记录", allowSuper = true) public ApiResponse updatePromotionFee(@Valid @RequestBody UpdatePromotionFeeDTO dto) { promotionFeeService.updatePromotionFee(dto); return ApiResponse.success(); @@ -45,7 +45,7 @@ public class PromotionFeeController { @DeleteMapping("/{id}") @Operation(summary = "删除推广费记录", description = "删除指定的推广费记录") - @RequireRole(description = "删除推广费记录", allowUser = false) + @RequirePermission(value = "ecom:order:delete", description = "删除推广费记录", allowSuper = true) public ApiResponse deletePromotionFee( @Parameter(description = "记录ID", required = true) @PathVariable Long id) { promotionFeeService.deletePromotionFee(id); @@ -54,7 +54,7 @@ public class PromotionFeeController { @GetMapping("/{id}") @Operation(summary = "查询推广费记录详情", description = "根据ID查询推广费记录详情") - @RequireRole(description = "查询推广费记录详情", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询推广费记录详情", allowSuper = true) public ApiResponse getPromotionFeeById( @Parameter(description = "记录ID", required = true) @PathVariable Long id) { PromotionFeeVO vo = promotionFeeService.getPromotionFeeById(id); @@ -63,7 +63,7 @@ public class PromotionFeeController { @PostMapping("/page") @Operation(summary = "分页查询推广费记录", description = "分页查询推广费记录列表") - @RequireRole(description = "查询推广费记录列表", allowUser = true) + @RequirePermission(value = "ecom:order:read", description = "查询推广费记录列表", allowSuper = true) public ApiResponse> getPromotionFeePage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = promotionFeeService.getPromotionFeePage(pageQueryDTO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeTypeController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeTypeController.java index fb1a39e0..1abfc23e 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeTypeController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/promotion/controller/PromotionFeeTypeController.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.dto.CreatePromotionFeeTypeDTO; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.dto.UpdatePromotionFeeTypeDTO; @@ -27,6 +28,7 @@ public class PromotionFeeTypeController { @PostMapping @Operation(summary = "创建推广费类型", description = "创建新的推广费类型") + @RequirePermission(value = "ecom:order:create", description = "创建推广费类型", allowSuper = true) public ApiResponse createPromotionFeeType(@Valid @RequestBody CreatePromotionFeeTypeDTO dto) { Long id = promotionFeeTypeService.createPromotionFeeType(dto); return ApiResponse.success(id); @@ -34,6 +36,7 @@ public class PromotionFeeTypeController { @PutMapping @Operation(summary = "更新推广费类型", description = "更新推广费类型信息") + @RequirePermission(value = "ecom:order:update", description = "更新推广费类型", allowSuper = true) public ApiResponse updatePromotionFeeType(@Valid @RequestBody UpdatePromotionFeeTypeDTO dto) { promotionFeeTypeService.updatePromotionFeeType(dto); return ApiResponse.success(); @@ -41,6 +44,7 @@ public class PromotionFeeTypeController { @DeleteMapping("/{id}") @Operation(summary = "删除推广费类型", description = "删除指定的推广费类型") + @RequirePermission(value = "ecom:order:delete", description = "删除推广费类型", allowSuper = true) public ApiResponse deletePromotionFeeType( @Parameter(description = "类型ID", required = true) @PathVariable Long id) { promotionFeeTypeService.deletePromotionFeeType(id); @@ -49,6 +53,7 @@ public class PromotionFeeTypeController { @GetMapping("/{id}") @Operation(summary = "查询推广费类型详情", description = "根据ID查询推广费类型详情") + @RequirePermission(value = "ecom:order:read", description = "查询推广费类型详情", allowSuper = true) public ApiResponse getPromotionFeeTypeById( @Parameter(description = "类型ID", required = true) @PathVariable Long id) { PromotionFeeTypeVO vo = promotionFeeTypeService.getPromotionFeeTypeById(id); @@ -57,6 +62,7 @@ public class PromotionFeeTypeController { @GetMapping("/active") @Operation(summary = "查询启用的推广费类型列表", description = "查询所有启用的推广费类型") + @RequirePermission(value = "ecom:order:read", description = "查询启用的推广费类型", allowSuper = true) public ApiResponse> getActivePromotionFeeTypeList() { List list = promotionFeeTypeService.getActivePromotionFeeTypeList(); return ApiResponse.success(list); @@ -64,6 +70,7 @@ public class PromotionFeeTypeController { @GetMapping("/all") @Operation(summary = "查询所有推广费类型列表", description = "查询所有推广费类型(包括禁用的)") + @RequirePermission(value = "ecom:order:read", description = "查询所有推广费类型", allowSuper = true) public ApiResponse> getAllPromotionFeeTypeList() { List list = promotionFeeTypeService.getAllPromotionFeeTypeList(); return ApiResponse.success(list); @@ -71,6 +78,7 @@ public class PromotionFeeTypeController { @PostMapping("/init") @Operation(summary = "初始化推广费类型数据", description = "为当前公司初始化默认的推广费类型数据") + @RequirePermission(value = "ecom:order:create", description = "初始化推广费类型", allowSuper = true) public ApiResponse initPromotionFeeType() { promotionFeeTypeService.initPromotionFeeTypeForCurrentCompany(); return ApiResponse.success(); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shop/controller/ShopController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shop/controller/ShopController.java index 95cc9f86..d013ace2 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shop/controller/ShopController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shop/controller/ShopController.java @@ -7,7 +7,7 @@ import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -44,7 +44,7 @@ public class ShopController { @Operation(summary = "创建店铺", description = "创建新的店铺") @PostMapping("/create") - @RequireRole(description = "创建店铺", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "创建店铺", allowSuper = true) public ApiResponse createShop(@Valid @RequestBody CreateShopDTO createShopDTO) { ShopVO shopVO = shopService.createShop(createShopDTO); return ApiResponse.success(shopVO); @@ -52,7 +52,7 @@ public class ShopController { @Operation(summary = "更新店铺", description = "更新现有店铺信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新店铺", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "更新店铺", allowSuper = true) public ApiResponse updateShop(@Valid @RequestBody UpdateShopDTO updateShopDTO, @Parameter(description = "店铺ID") @PathVariable Long id) { ShopVO shopVO = shopService.updateShop(updateShopDTO, id); @@ -61,7 +61,7 @@ public class ShopController { @Operation(summary = "删除店铺", description = "删除指定店铺") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除店铺", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "删除店铺", allowSuper = true) public ApiResponse deleteShop( @Parameter(description = "店铺ID") @PathVariable Long id) { shopService.deleteShop(id); @@ -70,7 +70,7 @@ public class ShopController { @Operation(summary = "分页获取店铺列表", description = "分页获取店铺列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询店铺列表", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询店铺列表", allowSuper = true) public ApiResponse> getShopPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = shopService.getShopPage(pageQueryDTO); @@ -79,7 +79,7 @@ public class ShopController { @Operation(summary = "上传店铺Logo", description = "上传店铺Logo图片,支持跨公司共享") @PostMapping("/upload-logo") - @RequireRole(description = "上传店铺Logo", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "上传店铺Logo", allowSuper = true) public ApiResponse uploadLogo(@RequestParam("file") MultipartFile file) { // 检查是否为图片文件 if (!FileUploadUtils.isImageFile(file.getOriginalFilename())) { @@ -92,7 +92,7 @@ public class ShopController { @Operation(summary = "获取店铺总览", description = "获取店铺总览,返回日期范围内每日的销售额、订单数、客单价、成本、退款金额、推广费、费比统计数据,包含时间范围的总值和每日数据数组") @PostMapping("/overview") - @RequireRole(description = "查询店铺总览", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询店铺总览", allowSuper = true) public ApiResponse getShopOverview( @Valid @RequestBody ShopStatisticsQueryDTO queryDTO) { ShopOverviewVO overview = shopService.getShopOverview(queryDTO); @@ -101,7 +101,7 @@ public class ShopController { @Operation(summary = "分页获取店铺商品信息", description = "通过中间表分页获取店铺商品信息,包含商品基本信息和规格列表") @PostMapping("/products/page") - @RequireRole(description = "查询店铺商品列表", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询店铺商品列表", allowSuper = true) public ApiResponse> getShopProductPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = shopService.getShopProductPage(pageQueryDTO); @@ -110,7 +110,7 @@ public class ShopController { @Operation(summary = "获取店铺概览统计数据", description = "获取指定店铺的概览统计数据,包括销售额、单量、推广费、利润、ROI等,以及多商品数据横向对比") @PostMapping("/overview-statistics") - @RequireRole(description = "查询店铺概览统计", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询店铺概览统计", allowSuper = true) public ApiResponse getShopOverviewStatistics(@Valid @RequestBody ShopOverviewQueryDTO queryDTO) { ShopOverviewStatisticsVO overviewVO = shopOverviewStatisticsService.getShopOverviewStatistics(queryDTO); return ApiResponse.success(overviewVO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shopmonthlytarget/controller/ShopMonthlyTargetController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shopmonthlytarget/controller/ShopMonthlyTargetController.java index c53e6a96..4cb42386 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shopmonthlytarget/controller/ShopMonthlyTargetController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/shopmonthlytarget/controller/ShopMonthlyTargetController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,7 +31,7 @@ public class ShopMonthlyTargetController { @Operation(summary = "创建店铺月销量目标", description = "创建新的店铺月销量目标") @PostMapping("/create") - @RequireRole(description = "创建店铺月销量目标", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "创建店铺月销量目标", allowSuper = true) public ApiResponse createShopMonthlyTarget(@Valid @RequestBody CreateShopMonthlyTargetDTO createDTO) { ShopMonthlyTargetVO vo = shopMonthlyTargetService.createShopMonthlyTarget(createDTO); return ApiResponse.success(vo); @@ -39,7 +39,7 @@ public class ShopMonthlyTargetController { @Operation(summary = "更新店铺月销量目标", description = "更新现有店铺月销量目标信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新店铺月销量目标", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "更新店铺月销量目标", allowSuper = true) public ApiResponse updateShopMonthlyTarget(@Valid @RequestBody UpdateShopMonthlyTargetDTO updateDTO, @Parameter(description = "目标ID") @PathVariable Long id) { ShopMonthlyTargetVO vo = shopMonthlyTargetService.updateShopMonthlyTarget(updateDTO, id); @@ -48,7 +48,7 @@ public class ShopMonthlyTargetController { @Operation(summary = "删除店铺月销量目标", description = "删除指定店铺月销量目标") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除店铺月销量目标", allowUser = false) + @RequirePermission(value = "ecom:shop:manage", description = "删除店铺月销量目标", allowSuper = true) public ApiResponse deleteShopMonthlyTarget( @Parameter(description = "目标ID") @PathVariable Long id) { shopMonthlyTargetService.deleteShopMonthlyTarget(id); @@ -57,7 +57,7 @@ public class ShopMonthlyTargetController { @Operation(summary = "分页获取店铺月销量目标列表", description = "分页获取店铺月销量目标列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询店铺月销量目标列表", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询店铺月销量目标列表", allowSuper = true) public ApiResponse> getShopMonthlyTargetPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = shopMonthlyTargetService.getShopMonthlyTargetPage(pageQueryDTO); @@ -66,11 +66,10 @@ public class ShopMonthlyTargetController { @Operation(summary = "获取店铺月销量目标详情", description = "根据ID获取店铺月销量目标详情") @GetMapping("/detail/{id}") - @RequireRole(description = "查询店铺月销量目标详情", allowUser = true) + @RequirePermission(value = "ecom:shop:read", description = "查询店铺月销量目标详情", allowSuper = true) public ApiResponse getShopMonthlyTargetById( @Parameter(description = "目标ID") @PathVariable Long id) { ShopMonthlyTargetVO vo = shopMonthlyTargetService.getShopMonthlyTargetById(id); return ApiResponse.success(vo); } } - diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/AccountController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/AccountController.java index f211f2e8..8a8d7acc 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/AccountController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/AccountController.java @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; @@ -31,7 +31,7 @@ public class AccountController { @Operation(summary = "创建账户(管理员)", description = "公司管理员创建本公司账户") @PostMapping("/create") - @RequireRole(description = "创建账户", allowUser = false) + @RequirePermission(value = "org:company:manage", description = "创建账户", allowSuper = true) public ApiResponse createAccountForCompany(@Valid @RequestBody CreateAccountDTO createAccountDTO) { AccountVO accountVO = accountService.createAccountForCompany(createAccountDTO); return ApiResponse.success(accountVO); @@ -39,6 +39,7 @@ public class AccountController { @Operation(summary = "分页查询账户(管理员)", description = "公司管理员分页查询本公司账户") @PostMapping("/page") + @RequirePermission(value = "org:company:manage", description = "查询账户列表", allowSuper = true) public ApiResponse> getAccountPageForCompany(@Valid @RequestBody PageQueryDTO pageQuery) { PageResultVO pageResult = accountService.getAccountPageForCompany(pageQuery); return ApiResponse.success(pageResult); @@ -46,7 +47,7 @@ public class AccountController { @Operation(summary = "更新账户信息", description = "公司管理员更新本公司账户信息") @PutMapping("/update/{accountId}") - @RequireRole(description = "更新账户", allowUser = false) + @RequirePermission(value = "org:company:manage", description = "更新账户", allowSuper = true) public ApiResponse updateAccount( @Parameter(description = "账户ID", example = "1") @PathVariable Long accountId, @Valid @RequestBody UpdateAccountDTO updateAccountDTO) { @@ -56,6 +57,7 @@ public class AccountController { @Operation(summary = "删除账户", description = "逻辑删除账户") @DeleteMapping("/delete/{accountId}") + @RequirePermission(value = "org:company:manage", description = "删除账户", allowSuper = true) public ApiResponse deleteAccount( @Parameter(description = "账户ID", example = "1") @PathVariable Long accountId) { accountService.deleteAccount(accountId); @@ -64,6 +66,7 @@ public class AccountController { @Operation(summary = "获取账户详情", description = "获取账户详细信息") @GetMapping("/detail/{accountId}") + @RequirePermission(value = "org:company:manage", description = "获取账户详情", allowSuper = true) public ApiResponse getAccountDetail( @Parameter(description = "账户ID", example = "1") @PathVariable Long accountId) { AccountVO accountVO = accountService.getAccountDetail(accountId); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/SuperAccountController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/SuperAccountController.java index f8b81f7f..8fc53fda 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/SuperAccountController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/account/controller/SuperAccountController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -13,7 +14,6 @@ import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperCreateAccoun import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperUpdateAccountDTO; import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO; import top.xyquan.ecomdmbbackend.modules.org.account.service.SuperAccountService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; /** * 超级管理员账户管理控制器 @@ -31,7 +31,7 @@ public class SuperAccountController { @Operation(summary = "创建账户", description = "超级管理员创建账户,可指定公司") @PostMapping("/create") - @RequireRole(description = "创建账户", allowCompany = false) + @RequirePermission(value = "org:company:manage", description = "创建账户", allowSuper = true) public ApiResponse createAccount(@Valid @RequestBody SuperCreateAccountDTO superCreateAccountDTO) { AccountVO accountVO = superAccountService.createAccount(superCreateAccountDTO); return ApiResponse.success(accountVO); @@ -39,7 +39,7 @@ public class SuperAccountController { @Operation(summary = "分页查询账户", description = "超级管理员分页查询所有账户") @PostMapping("/page") - @RequireRole(description = "查询账户列表", allowCompany = false) + @RequirePermission(value = "org:company:manage", description = "查询账户列表", allowSuper = true) public ApiResponse> getAccountPage(@Valid @RequestBody PageQueryDTO pageQuery) { PageResultVO pageResult = superAccountService.getAccountPage(pageQuery); return ApiResponse.success(pageResult); @@ -47,7 +47,7 @@ public class SuperAccountController { @Operation(summary = "更新账户信息", description = "超级管理员更新账户信息") @PutMapping("/update/{accountId}") - @RequireRole(description = "更新账户", allowCompany = false) + @RequirePermission(value = "org:company:manage", description = "更新账户", allowSuper = true) public ApiResponse updateAccount( @Parameter(description = "账户ID", example = "1") @PathVariable Long accountId, @Valid @RequestBody SuperUpdateAccountDTO superUpdateAccountDTO) { @@ -57,7 +57,7 @@ public class SuperAccountController { @Operation(summary = "删除账户", description = "超级管理员逻辑删除账户") @DeleteMapping("/delete/{accountId}") - @RequireRole(description = "删除账户", allowCompany = false) + @RequirePermission(value = "org:company:manage", description = "删除账户", allowSuper = true) public ApiResponse deleteAccount( @Parameter(description = "账户ID", example = "1") @PathVariable Long accountId) { superAccountService.deleteAccount(accountId); @@ -66,7 +66,7 @@ public class SuperAccountController { @Operation(summary = "获取账户详情", description = "超级管理员获取账户详细信息") @GetMapping("/detail/{accountId}") - @RequireRole(description = "查询账户详情", allowCompany = false) + @RequirePermission(value = "org:company:manage", description = "查询账户详情", allowSuper = true) public ApiResponse getAccountDetail( @Parameter(description = "账户ID", example = "1") @PathVariable Long accountId) { AccountVO accountVO = superAccountService.getAccountDetail(accountId); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/controller/CompanyController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/controller/CompanyController.java index 0ee38dde..d0c20866 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/controller/CompanyController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/company/controller/CompanyController.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -14,7 +15,6 @@ import top.xyquan.ecomdmbbackend.modules.org.company.model.dto.UpdateCompanyDTO; import top.xyquan.ecomdmbbackend.modules.org.company.model.dto.CompanyFilterDTO; import top.xyquan.ecomdmbbackend.modules.org.company.model.vo.CompanyVO; import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; import top.xyquan.ecomdmbbackend.utils.FileUploadUtils; /** @@ -33,15 +33,15 @@ public class CompanyController { @Operation(summary = "创建公司", description = "创建新的公司") @PostMapping("/create") - @RequireRole(description = "创建公司", allowCompany = false) - public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO createCompanyDTO) { + @RequirePermission(value = "org:company:create", description = "创建公司", allowSuper = true) + public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO createCompanyDTO) { CompanyVO companyVO = companyService.createCompany(createCompanyDTO); return ApiResponse.success(companyVO); } @Operation(summary = "更新公司", description = "更新现有公司信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新公司", allowCompany = false) + @RequirePermission(value = "org:company:update", description = "更新公司", allowSuper = true) public ApiResponse updateCompany(@Valid @RequestBody UpdateCompanyDTO updateCompanyDTO, @PathVariable Long id) { CompanyVO companyVO = companyService.updateCompany(updateCompanyDTO, id); @@ -50,7 +50,7 @@ public class CompanyController { @Operation(summary = "删除公司", description = "删除指定公司") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除公司", allowCompany = false) + @RequirePermission(value = "org:company:delete", description = "删除公司", allowSuper = true) public ApiResponse deleteCompany( @Parameter(description = "公司ID") @PathVariable Long id) { companyService.deleteCompany(id); @@ -59,7 +59,7 @@ public class CompanyController { @Operation(summary = "分页查询公司列表", description = "分页查询公司列表,支持多种过滤条件") @PostMapping("/page") - @RequireRole(description = "查询公司列表", allowCompany = false) + @RequirePermission(value = "org:company:read", description = "查询公司列表", allowSuper = true) public ApiResponse> getCompanyPage( @Valid @RequestBody PageQueryDTO pageQuery) { PageResultVO pageResult = companyService.getCompanyPage(pageQuery); @@ -68,7 +68,7 @@ public class CompanyController { @Operation(summary = "上传公司Logo", description = "上传公司Logo图片") @PostMapping("/upload-logo") - @RequireRole(description = "上传公司Logo", allowCompany = false) + @RequirePermission(value = "org:company:update", description = "上传公司Logo", allowSuper = true) public ApiResponse uploadLogo(@RequestParam("file") MultipartFile file) { // 检查是否为图片文件 if (!FileUploadUtils.isImageFile(file.getOriginalFilename())) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymember/controller/CompanyMemberController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymember/controller/CompanyMemberController.java index cb20157a..ca235aed 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymember/controller/CompanyMemberController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymember/controller/CompanyMemberController.java @@ -5,13 +5,13 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.CreateCompanyMemberDTO; import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.UpdateCompanyMemberDTO; import top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO; import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole; import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import java.util.List; @@ -35,7 +35,7 @@ public class CompanyMemberController { @Operation(summary = "创建公司成员", description = "创建新的公司成员") @PostMapping("/create") - @RequireRole(description = "创建公司成员", allowUser = false) + @RequirePermission(value = "org:member:manage", description = "创建公司成员", allowSuper = true) public ApiResponse create(@Valid @RequestBody CreateCompanyMemberDTO dto) { CompanyMemberVO vo = companyMemberService.create(dto); return ApiResponse.success(vo); @@ -43,7 +43,7 @@ public class CompanyMemberController { @Operation(summary = "更新成员职位", description = "更新成员的职位") @PutMapping("/update-position/{memberId}") - @RequireRole(description = "更新成员职位", allowUser = false) + @RequirePermission(value = "org:member:manage", description = "更新成员职位", allowSuper = true) public ApiResponse updatePosition( @Parameter(description = "成员ID") @PathVariable Long memberId, @RequestParam Long positionId) { @@ -53,7 +53,7 @@ public class CompanyMemberController { @Operation(summary = "变更成员角色", description = "变更成员的角色") @PutMapping("/change-role/{memberId}") - @RequireRole(description = "变更成员角色", allowUser = false) + @RequirePermission(value = "org:member:manage", description = "变更成员角色", allowSuper = true) public ApiResponse changeRole( @Parameter(description = "成员ID") @PathVariable Long memberId, @RequestParam String role) { @@ -63,7 +63,7 @@ public class CompanyMemberController { @Operation(summary = "移除成员", description = "移除公司成员") @DeleteMapping("/remove/{memberId}") - @RequireRole(description = "移除成员", allowUser = false) + @RequirePermission(value = "org:member:manage", description = "移除成员", allowSuper = true) public ApiResponse remove(@Parameter(description = "成员ID") @PathVariable Long memberId) { companyMemberService.remove(memberId); return ApiResponse.success(); @@ -71,7 +71,7 @@ public class CompanyMemberController { @Operation(summary = "获取公司所有成员", description = "获取指定公司的所有成员(含用户信息、职位名称)") @GetMapping("/company/{companyId}") - @RequireRole(description = "查询公司成员", allowUser = false) + @RequirePermission(value = "org:member:read", description = "查询公司成员", allowSuper = true) public ApiResponse> getByCompanyId( @Parameter(description = "公司ID") @PathVariable Long companyId) { List list = companyMemberService.getByCompanyId(companyId); @@ -80,7 +80,7 @@ public class CompanyMemberController { @Operation(summary = "获取用户所属公司列表", description = "获取当前用户所属的所有公司列表") @GetMapping("/user/{userId}") - @RequireRole(description = "查询用户公司列表") + @RequirePermission(value = "org:member:read", description = "查询用户公司列表", allowSuper = true) public ApiResponse> getByUserId( @Parameter(description = "用户ID") @PathVariable Long userId) { List list = companyMemberService.getByUserId(userId); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymenu/controller/CompanyMenuController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymenu/controller/CompanyMenuController.java index ccc5b5c5..5629bb06 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymenu/controller/CompanyMenuController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companymenu/controller/CompanyMenuController.java @@ -4,9 +4,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.org.companymenu.service.CompanyMenuService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; import top.xyquan.ecomdmbbackend.modules.org.companymenu.model.vo.CompanyMenuVO; import java.util.List; @@ -27,7 +27,7 @@ public class CompanyMenuController { @Operation(summary = "获取公司所有菜单ID(超管)", description = "获取指定公司的所有菜单ID列表") @GetMapping("/menu-ids/{id}") - @RequireRole(description = "获取公司菜单ID", allowUser = false) + @RequirePermission(value = "org:company-menu:assign", description = "获取公司菜单ID", allowSuper = true) public ApiResponse> getCompanyMenuIds( @Parameter(description = "公司ID") @PathVariable Long id) { List menuIds = companyMenuService.getCompanyMenuIds(id); @@ -36,7 +36,7 @@ public class CompanyMenuController { @Operation(summary = "批量更新公司菜单(超管)", description = "批量更新公司菜单状态,新增缺失的菜单,停用多余的菜单,启用已有的菜单") @PostMapping("/batch-update/{id}") - @RequireRole(description = "批量更新公司菜单", allowUser = false) + @RequirePermission(value = "org:company-menu:assign", description = "批量更新公司菜单", allowSuper = true) public ApiResponse batchUpdateCompanyMenus( @Parameter(description = "公司ID") @PathVariable Long id, @Parameter(description = "菜单ID列表") @RequestBody List menuIds) { @@ -46,7 +46,7 @@ public class CompanyMenuController { @Operation(summary = "获取公司所有菜单列表", description = "获取当前用户公司的所有菜单列表,包含公司菜单中间表ID,中间表只作为过滤条件,不覆盖系统菜单字段") @GetMapping("/menus") - @RequireRole(description = "获取公司菜单列表", allowUser = true) + @RequirePermission(value = "org:company-menu:assign", description = "获取公司菜单列表", allowSuper = true) public ApiResponse> getCompanyMenus() { List menus = companyMenuService.getCompanyMenus(); return ApiResponse.success(menus); @@ -54,7 +54,7 @@ public class CompanyMenuController { @Operation(summary = "获取公司完整菜单树", description = "获取当前用户公司的完整菜单树结构,包含公司菜单中间表ID,中间表只作为过滤条件,不覆盖系统菜单字段") @GetMapping("/menu-tree") - @RequireRole(description = "获取公司菜单树", allowUser = true) + @RequirePermission(value = "org:company-menu:assign", description = "获取公司菜单树", allowSuper = true) public ApiResponse> getCompanyMenuTree() { List menuTree = companyMenuService.getCompanyMenuTree(); return ApiResponse.success(menuTree); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/controller/CompanyPermissionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/controller/CompanyPermissionController.java new file mode 100644 index 00000000..e5710a04 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/controller/CompanyPermissionController.java @@ -0,0 +1,66 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.model.dto.BatchAssignCompanyPermissionDTO; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.service.CompanyPermissionService; +import top.xyquan.ecomdmbbackend.modules.sys.permission.model.vo.PermissionVO; + +import java.util.List; + +/** + * 公司权限管理控制器 + */ +@Tag(name = "组织-公司权限管理", description = "公司权限的分配和管理接口") +@RestController +@RequestMapping("/company-permission") +public class CompanyPermissionController { + + private final CompanyPermissionService companyPermissionService; + + public CompanyPermissionController(CompanyPermissionService companyPermissionService) { + this.companyPermissionService = companyPermissionService; + } + + @Operation(summary = "批量分配公司权限(超管)", description = "批量分配公司权限,覆盖原有的权限分配") + @PostMapping("/batch-assign") + @RequirePermission(value = "org:company-permission:assign", description = "批量分配公司权限", allowSuper = true) + public ApiResponse batchAssignCompanyPermissions( + @Valid @RequestBody BatchAssignCompanyPermissionDTO batchAssignDTO) { + companyPermissionService.batchAssignCompanyPermissions(batchAssignDTO); + return ApiResponse.success(); + } + + @Operation(summary = "获取公司权限列表(超管)", description = "获取指定公司的所有权限列表") + @GetMapping("/company/{companyId}") + @RequirePermission(value = "org:company-permission:assign", description = "查看公司权限", allowSuper = true) + public ApiResponse> getCompanyPermissions( + @Parameter(description = "公司ID") @PathVariable Long companyId) { + List permissions = companyPermissionService.getPermissionsByCompanyId(companyId); + return ApiResponse.success(permissions); + } + + @Operation(summary = "获取公司权限ID列表(超管)", description = "获取指定公司的所有权限ID列表") + @GetMapping("/company/{companyId}/ids") + @RequirePermission(value = "org:company-permission:assign", description = "查看公司权限", allowSuper = true) + public ApiResponse> getCompanyPermissionIds( + @Parameter(description = "公司ID") @PathVariable Long companyId) { + List permissionIds = companyPermissionService.getCompanyPermissionIds(companyId); + return ApiResponse.success(permissionIds); + } + + @Operation(summary = "批量更新公司权限(超管)", description = "批量更新公司权限") + @PostMapping("/company/{companyId}/batch-update") + @RequirePermission(value = "org:company-permission:assign", description = "批量更新公司权限", allowSuper = true) + public ApiResponse batchUpdateCompanyPermissions( + @Parameter(description = "公司ID") @PathVariable Long companyId, + @RequestBody List permissionIds) { + companyPermissionService.batchUpdateCompanyPermissions(companyId, permissionIds); + return ApiResponse.success(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/mapper/CompanyPermissionMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/mapper/CompanyPermissionMapper.java new file mode 100644 index 00000000..78f14dd5 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/mapper/CompanyPermissionMapper.java @@ -0,0 +1,31 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.model.po.CompanyPermissionPO; +import top.xyquan.ecomdmbbackend.modules.sys.permission.model.vo.PermissionVO; + +import java.util.List; + +/** + * 公司权限Mapper + */ +@Mapper +public interface CompanyPermissionMapper extends BaseMapper { + + /** + * 根据公司ID查询权限列表 + * @param companyId 公司ID + * @return 权限列表 + */ + List selectPermissionsByCompanyId(@Param("companyId") Long companyId); + + /** + * 检查公司是否有指定权限 + * @param companyId 公司ID + * @param permissionId 权限ID + * @return 是否有权限 + */ + boolean hasCompanyPermission(@Param("companyId") Long companyId, @Param("permissionId") Long permissionId); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/dto/BatchAssignCompanyPermissionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/dto/BatchAssignCompanyPermissionDTO.java new file mode 100644 index 00000000..4bb8d213 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/dto/BatchAssignCompanyPermissionDTO.java @@ -0,0 +1,25 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.model.dto; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +/** + * 批量分配公司权限DTO + */ +@Data +public class BatchAssignCompanyPermissionDTO { + + /** + * 公司ID + */ + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 权限ID列表 + */ + @NotNull(message = "权限ID列表不能为空") + private List permissionIds; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/po/CompanyPermissionPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/po/CompanyPermissionPO.java new file mode 100644 index 00000000..1d3b1259 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/po/CompanyPermissionPO.java @@ -0,0 +1,47 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 公司权限关联实体 + * 表名: org_company_permission + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("org_company_permission") +public class CompanyPermissionPO { + + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 权限ID(对应 sys_permission.id) + */ + @TableField("permission_id") + private Long permissionId; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/vo/CompanyPermissionVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/vo/CompanyPermissionVO.java new file mode 100644 index 00000000..af32efea --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/model/vo/CompanyPermissionVO.java @@ -0,0 +1,19 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.model.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import top.xyquan.ecomdmbbackend.modules.sys.permission.model.vo.PermissionVO; + +/** + * 公司权限VO + * 继承PermissionVO,添加公司权限中间表ID字段 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CompanyPermissionVO extends PermissionVO { + + /** + * 公司权限中间表ID + */ + private Long companyPermissionId; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/CompanyPermissionService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/CompanyPermissionService.java new file mode 100644 index 00000000..b67ff2c3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/CompanyPermissionService.java @@ -0,0 +1,55 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.service; + +import top.xyquan.ecomdmbbackend.modules.org.companypermission.model.dto.BatchAssignCompanyPermissionDTO; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.model.vo.CompanyPermissionVO; +import top.xyquan.ecomdmbbackend.modules.sys.permission.model.vo.PermissionVO; + +import java.util.List; + +/** + * 公司权限服务接口 + */ +public interface CompanyPermissionService { + + /** + * 批量分配公司权限 + * @param batchAssignDTO 批量分配DTO + */ + void batchAssignCompanyPermissions(BatchAssignCompanyPermissionDTO batchAssignDTO); + + /** + * 根据公司ID查询权限列表 + * @param companyId 公司ID + * @return 权限列表 + */ + List getPermissionsByCompanyId(Long companyId); + + /** + * 检查公司是否有指定权限 + * @param companyId 公司ID + * @param permissionId 权限ID + * @return 是否有权限 + */ + boolean hasCompanyPermission(Long companyId, Long permissionId); + + /** + * 获取公司所有权限ID列表 + * @param companyId 公司ID + * @return 权限ID列表 + */ + List getCompanyPermissionIds(Long companyId); + + /** + * 获取公司所有权限码列表 + * @param companyId 公司ID + * @return 权限码列表 + */ + List getCompanyPermissionCodes(Long companyId); + + /** + * 批量更新公司权限 + * @param companyId 公司ID + * @param permissionIds 权限ID列表 + */ + void batchUpdateCompanyPermissions(Long companyId, List permissionIds); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/impl/CompanyPermissionServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/impl/CompanyPermissionServiceImpl.java new file mode 100644 index 00000000..48ab4d31 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/companypermission/service/impl/CompanyPermissionServiceImpl.java @@ -0,0 +1,156 @@ +package top.xyquan.ecomdmbbackend.modules.org.companypermission.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.mapper.CompanyPermissionMapper; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.model.dto.BatchAssignCompanyPermissionDTO; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.model.po.CompanyPermissionPO; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.service.CompanyPermissionService; +import top.xyquan.ecomdmbbackend.modules.sys.permission.mapper.PermissionMapper; +import top.xyquan.ecomdmbbackend.modules.sys.permission.model.po.PermissionPO; +import top.xyquan.ecomdmbbackend.modules.sys.permission.model.vo.PermissionVO; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 公司权限服务实现类 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class CompanyPermissionServiceImpl extends ServiceImpl + implements CompanyPermissionService { + + private final CompanyPermissionMapper companyPermissionMapper; + private final PermissionMapper permissionMapper; + private final CurrentUserContext currentUserContext; + + /** + * 批量分配公司权限 + * @param batchAssignDTO 批量分配DTO + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void batchAssignCompanyPermissions(BatchAssignCompanyPermissionDTO batchAssignDTO) { + Long companyId = batchAssignDTO.getCompanyId(); + List permissionIds = batchAssignDTO.getPermissionIds(); + + // 先删除该公司所有权限关联 + LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); + deleteWrapper.eq(CompanyPermissionPO::getCompanyId, companyId); + this.remove(deleteWrapper); + + // 批量插入新的权限关联 + List companyPermissions = new ArrayList<>(); + for (Long permissionId : permissionIds) { + CompanyPermissionPO companyPermission = new CompanyPermissionPO(); + companyPermission.setCompanyId(companyId); + companyPermission.setPermissionId(permissionId); + companyPermission.setCreateBy(currentUserContext.getCurrentUserId()); + companyPermissions.add(companyPermission); + } + + if (!companyPermissions.isEmpty()) { + this.saveBatch(companyPermissions); + } + + log.info("批量分配公司权限完成,公司ID:{},权限数量:{}", companyId, permissionIds.size()); + } + + /** + * 根据公司ID查询权限列表 + * @param companyId 公司ID + * @return 权限列表 + */ + @Override + public List getPermissionsByCompanyId(Long companyId) { + return companyPermissionMapper.selectPermissionsByCompanyId(companyId); + } + + /** + * 检查公司是否有指定权限 + * @param companyId 公司ID + * @param permissionId 权限ID + * @return 是否有权限 + */ + @Override + public boolean hasCompanyPermission(Long companyId, Long permissionId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyPermissionPO::getCompanyId, companyId) + .eq(CompanyPermissionPO::getPermissionId, permissionId); + + return this.count(wrapper) > 0; + } + + /** + * 获取公司所有权限ID列表 + * @param companyId 公司ID + * @return 权限ID列表 + */ + @Override + public List getCompanyPermissionIds(Long companyId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyPermissionPO::getCompanyId, companyId); + + List companyPermissions = this.list(wrapper); + + return companyPermissions.stream() + .map(CompanyPermissionPO::getPermissionId) + .collect(Collectors.toList()); + } + + /** + * 获取公司所有权限码列表 + * @param companyId 公司ID + * @return 权限码列表 + */ + @Override + public List getCompanyPermissionCodes(Long companyId) { + List permissions = getPermissionsByCompanyId(companyId); + + return permissions.stream() + .map(PermissionVO::getCode) + .filter(code -> code != null) + .collect(Collectors.toList()); + } + + /** + * 批量更新公司权限 + * @param companyId 公司ID + * @param permissionIds 权限ID列表 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void batchUpdateCompanyPermissions(Long companyId, List permissionIds) { + // 先删除该公司所有权限关联 + LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); + deleteWrapper.eq(CompanyPermissionPO::getCompanyId, companyId); + this.remove(deleteWrapper); + + // 批量插入新的权限关联 + if (permissionIds != null && !permissionIds.isEmpty()) { + List companyPermissions = new ArrayList<>(); + for (Long permissionId : permissionIds) { + CompanyPermissionPO companyPermission = new CompanyPermissionPO(); + companyPermission.setCompanyId(companyId); + companyPermission.setPermissionId(permissionId); + companyPermission.setCreateBy(currentUserContext.getCurrentUserId()); + companyPermissions.add(companyPermission); + } + + if (!companyPermissions.isEmpty()) { + this.saveBatch(companyPermissions); + } + } + + log.info("批量更新公司权限完成,公司ID:{},权限数量:{}", companyId, + permissionIds != null ? permissionIds.size() : 0); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/department/controller/DepartmentController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/department/controller/DepartmentController.java index 83de7832..c0c5e5d3 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/department/controller/DepartmentController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/department/controller/DepartmentController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -13,7 +14,6 @@ import top.xyquan.ecomdmbbackend.modules.org.department.model.dto.UpdateDepartme import top.xyquan.ecomdmbbackend.modules.org.department.model.dto.DepartmentFilterDTO; import top.xyquan.ecomdmbbackend.modules.org.department.model.vo.DepartmentVO; import top.xyquan.ecomdmbbackend.modules.org.department.service.DepartmentService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; import java.util.List; @@ -33,7 +33,7 @@ public class DepartmentController { @Operation(summary = "创建部门", description = "创建新的部门") @PostMapping("/create") - @RequireRole(description = "创建部门", allowUser = false) + @RequirePermission(value = "org:department:manage", description = "创建部门", allowSuper = true) public ApiResponse createDepartment(@Valid @RequestBody CreateDepartmentDTO createDepartmentDTO) { DepartmentVO departmentVO = departmentService.createDepartment(createDepartmentDTO); return ApiResponse.success(departmentVO); @@ -41,7 +41,7 @@ public class DepartmentController { @Operation(summary = "更新部门", description = "更新现有部门信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新部门", allowUser = false) + @RequirePermission(value = "org:department:manage", description = "更新部门", allowSuper = true) public ApiResponse updateDepartment(@Valid @RequestBody UpdateDepartmentDTO updateDepartmentDTO, @PathVariable Long id) { DepartmentVO departmentVO = departmentService.updateDepartment(updateDepartmentDTO, id); @@ -50,7 +50,7 @@ public class DepartmentController { @Operation(summary = "删除部门", description = "删除指定部门") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除部门", allowUser = false) + @RequirePermission(value = "org:department:manage", description = "删除部门", allowSuper = true) public ApiResponse deleteDepartment( @Parameter(description = "部门ID") @PathVariable Long id) { departmentService.deleteDepartment(id); @@ -59,7 +59,7 @@ public class DepartmentController { @Operation(summary = "分页获取部门列表", description = "分页获取部门列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询部门列表", allowUser = true) + @RequirePermission(value = "org:department:read", description = "查询部门列表", allowSuper = true) public ApiResponse> getDepartmentPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = departmentService.getDepartmentPage(pageQueryDTO); @@ -68,7 +68,7 @@ public class DepartmentController { @Operation(summary = "获取全部部门", description = "获取当前公司全部部门列表") @GetMapping("/all") - @RequireRole(description = "查询全部部门", allowUser = true) + @RequirePermission(value = "org:department:read", description = "查询全部部门", allowSuper = true) public ApiResponse> getAllDepartments() { List result = departmentService.getAllDepartments(); return ApiResponse.success(result); @@ -76,7 +76,7 @@ public class DepartmentController { @Operation(summary = "获取部门树", description = "获取当前公司部门树形结构") @GetMapping("/tree") - @RequireRole(description = "查询部门树", allowUser = true) + @RequirePermission(value = "org:department:read", description = "查询部门树", allowSuper = true) public ApiResponse> getDepartmentTree() { List result = departmentService.getDepartmentTree(); return ApiResponse.success(result); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/departmentmember/controller/DepartmentMemberController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/departmentmember/controller/DepartmentMemberController.java index 2bab8c37..1cde2356 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/departmentmember/controller/DepartmentMemberController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/departmentmember/controller/DepartmentMemberController.java @@ -5,12 +5,12 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto.AddDepartmentMemberDTO; import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto.RemoveDepartmentMemberDTO; import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO; import top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; import java.util.List; @@ -30,7 +30,7 @@ public class DepartmentMemberController { @Operation(summary = "添加部门成员", description = "添加成员到部门") @PostMapping("/add") - @RequireRole(description = "添加部门成员", allowUser = false) + @RequirePermission(value = "org:department:manage", description = "添加部门成员", allowSuper = true) public ApiResponse addMember(@Valid @RequestBody AddDepartmentMemberDTO dto) { DepartmentMemberVO vo = departmentMemberService.addMember(dto); return ApiResponse.success(vo); @@ -38,7 +38,7 @@ public class DepartmentMemberController { @Operation(summary = "移除部门成员", description = "从部门移除成员") @PostMapping("/remove") - @RequireRole(description = "移除部门成员", allowUser = false) + @RequirePermission(value = "org:department:manage", description = "移除部门成员", allowSuper = true) public ApiResponse removeMember(@Valid @RequestBody RemoveDepartmentMemberDTO dto) { departmentMemberService.removeMember(dto.getDepartmentId(), dto.getUserId()); return ApiResponse.success(); @@ -46,7 +46,7 @@ public class DepartmentMemberController { @Operation(summary = "获取部门所有成员", description = "获取指定部门的所有成员(含用户信息)") @GetMapping("/department/{departmentId}") - @RequireRole(description = "查询部门成员", allowUser = false) + @RequirePermission(value = "org:department:read", description = "查询部门成员", allowSuper = true) public ApiResponse> getByDepartmentId( @Parameter(description = "部门ID") @PathVariable Long departmentId) { List list = departmentMemberService.getByDepartmentId(departmentId); @@ -55,7 +55,7 @@ public class DepartmentMemberController { @Operation(summary = "获取用户所属部门列表", description = "获取用户所属的所有部门列表") @GetMapping("/user/{userId}") - @RequireRole(description = "查询用户部门列表") + @RequirePermission(value = "org:department:read", description = "查询用户部门列表", allowSuper = true) public ApiResponse> getByUserId( @Parameter(description = "用户ID") @PathVariable Long userId) { List list = departmentMemberService.getByUserId(userId); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionController.java index 842edd19..a7ee9ae0 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -13,7 +14,6 @@ import top.xyquan.ecomdmbbackend.modules.org.position.model.dto.UpdatePositionDT import top.xyquan.ecomdmbbackend.modules.org.position.model.dto.PositionFilterDTO; import top.xyquan.ecomdmbbackend.modules.org.position.model.vo.PositionVO; import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionService; -import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; /** * 岗位管理控制器 @@ -31,7 +31,7 @@ public class PositionController { @Operation(summary = "创建岗位", description = "创建新的岗位") @PostMapping("/create") - @RequireRole(description = "创建岗位", allowUser = false) + @RequirePermission(value = "org:position:manage", description = "创建岗位", allowSuper = true) public ApiResponse createPosition(@Valid @RequestBody CreatePositionDTO createPositionDTO) { PositionVO positionVO = positionService.createPosition(createPositionDTO); return ApiResponse.success(positionVO); @@ -39,7 +39,7 @@ public class PositionController { @Operation(summary = "更新岗位", description = "更新现有岗位信息") @PutMapping("/update/{id}") - @RequireRole(description = "更新岗位", allowUser = false) + @RequirePermission(value = "org:position:manage", description = "更新岗位", allowSuper = true) public ApiResponse updatePosition(@Valid @RequestBody UpdatePositionDTO updatePositionDTO, @PathVariable Long id) { PositionVO positionVO = positionService.updatePosition(updatePositionDTO, id); @@ -48,7 +48,7 @@ public class PositionController { @Operation(summary = "删除岗位", description = "删除指定岗位") @DeleteMapping("/delete/{id}") - @RequireRole(description = "删除岗位", allowUser = false) + @RequirePermission(value = "org:position:manage", description = "删除岗位", allowSuper = true) public ApiResponse deletePosition( @Parameter(description = "岗位ID") @PathVariable Long id) { positionService.deletePosition(id); @@ -57,7 +57,7 @@ public class PositionController { @Operation(summary = "分页获取岗位列表", description = "分页获取岗位列表,支持条件过滤") @PostMapping("/page") - @RequireRole(description = "查询岗位列表", allowUser = true) + @RequirePermission(value = "org:position:read", description = "查询岗位列表", allowSuper = true) public ApiResponse> getPositionPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = positionService.getPositionPage(pageQueryDTO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionPermissionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionPermissionController.java index c99fa28a..1a3b5cfa 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionPermissionController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/position/controller/PositionPermissionController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.org.position.model.dto.BatchAssignPositionMenuDTO; import top.xyquan.ecomdmbbackend.modules.org.position.model.vo.PositionMenuVO; @@ -13,10 +14,10 @@ import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionMenuServic import java.util.List; /** - * 岗位权限管理控制器 + * 岗位菜单管理控制器 * 岗位菜单关联表: org_position_menu(由 org_position_company_menu_map 重命名) */ -@Tag(name = "组织-岗位权限管理", description = "岗位菜单的分配和管理接口") +@Tag(name = "组织-岗位菜单管理", description = "岗位菜单的分配和管理接口") @RestController @RequestMapping("/position-menu") public class PositionPermissionController { @@ -29,6 +30,7 @@ public class PositionPermissionController { @Operation(summary = "批量分配岗位菜单", description = "为指定岗位批量分配菜单") @PostMapping("/assign") + @RequirePermission(value = "org:position-menu:assign", description = "批量分配岗位菜单", allowSuper = true) public ApiResponse batchAssignPositionMenus(@Valid @RequestBody BatchAssignPositionMenuDTO batchAssignDTO) { positionMenuService.batchAssignPositionMenus(batchAssignDTO); return ApiResponse.success(); @@ -36,6 +38,7 @@ public class PositionPermissionController { @Operation(summary = "移除岗位菜单", description = "移除指定岗位的某个菜单") @DeleteMapping("/remove/{positionId}/{menuId}") + @RequirePermission(value = "org:position-menu:assign", description = "移除岗位菜单", allowSuper = true) public ApiResponse removePositionMenu( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "菜单ID") @PathVariable Long menuId) { @@ -45,6 +48,7 @@ public class PositionPermissionController { @Operation(summary = "查询岗位菜单列表", description = "根据岗位ID查询该岗位拥有的所有菜单") @GetMapping("/menus/{positionId}") + @RequirePermission(value = "org:position-menu:assign", description = "查询岗位菜单列表", allowSuper = true) public ApiResponse> getMenusByPositionId( @Parameter(description = "岗位ID") @PathVariable Long positionId) { List menus = positionMenuService.getMenusByPositionId(positionId); @@ -53,6 +57,7 @@ public class PositionPermissionController { @Operation(summary = "批量查询岗位菜单", description = "根据岗位ID列表批量查询菜单") @PostMapping("/menus/batch") + @RequirePermission(value = "org:position-menu:assign", description = "批量查询岗位菜单", allowSuper = true) public ApiResponse> getMenusByPositionIds(@RequestBody List positionIds) { List menus = positionMenuService.getMenusByPositionIds(positionIds); return ApiResponse.success(menus); @@ -60,6 +65,7 @@ public class PositionPermissionController { @Operation(summary = "检查岗位菜单", description = "检查指定岗位是否拥有某个菜单") @GetMapping("/check/{positionId}/{menuId}") + @RequirePermission(value = "org:position-menu:assign", description = "检查岗位菜单", allowSuper = true) public ApiResponse hasPositionMenu( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "菜单ID") @PathVariable Long menuId) { @@ -69,6 +75,7 @@ public class PositionPermissionController { @Operation(summary = "获取岗位所有菜单ID", description = "获取指定岗位的所有菜单ID列表") @GetMapping("/menu-ids/{positionId}") + @RequirePermission(value = "org:position-menu:assign", description = "获取岗位菜单ID", allowSuper = true) public ApiResponse> getPositionMenuIds( @Parameter(description = "岗位ID") @PathVariable Long positionId) { List menuIds = positionMenuService.getPositionMenuIds(positionId); @@ -77,6 +84,7 @@ public class PositionPermissionController { @Operation(summary = "批量更新岗位菜单", description = "批量更新岗位菜单") @PostMapping("/batch-update/{positionId}") + @RequirePermission(value = "org:position-menu:assign", description = "批量更新岗位菜单", allowSuper = true) public ApiResponse batchUpdatePositionMenus( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "菜单ID列表") @RequestBody List menuIds) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/positionpermission/controller/PositionPermissionManagementController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/positionpermission/controller/PositionPermissionManagementController.java index 4ad84cb3..0e7460f0 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/positionpermission/controller/PositionPermissionManagementController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/positionpermission/controller/PositionPermissionManagementController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.org.positionpermission.model.dto.BatchAssignPositionPermissionDTO; import top.xyquan.ecomdmbbackend.modules.org.positionpermission.model.vo.PositionPermissionVO; @@ -29,6 +30,7 @@ public class PositionPermissionManagementController { @Operation(summary = "批量分配岗位权限", description = "为指定岗位批量分配权限") @PostMapping("/assign") + @RequirePermission(value = "org:position-permission:assign", description = "批量分配岗位权限", allowSuper = true) public ApiResponse batchAssignPositionPermissions( @Valid @RequestBody BatchAssignPositionPermissionDTO batchAssignDTO) { positionPermissionService.batchAssignPositionPermissions(batchAssignDTO); @@ -37,6 +39,7 @@ public class PositionPermissionManagementController { @Operation(summary = "移除岗位权限", description = "移除指定岗位的某个权限") @DeleteMapping("/remove/{positionId}/{permissionId}") + @RequirePermission(value = "org:position-permission:assign", description = "移除岗位权限", allowSuper = true) public ApiResponse removePositionPermission( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "权限ID") @PathVariable Long permissionId) { @@ -46,6 +49,7 @@ public class PositionPermissionManagementController { @Operation(summary = "查询岗位权限列表", description = "根据岗位ID查询该岗位拥有的所有权限") @GetMapping("/permissions/{positionId}") + @RequirePermission(value = "org:position-permission:assign", description = "查询岗位权限列表", allowSuper = true) public ApiResponse> getPermissionsByPositionId( @Parameter(description = "岗位ID") @PathVariable Long positionId) { List permissions = positionPermissionService.getPermissionsByPositionId(positionId); @@ -54,6 +58,7 @@ public class PositionPermissionManagementController { @Operation(summary = "批量查询岗位权限", description = "根据岗位ID列表批量查询权限") @PostMapping("/permissions/batch") + @RequirePermission(value = "org:position-permission:assign", description = "批量查询岗位权限", allowSuper = true) public ApiResponse> getPermissionsByPositionIds(@RequestBody List positionIds) { List permissions = positionPermissionService.getPermissionsByPositionIds(positionIds); return ApiResponse.success(permissions); @@ -61,6 +66,7 @@ public class PositionPermissionManagementController { @Operation(summary = "检查岗位权限", description = "检查指定岗位是否拥有某个权限") @GetMapping("/check/{positionId}/{permissionId}") + @RequirePermission(value = "org:position-permission:assign", description = "检查岗位权限", allowSuper = true) public ApiResponse hasPositionPermission( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "权限ID") @PathVariable Long permissionId) { @@ -70,6 +76,7 @@ public class PositionPermissionManagementController { @Operation(summary = "检查岗位权限码", description = "检查指定岗位是否拥有某个权限码") @GetMapping("/check-code/{positionId}/{permissionCode}") + @RequirePermission(value = "org:position-permission:assign", description = "检查岗位权限码", allowSuper = true) public ApiResponse hasPositionPermissionByCode( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "权限码") @PathVariable String permissionCode) { @@ -79,6 +86,7 @@ public class PositionPermissionManagementController { @Operation(summary = "获取岗位所有权限ID", description = "获取指定岗位的所有权限ID列表") @GetMapping("/permission-ids/{positionId}") + @RequirePermission(value = "org:position-permission:assign", description = "获取岗位权限ID", allowSuper = true) public ApiResponse> getPositionPermissionIds( @Parameter(description = "岗位ID") @PathVariable Long positionId) { List permissionIds = positionPermissionService.getPositionPermissionIds(positionId); @@ -87,6 +95,7 @@ public class PositionPermissionManagementController { @Operation(summary = "获取岗位所有权限码", description = "获取指定岗位的所有权限码列表") @GetMapping("/permission-codes/{positionId}") + @RequirePermission(value = "org:position-permission:assign", description = "获取岗位权限码", allowSuper = true) public ApiResponse> getPositionPermissionCodes( @Parameter(description = "岗位ID") @PathVariable Long positionId) { List permissionCodes = positionPermissionService.getPositionPermissionCodes(positionId); @@ -95,6 +104,7 @@ public class PositionPermissionManagementController { @Operation(summary = "批量更新岗位权限", description = "批量更新岗位权限") @PostMapping("/batch-update/{positionId}") + @RequirePermission(value = "org:position-permission:assign", description = "批量更新岗位权限", allowSuper = true) public ApiResponse batchUpdatePositionPermissions( @Parameter(description = "岗位ID") @PathVariable Long positionId, @Parameter(description = "权限ID列表") @RequestBody List permissionIds) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/plan/controller/PlanController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/plan/controller/PlanController.java index 9770224b..606ed29f 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/plan/controller/PlanController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/plan/controller/PlanController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,6 +32,7 @@ public class PlanController { @Operation(summary = "创建套餐", description = "创建新的订阅套餐") @PostMapping("/create") + @RequirePermission(value = "system:company:manage", description = "创建套餐", allowSuper = true) public ApiResponse createPlan(@Valid @RequestBody CreatePlanDTO createPlanDTO) { PlanVO planVO = planService.createPlan(createPlanDTO); return ApiResponse.success(planVO); @@ -38,6 +40,7 @@ public class PlanController { @Operation(summary = "更新套餐", description = "更新现有套餐信息") @PutMapping("/update/{planId}") + @RequirePermission(value = "system:company:manage", description = "更新套餐", allowSuper = true) public ApiResponse updatePlan(@Valid @RequestBody UpdatePlanDTO updatePlanDTO, @PathVariable Long planId) { PlanVO planVO = planService.updatePlan(updatePlanDTO, planId); @@ -46,6 +49,7 @@ public class PlanController { @Operation(summary = "删除套餐", description = "删除指定套餐") @DeleteMapping("/delete/{planId}") + @RequirePermission(value = "system:company:manage", description = "删除套餐", allowSuper = true) public ApiResponse deletePlan( @Parameter(description = "套餐ID") @PathVariable Long planId) { planService.deletePlan(planId); @@ -54,6 +58,7 @@ public class PlanController { @Operation(summary = "分页获取套餐列表", description = "分页获取套餐列表,支持条件过滤") @PostMapping("/page") + @RequirePermission(value = "system:company:manage", description = "查询套餐列表", allowSuper = true) public ApiResponse> getPlanPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = planService.getPlanPage(pageQueryDTO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/planpricing/controller/PlanPricingController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/planpricing/controller/PlanPricingController.java index e60ad21f..523d0cdd 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/planpricing/controller/PlanPricingController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/planpricing/controller/PlanPricingController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,6 +32,7 @@ public class PlanPricingController { @Operation(summary = "创建定价", description = "创建新的套餐定价") @PostMapping("/create") + @RequirePermission(value = "system:company:manage", description = "创建定价", allowSuper = true) public ApiResponse createPlanPricing(@Valid @RequestBody CreatePlanPricingDTO createPlanPricingDTO) { PlanPricingVO planPricingVO = planPricingService.createPlanPricing(createPlanPricingDTO); return ApiResponse.success(planPricingVO); @@ -38,6 +40,7 @@ public class PlanPricingController { @Operation(summary = "更新定价", description = "更新现有定价信息") @PutMapping("/update/{id}") + @RequirePermission(value = "system:company:manage", description = "更新定价", allowSuper = true) public ApiResponse updatePlanPricing(@Valid @RequestBody UpdatePlanPricingDTO updatePlanPricingDTO, @PathVariable Long id) { PlanPricingVO planPricingVO = planPricingService.updatePlanPricing(updatePlanPricingDTO, id); @@ -46,6 +49,7 @@ public class PlanPricingController { @Operation(summary = "删除定价", description = "删除指定定价") @DeleteMapping("/delete/{id}") + @RequirePermission(value = "system:company:manage", description = "删除定价", allowSuper = true) public ApiResponse deletePlanPricing( @Parameter(description = "定价ID") @PathVariable Long id) { planPricingService.deletePlanPricing(id); @@ -54,6 +58,7 @@ public class PlanPricingController { @Operation(summary = "分页获取定价列表", description = "分页获取定价列表,支持条件过滤") @PostMapping("/page") + @RequirePermission(value = "system:company:manage", description = "查询定价列表", allowSuper = true) public ApiResponse> getPlanPricingPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = planPricingService.getPlanPricingPage(pageQueryDTO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/subscription/controller/SubscriptionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/subscription/controller/SubscriptionController.java index 7d9699e6..8dcbf9e6 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/subscription/controller/SubscriptionController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/subscription/controller/SubscriptionController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -31,6 +32,7 @@ public class SubscriptionController { @Operation(summary = "创建订阅", description = "创建新的订阅记录") @PostMapping("/create") + @RequirePermission(value = "system:company:manage", description = "创建订阅", allowSuper = true) public ApiResponse createSubscription( @Valid @RequestBody CreateSubscriptionDTO createSubscriptionDTO) { SubscriptionVO subscriptionVO = subscriptionService.createSubscription(createSubscriptionDTO); @@ -39,6 +41,7 @@ public class SubscriptionController { @Operation(summary = "更新订阅", description = "更新现有订阅信息") @PutMapping("/update/{id}") + @RequirePermission(value = "system:company:manage", description = "更新订阅", allowSuper = true) public ApiResponse updateSubscription( @Valid @RequestBody UpdateSubscriptionDTO updateSubscriptionDTO, @PathVariable Long id) { @@ -48,6 +51,7 @@ public class SubscriptionController { @Operation(summary = "删除订阅", description = "删除指定订阅") @DeleteMapping("/delete/{id}") + @RequirePermission(value = "system:company:manage", description = "删除订阅", allowSuper = true) public ApiResponse deleteSubscription( @Parameter(description = "订阅ID") @PathVariable Long id) { subscriptionService.deleteSubscription(id); @@ -56,6 +60,7 @@ public class SubscriptionController { @Operation(summary = "分页获取订阅列表", description = "分页获取订阅列表,支持条件过滤") @PostMapping("/page") + @RequirePermission(value = "system:company:manage", description = "查询订阅列表", allowSuper = true) public ApiResponse> getSubscriptionPage( @Valid @RequestBody PageQueryDTO pageQueryDTO) { PageResultVO result = subscriptionService.getSubscriptionPage(pageQueryDTO); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/controller/MenuController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/controller/MenuController.java index a211a8a2..af685065 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/controller/MenuController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/controller/MenuController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.sys.menu.model.dto.BatchSortMenuDTO; import top.xyquan.ecomdmbbackend.modules.sys.menu.model.dto.CreateMenuDTO; @@ -30,6 +31,7 @@ public class MenuController { @Operation(summary = "创建菜单", description = "创建新的菜单") @PostMapping("/create") + @RequirePermission(value = "system:menu:create", description = "创建菜单", allowSuper = true) public ApiResponse createMenu(@Valid @RequestBody CreateMenuDTO createMenuDTO) { MenuVO menuVO = menuService.createMenu(createMenuDTO); return ApiResponse.success(menuVO); @@ -37,6 +39,7 @@ public class MenuController { @Operation(summary = "更新菜单", description = "更新现有菜单信息") @PutMapping("/update/{id}") + @RequirePermission(value = "system:menu:update", description = "更新菜单", allowSuper = true) public ApiResponse updateMenu(@Valid @RequestBody UpdateMenuDTO updateMenuDTO, @PathVariable Long id) { MenuVO menuVO = menuService.updateMenu(updateMenuDTO, id); @@ -45,6 +48,7 @@ public class MenuController { @Operation(summary = "删除菜单", description = "删除指定菜单") @DeleteMapping("/delete/{id}") + @RequirePermission(value = "system:menu:delete", description = "删除菜单", allowSuper = true) public ApiResponse deleteMenu( @Parameter(description = "菜单ID") @PathVariable Long id) { menuService.deleteMenu(id); @@ -53,6 +57,7 @@ public class MenuController { @Operation(summary = "获取菜单树", description = "获取完整的菜单树结构") @GetMapping("/tree") + @RequirePermission(value = "system:menu:read", description = "获取菜单树", allowSuper = true) public ApiResponse> getMenuTree() { List menuTree = menuService.getMenuTree(); return ApiResponse.success(menuTree); @@ -60,6 +65,7 @@ public class MenuController { @Operation(summary = "获取所有菜单", description = "获取所有菜单的列表") @GetMapping("/list") + @RequirePermission(value = "system:menu:read", description = "获取所有菜单", allowSuper = true) public ApiResponse> getAllMenus() { List menuList = menuService.getAllMenus(); return ApiResponse.success(menuList); @@ -67,6 +73,7 @@ public class MenuController { @Operation(summary = "获取菜单详情", description = "根据ID获取菜单详细信息") @GetMapping("/detail/{id}") + @RequirePermission(value = "system:menu:read", description = "获取菜单详情", allowSuper = true) public ApiResponse getMenuDetail( @Parameter(description = "菜单ID") @PathVariable Long id) { MenuVO menuVO = menuService.getMenuDetail(id); @@ -75,6 +82,7 @@ public class MenuController { @Operation(summary = "批量菜单排序", description = "批量更新菜单的排序值") @PostMapping("/batch-sort") + @RequirePermission(value = "system:menu:update", description = "批量菜单排序", allowSuper = true) public ApiResponse batchSortMenu(@Valid @RequestBody BatchSortMenuDTO batchSortMenuDTO) { menuService.batchSortMenu(batchSortMenuDTO); return ApiResponse.success(); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/service/impl/UserMenuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/service/impl/UserMenuServiceImpl.java index 236aeb4a..779540f4 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/service/impl/UserMenuServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/menu/service/impl/UserMenuServiceImpl.java @@ -17,6 +17,7 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -89,11 +90,21 @@ public class UserMenuServiceImpl implements UserMenuService { // owner 角色获取公司所有菜单 menus = companyMenuService.getCompanyMenusForRoute(companyIdForUser); } else { - // member 角色根据职位获取菜单 + // member 角色根据职位获取菜单,同时需要公司有该菜单(取交集) if (member.getPositionId() == null) { menus = List.of(); } else { - menus = positionMenuService.getPositionMenusForRoute(member.getPositionId()); + // 1. 先查公司有哪些菜单 + List companyMenuIds = companyMenuService.getCompanyMenuIds(companyIdForUser); + Set companyMenuIdSet = Set.copyOf(companyMenuIds); + + // 2. 再查职位有哪些菜单 + List positionMenus = positionMenuService.getPositionMenusForRoute(member.getPositionId()); + + // 3. 取交集:职位菜单必须在公司菜单范围内 + menus = positionMenus.stream() + .filter(menu -> companyMenuIdSet.contains(menu.getId())) + .collect(Collectors.toList()); } } break; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/MenuPermissionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/MenuPermissionController.java index 5e0efce3..f6b3250a 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/MenuPermissionController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/MenuPermissionController.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.AddMenuPermissionDTO; import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.RemoveMenuPermissionDTO; @@ -27,6 +28,7 @@ public class MenuPermissionController { @Operation(summary = "添加菜单权限映射", description = "为指定菜单添加权限映射") @PostMapping("/add") + @RequirePermission(value = "system:menu:update", description = "添加菜单权限映射", allowSuper = true) public ApiResponse addMenuPermission(@Valid @RequestBody AddMenuPermissionDTO addMenuPermissionDTO) { MenuPermissionVO menuPermissionVO = menuPermissionService.addMenuPermission(addMenuPermissionDTO); return ApiResponse.success(menuPermissionVO); @@ -34,6 +36,7 @@ public class MenuPermissionController { @Operation(summary = "删除菜单权限映射", description = "删除指定菜单的权限映射") @PostMapping("/remove") + @RequirePermission(value = "system:menu:update", description = "删除菜单权限映射", allowSuper = true) public ApiResponse removeMenuPermission(@Valid @RequestBody RemoveMenuPermissionDTO removeMenuPermissionDTO) { menuPermissionService.removeMenuPermission(removeMenuPermissionDTO); return ApiResponse.success(); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/PermissionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/PermissionController.java index 727d2cd0..2de01915 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/PermissionController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/controller/PermissionController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -32,6 +33,7 @@ public class PermissionController { @Operation(summary = "创建权限", description = "创建新的权限") @PostMapping("/create") + @RequirePermission(value = "system:permission:manage", description = "创建权限", allowSuper = true) public ApiResponse createPermission(@Valid @RequestBody CreatePermissionDTO createPermissionDTO) { PermissionVO permissionVO = permissionService.createPermission(createPermissionDTO); return ApiResponse.success(permissionVO); @@ -39,6 +41,7 @@ public class PermissionController { @Operation(summary = "更新权限", description = "更新现有权限信息") @PutMapping("/update/{id}") + @RequirePermission(value = "system:permission:manage", description = "更新权限", allowSuper = true) public ApiResponse updatePermission(@Valid @RequestBody UpdatePermissionDTO updatePermissionDTO, @PathVariable Long id) { PermissionVO permissionVO = permissionService.updatePermission(updatePermissionDTO, id); @@ -47,6 +50,7 @@ public class PermissionController { @Operation(summary = "删除权限", description = "删除指定权限") @DeleteMapping("/delete/{id}") + @RequirePermission(value = "system:permission:manage", description = "删除权限", allowSuper = true) public ApiResponse deletePermission( @Parameter(description = "权限ID") @PathVariable Long id) { permissionService.deletePermission(id); @@ -55,6 +59,7 @@ public class PermissionController { @Operation(summary = "分页获取权限列表", description = "根据条件分页获取权限列表") @PostMapping("/page") + @RequirePermission(value = "system:permission:read", description = "查询权限列表", allowSuper = true) public ApiResponse> getPermissionPage( @Valid @RequestBody PageQueryDTO filterDTO) { PageResultVO pageResult = permissionService.getPermissionPage(filterDTO); @@ -63,6 +68,7 @@ public class PermissionController { @Operation(summary = "获取权限详情", description = "根据ID获取权限详细信息") @GetMapping("/detail/{id}") + @RequirePermission(value = "system:permission:read", description = "获取权限详情", allowSuper = true) public ApiResponse getPermissionDetail( @Parameter(description = "权限ID") @PathVariable Long id) { PermissionVO permissionVO = permissionService.getPermissionDetail(id); @@ -71,6 +77,7 @@ public class PermissionController { @Operation(summary = "获取所有权限", description = "获取所有启用的权限列表") @GetMapping("/list") + @RequirePermission(value = "system:permission:read", description = "获取所有权限", allowSuper = true) public ApiResponse> getAllPermissions() { List permissionList = permissionService.getAllPermissions(); return ApiResponse.success(permissionList); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/service/impl/PermissionCheckServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/service/impl/PermissionCheckServiceImpl.java index f4e213d3..1e9ad1f3 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/service/impl/PermissionCheckServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/permission/service/impl/PermissionCheckServiceImpl.java @@ -1,7 +1,9 @@ package top.xyquan.ecomdmbbackend.modules.sys.permission.service.impl; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import top.xyquan.ecomdmbbackend.modules.org.companypermission.service.CompanyPermissionService; import top.xyquan.ecomdmbbackend.modules.org.positionpermission.service.PositionPermissionService; import top.xyquan.ecomdmbbackend.modules.sys.permission.service.PermissionCheckService; @@ -10,23 +12,26 @@ import java.util.List; /** * 权限检查服务实现类 - * 直接从 org_position_permission 表查询权限码,不再通过菜单-权限链查询 + * 三级权限校验:平台(super) -> 公司(company) -> 职位(user) */ -@Service @Slf4j +@Service +@RequiredArgsConstructor public class PermissionCheckServiceImpl implements PermissionCheckService { private final PositionPermissionService positionPermissionService; - - public PermissionCheckServiceImpl(PositionPermissionService positionPermissionService) { - this.positionPermissionService = positionPermissionService; - } + private final CompanyPermissionService companyPermissionService; /** * 根据岗位ID和权限代码检查是否有权限 - * @param positionId 岗位ID + * 三级校验: + * 1. 先检查公司是否分配了该权限(org_company_permission) + * 2. 再检查岗位是否分配了该权限(org_position_permission) + * 3. 两个都要有才算有权限 + * + * @param positionId 岗位ID * @param permissionCode 权限代码 - * @param companyId 公司ID(已废弃参数,仅保留接口兼容性) + * @param companyId 公司ID * @return 是否有权限 */ @Override @@ -36,6 +41,17 @@ public class PermissionCheckServiceImpl implements PermissionCheckService { } try { + // 1. 先检查公司是否分配了该权限 + if (companyId != null) { + // 获取公司所有权限ID,然后根据权限码查找对应权限ID + List companyPermissionCodes = companyPermissionService.getCompanyPermissionCodes(companyId); + if (!companyPermissionCodes.contains(permissionCode)) { + log.debug("公司[{}]未分配权限[{}]", companyId, permissionCode); + return false; + } + } + + // 2. 再检查岗位是否分配了该权限 return positionPermissionService.hasPositionPermissionByCode(positionId, permissionCode); } catch (Exception e) { log.error("权限验证异常", e); @@ -46,7 +62,7 @@ public class PermissionCheckServiceImpl implements PermissionCheckService { /** * 获取岗位权限列表(权限码列表) * @param positionId 岗位ID - * @param companyId 公司ID(已废弃参数,仅保留接口兼容性) + * @param companyId 公司ID(已废弃参数,仅保留接口兼容性) * @return 权限码列表 */ @Override @@ -65,10 +81,10 @@ public class PermissionCheckServiceImpl implements PermissionCheckService { /** * 根据角色和权限代码检查是否有权限 - * @param role 角色 + * @param role 角色 (super/company/user) * @param permissionCode 权限代码 - * @param positionId 岗位ID - * @param companyId 公司ID + * @param positionId 岗位ID (仅user角色需要) + * @param companyId 公司ID (company角色需要) * @return 是否有权限 */ @Override diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/user/controller/UserController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/user/controller/UserController.java index 6badeeca..29bcf034 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/user/controller/UserController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/user/controller/UserController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; @@ -44,6 +45,7 @@ public class UserController { @Operation(summary = "更新用户信息", description = "更新当前登录用户的基本信息") @PutMapping("/info") + @RequirePermission(value = "system:user:update", description = "更新用户信息", allowSuper = true) public ApiResponse updateUserInfo(@Valid @RequestBody UpdateUserInfoDTO updateUserInfoDTO) { UserVO userVO = userService.updateCurrentUserInfo(updateUserInfoDTO); return ApiResponse.success(userVO); @@ -58,6 +60,7 @@ public class UserController { @Operation(summary = "上传用户头像", description = "上传用户头像图片") @PostMapping("/upload-avatar") + @RequirePermission(value = "system:user:update", description = "上传用户头像", allowSuper = true) public ApiResponse uploadAvatar(@RequestParam("file") MultipartFile file) { // 检查是否为图片文件 if (!FileUploadUtils.isImageFile(file.getOriginalFilename())) { @@ -77,6 +80,7 @@ public class UserController { @Operation(summary = "分页查询用户列表", description = "分页查询用户列表,支持多种过滤条件") @PostMapping("/page") + @RequirePermission(value = "system:user:read", description = "查询用户列表", allowSuper = true) public ApiResponse> getUserPage( @Valid @RequestBody PageQueryDTO pageQuery) { PageResultVO pageResult = userService.getUserPage(pageQuery); diff --git a/ecom-dmb-backend/src/main/resources/mapper/companypermission/CompanyPermissionMapper.xml b/ecom-dmb-backend/src/main/resources/mapper/companypermission/CompanyPermissionMapper.xml new file mode 100644 index 00000000..a332374f --- /dev/null +++ b/ecom-dmb-backend/src/main/resources/mapper/companypermission/CompanyPermissionMapper.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + +