新增功能:支持多数据库
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>
|
|
@ -1,180 +1,168 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
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>
|
||||||
///
|
/// 删除字典中的数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
|
/// <param name="value">需要删除的IDs</param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
///
|
public override bool DeleteDict(IEnumerable<int> value)
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
var ret = false;
|
||||||
public static IEnumerable<BootstrapDict> RetrieveDicts()
|
var ids = string.Join(",", value);
|
||||||
{
|
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
||||||
return BootstrapDict.RetrieveDicts();
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
}
|
{
|
||||||
/// <summary>
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||||
/// 删除字典中的数据
|
CacheCleanUtility.ClearCache(dictIds: ids);
|
||||||
/// </summary>
|
}
|
||||||
/// <param name="value">需要删除的IDs</param>
|
return ret;
|
||||||
/// <returns></returns>
|
}
|
||||||
public static bool DeleteDict(IEnumerable<int> value)
|
|
||||||
{
|
/// <summary>
|
||||||
var ret = false;
|
/// 保存新建/更新的字典信息
|
||||||
var ids = string.Join(",", value);
|
/// </summary>
|
||||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Dicts where ID in ({0})", ids);
|
/// <param name="dict"></param>
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
/// <returns></returns>
|
||||||
{
|
public override bool SaveDict(BootstrapDict dict)
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
{
|
||||||
CacheCleanUtility.ClearCache(dictIds: ids);
|
bool ret = false;
|
||||||
}
|
if (dict.Category.Length > 50) dict.Category = dict.Category.Substring(0, 50);
|
||||||
return ret;
|
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 ?
|
||||||
/// <summary>
|
"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";
|
||||||
/// </summary>
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
/// <param name="p"></param>
|
{
|
||||||
/// <returns></returns>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
|
||||||
public static bool SaveDict(BootstrapDict p)
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
|
||||||
bool ret = false;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
|
||||||
if (p.Category.Length > 50) p.Category = p.Category.Substring(0, 50);
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
|
||||||
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
if (p.Code.Length > 50) p.Code = p.Code.Substring(0, 50);
|
}
|
||||||
string sql = p.Id == 0 ?
|
CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString());
|
||||||
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
|
return ret;
|
||||||
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
|
}
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
/// <summary>
|
||||||
{
|
/// 保存网站个性化设置
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
/// </summary>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
/// <param name="name"></param>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
/// <param name="code"></param>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", p.Code));
|
/// <param name="category"></param>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Define", p.Define));
|
/// <returns></returns>
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
public override bool SaveSettings(BootstrapDict dict)
|
||||||
}
|
{
|
||||||
CacheCleanUtility.ClearCache(dictIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
var ret = false;
|
||||||
return ret;
|
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
||||||
}
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
/// <summary>
|
{
|
||||||
/// 保存网站个性化设置
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
|
||||||
/// </summary>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
|
||||||
/// <param name="name"></param>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
|
||||||
/// <param name="code"></param>
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
/// <param name="category"></param>
|
}
|
||||||
/// <returns></returns>
|
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
||||||
public static bool SaveSettings(BootstrapDict dict)
|
return ret;
|
||||||
{
|
}
|
||||||
var ret = false;
|
/// <summary>
|
||||||
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
|
/// 获取字典分类名称
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
/// </summary>
|
||||||
{
|
/// <returns></returns>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", dict.Name));
|
public override IEnumerable<string> RetrieveCategories()
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", dict.Code));
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", dict.Category));
|
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
{
|
||||||
}
|
var ret = new List<string>();
|
||||||
CacheCleanUtility.ClearCache(dictIds: string.Empty);
|
string sql = "select distinct Category from Dicts";
|
||||||
return ret;
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
}
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
/// <summary>
|
{
|
||||||
/// 获取字典分类名称
|
while (reader.Read())
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
ret.Add((string)reader[0]);
|
||||||
public static IEnumerable<string> RetrieveCategories()
|
}
|
||||||
{
|
}
|
||||||
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
|
return ret;
|
||||||
{
|
});
|
||||||
var ret = new List<string>();
|
}
|
||||||
string sql = "select distinct Category from Dicts";
|
/// <summary>
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
///
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
/// </summary>
|
||||||
{
|
/// <returns></returns>
|
||||||
while (reader.Read())
|
public override string RetrieveWebTitle()
|
||||||
{
|
{
|
||||||
ret.Add((string)reader[0]);
|
var settings = RetrieveDicts();
|
||||||
}
|
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
|
||||||
}
|
}
|
||||||
return ret;
|
/// <summary>
|
||||||
});
|
///
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
///
|
public override string RetrieveWebFooter()
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
var settings = RetrieveDicts();
|
||||||
public static string RetrieveWebTitle()
|
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
|
||||||
{
|
}
|
||||||
var settings = RetrieveDicts();
|
/// <summary>
|
||||||
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
|
/// 获得系统中配置的可以使用的网站样式
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
///
|
public override IEnumerable<BootstrapDict> RetrieveThemes()
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
var data = RetrieveDicts();
|
||||||
public static string RetrieveWebFooter()
|
return data.Where(d => d.Category == "网站样式");
|
||||||
{
|
}
|
||||||
var settings = RetrieveDicts();
|
/// <summary>
|
||||||
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
|
/// 获得网站设置中的当前样式
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 获得系统中配置的可以使用的网站样式
|
public override string RetrieveActiveTheme()
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
var data = RetrieveDicts();
|
||||||
public static IEnumerable<BootstrapDict> RetrieveThemes()
|
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);
|
||||||
var data = RetrieveDicts();
|
}
|
||||||
return data.Where(d => d.Category == "网站样式");
|
/// <summary>
|
||||||
}
|
/// 获取头像路径
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 获得网站设置中的当前样式
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override BootstrapDict RetrieveIconFolderPath()
|
||||||
/// <returns></returns>
|
{
|
||||||
public static string RetrieveActiveTheme()
|
var data = RetrieveDicts();
|
||||||
{
|
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
|
||||||
var data = RetrieveDicts();
|
}
|
||||||
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
|
/// <summary>
|
||||||
return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code);
|
/// 获得默认的前台首页地址,默认为~/Home/Index
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 获取头像路径
|
public override string RetrieveHomeUrl()
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
var settings = RetrieveDicts();
|
||||||
public static BootstrapDict RetrieveIconFolderPath()
|
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
|
||||||
{
|
}
|
||||||
var data = RetrieveDicts();
|
/// <summary>
|
||||||
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
|
///
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 获得默认的前台首页地址,默认为~/Home/Index
|
public override IEnumerable<KeyValuePair<string, string>> RetrieveApps()
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
var settings = RetrieveDicts();
|
||||||
public static string RetrieveHomeUrl()
|
return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
|
||||||
{
|
}
|
||||||
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 static 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,99 +1,95 @@
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using Longbow.Configuration;
|
using Longbow.Configuration;
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
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>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly string RetrieveExceptionsDataKey = "ExceptionHelper-RetrieveExceptions";
|
/// <param name="ex"></param>
|
||||||
/// <summary>
|
/// <param name="additionalInfo"></param>
|
||||||
///
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override void Log(Exception ex, NameValueCollection additionalInfo)
|
||||||
/// <param name="ex"></param>
|
{
|
||||||
/// <param name="additionalInfo"></param>
|
if (additionalInfo == null)
|
||||||
/// <returns></returns>
|
{
|
||||||
public static void Log(Exception ex, NameValueCollection additionalInfo)
|
additionalInfo = new NameValueCollection
|
||||||
{
|
{
|
||||||
if (additionalInfo == null)
|
["UserId"] = null,
|
||||||
{
|
["UserIp"] = null,
|
||||||
additionalInfo = new NameValueCollection
|
["ErrorPage"] = null
|
||||||
{
|
};
|
||||||
["UserId"] = null,
|
}
|
||||||
["UserIp"] = null,
|
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
|
||||||
["ErrorPage"] = null
|
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.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
}
|
{
|
||||||
var errorPage = additionalInfo["ErrorPage"] ?? (nameof(ex).Length > 50 ? nameof(ex).Substring(0, 50) : nameof(ex));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
||||||
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
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.SqlDBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ErrorPage", errorPage));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", DBAccessFactory.ToDBValue(additionalInfo["UserId"])));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@StackTrace", DbAccessFactory.ToDBValue(ex.StackTrace)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserIp", DBAccessFactory.ToDBValue(additionalInfo["UserIp"])));
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
|
CacheManager.Clear(RetrieveExceptionsDataKey);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Message", ex.Message));
|
ClearExceptions();
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace)));
|
}
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
}
|
||||||
CacheManager.Clear(RetrieveExceptionsDataKey);
|
/// <summary>
|
||||||
ClearExceptions();
|
///
|
||||||
}
|
/// </summary>
|
||||||
}
|
private static void ClearExceptions()
|
||||||
/// <summary>
|
{
|
||||||
///
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
/// </summary>
|
{
|
||||||
private static void ClearExceptions()
|
string sql = $"delete from Exceptions where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]}, GETDATE())";
|
||||||
{
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
System.Threading.Tasks.Task.Run(() =>
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
{
|
});
|
||||||
string sql = $"delete from Exceptions where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]}, GETDATE())";
|
}
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
/// <summary>
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
/// 查询一周内所有异常
|
||||||
});
|
/// </summary>
|
||||||
}
|
/// <returns></returns>
|
||||||
/// <summary>
|
public override IEnumerable<Bootstrap.DataAccess.Exceptions> RetrieveExceptions()
|
||||||
/// 查询一周内所有异常
|
{
|
||||||
/// </summary>
|
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<Exceptions> RetrieveExceptions()
|
string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
|
||||||
{
|
List<Exceptions> exceptions = new List<Exceptions>();
|
||||||
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
{
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
string sql = "select * from Exceptions where DATEDIFF(Week, LogTime, GETDATE()) = 0 order by LogTime desc";
|
{
|
||||||
List<Exceptions> exceptions = new List<Exceptions>();
|
while (reader.Read())
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
exceptions.Add(new Exceptions()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
AppDomainName = (string)reader[1],
|
||||||
exceptions.Add(new Exceptions()
|
ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
{
|
UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
|
||||||
Id = (int)reader[0],
|
UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
|
||||||
AppDomainName = (string)reader[1],
|
ExceptionType = (string)reader[5],
|
||||||
ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
Message = (string)reader[6],
|
||||||
UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],
|
StackTrace = (string)reader[7],
|
||||||
UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
|
LogTime = (DateTime)reader[8],
|
||||||
ExceptionType = (string)reader[5],
|
});
|
||||||
Message = (string)reader[6],
|
}
|
||||||
StackTrace = (string)reader[7],
|
}
|
||||||
LogTime = (DateTime)reader[8],
|
return exceptions;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exceptions;
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,242 +1,239 @@
|
||||||
using Longbow.Cache;
|
using Bootstrap.DataAccess;
|
||||||
using Longbow.Data;
|
using Longbow.Cache;
|
||||||
using System;
|
using Longbow.Data;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Data;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data;
|
||||||
using System.Data.SqlClient;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
namespace Bootstrap.DataAccess
|
|
||||||
{
|
namespace Bootstrap.DataAccess.SQLServer
|
||||||
/// <summary>
|
{
|
||||||
/// author:liuchun
|
/// <summary>
|
||||||
/// date:2016.10.22
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class GroupHelper
|
public class Group : Bootstrap.DataAccess.Group
|
||||||
{
|
{
|
||||||
internal const string RetrieveGroupsDataKey = "GroupHelper-RetrieveGroups";
|
/// <summary>
|
||||||
internal const string RetrieveGroupsByUserIdDataKey = "GroupHelper-RetrieveGroupsByUserId";
|
/// 查询所有群组信息
|
||||||
internal const string RetrieveGroupsByRoleIdDataKey = "GroupHelper-RetrieveGroupsByRoleId";
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="id"></param>
|
||||||
/// 查询所有群组信息
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override IEnumerable<Bootstrap.DataAccess.Group> RetrieveGroups(int id = 0)
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <returns></returns>
|
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
|
||||||
public static IEnumerable<Group> RetrieveGroups(int id = 0)
|
{
|
||||||
{
|
string sql = "select * from Groups";
|
||||||
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
|
List<Group> groups = new List<Group>();
|
||||||
{
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
string sql = "select * from Groups";
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
List<Group> groups = new List<Group>();
|
{
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
while (reader.Read())
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
{
|
||||||
{
|
groups.Add(new Group()
|
||||||
while (reader.Read())
|
{
|
||||||
{
|
Id = (int)reader[0],
|
||||||
groups.Add(new Group()
|
GroupName = (string)reader[1],
|
||||||
{
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||||
Id = (int)reader[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);
|
||||||
return groups;
|
}
|
||||||
});
|
/// <summary>
|
||||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
/// 删除群组信息
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="ids"></param>
|
||||||
/// 删除群组信息
|
public override bool DeleteGroup(IEnumerable<int> value)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="ids"></param>
|
bool ret = false;
|
||||||
public static bool DeleteGroup(IEnumerable<int> value)
|
var ids = string.Join(",", value);
|
||||||
{
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
||||||
bool ret = false;
|
{
|
||||||
var ids = string.Join(",", value);
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteGroups"))
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
{
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
CacheCleanUtility.ClearCache(groupIds: value);
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
return ret;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: value);
|
/// <summary>
|
||||||
return ret;
|
/// 保存新建/更新的群组信息
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="p"></param>
|
||||||
/// 保存新建/更新的群组信息
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override bool SaveGroup(Bootstrap.DataAccess.Group p)
|
||||||
/// <param name="p"></param>
|
{
|
||||||
/// <returns></returns>
|
bool ret = false;
|
||||||
public static bool SaveGroup(Group p)
|
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);
|
||||||
bool ret = false;
|
string sql = p.Id == 0 ?
|
||||||
if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50);
|
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
||||||
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
||||||
string sql = p.Id == 0 ?
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
|
{
|
||||||
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupName", p.GroupName));
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
return ret;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
/// <summary>
|
||||||
return ret;
|
/// 根据用户查询部门信息
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="userId"></param>
|
||||||
/// 根据用户查询部门信息
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override IEnumerable<Bootstrap.DataAccess.Group> RetrieveGroupsByUserId(int userId)
|
||||||
/// <param name="userId"></param>
|
{
|
||||||
/// <returns></returns>
|
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
|
||||||
public static IEnumerable<Group> RetrieveGroupsByUserId(int userId)
|
var ret = CacheManager.GetOrAdd(key, k =>
|
||||||
{
|
{
|
||||||
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, 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";
|
||||||
var ret = CacheManager.GetOrAdd(key, k =>
|
List<Group> groups = new List<Group>();
|
||||||
{
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
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";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
|
||||||
List<Group> groups = new List<Group>();
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
while (reader.Read())
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
{
|
||||||
{
|
groups.Add(new Group()
|
||||||
while (reader.Read())
|
{
|
||||||
{
|
Id = (int)reader[0],
|
||||||
groups.Add(new Group()
|
GroupName = (string)reader[1],
|
||||||
{
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
Id = (int)reader[0],
|
Checked = (string)reader[3]
|
||||||
GroupName = (string)reader[1],
|
});
|
||||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
}
|
||||||
Checked = (string)reader[3]
|
}
|
||||||
});
|
return groups;
|
||||||
}
|
}, RetrieveGroupsByUserIdDataKey);
|
||||||
}
|
return ret;
|
||||||
return groups;
|
}
|
||||||
}, RetrieveGroupsByUserIdDataKey);
|
/// <summary>
|
||||||
return ret;
|
/// 保存用户部门关系
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="id"></param>
|
||||||
/// 保存用户部门关系
|
/// <param name="groupIds"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="id"></param>
|
public override bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds)
|
||||||
/// <param name="groupIds"></param>
|
{
|
||||||
/// <returns></returns>
|
var ret = false;
|
||||||
public static bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds)
|
DataTable dt = new DataTable();
|
||||||
{
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
var ret = false;
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
DataTable dt = new DataTable();
|
//判断用户是否选定角色
|
||||||
dt.Columns.Add("UserID", typeof(int));
|
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
//判断用户是否选定角色
|
{
|
||||||
groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId));
|
try
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
{
|
||||||
{
|
//删除用户部门表中该用户所有的部门关系
|
||||||
try
|
string sql = "delete from UserGroup where UserID=@UserID;";
|
||||||
{
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
//删除用户部门表中该用户所有的部门关系
|
{
|
||||||
string sql = "delete from UserGroup where UserID=@UserID;";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
{
|
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", id));
|
// insert batch data into config table
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
|
{
|
||||||
// insert batch data into config table
|
bulk.BatchSize = 1000;
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
bulk.DestinationTableName = "UserGroup";
|
||||||
{
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
bulk.BatchSize = 1000;
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
bulk.DestinationTableName = "UserGroup";
|
bulk.WriteToServer(dt);
|
||||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
transaction.CommitTransaction();
|
||||||
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
}
|
||||||
bulk.WriteToServer(dt);
|
}
|
||||||
transaction.CommitTransaction();
|
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<int>() { id });
|
||||||
}
|
ret = true;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<int>() { id });
|
catch (Exception ex)
|
||||||
ret = true;
|
{
|
||||||
}
|
transaction.RollbackTransaction();
|
||||||
catch (Exception ex)
|
throw ex;
|
||||||
{
|
}
|
||||||
transaction.RollbackTransaction();
|
}
|
||||||
throw ex;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
/// <summary>
|
||||||
return ret;
|
/// 根据角色ID指派部门
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="roleId"></param>
|
||||||
/// 根据角色ID指派部门
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override IEnumerable<Bootstrap.DataAccess.Group> RetrieveGroupsByRoleId(int roleId)
|
||||||
/// <param name="roleId"></param>
|
{
|
||||||
/// <returns></returns>
|
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
|
||||||
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId)
|
return CacheManager.GetOrAdd(k, key =>
|
||||||
{
|
{
|
||||||
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
|
List<Group> groups = new List<Group>();
|
||||||
return CacheManager.GetOrAdd(k, key =>
|
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);
|
||||||
List<Group> groups = new List<Group>();
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@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";
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
while (reader.Read())
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
{
|
||||||
{
|
groups.Add(new Group()
|
||||||
while (reader.Read())
|
{
|
||||||
{
|
Id = (int)reader[0],
|
||||||
groups.Add(new Group()
|
GroupName = (string)reader[1],
|
||||||
{
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
Id = (int)reader[0],
|
Checked = (string)reader[3]
|
||||||
GroupName = (string)reader[1],
|
});
|
||||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
}
|
||||||
Checked = (string)reader[3]
|
}
|
||||||
});
|
return groups;
|
||||||
}
|
}, RetrieveGroupsByRoleIdDataKey);
|
||||||
}
|
}
|
||||||
return groups;
|
/// <summary>
|
||||||
}, RetrieveGroupsByRoleIdDataKey);
|
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
||||||
}
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="id"></param>
|
||||||
/// 根据角色ID以及选定的部门ID,保到角色部门表
|
/// <param name="groupIds"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="id"></param>
|
public override bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds)
|
||||||
/// <param name="groupIds"></param>
|
{
|
||||||
/// <returns></returns>
|
bool ret = false;
|
||||||
public static bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds)
|
DataTable dt = new DataTable();
|
||||||
{
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
bool ret = false;
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
DataTable dt = new DataTable();
|
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
{
|
||||||
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id));
|
try
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
{
|
||||||
{
|
//删除角色部门表该角色所有的部门
|
||||||
try
|
string sql = "delete from RoleGroup where RoleID=@RoleID";
|
||||||
{
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
//删除角色部门表该角色所有的部门
|
{
|
||||||
string sql = "delete from RoleGroup where RoleID=@RoleID";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
{
|
//批插入角色部门表
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id));
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
{
|
||||||
//批插入角色部门表
|
bulk.BatchSize = 1000;
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
{
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
bulk.BatchSize = 1000;
|
bulk.DestinationTableName = "RoleGroup";
|
||||||
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
bulk.WriteToServer(dt);
|
||||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
transaction.CommitTransaction();
|
||||||
bulk.DestinationTableName = "RoleGroup";
|
}
|
||||||
bulk.WriteToServer(dt);
|
}
|
||||||
transaction.CommitTransaction();
|
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<int>() { id });
|
||||||
}
|
ret = true;
|
||||||
}
|
}
|
||||||
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<int>() { id });
|
catch (Exception ex)
|
||||||
ret = true;
|
{
|
||||||
}
|
transaction.RollbackTransaction();
|
||||||
catch (Exception ex)
|
throw ex;
|
||||||
{
|
}
|
||||||
transaction.RollbackTransaction();
|
}
|
||||||
throw ex;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +1,86 @@
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using Longbow.Configuration;
|
using Longbow.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
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>
|
||||||
{
|
///
|
||||||
private const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs";
|
/// </summary>
|
||||||
/// <summary>
|
public class Log : Bootstrap.DataAccess.Log
|
||||||
/// 查询所有日志信息
|
{
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="tId"></param>
|
/// 查询所有日志信息
|
||||||
/// <returns></returns>
|
/// </summary>
|
||||||
public static IEnumerable<Log> RetrieveLogs(string tId = null)
|
/// <param name="tId"></param>
|
||||||
{
|
/// <returns></returns>
|
||||||
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
|
public override IEnumerable<Bootstrap.DataAccess.Log> RetrieveLogs(string tId = null)
|
||||||
{
|
{
|
||||||
string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0";
|
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
|
||||||
List<Log> logs = new List<Log>();
|
{
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0";
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
List<Log> logs = new List<Log>();
|
||||||
{
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
while (reader.Read())
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
logs.Add(new Log()
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
Id = (int)reader[0],
|
logs.Add(new Log()
|
||||||
CRUD = (string)reader[1],
|
{
|
||||||
UserName = (string)reader[2],
|
Id = (int)reader[0],
|
||||||
LogTime = (DateTime)reader[3],
|
CRUD = (string)reader[1],
|
||||||
ClientIp = (string)reader[4],
|
UserName = (string)reader[2],
|
||||||
ClientAgent = (string)reader[5],
|
LogTime = (DateTime)reader[3],
|
||||||
RequestUrl = (string)reader[6]
|
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));
|
return logs;
|
||||||
}
|
});
|
||||||
/// <summary>
|
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
|
||||||
/// 删除日志信息
|
}
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="value"></param>
|
/// 删除日志信息
|
||||||
/// <returns></returns>
|
/// </summary>
|
||||||
public static void DeleteLogAsync()
|
/// <param name="value"></param>
|
||||||
{
|
/// <returns></returns>
|
||||||
System.Threading.Tasks.Task.Run(() =>
|
private void DeleteLogAsync()
|
||||||
{
|
{
|
||||||
string sql = $"delete from Logs where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepLogsPeriod"]}, GETDATE())";
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
{
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
string sql = $"delete from Logs where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepLogsPeriod"]}, GETDATE())";
|
||||||
});
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
}
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd);
|
||||||
/// <summary>
|
});
|
||||||
/// 保存新增的日志信息
|
}
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="p"></param>
|
/// 保存新增的日志信息
|
||||||
/// <returns></returns>
|
/// </summary>
|
||||||
public static bool SaveLog(Log p)
|
/// <param name="p"></param>
|
||||||
{
|
/// <returns></returns>
|
||||||
if (p == null) throw new ArgumentNullException("p");
|
public override bool SaveLog(Bootstrap.DataAccess.Log p)
|
||||||
bool ret = false;
|
{
|
||||||
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, GetDate(), @ClientIp, @ClientAgent, @RequestUrl)";
|
if (p == null) throw new ArgumentNullException("p");
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
bool ret = false;
|
||||||
{
|
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, GetDate(), @ClientIp, @ClientAgent, @RequestUrl)";
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@CRUD", p.CRUD));
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", p.UserName));
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
|
||||||
}
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
|
||||||
CacheManager.Clear(RetrieveLogsDataKey);
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
DeleteLogAsync();
|
}
|
||||||
return ret;
|
CacheManager.Clear(RetrieveLogsDataKey);
|
||||||
}
|
DeleteLogAsync();
|
||||||
}
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,145 +1,169 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
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>
|
||||||
///
|
/// 删除菜单信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId";
|
/// <param name="value"></param>
|
||||||
/// <summary>
|
public override bool DeleteMenu(IEnumerable<int> value)
|
||||||
/// 删除菜单信息
|
{
|
||||||
/// </summary>
|
bool ret = false;
|
||||||
/// <param name="value"></param>
|
var ids = string.Join(",", value);
|
||||||
public static bool DeleteMenu(IEnumerable<int> value)
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
||||||
{
|
{
|
||||||
bool ret = false;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
var ids = string.Join(",", value);
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
|
}
|
||||||
{
|
CacheCleanUtility.ClearCache(menuIds: value);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
}
|
||||||
}
|
/// <summary>
|
||||||
CacheCleanUtility.ClearCache(menuIds: value);
|
/// 保存新建/更新的菜单信息
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="p"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 保存新建/更新的菜单信息
|
public override bool SaveMenu(BootstrapMenu p)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="p"></param>
|
if (string.IsNullOrEmpty(p.Name)) return false;
|
||||||
/// <returns></returns>
|
bool ret = false;
|
||||||
public static bool SaveMenu(BootstrapMenu p)
|
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 (string.IsNullOrEmpty(p.Name)) return false;
|
if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000);
|
||||||
bool ret = false;
|
string sql = p.Id == 0 ?
|
||||||
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
|
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
|
||||||
if (p.Icon != null && p.Icon.Length > 50) p.Icon = p.Icon.Substring(0, 50);
|
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
|
||||||
if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000);
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
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)" :
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.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";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Name", p.Name));
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Order", p.Order));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Icon", DbAccessFactory.ToDBValue(p.Icon)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ParentId", p.ParentId));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Url", DbAccessFactory.ToDBValue(p.Url)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", p.Name));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Category", p.Category));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Order", p.Order));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Target", p.Target));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Icon", DBAccessFactory.ToDBValue(p.Icon)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Url", DBAccessFactory.ToDBValue(p.Url)));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category));
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Target", p.Target));
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@IsResource", p.IsResource));
|
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
}
|
||||||
}
|
|
||||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
/// <summary>
|
||||||
return ret;
|
/// 查询某个角色所配置的菜单
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="roleId"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 查询某个角色所配置的菜单
|
public override IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="roleId"></param>
|
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
|
||||||
/// <returns></returns>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
|
{
|
||||||
{
|
var menus = new List<BootstrapMenu>();
|
||||||
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
|
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
var menus = new List<BootstrapMenu>();
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
{
|
||||||
{
|
while (reader.Read())
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
menus.Add(new BootstrapMenu()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0]
|
||||||
{
|
});
|
||||||
menus.Add(new BootstrapMenu()
|
}
|
||||||
{
|
}
|
||||||
Id = (int)reader[0]
|
}
|
||||||
});
|
return menus;
|
||||||
}
|
}, RetrieveMenusByRoleIdDataKey);
|
||||||
}
|
}
|
||||||
}
|
/// <summary>
|
||||||
return menus;
|
/// 通过角色ID保存当前授权菜单
|
||||||
}, RetrieveMenusByRoleIdDataKey);
|
/// </summary>
|
||||||
}
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="menuIds"></param>
|
||||||
/// 通过角色ID保存当前授权菜单
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds)
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <param name="menuIds"></param>
|
bool ret = false;
|
||||||
/// <returns></returns>
|
DataTable dt = new DataTable();
|
||||||
public static bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds)
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
{
|
dt.Columns.Add("NavigationID", typeof(int));
|
||||||
bool ret = false;
|
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
|
||||||
DataTable dt = new DataTable();
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
{
|
||||||
dt.Columns.Add("NavigationID", typeof(int));
|
try
|
||||||
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
|
{
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
//删除菜单角色表该角色所有的菜单
|
||||||
{
|
string sql = "delete from NavigationRole where RoleID=@RoleID";
|
||||||
try
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
//删除菜单角色表该角色所有的菜单
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
string sql = "delete from NavigationRole where RoleID=@RoleID";
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
//批插入菜单角色表
|
||||||
{
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id));
|
{
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
bulk.DestinationTableName = "NavigationRole";
|
||||||
//批插入菜单角色表
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
|
||||||
{
|
bulk.WriteToServer(dt);
|
||||||
bulk.DestinationTableName = "NavigationRole";
|
transaction.CommitTransaction();
|
||||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
}
|
||||||
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
|
}
|
||||||
bulk.WriteToServer(dt);
|
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<int>() { id });
|
||||||
transaction.CommitTransaction();
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<int>() { id });
|
{
|
||||||
ret = true;
|
transaction.RollbackTransaction();
|
||||||
}
|
throw ex;
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
transaction.RollbackTransaction();
|
return ret;
|
||||||
throw ex;
|
}
|
||||||
}
|
///// <summary>
|
||||||
}
|
/////
|
||||||
return ret;
|
///// </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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,116 +1,114 @@
|
||||||
using Longbow;
|
using Longbow;
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
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<Bootstrap.DataAccess.Message> RetrieveMessages(string userName)
|
||||||
private static IEnumerable<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.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserName", userName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
{
|
||||||
{
|
while (reader.Read())
|
||||||
while (reader.Read())
|
{
|
||||||
{
|
messages.Add(new Message()
|
||||||
messages.Add(new Message()
|
{
|
||||||
{
|
Id = (int)reader[0],
|
||||||
Id = (int)reader[0],
|
Title = (string)reader[1],
|
||||||
Title = (string)reader[1],
|
Content = (string)reader[2],
|
||||||
Content = (string)reader[2],
|
From = (string)reader[3],
|
||||||
From = (string)reader[3],
|
To = (string)reader[4],
|
||||||
To = (string)reader[4],
|
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
|
||||||
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
|
Status = (string)reader[6],
|
||||||
Status = (string)reader[6],
|
Mark = (int)reader[7],
|
||||||
Mark = (int)reader[7],
|
IsDelete = (int)reader[8],
|
||||||
IsDelete = (int)reader[8],
|
Label = (string)reader[9],
|
||||||
Label = (string)reader[9],
|
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
|
||||||
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
|
FromIcon = (string)reader[11],
|
||||||
FromIcon = (string)reader[11],
|
FromDisplayName = (string)reader[12]
|
||||||
FromDisplayName = (string)reader[12]
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
return messages;
|
||||||
return messages;
|
|
||||||
|
});
|
||||||
});
|
return messageRet.OrderByDescending(n => n.SendTime);
|
||||||
return messageRet.OrderByDescending(n => n.SendTime);
|
}
|
||||||
}
|
/// <summary>
|
||||||
/// <summary>
|
/// 收件箱
|
||||||
/// 收件箱
|
/// </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);
|
||||||
{
|
return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
||||||
var messageRet = RetrieveMessages(userName);
|
}
|
||||||
return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
/// <summary>
|
||||||
}
|
/// 发件箱
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 发件箱
|
/// <param name="userName"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="userName"></param>
|
public override IEnumerable<Bootstrap.DataAccess.Message> SendMail(string userName)
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<Message> SendMail(string userName)
|
var messageRet = RetrieveMessages(userName);
|
||||||
{
|
return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
||||||
var messageRet = RetrieveMessages(userName);
|
}
|
||||||
return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase));
|
/// <summary>
|
||||||
}
|
/// 垃圾箱
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 垃圾箱
|
/// <param name="userName"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="userName"></param>
|
public override IEnumerable<Bootstrap.DataAccess.Message> Trash(string userName)
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<Message> Trash(string userName)
|
var messageRet = RetrieveMessages(userName);
|
||||||
{
|
return messageRet.Where(n => n.IsDelete == 1);
|
||||||
var messageRet = RetrieveMessages(userName);
|
}
|
||||||
return messageRet.Where(n => n.IsDelete == 1);
|
/// <summary>
|
||||||
}
|
/// 标旗
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 标旗
|
/// <param name="userName"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="userName"></param>
|
public override IEnumerable<Bootstrap.DataAccess.Message> Flag(string userName)
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<Message> Mark(string userName)
|
var messageRet = RetrieveMessages(userName);
|
||||||
{
|
return messageRet.Where(n => n.Mark == 1);
|
||||||
var messageRet = RetrieveMessages(userName);
|
}
|
||||||
return messageRet.Where(n => n.Mark == 1);
|
/// <summary>
|
||||||
}
|
/// 获取Header处显示的消息列表
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// 获取Header处显示的消息列表
|
/// <param name="userName"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="userName"></param>
|
public override IEnumerable<Bootstrap.DataAccess.Message> RetrieveMessagesHeader(string userName)
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<Message> RetrieveMessagesHeader(string userName)
|
var messageRet = Inbox(userName);
|
||||||
{
|
messageRet.AsParallel().ForAll(n =>
|
||||||
var messageRet = Inbox(userName);
|
{
|
||||||
messageRet.AsParallel().ForAll(n =>
|
var ts = DateTime.Now - n.SendTime;
|
||||||
{
|
if (ts.TotalMinutes < 5) n.Period = "刚刚";
|
||||||
var ts = DateTime.Now - n.SendTime;
|
else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days);
|
||||||
if (ts.TotalMinutes < 5) n.Period = "刚刚";
|
else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
|
||||||
else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days);
|
else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
|
||||||
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;
|
||||||
});
|
}
|
||||||
return messageRet;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,322 +1,318 @@
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
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";
|
/// <summary>
|
||||||
internal const string RetrieveRolesByUserIdDataKey = "RoleHelper-RetrieveRolesByUserId";
|
/// 查询所有角色
|
||||||
internal const string RetrieveRolesByMenuIdDataKey = "RoleHelper-RetrieveRolesByMenuId";
|
/// </summary>
|
||||||
internal const string RetrieveRolesByGroupIdDataKey = "RoleHelper-RetrieveRolesByGroupId";
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 查询所有角色
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRoles(int id = 0)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="id"></param>
|
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<Role> RetrieveRoles(int id = 0)
|
string sql = "select * from Roles";
|
||||||
{
|
var roles = new List<Role>();
|
||||||
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
{
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
string sql = "select * from Roles";
|
{
|
||||||
List<Role> roles = new List<Role>();
|
while (reader.Read())
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
roles.Add(new Role()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
RoleName = (string)reader[1],
|
||||||
roles.Add(new Role()
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
|
||||||
{
|
});
|
||||||
Id = (int)reader[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);
|
||||||
}
|
}
|
||||||
return roles;
|
/// <summary>
|
||||||
});
|
/// 保存用户角色关系
|
||||||
return id == 0 ? ret : ret.Where(t => id == t.Id);
|
/// </summary>
|
||||||
}
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="roleIds"></param>
|
||||||
/// 保存用户角色关系
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override bool SaveRolesByUserId(int id, IEnumerable<int> roleIds)
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <param name="roleIds"></param>
|
var ret = false;
|
||||||
/// <returns></returns>
|
DataTable dt = new DataTable();
|
||||||
public static bool SaveRolesByUserId(int id, IEnumerable<int> roleIds)
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
{
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
var ret = false;
|
//判断用户是否选定角色
|
||||||
DataTable dt = new DataTable();
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
||||||
dt.Columns.Add("UserID", typeof(int));
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
{
|
||||||
//判断用户是否选定角色
|
try
|
||||||
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
{
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
// delete user from config table
|
||||||
{
|
string sql = "delete from UserRole where UserID = @UserID;";
|
||||||
try
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
// delete user from config table
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", id));
|
||||||
string sql = "delete from UserRole where UserID = @UserID;";
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
if (dt.Rows.Count > 0)
|
||||||
{
|
{
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", id));
|
// insert batch data into config table
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
if (dt.Rows.Count > 0)
|
{
|
||||||
{
|
bulk.DestinationTableName = "UserRole";
|
||||||
// insert batch data into config table
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
{
|
bulk.WriteToServer(dt);
|
||||||
bulk.DestinationTableName = "UserRole";
|
}
|
||||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
}
|
||||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
transaction.CommitTransaction();
|
||||||
bulk.WriteToServer(dt);
|
}
|
||||||
}
|
CacheCleanUtility.ClearCache(userIds: new List<int>() { id }, roleIds: roleIds);
|
||||||
}
|
ret = true;
|
||||||
transaction.CommitTransaction();
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
CacheCleanUtility.ClearCache(userIds: new List<int>() { id }, roleIds: roleIds);
|
{
|
||||||
ret = true;
|
transaction.RollbackTransaction();
|
||||||
}
|
throw ex;
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
transaction.RollbackTransaction();
|
return ret;
|
||||||
throw ex;
|
}
|
||||||
}
|
/// <summary>
|
||||||
}
|
/// 查询某个用户所拥有的角色
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <returns></returns>
|
||||||
/// <summary>
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRolesByUserId(int userId)
|
||||||
/// 查询某个用户所拥有的角色
|
{
|
||||||
/// </summary>
|
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId);
|
||||||
/// <returns></returns>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
public static IEnumerable<Role> RetrieveRolesByUserId(int userId)
|
{
|
||||||
{
|
List<Role> roles = new List<Role>();
|
||||||
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, 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";
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@UserID", userId));
|
||||||
List<Role> roles = new List<Role>();
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
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);
|
while (reader.Read())
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", userId));
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
roles.Add(new Role()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
RoleName = (string)reader[1],
|
||||||
roles.Add(new Role()
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
{
|
Checked = (string)reader[3]
|
||||||
Id = (int)reader[0],
|
});
|
||||||
RoleName = (string)reader[1],
|
}
|
||||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
}
|
||||||
Checked = (string)reader[3]
|
return roles;
|
||||||
});
|
}, RetrieveRolesByUserIdDataKey);
|
||||||
}
|
}
|
||||||
}
|
/// <summary>
|
||||||
return roles;
|
/// 删除角色表
|
||||||
}, RetrieveRolesByUserIdDataKey);
|
/// </summary>
|
||||||
}
|
/// <param name="value"></param>
|
||||||
/// <summary>
|
public override bool DeleteRole(IEnumerable<int> value)
|
||||||
/// 删除角色表
|
{
|
||||||
/// </summary>
|
bool ret = false;
|
||||||
/// <param name="value"></param>
|
var ids = string.Join(",", value);
|
||||||
public static bool DeleteRole(IEnumerable<int> value)
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
||||||
{
|
{
|
||||||
bool ret = false;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
var ids = string.Join(",", value);
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles"))
|
}
|
||||||
{
|
CacheCleanUtility.ClearCache(roleIds: value);
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
}
|
||||||
}
|
/// <summary>
|
||||||
CacheCleanUtility.ClearCache(roleIds: value);
|
/// 保存新建/更新的角色信息
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="p"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 保存新建/更新的角色信息
|
public override bool SaveRole(Bootstrap.DataAccess.Role p)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="p"></param>
|
bool ret = false;
|
||||||
/// <returns></returns>
|
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
|
||||||
public static bool SaveRole(Role p)
|
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 50) p.Description = p.Description.Substring(0, 500);
|
||||||
{
|
string sql = p.Id == 0 ?
|
||||||
bool ret = false;
|
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
||||||
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
|
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
||||||
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 50) p.Description = p.Description.Substring(0, 500);
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
string sql = p.Id == 0 ?
|
{
|
||||||
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ID", p.Id));
|
||||||
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Description", DbAccessFactory.ToDBValue(p.Description)));
|
||||||
{
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ID", p.Id));
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleName", p.RoleName));
|
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
}
|
||||||
}
|
/// <summary>
|
||||||
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
|
/// 查询某个菜单所拥有的角色
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="menuId"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 查询某个菜单所拥有的角色
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRolesByMenuId(int menuId)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="menuId"></param>
|
string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
|
||||||
/// <returns></returns>
|
var ret = CacheManager.GetOrAdd(key, k =>
|
||||||
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId)
|
{
|
||||||
{
|
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 key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
|
List<Role> roles = new List<Role>();
|
||||||
var ret = CacheManager.GetOrAdd(key, k =>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
|
||||||
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";
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
List<Role> roles = new List<Role>();
|
{
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
while (reader.Read())
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId));
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
roles.Add(new Role()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
RoleName = (string)reader[1],
|
||||||
roles.Add(new Role()
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
{
|
Checked = (string)reader[3]
|
||||||
Id = (int)reader[0],
|
});
|
||||||
RoleName = (string)reader[1],
|
}
|
||||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
}
|
||||||
Checked = (string)reader[3]
|
return roles;
|
||||||
});
|
}, RetrieveRolesByMenuIdDataKey);
|
||||||
}
|
return ret;
|
||||||
}
|
}
|
||||||
return roles;
|
/// <summary>
|
||||||
}, RetrieveRolesByMenuIdDataKey);
|
///
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="roleIds"></param>
|
||||||
///
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds)
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <param name="roleIds"></param>
|
var ret = false;
|
||||||
/// <returns></returns>
|
DataTable dt = new DataTable();
|
||||||
public static bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds)
|
dt.Columns.Add("NavigationID", typeof(int));
|
||||||
{
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
var ret = false;
|
//判断用户是否选定角色
|
||||||
DataTable dt = new DataTable();
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
||||||
dt.Columns.Add("NavigationID", typeof(int));
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
{
|
||||||
//判断用户是否选定角色
|
try
|
||||||
roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId));
|
{
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
// delete role from config table
|
||||||
{
|
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
|
||||||
try
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
// delete role from config table
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@NavigationID", id));
|
||||||
string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
|
||||||
{
|
// insert batch data into config table
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", id));
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
{
|
||||||
|
bulk.BatchSize = 1000;
|
||||||
// insert batch data into config table
|
bulk.DestinationTableName = "NavigationRole";
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
|
||||||
{
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
bulk.BatchSize = 1000;
|
bulk.WriteToServer(dt);
|
||||||
bulk.DestinationTableName = "NavigationRole";
|
transaction.CommitTransaction();
|
||||||
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
|
}
|
||||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
}
|
||||||
bulk.WriteToServer(dt);
|
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<int>() { id });
|
||||||
transaction.CommitTransaction();
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<int>() { id });
|
{
|
||||||
ret = true;
|
transaction.RollbackTransaction();
|
||||||
}
|
throw ex;
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
transaction.RollbackTransaction();
|
return ret;
|
||||||
throw ex;
|
}
|
||||||
}
|
/// <summary>
|
||||||
}
|
/// 根据GroupId查询和该Group有关的所有Roles
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="groupId"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 根据GroupId查询和该Group有关的所有Roles
|
public override IEnumerable<Bootstrap.DataAccess.Role> RetrieveRolesByGroupId(int groupId)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="groupId"></param>
|
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId);
|
||||||
/// <returns></returns>
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId)
|
{
|
||||||
{
|
List<Role> roles = new List<Role>();
|
||||||
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, 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";
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
|
||||||
List<Role> roles = new List<Role>();
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
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);
|
while (reader.Read())
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
roles.Add(new Role()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
RoleName = (string)reader[1],
|
||||||
roles.Add(new Role()
|
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
||||||
{
|
Checked = (string)reader[3]
|
||||||
Id = (int)reader[0],
|
});
|
||||||
RoleName = (string)reader[1],
|
}
|
||||||
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
|
}
|
||||||
Checked = (string)reader[3]
|
return roles;
|
||||||
});
|
}, RetrieveRolesByGroupIdDataKey);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return roles;
|
/// <summary>
|
||||||
}, RetrieveRolesByGroupIdDataKey);
|
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="roleIds"></param>
|
||||||
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds)
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <param name="roleIds"></param>
|
var ret = false;
|
||||||
/// <returns></returns>
|
//构造表格
|
||||||
public static bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds)
|
DataTable dt = new DataTable();
|
||||||
{
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
var ret = false;
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
//构造表格
|
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
|
||||||
DataTable dt = new DataTable();
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
{
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
try
|
||||||
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id));
|
{
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
// delete user from config table
|
||||||
{
|
string sql = "delete from RoleGroup where GroupID=@GroupID";
|
||||||
try
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
// delete user from config table
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
|
||||||
string sql = "delete from RoleGroup where GroupID=@GroupID";
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
|
||||||
{
|
// insert batch data into config table
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id));
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
{
|
||||||
|
bulk.BatchSize = 1000;
|
||||||
// insert batch data into config table
|
bulk.DestinationTableName = "RoleGroup";
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
{
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
bulk.BatchSize = 1000;
|
bulk.WriteToServer(dt);
|
||||||
bulk.DestinationTableName = "RoleGroup";
|
transaction.CommitTransaction();
|
||||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
}
|
||||||
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
}
|
||||||
bulk.WriteToServer(dt);
|
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<int>() { id });
|
||||||
transaction.CommitTransaction();
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<int>() { id });
|
{
|
||||||
ret = true;
|
transaction.RollbackTransaction();
|
||||||
}
|
throw ex;
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
transaction.RollbackTransaction();
|
return ret;
|
||||||
throw ex;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,44 +1,43 @@
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
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 override IEnumerable<Bootstrap.DataAccess.Task> RetrieveTasks()
|
||||||
public static IEnumerable<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.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
{
|
||||||
{
|
while (reader.Read())
|
||||||
while (reader.Read())
|
{
|
||||||
{
|
tasks.Add(new Task()
|
||||||
tasks.Add(new Task()
|
{
|
||||||
{
|
Id = (int)reader[0],
|
||||||
Id = (int)reader[0],
|
TaskName = (string)reader[1],
|
||||||
TaskName = (string)reader[1],
|
AssignName = (string)reader[2],
|
||||||
AssignName = (string)reader[2],
|
UserName = (string)reader[3],
|
||||||
UserName = (string)reader[3],
|
TaskTime = (int)reader[4],
|
||||||
TaskTime = (int)reader[4],
|
TaskProgress = (double)reader[5],
|
||||||
TaskProgress = (double)reader[5],
|
AssignTime = (DateTime)reader[6],
|
||||||
AssignTime = (DateTime)reader[6],
|
AssignDisplayName = (string)reader[7]
|
||||||
AssignDisplayName = (string)reader[7]
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
return tasks;
|
||||||
return tasks;
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -1,419 +1,421 @@
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
using Longbow;
|
using Longbow;
|
||||||
using Longbow.Cache;
|
using Longbow.Cache;
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using Longbow.Security;
|
using Longbow.Security;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
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>
|
/// 用户表实体类
|
||||||
public static class UserHelper
|
/// </summary>
|
||||||
{
|
public class User : Bootstrap.DataAccess.User
|
||||||
internal const string RetrieveUsersDataKey = "BootstrapUser-RetrieveUsers";
|
{
|
||||||
internal const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId";
|
/// <summary>
|
||||||
internal const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId";
|
/// 查询所有用户
|
||||||
internal const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 查询所有用户
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveUsers()
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="id"></param>
|
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<User> RetrieveUsers()
|
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");
|
||||||
return CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
|
|
||||||
{
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
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");
|
while (reader.Read())
|
||||||
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
users.Add(new User()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
UserName = (string)reader[1],
|
||||||
users.Add(new User()
|
DisplayName = (string)reader[2],
|
||||||
{
|
RegisterTime = (DateTime)reader[3],
|
||||||
Id = (int)reader[0],
|
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue),
|
||||||
UserName = (string)reader[1],
|
ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
|
||||||
DisplayName = (string)reader[2],
|
Description = (string)reader[6]
|
||||||
RegisterTime = (DateTime)reader[3],
|
});
|
||||||
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue),
|
}
|
||||||
ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
|
}
|
||||||
Description = (string)reader[6]
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
/// <summary>
|
||||||
return users;
|
/// 查询所有的新注册用户
|
||||||
});
|
/// </summary>
|
||||||
}
|
/// <returns></returns>
|
||||||
/// <summary>
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveNewUsers()
|
||||||
/// 查询所有的新注册用户
|
{
|
||||||
/// </summary>
|
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
|
||||||
/// <returns></returns>
|
{
|
||||||
public static IEnumerable<User> RetrieveNewUsers()
|
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
|
||||||
{
|
List<User> users = new List<User>();
|
||||||
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
{
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null order by RegisterTime desc";
|
{
|
||||||
List<User> users = new List<User>();
|
while (reader.Read())
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
{
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
users.Add(new User()
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
Id = (int)reader[0],
|
||||||
{
|
UserName = (string)reader[1],
|
||||||
users.Add(new User()
|
DisplayName = (string)reader[2],
|
||||||
{
|
RegisterTime = (DateTime)reader[3],
|
||||||
Id = (int)reader[0],
|
Description = (string)reader[4]
|
||||||
UserName = (string)reader[1],
|
});
|
||||||
DisplayName = (string)reader[2],
|
}
|
||||||
RegisterTime = (DateTime)reader[3],
|
}
|
||||||
Description = (string)reader[4]
|
return users;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
/// <summary>
|
||||||
return users;
|
/// 删除用户
|
||||||
});
|
/// </summary>
|
||||||
}
|
/// <param name="value"></param>
|
||||||
/// <summary>
|
public override bool DeleteUser(IEnumerable<int> value)
|
||||||
/// 删除用户
|
{
|
||||||
/// </summary>
|
bool ret = false;
|
||||||
/// <param name="value"></param>
|
var ids = string.Join(",", value);
|
||||||
public static bool DeleteUser(IEnumerable<int> value)
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
|
||||||
{
|
{
|
||||||
bool ret = false;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@ids", ids));
|
||||||
var ids = string.Join(",", value);
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
|
if (ret) CacheCleanUtility.ClearCache(userIds: value);
|
||||||
{
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
}
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: value);
|
/// <summary>
|
||||||
}
|
/// 保存新建
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="p"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// 保存新建
|
public override bool SaveUser(Bootstrap.DataAccess.User p)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="p"></param>
|
var ret = false;
|
||||||
/// <returns></returns>
|
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
||||||
public static bool SaveUser(User p)
|
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
|
||||||
{
|
p.PassSalt = LgbCryptography.GenerateSalt();
|
||||||
var ret = false;
|
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||||
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
|
||||||
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
|
{
|
||||||
p.PassSalt = LgbCryptography.GenerateSalt();
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
|
||||||
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@password", p.Password));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@passSalt", p.PassSalt));
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@displayName", p.DisplayName));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", p.UserName));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", DbAccessFactory.ToDBValue(p.ApprovedBy)));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@password", p.Password));
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@description", p.Description));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@passSalt", p.PassSalt));
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@displayName", p.DisplayName));
|
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", DBAccessFactory.ToDBValue(p.ApprovedBy)));
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@description", p.Description));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
}
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
/// <summary>
|
||||||
}
|
///
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="password"></param>
|
||||||
///
|
/// <param name="displayName"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="id"></param>
|
public override bool UpdateUser(int id, string password, string displayName)
|
||||||
/// <param name="password"></param>
|
{
|
||||||
/// <param name="displayName"></param>
|
bool ret = false;
|
||||||
/// <returns></returns>
|
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
|
||||||
public static bool UpdateUser(int id, string password, string displayName)
|
var passSalt = LgbCryptography.GenerateSalt();
|
||||||
{
|
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||||
bool ret = false;
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
|
{
|
||||||
var passSalt = LgbCryptography.GenerateSalt();
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@Password", newPassword));
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id));
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", displayName));
|
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", newPassword));
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", passSalt));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
}
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
|
/// <summary>
|
||||||
}
|
///
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="approvedBy"></param>
|
||||||
///
|
/// <returns></returns>
|
||||||
/// </summary>
|
public override bool ApproveUser(int id, string approvedBy)
|
||||||
/// <param name="id"></param>
|
{
|
||||||
/// <param name="approvedBy"></param>
|
var ret = false;
|
||||||
/// <returns></returns>
|
var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id";
|
||||||
public static bool ApproveUser(int id, string approvedBy)
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
{
|
{
|
||||||
var ret = false;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id";
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
{
|
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id));
|
}
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", approvedBy));
|
return ret;
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
}
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
/// <summary>
|
||||||
}
|
///
|
||||||
return ret;
|
/// </summary>
|
||||||
}
|
/// <param name="id"></param>
|
||||||
/// <summary>
|
/// <param name="rejectBy"></param>
|
||||||
///
|
/// <param name="reason"></param>
|
||||||
/// </summary>
|
/// <returns></returns>
|
||||||
/// <param name="userName"></param>
|
public override bool RejectUser(int id, string rejectBy)
|
||||||
/// <param name="password"></param>
|
{
|
||||||
/// <param name="newPass"></param>
|
var ret = false;
|
||||||
/// <returns></returns>
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
|
||||||
public static bool ChangePassword(string userName, string password, string newPass)
|
{
|
||||||
{
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@id", id));
|
||||||
bool ret = false;
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
|
||||||
if (BootstrapUser.Authenticate(userName, password))
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
|
||||||
{
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
|
||||||
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
|
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
||||||
var passSalt = LgbCryptography.GenerateSalt();
|
}
|
||||||
var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
|
return ret;
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
}
|
||||||
{
|
/// <summary>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", newPassword));
|
/// 通过roleId获取所有用户
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", passSalt));
|
/// </summary>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
/// <param name="roleId"></param>
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
/// <returns></returns>
|
||||||
}
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveUsersByRoleId(int roleId)
|
||||||
}
|
{
|
||||||
return ret;
|
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
|
||||||
}
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
/// <summary>
|
{
|
||||||
///
|
List<User> users = new List<User>();
|
||||||
/// </summary>
|
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";
|
||||||
/// <param name="id"></param>
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
/// <param name="rejectBy"></param>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
|
||||||
/// <param name="reason"></param>
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
/// <returns></returns>
|
{
|
||||||
public static bool RejectUser(int id, string rejectBy)
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
var ret = false;
|
users.Add(new User()
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
|
{
|
||||||
{
|
Id = (int)reader[0],
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id));
|
UserName = (string)reader[1],
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedBy", rejectBy));
|
DisplayName = (string)reader[2],
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedReason", "未填写"));
|
Checked = (string)reader[3]
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
|
});
|
||||||
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return users;
|
||||||
}
|
}, RetrieveUsersByRoleIdDataKey);
|
||||||
/// <summary>
|
}
|
||||||
/// 通过roleId获取所有用户
|
/// <summary>
|
||||||
/// </summary>
|
/// 通过角色ID保存当前授权用户(插入)
|
||||||
/// <param name="roleId"></param>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="id">角色ID</param>
|
||||||
public static IEnumerable<User> RetrieveUsersByRoleId(int roleId)
|
/// <param name="userIds">用户ID数组</param>
|
||||||
{
|
/// <returns></returns>
|
||||||
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
|
public override bool SaveUsersByRoleId(int id, IEnumerable<int> userIds)
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
{
|
||||||
{
|
bool ret = false;
|
||||||
List<User> users = new List<User>();
|
DataTable dt = new DataTable();
|
||||||
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";
|
dt.Columns.Add("RoleID", typeof(int));
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
try
|
||||||
{
|
{
|
||||||
users.Add(new User()
|
//删除用户角色表该角色所有的用户
|
||||||
{
|
string sql = "delete from UserRole where RoleID=@RoleID";
|
||||||
Id = (int)reader[0],
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
UserName = (string)reader[1],
|
{
|
||||||
DisplayName = (string)reader[2],
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@RoleID", id));
|
||||||
Checked = (string)reader[3]
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
});
|
//批插入用户角色表
|
||||||
}
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
}
|
{
|
||||||
return users;
|
bulk.DestinationTableName = "UserRole";
|
||||||
}, RetrieveUsersByRoleIdDataKey);
|
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
||||||
}
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
/// <summary>
|
bulk.WriteToServer(dt);
|
||||||
/// 通过角色ID保存当前授权用户(插入)
|
transaction.CommitTransaction();
|
||||||
/// </summary>
|
}
|
||||||
/// <param name="id">角色ID</param>
|
}
|
||||||
/// <param name="userIds">用户ID数组</param>
|
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<int>() { id });
|
||||||
/// <returns></returns>
|
ret = true;
|
||||||
public static bool SaveUsersByRoleId(int id, IEnumerable<int> userIds)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
bool ret = false;
|
{
|
||||||
DataTable dt = new DataTable();
|
transaction.RollbackTransaction();
|
||||||
dt.Columns.Add("RoleID", typeof(int));
|
throw ex;
|
||||||
dt.Columns.Add("UserID", typeof(int));
|
}
|
||||||
userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId));
|
}
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
return ret;
|
||||||
{
|
}
|
||||||
try
|
/// <summary>
|
||||||
{
|
/// 通过groupId获取所有用户
|
||||||
//删除用户角色表该角色所有的用户
|
/// </summary>
|
||||||
string sql = "delete from UserRole where RoleID=@RoleID";
|
/// <param name="groupId"></param>
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
/// <returns></returns>
|
||||||
{
|
public override IEnumerable<Bootstrap.DataAccess.User> RetrieveUsersByGroupId(int groupId)
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id));
|
{
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
|
||||||
//批插入用户角色表
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
{
|
||||||
{
|
List<User> users = new List<User>();
|
||||||
bulk.DestinationTableName = "UserRole";
|
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";
|
||||||
bulk.ColumnMappings.Add("RoleID", "RoleID");
|
DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
|
||||||
bulk.WriteToServer(dt);
|
using (DbDataReader reader = DBAccessManager.DBAccess.ExecuteReader(cmd))
|
||||||
transaction.CommitTransaction();
|
{
|
||||||
}
|
while (reader.Read())
|
||||||
}
|
{
|
||||||
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<int>() { id });
|
users.Add(new User()
|
||||||
ret = true;
|
{
|
||||||
}
|
Id = (int)reader[0],
|
||||||
catch (Exception ex)
|
UserName = (string)reader[1],
|
||||||
{
|
DisplayName = (string)reader[2],
|
||||||
transaction.RollbackTransaction();
|
Checked = (string)reader[3]
|
||||||
throw ex;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return users;
|
||||||
}
|
}, RetrieveUsersByRoleIdDataKey);
|
||||||
/// <summary>
|
}
|
||||||
/// 通过groupId获取所有用户
|
/// <summary>
|
||||||
/// </summary>
|
/// 通过部门ID保存当前授权用户(插入)
|
||||||
/// <param name="groupId"></param>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="id">GroupID</param>
|
||||||
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId)
|
/// <param name="userIds">用户ID数组</param>
|
||||||
{
|
/// <returns></returns>
|
||||||
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
|
public override bool SaveUsersByGroupId(int id, IEnumerable<int> userIds)
|
||||||
return CacheManager.GetOrAdd(key, k =>
|
{
|
||||||
{
|
bool ret = false;
|
||||||
List<User> users = new List<User>();
|
DataTable dt = new DataTable();
|
||||||
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";
|
dt.Columns.Add("UserID", typeof(int));
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
dt.Columns.Add("GroupID", typeof(int));
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (TransactionPackage transaction = DBAccessManager.DBAccess.BeginTransaction())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
try
|
||||||
{
|
{
|
||||||
users.Add(new User()
|
//删除用户角色表该角色所有的用户
|
||||||
{
|
string sql = "delete from UserGroup where GroupID = @GroupID";
|
||||||
Id = (int)reader[0],
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
UserName = (string)reader[1],
|
{
|
||||||
DisplayName = (string)reader[2],
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@GroupID", id));
|
||||||
Checked = (string)reader[3]
|
DBAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
||||||
});
|
//批插入用户角色表
|
||||||
}
|
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
||||||
}
|
{
|
||||||
return users;
|
bulk.DestinationTableName = "UserGroup";
|
||||||
}, RetrieveUsersByRoleIdDataKey);
|
bulk.ColumnMappings.Add("UserID", "UserID");
|
||||||
}
|
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
||||||
/// <summary>
|
bulk.WriteToServer(dt);
|
||||||
/// 通过部门ID保存当前授权用户(插入)
|
transaction.CommitTransaction();
|
||||||
/// </summary>
|
}
|
||||||
/// <param name="id">GroupID</param>
|
}
|
||||||
/// <param name="userIds">用户ID数组</param>
|
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<int>() { id });
|
||||||
/// <returns></returns>
|
ret = true;
|
||||||
public static bool SaveUsersByGroupId(int id, IEnumerable<int> userIds)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
bool ret = false;
|
{
|
||||||
DataTable dt = new DataTable();
|
transaction.RollbackTransaction();
|
||||||
dt.Columns.Add("UserID", typeof(int));
|
throw ex;
|
||||||
dt.Columns.Add("GroupID", typeof(int));
|
}
|
||||||
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id));
|
}
|
||||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
return ret;
|
||||||
{
|
}
|
||||||
try
|
/// <summary>
|
||||||
{
|
/// 根据用户名修改用户头像
|
||||||
//删除用户角色表该角色所有的用户
|
/// </summary>
|
||||||
string sql = "delete from UserGroup where GroupID = @GroupID";
|
/// <param name="userName"></param>
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
/// <param name="iconName"></param>
|
||||||
{
|
/// <returns></returns>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id));
|
public override bool SaveUserIconByName(string userName, string iconName)
|
||||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
|
{
|
||||||
//批插入用户角色表
|
bool ret = false;
|
||||||
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
|
string sql = "Update Users set Icon = @iconName where UserName = @userName";
|
||||||
{
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
bulk.DestinationTableName = "UserGroup";
|
{
|
||||||
bulk.ColumnMappings.Add("UserID", "UserID");
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@iconName", iconName));
|
||||||
bulk.ColumnMappings.Add("GroupID", "GroupID");
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
bulk.WriteToServer(dt);
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
transaction.CommitTransaction();
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
}
|
}
|
||||||
}
|
return ret;
|
||||||
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<int>() { id });
|
}
|
||||||
ret = true;
|
/// <summary>
|
||||||
}
|
///
|
||||||
catch (Exception ex)
|
/// </summary>
|
||||||
{
|
/// <param name="userName"></param>
|
||||||
transaction.RollbackTransaction();
|
/// <param name="displayName"></param>
|
||||||
throw ex;
|
/// <returns></returns>
|
||||||
}
|
public override bool SaveDisplayName(string userName, string displayName)
|
||||||
}
|
{
|
||||||
return ret;
|
bool ret = false;
|
||||||
}
|
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
|
||||||
/// <summary>
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
/// 根据用户名修改用户头像
|
{
|
||||||
/// </summary>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
|
||||||
/// <param name="userName"></param>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
/// <param name="iconName"></param>
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
/// <returns></returns>
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
public static bool SaveUserIconByName(string userName, string iconName)
|
}
|
||||||
{
|
return ret;
|
||||||
bool ret = false;
|
}
|
||||||
string sql = "Update Users set Icon = @iconName where UserName = @userName";
|
/// <summary>
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
/// 根据用户名更改用户皮肤
|
||||||
{
|
/// </summary>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@iconName", iconName));
|
/// <param name="userName"></param>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
/// <param name="cssName"></param>
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
/// <returns></returns>
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
public override bool SaveUserCssByName(string userName, string cssName)
|
||||||
}
|
{
|
||||||
return ret;
|
bool ret = false;
|
||||||
}
|
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
||||||
/// <summary>
|
using (DbCommand cmd = DBAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
||||||
///
|
{
|
||||||
/// </summary>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@cssName", DbAccessFactory.ToDBValue(cssName)));
|
||||||
/// <param name="userName"></param>
|
cmd.Parameters.Add(DBAccessManager.DBAccess.CreateParameter("@userName", userName));
|
||||||
/// <param name="displayName"></param>
|
ret = DBAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
|
||||||
/// <returns></returns>
|
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
||||||
public static bool SaveDisplayName(string userName, string displayName)
|
}
|
||||||
{
|
return ret;
|
||||||
bool ret = false;
|
}
|
||||||
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
|
/// <summary>
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
///
|
||||||
{
|
/// </summary>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", displayName));
|
/// <param name="userName"></param>
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
/// <returns></returns>
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
public override BootstrapUser RetrieveUserByUserName(string userName)
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
{
|
||||||
}
|
var key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
|
||||||
return ret;
|
return CacheManager.GetOrAdd(key, k =>
|
||||||
}
|
{
|
||||||
/// <summary>
|
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";
|
||||||
/// </summary>
|
var db = DBAccessManager.DBAccess;
|
||||||
/// <param name="userName"></param>
|
var cmd = db.CreateCommand(CommandType.Text, sql);
|
||||||
/// <param name="cssName"></param>
|
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
|
||||||
/// <returns></returns>
|
using (DbDataReader reader = db.ExecuteReader(cmd))
|
||||||
public static bool SaveUserCssByName(string userName, string cssName)
|
{
|
||||||
{
|
if (reader.Read())
|
||||||
bool ret = false;
|
{
|
||||||
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
user = new BootstrapUser
|
||||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
{
|
||||||
{
|
UserName = (string)reader[0],
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@cssName", DBAccessFactory.ToDBValue(cssName)));
|
DisplayName = (string)reader[1],
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", userName));
|
Icon = (string)reader[2],
|
||||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
|
||||||
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
|
};
|
||||||
}
|
}
|
||||||
return ret;
|
}
|
||||||
}
|
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,87 +1,89 @@
|
||||||
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
|
{
|
||||||
{
|
/// <summary>
|
||||||
internal static class CacheCleanUtility
|
///
|
||||||
{
|
/// </summary>
|
||||||
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
public static class CacheCleanUtility
|
||||||
/// <summary>
|
{
|
||||||
///
|
private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles";
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="roleIds"></param>
|
///
|
||||||
/// <param name="userIds"></param>
|
/// </summary>
|
||||||
/// <param name="groupIds"></param>
|
/// <param name="roleIds"></param>
|
||||||
/// <param name="menuIds"></param>
|
/// <param name="userIds"></param>
|
||||||
/// <param name="dictIds"></param>
|
/// <param name="groupIds"></param>
|
||||||
/// <param name="cacheKey"></param>
|
/// <param name="menuIds"></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)
|
/// <param name="dictIds"></param>
|
||||||
{
|
/// <param name="cacheKey"></param>
|
||||||
var cacheKeys = new List<string>();
|
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 corsKeys = new List<string>();
|
{
|
||||||
if (roleIds != null)
|
var cacheKeys = new List<string>();
|
||||||
{
|
var corsKeys = new List<string>();
|
||||||
roleIds.ToList().ForEach(id =>
|
if (roleIds != null)
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
|
roleIds.ToList().ForEach(id =>
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", MenuHelper.RetrieveMenusByRoleIdDataKey, id));
|
cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByRoleIdDataKey, id));
|
||||||
});
|
cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByRoleIdDataKey, id));
|
||||||
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
|
cacheKeys.Add(string.Format("{0}-{1}", Menu.RetrieveMenusByRoleIdDataKey, id));
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
});
|
||||||
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
cacheKeys.Add(Role.RetrieveRolesDataKey + "*");
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
}
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
||||||
if (userIds != null)
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
{
|
}
|
||||||
userIds.ToList().ForEach(id =>
|
if (userIds != null)
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
|
userIds.ToList().ForEach(id =>
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
|
{
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByUserIdDataKey, id));
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(string.Format("{0}-{1}", Group.RetrieveGroupsByUserIdDataKey, id));
|
||||||
});
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
});
|
||||||
corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
|
cacheKeys.Add(User.RetrieveNewUsersDataKey + "*");
|
||||||
}
|
cacheKeys.Add(User.RetrieveUsersDataKey + "*");
|
||||||
if (groupIds != null)
|
corsKeys.Add(User.RetrieveUsersDataKey + "*");
|
||||||
{
|
}
|
||||||
groupIds.ToList().ForEach(id =>
|
if (groupIds != null)
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
|
groupIds.ToList().ForEach(id =>
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
|
{
|
||||||
});
|
cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByGroupIdDataKey, id));
|
||||||
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
|
cacheKeys.Add(string.Format("{0}-{1}", User.RetrieveUsersByGroupIdDataKey, id));
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
});
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Group.RetrieveGroupsDataKey + "*");
|
||||||
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
}
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
if (menuIds != null)
|
cacheKeys.Add(RetrieveAllRolesDataKey + "*");
|
||||||
{
|
}
|
||||||
menuIds.ToList().ForEach(id =>
|
if (menuIds != null)
|
||||||
{
|
{
|
||||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
menuIds.ToList().ForEach(id =>
|
||||||
});
|
{
|
||||||
cacheKeys.Add(MenuHelper.RetrieveMenusByRoleIdDataKey + "*");
|
cacheKeys.Add(string.Format("{0}-{1}", Role.RetrieveRolesByMenuIdDataKey, id));
|
||||||
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
});
|
||||||
corsKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
|
cacheKeys.Add(Menu.RetrieveMenusByRoleIdDataKey + "*");
|
||||||
}
|
cacheKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
if (dictIds != null)
|
corsKeys.Add(Menu.RetrieveMenusDataKey + "*");
|
||||||
{
|
}
|
||||||
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
if (dictIds != null)
|
||||||
cacheKeys.Add(DictHelper.RetrieveCategoryDataKey);
|
{
|
||||||
corsKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
|
cacheKeys.Add(Dict.RetrieveDictsDataKey + "*");
|
||||||
}
|
cacheKeys.Add(Dict.RetrieveCategoryDataKey);
|
||||||
if (cacheKey != null)
|
corsKeys.Add(Dict.RetrieveDictsDataKey + "*");
|
||||||
{
|
}
|
||||||
cacheKeys.Add(cacheKey);
|
if (cacheKey != null)
|
||||||
corsKeys.Add(cacheKey);
|
{
|
||||||
}
|
cacheKeys.Add(cacheKey);
|
||||||
CacheManager.Clear(cacheKeys);
|
corsKeys.Add(cacheKey);
|
||||||
CacheManager.CorsClear(corsKeys);
|
}
|
||||||
}
|
CacheManager.Clear(cacheKeys);
|
||||||
}
|
CacheManager.CorsClear(corsKeys);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
using Longbow.Data;
|
using Longbow.Data;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </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>
|
||||||
get { return db.Value; }
|
public static IDbAccess DBAccess
|
||||||
}
|
{
|
||||||
}
|
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