mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
处理权限
This commit is contained in:
+1
-1
@@ -82,7 +82,7 @@ public class DataSourceController {
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得系统数据源列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:data-source:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:data-source:query')")
|
||||
public CommonResult<List<DataSourceRespVO>> list( ) {
|
||||
return success(dataSourceService.list());
|
||||
|
||||
|
||||
+8
-8
@@ -37,7 +37,7 @@ public class LabelController {
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建标签")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:create')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:create')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<Long> createLabel(@Valid @RequestBody LabelSaveReqVO createReqVO) {
|
||||
return success(labelService.createLabel(createReqVO));
|
||||
@@ -45,7 +45,7 @@ public class LabelController {
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新标签")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:update')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:update')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<Boolean> updateLabel(@Valid @RequestBody LabelSaveReqVO updateReqVO) {
|
||||
labelService.updateLabel(updateReqVO);
|
||||
@@ -55,7 +55,7 @@ public class LabelController {
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除标签")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:label:delete')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:delete')")
|
||||
public CommonResult<Boolean> deleteLabel(@RequestParam("id") Long id) {
|
||||
labelService.deleteLabel(id);
|
||||
return success(true);
|
||||
@@ -64,7 +64,7 @@ public class LabelController {
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得标签")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<LabelRespVO> getLabel(@RequestParam("id") Long id) {
|
||||
return success(labelService.getLabel(id));
|
||||
@@ -72,7 +72,7 @@ public class LabelController {
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得标签分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<PageResult<LabelRespVO>> getLabelPage(@Valid LabelPageReqVO pageReqVO) {
|
||||
PageResult<LabelDO> pageResult = labelService.getLabelPage(pageReqVO);
|
||||
@@ -82,7 +82,7 @@ public class LabelController {
|
||||
@GetMapping("list")
|
||||
@Operation(summary = "获得标签列表")
|
||||
@Parameter(name = "type", description = "类型", required = false, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<List<LabelRespVO>> getList(@RequestParam("type") String type) {
|
||||
return success(BeanUtils.toBean(labelService.list(type), LabelRespVO.class));
|
||||
@@ -90,7 +90,7 @@ public class LabelController {
|
||||
|
||||
@GetMapping("/group-list")
|
||||
@Operation(summary = "获得分组标签列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:query')")
|
||||
@OperateLog(enable = false)
|
||||
public CommonResult<Map<String, List<LabelRespVO>>> getGroupList(@RequestParam(value = "organId", required = false) Long organId) {
|
||||
return success(labelService.getGroupList(organId));
|
||||
@@ -98,7 +98,7 @@ public class LabelController {
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出标签 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:label:export')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:label:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportLabelExcel(@Valid LabelPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
|
||||
+8
-8
@@ -39,7 +39,7 @@ public class MachineController {
|
||||
|
||||
@PutMapping("/create-cutting")
|
||||
@Operation(summary = "创建机台")
|
||||
@PreAuthorize("@ss.hasPermission('machine::create')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::create')")
|
||||
@OperateLog(logArgs = false)
|
||||
public CommonResult<Long> createCutting(@Validated(CreateGroup.class) @RequestBody CuttingSaveReqVO createReqVO) {
|
||||
return success(machineService.createCutting(createReqVO));
|
||||
@@ -47,7 +47,7 @@ public class MachineController {
|
||||
|
||||
@PostMapping("/update-cutting")
|
||||
@Operation(summary = "更新机台")
|
||||
@PreAuthorize("@ss.hasPermission('machine::update')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::update')")
|
||||
@OperateLog(logArgs = false)
|
||||
public CommonResult<Boolean> update(@Validated(UpdateGroup.class) @RequestBody CuttingSaveReqVO updateReqVO) {
|
||||
machineService.updateCutting(updateReqVO);
|
||||
@@ -57,7 +57,7 @@ public class MachineController {
|
||||
@DeleteMapping("/delete-cutting")
|
||||
@Operation(summary = "删除机台")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('machine::delete')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::delete')")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
|
||||
machineService.deleteCutting(id);
|
||||
return success(true);
|
||||
@@ -66,7 +66,7 @@ public class MachineController {
|
||||
@DeleteMapping("/batch-delete-cutting")
|
||||
@Operation(summary = "批量删除机台")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('machine::delete')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::delete')")
|
||||
public CommonResult<Boolean> batchDeleteCutting(@RequestParam("ids") List<Long> ids) {
|
||||
machineService.batchDeleteCutting(ids);
|
||||
return success(true);
|
||||
@@ -75,7 +75,7 @@ public class MachineController {
|
||||
@GetMapping("/get-cutting")
|
||||
@Operation(summary = "获得机台")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
public CommonResult<CuttingRespVO> get(@RequestParam("id") Long id) {
|
||||
CuttingRespVO respVO = machineService.getCutting(id);
|
||||
return success(respVO);
|
||||
@@ -83,7 +83,7 @@ public class MachineController {
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得机台分页")
|
||||
@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
public CommonResult<PageResult<CuttingRespVO>> getPage(@Valid MachinePageReqVO pageReqVO) {
|
||||
PageResult<MachineDO> pageResult = machineService.getPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, CuttingRespVO.class));
|
||||
@@ -92,7 +92,7 @@ public class MachineController {
|
||||
@GetMapping("getDefaultCutting")
|
||||
@Operation(summary = "获得默认机台模板")
|
||||
@Parameter(name = "machineType", description = "机台类型", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
public CommonResult<CuttingTemplateRespVO> getDefaultCutting(@RequestParam Integer machineType) {
|
||||
return success(machineTemplateService.getDefaultCutting(machineType));
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class MachineController {
|
||||
|
||||
@GetMapping("getMachineTree")
|
||||
@Operation(summary = "获得机台树")
|
||||
@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
//@PreAuthorize("@ss.hasPermission('machine::query')")
|
||||
public CommonResult<Map<Integer, List<MachineVO>>> getMachineTree(@RequestParam(required = false) Long organId) {
|
||||
return success(machineService.getMachineTree(organId));
|
||||
}
|
||||
|
||||
+45
-5
@@ -1,14 +1,23 @@
|
||||
package com.cf.imes.module.system.controller.admin.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO;
|
||||
import com.cf.imes.module.system.convert.auth.AuthConvert;
|
||||
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.permission.RoleDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import com.cf.imes.module.system.service.permission.MenuService;
|
||||
import com.cf.imes.module.system.service.permission.PermissionService;
|
||||
import com.cf.imes.module.system.service.permission.RoleService;
|
||||
import com.cf.imes.module.system.service.user.AdminUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -18,10 +27,12 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "管理后台 - 菜单")
|
||||
@RestController
|
||||
@@ -32,6 +43,15 @@ public class MenuController {
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建菜单")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:create')")
|
||||
@@ -59,9 +79,29 @@ public class MenuController {
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) {
|
||||
List<MenuDO> list = menuService.getMenuList(reqVO);
|
||||
List <MenuDO> list = null;
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if(loginUser.getIsSupAdmin()) {
|
||||
list = menuService.getMenuList(reqVO);
|
||||
}else {
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
if (user == null) {
|
||||
return success(new ArrayList<>());
|
||||
}
|
||||
Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(getLoginUserId());
|
||||
if (CollUtil.isEmpty(roleIds)) {
|
||||
return success(new ArrayList<>());
|
||||
}
|
||||
//List<RoleDO> roles = roleService.getRoleList(roleIds);
|
||||
List<RoleDO> roles = roleService.getRoleList1(roleIds);
|
||||
roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色
|
||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId2(convertSet(roles, RoleDO::getId));
|
||||
//List<MenuDO> menuList = menuService.getMenuList(menuIds);
|
||||
list = menuService.getMenuList1(menuIds);
|
||||
list.removeIf(menu -> !CommonStatusEnum.ENABLE.getStatus().equals(menu.getStatus())); // 移除禁用的菜单
|
||||
}
|
||||
list.sort(Comparator.comparing(MenuDO::getSort));
|
||||
return success(BeanUtils.toBean(list, MenuRespVO.class));
|
||||
}
|
||||
@@ -78,7 +118,7 @@ public class MenuController {
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获取菜单信息")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
//@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
public CommonResult<MenuRespVO> getMenu(Long id) {
|
||||
MenuDO menu = menuService.getMenu(id);
|
||||
return success(BeanUtils.toBean(menu, MenuRespVO.class));
|
||||
|
||||
+15
-3
@@ -1,8 +1,11 @@
|
||||
package com.cf.imes.module.system.controller.admin.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleDataScopeReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleMenuReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignUserRoleReqVO;
|
||||
@@ -18,9 +21,12 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_ADMIN_ROLE_ID;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_STAFF_ROLE_ID;
|
||||
|
||||
/**
|
||||
* 权限 Controller,提供赋予用户、角色的权限的 API 接口
|
||||
@@ -49,9 +55,15 @@ public class PermissionController {
|
||||
@Operation(summary = "赋予角色菜单")
|
||||
@PreAuthorize("@ss.hasPermission('system:permission:assign-role-menu')")
|
||||
public CommonResult<Boolean> assignRoleMenu(@Validated @RequestBody PermissionAssignRoleMenuReqVO reqVO) {
|
||||
// 开启多组织的情况下,需要过滤掉未开通的菜单
|
||||
organService.handleOrganMenu(menuIds -> reqVO.getMenuIds().removeIf(menuId -> !CollUtil.contains(menuIds, menuId)));
|
||||
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
if(!loginUser.getIsSupAdmin() && ( Objects.equals(reqVO.getRoleId(), ORGAN_ADMIN_ROLE_ID) || Objects.equals(reqVO.getRoleId(), ORGAN_STAFF_ROLE_ID))) {
|
||||
throw new ServiceException(11541, "内置角色无法修改");
|
||||
}
|
||||
if(Objects.equals(reqVO.getRoleId(), ORGAN_ADMIN_ROLE_ID) || Objects.equals(reqVO.getRoleId(), ORGAN_STAFF_ROLE_ID)) {
|
||||
} else {
|
||||
// 开启多组织的情况下,需要过滤掉未开通的菜单
|
||||
organService.handleOrganMenu(menuIds -> reqVO.getMenuIds().removeIf(menuId -> !CollUtil.contains(menuIds, menuId)));
|
||||
}
|
||||
// 执行菜单的分配
|
||||
permissionService.assignRoleMenu(reqVO.getRoleId(), reqVO.getMenuIds());
|
||||
return success(true);
|
||||
|
||||
+7
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.module.system.controller.admin.permission;
|
||||
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.pojo.PageParam;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
@@ -34,6 +35,8 @@ import java.util.Objects;
|
||||
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_ADMIN_ROLE_ID;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_STAFF_ROLE_ID;
|
||||
import static java.util.Collections.singleton;
|
||||
|
||||
@Tag(name = "管理后台 - 角色")
|
||||
@@ -60,6 +63,10 @@ public class RoleController {
|
||||
@Operation(summary = "修改角色")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:update')")
|
||||
public CommonResult<Boolean> updateRole(@Valid @RequestBody RoleSaveReqVO updateReqVO) {
|
||||
if(Objects.equals(updateReqVO.getId(), ORGAN_ADMIN_ROLE_ID) || Objects.equals(updateReqVO.getId(), ORGAN_STAFF_ROLE_ID)) {
|
||||
throw new ServiceException(11541, "内置角色无法修改");
|
||||
}
|
||||
|
||||
if(Objects.isNull(updateReqVO.getOrganId())) {
|
||||
updateReqVO.setOrganId(OrganContextHolder.getOrganId());
|
||||
}
|
||||
|
||||
+12
@@ -1,6 +1,9 @@
|
||||
package com.cf.imes.module.system.dal.mysql.permission;
|
||||
|
||||
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.module.system.dal.dataobject.permission.RoleMenuDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -8,6 +11,9 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_ADMIN_ROLE_ID;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_STAFF_ROLE_ID;
|
||||
|
||||
@Mapper
|
||||
public interface RoleMenuMapper extends BaseMapperX<RoleMenuDO> {
|
||||
|
||||
@@ -37,4 +43,10 @@ public interface RoleMenuMapper extends BaseMapperX<RoleMenuDO> {
|
||||
delete(new LambdaQueryWrapper<RoleMenuDO>().eq(RoleMenuDO::getRoleId, roleId));
|
||||
}
|
||||
|
||||
@OrganIgnore
|
||||
default List<RoleMenuDO> selectListByRoleIdWithOrganAdmin(Collection<Long> roleIds){
|
||||
return selectList(new LambdaQueryWrapperX<RoleMenuDO>()
|
||||
.eq(RoleMenuDO::getOrganId, 0)
|
||||
.in(RoleMenuDO::getRoleId, roleIds));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -337,11 +337,14 @@ public class OrganServiceImpl implements OrganService {
|
||||
// 获得组织,然后获得菜单
|
||||
OrganizationDO tenant = getOrgan(OrganContextHolder.getRequiredOrganId());
|
||||
Set<Long> menuIds;
|
||||
if (isSystemTenant(tenant)) { // 系统组织,菜单是全量的
|
||||
|
||||
menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds();
|
||||
|
||||
/* if (isSystemTenant(tenant)) { // 系统组织,菜单是全量的
|
||||
menuIds = CollectionUtils.convertSet(menuService.getMenuList(), MenuDO::getId);
|
||||
} else {
|
||||
menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds();
|
||||
}
|
||||
}*/
|
||||
// 执行处理器
|
||||
handler.handle(menuIds);
|
||||
}
|
||||
|
||||
+23
-4
@@ -36,10 +36,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static com.cf.imes.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_ADMIN_ROLE_ID;
|
||||
import static com.cf.imes.module.system.service.organ.OrganServiceImpl.ORGAN_STAFF_ROLE_ID;
|
||||
|
||||
/**
|
||||
* 权限 Service 实现类
|
||||
@@ -142,19 +145,29 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
allEntries = true) // allEntries 清空所有缓存,主要一次更新涉及到的 menuIds 较多,反倒批量会更快
|
||||
public void assignRoleMenu(Long roleId, Set<Long> menuIds) {
|
||||
// 获得角色拥有菜单编号
|
||||
Set<Long> dbMenuIds = convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId);
|
||||
Set<Long> dbMenuIds = null;
|
||||
if (Objects.equals(roleId, ORGAN_ADMIN_ROLE_ID) || Objects.equals(roleId, ORGAN_STAFF_ROLE_ID)) {
|
||||
dbMenuIds = convertSet(roleMenuMapper.selectListByRoleIdWithOrganAdmin(List.of(roleId)), RoleMenuDO::getMenuId);
|
||||
}else {
|
||||
dbMenuIds = convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId);
|
||||
}
|
||||
|
||||
// 计算新增和删除的菜单编号
|
||||
Set<Long> menuIdList = CollUtil.emptyIfNull(menuIds);
|
||||
Collection<Long> createMenuIds = CollUtil.subtract(menuIdList, dbMenuIds);
|
||||
Collection<Long> deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIdList);
|
||||
// 执行新增和删除。对于已经授权的菜单,不用做任何处理
|
||||
if (CollUtil.isNotEmpty(createMenuIds)) {
|
||||
roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, menuId -> {
|
||||
Function<Long, RoleMenuDO> longRoleMenuDOFunction = menuId -> {
|
||||
RoleMenuDO entity = new RoleMenuDO();
|
||||
entity.setRoleId(roleId);
|
||||
entity.setMenuId(menuId);
|
||||
if (Objects.equals(roleId, ORGAN_ADMIN_ROLE_ID) || Objects.equals(roleId, ORGAN_STAFF_ROLE_ID)) {
|
||||
entity.setOrganId(0L);
|
||||
}
|
||||
return entity;
|
||||
}));
|
||||
};
|
||||
roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, longRoleMenuDOFunction));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(deleteMenuIds)) {
|
||||
roleMenuMapper.deleteListByRoleIdAndMenuIds(roleId, deleteMenuIds);
|
||||
@@ -193,10 +206,16 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
return convertSet(menuService.getMenuList(), MenuDO::getId);
|
||||
}
|
||||
// 如果是非管理员的情况下,获得拥有的菜单编号
|
||||
List<RoleMenuDO> from = roleMenuMapper.selectListByRoleId(roleIds);
|
||||
List<RoleMenuDO> from = null;
|
||||
if(roleIds.contains(ORGAN_ADMIN_ROLE_ID) || roleIds.contains(ORGAN_STAFF_ROLE_ID)) {
|
||||
from = roleMenuMapper.selectListByRoleIdWithOrganAdmin(roleIds);
|
||||
}else {
|
||||
from = roleMenuMapper.selectListByRoleId(roleIds);
|
||||
}
|
||||
return convertSet(from, RoleMenuDO::getMenuId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public Set<Long> getRoleMenuListByRoleId2(Set<Long> roleIds) {
|
||||
|
||||
@@ -186,6 +186,7 @@ chenfeng:
|
||||
- system_label_element_template
|
||||
- system_data_source
|
||||
- system_notify_message
|
||||
- system_data_source_field
|
||||
use-data-code: imes_prod #动态数据源标识,后期添加的数据源需要修改此值
|
||||
|
||||
sms-code: # 短信验证码相关的配置项
|
||||
|
||||
Reference in New Issue
Block a user