feat: 更新 IDict 接口
This commit is contained in:
parent
97836b447f
commit
50bc67c5d8
|
@ -463,7 +463,7 @@ class DictService : IDict
|
|||
|
||||
public bool DeleteClient(string appId)
|
||||
{
|
||||
var ret = false;
|
||||
bool ret;
|
||||
try
|
||||
{
|
||||
Database.BeginTransaction();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using BootstrapClient.DataAccess.Models;
|
||||
using BootstrapClient.Web.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using PetaPoco;
|
||||
|
||||
namespace BootstrapClient.DataAccess.PetaPoco.Services;
|
||||
|
@ -9,17 +8,13 @@ class DictService : IDict
|
|||
{
|
||||
private IDatabase Database { get; }
|
||||
|
||||
private string AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public DictService(IDatabase db, IConfiguration configuration)
|
||||
public DictService(IDatabase db)
|
||||
{
|
||||
Database = db;
|
||||
AppId = configuration.GetValue("AppId", "BA");
|
||||
}
|
||||
|
||||
public List<Dict> GetAll() => Database.Fetch<Dict>();
|
||||
|
@ -31,11 +26,11 @@ class DictService : IDict
|
|||
return code == "1";
|
||||
}
|
||||
|
||||
public string GetWebTitle()
|
||||
public string GetWebTitle(string appId)
|
||||
{
|
||||
var dicts = GetAll();
|
||||
var title = "网站标题";
|
||||
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
||||
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == appId)?.Name;
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站标题") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站标题");
|
||||
|
@ -44,11 +39,11 @@ class DictService : IDict
|
|||
return title;
|
||||
}
|
||||
|
||||
public string GetWebFooter()
|
||||
public string GetWebFooter(string appId)
|
||||
{
|
||||
var dicts = GetAll();
|
||||
var title = "网站页脚";
|
||||
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
|
||||
var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == appId)?.Name;
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站页脚") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站页脚");
|
||||
|
|
|
@ -30,39 +30,4 @@ class NavigationService : INavigation
|
|||
var order = Database.Provider.EscapeSqlIdentifier("Order");
|
||||
return Database.Fetch<Navigation>($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application from Navigations n inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = 'Administrators')) nav on n.ID = nav.NavigationID Where n.Category = '1' ORDER BY n.Application, n.{order}", new { UserName = userName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> GetMenusByRoleId(string? roleId)
|
||||
{
|
||||
return Database.Fetch<string>("select NavigationID from NavigationRole where RoleID = @0", roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="menuIds"></param>
|
||||
/// <returns></returns>
|
||||
public bool SaveMenusByRoleId(string? roleId, List<string> menuIds)
|
||||
{
|
||||
var ret = false;
|
||||
try
|
||||
{
|
||||
Database.BeginTransaction();
|
||||
Database.Execute("delete from NavigationRole where RoleID = @0", roleId);
|
||||
Database.InsertBatch("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId }));
|
||||
Database.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Database.AbortTransaction();
|
||||
throw;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ class UserService : IUser
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<string> GetApps(string userName)
|
||||
{
|
||||
return Database.Fetch<string>($"select d.Code from Dicts d inner join RoleApp ra on d.Code = ra.AppId inner join (select r.Id from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 union select r.Id from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0) r on ra.RoleId = r.ID union select Code from Dicts where Category = @1 and exists(select r.ID from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 and r.RoleName = @2 union select r.ID from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0 and r.RoleName = @2)", userName, "应用程序", "Administrators");
|
||||
|
@ -43,7 +42,6 @@ class UserService : IUser
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<string> GetRoles(string userName)
|
||||
{
|
||||
return Database.Fetch<string>($"select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @0 union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@0", userName);
|
||||
|
|
|
@ -108,8 +108,8 @@ public sealed partial class MainLayout
|
|||
MenuItems = NavigationsService.GetMenus(userName).Where(i => i.Application == Context.AppId).ToMenus();
|
||||
|
||||
Context.DisplayName = user?.DisplayName ?? "未注册账户";
|
||||
Title = DictsService.GetWebTitle();
|
||||
Footer = DictsService.GetWebFooter();
|
||||
Title = DictsService.GetWebTitle(Context.AppId);
|
||||
Footer = DictsService.GetWebFooter(Context.AppId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ public interface IDict
|
|||
/// 获取 站点 Title 配置信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetWebTitle();
|
||||
string GetWebTitle(string appId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取站点 Footer 配置信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetWebFooter();
|
||||
string GetWebFooter(string appId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue