using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.SqlTypes; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.SystemDAL; using EMIS.Entities; using EMIS.ViewModel.SystemView; using EMIS.ViewModel; using System.Web; namespace EMIS.CommonLogic.SystemServices { public class AnnouncementServices : BaseServices, IAnnouncementServices { public AnnouncementDAL AnnouncementDAL { get; set; } public RoleDAL RoleDAL { get; set; } public UserDAL UserDAL { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetAnnouncementTypeViewList (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> exp = (x => true); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) return AnnouncementDAL.GetAnnouncementTypeView(exp).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Name) .ToGridResultSet(pageIndex, pageSize); return AnnouncementDAL.GetAnnouncementTypeView(exp).OrderBy(x => x.Name).ToGridResultSet(pageIndex, pageSize); } public IList GetUsableAnnouncementTypeViewList() { return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList(); } public IList GetAnnouncementTypeViewHaveSourseList() { var userID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; var roleID = EMIS.Utility.FormValidate.CustomPrincipal.Current.RoleID; 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(); return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && announcementTypeIDList.Contains(x.AnnouncementTypeID)).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList(); } public Bowin.Common.Linq.Entity.IGridResultSet GetAnnouncementViewList (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize, Guid? typeID = null) { Expression> exp = (x => true); if (typeID.HasValue) { exp = exp.And(x => x.AnnouncementTypeID == typeID); } var query = AnnouncementDAL.GetAnnouncementView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } return query.OrderBy(x => x.OrderByNum).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.StartTime).ToGridResultSet(pageIndex, pageSize); } public ViewModel.SystemView.AnnouncementTypeView GetAnnouncementTypeViewInfo(Guid? announcementTypeID) { return AnnouncementDAL.GetAnnouncementTypeView(x => x.AnnouncementTypeID == announcementTypeID).FirstOrDefault(); } public ViewModel.SystemView.AnnouncementView GetAnnouncementViewInfo(Guid? announcementID) { return AnnouncementDAL.GetAnnouncementView(x => x.AnnouncementID == announcementID).FirstOrDefault(); } public void SaveType(ViewModel.SystemView.AnnouncementTypeView announcementType) { var announcementTypeEntity = AnnouncementDAL.AnnouncementTypeRepository.GetSingle (x => x.AnnouncementTypeID == announcementType.AnnouncementTypeID); if (announcementTypeEntity != null) { announcementTypeEntity.No = announcementType.No; announcementTypeEntity.Name = announcementType.Name; announcementTypeEntity.Description = announcementType.Description; this.SetModifyStatus(announcementTypeEntity); } else { announcementTypeEntity = new Sys_AnnouncementType(); announcementTypeEntity.AnnouncementTypeID = Guid.NewGuid(); announcementTypeEntity.No = announcementType.No; announcementTypeEntity.Name = announcementType.Name; announcementTypeEntity.Description = announcementType.Description; this.SetNewStatus(announcementTypeEntity); UnitOfWork.Add(announcementTypeEntity); } UnitOfWork.Commit(); } public Sys_Announcement Save(ViewModel.SystemView.AnnouncementView announcement, IList roleIDList, List userIDList) { announcement.Content = HttpUtility.HtmlDecode(announcement.Content); var announcementEntity = AnnouncementDAL.AnnouncementRepository.GetSingle (x => x.AnnouncementID == announcement.AnnouncementID, (x => x.Sys_Role), (x => x.Sys_User)); if (announcementEntity != null) { announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID; announcementEntity.Title = announcement.Title; announcementEntity.Content = announcement.IsSendWXEdit ? announcement.textContent : announcement.Content; announcementEntity.StartTime = announcement.StartTime; announcementEntity.EndTime = announcement.EndTime; announcementEntity.IsTop = announcement.IsTopEdit; this.SetModifyStatus(announcementEntity); } else { announcementEntity = new Sys_Announcement(); announcementEntity.AnnouncementID = Guid.NewGuid(); announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID; announcementEntity.Title = announcement.Title; announcementEntity.Content = announcement.IsSendWXEdit ? announcement.textContent : announcement.Content; announcementEntity.StartTime = announcement.StartTime; announcementEntity.EndTime = announcement.EndTime; announcementEntity.IsTop = announcement.IsTopEdit; this.SetNewStatus(announcementEntity); UnitOfWork.Add(announcementEntity); } var roleList = RoleDAL.RoleRepository.GetList(x => roleIDList.Contains(x.RoleID)).ToList(); var userList = UserDAL.UserRepository.GetList(x => userIDList.Contains(x.UserID)).ToList(); announcementEntity.Sys_Role = new HashSet(); announcementEntity.Sys_User = new HashSet(); roleList.ForEach(x => announcementEntity.Sys_Role.Add(x)); userList.ForEach(x => announcementEntity.Sys_User.Add(x)); UnitOfWork.Commit(); return announcementEntity; } public void DeleteType(IList announcementTypeID) { if (announcementTypeID.Count > 0) { UnitOfWork.Delete(x => announcementTypeID.Contains(x.AnnouncementTypeID)); } } public void Delete(IList announcementID) { if (announcementID.Count > 0) { var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => announcementID.Contains(x.AnnouncementID), (x => x.Sys_Role), (x => x.Sys_User)); foreach (var announcement in announcementList) { announcement.Sys_Role = new HashSet(); announcement.Sys_User = new HashSet(); } UnitOfWork.Remove(x => announcementID.Contains(x.AnnouncementID)); UnitOfWork.Commit(); } } /// /// 根据公告ID获取发布角色列表 /// /// /// public IList GetAnnouncementRoleViewList(Guid announcementID) { return RoleDAL.GetRoleView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID)) .OrderBy(x=>x.OrderNo).ThenBy(x=>x.TypeID).ToList(); } public IList GetAnnouncementUserViewList(Guid announcementID) { return UserDAL.GetStudentUserView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID), x => true) .OrderBy(x => x.LoginID).ToList(); } public IGridResultSet GetUserAnnouncementView(Guid userID, int pageIndex, int pageSize, Guid? type = null) { var nowDateTime = DateTime.Now; var sqlDateTimeMinValue = SqlDateTime.MinValue.Value; var sqlDateTimeMaxValue = SqlDateTime.MaxValue.Value; //var socAnnouncementType = AnnouncementDAL.AnnouncementTypeRepository.GetList(); Expression> exp = (x => ((x.StartTime ?? sqlDateTimeMinValue) <= nowDateTime) && ((x.EndTime ?? sqlDateTimeMaxValue) >= nowDateTime)); Expression> 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)); Expression> exp2 = exp.And(x => x.Sys_Role.Count == 0 && x.Sys_User.Count == 0); if (type.HasValue) { exp = exp.And(x => x.AnnouncementTypeID == type); exp1 = exp1.And(x => x.AnnouncementTypeID == type); exp2 = exp2.And(x => x.AnnouncementTypeID == type); } return this.AnnouncementDAL.GetAnnouncementView(exp1).Concat(this.AnnouncementDAL.GetAnnouncementView(exp2)) .OrderBy(x => x.OrderByNum).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.StartTime).ToGridResultSet(pageIndex, pageSize); } public void SetTop(List announcementIDList, bool? isTop) { try { var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => announcementIDList.Contains(x.AnnouncementID)).ToList(); announcementList.ForEach(x => x.IsTop = isTop); UnitOfWork.BatchUpdate(announcementList); } catch (Exception) { throw; } } public Sys_Announcement UserAnnouncementSave(AnnouncementView announcement, List userIDList) { announcement.StartTime = null; announcement.EndTime = null; announcement.IsTop = false; return this.Save(announcement, new List(), userIDList); } public void CheckAndRecordScore(Guid? announcementID, string loginID, string openID) { var user = UserDAL.GetStudentUserView(x => x.LoginID == loginID, y => true); } //public List GetUserByRoleIDs(List roleIDs) //{ // var roleList = RoleDAL.RoleRepository.Entities.Where(x => roleIDs.Contains(x.RoleID)); // var userList = roleList.Select(x => x.Sys_User).ToList(); // return userList; //} public bool CheckAnnouncementID(string announcementID) { var announcementIDGuid = new Guid(announcementID); var announcement = AnnouncementDAL.GetAnnouncementView(x => x.AnnouncementID == announcementIDGuid).FirstOrDefault(); if (announcement != null) { return true; } else { return false; } } } }