using EMIS.DataLogic.EducationManage; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel; using EMIS.ViewModel.EducationManage; using System.Linq.Expressions; using EMIS.Entities; using System.Transactions; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.SystemView; using EMIS.DataLogic.ExaminationApply; namespace EMIS.CommonLogic.EducationManage { public class ExaminationMessageServices : BaseServices, IExaminationMessageServices { public ExaminationMessageDAL ExaminationMessageDAL { get; set; } public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; } public Lazy AnnouncementServices { get; set; } public IGridResultSet GetExaminationMessageViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? year, Guid? classmajorID, int? pageIndex, int? pageSize) { Expression> batchExp = (x => true); Expression> projectExp = (x => true); Expression> facultyExp = (x => true); Expression> gradeExp = (x => true); Expression> classExp = (x => true); if (schoolyearID.HasValue) { batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID); } if (examinationBatchID.HasValue) { batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID); } if (examinationTypeID.HasValue) { projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID); } if (examinationProjectID.HasValue) { projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID); } if (schoolAreaID.HasValue) { gradeExp = gradeExp.And(x => x.SchoolAreaID == schoolAreaID); } if (collegeID.HasValue) { facultyExp = facultyExp.And(x => x.CollegeID == collegeID); } if (year.HasValue) { gradeExp = gradeExp.And(x => x.SchoolyearID == year); } if (classmajorID.HasValue) { classExp = classExp.And(x => x.ClassmajorID == classmajorID); } var query = ExaminationMessageDAL.GetExaminationMessageViewQueryable(batchExp, projectExp, facultyExp, gradeExp, classExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute)) { query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue); } return query.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationBatchName) .ThenBy(x => x.ExaminationTypeName) .ThenBy(x => x.ExaminationProjectName) .ThenBy(x => x.ClassmajorName) .ThenByDescending(x => x.UserName) .ToGridResultSet(pageIndex, pageSize); } public List Save(ExaminationMessageSaveView examinationMessageSaveView) { var dbExaminationMessageList = ExaminationMessageDAL.ExaminationMessageRepository .GetList(x => examinationMessageSaveView.ExaminationRegistrationIDList.Contains(x.ExaminationRegistrationID)).ToList(); var registList = ExaminationSubjectDAL.GetStudentListView(x => examinationMessageSaveView.ExaminationRegistrationIDList.Contains(x.ExaminationRegistrationID), (x => true), (x => true), (x => true)).ToList(); var userIDList = registList.Select(x => x.UserID).Distinct().ToList(); var resultView = registList.GroupBy(x => new { x.ExaminationProjectID, x.ExaminationProjectName }) .Select(x => new ExaminationMessageAnnounceView { ExaminationProjectID = x.Key.ExaminationProjectID, ExaminationProjectName = x.Key.ExaminationProjectName, ExaminationTime = examinationMessageSaveView.ExaminationTime, Remark = examinationMessageSaveView.Remark, UserIDList = x.Select(w => w.UserID).ToList() }).ToList(); var insertList = examinationMessageSaveView.ExaminationRegistrationIDList.Where(x => !dbExaminationMessageList.Any(w => w.ExaminationRegistrationID == x)) .Select(x => new EM_ExaminationMessage { ExaminationRegistrationID = x, ExaminationTime = examinationMessageSaveView.ExaminationTime, Remark = examinationMessageSaveView.Remark }).ToList(); insertList.ForEach(x => this.SetNewStatus(x)); var updateList = examinationMessageSaveView.ExaminationRegistrationIDList.Join(dbExaminationMessageList, (x => x), (x => x.ExaminationRegistrationID), ((x, y) => new EM_ExaminationMessage { ExaminationRegistrationID = y.ExaminationRegistrationID, ExaminationTime = examinationMessageSaveView.ExaminationTime, Remark = examinationMessageSaveView.Remark })).ToList(); updateList.ForEach(x => this.SetModifyStatus(x)); //HttpUtility.HtmlDecode( var announcementView = new AnnouncementView() { Title = "考试通知", Content = "考试时间:" + examinationMessageSaveView.ExaminationTime.Value.ToString() + "
" + examinationMessageSaveView.Remark + "", StartTime = null, EndTime = null, IsTop = false }; using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable })) { UnitOfWork.BulkInsert(insertList); UnitOfWork.BatchUpdate(updateList); this.AnnouncementServices.Value.Save(announcementView, new List(), userIDList); scope.Complete(); } return resultView; } } }