ExaminationMessageServices.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using EMIS.DataLogic.EducationManage;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.EducationManage;
  10. using System.Linq.Expressions;
  11. using EMIS.Entities;
  12. using System.Transactions;
  13. using EMIS.CommonLogic.SystemServices;
  14. using EMIS.ViewModel.SystemView;
  15. using EMIS.DataLogic.ExaminationApply;
  16. namespace EMIS.CommonLogic.EducationManage
  17. {
  18. public class ExaminationMessageServices : BaseServices, IExaminationMessageServices
  19. {
  20. public ExaminationMessageDAL ExaminationMessageDAL { get; set; }
  21. public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; }
  22. public Lazy<IAnnouncementServices> AnnouncementServices { get; set; }
  23. public IGridResultSet<ExaminationMessageView> GetExaminationMessageViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID,
  24. Guid? examinationTypeID, Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? year, Guid? classmajorID, int? pageIndex, int? pageSize)
  25. {
  26. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  27. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  28. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  29. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  30. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  31. if (schoolyearID.HasValue)
  32. {
  33. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  34. }
  35. if (examinationBatchID.HasValue)
  36. {
  37. batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
  38. }
  39. if (examinationTypeID.HasValue)
  40. {
  41. projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID);
  42. }
  43. if (examinationProjectID.HasValue)
  44. {
  45. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  46. }
  47. if (schoolAreaID.HasValue)
  48. {
  49. gradeExp = gradeExp.And(x => x.SchoolAreaID == schoolAreaID);
  50. }
  51. if (collegeID.HasValue)
  52. {
  53. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  54. }
  55. if (year.HasValue)
  56. {
  57. gradeExp = gradeExp.And(x => x.SchoolyearID == year);
  58. }
  59. if (classmajorID.HasValue)
  60. {
  61. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  62. }
  63. var query = ExaminationMessageDAL.GetExaminationMessageViewQueryable(batchExp, projectExp, facultyExp, gradeExp, classExp);
  64. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  65. {
  66. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  67. }
  68. return query.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationBatchName)
  69. .ThenBy(x => x.ExaminationTypeName)
  70. .ThenBy(x => x.ExaminationProjectName)
  71. .ThenBy(x => x.ClassmajorName)
  72. .ThenByDescending(x => x.UserName)
  73. .ToGridResultSet(pageIndex, pageSize);
  74. }
  75. public List<ExaminationMessageAnnounceView> Save(ExaminationMessageSaveView examinationMessageSaveView)
  76. {
  77. var dbExaminationMessageList = ExaminationMessageDAL.ExaminationMessageRepository
  78. .GetList(x => examinationMessageSaveView.ExaminationRegistrationIDList.Contains(x.ExaminationRegistrationID)).ToList();
  79. var registList = ExaminationSubjectDAL.GetStudentListView(x => examinationMessageSaveView.ExaminationRegistrationIDList.Contains(x.ExaminationRegistrationID),
  80. (x => true), (x => true), (x => true)).ToList();
  81. var userIDList = registList.Select(x => x.UserID).Distinct().ToList();
  82. var resultView = registList.GroupBy(x => new { x.ExaminationProjectID, x.ExaminationProjectName })
  83. .Select(x => new ExaminationMessageAnnounceView
  84. {
  85. ExaminationProjectID = x.Key.ExaminationProjectID,
  86. ExaminationProjectName = x.Key.ExaminationProjectName,
  87. ExaminationTime = examinationMessageSaveView.ExaminationTime,
  88. Remark = examinationMessageSaveView.Remark,
  89. UserIDList = x.Select(w => w.UserID).ToList()
  90. }).ToList();
  91. var insertList = examinationMessageSaveView.ExaminationRegistrationIDList.Where(x => !dbExaminationMessageList.Any(w => w.ExaminationRegistrationID == x))
  92. .Select(x => new EM_ExaminationMessage
  93. {
  94. ExaminationRegistrationID = x,
  95. ExaminationTime = examinationMessageSaveView.ExaminationTime,
  96. Remark = examinationMessageSaveView.Remark
  97. }).ToList();
  98. insertList.ForEach(x => this.SetNewStatus(x));
  99. var updateList = examinationMessageSaveView.ExaminationRegistrationIDList.Join(dbExaminationMessageList, (x => x), (x => x.ExaminationRegistrationID),
  100. ((x, y) => new EM_ExaminationMessage
  101. {
  102. ExaminationRegistrationID = y.ExaminationRegistrationID,
  103. ExaminationTime = examinationMessageSaveView.ExaminationTime,
  104. Remark = examinationMessageSaveView.Remark
  105. })).ToList();
  106. updateList.ForEach(x => this.SetModifyStatus(x));
  107. //HttpUtility.HtmlDecode(
  108. var announcementView = new AnnouncementView()
  109. {
  110. Title = "考试通知",
  111. Content = "<span style=\"font-weight:bold\">考试时间:" + examinationMessageSaveView.ExaminationTime.Value.ToString() + "</span><br/><span>" + examinationMessageSaveView.Remark + "</span>",
  112. StartTime = null,
  113. EndTime = null,
  114. IsTop = false
  115. };
  116. using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
  117. {
  118. UnitOfWork.BulkInsert(insertList);
  119. UnitOfWork.BatchUpdate(updateList);
  120. this.AnnouncementServices.Value.Save(announcementView, new List<Guid?>(), userIDList);
  121. scope.Complete();
  122. }
  123. return resultView;
  124. }
  125. }
  126. }