async Task <(IList <EmployeeMenuRequestDto>, IList <EmployeeMenuRequestDto>)> GetAddOrRemoveEmployeeMenuAction(EmployeeMenuRequestDto employeeMenuRequestDto)
        {
            //查询该机构所有菜单
            var allExitsMenu = await _employeeMenuAppService.GetMenuByEmployeeIdAsync(employeeMenuRequestDto.EmployeeId);

            var allExitsMenuIds = allExitsMenu.Select(m => m.MenuId).ToList();

            var addMenuIds = employeeMenuRequestDto.MenuIds.Except(allExitsMenuIds);
            var delMenuIds = allExitsMenuIds.Except(employeeMenuRequestDto.MenuIds);

            var removeEmpMenu = allExitsMenu.Where(e => delMenuIds.Contains(e.MenuId));
            var addDto        = addMenuIds.Select(m => new EmployeeMenuRequestDto
            {
                Id             = Guid.NewGuid().ToString(),
                MenuId         = m,
                EmployeeId     = employeeMenuRequestDto.EmployeeId,
                CreateUserId   = employeeMenuRequestDto.CreateUserId,
                CreateUserName = employeeMenuRequestDto.CreateUserName,
            }).ToList();
            var delDto = delMenuIds.Select(m =>
                                           new EmployeeMenuRequestDto
            {
                MenuId         = m,
                EmployeeId     = employeeMenuRequestDto.EmployeeId,
                IsDelete       = true,
                ModifyUserId   = employeeMenuRequestDto.ModifyUserId,
                ModifyUserName = employeeMenuRequestDto.ModifyUserName,
                ModifyDate     = DateTime.Now
            });

            return(addDto.ToList(), delDto.ToList());
        }
Exemple #2
0
        private async Task <IList <PowerSelectViewResponse> > GetEmployeeMenuAsync(string employeeId)
        {
            var employeeMenuDtos = await _employeeMenuAppService.GetMenuByEmployeeIdAsync(employeeId);

            // return employeeMenuDtos.Select(o => new PowerSelectViewResponse { Id = o.MenuId }).ToList();
            var empMenuIds = employeeMenuDtos.Select(e => e.MenuId).ToList();
            //1.查询该人员所在机构下所拥有的菜单权限
            var relationOrgEmpViews = await _relationOrganizationEmployeeAppService.GetOrgIdsByEmployeeIds(new List <string> {
                employeeId
            });

            var orgIds       = relationOrgEmpViews.Select(r => r.OrganizationId).ToList();
            var orgMenuViews = await _organizationMenuAppService.GetMenuByOrgIdsAsync(orgIds);

            var orgMenuIds = orgMenuViews.Select(o => o.MenuId).ToList();

            //2.查询该人员所在角色下所拥有的的菜单权限
            var relationRoleEmpViews = await _relationEmployeeRoleAppService.GetRoleIdsByEmployeeIds(new List <string> {
                employeeId
            });

            var roleIds       = relationRoleEmpViews.Select(r => r.RoleId).ToList();
            var roleMenuViews = await _roleMenuAppService.GetMenuByRoleIdsAsync(roleIds);

            var roleMenuIds = roleMenuViews.Select(r => r.MenuId).ToList();


            //3.移除个人菜单中与机构、角色重复的
            empMenuIds.RemoveAll(e => orgMenuIds.Contains(e));
            empMenuIds.RemoveAll(e => roleMenuIds.Contains(e));

            //4.继承自机构的菜单权限,标记为禁止取消
            var powerSelectOrg = orgMenuIds.Select(o => new PowerSelectViewResponse {
                Id = o, Disabled = true
            });
            //5.继承自角色的菜单权限,标记为禁止取消
            var powerSelectRole = roleMenuIds.Select(r => new PowerSelectViewResponse {
                Id = r, Disabled = true
            });

            var powerSelectEmp = empMenuIds.Select(e => new PowerSelectViewResponse {
                Id = e
            });

            return(powerSelectOrg.Concat(powerSelectRole).Concat(powerSelectEmp).ToList());
        }