diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj
index 4876094c..d84c2d2e 100644
--- a/Bootstrap.Admin/Bootstrap.Admin.csproj
+++ b/Bootstrap.Admin/Bootstrap.Admin.csproj
@@ -28,6 +28,7 @@
+
diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json
index 1228a49f..947b156e 100644
--- a/Bootstrap.Admin/appsettings.json
+++ b/Bootstrap.Admin/appsettings.json
@@ -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": {
diff --git a/Bootstrap.DataAccess.MySQL/Bootstrap.DataAccess.MySQL.csproj b/Bootstrap.DataAccess.MySQL/Bootstrap.DataAccess.MySQL.csproj
new file mode 100644
index 00000000..c0dfdc0e
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Bootstrap.DataAccess.MySQL.csproj
@@ -0,0 +1,21 @@
+
+
+
+ netcoreapp2.1
+ true
+ ..\Keys\Longbow.Utility.snk
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Bootstrap.DataAccess.MySQL/Dict.cs b/Bootstrap.DataAccess.MySQL/Dict.cs
new file mode 100644
index 00000000..563d03d9
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Dict.cs
@@ -0,0 +1,10 @@
+namespace Bootstrap.DataAccess.MySQL
+{
+ ///
+ ///
+ ///
+ public class Dict : DataAccess.Dict
+ {
+
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/Exceptions.cs b/Bootstrap.DataAccess.MySQL/Exceptions.cs
new file mode 100644
index 00000000..5f6ee09c
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Exceptions.cs
@@ -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
+{
+ ///
+ ///
+ ///
+ public class Exceptions : DataAccess.Exceptions
+ {
+ ///
+ ///
+ ///
+ 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);
+ });
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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;
+ }
+ ///
+ /// 查询一周内所有异常
+ ///
+ ///
+ public override IEnumerable RetrieveExceptions()
+ {
+ string sql = "select * from Exceptions where LogTime > date_add(now(), interval -7 day) order by LogTime desc";
+ List exceptions = new List();
+ 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;
+ }
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/Group.cs b/Bootstrap.DataAccess.MySQL/Group.cs
new file mode 100644
index 00000000..f6571f38
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Group.cs
@@ -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
+{
+ ///
+ ///
+ ///
+ public class Group : DataAccess.Group
+ {
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveGroups()
+ {
+ string sql = "select * from `Groups`";
+ List groups = new List();
+ 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;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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;
+ }
+
+ ///
+ ///
+ /// 删除群组信息
+ ///
+ ///
+ public override bool DeleteGroup(IEnumerable 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;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable 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 groups = new List();
+ 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;
+ }
+
+ ///
+ /// 保存用户部门关系
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveGroupsByUserId(string userId, IEnumerable 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;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveGroupsByRoleId(string roleId)
+ {
+ List groups = new List();
+ 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;
+ }
+
+ ///
+ /// 根据角色ID以及选定的部门ID,保到角色部门表
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveGroupsByRoleId(string roleId, IEnumerable 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;
+ }
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/Log.cs b/Bootstrap.DataAccess.MySQL/Log.cs
new file mode 100644
index 00000000..8b10286a
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Log.cs
@@ -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
+{
+ ///
+ ///
+ ///
+ public class Log : DataAccess.Log
+ {
+ ///
+ /// 查询所有日志信息
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveLogs()
+ {
+ string sql = "select * from Logs where LogTime > date_add(now(), interval -7 day)";
+ List logs = new List();
+ 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;
+ }
+ ///
+ /// 删除日志信息
+ ///
+ ///
+ ///
+ 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);
+ });
+ }
+ ///
+ /// 保存新增的日志信息
+ ///
+ ///
+ ///
+ 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;
+ }
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/Menu.cs b/Bootstrap.DataAccess.MySQL/Menu.cs
new file mode 100644
index 00000000..5360cc30
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Menu.cs
@@ -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
+{
+ ///
+ ///
+ ///
+ public class Menu : DataAccess.Menu
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveAllMenus(string userName)
+ {
+ var menus = new List();
+ 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;
+ }
+
+ ///
+ /// 删除菜单信息
+ ///
+ ///
+ public override bool DeleteMenu(IEnumerable 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;
+ }
+
+ ///
+ ///
+ /// 通过角色ID保存当前授权菜单
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveMenusByRoleId(string roleId, IEnumerable 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;
+ }
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/Message.cs b/Bootstrap.DataAccess.MySQL/Message.cs
new file mode 100644
index 00000000..9621fce6
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Message.cs
@@ -0,0 +1,50 @@
+using Longbow;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+
+namespace Bootstrap.DataAccess.MySQL
+{
+ ///
+ ///
+ ///
+ public class Message : DataAccess.Message
+ {
+ ///
+ /// 所有有关userName所有消息列表
+ ///
+ ///
+ ///
+ protected override IEnumerable 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 messages = new List();
+ 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;
+ }
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/Role.cs b/Bootstrap.DataAccess.MySQL/Role.cs
new file mode 100644
index 00000000..7d79dc5e
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Role.cs
@@ -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
+{
+ ///
+ ///
+ ///
+ public class Role : DataAccess.Role
+ {
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable RetrieveRolesByUserName(string userName)
+ {
+ var entities = new List();
+ 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;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override IEnumerable 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();
+ 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;
+ }
+
+ ///
+ ///
+ /// 保存用户角色关系
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveRolesByUserId(string userId, IEnumerable 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;
+ }
+
+ ///
+ /// 删除角色表
+ ///
+ ///
+ public override bool DeleteRole(IEnumerable 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;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override bool SavaRolesByMenuId(string menuId, IEnumerable 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;
+ }
+
+ ///
+ /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
+ ///
+ ///
+ ///
+ ///
+ public override bool SaveRolesByGroupId(string groupId, IEnumerable 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Bootstrap.DataAccess.MySQL/Task.cs b/Bootstrap.DataAccess.MySQL/Task.cs
new file mode 100644
index 00000000..abc4cd42
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/Task.cs
@@ -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
+ {
+ ///
+ /// 查询所有任务
+ ///
+ ///
+ public override IEnumerable 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 tasks = new List();
+ 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;
+ }
+ }
+}
diff --git a/Bootstrap.DataAccess.MySQL/User.cs b/Bootstrap.DataAccess.MySQL/User.cs
new file mode 100644
index 00000000..b9a2dfd4
--- /dev/null
+++ b/Bootstrap.DataAccess.MySQL/User.cs
@@ -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
+{
+ ///
+ /// 用户表实体类
+ ///
+ public class User : DataAccess.User
+ {
+ ///
+ ///
+ /// 删除用户
+ ///
+ ///
+ public override bool DeleteUser(IEnumerable 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;
+ }
+ ///
+ /// 保存新建
+ ///
+ ///
+ ///
+ 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;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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;
+ }
+ ///
+ /// 通过角色ID保存当前授权用户(插入)
+ ///
+ /// 角色ID
+ /// 用户ID数组
+ ///
+ public override bool SaveUsersByRoleId(string roleId, IEnumerable 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;
+ }
+ ///
+ /// 通过部门ID保存当前授权用户(插入)
+ ///
+ /// GroupID
+ /// 用户ID数组
+ ///
+ public override bool SaveUsersByGroupId(string groupId, IEnumerable 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;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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;
+ }
+ }
+}
diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln
index a9a641a7..48a75130 100644
--- a/BootstrapAdmin.sln
+++ b/BootstrapAdmin.sln
@@ -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
diff --git a/DatabaseScripts/MySQL/initData.sql b/DatabaseScripts/MySQL/initData.sql
new file mode 100644
index 00000000..4c69473c
--- /dev/null
+++ b/DatabaseScripts/MySQL/initData.sql
@@ -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;
diff --git a/DatabaseScripts/MySQL/install.sql b/DatabaseScripts/MySQL/install.sql
new file mode 100644
index 00000000..8df5f9ef
--- /dev/null
+++ b/DatabaseScripts/MySQL/install.sql
@@ -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
+);
\ No newline at end of file