AnnouncementServices.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 UserDAL UserDAL { get; set; }
  21. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SystemView.AnnouncementTypeView> GetAnnouncementTypeViewList
  22. (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
  23. {
  24. Expression<Func<Sys_AnnouncementType, bool>> exp = (x => true);
  25. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  26. return AnnouncementDAL.GetAnnouncementTypeView(exp).DynamicWhere(configuretView.Attribute,
  27. configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Name)
  28. .ToGridResultSet<AnnouncementTypeView>(pageIndex, pageSize);
  29. return AnnouncementDAL.GetAnnouncementTypeView(exp).OrderBy(x => x.Name).ToGridResultSet<AnnouncementTypeView>(pageIndex, pageSize);
  30. }
  31. public IList<AnnouncementTypeView> GetUsableAnnouncementTypeViewList()
  32. {
  33. return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList();
  34. }
  35. public IList<AnnouncementTypeView> GetAnnouncementTypeViewHaveSourseList()
  36. {
  37. var userID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  38. var roleID = EMIS.Utility.FormValidate.CustomPrincipal.Current.RoleID;
  39. var announcementTypeIDList = AnnouncementDAL.GetAnnouncementView(x => (x.Sys_Role.Any(w => w.Sys_User.Any(u => u.UserID == userID)) || x.Sys_Role.Count == 0) && (x.Sys_User.Any(y => y.UserID == userID) || x.Sys_User.Count == 0)).Select(x => x.AnnouncementTypeID).ToList();
  40. return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && announcementTypeIDList.Contains(x.AnnouncementTypeID)).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList();
  41. }
  42. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SystemView.AnnouncementView> GetAnnouncementViewList
  43. (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize, Guid? typeID = null)
  44. {
  45. Expression<Func<Sys_Announcement, bool>> exp = (x => true);
  46. if (typeID.HasValue)
  47. {
  48. exp = exp.And(x => x.AnnouncementTypeID == typeID);
  49. }
  50. var query = AnnouncementDAL.GetAnnouncementView(exp);
  51. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  52. {
  53. query = query.DynamicWhere(configuretView.Attribute,
  54. configuretView.Condition, configuretView.ConditionValue);
  55. }
  56. return query.OrderBy(x => x.OrderByNum).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.StartTime).ToGridResultSet<AnnouncementView>(pageIndex, pageSize);
  57. }
  58. public ViewModel.SystemView.AnnouncementTypeView GetAnnouncementTypeViewInfo(Guid? announcementTypeID)
  59. {
  60. return AnnouncementDAL.GetAnnouncementTypeView(x => x.AnnouncementTypeID == announcementTypeID).FirstOrDefault();
  61. }
  62. public ViewModel.SystemView.AnnouncementView GetAnnouncementViewInfo(Guid? announcementID)
  63. {
  64. return AnnouncementDAL.GetAnnouncementView(x => x.AnnouncementID == announcementID).FirstOrDefault();
  65. }
  66. public void SaveType(ViewModel.SystemView.AnnouncementTypeView announcementType)
  67. {
  68. var announcementTypeEntity = AnnouncementDAL.AnnouncementTypeRepository.GetSingle
  69. (x => x.AnnouncementTypeID == announcementType.AnnouncementTypeID);
  70. if (announcementTypeEntity != null)
  71. {
  72. announcementTypeEntity.No = announcementType.No;
  73. announcementTypeEntity.Name = announcementType.Name;
  74. announcementTypeEntity.Description = announcementType.Description;
  75. this.SetModifyStatus(announcementTypeEntity);
  76. }
  77. else
  78. {
  79. announcementTypeEntity = new Sys_AnnouncementType();
  80. announcementTypeEntity.AnnouncementTypeID = Guid.NewGuid();
  81. announcementTypeEntity.No = announcementType.No;
  82. announcementTypeEntity.Name = announcementType.Name;
  83. announcementTypeEntity.Description = announcementType.Description;
  84. this.SetNewStatus(announcementTypeEntity);
  85. UnitOfWork.Add(announcementTypeEntity);
  86. }
  87. UnitOfWork.Commit();
  88. }
  89. public Sys_Announcement Save(ViewModel.SystemView.AnnouncementView announcement, IList<Guid?> roleIDList, List<Guid?> userIDList)
  90. {
  91. announcement.Content = HttpUtility.HtmlDecode(announcement.Content);
  92. var announcementEntity = AnnouncementDAL.AnnouncementRepository.GetSingle
  93. (x => x.AnnouncementID == announcement.AnnouncementID, (x => x.Sys_Role), (x => x.Sys_User));
  94. if (announcementEntity != null)
  95. {
  96. announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID;
  97. announcementEntity.Title = announcement.Title;
  98. announcementEntity.Content = announcement.IsSendWXEdit ? announcement.textContent : announcement.Content;
  99. announcementEntity.StartTime = announcement.StartTime;
  100. announcementEntity.EndTime = announcement.EndTime;
  101. announcementEntity.IsTop = announcement.IsTopEdit;
  102. this.SetModifyStatus(announcementEntity);
  103. }
  104. else
  105. {
  106. announcementEntity = new Sys_Announcement();
  107. announcementEntity.AnnouncementID = Guid.NewGuid();
  108. announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID;
  109. announcementEntity.Title = announcement.Title;
  110. announcementEntity.Content = announcement.IsSendWXEdit ? announcement.textContent : announcement.Content;
  111. announcementEntity.StartTime = announcement.StartTime;
  112. announcementEntity.EndTime = announcement.EndTime;
  113. announcementEntity.IsTop = announcement.IsTopEdit;
  114. this.SetNewStatus(announcementEntity);
  115. UnitOfWork.Add(announcementEntity);
  116. }
  117. var roleList = RoleDAL.RoleRepository.GetList(x => roleIDList.Contains(x.RoleID)).ToList();
  118. var userList = UserDAL.UserRepository.GetList(x => userIDList.Contains(x.UserID)).ToList();
  119. announcementEntity.Sys_Role = new HashSet<Sys_Role>();
  120. announcementEntity.Sys_User = new HashSet<Sys_User>();
  121. roleList.ForEach(x => announcementEntity.Sys_Role.Add(x));
  122. userList.ForEach(x => announcementEntity.Sys_User.Add(x));
  123. UnitOfWork.Commit();
  124. return announcementEntity;
  125. }
  126. public void DeleteType(IList<Guid?> announcementTypeID)
  127. {
  128. if (announcementTypeID.Count > 0)
  129. {
  130. UnitOfWork.Delete<Sys_AnnouncementType>(x => announcementTypeID.Contains(x.AnnouncementTypeID));
  131. }
  132. }
  133. public void Delete(IList<Guid?> announcementID)
  134. {
  135. if (announcementID.Count > 0)
  136. {
  137. var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => announcementID.Contains(x.AnnouncementID), (x => x.Sys_Role), (x => x.Sys_User));
  138. foreach (var announcement in announcementList)
  139. {
  140. announcement.Sys_Role = new HashSet<Sys_Role>();
  141. announcement.Sys_User = new HashSet<Sys_User>();
  142. }
  143. UnitOfWork.Remove<Sys_Announcement>(x => announcementID.Contains(x.AnnouncementID));
  144. UnitOfWork.Commit();
  145. }
  146. }
  147. /// <summary>
  148. /// 根据公告ID获取发布角色列表
  149. /// </summary>
  150. /// <param name="announcementID"></param>
  151. /// <returns></returns>
  152. public IList<RoleView> GetAnnouncementRoleViewList(Guid announcementID)
  153. {
  154. return RoleDAL.GetRoleView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID))
  155. .OrderBy(x=>x.OrderNo).ThenBy(x=>x.TypeID).ToList();
  156. }
  157. public IList<StudentUserView> GetAnnouncementUserViewList(Guid announcementID)
  158. {
  159. return UserDAL.GetStudentUserView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID), x => true)
  160. .OrderBy(x => x.LoginID).ToList();
  161. }
  162. public IGridResultSet<AnnouncementView> GetUserAnnouncementView(Guid userID, int pageIndex, int pageSize, Guid? type = null)
  163. {
  164. var nowDateTime = DateTime.Now;
  165. var sqlDateTimeMinValue = SqlDateTime.MinValue.Value;
  166. var sqlDateTimeMaxValue = SqlDateTime.MaxValue.Value;
  167. //var socAnnouncementType = AnnouncementDAL.AnnouncementTypeRepository.GetList();
  168. Expression<Func<Sys_Announcement, bool>> exp = (x => ((x.StartTime ?? sqlDateTimeMinValue) <= nowDateTime)
  169. && ((x.EndTime ?? sqlDateTimeMaxValue) >= nowDateTime));
  170. 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));
  171. Expression<Func<Sys_Announcement, bool>> exp2 = exp.And(x => x.Sys_Role.Count == 0 && x.Sys_User.Count == 0);
  172. if (type.HasValue)
  173. {
  174. exp = exp.And(x => x.AnnouncementTypeID == type);
  175. exp1 = exp1.And(x => x.AnnouncementTypeID == type);
  176. exp2 = exp2.And(x => x.AnnouncementTypeID == type);
  177. }
  178. return this.AnnouncementDAL.GetAnnouncementView(exp1).Concat(this.AnnouncementDAL.GetAnnouncementView(exp2))
  179. .OrderBy(x => x.OrderByNum).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.StartTime).ToGridResultSet(pageIndex, pageSize);
  180. }
  181. public void SetTop(List<Guid?> announcementIDList, bool? isTop)
  182. {
  183. try
  184. {
  185. var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => announcementIDList.Contains(x.AnnouncementID)).ToList();
  186. announcementList.ForEach(x => x.IsTop = isTop);
  187. UnitOfWork.BatchUpdate(announcementList);
  188. }
  189. catch (Exception)
  190. {
  191. throw;
  192. }
  193. }
  194. public Sys_Announcement UserAnnouncementSave(AnnouncementView announcement, List<Guid?> userIDList)
  195. {
  196. announcement.StartTime = null;
  197. announcement.EndTime = null;
  198. announcement.IsTop = false;
  199. return this.Save(announcement, new List<Guid?>(), userIDList);
  200. }
  201. public void CheckAndRecordScore(Guid? announcementID, string loginID, string openID)
  202. {
  203. var user = UserDAL.GetStudentUserView(x => x.LoginID == loginID, y => true);
  204. }
  205. //public List<Sys_User> GetUserByRoleIDs(List<Guid?> roleIDs)
  206. //{
  207. // var roleList = RoleDAL.RoleRepository.Entities.Where(x => roleIDs.Contains(x.RoleID));
  208. // var userList = roleList.Select(x => x.Sys_User).ToList();
  209. // return userList;
  210. //}
  211. public bool CheckAnnouncementID(string announcementID)
  212. {
  213. var announcementIDGuid = new Guid(announcementID);
  214. var announcement = AnnouncementDAL.GetAnnouncementView(x => x.AnnouncementID == announcementIDGuid).FirstOrDefault();
  215. if (announcement != null)
  216. {
  217. return true;
  218. }
  219. else {
  220. return false;
  221. }
  222. }
  223. }
  224. }