Browse Source

新增基础功能授权(未完全),其他优化20241120

kitchenmanage
gwbvipvip 1 month ago
parent
commit
0f2cff96fd
10 changed files with 196 additions and 1 deletions
  1. +3
    -1
      BPA.SAAS.Manage.Application/DataBase/Services/GoodsClassifyService.cs
  2. +13
    -0
      BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleMenuDtoInput.cs
  3. +3
    -0
      BPA.SAAS.Manage.Application/Org/Interface/IRoleService.cs
  4. +28
    -0
      BPA.SAAS.Manage.Application/Org/RolesServices.cs
  5. +68
    -0
      BPA.SAAS.Manage.Application/Org/Services/RoleService.cs
  6. +1
    -0
      BPA.SAAS.Manage.Application/System/Interface/IMenuService.cs
  7. +9
    -0
      BPA.SAAS.Manage.Application/System/MenuServices.cs
  8. +18
    -0
      BPA.SAAS.Manage.Application/System/Services/MenuService.cs
  9. +35
    -0
      BPA.SAAS.Manage.Core/System/BPA_BasicMenu.cs
  10. +18
    -0
      BPA.SAAS.Manage.Core/System/BPA_RoleBasicMenu.cs

+ 3
- 1
BPA.SAAS.Manage.Application/DataBase/Services/GoodsClassifyService.cs View File

@@ -124,7 +124,9 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services
/// <returns></returns>
public async Task<List<RelationGoodsIdDto>> GetRelation(string classifyId)
{
var result = await _db.Queryable<BPA_GoodsClassifyRelation>().Where(t => t.ClassifyId == classifyId)
var result = await _db.Queryable<BPA_GoodsClassifyRelation>().LeftJoin<BPA_GoodsInfo>((a, b) => a.GoodsId == b.Id)
.Where((a, b) => a.ClassifyId == classifyId)
.OrderByDescending((a, b) => b.CreateAt)
.Select(a => new RelationGoodsIdDto
{
GoodsId = a.GoodsId,


+ 13
- 0
BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleMenuDtoInput.cs View File

@@ -18,4 +18,17 @@ namespace BPA.SAAS.Manage.Application.Org.Dtos.Role
/// </summary>
public List<string> SysMenuId { get; set; }
}

public class RoleBasicMenuDtoInput
{
/// <summary>
/// 角色Id
/// </summary>
public string SysRoleId { get; set; }

/// <summary>
/// 功能菜单Id
/// </summary>
public List<string> SysBasicMenuId { get; set; }
}
}

+ 3
- 0
BPA.SAAS.Manage.Application/Org/Interface/IRoleService.cs View File

@@ -19,5 +19,8 @@ namespace BPA.SAAS.Manage.Application.Org.Interface
Task<bool> Disable(string Id);
Task<bool> Enable(string Id);
Task<Dictionary<string, object>> GetRole();
Task<List<QueryRoleMenuListDto>> GetBasicMenuRole(string roleId);
Task<bool> UpdateBasicMenuRole(RoleBasicMenuDtoInput input);
Task<List<string>> GetRoleBasicMenu();
}
}

+ 28
- 0
BPA.SAAS.Manage.Application/Org/RolesServices.cs View File

@@ -106,5 +106,33 @@ namespace BPA.SAAS.Manage.Application.Org
{
return await _roleService.GetRole();
}
/// <summary>
/// 根据角色查询角色基础功能菜单
/// </summary>
/// <returns></returns>
[HttpGet("/api/roles/getBasicMenuRole")]
public async Task<List<QueryRoleMenuListDto>> GetBasicMenuRole(string roleId)
{
return await _roleService.GetBasicMenuRole(roleId);
}
/// <summary>
/// 更新角色基础功能菜单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/roles/updateBasicMenuRole")]
public async Task<bool> UpdateBasicMenuRole(RoleBasicMenuDtoInput input)
{
return await _roleService.UpdateBasicMenuRole(input);
}
/// <summary>
/// 获取用户基础功能权限编码列表
/// </summary>
/// <returns></returns>
[HttpGet("/api/roles/getRoleBasicMenu")]
public async Task<List<string>> GetRoleBasicMenu()
{
return await _roleService.GetRoleBasicMenu();
}
}
}

+ 68
- 0
BPA.SAAS.Manage.Application/Org/Services/RoleService.cs View File

@@ -232,5 +232,73 @@ namespace BPA.SAAS.Manage.Application.Org.Services
var str = string.Format("{0}", ram.ToString().Substring(0, Length));
return str;
}

public async Task<List<QueryRoleMenuListDto>> GetBasicMenuRole(string roleId)
{
return await _db.Queryable<BPA_RoleBasicMenu>().LeftJoin<BPA_BasicMenu>((t, x) => t.SysBasicMenuId == x.Id)
.Where(t => t.SysRoleId == roleId).OrderBy((t, x) => x.CreateAt).Select((t, x) => new QueryRoleMenuListDto()
{
Id = x.Id,
Name = x.Name,
IsParentMenu = string.IsNullOrWhiteSpace(x.Pid)
}).ToListAsync();
}

public async Task<bool> UpdateBasicMenuRole(RoleBasicMenuDtoInput input)
{
var models = new List<BPA_RoleBasicMenu>();
var newMenuIds = new List<string>();
_db.Deleteable<BPA_RoleBasicMenu>(t => t.SysRoleId == input.SysRoleId).ExecuteCommandHasChange();
if (input.SysBasicMenuId != null)
{
var basicMenus = await _db.Queryable<BPA_BasicMenu>().ToListAsync();
foreach (var item in input.SysBasicMenuId)
{
var pid = basicMenus.FirstOrDefault(t => t.Id == item).Pid;
if (pid != null && pid != "")
{
var pid2 = basicMenus.FirstOrDefault(t => t.Id == pid).Pid;
if (pid2 != null)
{
newMenuIds.Add(pid2);
}
newMenuIds.Add(pid);
}
newMenuIds.Add(item);
}
newMenuIds.Distinct().ToList().ForEach(item =>
{
models.Add(new BPA_RoleBasicMenu
{
Id = Guid.NewGuid().ToString(),
SysBasicMenuId = item,
SysRoleId = input.SysRoleId
});
});
}
if (models.Count <= 0)
return true;
return await _db.Insertable(models).ExecuteCommandAsync() > 0;
}

/// <summary>
/// 获取用户基础功能权限编码列表
/// </summary>
/// <returns></returns>
public async Task<List<string>> GetRoleBasicMenu()
{
var result = new List<string>();
var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
var sysRoleIdList = await _db.Queryable<BPA_UserRole>().Where(t => t.SysUserId == userId).Select(a => a.SysRoleId).ToListAsync();
var roleBasicMenuIdList = await _db.Queryable<BPA_RoleBasicMenu>().Where(t => sysRoleIdList.Contains(t.SysRoleId)).Select(a => a.SysBasicMenuId).Distinct().ToListAsync();
var basicMenuList = await _db.Queryable<BPA_BasicMenu>().ToListAsync();
foreach (var id in roleBasicMenuIdList)
{
var menuCode = basicMenuList.FirstOrDefault(t => t.Id == id)?.Code;
if (menuCode != null)
result.Add(menuCode);
}
return result;
}
}
}

+ 1
- 0
BPA.SAAS.Manage.Application/System/Interface/IMenuService.cs View File

@@ -19,5 +19,6 @@ namespace BPA.SAAS.Manage.Application.System.Interface
Task<List<MenuRouteDtoOutput>> DymicMenuTree(int type);
Task<bool> Enable(string Id);
Task<bool> Disable(string Id);
Task<List<MenuTreeOutput>> BasicMenuTree();
}
}

+ 9
- 0
BPA.SAAS.Manage.Application/System/MenuServices.cs View File

@@ -87,5 +87,14 @@ namespace BPA.SAAS.Manage.Application.System
{
return await _menuService.Disable(Id);
}
/// <summary>
/// 获取基础功能树
/// </summary>
/// <returns></returns>
[HttpGet("/api/menu/basicMenuTree")]
public async Task<List<MenuTreeOutput>> BasicMenuTree()
{
return await _menuService.BasicMenuTree();
}
}
}

+ 18
- 0
BPA.SAAS.Manage.Application/System/Services/MenuService.cs View File

@@ -330,6 +330,24 @@ namespace BPA.SAAS.Manage.Application.System.Services
}

}

public async Task<List<MenuTreeOutput>> BasicMenuTree()
{
var allMenus = await _db.Queryable<BPA_BasicMenu>().OrderBy(t => t.Sort).ToListAsync();
List<MenuTreeOutput> buildMenuTree(string parentId)
{
return allMenus.Where(t => t.Pid == parentId)
.Select(t => new MenuTreeOutput
{
Key = t.Id,
Title = t.Name,
value = t.Id,
Children = buildMenuTree(t.Id)
}).ToList();
}
return buildMenuTree(null);
}

public async Task<List<MenuTreeOutput>> MenuTree()
{
var AllMenus = _db.Queryable<BPA_Menu>().OrderBy(t => t.Sort).ToList();


+ 35
- 0
BPA.SAAS.Manage.Core/System/BPA_BasicMenu.cs View File

@@ -0,0 +1,35 @@
using BPA.SAAS.Manage.Core.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Core.System
{
/// <summary>
/// 基础功能菜单表
/// </summary>
public class BPA_BasicMenu
{
public string Id { get; set; }
/// <summary>
/// 父级Id
/// </summary>
public string Pid { get; set; }
/// <summary>
/// 菜单名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 菜单编码 唯一
/// </summary>
public string Code { get; set; }
/// <summary>
/// 排序
/// </summary>
public int Sort { get; set; }
public DateTime CreateAt { get; set; }
public string CreateBy { get; set; }
}
}

+ 18
- 0
BPA.SAAS.Manage.Core/System/BPA_RoleBasicMenu.cs View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.Manage.Core.System
{
/// <summary>
/// 角色基础功能关系表
/// </summary>
public class BPA_RoleBasicMenu
{
public string Id { get; set; }
public string SysRoleId { get; set; }
public string SysBasicMenuId { get; set; }
}
}

Loading…
Cancel
Save