AnnouncementServices.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Data.SqlTypes;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.DataLogic.SystemDAL;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel.SystemView;
  12. using EMIS.ViewModel;
  13. using System.Web;
  14. namespace EMIS.CommonLogic.SystemServices
  15. {
  16. public class AnnouncementServices : BaseServices, IAnnouncementServices
  17. {
  18. public AnnouncementDAL AnnouncementDAL { get; set; }
  19. public RoleDAL RoleDAL { get; set; }
  20. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SystemView.AnnouncementTypeView> GetAnnouncementTypeViewList
  21. (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
  22. {
  23. Expression<Func<Sys_AnnouncementType, bool>> exp = (x => true);
  24. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  25. return AnnouncementDAL.GetAnnouncementTypeView(exp).DynamicWhere(configuretView.Attribute,
  26. configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Name)
  27. .ToGridResultSet<AnnouncementTypeView>(pageIndex, pageSize);
  28. return AnnouncementDAL.GetAnnouncementTypeView(exp).OrderBy(x => x.Name).ToGridResultSet<AnnouncementTypeView>(pageIndex, pageSize);
  29. }
  30. public IList<AnnouncementTypeView> GetUsableAnnouncementTypeViewList()
  31. {
  32. return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList();
  33. }
  34. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SystemView.AnnouncementView> GetAnnouncementViewList
  35. (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
  36. {
  37. Expression<Func<Sys_Announcement, bool>> exp = (x => true);
  38. var query = AnnouncementDAL.GetAnnouncementView(exp);
  39. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  40. {
  41. query = query.DynamicWhere(configuretView.Attribute,
  42. configuretView.Condition, configuretView.ConditionValue);
  43. }
  44. return query.OrderByDescending(x => x.StartTime).ToGridResultSet<AnnouncementView>(pageIndex, pageSize);
  45. }
  46. public ViewModel.SystemView.AnnouncementTypeView GetAnnouncementTypeViewInfo(Guid? announcementTypeID)
  47. {
  48. return AnnouncementDAL.GetAnnouncementTypeView(x => x.AnnouncementTypeID == announcementTypeID).FirstOrDefault();
  49. }
  50. public ViewModel.SystemView.AnnouncementView GetAnnouncementViewInfo(Guid? announcementID)
  51. {
  52. return AnnouncementDAL.GetAnnouncementView(x => x.AnnouncementID == announcementID).FirstOrDefault();
  53. }
  54. public void SaveType(ViewModel.SystemView.AnnouncementTypeView announcementType)
  55. {
  56. var announcementTypeEntity = AnnouncementDAL.AnnouncementTypeRepository.GetSingle
  57. (x => x.AnnouncementTypeID == announcementType.AnnouncementTypeID);
  58. if (announcementTypeEntity != null)
  59. {
  60. announcementTypeEntity.No = announcementType.No;
  61. announcementTypeEntity.Name = announcementType.Name;
  62. announcementTypeEntity.Description = announcementType.Description;
  63. this.SetModifyStatus(announcementTypeEntity);
  64. }
  65. else
  66. {
  67. announcementTypeEntity = new Sys_AnnouncementType();
  68. announcementTypeEntity.AnnouncementTypeID = Guid.NewGuid();
  69. announcementTypeEntity.No = announcementType.No;
  70. announcementTypeEntity.Name = announcementType.Name;
  71. announcementTypeEntity.Description = announcementType.Description;
  72. this.SetNewStatus(announcementTypeEntity);
  73. UnitOfWork.Add(announcementTypeEntity);
  74. }
  75. UnitOfWork.Commit();
  76. }
  77. public void Save(ViewModel.SystemView.AnnouncementView announcement, IList<Guid?> roleIDList)
  78. {
  79. announcement.Content = HttpUtility.HtmlDecode(announcement.Content);
  80. var announcementEntity = AnnouncementDAL.AnnouncementRepository.GetSingle
  81. (x => x.AnnouncementID == announcement.AnnouncementID, (x => x.Sys_Role));
  82. if (announcementEntity != null)
  83. {
  84. announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID;
  85. announcementEntity.Title = announcement.Title;
  86. announcementEntity.Content = announcement.Content;
  87. announcementEntity.StartTime = announcement.StartTime;
  88. announcementEntity.EndTime = announcement.EndTime;
  89. this.SetModifyStatus(announcementEntity);
  90. }
  91. else
  92. {
  93. announcementEntity = new Sys_Announcement();
  94. announcementEntity.AnnouncementID = Guid.NewGuid();
  95. announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID;
  96. announcementEntity.Title = announcement.Title;
  97. announcementEntity.Content = announcement.Content;
  98. announcementEntity.StartTime = announcement.StartTime;
  99. announcementEntity.EndTime = announcement.EndTime;
  100. this.SetNewStatus(announcementEntity);
  101. UnitOfWork.Add(announcementEntity);
  102. }
  103. var roleList = RoleDAL.RoleRepository.GetList(x => roleIDList.Contains(x.RoleID)).ToList();
  104. announcementEntity.Sys_Role = new HashSet<Sys_Role>();
  105. roleList.ForEach(x => announcementEntity.Sys_Role.Add(x));
  106. UnitOfWork.Commit();
  107. }
  108. public void DeleteType(IList<Guid?> announcementTypeID)
  109. {
  110. if (announcementTypeID.Count > 0)
  111. {
  112. UnitOfWork.Delete<Sys_AnnouncementType>(x => announcementTypeID.Contains(x.AnnouncementTypeID));
  113. }
  114. }
  115. public void Delete(IList<Guid?> announcementID)
  116. {
  117. if (announcementID.Count > 0)
  118. {
  119. var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => announcementID.Contains(x.AnnouncementID), (x => x.Sys_Role), (x => x.Sys_User));
  120. foreach (var announcement in announcementList)
  121. {
  122. announcement.Sys_Role = new HashSet<Sys_Role>();
  123. announcement.Sys_User = new HashSet<Sys_User>();
  124. }
  125. UnitOfWork.Remove<Sys_Announcement>(x => announcementID.Contains(x.AnnouncementID));
  126. UnitOfWork.Commit();
  127. }
  128. }
  129. /// <summary>
  130. /// 根据公告ID获取发布角色列表
  131. /// </summary>
  132. /// <param name="announcementID"></param>
  133. /// <returns></returns>
  134. public IList<RoleView> GetAnnouncementRoleViewList(Guid announcementID)
  135. {
  136. return RoleDAL.GetRoleView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID))
  137. .OrderBy(x=>x.OrderNo).ThenBy(x=>x.TypeID).ToList();
  138. }
  139. public IGridResultSet<AnnouncementView> GetUserAnnouncementView(Guid userID, int pageIndex, int pageSize)
  140. {
  141. var nowDateTime = DateTime.Now;
  142. var sqlDateTimeMinValue = SqlDateTime.MinValue.Value;
  143. var sqlDateTimeMaxValue = SqlDateTime.MaxValue.Value;
  144. //var socAnnouncementType = AnnouncementDAL.AnnouncementTypeRepository.GetList();
  145. Expression<Func<Sys_Announcement, bool>> exp = (x => ((x.StartTime ?? sqlDateTimeMinValue) <= nowDateTime)
  146. && ((x.EndTime ?? sqlDateTimeMaxValue) >= nowDateTime));
  147. Expression<Func<Sys_Announcement, bool>> exp1 = exp.And(x => x.Sys_Role.Any(w => w.Sys_User.Any(u => u.UserID == userID)) || x.Sys_User.Any(y => y.UserID ==userID));
  148. Expression<Func<Sys_Announcement, bool>> exp2 = exp.And(x => x.Sys_Role.Count == 0 && x.Sys_User.Count == 0);
  149. return this.AnnouncementDAL.GetAnnouncementView(exp1).Concat(this.AnnouncementDAL.GetAnnouncementView(exp2))
  150. .OrderByDescending(x => x.StartTime).ThenByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize);
  151. }
  152. }
  153. }