Browse Source

菜单

storemanagement
zhaoy 11 months ago
parent
commit
b27e86cbbf
1 changed files with 78 additions and 53 deletions
  1. +78
    -53
      BPA.SAAS.Manage.Application/System/Services/MenuService.cs

+ 78
- 53
BPA.SAAS.Manage.Application/System/Services/MenuService.cs View File

@@ -6,7 +6,7 @@ using BPA.SAAS.Manage.Core.Org;
using BPA.SAAS.Manage.Core.System;
using Furion.LinqBuilder;
using Mapster.Utils;
using StackExchange.Profiling.Internal;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -32,7 +32,7 @@ namespace BPA.SAAS.Manage.Application.System.Services
if (App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value == null)
return null;

var AllMenus = await _db.Queryable<BPA_Menu>().OrderBy(t => t.Sort).ToListAsync();
var AllMenus =await _db.Queryable<BPA_Menu>().OrderBy(t => t.Sort).ToListAsync();

var query = AllMenus.Where(t => t.Pid == "" || t.Pid == null);

@@ -53,7 +53,7 @@ namespace BPA.SAAS.Manage.Application.System.Services
Sort = t.Sort,
Component = t.Component,
Status = t.Status,
IsAdmin = t.IsAdmin,
IsAdmin=t.IsAdmin,
Children = AllMenus.Where(x => x.Pid == t.Id).Select(x => new MenuTreeDtoOutput
{
Id = x.Id,
@@ -66,7 +66,7 @@ namespace BPA.SAAS.Manage.Application.System.Services
Sort = x.Sort,
Component = x.Component,
Status = x.Status,
IsAdmin = x.IsAdmin,
IsAdmin=x.IsAdmin,
Children = AllMenus.Where(y => y.Pid == x.Id).Select(y => new MenuTreeDtoOutput
{
Id = y.Id.ToString(),
@@ -79,7 +79,7 @@ namespace BPA.SAAS.Manage.Application.System.Services
Sort = y.Sort,
Component = y.Component,
Status = y.Status,
IsAdmin = y.IsAdmin,
IsAdmin=y.IsAdmin
}).ToList()
}).ToList()
}).ToList();
@@ -103,7 +103,7 @@ namespace BPA.SAAS.Manage.Application.System.Services
throw Oops.Oh("菜单名称过长");
}
var menu = input.Adapt<BPA_Menu>();
return await _db.Insertable(menu).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0;
return await _db.Insertable(menu).CallEntityMethod(t => t.Create()).ExecuteCommandAsync()> 0;
}

/// <summary>
@@ -113,18 +113,18 @@ namespace BPA.SAAS.Manage.Application.System.Services
/// <returns></returns>
public async Task<bool> Update(MenuDtoInput input)
{
var menu = await _db.Queryable<BPA_Menu>().Where(x => x.Id == input.Id).FirstAsync();
var menu = await _db.Queryable< BPA_Menu >().Where(x=>x.Id== input.Id).FirstAsync();
//menu = input.Adapt<BPA_Menu>();
menu.Code = input.Code;
menu.Component = input.Component;
menu.Name = input.Name;
menu.Pid = input.Pid;
menu.Name= input.Name;
menu.Pid= input.Pid;
menu.Router = input.Router;
menu.Remark = input.Remark;
menu.Remark= input.Remark;
menu.Sort = input.Sort;
menu.Icon = input.Icon;
menu.IsAdmin = input.IsAdmin;
return await _db.Updateable(menu).ExecuteCommandAsync() > 0;
menu.IsAdmin= input.IsAdmin;
return await _db.Updateable(menu).ExecuteCommandAsync()>0;
}

/// <summary>
@@ -143,9 +143,9 @@ namespace BPA.SAAS.Manage.Application.System.Services
{
x.IsDeleted = 1;
});
var res = await _db.Updateable(resEntitites).ExecuteCommandAsync();
var res =await _db.Updateable(resEntitites).ExecuteCommandAsync();
_db.Ado.CommitTran();
return res > 0;
return res>0;
}
catch (Exception)
{
@@ -153,11 +153,11 @@ namespace BPA.SAAS.Manage.Application.System.Services
return false;
}
}
/// <summary>
/// 查询菜单树
/// </summary>
/// <param name="GetType"></param>
/// <returns></returns>
/// <summary>
/// 查询菜单树
/// </summary>
/// <param name="GetType"></param>
/// <returns></returns>
public async Task<List<MenuTreeOutput>> MenuTree(string GetType)
{
if (!string.IsNullOrWhiteSpace(GetType) && GetType.ToLower() == "user")
@@ -169,7 +169,7 @@ namespace BPA.SAAS.Manage.Application.System.Services
{
return null;
}
List<BPA_Roles> dataRoles = await _db.Queryable<BPA_Roles>().Where(a => a.GroupId == GroupId).ToListAsync();
List<BPA_Roles> dataRoles =await _db.Queryable<BPA_Roles>().Where(a => a.GroupId == GroupId).ToListAsync();
if (dataRoles.Count() <= 0)
{
return null;
@@ -246,70 +246,95 @@ namespace BPA.SAAS.Manage.Application.System.Services
List<BPA_Menu> ParnMenus = new();
if (IsAdmin == "1" && account == "admin")
{
//ParnMenus = await _db.Queryable<BPA_Menu>().Where(t => t.IsAdmin == 1).OrderBy(t => t.Sort).ToListAsync();
var childMenus = await _db.Queryable<BPA_Menu>().Where(t => t.IsAdmin == 1 && t.Type == 3).OrderBy(t => t.Sort).ToListAsync();
var parnids= childMenus.Select(t => t.Pid).ToList();
var parnlist = _db.Queryable<BPA_Menu>().Where(x => parnids.Contains(x.Id)).Select(t => new MenuRouteDtoOutput
var adminmenu = await _db.Queryable<BPA_Menu>().Where(t =>t.IsAdmin==1).OrderBy(t => t.Sort).ToListAsync();
var pids= adminmenu.Select(t => t.Pid).ToList();
var pidmenu=await _db.Queryable<BPA_Menu>().Where(t => pids.Contains(t.Id)).ToListAsync();
adminmenu.AddRange(pidmenu);
//去重
adminmenu = adminmenu.Where((x, i) => adminmenu.FindIndex(z => z.Id == x.Id) == i).ToList();
var data = adminmenu.Where(t => t.Pid == null || t.Pid == "").OrderBy(t => t.Sort).Select(t => new MenuRouteDtoOutput
{
Id = t.Id,
Component = t.Component,
Icon = t.Icon,
Name = t.Name,
Path = t.Router,
Routes= AllMenus.Where(p=>p.Id==t.Pid).Select(t => new MenuRouteChildDtoOutput
{
Id = t.Id,
Component = t.Component,
Name = t.Name,
Path = t.Router,
}).ToList()
}).ToList();
var list=parnlist.Select(t => new MenuRouteDtoOutput
{
Id = t.Id,
Component = t.Component,
Icon = t.Icon,
Name = t.Name,
Path = t.Path,
Routes = childMenus.Where(x => x.Pid == t.Id).Select(x => new MenuRouteChildDtoOutput
Routes = adminmenu.Where(y => y.Pid == t.Id).Select(x => new MenuRouteChildDtoOutput
{
Id = t.Id,
Component = x.Component,
Name = x.Name,
Path = x.Router,
Routes = childMenus.Where(x => x.Pid == t.Id).Select(x => new MenuRouteChildDtoOutput
Routes = adminmenu.Where(y => y.Pid == x.Id).Select(y => new MenuRouteChildDtoOutput
{
Id = t.Id,
Component = x.Component,
Name = x.Name,
Path = x.Router,
Component = y.Component,
Name = y.Name,
Path = y.Router
}).ToList()
}).ToList()
}).ToList();
return list;
return data;
}
else{
var childMenus = await _db.Queryable<BPA_Menu>().Where(t => t.IsAdmin == 0 && (t.Type == 3 || t.Type == type)).OrderBy(t => t.Sort).ToListAsync();
var parnids = childMenus.Select(t => t.Pid).ToList();
var parnlist = _db.Queryable<BPA_Menu>().Where(x => parnids.Contains(x.Id)).ToList();
var list = parnlist.OrderBy(t => t.Sort).Select(t => new MenuRouteDtoOutput
else
{
AllMenus= AllMenus.Where(t=> t.IsAdmin == 0).ToList();
ParnMenus = await _db.Queryable<BPA_Menu>().LeftJoin<BPA_RoleMenu>((t, x) => t.Id == x.SysMenuId).LeftJoin<BPA_UserRole>((t, x, y) => x.SysRoleId == y.SysRoleId)
.Where((t, x, y) => y.SysUserId == UserId && t.Status == 0 && t.IsAdmin==0).Select(t => t).ToListAsync();
var data = ParnMenus.Where(t => t.Pid == null || t.Pid == "").OrderBy(t => t.Sort).Select(t => new MenuRouteDtoOutput
{
Id = t.Id,
Component = t.Component,
Icon = t.Icon,
Name = t.Name,
Path = t.Router,
Routes = childMenus.Where(x => x.Pid == t.Id).Select(x => new MenuRouteChildDtoOutput
Routes = AllMenus.Where(y => y.Pid == t.Id).Select(x => new MenuRouteChildDtoOutput
{
Id = t.Id,
Component = x.Component,
Name = x.Name,
Path = x.Router,
Routes = AllMenus.Where(y => y.Pid == x.Id).Select(y => new MenuRouteChildDtoOutput
{
Id = t.Id,
Component = y.Component,
Name = y.Name,
Path = y.Router
}).ToList()
}).ToList()
}).ToList();
return list;
return data;
}

// ParnMenus = await _db.Queryable<BPA_Menu>().Where(t => (t.Name == "系统管理" || t.Name == "加盟商管理" || t.Name == "设备管理")).OrderBy(t => t.Sort).ToListAsync();
//else
// ParnMenus = await _db.Queryable<BPA_Menu>().LeftJoin<BPA_RoleMenu>((t, x) => t.Id == x.SysMenuId).LeftJoin<BPA_UserRole>((t, x, y) => x.SysRoleId == y.SysRoleId)
// .Where((t, x, y) => y.SysUserId == UserId && t.Status == 0 && (t.Type== type || t.Type==3) && (t.Name!= "产品管理" || t.Name != "版本管理")).Select(t => t).ToListAsync();
//菜单去重
// ParnMenus = AllMenus.Where((x, i) => AllMenus.FindIndex(z => z.Id == x.Id) == i).ToList();
//var data = ParnMenus.Where(t => t.Pid == null || t.Pid == "").OrderBy(t => t.Sort).Select(t => new MenuRouteDtoOutput
//{
// Id = t.Id,
// Component = t.Component,
// Icon = t.Icon,
// Name = t.Name,
// Path = t.Router,
// Routes = AllMenus.Where(x => x.Pid == t.Id) .WhereIF(IsAdmin == "1" && account == "admin", x =>x.Name!="设备信息" && x.Name != "设备数据同步").Select(x => new MenuRouteChildDtoOutput
// {
// Id = t.Id,
// Component = x.Component,
// Name = x.Name,
// Path = x.Router,
// Routes = AllMenus.Where(y => y.Pid == x.Id).Select(y => new MenuRouteChildDtoOutput
// {
// Id = t.Id,
// Component = y.Component,
// Name = y.Name,
// Path = y.Router
// }).ToList()
// }).ToList()
//}).ToList();
// return data;
}
/// <summary>
/// 启用


Loading…
Cancel
Save