mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
wip:岗位权限
This commit is contained in:
+19
@@ -73,4 +73,23 @@ public class CompanyMenuController {
|
||||
companyMenuService.batchDeleteCompanyMenu(id, menuIds);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取公司所有菜单ID", description = "获取指定公司的所有菜单ID列表")
|
||||
@GetMapping("/menu-ids/{id}")
|
||||
@RequireRole(description = "获取公司菜单ID", allowUser = false)
|
||||
public ApiResponse<List<Long>> getCompanyMenuIds(
|
||||
@Parameter(description = "公司ID") @PathVariable Long id) {
|
||||
List<Long> menuIds = companyMenuService.getCompanyMenuIds(id);
|
||||
return ApiResponse.success(menuIds);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量更新公司菜单", description = "批量更新公司菜单状态,新增缺失的菜单,停用多余的菜单,启用已有的菜单")
|
||||
@PostMapping("/batch-update/{id}")
|
||||
@RequireRole(description = "批量更新公司菜单", allowUser = false)
|
||||
public ApiResponse<Void> batchUpdateCompanyMenus(
|
||||
@Parameter(description = "公司ID") @PathVariable Long id,
|
||||
@Parameter(description = "菜单ID列表") @RequestBody List<Long> menuIds) {
|
||||
companyMenuService.batchUpdateCompanyMenus(id, menuIds);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -65,4 +65,21 @@ public class PositionPermissionController {
|
||||
boolean hasPermission = positionCompanyMenuService.hasPositionMenu(positionId, companyMenuId);
|
||||
return ApiResponse.success(hasPermission);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取岗位所有公司菜单ID", description = "获取指定岗位的所有公司菜单ID列表")
|
||||
@GetMapping("/company-menu-ids/{positionId}")
|
||||
public ApiResponse<List<Long>> getPositionCompanyMenuIds(
|
||||
@Parameter(description = "岗位ID") @PathVariable Long positionId) {
|
||||
List<Long> companyMenuIds = positionCompanyMenuService.getPositionCompanyMenuIds(positionId);
|
||||
return ApiResponse.success(companyMenuIds);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量更新岗位公司菜单", description = "批量更新岗位公司菜单权限,新增缺失的权限,删除多余的权限")
|
||||
@PostMapping("/batch-update/{positionId}")
|
||||
public ApiResponse<Void> batchUpdatePositionCompanyMenus(
|
||||
@Parameter(description = "岗位ID") @PathVariable Long positionId,
|
||||
@Parameter(description = "公司菜单ID列表") @RequestBody List<Long> companyMenuIds) {
|
||||
positionCompanyMenuService.batchUpdatePositionCompanyMenus(positionId, companyMenuIds);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -32,6 +32,12 @@ public class PositionCompanyMenuPO {
|
||||
@TableField("company_menu_id")
|
||||
private Long companyMenuId;
|
||||
|
||||
/**
|
||||
* 状态(0-停用,1-启用)
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+16
@@ -62,4 +62,20 @@ public interface CompanyMenuService extends IService<CompanyMenuPO> {
|
||||
*/
|
||||
List<MenuVO> getCompanyMenusForRoute(Long companyId);
|
||||
|
||||
/**
|
||||
* 获取公司所有菜单ID列表
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @return 菜单ID列表
|
||||
*/
|
||||
List<Long> getCompanyMenuIds(Long companyId);
|
||||
|
||||
/**
|
||||
* 批量更新公司菜单
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param menuIds 菜单ID列表
|
||||
*/
|
||||
void batchUpdateCompanyMenus(Long companyId, List<Long> menuIds);
|
||||
|
||||
}
|
||||
|
||||
+16
@@ -58,4 +58,20 @@ public interface PositionCompanyMenuService {
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<MenuVO> getPositionMenusForRoute(Long positionId);
|
||||
|
||||
/**
|
||||
* 获取岗位所有公司菜单ID列表
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @return 公司菜单ID列表
|
||||
*/
|
||||
List<Long> getPositionCompanyMenuIds(Long positionId);
|
||||
|
||||
/**
|
||||
* 批量更新岗位公司菜单
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @param companyMenuIds 公司菜单ID列表
|
||||
*/
|
||||
void batchUpdatePositionCompanyMenus(Long positionId, List<Long> companyMenuIds);
|
||||
}
|
||||
|
||||
+58
@@ -234,6 +234,64 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getCompanyMenuIds(Long companyId) {
|
||||
// 查询公司所有菜单(包括启用和禁用的)
|
||||
LambdaQueryWrapper<CompanyMenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMenuPO::getCompanyId, companyId);
|
||||
wrapper.eq(CompanyMenuPO::getStatus, 1);
|
||||
|
||||
List<CompanyMenuPO> companyMenus = this.list(wrapper);
|
||||
|
||||
// 返回菜单ID列表
|
||||
return companyMenus.stream()
|
||||
.map(CompanyMenuPO::getMenuId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchUpdateCompanyMenus(Long companyId, List<Long> menuIds) {
|
||||
// 查询公司现有菜单
|
||||
LambdaQueryWrapper<CompanyMenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMenuPO::getCompanyId, companyId);
|
||||
List<CompanyMenuPO> existingMenus = this.list(wrapper);
|
||||
|
||||
// 构建现有菜单ID到CompanyMenuPO的映射
|
||||
Map<Long, CompanyMenuPO> existingMenuMap = existingMenus.stream()
|
||||
.collect(Collectors.toMap(CompanyMenuPO::getMenuId, cm -> cm));
|
||||
|
||||
// 1. 处理新增的菜单(接收到的菜单ID在公司现有菜单中没有的)
|
||||
for (Long menuId : menuIds) {
|
||||
if (!existingMenuMap.containsKey(menuId)) {
|
||||
// 新增菜单
|
||||
CompanyMenuPO newCompanyMenu = new CompanyMenuPO();
|
||||
newCompanyMenu.setCompanyId(companyId);
|
||||
newCompanyMenu.setMenuId(menuId);
|
||||
newCompanyMenu.setStatus(1); // 启用状态
|
||||
this.save(newCompanyMenu);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 处理现有菜单的状态
|
||||
for (CompanyMenuPO existingMenu : existingMenus) {
|
||||
Long menuId = existingMenu.getMenuId();
|
||||
|
||||
if (menuIds.contains(menuId)) {
|
||||
// 接收到的菜单ID列表中有这个菜单,启用它
|
||||
if (existingMenu.getStatus() == 0) {
|
||||
existingMenu.setStatus(1);
|
||||
this.updateById(existingMenu);
|
||||
}
|
||||
} else {
|
||||
// 接收到的菜单ID列表中没有这个菜单,停用它
|
||||
if (existingMenu.getStatus() == 1) {
|
||||
existingMenu.setStatus(0);
|
||||
this.updateById(existingMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
|
||||
+48
@@ -280,4 +280,52 @@ public class PositionCompanyMenuServiceImpl extends ServiceImpl<PositionCompanyM
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getPositionCompanyMenuIds(Long positionId) {
|
||||
// 查询岗位菜单权限关联记录
|
||||
LambdaQueryWrapper<PositionCompanyMenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PositionCompanyMenuPO::getPositionId, positionId);
|
||||
|
||||
List<PositionCompanyMenuPO> positionMenus = this.list(wrapper);
|
||||
|
||||
// 返回公司菜单ID列表
|
||||
return positionMenus.stream()
|
||||
.map(PositionCompanyMenuPO::getCompanyMenuId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchUpdatePositionCompanyMenus(Long positionId, List<Long> companyMenuIds) {
|
||||
// 查询岗位现有菜单权限
|
||||
LambdaQueryWrapper<PositionCompanyMenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PositionCompanyMenuPO::getPositionId, positionId);
|
||||
List<PositionCompanyMenuPO> existingMenus = this.list(wrapper);
|
||||
|
||||
// 构建现有公司菜单ID到PositionCompanyMenuPO的映射
|
||||
Map<Long, PositionCompanyMenuPO> existingMenuMap = existingMenus.stream()
|
||||
.collect(Collectors.toMap(PositionCompanyMenuPO::getCompanyMenuId, pm -> pm));
|
||||
|
||||
// 1. 处理新增的菜单权限(接收到的公司菜单ID在岗位现有菜单权限中没有的)
|
||||
for (Long companyMenuId : companyMenuIds) {
|
||||
if (!existingMenuMap.containsKey(companyMenuId)) {
|
||||
// 新增菜单权限
|
||||
PositionCompanyMenuPO newPositionMenu = new PositionCompanyMenuPO();
|
||||
newPositionMenu.setPositionId(positionId);
|
||||
newPositionMenu.setCompanyMenuId(companyMenuId);
|
||||
this.save(newPositionMenu);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 处理现有菜单权限的删除(岗位现有菜单权限中有但接收列表中没有的)
|
||||
for (PositionCompanyMenuPO existingMenu : existingMenus) {
|
||||
Long companyMenuId = existingMenu.getCompanyMenuId();
|
||||
|
||||
if (!companyMenuIds.contains(companyMenuId)) {
|
||||
// 接收到的公司菜单ID列表中没有这个菜单权限,删除它
|
||||
this.removeById(existingMenu.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ CREATE TABLE `org_position_company_menu_map` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`position_id` bigint unsigned NOT NULL COMMENT '岗位ID',
|
||||
`company_menu_id` bigint unsigned NOT NULL COMMENT '公司菜单权限ID',
|
||||
`status` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '状态(0-停用,1-启用)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`create_by` bigint unsigned NOT NULL COMMENT '创建人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
|
||||
Reference in New Issue
Block a user