diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 1c14bb6e..d6c33556 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -278,7 +278,7 @@ - + Web.config diff --git a/Bootstrap.Admin/Controllers/AdminController.cs b/Bootstrap.Admin/Controllers/AdminController.cs index edb3a982..c25033c1 100644 --- a/Bootstrap.Admin/Controllers/AdminController.cs +++ b/Bootstrap.Admin/Controllers/AdminController.cs @@ -94,9 +94,9 @@ namespace Bootstrap.Admin.Controllers /// /// /// - public ActionResult News() + public ActionResult Notifications() { - var v = new NavigatorBarModel("~/Admin/News"); + var v = new NavigatorBarModel("~/Admin/Notifications"); return View(v); } diff --git a/Bootstrap.Admin/Views/Admin/News.cshtml b/Bootstrap.Admin/Views/Admin/Notifications.cshtml similarity index 94% rename from Bootstrap.Admin/Views/Admin/News.cshtml rename to Bootstrap.Admin/Views/Admin/Notifications.cshtml index 12d2f2cf..59c16257 100644 --- a/Bootstrap.Admin/Views/Admin/News.cshtml +++ b/Bootstrap.Admin/Views/Admin/Notifications.cshtml @@ -20,7 +20,7 @@
用户注册
-
    +
      @foreach (var nofi in Model.Notifications) {
    • @@ -45,7 +45,7 @@
      程序错误
      -
        +
          @foreach (var nofi in Model.Notifications) {
        • @@ -70,7 +70,7 @@
          数据库报警
          -
        • diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index 8fe94ffa..4cd9aa6b 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -16,6 +16,7 @@ namespace Bootstrap.DataAccess /// /// /// + /// internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, string menuIds = null, string dictIds = null, string logIds = null, string notifyIds = null) { var cacheKeys = new List(); diff --git a/Bootstrap.DataAccess/Notification.cs b/Bootstrap.DataAccess/Notification.cs index a2375902..6bc761a5 100644 --- a/Bootstrap.DataAccess/Notification.cs +++ b/Bootstrap.DataAccess/Notification.cs @@ -1,16 +1,51 @@ -using System; -namespace Bootstrap.DataAccess -{ - public class Notification - { - public int ID { get; set; } - public string Category { get; set; } - public string Title { get; set; } - public string Content { get; set; } - public DateTime RegisterTime { get; set; } - public DateTime ProcessTime { get; set; } - public string ProcessBy { get; set; } - public string ProcessResult { get; set; } - public string Status { get; set; } - } -} +using System; + +namespace Bootstrap.DataAccess +{ + /// + /// + /// + public class Notification + { + /// + /// + /// + public int ID { get; set; } + /// + /// + /// + public string Category { get; set; } + /// + /// + /// + public string Title { get; set; } + /// + /// + /// + public string Content { get; set; } + /// + /// + /// + public DateTime RegisterTime { get; set; } + /// + /// + /// + public DateTime ProcessTime { get; set; } + /// + /// + /// + public string ProcessBy { get; set; } + /// + /// + /// + public string ProcessResult { get; set; } + /// + /// + /// + public string Status { get; set; } + /// + /// 获得/设置 市场描述 2分钟内为刚刚 + /// + public string Period { get; set; } + } +} diff --git a/Bootstrap.DataAccess/NotificationHelper.cs b/Bootstrap.DataAccess/NotificationHelper.cs index 79e9acf6..6a7e5dee 100644 --- a/Bootstrap.DataAccess/NotificationHelper.cs +++ b/Bootstrap.DataAccess/NotificationHelper.cs @@ -1,82 +1,91 @@ -using Longbow; -using Longbow.Caching; -using Longbow.Caching.Configuration; -using Longbow.ExceptionManagement; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; - -namespace Bootstrap.DataAccess -{ - public class NotificationHelper - { - internal const string RetrieveNotifyDataKey = "NotificationHelper-RetrieveNotifications"; - - /// - /// 新用户注册的通知的面板显示 - /// - /// - /// - public static IEnumerable RetrieveNotifications(string category = null) - { - return CacheManager.GetOrAdd(RetrieveNotifyDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNotifyDataKey), key => - { - string sql = "select * from Notifications where Category=@Category"; - List notifications = new List(); - DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", Convert.ToInt32(category), ParameterDirection.Input)); - try - { - using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - notifications.Add(new Notification() - { - ID = (int)reader[0], - Category = (string)reader[1], - Title = (string)reader[2], - Content = (string)reader[3], - RegisterTime = (DateTime)reader[4], - ProcessTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), - ProcessBy = LgbConvert.ReadValue(reader[6], string.Empty), - ProcessResult = LgbConvert.ReadValue(reader[7], string.Empty), - Status = (string)reader[8] - }); - } - } - } - catch (Exception ex) { ExceptionManager.Publish(ex); } - return notifications; - - }, CacheSection.RetrieveDescByKey(RetrieveNotifyDataKey)); - } - - /// - /// 点击某一行用户注册通知的处理成功操作 - /// - /// - /// - public static bool ProcessRegisterUser(string id) - { - bool ret = false; - if (string.IsNullOrEmpty(id)) return ret; - try - { - using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_ProcessRegisterUser")) - { - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", Convert.ToInt32(id), ParameterDirection.Input)); - DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); - } - CacheCleanUtility.ClearCache(notifyIds: id); - ret = true; - } - catch (Exception ex) - { - ExceptionManager.Publish(ex); - } - return ret; - } - } -} +using Longbow; +using Longbow.Caching; +using Longbow.Caching.Configuration; +using Longbow.ExceptionManagement; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Linq; + +namespace Bootstrap.DataAccess +{ + public class NotificationHelper + { + internal const string RetrieveNotifyDataKey = "NotificationHelper-RetrieveNotifications"; + + /// + /// 新用户注册的通知的面板显示 + /// + /// + /// + public static IEnumerable RetrieveNotifications() + { + var ret = CacheManager.GetOrAdd(RetrieveNotifyDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNotifyDataKey), key => + { + string sql = "select * from Notifications"; + List notifications = new List(); + DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); + try + { + using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) + { + while (reader.Read()) + { + notifications.Add(new Notification() + { + ID = (int)reader[0], + Category = (string)reader[1], + Title = (string)reader[2], + Content = (string)reader[3], + RegisterTime = (DateTime)reader[4], + ProcessTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), + ProcessBy = LgbConvert.ReadValue(reader[6], string.Empty), + ProcessResult = LgbConvert.ReadValue(reader[7], string.Empty), + Status = (string)reader[8] + }); + } + } + } + catch (Exception ex) { ExceptionManager.Publish(ex); } + return notifications; + + }, CacheSection.RetrieveDescByKey(RetrieveNotifyDataKey)); + ret.AsParallel().ForAll(n => + { + var ts = DateTime.Now - n.RegisterTime; + if (ts.TotalMinutes < 5) n.Period = "刚刚"; + else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days); + else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours); + else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes); + }); + return ret; + } + + /// + /// 点击某一行用户注册通知的处理成功操作 + /// + /// + /// + public static bool ProcessRegisterUser(string id) + { + bool ret = false; + if (string.IsNullOrEmpty(id)) return ret; + try + { + using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_ProcessRegisterUser")) + { + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", id, ParameterDirection.Input)); + DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); + } + CacheCleanUtility.ClearCache(notifyIds: id); + ret = true; + } + catch (Exception ex) + { + ExceptionManager.Publish(ex); + } + return ret; + } + } +} diff --git a/Bootstrap.DataAccessTests/NotificationHelperTest.cs b/Bootstrap.DataAccessTests/NotificationHelperTest.cs index 0e97bafb..cc451ea5 100644 --- a/Bootstrap.DataAccessTests/NotificationHelperTest.cs +++ b/Bootstrap.DataAccessTests/NotificationHelperTest.cs @@ -1,20 +1,20 @@ -using Bootstrap.DataAccess; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; -namespace Bootstrap.DataAccessTests -{ - [TestClass] - public class NotificationHelperTest - { - [TestMethod] - public void RetrieveNotificationsTest() - { - Assert.IsTrue(NotificationHelper.RetrieveNotifications("0").Count() >= 1, "带参数的NotificationHelper.RetrieveNotifications方法调用失败,请检查数据库连接或者数据库SQL语句"); - } - [TestMethod] - public void ProcessRegisterUserTest() - { - Assert.IsTrue(NotificationHelper.ProcessRegisterUser("1"), "带参数的NotificationHelper.ProcessRegisterUser方法调用失败,请检查数据库连接或者数据库SQL语句"); - } - } -} +using Bootstrap.DataAccess; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Linq; +namespace Bootstrap.DataAccessTests +{ + [TestClass] + public class NotificationHelperTest + { + [TestMethod] + public void RetrieveNotificationsTest() + { + Assert.IsTrue(NotificationHelper.RetrieveNotifications().Count() >= 0, "带参数的NotificationHelper.RetrieveNotifications方法调用失败,请检查数据库连接或者数据库SQL语句"); + } + [TestMethod] + public void ProcessRegisterUserTest() + { + Assert.IsTrue(NotificationHelper.ProcessRegisterUser("1"), "带参数的NotificationHelper.ProcessRegisterUser方法调用失败,请检查数据库连接或者数据库SQL语句"); + } + } +} diff --git a/Bootstrap.DataAccessTests/UserHelperTests.cs b/Bootstrap.DataAccessTests/UserHelperTests.cs index 07255a6f..f99ca712 100644 --- a/Bootstrap.DataAccessTests/UserHelperTests.cs +++ b/Bootstrap.DataAccessTests/UserHelperTests.cs @@ -48,6 +48,7 @@ namespace Bootstrap.DataAccess.Tests // 测试更新用户方法 ID != 0 var user = users.FirstOrDefault(u => u.UserName == User.UserName); user.DisplayName = "测试者2号"; + user.Description = "测试"; Assert.IsTrue(UserHelper.SaveUser(user), string.Format("更新用户ID={0}操作失败,请检查UserHelper.SaveUser方法", user.ID)); var ret = UserHelper.RetrieveUsers(user.ID); Assert.IsTrue(ret.Count() == 1, "带参数的UserHelper.RetrieveUsers方法调用失败"); diff --git a/DatabaseScripts/InitData.sql b/DatabaseScripts/InitData.sql index 8b3d908f..47a67a27 100644 --- a/DatabaseScripts/InitData.sql +++ b/DatabaseScripts/InitData.sql @@ -31,7 +31,7 @@ INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [C INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (6, 0, N'字典表维护', 50, N'fa fa-book', N'~/Admin/Dicts', N'0') INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (7, 0, N'个性化维护', 60, N'fa fa-pencil', N'~/Admin/Profiles', N'0') INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (8, 0, N'系统日志', 70, N'fa fa-gears', N'~/Admin/Logs', N'0') -INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (9, 0, N'通知管理', 80, N'fa fa-bell-o', N'~/Admin/News', N'0') +INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (9, 0, N'通知管理', 80, N'fa fa-bell-o', N'~/Admin/Notifications', N'0') INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (10, 0, N'个人中心', 90, N'fa fa-suitcase', N'~/Admin/Infos', N'0') INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (11, 0, N'返回前台', 100, N'fa fa-hand-o-left', N'~/Home/Index', N'0') INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (12, 0, N'锁定屏幕', 110, N'fa fa-lock', N'~/Home/Lock', N'0') @@ -39,10 +39,10 @@ INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [C INSERT [dbo].[Navigations] ([ID], [ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (14, 13, N'锁定屏幕', 10, N'fa fa-lock', N'~/Home/Lock', N'1') SET IDENTITY_INSERT [dbo].[Navigations] OFF -DELETE FROM RoleGroup where ID in (1) -SET IDENTITY_INSERT [dbo].[RoleGroup] ON -INSERT [dbo].[RoleGroup] ([ID], [RoleID], [GroupID]) VALUES (1, 1, 1) -SET IDENTITY_INSERT [dbo].[RoleGroup] OFF +DELETE FROM GROUPS WHERE ID = 1 +SET IDENTITY_INSERT [dbo].[Groups] ON +INSERT [dbo].[Groups] ([ID], [GroupName], [Description]) VALUES (1, 1, N'系统默认组') +SET IDENTITY_INSERT [dbo].[Groups] OFF DELETE FROM Roles where ID in (1, 2) SET IDENTITY_INSERT [dbo].[Roles] ON @@ -50,6 +50,11 @@ INSERT [dbo].[Roles] ([ID], [RoleName], [Description]) VALUES (1, N'Administrato INSERT [dbo].[Roles] ([ID], [RoleName], [Description]) VALUES (2, N'Default', N'默认用户,可访问前台页面') SET IDENTITY_INSERT [dbo].[Roles] OFF +DELETE FROM RoleGroup where ID in (1) +SET IDENTITY_INSERT [dbo].[RoleGroup] ON +INSERT [dbo].[RoleGroup] ([ID], [RoleID], [GroupID]) VALUES (1, 1, 1) +SET IDENTITY_INSERT [dbo].[RoleGroup] OFF + DELETE FROM UserGroup where ID in (1) SET IDENTITY_INSERT [dbo].[UserGroup] ON INSERT [dbo].[UserGroup] ([ID], [UserID], [GroupID]) VALUES (1, 1, 1)