FinalExaminationServices.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.Entities;
  6. using EMIS.ViewModel;
  7. using EMIS.ViewModel.CacheManage;
  8. namespace EMIS.ExtensionLogic.ServiceLogic.ScoreManage
  9. {
  10. public class FinalExaminationServices : EMIS.CommonLogic.ScoreManage.FinalExaminationServices
  11. {
  12. public override void GenerateResitExamination(Guid? schoolyearID, Guid? collegeID, int? gradeID, int? standardID, Guid? classmajorID)
  13. {
  14. try
  15. {
  16. var startStatusID = this.GetStartStatus();
  17. var statusList = this.GetStatusViewList();
  18. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  19. var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  20. ER_ExamsStateSetting examsStateSetting = finalExaminationDAL.ExamsStateSettingRepository.GetSingle(x => x.ExamsStateID == (int)CF_ExamsState.Suspension);
  21. List<ER_FinalExamination> listFinalExamination = new List<ER_FinalExamination>();
  22. //List<ER_FinalExamination> SlistFinalExamination = new List<ER_FinalExamination>();
  23. //var studentList = this.DataRangeFunction(finalExaminationDAL.GetResitFinalExaminationStudent(schoolyearID, approvedStatus)).ToList();
  24. var query = this.GerenateResitDataRangeFunction(finalExaminationDAL.GetNotPassStudent(schoolyearID));
  25. //var q = finalExaminationDAL.GetSuspensionStudent(schoolyearID);
  26. //var Squery = this.GerenateResitDataRangeFunction(q);
  27. if (collegeID.HasValue)
  28. {//院系所
  29. query = query.Where(x => x.CollegeID == collegeID);
  30. //Squery = Squery.Where(x => x.CollegeID == collegeID);
  31. }
  32. if (gradeID.HasValue && gradeID != -1)
  33. {//年级
  34. query = query.Where(x => x.Year == gradeID);
  35. //Squery = Squery.Where(x => x.Year == gradeID);
  36. }
  37. if (standardID.HasValue) //专业
  38. {
  39. query = query.Where(x => x.StandardID == standardID);
  40. //Squery = Squery.Where(x => x.StandardID == standardID);
  41. }
  42. if (classmajorID.HasValue)
  43. {
  44. query = query.Where(x => x.ClassmajorID == classmajorID);
  45. //Squery = Squery.Where(x => x.ClassmajorID == classmajorID);
  46. }
  47. var studentList = query.ToList();
  48. //var SuspensionsutdentList = Squery.ToList();
  49. var finalIDList = studentList.Select(x => x.FinalExaminationID).ToList();
  50. var finalList = scoreDAL.finalExaminationRepository.GetList(x => finalIDList.Contains(x.FinalExaminationID), x => x.ER_FinalExaminationStudent).ToList();
  51. var studentIDList = studentList.Select(x => x.UserID).ToList();
  52. var stuUserList = finalExaminationDAL.studentRepository.GetList(x => studentIDList.Contains(x.UserID), x => x.CF_Classmajor, x => x.CF_Classmajor.CF_Grademajor).ToList();
  53. var ExamsStateSettingList = finalExaminationDAL.ExamsStateSettingRepository.Entities.ToList();
  54. var queryFinalExamination = studentList.GroupBy(x => new
  55. {
  56. x.FinalExaminationID,
  57. //x.Year,
  58. //x.CollegeID,
  59. //x.GrademajorID,
  60. //x.GrademajorName,
  61. //x.CoursematerialID,
  62. //x.DepartmentID,
  63. x.CourseName,
  64. //x.CourseTypeID,
  65. //x.ExaminationModeID,
  66. ////x.StartTermID,
  67. //x.Credit,
  68. //////总学时
  69. //x.TotalHours,
  70. //x.ResultTypeID,
  71. x.ExamsCategoryID,
  72. });
  73. foreach (var finalExaminationView in queryFinalExamination)
  74. {
  75. ER_FinalExamination finalExamination = new ER_FinalExamination();
  76. var dbfianl = finalList.FirstOrDefault(x => x.FinalExaminationID == finalExaminationView.Key.FinalExaminationID);
  77. var examsCategoryID = ExamsStateSettingList.FirstOrDefault(x => x.ExamsStateID == dbfianl.ExamsCategoryID);
  78. var grademajorName = studentList.Where(x => x.FinalExaminationID == finalExaminationView.Key.FinalExaminationID).FirstOrDefault().GrademajorName;
  79. var stuUserID = dbfianl.ER_FinalExaminationStudent.FirstOrDefault().UserID;
  80. if (stuUserList.Where(x => x.UserID == stuUserID).FirstOrDefault() != null)
  81. {
  82. grademajorName = stuUserList.Where(x => x.UserID == stuUserID).FirstOrDefault().CF_Classmajor.CF_Grademajor.Name;
  83. //如果存在同一条期末设定有多个年级专业的学生,随机取一个年级专业名称
  84. }
  85. if (finalExaminationView.Key.ExamsCategoryID == (int)CF_ExamsCategory.Resit)
  86. {
  87. string className = finalExaminationView.Key.CourseName + " - " + grademajorName + "-补考";
  88. finalExamination.FinalExaminationID = Guid.NewGuid();
  89. finalExamination.SchoolyearID = curSchoolyear.SchoolYearID;
  90. finalExamination.GradeYearID = dbfianl.GradeYearID;
  91. finalExamination.DepartmentID = dbfianl.DepartmentID;
  92. finalExamination.ClassName = className;
  93. finalExamination.CoursematerialID = dbfianl.CoursematerialID;
  94. finalExamination.CourseTypeID = dbfianl.CourseTypeID;
  95. finalExamination.ExamsCategoryID = finalExaminationView.Key.ExamsCategoryID;
  96. //(int)EMIS.ViewModel.CF_ExamsCategory.Resit;
  97. finalExamination.ExaminationModeID = dbfianl.ExaminationModeID;
  98. finalExamination.Credit = dbfianl.Credit;
  99. //总学时
  100. finalExamination.TotalHours = dbfianl.TotalHours;
  101. finalExamination.ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.ResitExamination;
  102. finalExamination.ApprovalStatus = startStatusID; //(int)EMIS.ViewModel.CF_ScoreState.NoCanInput;
  103. finalExamination.ResultTypeID = dbfianl.ResultTypeID;
  104. finalExamination.CollegeID = dbfianl.CollegeID;
  105. finalExamination.IsEntry = false;
  106. finalExamination.CreatorUserID = finalExaminationView.FirstOrDefault().CreatorUserID;
  107. SetNewStatus(finalExamination);
  108. }
  109. else
  110. {
  111. string className = finalExaminationView.Key.CourseName + " - " + grademajorName + " - " + IdNameExt.GetDictionaryItem(DictionaryItem.CF_ExamsCategory.ToString()).Where(x => x.Value == finalExaminationView.Key.ExamsCategoryID).Select(x => x.Name).FirstOrDefault();
  112. finalExamination.FinalExaminationID = Guid.NewGuid();
  113. finalExamination.SchoolyearID = curSchoolyear.SchoolYearID;
  114. finalExamination.GradeYearID = dbfianl.GradeYearID;
  115. finalExamination.DepartmentID = dbfianl.DepartmentID;
  116. finalExamination.ClassName = className;
  117. finalExamination.CoursematerialID = dbfianl.CoursematerialID;
  118. finalExamination.CourseTypeID = dbfianl.CourseTypeID;
  119. finalExamination.ExamsCategoryID = finalExaminationView.Key.ExamsCategoryID;
  120. //(int)EMIS.ViewModel.CF_ExamsCategory.Resit;
  121. finalExamination.ExaminationModeID = dbfianl.ExaminationModeID;
  122. finalExamination.Credit = dbfianl.Credit;
  123. //总学时
  124. finalExamination.TotalHours = dbfianl.TotalHours;
  125. finalExamination.ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.ResitExamination;
  126. finalExamination.ApprovalStatus = startStatusID; //(int)EMIS.ViewModel.CF_ScoreState.NoCanInput;
  127. finalExamination.ResultTypeID = dbfianl.ResultTypeID;
  128. finalExamination.CollegeID = dbfianl.CollegeID;
  129. finalExamination.IsEntry = false;
  130. finalExamination.CreatorUserID = finalExaminationView.FirstOrDefault().CreatorUserID;
  131. SetNewStatus(finalExamination);
  132. }
  133. var queryStudent = finalExaminationView.Select(x => new ER_FinalExaminationStudent
  134. {
  135. FinalExaminationStudentID = Guid.NewGuid(),
  136. FinalExaminationID = finalExamination.FinalExaminationID,
  137. UserID = x.UserID,
  138. SchoolyearNumID = x.SchoolyearNumID,
  139. StarttermID = x.StartTermID,
  140. RecordStatus = (int)SYS_STATUS.USABLE,
  141. CreateTime = DateTime.Now,
  142. CreateUserID = curUser.UserID,
  143. ModifyTime = DateTime.Now,
  144. ModifyUserID = curUser.UserID
  145. });
  146. finalExamination.ER_FinalExaminationStudent = new HashSet<ER_FinalExaminationStudent>(queryStudent.ToList());
  147. listFinalExamination.Add(finalExamination);
  148. }
  149. UnitOfWork.BulkInsert(listFinalExamination);
  150. UnitOfWork.BulkInsert(listFinalExamination.SelectMany(x => x.ER_FinalExaminationStudent).ToList());
  151. //UnitOfWork.BulkInsert(SlistFinalExamination);
  152. //UnitOfWork.BulkInsert(SlistFinalExamination.SelectMany(x => x.ER_FinalExaminationStudent).ToList());
  153. UnitOfWork.Commit();
  154. }
  155. catch (Exception)
  156. {
  157. throw;
  158. }
  159. }
  160. }
  161. }