新增功能:支持多数据库
This commit is contained in:
parent
6e1f065271
commit
5494eae930
|
@ -345,6 +345,7 @@ ASALocalRun/
|
||||||
# Net Core Keys
|
# Net Core Keys
|
||||||
[Kk]eys/
|
[Kk]eys/
|
||||||
lib/
|
lib/
|
||||||
|
*.db
|
||||||
|
|
||||||
###### -- Custom Ignore Section, Make sure all files you add to the git repo are below this line -- ######
|
###### -- Custom Ignore Section, Make sure all files you add to the git repo are below this line -- ######
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj" />
|
||||||
|
<ProjectReference Include="..\Bootstrap.DataAccess.SQLServer\Bootstrap.DataAccess.SQLServer.csproj" />
|
||||||
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
|
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using Bootstrap.Admin.Models;
|
using Bootstrap.Admin.Models;
|
||||||
using Bootstrap.Security;
|
using Bootstrap.DataAccess;
|
||||||
using Longbow;
|
using Longbow;
|
||||||
using Longbow.Configuration;
|
using Longbow.Configuration;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
@ -39,7 +39,7 @@ namespace Bootstrap.Admin.Controllers
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Login(string userName, string password, string remember)
|
public async Task<IActionResult> Login(string userName, string password, string remember)
|
||||||
{
|
{
|
||||||
if (BootstrapUser.Authenticate(userName, password))
|
if (UserHelper.Authenticate(userName, password))
|
||||||
{
|
{
|
||||||
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
|
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
|
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
using Bootstrap.DataAccess;
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.Admin.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class InterfaceController : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IEnumerable<BootstrapDict> RetrieveDicts()
|
||||||
|
{
|
||||||
|
return DictHelper.RetrieveDicts();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IEnumerable<string> RetrieveRolesByUrl([FromBody]string url)
|
||||||
|
{
|
||||||
|
return RoleHelper.RetrieveRolesByUrl(url);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IEnumerable<string> RetrieveRolesByUserName([FromBody]string userName)
|
||||||
|
{
|
||||||
|
return RoleHelper.RetrieveRolesByUserName(userName);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public BootstrapUser RetrieveUserByUserName([FromBody]string userName)
|
||||||
|
{
|
||||||
|
return UserHelper.RetrieveUserByUserName(userName);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IEnumerable<BootstrapMenu> RetrieveAppMenus([FromBody]AppMenuArgs args)
|
||||||
|
{
|
||||||
|
return MenuHelper.RetrieveAppMenus(args.Name, args.Url);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class AppMenuArgs
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Url { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.DataAccess;
|
||||||
|
using Bootstrap.Security;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
@ -26,7 +27,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
dynamic user = value;
|
dynamic user = value;
|
||||||
string userName = user.userName;
|
string userName = user.userName;
|
||||||
string password = user.password;
|
string password = user.password;
|
||||||
if (BootstrapUser.Authenticate(userName, password))
|
if (UserHelper.Authenticate(userName, password))
|
||||||
{
|
{
|
||||||
return BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
return BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
|
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
|
||||||
break;
|
break;
|
||||||
case "user":
|
case "user":
|
||||||
ret = BootstrapMenu.RetrieveAllMenus(User.Identity.Name).ToList();
|
ret = MenuHelper.RetrieveAllMenus(User.Identity.Name).ToList();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
message.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon));
|
message.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon));
|
||||||
|
|
||||||
//Apps
|
//Apps
|
||||||
var apps = ExceptionHelper.RetrieveExceptions().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException");
|
var apps = ExceptionsHelper.RetrieveExceptions().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException");
|
||||||
var appExceptionsCount = apps.Count();
|
var appExceptionsCount = apps.Count();
|
||||||
|
|
||||||
apps = apps.Take(6);
|
apps = apps.Take(6);
|
||||||
|
@ -61,7 +61,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
});
|
});
|
||||||
|
|
||||||
//Dbs
|
//Dbs
|
||||||
var dbs = ExceptionHelper.RetrieveExceptions().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException");
|
var dbs = ExceptionsHelper.RetrieveExceptions().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException");
|
||||||
var dbExceptionsCount = dbs.Count();
|
var dbExceptionsCount = dbs.Count();
|
||||||
|
|
||||||
dbs = dbs.Take(6);
|
dbs = dbs.Take(6);
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public bool Get(string userName)
|
public bool Get(string userName)
|
||||||
{
|
{
|
||||||
return BootstrapUser.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName);
|
return UserHelper.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 登录页面注册新用户提交按钮调用
|
/// 登录页面注册新用户提交按钮调用
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.DataAccess;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
|
||||||
namespace Bootstrap.Admin.Models
|
namespace Bootstrap.Admin.Models
|
||||||
|
@ -10,7 +10,7 @@ namespace Bootstrap.Admin.Models
|
||||||
{
|
{
|
||||||
public HeaderBarModel(IIdentity identity)
|
public HeaderBarModel(IIdentity identity)
|
||||||
{
|
{
|
||||||
var user = BootstrapUser.RetrieveUserByUserName(identity.Name);
|
var user = UserHelper.RetrieveUserByUserName(identity.Name);
|
||||||
Icon = user.Icon;
|
Icon = user.Icon;
|
||||||
DisplayName = user.DisplayName;
|
DisplayName = user.DisplayName;
|
||||||
UserName = user.UserName;
|
UserName = user.UserName;
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Bootstrap.Admin.Models
|
||||||
{
|
{
|
||||||
public NavigatorBarModel(ControllerBase controller) : base(controller.User.Identity)
|
public NavigatorBarModel(ControllerBase controller) : base(controller.User.Identity)
|
||||||
{
|
{
|
||||||
Navigations = BootstrapMenu.RetrieveSystemMenus(UserName, $"~{controller.HttpContext.Request.Path}");
|
Navigations = MenuHelper.RetrieveSystemMenus(UserName, $"~{controller.HttpContext.Request.Path}");
|
||||||
Applications = DictHelper.RetrieveApps();
|
Applications = DictHelper.RetrieveApps();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Query
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public QueryData<Exceptions> RetrieveData()
|
public QueryData<Exceptions> RetrieveData()
|
||||||
{
|
{
|
||||||
var data = ExceptionHelper.RetrieveExceptions();
|
var data = ExceptionsHelper.RetrieveExceptions();
|
||||||
if (StartTime > DateTime.MinValue)
|
if (StartTime > DateTime.MinValue)
|
||||||
{
|
{
|
||||||
data = data.Where(t => t.LogTime > StartTime);
|
data = data.Where(t => t.LogTime > StartTime);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.DataAccess;
|
||||||
|
using Bootstrap.Security;
|
||||||
using Longbow.Web.Mvc;
|
using Longbow.Web.Mvc;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ namespace Bootstrap.Admin.Query
|
||||||
|
|
||||||
public QueryData<BootstrapMenu> RetrieveData(string userName)
|
public QueryData<BootstrapMenu> RetrieveData(string userName)
|
||||||
{
|
{
|
||||||
var data = BootstrapMenu.RetrieveMenusByUserName(userName);
|
var data = MenuHelper.RetrieveMenusByUserName(userName);
|
||||||
if (!string.IsNullOrEmpty(ParentName))
|
if (!string.IsNullOrEmpty(ParentName))
|
||||||
{
|
{
|
||||||
data = data.Where(t => t.ParentName.Contains(ParentName));
|
data = data.Where(t => t.ParentName.Contains(ParentName));
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace Bootstrap.Admin
|
||||||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||||
});
|
});
|
||||||
services.AddCors();
|
services.AddCors();
|
||||||
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionHelper.Log));
|
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
|
||||||
services.AddConfigurationManager();
|
services.AddConfigurationManager();
|
||||||
services.AddCacheManager();
|
services.AddCacheManager();
|
||||||
services.AddDBAccessFactory();
|
services.AddDBAccessFactory();
|
||||||
|
@ -83,7 +83,7 @@ namespace Bootstrap.Admin
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseBootstrapAdminAuthorization();
|
app.UseBootstrapAdminAuthorization(userName => RoleHelper.RetrieveRolesByUserName(userName), url => RoleHelper.RetrieveRolesByUrl(url));
|
||||||
app.UseCacheManagerCorsHandler();
|
app.UseCacheManagerCorsHandler();
|
||||||
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
||||||
app.UseMvc(routes =>
|
app.UseMvc(routes =>
|
||||||
|
|
|
@ -15,6 +15,20 @@
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
|
"ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"
|
||||||
},
|
},
|
||||||
|
"DB": [
|
||||||
|
{
|
||||||
|
"Enabled": false,
|
||||||
|
"Widget": "Bootstrap.DataAccess.SQLServer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Enabled": true,
|
||||||
|
"Widget": "Bootstrap.DataAccess.SQLite",
|
||||||
|
"DBProviderFactory": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"ba": "Data Source=BootstrapAdmin.db;"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"AllowOrigins": "http://localhost,http://10.15.63.218",
|
"AllowOrigins": "http://localhost,http://10.15.63.218",
|
||||||
"KeyPath": "D:\\App\\Web-App\\keys",
|
"KeyPath": "D:\\App\\Web-App\\keys",
|
||||||
"ApplicationName": "__bd__",
|
"ApplicationName": "__bd__",
|
||||||
|
@ -26,7 +40,6 @@
|
||||||
"Expires": 5,
|
"Expires": 5,
|
||||||
"SecurityKey": "BootstrapAdmin-V1.1"
|
"SecurityKey": "BootstrapAdmin-V1.1"
|
||||||
},
|
},
|
||||||
"BAAuthorizateScheme": "Role",
|
|
||||||
"KeepExceptionsPeriod": 12,
|
"KeepExceptionsPeriod": 12,
|
||||||
"KeepLogsPeriod": 12,
|
"KeepLogsPeriod": 12,
|
||||||
"CookieExpiresDays": 7,
|
"CookieExpiresDays": 7,
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
|
namespace Bootstrap.Client.DataAccess
|
||||||
|
{
|
||||||
|
internal static class BAHelper
|
||||||
|
{
|
||||||
|
private readonly static LgbHttpClient _client = new LgbHttpClient(new HttpClient() { BaseAddress = new Uri($"{ConfigurationManager.AppSettings["AuthHost"]}/api/Interface/") });
|
||||||
|
|
||||||
|
private static T ExecuteRemoteAction<T>(string actionName, object data = null)
|
||||||
|
{
|
||||||
|
var task = _client.PostAsJsonAsync<T>(actionName, data);
|
||||||
|
task.Wait();
|
||||||
|
return task.Result;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(object args) => ExecuteRemoteAction<IEnumerable<BootstrapMenu>>("RetrieveAppMenus", args);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveRolesByUrl(string url) => ExecuteRemoteAction<IEnumerable<string>>("RetrieveRolesByUrl", url);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => ExecuteRemoteAction<IEnumerable<string>>("RetrieveRolesByUserName", userName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapDict> RetrieveDicts() => ExecuteRemoteAction<IEnumerable<BootstrapDict>>("RetrieveDicts");
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static BootstrapUser RetrieveUserByUserName(string userName) => ExecuteRemoteAction<BootstrapUser>("RetrieveUserByUserName", userName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bootstrap.Security" Version="1.0.4" />
|
<PackageReference Include="Bootstrap.Security" Version="1.0.4" />
|
||||||
|
<PackageReference Include="Longbow" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Longbow.Configuration" Version="1.0.3" />
|
||||||
|
<PackageReference Include="Longbow.Data" Version="1.0.3" />
|
||||||
<PackageReference Include="Longbow.Web" Version="1.0.1" />
|
<PackageReference Include="Longbow.Web" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
using Longbow.Data;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Bootstrap.Client.DataAccess
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public static class DBAccessManager
|
|
||||||
{
|
|
||||||
private static readonly Lazy<IDBAccess> db = new Lazy<IDBAccess>(() => DBAccessFactory.CreateDB("ba"), true);
|
|
||||||
|
|
||||||
public static IDBAccess SqlDBAccess
|
|
||||||
{
|
|
||||||
get { return db.Value; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Bootstrap.Client.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class DbAccessManager
|
||||||
|
{
|
||||||
|
private static readonly Lazy<IDbAccess> _db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("sql"), true);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static IDbAccess DbAccess { get { return _db.Value; } }
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,15 +47,12 @@ namespace Bootstrap.Client.DataAccess
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static IEnumerable<BootstrapDict> RetrieveDicts()
|
private static IEnumerable<BootstrapDict> RetrieveDicts() => BAHelper.RetrieveDicts();
|
||||||
{
|
|
||||||
return BootstrapDict.RetrieveDicts();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string RetrieveAppName(string name, string defaultValue = "未设置")
|
private static string RetrieveAppName(string name, string defaultValue = "未设置")
|
||||||
{
|
{
|
||||||
var dicts = BootstrapDict.RetrieveDicts();
|
var dicts = RetrieveDicts();
|
||||||
var platName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == ConfigurationManager.AppSettings["AppId"]).Name;
|
var platName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == ConfigurationManager.AppSettings["AppId"])?.Name;
|
||||||
return dicts.FirstOrDefault(d => d.Category == platName && d.Name == name)?.Code ?? $"{name}{defaultValue}";
|
return dicts.FirstOrDefault(d => d.Category == platName && d.Name == name)?.Code ?? $"{name}{defaultValue}";
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -64,9 +61,8 @@ namespace Bootstrap.Client.DataAccess
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string RetrieveActiveTheme()
|
public static string RetrieveActiveTheme()
|
||||||
{
|
{
|
||||||
var data = RetrieveDicts();
|
var theme = RetrieveDicts().Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault()?.Code;
|
||||||
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
|
return theme == null ? string.Empty : theme.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme;
|
||||||
return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.Client.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class MenuHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string name, string url) => BAHelper.RetrieveAppMenus(new { Name = name, Url = url });
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.Client.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class RoleHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => BAHelper.RetrieveRolesByUserName(userName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveRolesByUrl(string url) => BAHelper.RetrieveRolesByUrl(url);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
|
||||||
|
namespace Bootstrap.Client.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户表相关操作类
|
||||||
|
/// </summary>
|
||||||
|
public static class UserHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static BootstrapUser RetrieveUserByUserName(string userName)=> BAHelper.RetrieveUserByUserName(userName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using Bootstrap.Client.DataAccess;
|
using Bootstrap.Client.DataAccess;
|
||||||
using Bootstrap.Security;
|
|
||||||
using Longbow.Configuration;
|
using Longbow.Configuration;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using System;
|
using System;
|
||||||
|
@ -18,7 +17,7 @@ namespace Bootstrap.Client.Models
|
||||||
/// <param name="identity"></param>
|
/// <param name="identity"></param>
|
||||||
public HeaderBarModel(IIdentity identity)
|
public HeaderBarModel(IIdentity identity)
|
||||||
{
|
{
|
||||||
var user = BootstrapUser.RetrieveUserByUserName(identity.Name);
|
var user = UserHelper.RetrieveUserByUserName(identity.Name);
|
||||||
Icon = $"{ConfigurationManager.AppSettings["AuthHost"]}/{user.Icon.TrimStart('~', '/')}";
|
Icon = $"{ConfigurationManager.AppSettings["AuthHost"]}/{user.Icon.TrimStart('~', '/')}";
|
||||||
DisplayName = user.DisplayName;
|
DisplayName = user.DisplayName;
|
||||||
UserName = user.UserName;
|
UserName = user.UserName;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Client.DataAccess;
|
||||||
|
using Bootstrap.Security;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
@ -15,11 +16,11 @@ namespace Bootstrap.Client.Models
|
||||||
/// <param name="controller"></param>
|
/// <param name="controller"></param>
|
||||||
public NavigatorBarModel(ControllerBase controller) : base(controller.User.Identity)
|
public NavigatorBarModel(ControllerBase controller) : base(controller.User.Identity)
|
||||||
{
|
{
|
||||||
Navigations = BootstrapMenu.RetrieveAppMenus(UserName, $"~/{controller.ControllerContext.ActionDescriptor.ControllerName}/{controller.ControllerContext.ActionDescriptor.ActionName}");
|
Navigations = MenuHelper.RetrieveAppMenus(UserName, $"~/{controller.ControllerContext.ActionDescriptor.ControllerName}/{controller.ControllerContext.ActionDescriptor.ActionName}");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<BootstrapMenu> Navigations { get;}
|
public IEnumerable<BootstrapMenu> Navigations { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using Bootstrap.Security.Filter;
|
using Bootstrap.Client.DataAccess;
|
||||||
|
using Bootstrap.Security.Filter;
|
||||||
using Bootstrap.Security.Middleware;
|
using Bootstrap.Security.Middleware;
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using Longbow.Cache.Middleware;
|
using Longbow.Cache.Middleware;
|
||||||
|
@ -87,7 +88,7 @@ namespace Bootstrap.Client
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseCookiePolicy();
|
app.UseCookiePolicy();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseBootstrapAdminAuthorization();
|
app.UseBootstrapAdminAuthorization(userName => RoleHelper.RetrieveRolesByUserName(userName), url => RoleHelper.RetrieveRolesByUrl(url));
|
||||||
app.UseWebSocketHandler(options => options.UseAuthentication = true);
|
app.UseWebSocketHandler(options => options.UseAuthentication = true);
|
||||||
app.UseCacheManagerCorsHandler();
|
app.UseCacheManagerCorsHandler();
|
||||||
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Bootstrap.Security" Version="1.0.4" />
|
||||||
|
<PackageReference Include="Longbow.Cache" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Longbow.Data" Version="1.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -7,38 +7,26 @@ using System.Data.Common;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DictHelper
|
public class Dict : DataAccess.Dict
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
internal const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IEnumerable<BootstrapDict> RetrieveDicts()
|
|
||||||
{
|
|
||||||
return BootstrapDict.RetrieveDicts();
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除字典中的数据
|
/// 删除字典中的数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">需要删除的IDs</param>
|
/// <param name="value">需要删除的IDs</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool DeleteDict(IEnumerable<int> value)
|
public override bool DeleteDict(IEnumerable<int> value)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
var ids = string.Join(",", value);
|
var ids = string.Join(",", value);
|
||||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||||
CacheCleanUtility.ClearCache(dictIds: ids);
|
CacheCleanUtility.ClearCache(dictIds: ids);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -47,27 +35,27 @@ namespace Bootstrap.DataAccess
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存新建/更新的字典信息
|
/// 保存新建/更新的字典信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="dict"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveDict(BootstrapDict p)
|
public override bool SaveDict(BootstrapDict dict)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (p.Category.Length > 50) p.Category = p.Category.Substring(0, 50);
|
if (dict.Category.Length > 50) dict.Category = dict.Category.Substring(0, 50);
|
||||||
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
|
if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50);
|
||||||
if (p.Code.Length > 50) p.Code = p.Code.Substring(0, 50);
|
if (dict.Code.Length > 50) dict.Code = dict.Code.Substring(0, 50);
|
||||||
string sql = p.Id == 0 ?
|
string sql = dict.Id == 0 ?
|
||||||
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
|
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
|
||||||
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
|
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", p.Code));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Define", p.Define));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(dictIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -77,16 +65,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="code"></param>
|
/// <param name="code"></param>
|
||||||
/// <param name="category"></param>
|
/// <param name="category"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveSettings(BootstrapDict dict)
|
public override bool SaveSettings(BootstrapDict dict)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", dict.Name));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", dict.Code));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", dict.Category));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -95,14 +83,14 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获取字典分类名称
|
/// 获取字典分类名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<string> RetrieveCategories()
|
public override IEnumerable<string> RetrieveCategories()
|
||||||
{
|
{
|
||||||
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
||||||
{
|
{
|
||||||
var ret = new List<string>();
|
var ret = new List<string>();
|
||||||
string sql = "select distinct Category from Dicts";
|
string sql = "select distinct Category from Dicts";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -116,7 +104,7 @@ namespace Bootstrap.DataAccess
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string RetrieveWebTitle()
|
public override string RetrieveWebTitle()
|
||||||
{
|
{
|
||||||
var settings = RetrieveDicts();
|
var settings = RetrieveDicts();
|
||||||
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
|
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
|
||||||
|
@ -125,7 +113,7 @@ namespace Bootstrap.DataAccess
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string RetrieveWebFooter()
|
public override string RetrieveWebFooter()
|
||||||
{
|
{
|
||||||
var settings = RetrieveDicts();
|
var settings = RetrieveDicts();
|
||||||
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
|
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
|
||||||
|
@ -134,7 +122,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得系统中配置的可以使用的网站样式
|
/// 获得系统中配置的可以使用的网站样式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<BootstrapDict> RetrieveThemes()
|
public override IEnumerable<BootstrapDict> RetrieveThemes()
|
||||||
{
|
{
|
||||||
var data = RetrieveDicts();
|
var data = RetrieveDicts();
|
||||||
return data.Where(d => d.Category == "网站样式");
|
return data.Where(d => d.Category == "网站样式");
|
||||||
|
@ -143,7 +131,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得网站设置中的当前样式
|
/// 获得网站设置中的当前样式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string RetrieveActiveTheme()
|
public override string RetrieveActiveTheme()
|
||||||
{
|
{
|
||||||
var data = RetrieveDicts();
|
var data = RetrieveDicts();
|
||||||
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
|
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
|
||||||
|
@ -153,7 +141,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获取头像路径
|
/// 获取头像路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static BootstrapDict RetrieveIconFolderPath()
|
public override BootstrapDict RetrieveIconFolderPath()
|
||||||
{
|
{
|
||||||
var data = RetrieveDicts();
|
var data = RetrieveDicts();
|
||||||
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
|
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
|
||||||
|
@ -162,7 +150,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得默认的前台首页地址,默认为~/Home/Index
|
/// 获得默认的前台首页地址,默认为~/Home/Index
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string RetrieveHomeUrl()
|
public override string RetrieveHomeUrl()
|
||||||
{
|
{
|
||||||
var settings = RetrieveDicts();
|
var settings = RetrieveDicts();
|
||||||
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
|
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
|
||||||
|
@ -171,7 +159,7 @@ namespace Bootstrap.DataAccess
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps()
|
public override IEnumerable<KeyValuePair<string, string>> RetrieveApps()
|
||||||
{
|
{
|
||||||
var settings = RetrieveDicts();
|
var settings = RetrieveDicts();
|
||||||
return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
|
return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
|
|
@ -7,24 +7,20 @@ using System.Collections.Specialized;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ExceptionHelper
|
public class Exceptions : Bootstrap.DataAccess.Exceptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
private static readonly string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ex"></param>
|
/// <param name="ex"></param>
|
||||||
/// <param name="additionalInfo"></param>
|
/// <param name="additionalInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static void Log(Exception ex, NameValueCollection additionalInfo)
|
public override void Log(Exception ex, NameValueCollection additionalInfo)
|
||||||
{
|
{
|
||||||
if (additionalInfo == null)
|
if (additionalInfo == null)
|
||||||
{
|
{
|
||||||
|
@ -37,16 +33,16 @@ namespace Bootstrap.DataAccess
|
||||||
}
|
}
|
||||||
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
|
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
|
||||||
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())";
|
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ErrorPage", errorPage));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", DBAccessFactory.ToDBValue(additionalInfo["UserId"])));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserIp", DBAccessFactory.ToDBValue(additionalInfo["UserIp"])));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Message", ex.Message));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
CacheManager.Clear(RetrieveExceptionsDataKey);
|
CacheManager.Clear(RetrieveExceptionsDataKey);
|
||||||
ClearExceptions();
|
ClearExceptions();
|
||||||
}
|
}
|
||||||
|
@ -59,22 +55,22 @@ namespace Bootstrap.DataAccess
|
||||||
System.Threading.Tasks.Task.Run(() =>
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
{
|
{
|
||||||
string sql = $"delete from Exceptions where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]}, GETDATE())";
|
string sql = $"delete from Exceptions where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]}, GETDATE())";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询一周内所有异常
|
/// 查询一周内所有异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Exceptions> RetrieveExceptions()
|
public override IEnumerable<Bootstrap.DataAccess.Exceptions> RetrieveExceptions()
|
||||||
{
|
{
|
||||||
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
|
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
|
string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
|
||||||
List<Exceptions> exceptions = new List<Exceptions>();
|
List<Exceptions> exceptions = new List<Exceptions>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
|
@ -1,4 +1,5 @@
|
||||||
using Longbow.Cache;
|
using Bootstrap.DataAccess;
|
||||||
|
using Longbow.Cache;
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -7,30 +8,26 @@ using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// author:liuchun
|
///
|
||||||
/// date:2016.10.22
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class GroupHelper
|
public class Group : Bootstrap.DataAccess.Group
|
||||||
{
|
{
|
||||||
internal const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups";
|
|
||||||
internal const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId";
|
|
||||||
internal const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有群组信息
|
/// 查询所有群组信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Group> RetrieveGroups(int id = 0)
|
public override IEnumerable<Bootstrap.DataAccess.Group> RetrieveGroups(int id = 0)
|
||||||
{
|
{
|
||||||
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
|
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select * from Groups";
|
string sql = "select * from Groups";
|
||||||
List<Group> groups = new List<Group>();
|
List<Group> groups = new List<Group>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -50,14 +47,14 @@ namespace Bootstrap.DataAccess
|
||||||
/// 删除群组信息
|
/// 删除群组信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
public static bool DeleteGroup(IEnumerable<int> value)
|
public override bool DeleteGroup(IEnumerable<int> value)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
var ids = string.Join(",", value);
|
var ids = string.Join(",", value);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: value);
|
CacheCleanUtility.ClearCache(groupIds: value);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -67,7 +64,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="p"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveGroup(Group p)
|
public override bool SaveGroup(Bootstrap.DataAccess.Group p)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50);
|
if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50);
|
||||||
|
@ -75,12 +72,12 @@ namespace Bootstrap.DataAccess
|
||||||
string sql = p.Id == 0 ?
|
string sql = p.Id == 0 ?
|
||||||
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
||||||
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -90,16 +87,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Group> RetrieveGroupsByUserId(int userId)
|
public override IEnumerable<Bootstrap.DataAccess.Group> RetrieveGroupsByUserId(int userId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
|
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
|
||||||
var ret = CacheManager.GetOrAdd(key, k =>
|
var ret = CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
|
string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
|
||||||
List<Group> groups = new List<Group>();
|
List<Group> groups = new List<Group>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -122,7 +119,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="groupIds"></param>
|
/// <param name="groupIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds)
|
public override bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
|
@ -130,16 +127,16 @@ namespace Bootstrap.DataAccess
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
//判断用户是否选定角色
|
//判断用户是否选定角色
|
||||||
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
|
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//删除用户部门表中该用户所有的部门关系
|
//删除用户部门表中该用户所有的部门关系
|
||||||
string sql = "delete from UserGroup where UserID=@UserID;";
|
string sql = "delete from UserGroup where UserID=@UserID;";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
|
||||||
// insert batch data into config table
|
// insert batch data into config table
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
@ -168,16 +165,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="roleId"></param>
|
/// <param name="roleId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId)
|
public override IEnumerable<Bootstrap.DataAccess.Group> RetrieveGroupsByRoleId(int roleId)
|
||||||
{
|
{
|
||||||
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
|
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
|
||||||
return CacheManager.GetOrAdd(k, key =>
|
return CacheManager.GetOrAdd(k, key =>
|
||||||
{
|
{
|
||||||
List<Group> groups = new List<Group>();
|
List<Group> groups = new List<Group>();
|
||||||
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
|
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -199,23 +196,23 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="groupIds"></param>
|
/// <param name="groupIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds)
|
public override bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
|
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//删除角色部门表该角色所有的部门
|
//删除角色部门表该角色所有的部门
|
||||||
string sql = "delete from RoleGroup where RoleID=@RoleID";
|
string sql = "delete from RoleGroup where RoleID=@RoleID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
//批插入角色部门表
|
//批插入角色部门表
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
{
|
{
|
|
@ -6,24 +6,26 @@ using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
public static class LogHelper
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Log : Bootstrap.DataAccess.Log
|
||||||
{
|
{
|
||||||
private const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有日志信息
|
/// 查询所有日志信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tId"></param>
|
/// <param name="tId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Log> RetrieveLogs(string tId = null)
|
public override IEnumerable<Bootstrap.DataAccess.Log> RetrieveLogs(string tId = null)
|
||||||
{
|
{
|
||||||
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
|
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0";
|
string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0";
|
||||||
List<Log> logs = new List<Log>();
|
List<Log> logs = new List<Log>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -48,13 +50,13 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static void DeleteLogAsync()
|
private void DeleteLogAsync()
|
||||||
{
|
{
|
||||||
System.Threading.Tasks.Task.Run(() =>
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
{
|
{
|
||||||
string sql = $"delete from Logs where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepLogsPeriod"]}, GETDATE())";
|
string sql = $"delete from Logs where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepLogsPeriod"]}, GETDATE())";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -62,19 +64,19 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="p"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveLog(Log p)
|
public override bool SaveLog(Bootstrap.DataAccess.Log p)
|
||||||
{
|
{
|
||||||
if (p == null) throw new ArgumentNullException("p");
|
if (p == null) throw new ArgumentNullException("p");
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, GetDate(), @ClientIp, @ClientAgent, @RequestUrl)";
|
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, GetDate(), @ClientIp, @ClientAgent, @RequestUrl)";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@CRUD", p.CRUD));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", p.UserName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheManager.Clear(RetrieveLogsDataKey);
|
CacheManager.Clear(RetrieveLogsDataKey);
|
||||||
DeleteLogAsync();
|
DeleteLogAsync();
|
|
@ -8,29 +8,25 @@ using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MenuHelper
|
public class Menu : Bootstrap.DataAccess.Menu
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
internal const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除菜单信息
|
/// 删除菜单信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
public static bool DeleteMenu(IEnumerable<int> value)
|
public override bool DeleteMenu(IEnumerable<int> value)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
var ids = string.Join(",", value);
|
var ids = string.Join(",", value);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(menuIds: value);
|
CacheCleanUtility.ClearCache(menuIds: value);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -40,7 +36,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="p"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveMenu(BootstrapMenu p)
|
public override bool SaveMenu(BootstrapMenu p)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(p.Name)) return false;
|
if (string.IsNullOrEmpty(p.Name)) return false;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -50,19 +46,19 @@ namespace Bootstrap.DataAccess
|
||||||
string sql = p.Id == 0 ?
|
string sql = p.Id == 0 ?
|
||||||
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
|
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
|
||||||
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
|
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ParentId", p.ParentId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", p.Name));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Order", p.Order));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Order", p.Order));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Icon", DBAccessFactory.ToDBValue(p.Icon)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Url", DBAccessFactory.ToDBValue(p.Url)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", p.Category));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Target", p.Target));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Target", p.Target));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@IsResource", p.IsResource));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -73,17 +69,17 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="roleId"></param>
|
/// <param name="roleId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
public override IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
|
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
var menus = new List<BootstrapMenu>();
|
var menus = new List<BootstrapMenu>();
|
||||||
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -103,23 +99,23 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="menuIds"></param>
|
/// <param name="menuIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds)
|
public override bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
dt.Columns.Add("NavigationID", typeof(int));
|
dt.Columns.Add("NavigationID", typeof(int));
|
||||||
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
|
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//删除菜单角色表该角色所有的菜单
|
//删除菜单角色表该角色所有的菜单
|
||||||
string sql = "delete from NavigationRole where RoleID=@RoleID";
|
string sql = "delete from NavigationRole where RoleID=@RoleID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
//批插入菜单角色表
|
//批插入菜单角色表
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
{
|
{
|
||||||
|
@ -141,5 +137,33 @@ namespace Bootstrap.DataAccess
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName, string activeUrl = null) => RetrieveAllMenus(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveAppMenus(string userName, string activeUrl = null) => RetrieveAppMenus(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName, string activeUrl = null) => RetrieveMenusByUserName(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null) => RetrieveSystemMenus(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,28 +6,27 @@ using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MessageHelper
|
public class Message : Bootstrap.DataAccess.Message
|
||||||
{
|
{
|
||||||
private const string RetrieveMessageDataKey = "MessageHelper-RetrieveMessages";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所有有关userName所有消息列表
|
/// 所有有关userName所有消息列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static IEnumerable<Message> RetrieveMessages(string userName)
|
private static IEnumerable<Bootstrap.DataAccess.Message> RetrieveMessages(string userName)
|
||||||
{
|
{
|
||||||
var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key =>
|
var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
|
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
|
||||||
List<Message> messages = new List<Message>();
|
List<Message> messages = new List<Message>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -58,8 +57,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// 收件箱
|
/// 收件箱
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
|
public override IEnumerable<Bootstrap.DataAccess.Message> Inbox(string userName)
|
||||||
public static IEnumerable<Message> Inbox(string userName)
|
|
||||||
{
|
{
|
||||||
var messageRet = RetrieveMessages(userName);
|
var messageRet = RetrieveMessages(userName);
|
||||||
return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
@ -69,7 +67,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Message> SendMail(string userName)
|
public override IEnumerable<Bootstrap.DataAccess.Message> SendMail(string userName)
|
||||||
{
|
{
|
||||||
var messageRet = RetrieveMessages(userName);
|
var messageRet = RetrieveMessages(userName);
|
||||||
return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
@ -79,7 +77,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Message> Trash(string userName)
|
public override IEnumerable<Bootstrap.DataAccess.Message> Trash(string userName)
|
||||||
{
|
{
|
||||||
var messageRet = RetrieveMessages(userName);
|
var messageRet = RetrieveMessages(userName);
|
||||||
return messageRet.Where(n => n.IsDelete == 1);
|
return messageRet.Where(n => n.IsDelete == 1);
|
||||||
|
@ -89,7 +87,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Message> Mark(string userName)
|
public override IEnumerable<Bootstrap.DataAccess.Message> Flag(string userName)
|
||||||
{
|
{
|
||||||
var messageRet = RetrieveMessages(userName);
|
var messageRet = RetrieveMessages(userName);
|
||||||
return messageRet.Where(n => n.Mark == 1);
|
return messageRet.Where(n => n.Mark == 1);
|
||||||
|
@ -99,7 +97,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Message> RetrieveMessagesHeader(string userName)
|
public override IEnumerable<Bootstrap.DataAccess.Message> RetrieveMessagesHeader(string userName)
|
||||||
{
|
{
|
||||||
var messageRet = Inbox(userName);
|
var messageRet = Inbox(userName);
|
||||||
messageRet.AsParallel().ForAll(n =>
|
messageRet.AsParallel().ForAll(n =>
|
|
@ -7,30 +7,26 @@ using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class RoleHelper
|
public class Role : Bootstrap.DataAccess.Role
|
||||||
{
|
{
|
||||||
internal const string RetrieveRolesDataKey = "RoleHelper-RetrieveRoles";
|
|
||||||
internal const string RetrieveRolesByUserIdDataKey = "RoleHelper-RetrieveRolesByUserId";
|
|
||||||
internal const string RetrieveRolesByMenuIdDataKey = "RoleHelper-RetrieveRolesByMenuId";
|
|
||||||
internal const string RetrieveRolesByGroupIdDataKey = "RoleHelper-RetrieveRolesByGroupId";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有角色
|
/// 查询所有角色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Role> RetrieveRoles(int id = 0)
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRoles(int id = 0)
|
||||||
{
|
{
|
||||||
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
|
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select * from Roles";
|
string sql = "select * from Roles";
|
||||||
List<Role> roles = new List<Role>();
|
var roles = new List<Role>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -52,7 +48,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="roleIds"></param>
|
/// <param name="roleIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveRolesByUserId(int id, IEnumerable<int> roleIds)
|
public override bool SaveRolesByUserId(int id, IEnumerable<int> roleIds)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
|
@ -60,16 +56,16 @@ namespace Bootstrap.DataAccess
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
//判断用户是否选定角色
|
//判断用户是否选定角色
|
||||||
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// delete user from config table
|
// delete user from config table
|
||||||
string sql = "delete from UserRole where UserID = @UserID;";
|
string sql = "delete from UserRole where UserID = @UserID;";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
if (dt.Rows.Count > 0)
|
if (dt.Rows.Count > 0)
|
||||||
{
|
{
|
||||||
// insert batch data into config table
|
// insert batch data into config table
|
||||||
|
@ -98,16 +94,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// 查询某个用户所拥有的角色
|
/// 查询某个用户所拥有的角色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Role> RetrieveRolesByUserId(int userId)
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRolesByUserId(int userId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId);
|
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId);
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
List<Role> roles = new List<Role>();
|
List<Role> roles = new List<Role>();
|
||||||
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -127,14 +123,14 @@ namespace Bootstrap.DataAccess
|
||||||
/// 删除角色表
|
/// 删除角色表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
public static bool DeleteRole(IEnumerable<int> value)
|
public override bool DeleteRole(IEnumerable<int> value)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
var ids = string.Join(",", value);
|
var ids = string.Join(",", value);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(roleIds: value);
|
CacheCleanUtility.ClearCache(roleIds: value);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -144,7 +140,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="p"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveRole(Role p)
|
public override bool SaveRole(Bootstrap.DataAccess.Role p)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
|
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
|
||||||
|
@ -152,12 +148,12 @@ namespace Bootstrap.DataAccess
|
||||||
string sql = p.Id == 0 ?
|
string sql = p.Id == 0 ?
|
||||||
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
||||||
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleName", p.RoleName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -167,16 +163,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="menuId"></param>
|
/// <param name="menuId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId)
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRolesByMenuId(int menuId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
|
string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
|
||||||
var ret = CacheManager.GetOrAdd(key, k =>
|
var ret = CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
|
||||||
List<Role> roles = new List<Role>();
|
List<Role> roles = new List<Role>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -199,7 +195,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="roleIds"></param>
|
/// <param name="roleIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds)
|
public override bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
|
@ -207,16 +203,16 @@ namespace Bootstrap.DataAccess
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
//判断用户是否选定角色
|
//判断用户是否选定角色
|
||||||
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// delete role from config table
|
// delete role from config table
|
||||||
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
|
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
|
||||||
// insert batch data into config table
|
// insert batch data into config table
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
@ -245,16 +241,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="groupId"></param>
|
/// <param name="groupId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId)
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRolesByGroupId(int groupId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId);
|
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId);
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
List<Role> roles = new List<Role>();
|
List<Role> roles = new List<Role>();
|
||||||
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -277,7 +273,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="roleIds"></param>
|
/// <param name="roleIds"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds)
|
public override bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
//构造表格
|
//构造表格
|
||||||
|
@ -285,16 +281,16 @@ namespace Bootstrap.DataAccess
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// delete user from config table
|
// delete user from config table
|
||||||
string sql = "delete from RoleGroup where GroupID=@GroupID";
|
string sql = "delete from RoleGroup where GroupID=@GroupID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
|
||||||
// insert batch data into config table
|
// insert batch data into config table
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
|
@ -4,23 +4,22 @@ using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
public static class TaskHelper
|
public class Task : Bootstrap.DataAccess.Task
|
||||||
{
|
{
|
||||||
private const string RetrieveTasksDataKey = "TaskHelper-RetrieveTasks";
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有任务
|
/// 查询所有任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Task> RetrieveTasks()
|
public override IEnumerable<Bootstrap.DataAccess.Task> RetrieveTasks()
|
||||||
{
|
{
|
||||||
return CacheManager.GetOrAdd(RetrieveTasksDataKey, key =>
|
return CacheManager.GetOrAdd(RetrieveTasksDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select top 1000 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc";
|
string sql = "select top 1000 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc";
|
||||||
List<Task> tasks = new List<Task>();
|
List<Task> tasks = new List<Task>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
|
@ -10,31 +10,27 @@ using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户表相关操作类
|
/// 用户表实体类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class UserHelper
|
public class User : Bootstrap.DataAccess.User
|
||||||
{
|
{
|
||||||
internal const string RetrieveUsersDataKey = "BootstrapUser-RetrieveUsers";
|
|
||||||
internal const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId";
|
|
||||||
internal const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId";
|
|
||||||
internal const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有用户
|
/// 查询所有用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<User> RetrieveUsers()
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveUsers()
|
||||||
{
|
{
|
||||||
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
|
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
|
||||||
{
|
{
|
||||||
List<User> users = new List<User>();
|
List<User> users = new List<User>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
||||||
|
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -57,14 +53,14 @@ namespace Bootstrap.DataAccess
|
||||||
/// 查询所有的新注册用户
|
/// 查询所有的新注册用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<User> RetrieveNewUsers()
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveNewUsers()
|
||||||
{
|
{
|
||||||
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
|
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
|
||||||
{
|
{
|
||||||
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
|
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
|
||||||
List<User> users = new List<User>();
|
List<User> users = new List<User>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -85,14 +81,14 @@ namespace Bootstrap.DataAccess
|
||||||
/// 删除用户
|
/// 删除用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
public static bool DeleteUser(IEnumerable<int> value)
|
public override bool DeleteUser(IEnumerable<int> value)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
var ids = string.Join(",", value);
|
var ids = string.Join(",", value);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: value);
|
if (ret) CacheCleanUtility.ClearCache(userIds: value);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -102,22 +98,22 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="p"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveUser(User p)
|
public override bool SaveUser(Bootstrap.DataAccess.User p)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
||||||
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
|
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
|
||||||
p.PassSalt = LgbCryptography.GenerateSalt();
|
p.PassSalt = LgbCryptography.GenerateSalt();
|
||||||
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", p.UserName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@password", p.Password));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@passSalt", p.PassSalt));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@displayName", p.DisplayName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", DBAccessFactory.ToDBValue(p.ApprovedBy)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@description", p.Description));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -129,19 +125,19 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="password"></param>
|
/// <param name="password"></param>
|
||||||
/// <param name="displayName"></param>
|
/// <param name="displayName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool UpdateUser(int id, string password, string displayName)
|
public override bool UpdateUser(int id, string password, string displayName)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
|
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
|
||||||
var passSalt = LgbCryptography.GenerateSalt();
|
var passSalt = LgbCryptography.GenerateSalt();
|
||||||
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", displayName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", newPassword));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", passSalt));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
|
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -152,15 +148,15 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="approvedBy"></param>
|
/// <param name="approvedBy"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool ApproveUser(int id, string approvedBy)
|
public override bool ApproveUser(int id, string approvedBy)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id";
|
var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", approvedBy));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -168,44 +164,19 @@ namespace Bootstrap.DataAccess
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
/// <param name="newPass"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool ChangePassword(string userName, string password, string newPass)
|
|
||||||
{
|
|
||||||
bool ret = false;
|
|
||||||
if (BootstrapUser.Authenticate(userName, password))
|
|
||||||
{
|
|
||||||
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
|
|
||||||
var passSalt = LgbCryptography.GenerateSalt();
|
|
||||||
var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
|
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
|
||||||
{
|
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", newPassword));
|
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", passSalt));
|
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="rejectBy"></param>
|
/// <param name="rejectBy"></param>
|
||||||
/// <param name="reason"></param>
|
/// <param name="reason"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool RejectUser(int id, string rejectBy)
|
public override bool RejectUser(int id, string rejectBy)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedBy", rejectBy));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedReason", "未填写"));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -215,16 +186,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="roleId"></param>
|
/// <param name="roleId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<User> RetrieveUsersByRoleId(int roleId)
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveUsersByRoleId(int roleId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
|
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
List<User> users = new List<User>();
|
List<User> users = new List<User>();
|
||||||
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
|
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -246,23 +217,23 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id">角色ID</param>
|
/// <param name="id">角色ID</param>
|
||||||
/// <param name="userIds">用户ID数组</param>
|
/// <param name="userIds">用户ID数组</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveUsersByRoleId(int id, IEnumerable<int> userIds)
|
public override bool SaveUsersByRoleId(int id, IEnumerable<int> userIds)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
dt.Columns.Add("UserID", typeof(int));
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
|
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//删除用户角色表该角色所有的用户
|
//删除用户角色表该角色所有的用户
|
||||||
string sql = "delete from UserRole where RoleID=@RoleID";
|
string sql = "delete from UserRole where RoleID=@RoleID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
//批插入用户角色表
|
//批插入用户角色表
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
{
|
{
|
||||||
|
@ -289,16 +260,16 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="groupId"></param>
|
/// <param name="groupId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId)
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveUsersByGroupId(int groupId)
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
|
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
List<User> users = new List<User>();
|
List<User> users = new List<User>();
|
||||||
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
|
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
@ -320,23 +291,23 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="id">GroupID</param>
|
/// <param name="id">GroupID</param>
|
||||||
/// <param name="userIds">用户ID数组</param>
|
/// <param name="userIds">用户ID数组</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveUsersByGroupId(int id, IEnumerable<int> userIds)
|
public override bool SaveUsersByGroupId(int id, IEnumerable<int> userIds)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
DataTable dt = new DataTable();
|
DataTable dt = new DataTable();
|
||||||
dt.Columns.Add("UserID", typeof(int));
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
|
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//删除用户角色表该角色所有的用户
|
//删除用户角色表该角色所有的用户
|
||||||
string sql = "delete from UserGroup where GroupID = @GroupID";
|
string sql = "delete from UserGroup where GroupID = @GroupID";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
//批插入用户角色表
|
//批插入用户角色表
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
{
|
{
|
||||||
|
@ -364,15 +335,15 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="iconName"></param>
|
/// <param name="iconName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveUserIconByName(string userName, string iconName)
|
public override bool SaveUserIconByName(string userName, string iconName)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
string sql = "Update Users set Icon = @iconName where UserName = @userName";
|
string sql = "Update Users set Icon = @iconName where UserName = @userName";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@iconName", iconName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@iconName", iconName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -383,15 +354,15 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="displayName"></param>
|
/// <param name="displayName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveDisplayName(string userName, string displayName)
|
public override bool SaveDisplayName(string userName, string displayName)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
|
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", displayName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -402,18 +373,49 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="cssName"></param>
|
/// <param name="cssName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool SaveUserCssByName(string userName, string cssName)
|
public override bool SaveUserCssByName(string userName, string cssName)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@cssName", DBAccessFactory.ToDBValue(cssName)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override BootstrapUser RetrieveUserByUserName(string userName)
|
||||||
|
{
|
||||||
|
var key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
BootstrapUser user = null;
|
||||||
|
var sql = "select UserName, DisplayName, case isnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end + Icon Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = N'头像地址' and Name = N'头像路径' where ApprovedTime is not null and UserName = @UserName";
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
var cmd = db.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
|
||||||
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
user = new BootstrapUser
|
||||||
|
{
|
||||||
|
UserName = (string)reader[0],
|
||||||
|
DisplayName = (string)reader[1],
|
||||||
|
Icon = (string)reader[2],
|
||||||
|
Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}, RetrieveUsersByNameDataKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Longbow.Cache" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Longbow.Configuration" Version="1.0.3" />
|
||||||
|
<PackageReference Include="Longbow.Data" Version="1.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,168 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Dict : DataAccess.Dict
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 删除字典中的数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">需要删除的IDs</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool DeleteDict(IEnumerable<int> value)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
var ids = string.Join(",", value);
|
||||||
|
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||||
|
CacheCleanUtility.ClearCache(dictIds: ids);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的字典信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dict"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveDict(BootstrapDict dict)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
if (dict.Category.Length > 50) dict.Category = dict.Category.Substring(0, 50);
|
||||||
|
if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50);
|
||||||
|
if (dict.Code.Length > 50) dict.Code = dict.Code.Substring(0, 50);
|
||||||
|
string sql = dict.Id == 0 ?
|
||||||
|
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
|
||||||
|
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存网站个性化设置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="code"></param>
|
||||||
|
/// <param name="category"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveSettings(BootstrapDict dict)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取字典分类名称
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<string> RetrieveCategories()
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
||||||
|
{
|
||||||
|
var ret = new List<string>();
|
||||||
|
string sql = "select distinct Category from Dicts";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
ret.Add((string)reader[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string RetrieveWebTitle()
|
||||||
|
{
|
||||||
|
var settings = RetrieveDicts();
|
||||||
|
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string RetrieveWebFooter()
|
||||||
|
{
|
||||||
|
var settings = RetrieveDicts();
|
||||||
|
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获得系统中配置的可以使用的网站样式
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<BootstrapDict> RetrieveThemes()
|
||||||
|
{
|
||||||
|
var data = RetrieveDicts();
|
||||||
|
return data.Where(d => d.Category == "网站样式");
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获得网站设置中的当前样式
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string RetrieveActiveTheme()
|
||||||
|
{
|
||||||
|
var data = RetrieveDicts();
|
||||||
|
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
|
||||||
|
return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取头像路径
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override BootstrapDict RetrieveIconFolderPath()
|
||||||
|
{
|
||||||
|
var data = RetrieveDicts();
|
||||||
|
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获得默认的前台首页地址,默认为~/Home/Index
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string RetrieveHomeUrl()
|
||||||
|
{
|
||||||
|
var settings = RetrieveDicts();
|
||||||
|
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<KeyValuePair<string, string>> RetrieveApps()
|
||||||
|
{
|
||||||
|
var settings = RetrieveDicts();
|
||||||
|
return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Configuration;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Exceptions : DataAccess.Exceptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ex"></param>
|
||||||
|
/// <param name="additionalInfo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override void Log(Exception ex, NameValueCollection additionalInfo)
|
||||||
|
{
|
||||||
|
if (additionalInfo == null)
|
||||||
|
{
|
||||||
|
additionalInfo = new NameValueCollection
|
||||||
|
{
|
||||||
|
["UserId"] = null,
|
||||||
|
["UserIp"] = null,
|
||||||
|
["ErrorPage"] = null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
|
||||||
|
var sql = "insert into Exceptions (ID, AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (NULL, @AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, datetime('now', 'localtime'))";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", DbAccessFactory.ToDBValue(additionalInfo["UserId"])));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserIp", DbAccessFactory.ToDBValue(additionalInfo["UserIp"])));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
|
CacheManager.Clear(RetrieveExceptionsDataKey);
|
||||||
|
ClearExceptions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
private static void ClearExceptions()
|
||||||
|
{
|
||||||
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
|
{
|
||||||
|
string sql = $"delete from Exceptions where LogTime < datetime('now', 'localtime', '-{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]} month')";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询一周内所有异常
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Exceptions> RetrieveExceptions()
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select * from Exceptions where LogTime > datetime('now', 'localtime', '-7 day') order by LogTime desc";
|
||||||
|
List<Exceptions> exceptions = new List<Exceptions>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
exceptions.Add(new Exceptions()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
AppDomainName = (string)reader[1],
|
||||||
|
ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
|
UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
|
||||||
|
UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
|
||||||
|
ExceptionType = (string)reader[5],
|
||||||
|
Message = (string)reader[6],
|
||||||
|
StackTrace = (string)reader[7],
|
||||||
|
LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return exceptions;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,239 @@
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Group : DataAccess.Group
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Group> RetrieveGroups(int id = 0)
|
||||||
|
{
|
||||||
|
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select * from Groups";
|
||||||
|
List<Group> groups = new List<Group>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
groups.Add(new Group()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
GroupName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
});
|
||||||
|
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids"></param>
|
||||||
|
public override bool DeleteGroup(IEnumerable<int> value)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
var ids = string.Join(",", value);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(groupIds: value);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveGroup(Bootstrap.DataAccess.Group p)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50);
|
||||||
|
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
||||||
|
string sql = p.Id == 0 ?
|
||||||
|
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
||||||
|
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户查询部门信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Group> RetrieveGroupsByUserId(int userId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
|
||||||
|
var ret = CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
|
||||||
|
List<Group> groups = new List<Group>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
groups.Add(new Group()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
GroupName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}, RetrieveGroupsByUserIdDataKey);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存用户部门关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
|
//判断用户是否选定角色
|
||||||
|
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//删除用户部门表中该用户所有的部门关系
|
||||||
|
string sql = "delete from UserGroup where UserID=@UserID;";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
|
||||||
|
// insert batch data into config table
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.BatchSize = 1000;
|
||||||
|
bulk.DestinationTableName = "UserGroup";
|
||||||
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色ID指派部门
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Group> RetrieveGroupsByRoleId(int roleId)
|
||||||
|
{
|
||||||
|
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
|
||||||
|
return CacheManager.GetOrAdd(k, key =>
|
||||||
|
{
|
||||||
|
List<Group> groups = new List<Group>();
|
||||||
|
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
groups.Add(new Group()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
GroupName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}, RetrieveGroupsByRoleIdDataKey);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
|
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//删除角色部门表该角色所有的部门
|
||||||
|
string sql = "delete from RoleGroup where RoleID=@RoleID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
//批插入角色部门表
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.BatchSize = 1000;
|
||||||
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
|
bulk.DestinationTableName = "RoleGroup";
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Log : DataAccess.Log
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Log> RetrieveLogs(string tId = null)
|
||||||
|
{
|
||||||
|
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')";
|
||||||
|
List<Log> logs = new List<Log>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
logs.Add(new Log()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
CRUD = (string)reader[1],
|
||||||
|
UserName = (string)reader[2],
|
||||||
|
LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
|
||||||
|
ClientIp = (string)reader[4],
|
||||||
|
ClientAgent = (string)reader[5],
|
||||||
|
RequestUrl = (string)reader[6]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return logs;
|
||||||
|
});
|
||||||
|
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private void DeleteLogAsync()
|
||||||
|
{
|
||||||
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
|
{
|
||||||
|
string sql = $"delete from Logs where LogTime < datetime('now', 'localtime', '-{ConfigurationManager.AppSettings["KeepLogsPeriod"]} month')";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新增的日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveLog(Bootstrap.DataAccess.Log p)
|
||||||
|
{
|
||||||
|
if (p == null) throw new ArgumentNullException("p");
|
||||||
|
bool ret = false;
|
||||||
|
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, datetime('now', 'localtime'), @ClientIp, @ClientAgent, @RequestUrl)";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
CacheManager.Clear(RetrieveLogsDataKey);
|
||||||
|
DeleteLogAsync();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,170 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Menu : DataAccess.Menu
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 删除菜单信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public override bool DeleteMenu(IEnumerable<int> value)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
var ids = string.Join(",", value);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(menuIds: value);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的菜单信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveMenu(BootstrapMenu p)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(p.Name)) return false;
|
||||||
|
bool ret = false;
|
||||||
|
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
|
||||||
|
if (p.Icon != null && p.Icon.Length > 50) p.Icon = p.Icon.Substring(0, 50);
|
||||||
|
if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000);
|
||||||
|
string sql = p.Id == 0 ?
|
||||||
|
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
|
||||||
|
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", p.Name));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Order", p.Order));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", p.Category));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Target", p.Target));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个角色所配置的菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
var menus = new List<BootstrapMenu>();
|
||||||
|
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
menus.Add(new BootstrapMenu()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return menus;
|
||||||
|
}, RetrieveMenusByRoleIdDataKey);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色ID保存当前授权菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="menuIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
|
dt.Columns.Add("NavigationID", typeof(int));
|
||||||
|
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//删除菜单角色表该角色所有的菜单
|
||||||
|
string sql = "delete from NavigationRole where RoleID=@RoleID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
//批插入菜单角色表
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.DestinationTableName = "NavigationRole";
|
||||||
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
|
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName, string activeUrl = null) => RetrieveAllMenus(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveAppMenus(string userName, string activeUrl = null) => RetrieveAppMenus(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName, string activeUrl = null) => RetrieveMenusByUserName(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
///// <summary>
|
||||||
|
/////
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="userName"></param>
|
||||||
|
///// <param name="activeUrl"></param>
|
||||||
|
///// <returns></returns>
|
||||||
|
//public override IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null) => RetrieveSystemMenus(DBAccessManager.DBAccess, userName, activeUrl);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Message : DataAccess.Message
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 所有有关userName所有消息列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static IEnumerable<DataAccess.Message> RetrieveMessages(string userName)
|
||||||
|
{
|
||||||
|
var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
|
||||||
|
List<Message> messages = new List<Message>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
messages.Add(new Message()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
Title = (string)reader[1],
|
||||||
|
Content = (string)reader[2],
|
||||||
|
From = (string)reader[3],
|
||||||
|
To = (string)reader[4],
|
||||||
|
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
|
||||||
|
Status = (string)reader[6],
|
||||||
|
Mark = LgbConvert.ReadValue(reader[7], 0),
|
||||||
|
IsDelete = LgbConvert.ReadValue(reader[8], 0),
|
||||||
|
Label = (string)reader[9],
|
||||||
|
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
|
||||||
|
FromIcon = (string)reader[11],
|
||||||
|
FromDisplayName = (string)reader[12]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
|
||||||
|
});
|
||||||
|
return messageRet.OrderByDescending(n => n.SendTime);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 收件箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
public override IEnumerable<DataAccess.Message> Inbox(string userName)
|
||||||
|
{
|
||||||
|
var messageRet = RetrieveMessages(userName);
|
||||||
|
return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 发件箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Message> SendMail(string userName)
|
||||||
|
{
|
||||||
|
var messageRet = RetrieveMessages(userName);
|
||||||
|
return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 垃圾箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Message> Trash(string userName)
|
||||||
|
{
|
||||||
|
var messageRet = RetrieveMessages(userName);
|
||||||
|
return messageRet.Where(n => n.IsDelete == 1);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 标旗
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Message> Flag(string userName)
|
||||||
|
{
|
||||||
|
var messageRet = RetrieveMessages(userName);
|
||||||
|
return messageRet.Where(n => n.Mark == 1);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Header处显示的消息列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Message> RetrieveMessagesHeader(string userName)
|
||||||
|
{
|
||||||
|
var messageRet = Inbox(userName);
|
||||||
|
messageRet.AsParallel().ForAll(n =>
|
||||||
|
{
|
||||||
|
var ts = DateTime.Now - n.SendTime;
|
||||||
|
if (ts.TotalMinutes < 5) n.Period = "刚刚";
|
||||||
|
else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days);
|
||||||
|
else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
|
||||||
|
else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
|
||||||
|
});
|
||||||
|
return messageRet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,319 @@
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Role : DataAccess.Role
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Role> RetrieveRoles(int id = 0)
|
||||||
|
{
|
||||||
|
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select * from Roles";
|
||||||
|
var roles = new List<Role>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
roles.Add(new Role()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
RoleName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
});
|
||||||
|
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存用户角色关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveRolesByUserId(int id, IEnumerable<int> roleIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
|
//判断用户是否选定角色
|
||||||
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// delete user from config table
|
||||||
|
string sql = "delete from UserRole where UserID = @UserID;";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
if (dt.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
// insert batch data into config table
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.DestinationTableName = "UserRole";
|
||||||
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(userIds: new List<int>() { id }, roleIds: roleIds);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个用户所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Role> RetrieveRolesByUserId(int userId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
List<Role> roles = new List<Role>();
|
||||||
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
roles.Add(new Role()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
RoleName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
}, RetrieveRolesByUserIdDataKey);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除角色表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public override bool DeleteRole(IEnumerable<int> value)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
var ids = string.Join(",", value);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(roleIds: value);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的角色信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveRole(DataAccess.Role p)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
|
||||||
|
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 50) p.Description = p.Description.Substring(0, 500);
|
||||||
|
string sql = p.Id == 0 ?
|
||||||
|
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
||||||
|
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个菜单所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="menuId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Role> RetrieveRolesByMenuId(int menuId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
|
||||||
|
var ret = CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
|
||||||
|
List<Role> roles = new List<Role>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
roles.Add(new Role()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
RoleName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
}, RetrieveRolesByMenuIdDataKey);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("NavigationID", typeof(int));
|
||||||
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
|
//判断用户是否选定角色
|
||||||
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// delete role from config table
|
||||||
|
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
|
||||||
|
// insert batch data into config table
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.BatchSize = 1000;
|
||||||
|
bulk.DestinationTableName = "NavigationRole";
|
||||||
|
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
|
||||||
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据GroupId查询和该Group有关的所有Roles
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Role> RetrieveRolesByGroupId(int groupId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
List<Role> roles = new List<Role>();
|
||||||
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
roles.Add(new Role()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
RoleName = (string)reader[1],
|
||||||
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
}, RetrieveRolesByGroupIdDataKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
//构造表格
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// delete user from config table
|
||||||
|
string sql = "delete from RoleGroup where GroupID=@GroupID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
|
||||||
|
// insert batch data into config table
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.BatchSize = 1000;
|
||||||
|
bulk.DestinationTableName = "RoleGroup";
|
||||||
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
public class Task : DataAccess.Task
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有任务
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.Task> RetrieveTasks()
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(RetrieveTasksDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000";
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
tasks.Add(new Task()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
TaskName = (string)reader[1],
|
||||||
|
AssignName = (string)reader[2],
|
||||||
|
UserName = (string)reader[3],
|
||||||
|
TaskTime = LgbConvert.ReadValue(reader[4], 0),
|
||||||
|
TaskProgress = (double)reader[5],
|
||||||
|
AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue),
|
||||||
|
AssignDisplayName = (string)reader[7]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tasks;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,420 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Data;
|
||||||
|
using Longbow.Security;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess.SQLite
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户表实体类
|
||||||
|
/// </summary>
|
||||||
|
public class User : DataAccess.User
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.User> RetrieveUsers()
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
|
||||||
|
{
|
||||||
|
List<User> users = new List<User>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
||||||
|
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
users.Add(new User()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
UserName = (string)reader[1],
|
||||||
|
DisplayName = (string)reader[2],
|
||||||
|
RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
|
||||||
|
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue),
|
||||||
|
ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
|
||||||
|
Description = (string)reader[6]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有的新注册用户
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.User> RetrieveNewUsers()
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
|
||||||
|
List<User> users = new List<User>();
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
users.Add(new User()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
UserName = (string)reader[1],
|
||||||
|
DisplayName = (string)reader[2],
|
||||||
|
RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
|
||||||
|
Description = (string)reader[4]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public override bool DeleteUser(IEnumerable<int> value)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
var ids = string.Join(",", value);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(userIds: value);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveUser(DataAccess.User p)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
||||||
|
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
|
||||||
|
p.PassSalt = LgbCryptography.GenerateSalt();
|
||||||
|
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <param name="displayName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool UpdateUser(int id, string password, string displayName)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
|
||||||
|
var passSalt = LgbCryptography.GenerateSalt();
|
||||||
|
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="approvedBy"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool ApproveUser(int id, string approvedBy)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
var sql = "update Users set ApprovedTime = datetime('now', 'localtime'), ApprovedBy = @approvedBy where ID = @id";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="rejectBy"></param>
|
||||||
|
/// <param name="reason"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool RejectUser(int id, string rejectBy)
|
||||||
|
{
|
||||||
|
var ret = false;
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过roleId获取所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.User> RetrieveUsersByRoleId(int roleId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
List<User> users = new List<User>();
|
||||||
|
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
users.Add(new User()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
UserName = (string)reader[1],
|
||||||
|
DisplayName = (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
}, RetrieveUsersByRoleIdDataKey);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色ID保存当前授权用户(插入)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">角色ID</param>
|
||||||
|
/// <param name="userIds">用户ID数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveUsersByRoleId(int id, IEnumerable<int> userIds)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
|
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//删除用户角色表该角色所有的用户
|
||||||
|
string sql = "delete from UserRole where RoleID=@RoleID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
//批插入用户角色表
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.DestinationTableName = "UserRole";
|
||||||
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过groupId获取所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<DataAccess.User> RetrieveUsersByGroupId(int groupId)
|
||||||
|
{
|
||||||
|
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
List<User> users = new List<User>();
|
||||||
|
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
|
||||||
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
users.Add(new User()
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
UserName = (string)reader[1],
|
||||||
|
DisplayName = (string)reader[2],
|
||||||
|
Checked = (string)reader[3]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
}, RetrieveUsersByRoleIdDataKey);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过部门ID保存当前授权用户(插入)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">GroupID</param>
|
||||||
|
/// <param name="userIds">用户ID数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveUsersByGroupId(int id, IEnumerable<int> userIds)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
DataTable dt = new DataTable();
|
||||||
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
|
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
|
||||||
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//删除用户角色表该角色所有的用户
|
||||||
|
string sql = "delete from UserGroup where GroupID = @GroupID";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
|
||||||
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
|
//批插入用户角色表
|
||||||
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
|
bulk.DestinationTableName = "UserGroup";
|
||||||
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
|
bulk.WriteToServer(dt);
|
||||||
|
transaction.CommitTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<int>() { id });
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.RollbackTransaction();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户名修改用户头像
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="iconName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveUserIconByName(string userName, string iconName)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
string sql = "Update Users set Icon = @iconName where UserName = @userName";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@iconName", iconName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="displayName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveDisplayName(string userName, string displayName)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户名更改用户皮肤
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="cssName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool SaveUserCssByName(string userName, string cssName)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override BootstrapUser RetrieveUserByUserName(string userName)
|
||||||
|
{
|
||||||
|
var key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
|
||||||
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
BootstrapUser user = null;
|
||||||
|
var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName";
|
||||||
|
var cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
|
||||||
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
user = new BootstrapUser
|
||||||
|
{
|
||||||
|
UserName = (string)reader[0],
|
||||||
|
DisplayName = (string)reader[1],
|
||||||
|
Icon = (string)reader[2],
|
||||||
|
Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}, RetrieveUsersByNameDataKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bootstrap.Security" Version="1.0.4" />
|
<PackageReference Include="Bootstrap.Security" Version="1.0.4" />
|
||||||
<PackageReference Include="Longbow.Web" Version="1.0.1" />
|
<PackageReference Include="Longbow.Web" Version="1.0.1" />
|
||||||
|
<PackageReference Include="Longbow.Cache" Version="1.0.2" />
|
||||||
|
<PackageReference Include="Longbow.Data" Version="1.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
using Bootstrap.Security;
|
using Longbow.Cache;
|
||||||
using Longbow.Cache;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
internal static class CacheCleanUtility
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class CacheCleanUtility
|
||||||
{
|
{
|
||||||
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -17,7 +19,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <param name="menuIds"></param>
|
/// <param name="menuIds"></param>
|
||||||
/// <param name="dictIds"></param>
|
/// <param name="dictIds"></param>
|
||||||
/// <param name="cacheKey"></param>
|
/// <param name="cacheKey"></param>
|
||||||
internal static void ClearCache(IEnumerable<int> roleIds = null, IEnumerable<int> userIds = null, IEnumerable<int> groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null)
|
public static void ClearCache(IEnumerable<int> roleIds = null, IEnumerable<int> userIds = null, IEnumerable<int> groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null)
|
||||||
{
|
{
|
||||||
var cacheKeys = new List<string>();
|
var cacheKeys = new List<string>();
|
||||||
var corsKeys = new List<string>();
|
var corsKeys = new List<string>();
|
||||||
|
@ -25,55 +27,55 @@ namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
roleIds.ToList().ForEach(id =>
|
roleIds.ToList().ForEach(id =>
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByRoleIdDataKey, id));
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByRoleIdDataKey, id));
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", Menu.RetrieveMenusByRoleIdDataKey, id));
|
||||||
});
|
});
|
||||||
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
cacheKeys.Add(Role.RetrieveRolesDataKey + "*");
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
}
|
}
|
||||||
if (userIds != null)
|
if (userIds != null)
|
||||||
{
|
{
|
||||||
userIds.ToList().ForEach(id =>
|
userIds.ToList().ForEach(id =>
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByUserIdDataKey, id));
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByUserIdDataKey, id));
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
});
|
});
|
||||||
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
cacheKeys.Add(User.RetrieveNewUsersDataKey + "*");
|
||||||
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
cacheKeys.Add(User.RetrieveUsersDataKey + "*");
|
||||||
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
corsKeys.Add(User.RetrieveUsersDataKey + "*");
|
||||||
}
|
}
|
||||||
if (groupIds != null)
|
if (groupIds != null)
|
||||||
{
|
{
|
||||||
groupIds.ToList().ForEach(id =>
|
groupIds.ToList().ForEach(id =>
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByGroupIdDataKey, id));
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByGroupIdDataKey, id));
|
||||||
});
|
});
|
||||||
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
cacheKeys.Add(Group.RetrieveGroupsDataKey + "*");
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
||||||
}
|
}
|
||||||
if (menuIds != null)
|
if (menuIds != null)
|
||||||
{
|
{
|
||||||
menuIds.ToList().ForEach(id =>
|
menuIds.ToList().ForEach(id =>
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByMenuIdDataKey, id));
|
||||||
});
|
});
|
||||||
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusByRoleIdDataKey + "*");
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
}
|
}
|
||||||
if (dictIds != null)
|
if (dictIds != null)
|
||||||
{
|
{
|
||||||
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
cacheKeys.Add(Dict.RetrieveDictsDataKey + "*");
|
||||||
cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
|
cacheKeys.Add(Dict.RetrieveCategoryDataKey);
|
||||||
corsKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
corsKeys.Add(Dict.RetrieveDictsDataKey + "*");
|
||||||
}
|
}
|
||||||
if (cacheKey != null)
|
if (cacheKey != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,9 +8,11 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DBAccessManager
|
public static class DBAccessManager
|
||||||
{
|
{
|
||||||
private static readonly Lazy<IDBAccess> db = new Lazy<IDBAccess>(() => DBAccessFactory.CreateDB("ba"), true);
|
private static readonly Lazy<IDbAccess> db = new Lazy<IDbAccess>(() => DbAccessFactory.CreateDB("ba"), true);
|
||||||
|
/// <summary>
|
||||||
public static IDBAccess SqlDBAccess
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static IDbAccess DBAccess
|
||||||
{
|
{
|
||||||
get { return db.Value; }
|
get { return db.Value; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Dict : BootstrapDict
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
|
||||||
|
/// <summary>
|
||||||
|
/// 缓存索引,BootstrapAdmin后台清理缓存时使用
|
||||||
|
/// </summary>
|
||||||
|
public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts";
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<KeyValuePair<string, string>> RetrieveApps() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 删除字典中的数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">需要删除的IDs</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool DeleteDict(IEnumerable<int> value) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的字典信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dict"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveDict(BootstrapDict dict) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存网站个性化设置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="code"></param>
|
||||||
|
/// <param name="category"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveSettings(BootstrapDict dict) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 获取字典分类名称
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<string> RetrieveCategories() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual string RetrieveWebTitle() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual string RetrieveWebFooter() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 获得系统中配置的可以使用的网站样式
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapDict> RetrieveThemes() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 获得网站设置中的当前样式
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual string RetrieveActiveTheme() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 获取头像路径
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual BootstrapDict RetrieveIconFolderPath() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 获得默认的前台首页地址,默认为~/Home/Index
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual string RetrieveHomeUrl() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过数据库获得所有字典表配置信息,缓存Key=DictHelper-RetrieveDicts
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db">数据库连接实例</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapDict> RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key =>
|
||||||
|
{
|
||||||
|
string sql = "select ID, Category, Name, Code, Define from Dicts";
|
||||||
|
var Dicts = new List<BootstrapDict>();
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
var cmd = db.CreateCommand(CommandType.Text, sql);
|
||||||
|
using (var reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Dicts.Add(new BootstrapDict
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
Category = (string)reader[1],
|
||||||
|
Name = (string)reader[2],
|
||||||
|
Code = (string)reader[3],
|
||||||
|
Define = LgbConvert.ReadValue(reader[4], 0)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Dicts;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -6,6 +9,10 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Exceptions
|
public class Exceptions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
protected const string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -46,5 +53,17 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得/设置 时间描述 2分钟内为刚刚
|
/// 获得/设置 时间描述 2分钟内为刚刚
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Period { get; set; }
|
public string Period { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ex"></param>
|
||||||
|
/// <param name="additionalInfo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual void Log(Exception ex, NameValueCollection additionalInfo) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 查询一周内所有异常
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Exceptions> RetrieveExceptions() => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
namespace Bootstrap.DataAccess
|
using Longbow.Cache;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
|
public const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups";
|
||||||
|
public const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId";
|
||||||
|
public const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId";
|
||||||
|
public const string RetrieveGroupsByUserNameDataKey = "BootstrapAdminGroupMiddleware-RetrieveGroupsByUserName";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得/设置 群组主键ID
|
/// 获得/设置 群组主键ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -24,5 +34,74 @@
|
||||||
/// 获取/设置 用户群组关联状态 checked 标示已经关联 '' 标示未关联
|
/// 获取/设置 用户群组关联状态 checked 标示已经关联 '' 标示未关联
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Checked { get; set; }
|
public string Checked { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Group> RetrieveGroups(int id = 0) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 删除群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids"></param>
|
||||||
|
public virtual bool DeleteGroup(IEnumerable<int> value) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveGroup(Group p) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户查询部门信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Group> RetrieveGroupsByUserId(int userId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存用户部门关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色ID指派部门
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Group> RetrieveGroupsByRoleId(int roleId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="connName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<string> RetrieveGroupsByUserName(string userName)
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r =>
|
||||||
|
{
|
||||||
|
var entities = new List<string>();
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select g.GroupName, g.[Description] from Groups g inner join UserGroup ug on g.ID = ug.GroupID inner join Users u on ug.UserID = u.ID where UserName = @UserName"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
|
||||||
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
entities.Add((string)reader[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entities;
|
||||||
|
}, RetrieveGroupsByUserNameDataKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class DictHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapDict> RetrieveDicts() => DbAdapterManager.Create<Dict>().RetrieveDicts();
|
||||||
|
/// <summary>
|
||||||
|
/// 删除字典中的数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">需要删除的IDs</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool DeleteDict(IEnumerable<int> value) => DbAdapterManager.Create<Dict>().DeleteDict(value);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的字典信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveDict(BootstrapDict p) => DbAdapterManager.Create<Dict>().SaveDict(p);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存网站个性化设置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="code"></param>
|
||||||
|
/// <param name="category"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveSettings(BootstrapDict dict) => DbAdapterManager.Create<Dict>().SaveSettings(dict);
|
||||||
|
/// <summary>
|
||||||
|
/// 获取字典分类名称
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveCategories() => DbAdapterManager.Create<Dict>().RetrieveCategories();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string RetrieveWebTitle() => DbAdapterManager.Create<Dict>().RetrieveWebTitle();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string RetrieveWebFooter() => DbAdapterManager.Create<Dict>().RetrieveWebFooter();
|
||||||
|
/// <summary>
|
||||||
|
/// 获得系统中配置的可以使用的网站样式
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapDict> RetrieveThemes() => DbAdapterManager.Create<Dict>().RetrieveThemes();
|
||||||
|
/// <summary>
|
||||||
|
/// 获得网站设置中的当前样式
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string RetrieveActiveTheme() => DbAdapterManager.Create<Dict>().RetrieveActiveTheme();
|
||||||
|
/// <summary>
|
||||||
|
/// 获取头像路径
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static BootstrapDict RetrieveIconFolderPath() => DbAdapterManager.Create<Dict>().RetrieveIconFolderPath();
|
||||||
|
/// <summary>
|
||||||
|
/// 获得默认的前台首页地址,默认为~/Home/Index
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string RetrieveHomeUrl() => DbAdapterManager.Create<Dict>().RetrieveHomeUrl();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbAdapterManager.Create<Dict>().RetrieveApps();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class ExceptionsHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ex"></param>
|
||||||
|
/// <param name="additionalInfo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static void Log(Exception ex, NameValueCollection additionalInfo) => DbAdapterManager.Create<Exceptions>().Log(ex, additionalInfo);
|
||||||
|
/// <summary>
|
||||||
|
/// 查询一周内所有异常
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Exceptions> RetrieveExceptions() => DbAdapterManager.Create<Exceptions>().RetrieveExceptions();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// author:liuchun
|
||||||
|
/// date:2016.10.22
|
||||||
|
/// </summary>
|
||||||
|
public static class GroupHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Group> RetrieveGroups(int id = 0) => DbAdapterManager.Create<Group>().RetrieveGroups(id);
|
||||||
|
/// <summary>
|
||||||
|
/// 删除群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids"></param>
|
||||||
|
public static bool DeleteGroup(IEnumerable<int> value) => DbAdapterManager.Create<Group>().DeleteGroup(value);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的群组信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveGroup(Group p) => DbAdapterManager.Create<Group>().SaveGroup(p);
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户查询部门信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Group> RetrieveGroupsByUserId(int userId) => DbAdapterManager.Create<Group>().RetrieveGroupsByUserId(userId);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存用户部门关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds) => DbAdapterManager.Create<Group>().SaveGroupsByUserId(id, groupIds);
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色ID指派部门
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId) => DbAdapterManager.Create<Group>().RetrieveGroupsByRoleId(roleId);
|
||||||
|
/// <summary>
|
||||||
|
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="groupIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds) => DbAdapterManager.Create<Group>().SaveGroupsByRoleId(id, groupIds);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
public static class LogHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Log> RetrieveLogs(string tId = null) => DbAdapterManager.Create<Log>().RetrieveLogs(tId);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新增的日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveLog(Log p) => DbAdapterManager.Create<Log>().SaveLog(p);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class MenuHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveMenu(BootstrapMenu value) => DbAdapterManager.Create<Menu>().SaveMenu(value);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool DeleteMenu(IEnumerable<int> value) => DbAdapterManager.Create<Menu>().DeleteMenu(value);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName) => DbAdapterManager.Create<Menu>().RetrieveMenusByUserName(userName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int id) => DbAdapterManager.Create<Menu>().RetrieveMenusByRoleId(id);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveMenusByRoleId(int id, IEnumerable<int> value) => DbAdapterManager.Create<Menu>().SaveMenusByRoleId(id, value);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string name, string url) => DbAdapterManager.Create<Menu>().RetrieveAppMenus(name, url);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="activeUrl"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null) => DbAdapterManager.Create<Menu>().RetrieveSystemMenus(userName, activeUrl);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<BootstrapMenu> RetrieveAllMenus(string name) => DbAdapterManager.Create<Menu>().RetrieveAllMenus(name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class MessageHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 收件箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
public static IEnumerable<Message> Inbox(string userName) => DbAdapterManager.Create<Message>().Inbox(userName);
|
||||||
|
/// <summary>
|
||||||
|
/// 发件箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Message> SendMail(string userName) => DbAdapterManager.Create<Message>().SendMail(userName);
|
||||||
|
/// <summary>
|
||||||
|
/// 垃圾箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Message> Trash(string userName) => DbAdapterManager.Create<Message>().Trash(userName);
|
||||||
|
/// <summary>
|
||||||
|
/// 标旗
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Message> Mark(string userName) => DbAdapterManager.Create<Message>().Flag(userName);
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Header处显示的消息列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Message> RetrieveMessagesHeader(string userName) => DbAdapterManager.Create<Message>().RetrieveMessagesHeader(userName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class RoleHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Role> RetrieveRoles(int id = 0) => DbAdapterManager.Create<Role>().RetrieveRoles(id);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存用户角色关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveRolesByUserId(int id, IEnumerable<int> roleIds) => DbAdapterManager.Create<Role>().SaveRolesByUserId(id, roleIds);
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个用户所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Role> RetrieveRolesByUserId(int userId) => DbAdapterManager.Create<Role>().RetrieveRolesByUserId(userId);
|
||||||
|
/// <summary>
|
||||||
|
/// 删除角色表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public static bool DeleteRole(IEnumerable<int> value) => DbAdapterManager.Create<Role>().DeleteRole(value);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的角色信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveRole(Role p) => DbAdapterManager.Create<Role>().SaveRole(p);
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个菜单所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="menuId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId) => DbAdapterManager.Create<Role>().RetrieveRolesByMenuId(menuId);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds) => DbAdapterManager.Create<Role>().SavaRolesByMenuId(id, roleIds);
|
||||||
|
/// <summary>
|
||||||
|
/// 根据GroupId查询和该Group有关的所有Roles
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId) => DbAdapterManager.Create<Role>().RetrieveRolesByGroupId(groupId);
|
||||||
|
/// <summary>
|
||||||
|
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds) => DbAdapterManager.Create<Role>().SaveRolesByGroupId(id, roleIds);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => DbAdapterManager.Create<Role>().RetrieveRolesByUserName(userName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<string> RetrieveRolesByUrl(string url) => DbAdapterManager.Create<Role>().RetrieveRolesByUrl(url);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
public static class TaskHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有任务
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<Task> RetrieveTasks() => DbAdapterManager.Create<Task>().RetrieveTasks();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户表相关操作类
|
||||||
|
/// </summary>
|
||||||
|
public static class UserHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<User> RetrieveUsers() => DbAdapterManager.Create<User>().RetrieveUsers();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool Authenticate(string userName, string password) => DbAdapterManager.Create<User>().Authenticate(userName, password);
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有的新注册用户
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<User> RetrieveNewUsers() => DbAdapterManager.Create<User>().RetrieveNewUsers();
|
||||||
|
/// <summary>
|
||||||
|
/// 删除用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public static bool DeleteUser(IEnumerable<int> value) => DbAdapterManager.Create<User>().DeleteUser(value);
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveUser(User p) => DbAdapterManager.Create<User>().SaveUser(p);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <param name="displayName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool UpdateUser(int id, string password, string displayName) => DbAdapterManager.Create<User>().UpdateUser(id, password, displayName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="approvedBy"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool ApproveUser(int id, string approvedBy) => DbAdapterManager.Create<User>().ApproveUser(id, approvedBy);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <param name="newPass"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool ChangePassword(string userName, string password, string newPass) => DbAdapterManager.Create<User>().ChangePassword(userName, password, newPass);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="rejectBy"></param>
|
||||||
|
/// <param name="reason"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool RejectUser(int id, string rejectBy) => DbAdapterManager.Create<User>().RejectUser(id, rejectBy);
|
||||||
|
/// <summary>
|
||||||
|
/// 通过roleId获取所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<User> RetrieveUsersByRoleId(int roleId) => DbAdapterManager.Create<User>().RetrieveUsersByRoleId(roleId);
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色ID保存当前授权用户(插入)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">角色ID</param>
|
||||||
|
/// <param name="userIds">用户ID数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveUsersByRoleId(int id, IEnumerable<int> userIds) => DbAdapterManager.Create<User>().SaveUsersByRoleId(id, userIds);
|
||||||
|
/// <summary>
|
||||||
|
/// 通过groupId获取所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId) => DbAdapterManager.Create<User>().RetrieveUsersByGroupId(groupId);
|
||||||
|
/// <summary>
|
||||||
|
/// 通过部门ID保存当前授权用户(插入)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">GroupID</param>
|
||||||
|
/// <param name="userIds">用户ID数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveUsersByGroupId(int id, IEnumerable<int> userIds) => DbAdapterManager.Create<User>().SaveUsersByGroupId(id, userIds);
|
||||||
|
/// 根据用户名修改用户头像
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="iconName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveUserIconByName(string userName, string iconName) => DbAdapterManager.Create<User>().SaveUserIconByName(userName, iconName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="displayName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveDisplayName(string userName, string displayName) => DbAdapterManager.Create<User>().SaveDisplayName(userName, displayName);
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户名更改用户皮肤
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="cssName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool SaveUserCssByName(string userName, string cssName) => DbAdapterManager.Create<User>().SaveUserCssByName(userName, cssName);
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static BootstrapUser RetrieveUserByUserName(string name) => DbAdapterManager.Create<User>().RetrieveUserByUserName(name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
public class Log
|
public class Log
|
||||||
{
|
{
|
||||||
|
protected const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得/设置 操作日志主键ID
|
/// 获得/设置 操作日志主键ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -37,5 +40,17 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获取/设置 请求网址
|
/// 获取/设置 请求网址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string RequestUrl { get; set; }
|
public string RequestUrl { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Log> RetrieveLogs(string tId = null) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新增的日志信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveLog(Log p) => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,168 @@
|
||||||
|
using Bootstrap.Security;
|
||||||
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class Menu : BootstrapMenu
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId";
|
||||||
|
public const string RetrieveMenusDataKey = "BootstrapMenu-RetrieveMenusByUserName";
|
||||||
|
public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus";
|
||||||
|
/// <summary>
|
||||||
|
/// 删除菜单信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public virtual bool DeleteMenu(IEnumerable<int> value) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的菜单信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveMenu(BootstrapMenu p) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个角色所配置的菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色ID保存当前授权菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="menuIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过当前用户名获得所有菜单,层次化后集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName">当前登陆的用户名</param>
|
||||||
|
/// <param name="activeUrl">当前访问菜单</param>
|
||||||
|
/// <param name="connName">连接字符串名称,默认为ba</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName, string activeUrl = null)
|
||||||
|
{
|
||||||
|
var menus = RetrieveMenusByUserName(userName, activeUrl);
|
||||||
|
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.Category).ThenBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||||
|
CascadeMenus(menus, root);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过当前用户名获得前台菜单,层次化后集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName">当前登陆的用户名</param>
|
||||||
|
/// <param name="activeUrl">当前访问菜单</param>
|
||||||
|
/// <param name="connName">连接字符串名称,默认为ba</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapMenu> RetrieveAppMenus(string userName, string activeUrl = null)
|
||||||
|
{
|
||||||
|
var menus = RetrieveMenusByUserName(userName, activeUrl).Where(m => m.Category == "1" && m.IsResource == 0);
|
||||||
|
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||||
|
CascadeMenus(menus, root);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过当前用户名获得所有菜单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName">当前登陆的用户名</param>
|
||||||
|
/// <param name="activeUrl">当前访问菜单</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName, string activeUrl = null)
|
||||||
|
{
|
||||||
|
// TODO: 考虑第三方应用获取
|
||||||
|
var appId = LgbConvert.ReadValue(ConfigurationManager.AppSettings["AppId"], "0");
|
||||||
|
var key = string.Format("{0}-{1}-{2}", RetrieveMenusDataKey, userName, appId);
|
||||||
|
var navs = CacheManager.GetOrAdd(key, k =>
|
||||||
|
{
|
||||||
|
var menus = RetrieveAllMenus(userName);
|
||||||
|
return appId == "0" ? menus : menus.Where(m => m.ApplicationCode == appId);
|
||||||
|
}, RetrieveMenusDataKey);
|
||||||
|
if (!string.IsNullOrEmpty(activeUrl)) ActiveMenu(null, navs, activeUrl);
|
||||||
|
return navs;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过当前用户名获得后台菜单,层次化后集合
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db"></param>
|
||||||
|
/// <param name="userName">当前登陆的用户名</param>
|
||||||
|
/// <param name="activeUrl">当前访问菜单</param>
|
||||||
|
/// <param name="connName">连接字符串名称,默认为ba</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null)
|
||||||
|
{
|
||||||
|
var menus = RetrieveMenusByUserName(userName, activeUrl).Where(m => m.Category == "0" && m.IsResource == 0);
|
||||||
|
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
|
||||||
|
CascadeMenus(menus, root);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName)
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(RetrieveMenusAll, k =>
|
||||||
|
{
|
||||||
|
var menus = new List<BootstrapMenu>();
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select n.ID, n.ParentId, n.Name, n.[Order], n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.[Application], d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID 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 = @RoleName)) nav on n.ID = nav.NavigationID"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@Category", "菜单"));
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@RoleName", "Administrators"));
|
||||||
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
menus.Add(new BootstrapMenu
|
||||||
|
{
|
||||||
|
Id = LgbConvert.ReadValue(reader[0], 0),
|
||||||
|
ParentId = LgbConvert.ReadValue(reader[1], 0),
|
||||||
|
Name = (string)reader[2],
|
||||||
|
Order = LgbConvert.ReadValue(reader[3], 0),
|
||||||
|
Icon = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
|
||||||
|
Url = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
|
||||||
|
Category = (string)reader[6],
|
||||||
|
Target = (string)reader[7],
|
||||||
|
IsResource = LgbConvert.ReadValue(reader[8], false) ? 1 : 0,
|
||||||
|
ApplicationCode = reader.IsDBNull(9) ? string.Empty : (string)reader[9],
|
||||||
|
CategoryName = (string)reader[10],
|
||||||
|
ParentName = reader.IsDBNull(11) ? string.Empty : (string)reader[11],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return menus;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CascadeMenus(IEnumerable<BootstrapMenu> navs, IEnumerable<BootstrapMenu> level)
|
||||||
|
{
|
||||||
|
level.ToList().ForEach(m =>
|
||||||
|
{
|
||||||
|
m.Menus = navs.Where(sub => sub.ParentId == m.Id).OrderBy(sub => sub.Order);
|
||||||
|
CascadeMenus(navs, m.Menus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ActiveMenu(BootstrapMenu parent, IEnumerable<BootstrapMenu> menus, string url)
|
||||||
|
{
|
||||||
|
if (menus == null || !menus.Any()) return;
|
||||||
|
menus.AsParallel().ForAll(m =>
|
||||||
|
{
|
||||||
|
m.Active = m.Url.Equals(url, StringComparison.OrdinalIgnoreCase) ? "active" : "";
|
||||||
|
ActiveMenu(m, m.Menus, url);
|
||||||
|
if (parent != null && m.Active != "") parent.Active = m.Active;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -10,6 +8,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Message
|
public class Message
|
||||||
{
|
{
|
||||||
|
protected const string RetrieveMessageDataKey = "MessageHelper-RetrieveMessages";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 消息主键 数据库自增
|
/// 消息主键 数据库自增
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -66,5 +65,34 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获得/设置 发件人昵称
|
/// 获得/设置 发件人昵称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FromDisplayName { get; set; }
|
public string FromDisplayName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 收件箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
public virtual IEnumerable<Message> Inbox(string userName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 发件箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Message> SendMail(string userName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 垃圾箱
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Message> Trash(string userName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 标旗
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Message> Flag(string userName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Header处显示的消息列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Message> RetrieveMessagesHeader(string userName) => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class Notification
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string Category { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string Title { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string Content { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public DateTime RegisterTime { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public DateTime ProcessTime { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string ProcessBy { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string ProcessResult { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string Status { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 获得/设置 市场描述 2分钟内为刚刚
|
|
||||||
/// </summary>
|
|
||||||
public string Period { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,24 @@
|
||||||
namespace Bootstrap.DataAccess
|
using Longbow;
|
||||||
|
using Longbow.Cache;
|
||||||
|
using Longbow.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Role
|
public class Role
|
||||||
{
|
{
|
||||||
|
public const string RetrieveRolesDataKey = "RoleHelper-RetrieveRoles";
|
||||||
|
public const string RetrieveRolesByUserIdDataKey = "RoleHelper-RetrieveRolesByUserId";
|
||||||
|
public const string RetrieveRolesByMenuIdDataKey = "RoleHelper-RetrieveRolesByMenuId";
|
||||||
|
public const string RetrieveRolesByGroupIdDataKey = "RoleHelper-RetrieveRolesByGroupId";
|
||||||
|
public const string RetrieveRolesByUserNameDataKey = "BootstrapAdminRoleMiddleware-RetrieveRolesByUserName";
|
||||||
|
public const string RetrieveRolesByUrlDataKey = "BootstrapAdminAuthorizeFilter-RetrieveRolesByUrl";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得/设置 角色主键ID
|
/// 获得/设置 角色主键ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -21,5 +35,111 @@
|
||||||
/// 获取/设置 用户角色关联状态 checked 标示已经关联 '' 标示未关联
|
/// 获取/设置 用户角色关联状态 checked 标示已经关联 '' 标示未关联
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Checked { get; set; }
|
public string Checked { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Role> RetrieveRoles(int id = 0) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存用户角色关系
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveRolesByUserId(int id, IEnumerable<int> roleIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个用户所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Role> RetrieveRolesByUserId(int userId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 删除角色表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public virtual bool DeleteRole(IEnumerable<int> value) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建/更新的角色信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveRole(Role p) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 查询某个菜单所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="menuId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Role> RetrieveRolesByMenuId(int menuId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据GroupId查询和该Group有关的所有Roles
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Role> RetrieveRolesByGroupId(int groupId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="roleIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<string> RetrieveRolesByUserName(string userName)
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), r =>
|
||||||
|
{
|
||||||
|
var entities = new List<string>();
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "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 = @UserName union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join 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=@UserName"))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
|
||||||
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
entities.Add((string)reader[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entities;
|
||||||
|
}, RetrieveRolesByUserNameDataKey);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据菜单url查询某个所拥有的角色
|
||||||
|
/// 从NavigatorRole表查
|
||||||
|
/// 从Navigators-〉GroupNavigatorRole-〉Role查查询某个用户所拥有的角色
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<string> RetrieveRolesByUrl(string url)
|
||||||
|
{
|
||||||
|
return CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), k =>
|
||||||
|
{
|
||||||
|
string sql = "select distinct r.RoleName, r.[Description] from Roles r inner join NavigationRole nr on r.ID = nr.RoleID inner join Navigations n on nr.NavigationID = n.ID and n.[Application] = @AppId and n.Url like @Url";
|
||||||
|
var Roles = new List<string> { "Administrators" };
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
var cmd = db.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@Url", string.Format("{0}%", url)));
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@AppId", LgbConvert.ReadValue(ConfigurationManager.AppSettings["AppId"], "0")));
|
||||||
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Roles.Add((string)reader[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Roles;
|
||||||
|
}, RetrieveRolesByUrlDataKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
public class Task
|
public class Task
|
||||||
{
|
{
|
||||||
|
protected const string RetrieveTasksDataKey = "TaskHelper-RetrieveTasks";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取/设置 任务ID
|
/// 获取/设置 任务ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -36,5 +38,10 @@ namespace Bootstrap.DataAccess
|
||||||
/// 获取/设置 分配时间
|
/// 获取/设置 分配时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime AssignTime { get; set; }
|
public DateTime AssignTime { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有任务
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<Task> RetrieveTasks() => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
|
using Longbow.Security;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -8,6 +12,11 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class User : BootstrapUser
|
public class User : BootstrapUser
|
||||||
{
|
{
|
||||||
|
public const string RetrieveUsersDataKey = "BootstrapUser-RetrieveUsers";
|
||||||
|
public const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId";
|
||||||
|
public const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId";
|
||||||
|
public const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
|
||||||
|
protected const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得/设置 用户主键ID
|
/// 获得/设置 用户主键ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -53,6 +62,156 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string NewPassword { get; set; }
|
public string NewPassword { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 验证用户登陆账号与密码正确
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool Authenticate(string userName, string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false;
|
||||||
|
string oldPassword = null;
|
||||||
|
string passwordSalt = null;
|
||||||
|
string sql = "select [Password], PassSalt from Users where ApprovedTime is not null and UserName = @UserName";
|
||||||
|
var db = DBAccessManager.DBAccess;
|
||||||
|
using (DbCommand cmd = db.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
|
||||||
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
oldPassword = (string)reader[0];
|
||||||
|
passwordSalt = (string)reader[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !string.IsNullOrEmpty(passwordSalt) && oldPassword == LgbCryptography.ComputeHash(password, passwordSalt);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<User> RetrieveUsers() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 查询所有的新注册用户
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<User> RetrieveNewUsers() => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 删除用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public virtual bool DeleteUser(IEnumerable<int> value) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 保存新建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveUser(User p) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <param name="displayName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool UpdateUser(int id, string password, string displayName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="approvedBy"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool ApproveUser(int id, string approvedBy) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <param name="newPass"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool ChangePassword(string userName, string password, string newPass)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
if (Authenticate(userName, password))
|
||||||
|
{
|
||||||
|
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
|
||||||
|
var passSalt = LgbCryptography.GenerateSalt();
|
||||||
|
var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
|
||||||
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
|
||||||
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="rejectBy"></param>
|
||||||
|
/// <param name="reason"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool RejectUser(int id, string rejectBy) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过roleId获取所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<User> RetrieveUsersByRoleId(int roleId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过角色ID保存当前授权用户(插入)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">角色ID</param>
|
||||||
|
/// <param name="userIds">用户ID数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveUsersByRoleId(int id, IEnumerable<int> userIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过groupId获取所有用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual IEnumerable<User> RetrieveUsersByGroupId(int groupId) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 通过部门ID保存当前授权用户(插入)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">GroupID</param>
|
||||||
|
/// <param name="userIds">用户ID数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveUsersByGroupId(int id, IEnumerable<int> userIds) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户名修改用户头像
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="iconName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveUserIconByName(string userName, string iconName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param namve="userName"></param>
|
||||||
|
/// <param name="displayName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveDisplayName(string userName, string displayName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
/// 根据用户名更改用户皮肤
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userName"></param>
|
||||||
|
/// <param name="cssName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual bool SaveUserCssByName(string userName, string cssName) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual BootstrapUser RetrieveUserByUserName(string name) => throw new NotImplementedException();
|
||||||
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
|
@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.27703.2047
|
VisualStudioVersion = 15.0.27703.2047
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess", "Bootstrap.DataAccess\Bootstrap.DataAccess.csproj", "{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}"
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sql", "sql", "{87319AF5-7C40-4362-B67C-35F9DD737DB4}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sql", "sql", "{87319AF5-7C40-4362-B67C-35F9DD737DB4}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
DatabaseScripts\InitData.sql = DatabaseScripts\InitData.sql
|
DatabaseScripts\InitData.sql = DatabaseScripts\InitData.sql
|
||||||
|
@ -31,7 +29,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Client", "Bootstr
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{C7F51A14-2D89-4D1F-AD78-C42B79AB0BF0}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{C7F51A14-2D89-4D1F-AD78-C42B79AB0BF0}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.Client.DataAccess", "Bootstrap.Client.DataAccess\Bootstrap.Client.DataAccess.csproj", "{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Client.DataAccess", "Bootstrap.Client.DataAccess\Bootstrap.Client.DataAccess.csproj", "{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess", "Bootstrap.DataAccess\Bootstrap.DataAccess.csproj", "{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.SQLite", "Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj", "{BC18A24F-5C99-4DF5-803D-72A912BCBD57}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{523515EC-2AD7-4282-9AF4-9D20371183B0}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
DatabaseScripts\SQLite\InitData.sql = DatabaseScripts\SQLite\InitData.sql
|
||||||
|
DatabaseScripts\SQLite\Install.sql = DatabaseScripts\SQLite\Install.sql
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.SQLServer", "Bootstrap.DataAccess.SQLServer\Bootstrap.DataAccess.SQLServer.csproj", "{555BB7E8-36A4-4EDE-88A9-BEF3E6ACE71B}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -39,10 +49,6 @@ Global
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
@ -55,6 +61,18 @@ Global
|
||||||
{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B6B29DE5-D7B0-4A4D-9E7A-AADC68E9C43F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{555BB7E8-36A4-4EDE-88A9-BEF3E6ACE71B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{555BB7E8-36A4-4EDE-88A9-BEF3E6ACE71B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{555BB7E8-36A4-4EDE-88A9-BEF3E6ACE71B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{555BB7E8-36A4-4EDE-88A9-BEF3E6ACE71B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
DELETE From Users where ID = 1;
|
||||||
|
-- ADMIN/123789
|
||||||
|
INSERT INTO Users (ID, UserName, [Password], PassSalt, DisplayName, RegisterTime, ApprovedTime,ApprovedBy, [Description]) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator', datetime(CURRENT_TIMESTAMP, 'localtime'), datetime(CURRENT_TIMESTAMP, 'localtime'), 'system', '系统默认创建');
|
||||||
|
|
||||||
|
DELETE From Dicts;
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '菜单', '系统菜单', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '菜单', '外部菜单', '1', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '应用程序', '未设置', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站设置', '网站标题', '后台管理系统', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站设置', '网站页脚', '2016 © 通用后台管理系统', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '系统通知', '用户注册', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '系统通知', '程序异常', '1', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '系统通知', '数据库连接', '2', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '通知状态', '未处理', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '通知状态', '已处理', '1', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '处理结果', '同意', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '处理结果', '拒绝', '1', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息状态', '未读', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息状态', '已读', '1', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息标签', '一般', '0', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息标签', '紧要', '1', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '头像地址', '头像路径', '~/images/uploader/', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站样式', '蓝色样式', 'blue.css', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站样式', '黑色样式', 'black.css', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0);
|
||||||
|
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站设置', '前台首页', '~/Home/Index', 0);
|
||||||
|
|
||||||
|
DELETE FROM Navigations;
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (1, 0, '后台管理', 10, 'fa fa-gear', '~/Admin/Index', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (2, 0, '个人中心', 20, 'fa fa-suitcase', '~/Admin/Profiles', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (3, 0, '返回前台', 30, 'fa fa-hand-o-left', '~/Home/Index', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (4, 0, '网站设置', 40, 'fa fa-fa', '~/Admin/Settings', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (5, 0, '菜单管理', 50, 'fa fa-dashboard', '~/Admin/Menus', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (6, 0, '用户管理', 60, 'fa fa-user', '~/Admin/Users', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (7, 0, '角色管理', 70, 'fa fa-sitemap', '~/Admin/Roles', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (8, 0, '部门管理', 80, 'fa fa-bank', '~/Admin/Groups', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (9, 0, '字典表维护', 90, 'fa fa-book', '~/Admin/Dicts', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (10, 0, '站内消息', 100, 'fa fa-envelope', '~/Admin/Messages', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (11, 0, '任务管理', 110, 'fa fa fa-tasks', '~/Admin/Tasks', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (12, 0, '通知管理', 120, 'fa fa-bell', '~/Admin/Notifications', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (13, 0, '系统日志', 130, 'fa fa-gears', '~/Admin/Logs', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (14, 0, '程序异常', 140, 'fa fa-cubes', '~/Admin/Exceptions', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (16, 0, '工具集合', 160, 'fa fa-gavel', '#', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (17, 16, '客户端测试', 10, 'fa fa-wrench', '~/Admin/Mobile', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (18, 16, 'API文档', 10, 'fa fa-wrench', '~/Admin/Api', '0');
|
||||||
|
INSERT INTO [Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (19, 16, '图标集', 10, 'fa fa-dashboard', '~/Admin/FAIco', '0');
|
||||||
|
|
||||||
|
DELETE FROM GROUPS WHERE ID = 1;
|
||||||
|
INSERT INTO [Groups] ([ID], [GroupName], [Description]) VALUES (1, 'Admi', '系统默认组');
|
||||||
|
|
||||||
|
DELETE FROM Roles where ID in (1, 2);
|
||||||
|
INSERT INTO [Roles] ([ID], [RoleName], [Description]) VALUES (1, 'Administrators', '系统管理员');
|
||||||
|
INSERT INTO [Roles] ([ID], [RoleName], [Description]) VALUES (2, 'Default', '默认用户,可访问前台页面');
|
||||||
|
|
||||||
|
DELETE FROM RoleGroup;
|
||||||
|
INSERT INTO [RoleGroup] ([RoleID], [GroupID]) VALUES (1, 1);
|
||||||
|
|
||||||
|
DELETE FROM UserGroup;
|
||||||
|
INSERT INTO [UserGroup] ([UserID], [GroupID]) VALUES (1, 1);
|
||||||
|
|
||||||
|
DELETE FROM UserRole;
|
||||||
|
INSERT INTO [UserRole] ([UserID], [RoleID]) VALUES (1, 1);
|
||||||
|
INSERT INTO [UserRole] ([UserID], [RoleID]) VALUES (1, 2);
|
||||||
|
|
||||||
|
DELETE FROM NavigationRole;
|
||||||
|
INSERT INTO NavigationRole SELECT NULL, ID, 1 FROM navigations;
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (1, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (2, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (3, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (10, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (16, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (17, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (18, 2);
|
||||||
|
INSERT INTO [NavigationRole] ([NavigationID], [RoleID]) VALUES (19, 2);
|
|
@ -0,0 +1,140 @@
|
||||||
|
CREATE TABLE Users (
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[UserName] NVARCHAR (50) NOT NULL,
|
||||||
|
[Password] VARCHAR (50) NOT NULL,
|
||||||
|
[PassSalt] VARCHAR (50) NOT NULL,
|
||||||
|
[DisplayName] VARCHAR (50) NOT NULL,
|
||||||
|
[RegisterTime] DATETIME NOT NULL,
|
||||||
|
[ApprovedTime] DATETIME,
|
||||||
|
[ApprovedBy] VARCHAR (50),
|
||||||
|
[Description] VARCHAR (500) NOT NULL,
|
||||||
|
[RejectedBy] VARCHAR (50),
|
||||||
|
[RejectedTime] DATETIME,
|
||||||
|
[RejectedReason] VARCHAR (50),
|
||||||
|
[Icon] VARCHAR (50),
|
||||||
|
[Css] VARCHAR (50)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE UserRole (
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[UserID] INT NOT NULL,
|
||||||
|
[RoleID] INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE UserGroup(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[UserID] INT NOT NULL,
|
||||||
|
[GroupID] INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Roles(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[RoleName] VARCHAR (50) NULL,
|
||||||
|
[Description] VARCHAR (500) NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE RoleGroup(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[RoleID] INT NOT NULL,
|
||||||
|
[GroupID] INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Notifications(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[Category] VARCHAR (50) NOT NULL,
|
||||||
|
[Title] VARCHAR (50) NOT NULL,
|
||||||
|
[Content] VARCHAR (50) NOT NULL,
|
||||||
|
[RegisterTime] DATETIME NOT NULL,
|
||||||
|
[ProcessTime] DATETIME NULL,
|
||||||
|
[ProcessBy] VARCHAR (50) NULL,
|
||||||
|
[ProcessResult] VARCHAR (50) NULL,
|
||||||
|
[Status] VARCHAR (50) DEFAULT (0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Navigations(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[ParentId] INT DEFAULT (0),
|
||||||
|
[Name] VARCHAR (50) NOT NULL,
|
||||||
|
[Order] INT DEFAULT (0),
|
||||||
|
[Icon] VARCHAR (50) DEFAULT none,
|
||||||
|
[Url] VARCHAR (4000) NULL,
|
||||||
|
[Category] VARCHAR (50) DEFAULT 0,
|
||||||
|
[Target] VARCHAR (10) DEFAULT _self,
|
||||||
|
[IsResource] INT DEFAULT (0),
|
||||||
|
[Application] VARCHAR (200) DEFAULT (0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE NavigationRole(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[NavigationID] INT NOT NULL,
|
||||||
|
[RoleID] INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Logs(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[CRUD] VARCHAR (50) NOT NULL,
|
||||||
|
[UserName] VARCHAR (50) NOT NULL,
|
||||||
|
[LogTime] DATETIME NOT NULL,
|
||||||
|
[ClientIp] VARCHAR (15) NOT NULL,
|
||||||
|
[ClientAgent] VARCHAR (500) NOT NULL,
|
||||||
|
[RequestUrl] VARCHAR (500) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Groups(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[GroupName] VARCHAR (50) NULL,
|
||||||
|
[Description] VARCHAR (500) NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Exceptions(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[AppDomainName] VARCHAR (50) NOT NULL,
|
||||||
|
[ErrorPage] VARCHAR (50) NOT NULL,
|
||||||
|
[UserID] VARCHAR (50) NULL,
|
||||||
|
[UserIp] VARCHAR (15) NULL,
|
||||||
|
[ExceptionType] TEXT NOT NULL,
|
||||||
|
[Message] TEXT NOT NULL,
|
||||||
|
[StackTrace] TEXT NULL,
|
||||||
|
[LogTime] DATETIME NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Dicts(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[Category] VARCHAR (50) NOT NULL,
|
||||||
|
[Name] VARCHAR (50) NOT NULL,
|
||||||
|
[Code] VARCHAR (500) NOT NULL,
|
||||||
|
[Define] INT DEFAULT (1)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Messages(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[Title] VARCHAR (50) NOT NULL,
|
||||||
|
[Content] VARCHAR (500) NOT NULL,
|
||||||
|
[From] VARCHAR (50) NOT NULL,
|
||||||
|
[To] VARCHAR (50) NOT NULL,
|
||||||
|
[SendTime] DATETIME NOT NULL,
|
||||||
|
[Status] VARCHAR (50) NOT NULL,
|
||||||
|
[Flag] INT DEFAULT (0),
|
||||||
|
[IsDelete] INT DEFAULT (0),
|
||||||
|
[Label] VARCHAR (50)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Tasks(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[TaskName] VARCHAR (500) NOT NULL,
|
||||||
|
[AssignName] VARCHAR (50) NOT NULL,
|
||||||
|
[UserName] VARCHAR (50) NOT NULL,
|
||||||
|
[TaskTime] INT NOT NULL,
|
||||||
|
[TaskProgress] INT NOT NULL,
|
||||||
|
[AssignTime] DATETIME NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE RejectUsers(
|
||||||
|
[ID] INTEGER PRIMARY KEY,
|
||||||
|
[UserName] VARCHAR (50) NOT NULL,
|
||||||
|
[DisplayName] VARCHAR (50) NOT NULL,
|
||||||
|
[RegisterTime] DATETIME NOT NULL,
|
||||||
|
[RejectedBy] VARCHAR (50) NULL,
|
||||||
|
[RejectedTime] DATETIME NULL,
|
||||||
|
[RejectedReason] VARCHAR (50) NULL
|
||||||
|
);
|
Loading…
Reference in New Issue