增加工程:增加MySQL数据库支持

This commit is contained in:
Argo-MacBookPro 2018-11-02 12:46:56 +08:00
parent 9294cf1fc6
commit c5fde0ba3b
15 changed files with 1390 additions and 13 deletions

View File

@ -28,6 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess.MongoDB\Bootstrap.DataAccess.MongoDB.csproj" />
<ProjectReference Include="..\Bootstrap.DataAccess.MySQL\Bootstrap.DataAccess.MySQL.csproj" />
<ProjectReference Include="..\Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj" />
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>

View File

@ -17,11 +17,19 @@
},
"DB": [
{
"Enabled": false,
"Enabled": true,
"Widget": "Bootstrap.DataAccess"
},
{
"Enabled": false,
"Enabled": true,
"Widget": "Bootstrap.DataAccess.MySQL",
"DBProviderFactory": "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data",
"ConnectionStrings": {
"ba": "Server=10.211.55.2;Database=BA;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"
}
},
{
"Enabled": true,
"Widget": "Bootstrap.DataAccess.SQLite",
"DBProviderFactory": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite",
"ConnectionStrings": {

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\Keys\Longbow.Utility.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\Keys\Longbow.Utility.snk" Link="Longbow.Utility.snk" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Dict : DataAccess.Dict
{
}
}

View File

@ -0,0 +1,92 @@
using Longbow;
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.MySQL
{
/// <summary>
///
/// </summary>
public class Exceptions : DataAccess.Exceptions
{
/// <summary>
///
/// </summary>
private static void ClearExceptions()
{
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Exceptions where LogTime < date_add(now(), interval -{ConfigurationManager.AppSettings["KeepExceptionsPeriod"]} month)";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
});
}
/// <summary>
///
/// </summary>
/// <param name="ex"></param>
/// <param name="additionalInfo"></param>
/// <returns></returns>
public override bool Log(Exception ex, NameValueCollection additionalInfo)
{
if (additionalInfo == null)
{
additionalInfo = new NameValueCollection
{
["UserId"] = null,
["UserIp"] = null,
["ErrorPage"] = null
};
}
var errorPage = additionalInfo["ErrorPage"] ?? ex.GetType().Name;
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, now())";
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", DbAdapterManager.ToDBValue(additionalInfo["UserId"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAdapterManager.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", DbAdapterManager.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
ClearExceptions();
}
return true;
}
/// <summary>
/// 查询一周内所有异常
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Exceptions> RetrieveExceptions()
{
string sql = "select * from Exceptions where LogTime > date_add(now(), interval -7 day) order by LogTime desc";
List<DataAccess.Exceptions> exceptions = new List<DataAccess.Exceptions>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
exceptions.Add(new DataAccess.Exceptions()
{
Id = reader[0].ToString(),
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;
}
}
}

View File

@ -0,0 +1,228 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Group : DataAccess.Group
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroups()
{
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 = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
});
}
}
return groups;
}
/// <summary>
///
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveGroup(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 = string.IsNullOrEmpty(p.Id) ?
"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", DbAdapterManager.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
/// <summary>
/// <summary>
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public override bool DeleteGroup(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserGroup where GroupID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from RoleGroup where GroupID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from `Groups` where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroupsByUserId(string userId)
{
string sql = "select g.ID,g.GroupName,g.Description,case ug.GroupID when g.ID then 'checked' else '' end status from `Groups` g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
List<Group> groups = new List<Group>();
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 = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return groups;
}
/// <summary>
/// 保存用户部门关系
/// </summary>
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户部门表中该用户所有的部门关系
string sql = $"delete from UserGroup where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
groupIds.ToList().ForEach(gId =>
{
cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ({userId}, {gId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroupsByRoleId(string roleId)
{
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 = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return groups;
}
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表
/// </summary>
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除角色部门表该角色所有的部门
string sql = $"delete from RoleGroup where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
groupIds.ToList().ForEach(gId =>
{
cmd.CommandText = $"Insert Into RoleGroup (RoleID, GroupID) Values ({roleId}, {gId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -0,0 +1,80 @@
using Longbow;
using Longbow.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Log : DataAccess.Log
{
/// <summary>
/// 查询所有日志信息
/// </summary>
/// <param name="tId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Log> RetrieveLogs()
{
string sql = "select * from Logs where LogTime > date_add(now(), interval -7 day)";
List<DataAccess.Log> logs = new List<DataAccess.Log>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
logs.Add(new DataAccess.Log()
{
Id = reader[0].ToString(),
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;
}
/// <summary>
/// 删除日志信息
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private static void DeleteLogAsync()
{
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Logs where LogTime < date_add(now(), interval -{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(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, now(), @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;
}
DeleteLogAsync();
return ret;
}
}
}

View File

@ -0,0 +1,124 @@
using Bootstrap.Security;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Menu : DataAccess.Menu
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName)
{
var menus = new List<BootstrapMenu>();
using (DbCommand cmd = DbAccessManager.DBAccess.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(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", "菜单"));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", "Administrators"));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
menus.Add(new BootstrapMenu
{
Id = reader[0].ToString(),
ParentId = reader[1].ToString(),
Name = (string)reader[2],
Order = reader.IsDBNull(3) ? 0 : (int)reader[3],
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 = reader.IsDBNull(8) ? 0 : (int)reader[8] > 0 ? 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;
}
/// <summary>
/// 删除菜单信息
/// </summary>
/// <param name="value"></param>
public override bool DeleteMenu(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from NavigationRole where NavigationID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Navigations where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}
/// <summary>
/// <summary>
/// 通过角色ID保存当前授权菜单
/// </summary>
/// <param name="roleId"></param>
/// <param name="menuIds"></param>
/// <returns></returns>
public override bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = $"delete from NavigationRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入菜单角色表
menuIds.ToList().ForEach(mId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -0,0 +1,50 @@
using Longbow;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Message : DataAccess.Message
{
/// <summary>
/// 所有有关userName所有消息列表
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
protected override IEnumerable<DataAccess.Message> RetrieveMessages(string userName)
{
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<DataAccess.Message> messages = new List<DataAccess.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 DataAccess.Message()
{
Id = reader[0].ToString(),
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;
}
}
}

View File

@ -0,0 +1,212 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Role : DataAccess.Role
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveRolesByUserName(string userName)
{
var entities = new List<string>();
using (DbCommand cmd = DbAccessManager.DBAccess.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(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
entities.Add((string)reader[0]);
}
}
}
return entities;
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveRolesByUrl(string url)
{
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 = '0' and n.Url like @Url";
var ret = new List<string>();
var cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", $"{url}%"));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
ret.Add((string)reader[0]);
}
}
if (ret.Count == 0) ret.Add("Administrators");
return ret;
}
/// <summary>
/// <summary>
/// 保存用户角色关系
/// </summary>
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
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))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {userId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 删除角色表
/// </summary>
/// <param name="value"></param>
public override bool DeleteRole(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserRole where RoleID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from RoleGroup where RoleID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from NavigationRole where RoleID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Roles where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete role from config table
string sql = $"delete from NavigationRole where NavigationID = {menuId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {menuId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 根据GroupId更新Roles信息删除旧的Roles信息插入新的Roles信息
/// </summary>
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = false;
//构造表格
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))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into RoleGroup (GroupID, RoleID) Values ( {groupId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -0,0 +1,40 @@
using Longbow;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.MySQL
{
public class Task : DataAccess.Task
{
/// <summary>
/// 查询所有任务
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Task> RetrieveTasks()
{
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<DataAccess.Task> tasks = new List<DataAccess.Task>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
tasks.Add(new DataAccess.Task()
{
Id = reader[0].ToString(),
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;
}
}
}

View File

@ -0,0 +1,257 @@
using Bootstrap.Security;
using Longbow.Data;
using Longbow.Security.Cryptography;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
/// 用户表实体类
/// </summary>
public class User : DataAccess.User
{
/// <summary>
/// <summary>
/// 删除用户
/// </summary>
/// <param name="value"></param>
public override bool DeleteUser(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"Delete from UserRole where UserID in ({ids})"))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from UserGroup where UserID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Users where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 保存新建
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveUser(DataAccess.User p)
{
var ret = false;
if (string.IsNullOrEmpty(p.Id) && 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 (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select UserName from Users Where UserName = @userName"))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", p.UserName));
var un = DbAccessManager.DBAccess.ExecuteScalar(cmd, transaction);
if (DbAdapterManager.ToObjectValue(un) == null)
{
cmd.CommandText = "Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedBy, ApprovedTime, Description) values (@userName, @password, @passSalt, @displayName, datetime('now', 'localtime'), @approvedBy, now(), @description)";
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", DbAdapterManager.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = '{p.UserName}'";
cmd.Parameters.Clear();
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
}
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="approvedBy"></param>
/// <returns></returns>
public override bool ApproveUser(string id, string approvedBy)
{
var ret = false;
var sql = "update Users set ApprovedTime = now(), 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;
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="rejectBy"></param>
/// <param name="reason"></param>
/// <returns></returns>
public override bool RejectUser(string id, string rejectBy)
{
var ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"insert into RejectUsers (UserName, DisplayName, RegisterTime, RejectedBy, RejectedTime, RejectedReason) select UserName, DisplayName, Registertime, '{rejectBy}', now(), '未填写' from Users where ID = {id}"))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from UserRole where UserId = {id}";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from UserGroup where UserId = {id}";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from users where ID = {id}";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 通过角色ID保存当前授权用户插入
/// </summary>
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
userIds.ToList().ForEach(uId =>
{
cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {uId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 通过部门ID保存当前授权用户插入
/// </summary>
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserGroup where GroupID = {groupId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
userIds.ToList().ForEach(uId =>
{
cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ( {uId}, {groupId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override BootstrapUser RetrieveUserByUserName(string userName)
{
BootstrapUser user = null;
var sql = "select UserName, DisplayName, CONCAT(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 db = DbAccessManager.DBAccess;
var cmd = db.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
using (DbDataReader reader = db.ExecuteReader(cmd))
{
if (reader.Read())
{
user = new BootstrapUser
{
UserName = (string)reader[0],
DisplayName = (string)reader[1],
Icon = (string)reader[2],
Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
};
}
}
return user;
}
}
}

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2047
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sql", "Sql", "{87319AF5-7C40-4362-B67C-35F9DD737DB4}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLServer", "SQLServer", "{87319AF5-7C40-4362-B67C-35F9DD737DB4}"
ProjectSection(SolutionItems) = preProject
DatabaseScripts\InitData.sql = DatabaseScripts\InitData.sql
DatabaseScripts\Install.sql = DatabaseScripts\Install.sql
@ -11,7 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sql", "Sql", "{87319AF5-7C4
DatabaseScripts\Readme.txt = DatabaseScripts\Readme.txt
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.Admin", "Bootstrap.Admin\Bootstrap.Admin.csproj", "{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Admin", "Bootstrap.Admin\Bootstrap.Admin.csproj", "{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{792A0B12-3F41-4BC4-A768-7D8D91C213B2}"
ProjectSection(SolutionItems) = preProject
@ -25,15 +25,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{5864
Scripts\Publish.vbs = Scripts\Publish.vbs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.Client", "Bootstrap.Client\Bootstrap.Client.csproj", "{C82A6E45-AB90-43D1-8429-5CBE953D8151}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Client", "Bootstrap.Client\Bootstrap.Client.csproj", "{C82A6E45-AB90-43D1-8429-5CBE953D8151}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{C7F51A14-2D89-4D1F-AD78-C42B79AB0BF0}"
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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccess", "Bootstrap.DataAccess\Bootstrap.DataAccess.csproj", "{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess", "Bootstrap.DataAccess\Bootstrap.DataAccess.csproj", "{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccess.SQLite", "Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj", "{BC18A24F-5C99-4DF5-803D-72A912BCBD57}"
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
@ -41,17 +41,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{523515
DatabaseScripts\SQLite\Install.sql = DatabaseScripts\SQLite\Install.sql
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccess.MongoDB", "Bootstrap.DataAccess.MongoDB\Bootstrap.DataAccess.MongoDB.csproj", "{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.MongoDB", "Bootstrap.DataAccess.MongoDB\Bootstrap.DataAccess.MongoDB.csproj", "{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MongoDB", "MongoDB", "{A06A0AD8-A246-4329-B024-7174AE4A3EDE}"
ProjectSection(SolutionItems) = preProject
DatabaseScripts\MongoDB\BootstrapAdmin.Users.json = DatabaseScripts\MongoDB\BootstrapAdmin.Users.json
DatabaseScripts\MongoDB\BootstrapAdmin.Roles.json = DatabaseScripts\MongoDB\BootstrapAdmin.Roles.json
DatabaseScripts\MongoDB\BootstrapAdmin.Navigations.json = DatabaseScripts\MongoDB\BootstrapAdmin.Navigations.json
DatabaseScripts\MongoDB\BootstrapAdmin.Groups.json = DatabaseScripts\MongoDB\BootstrapAdmin.Groups.json
DatabaseScripts\MongoDB\BootstrapAdmin.Dicts.json = DatabaseScripts\MongoDB\BootstrapAdmin.Dicts.json
DatabaseScripts\MongoDB\BootstrapAdmin.Groups.json = DatabaseScripts\MongoDB\BootstrapAdmin.Groups.json
DatabaseScripts\MongoDB\BootstrapAdmin.Navigations.json = DatabaseScripts\MongoDB\BootstrapAdmin.Navigations.json
DatabaseScripts\MongoDB\BootstrapAdmin.Roles.json = DatabaseScripts\MongoDB\BootstrapAdmin.Roles.json
DatabaseScripts\MongoDB\BootstrapAdmin.Users.json = DatabaseScripts\MongoDB\BootstrapAdmin.Users.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MySQL", "MySQL", "{084E2E94-6B7D-4D3E-9BF1-6972427FBF80}"
ProjectSection(SolutionItems) = preProject
DatabaseScripts\MySQL\initData.sql = DatabaseScripts\MySQL\initData.sql
DatabaseScripts\MySQL\install.sql = DatabaseScripts\MySQL\install.sql
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccess.MySQL", "Bootstrap.DataAccess.MySQL\Bootstrap.DataAccess.MySQL.csproj", "{B6877AEA-EC65-47DA-BA6E-FD657729C285}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -82,6 +90,10 @@ Global
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.Build.0 = Release|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,102 @@
DELETE From Users where ID = 1;
-- ADMIN/123789
ALTER TABLE Users MODIFY COLUMN ID INT NOT NULL;
INSERT INTO Users (ID, UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime,ApprovedBy, Description) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator', now(), now(), 'system', '系统默认创建');
ALTER TABLE Users MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT;
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;
ALTER TABLE Navigations MODIFY COLUMN ID INT NOT NULL;
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', '~/swagger', '0');
INSERT INTO Navigations (ID, ParentId, Name, `Order`, Icon, Url, Category) VALUES (19, 16, '图标集', 10, 'fa fa-dashboard', '~/Admin/FAIco', '0');
ALTER TABLE Navigations MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT;
DELETE FROM `Groups` WHERE ID = 1;
ALTER TABLE `Groups` MODIFY COLUMN ID INT NOT NULL;
INSERT INTO `Groups` (ID, GroupName, Description) VALUES (1, 'Admin', '系统默认组');
ALTER TABLE `Groups` MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT;
DELETE FROM Roles where ID in (1, 2);
ALTER TABLE Roles MODIFY COLUMN ID INT NOT NULL;
INSERT INTO Roles (ID, RoleName, Description) VALUES (1, 'Administrators', '系统管理员');
INSERT INTO Roles (ID, RoleName, Description) VALUES (2, 'Default', '默认用户,可访问前台页面');
ALTER TABLE Roles MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT;
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);
-- Client Data
Delete From Dicts Where Category = '应用程序' and Code = 2;
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('应用程序', '测试平台', 2, 0);
Delete From Dicts Where Category = '测试平台';
Insert into Dicts (Category, Name, Code, Define) values ('测试平台', '网站标题', 'BA Client', 1);
Insert into Dicts (Category, Name, Code, Define) values ('测试平台', '网站页脚', '通用后台管理测试平台', 1);
Insert into Dicts (Category, Name, Code, Define) values ('测试平台', '个人中心地址', 'http://localhost:50852/Admin/Profiles', 1);
Insert into Dicts (Category, Name, Code, Define) values ('测试平台', '系统设置地址', 'http://localhost:50852/Admin/Settings', 1);
Delete from Navigations where Application = 2;
INSERT into Navigations (ID, ParentId, Name, `Order`, Icon, Url, Category, Application) VALUES (NULL, 0, '首页', 10, 'fa fa-fa', '~/Home/Index', '1', 2);
INSERT into Navigations (ID, ParentId, Name, `Order`, Icon, Url, Category, Application) VALUES (NULL, 0, '测试页面', 20, 'fa fa-fa', '#', '1', 2);
INSERT into Navigations (ID, ParentId, Name, `Order`, Icon, Url, Category, Application) VALUES (NULL, @@identity, '关于', 10, 'fa fa-fa', '~/Home/About', '1', 2);
-- 菜单授权
DELETE FROM NavigationRole Where NavigationID in (Select ID From Navigations Where Application = 2);
INSERT INTO NavigationRole SELECT NULL, ID, 2 FROM Navigations Where Application = 2;

View File

@ -0,0 +1,140 @@
CREATE TABLE Users (
ID INTEGER PRIMARY KEY Auto_increment,
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 Auto_increment,
UserID INT NOT NULL,
RoleID INT NOT NULL
);
CREATE TABLE UserGroup(
ID INTEGER PRIMARY KEY Auto_increment,
UserID INT NOT NULL,
GroupID INT NOT NULL
);
CREATE TABLE Roles(
ID INTEGER PRIMARY KEY Auto_increment,
RoleName VARCHAR (50) NULL,
Description VARCHAR (500) NULL
);
CREATE TABLE RoleGroup(
ID INTEGER PRIMARY KEY Auto_increment,
RoleID INT NOT NULL,
GroupID INT NOT NULL
);
CREATE TABLE Notifications(
ID INTEGER PRIMARY KEY Auto_increment,
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 Auto_increment,
ParentId INT DEFAULT 0,
Name VARCHAR (50) NOT NULL,
`Order` INT DEFAULT 0,
Icon VARCHAR (50) DEFAULT 'fa fa-fa',
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 Auto_increment,
NavigationID INT NOT NULL,
RoleID INT NOT NULL
);
CREATE TABLE Logs(
ID INTEGER PRIMARY KEY Auto_increment,
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 Auto_increment,
GroupName VARCHAR (50) NULL,
Description VARCHAR (500) NULL
);
CREATE TABLE Exceptions(
ID INTEGER PRIMARY KEY Auto_increment,
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 Auto_increment,
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 Auto_increment,
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 Auto_increment,
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 Auto_increment,
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
);