123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- 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<ViewModel.SystemView.AnnouncementTypeView> GetAnnouncementTypeViewList
- (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- Expression<Func<Sys_AnnouncementType, bool>> 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<AnnouncementTypeView>(pageIndex, pageSize);
- return AnnouncementDAL.GetAnnouncementTypeView(exp).OrderBy(x => x.Name).ToGridResultSet<AnnouncementTypeView>(pageIndex, pageSize);
- }
- public IList<AnnouncementTypeView> GetUsableAnnouncementTypeViewList()
- {
- return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList();
- }
- public IList<AnnouncementTypeView> 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<ViewModel.SystemView.AnnouncementView> GetAnnouncementViewList
- (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize, Guid? typeID = null)
- {
- Expression<Func<Sys_Announcement, bool>> 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<AnnouncementView>(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<Guid?> roleIDList, List<Guid?> 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<Sys_Role>();
- announcementEntity.Sys_User = new HashSet<Sys_User>();
- roleList.ForEach(x => announcementEntity.Sys_Role.Add(x));
- userList.ForEach(x => announcementEntity.Sys_User.Add(x));
- UnitOfWork.Commit();
- return announcementEntity;
- }
- public void DeleteType(IList<Guid?> announcementTypeID)
- {
- if (announcementTypeID.Count > 0)
- {
- UnitOfWork.Delete<Sys_AnnouncementType>(x => announcementTypeID.Contains(x.AnnouncementTypeID));
- }
- }
- public void Delete(IList<Guid?> 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<Sys_Role>();
- announcement.Sys_User = new HashSet<Sys_User>();
- }
- UnitOfWork.Remove<Sys_Announcement>(x => announcementID.Contains(x.AnnouncementID));
- UnitOfWork.Commit();
- }
- }
- /// <summary>
- /// 根据公告ID获取发布角色列表
- /// </summary>
- /// <param name="announcementID"></param>
- /// <returns></returns>
- public IList<RoleView> 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<StudentUserView> GetAnnouncementUserViewList(Guid announcementID)
- {
- return UserDAL.GetStudentUserView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID), x => true)
- .OrderBy(x => x.LoginID).ToList();
- }
- public IGridResultSet<AnnouncementView> 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<Func<Sys_Announcement, bool>> exp = (x => ((x.StartTime ?? sqlDateTimeMinValue) <= nowDateTime)
- && ((x.EndTime ?? sqlDateTimeMaxValue) >= nowDateTime));
- 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));
- Expression<Func<Sys_Announcement, bool>> 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<Guid?> 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<Guid?> userIDList)
- {
- announcement.StartTime = null;
- announcement.EndTime = null;
- announcement.IsTop = false;
- return this.Save(announcement, new List<Guid?>(), userIDList);
- }
- public void CheckAndRecordScore(Guid? announcementID, string loginID, string openID)
- {
- var user = UserDAL.GetStudentUserView(x => x.LoginID == loginID, y => true);
- }
- //public List<Sys_User> GetUserByRoleIDs(List<Guid?> 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;
- }
- }
- }
- }
|