diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 8248ae1e..1c14bb6e 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -243,7 +243,6 @@ - diff --git a/Bootstrap.Admin/Models/HeaderBarModel.cs b/Bootstrap.Admin/Models/HeaderBarModel.cs index 85d71378..99f582a1 100644 --- a/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -17,7 +17,7 @@ namespace Bootstrap.Admin.Models UserID = user.ID; HomeUrl = "~/"; Menus = MenuHelper.RetrieveLinksByUserName(UserName); - Notifications = NotificationsHelper.RetrieveNotifications(); + Notifications = NotificationHelper.RetrieveNotifications(); } public string UserName { get; protected set; } /// @@ -43,6 +43,6 @@ namespace Bootstrap.Admin.Models /// /// /// - public IEnumerable Notifications { get; set; } + public IEnumerable Notifications { get; set; } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Web.config b/Bootstrap.Admin/Web.config index 72034dd5..40a12350 100644 --- a/Bootstrap.Admin/Web.config +++ b/Bootstrap.Admin/Web.config @@ -42,6 +42,7 @@ + diff --git a/Bootstrap.Admin/packages.config b/Bootstrap.Admin/packages.config deleted file mode 100644 index fc40b7d3..00000000 --- a/Bootstrap.Admin/packages.config +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 6f5bcc8e..a665cf3e 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -67,8 +67,8 @@ - - + + diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index 1940e8aa..8fe94ffa 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -16,7 +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) + 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(); if (roleIds != null) @@ -76,6 +76,12 @@ namespace Bootstrap.DataAccess CacheManager.Clear(key => key.Contains(LogHelper.RetrieveLogsDataKey)); cacheKeys.Clear(); } + if (notifyIds != null) + { + // final cleanup + CacheManager.Clear(key => key.Contains(NotificationHelper.RetrieveNotifyDataKey)); + cacheKeys.Clear(); + } } } } diff --git a/Bootstrap.DataAccess/Notification.cs b/Bootstrap.DataAccess/Notification.cs new file mode 100644 index 00000000..a2375902 --- /dev/null +++ b/Bootstrap.DataAccess/Notification.cs @@ -0,0 +1,16 @@ +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; } + } +} diff --git a/Bootstrap.DataAccess/NotificationHelper.cs b/Bootstrap.DataAccess/NotificationHelper.cs new file mode 100644 index 00000000..79e9acf6 --- /dev/null +++ b/Bootstrap.DataAccess/NotificationHelper.cs @@ -0,0 +1,82 @@ +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; + } + } +} diff --git a/Bootstrap.DataAccessTests/Bootstrap.DataAccessTests.csproj b/Bootstrap.DataAccessTests/Bootstrap.DataAccessTests.csproj index b966d482..abf347a0 100644 --- a/Bootstrap.DataAccessTests/Bootstrap.DataAccessTests.csproj +++ b/Bootstrap.DataAccessTests/Bootstrap.DataAccessTests.csproj @@ -61,6 +61,7 @@ + diff --git a/Bootstrap.DataAccessTests/NotificationHelperTest.cs b/Bootstrap.DataAccessTests/NotificationHelperTest.cs new file mode 100644 index 00000000..0e97bafb --- /dev/null +++ b/Bootstrap.DataAccessTests/NotificationHelperTest.cs @@ -0,0 +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语句"); + } + } +} diff --git a/DatabaseScripts/Procedures.sql b/DatabaseScripts/Procedures.sql index 0de67693..9125f04f 100644 --- a/DatabaseScripts/Procedures.sql +++ b/DatabaseScripts/Procedures.sql @@ -208,3 +208,28 @@ BEGIN END GO +Drop PROCEDURE Proc_ProcessRegisterUser +GO +-- ============================================= +-- Author: XiaTiantian +-- Create date: 2016-11-10 +-- Description: +-- ============================================= +Create PROCEDURE Proc_ProcessRegisterUser + -- Add the parameters for the stored procedure here + @id int + WITH ENCRYPTION +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + SET XACT_ABORT ON; + -- Insert statements for procedure here + update Users set ApprovedTime=GETDATE() where UserName=(select Title from Notifications where ID=@id) + update Notifications set Status='1',ProcessTime=GETDATE(),ProcessResult='0' where ID=@id +END +GO + + +