RetakePlanDAL.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.RetakeManage;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.ChargeManage.ArrearsSituation;
  11. using EMIS.ViewModel.ChargeManage.ChargeSituation;
  12. using EMIS.ViewModel.EducationManagement;
  13. namespace EMIS.DataLogic.RetakeManage
  14. {
  15. public class RetakePlanDAL
  16. {
  17. public RetakePlanRepository RetakePlanRepository { get; set; }
  18. public RetakePlanStudentRepository RetakePlanStudentRepository { get; set; }
  19. public RetakeExamsCatagoryRepository RetakeExamsCatagoryRepository { get; set; }
  20. public CoursematerialRepository CoursematerialRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. public StudentRepository StudentRepository { get; set; }
  24. public ClassmajorRepository ClassmajorRepository { get; set; }
  25. public GrademajorRepository GrademajorRepository { get; set; }
  26. public FacultymajorRepository FacultymajorRepository { get; set; }
  27. public CollegeRepository CollegeRepository { get; set; }
  28. public FinallyScoreRepository FinallyScoreRepository { get; set; }
  29. public StudentChargeRepository StudentChargeRepository { get; set; }
  30. public ParameterRepository ParameterRepository { get; set; }
  31. public EducationMissionRepository EducationMissionRepository { get; set; }
  32. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  33. public EducationMissionClassTeachingSettingRepository EducationMissionClassTeachingSettingRepository { get; set; }
  34. public EducationSchedulingClassRepository EducationSchedulingClassRepository { get; set; }
  35. public AdultEducationScheduleRepository AdultEducationScheduleRepository { get; set; }
  36. public AdultEducationScheduleTeacherRepository AdultEducationScheduleTeacherRepository { get; set; }
  37. public CourseTimeHoursRepository CourseTimeHoursRepository { get; set; }
  38. public Lazy<ChargeControlDAL> ChargeControlDAL { get; set; }
  39. public IQueryable<RetakeStudentListView> GetRetakeStudentListViewQuery(Expression<Func<ER_RetakePlan, bool>> exp,
  40. Expression<Func<ER_RetakePlanStudent, bool>> studentExp)
  41. {
  42. var query = (from plan in RetakePlanRepository.GetList(exp)
  43. join schoolyear in SchoolyearRepository.Entities on plan.SchoolyearID equals schoolyear.SchoolyearID
  44. join planstudent in RetakePlanStudentRepository.GetList(studentExp) on plan.RetakePlanID equals planstudent.RetakePlanID
  45. join student in StudentRepository.Entities on planstudent.UserID equals student.UserID
  46. join user in UserRepository.Entities on planstudent.UserID equals user.UserID
  47. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  48. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID
  49. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID
  50. join college in CollegeRepository.Entities on faculty.CollegeID equals college.CollegeID
  51. join course in CoursematerialRepository.Entities on plan.CoursematerialID equals course.CoursematerialID
  52. join nopass in
  53. (
  54. from score in FinallyScoreRepository.GetList(x => x.TotalScore < 60 && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  55. join type in RetakeExamsCatagoryRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE) on score.ExamsCategoryID equals type.ExamsCategoryID
  56. group score by score.UserID into g
  57. select new
  58. {
  59. UserID = g.Key,
  60. NoPassCount = g.Count()
  61. }
  62. ) on planstudent.UserID equals nopass.UserID into dnopass
  63. from enopass in dnopass.DefaultIfEmpty()
  64. //此处有误,后续修复。。。
  65. join arrears in ChargeControlDAL.Value.GetReatkePlanListViewAble(x => x.ChargeTag == (int)EC_ChargeTag.Retake)
  66. .GroupBy(x => x.UserID).Select(x => new { UserID = x.Key })
  67. on planstudent.UserID equals arrears.UserID into darrears
  68. from earrears in darrears.DefaultIfEmpty()
  69. join s in ChargeControlDAL.Value.StudentChargeRepository.Entities.Where(x => x.ChargeTag == (int)EC_ChargeTag.Retake)
  70. on planstudent.UserID equals s.UserID into d
  71. from e in d.DefaultIfEmpty()
  72. select new RetakeStudentListView
  73. {
  74. CourseTypeID = plan.CourseTypeID,
  75. CourseCode = course.CourseCode,
  76. CourseName = course.CourseName,
  77. SchoolyearID = plan.SchoolyearID,
  78. SchoolyearCode = schoolyear.Code,
  79. UserID = planstudent.UserID,
  80. LoginID = user.LoginID,
  81. UserName = user.Name,
  82. CollegeID = faculty.CollegeID,
  83. CollegeNo = college.No,
  84. CollegeName = college.Name,
  85. Gradeyear = grade.GradeID,
  86. StandardID = faculty.StandardID,
  87. ClassmajorID = student.ClassmajorID,
  88. ClassName = classmajor.Name,
  89. NoPassCount = enopass.UserID == null ? 0 : enopass.NoPassCount,
  90. IsNoArrears = earrears.UserID == null,
  91. AmountSum = e.Amount
  92. });
  93. return query.Distinct();
  94. }
  95. public IQueryable<RetakeStudentListView> GetRetakeStudentDetailListViewQuery(Expression<Func<ER_RetakePlan, bool>> exp,
  96. Expression<Func<ER_RetakePlanStudent, bool>> studentExp)
  97. {
  98. var query = (from plan in RetakePlanRepository.GetList(exp)
  99. join schoolyear in SchoolyearRepository.Entities on plan.SchoolyearID equals schoolyear.SchoolyearID
  100. join planstudent in RetakePlanStudentRepository.GetList(studentExp) on plan.RetakePlanID equals planstudent.RetakePlanID
  101. join student in StudentRepository.Entities on planstudent.UserID equals student.UserID
  102. join user in UserRepository.Entities on planstudent.UserID equals user.UserID
  103. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  104. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID
  105. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID
  106. join college in CollegeRepository.Entities on faculty.CollegeID equals college.CollegeID
  107. join course in CoursematerialRepository.Entities on plan.CoursematerialID equals course.CoursematerialID
  108. join nopass in
  109. (
  110. from score in FinallyScoreRepository.GetList(x => x.TotalScore < 60 && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  111. join type in RetakeExamsCatagoryRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE) on score.ExamsCategoryID equals type.ExamsCategoryID
  112. group score by score.UserID into g
  113. select new
  114. {
  115. UserID = g.Key,
  116. NoPassCount = g.Count()
  117. }
  118. ) on planstudent.UserID equals nopass.UserID into dnopass
  119. from enopass in dnopass.DefaultIfEmpty()
  120. //此处有误,后续修复。。。
  121. join arrears in ChargeControlDAL.Value.GetArrearListViewAble(x => x.ChargeTag == (int)EC_ChargeTag.Retake)
  122. .GroupBy(x => x.UserID).Select(x => new { UserID = x.Key })
  123. on planstudent.UserID equals arrears.UserID into darrears
  124. from earrears in darrears.DefaultIfEmpty()
  125. select new RetakeStudentListView
  126. {
  127. RetakePlanStudentID = planstudent.RetakePlanStudentID,
  128. CoursematerialID = plan.CoursematerialID,
  129. CourseCode = course.CourseCode,
  130. Abbreviation = course.Abbreviation,
  131. CourseName = course.CourseName,
  132. SchoolyearID = plan.SchoolyearID,
  133. SchoolyearCode = schoolyear.Code,
  134. CourseTypeID = plan.CourseTypeID,
  135. Credit = plan.Credit,
  136. UserID = planstudent.UserID,
  137. LoginID = user.LoginID,
  138. UserName = user.Name,
  139. CollegeID = faculty.CollegeID,
  140. CollegeNo = college.No,
  141. CollegeName = college.Name,
  142. Gradeyear = grade.GradeID,
  143. StandardID = faculty.StandardID,
  144. ClassmajorID = student.ClassmajorID,
  145. ClassName = plan.ClassName,
  146. SchoolyearNumID = planstudent.SchoolyearNumID,
  147. StarttermID = planstudent.StarttermID,
  148. NoPassCount = enopass.UserID == null ? 0 : enopass.NoPassCount,
  149. IsNoArrears = earrears.UserID == null
  150. });
  151. return query.Distinct();
  152. }
  153. public IQueryable<StudentChargeView> GetStudentChargeQueryable(Expression<Func<ER_RetakePlan, bool>> exp,
  154. Expression<Func<ER_RetakePlanStudent, bool>> studentExp)
  155. {
  156. var chargeProjectIDStr = ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.RetakeChargeProjectID)
  157. .Select(x => x.Value).FirstOrDefault();
  158. Guid? chargeProjectID = null;
  159. if (chargeProjectIDStr != null)
  160. {
  161. chargeProjectID = new Guid(chargeProjectIDStr);
  162. }
  163. else
  164. {
  165. throw new Exception("请先在重修参数菜单中指定推送的收费项目。");
  166. }
  167. var query = (from planStudent in this.GetRetakeStudentListViewQuery(exp, studentExp)
  168. join schoolyear in SchoolyearRepository.Entities on planStudent.SchoolyearID equals schoolyear.SchoolyearID
  169. join charge in StudentChargeRepository.Entities
  170. on new { planStudent.UserID, ChargeYear = (int?)schoolyear.Years, ChargeProjectID = chargeProjectID }
  171. equals new { charge.UserID, charge.ChargeYear, charge.ChargeProjectID }
  172. into dcharge
  173. from echarge in dcharge.DefaultIfEmpty()
  174. where echarge.StudentChargeID == null
  175. select new StudentChargeView
  176. {
  177. StudentChargeID = Guid.NewGuid(),
  178. UserID = planStudent.UserID,
  179. ChargeProjectID = chargeProjectID,
  180. ChargeYear = schoolyear.Years,
  181. Amount = 0,
  182. ActualAmount = 0,
  183. ChargeTag = (int)EC_ChargeTag.Retake,
  184. Remark = ""
  185. });
  186. return query;
  187. }
  188. public IQueryable<ER_RetakePlan> GetRetakePlanByStudentQueryable(IQueryable<RetakeStudentView> studentQueryable, int? startStatusID)
  189. {
  190. var schoolyearIDStr = ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.RetakeSchoolyearID)
  191. .Select(x => x.Value).FirstOrDefault();
  192. Guid? schoolyearID = null;
  193. if (schoolyearIDStr != null)
  194. {
  195. schoolyearID = new Guid(schoolyearIDStr);
  196. }
  197. else
  198. {
  199. throw new Exception("未设置重修学年学期,无法生成重修学生名单,请在重修参数菜单中设置重修学年学期。");
  200. }
  201. var query = (from planStudent in studentQueryable
  202. group planStudent by new { planStudent.CoursematerialID, planStudent.CourseTypeID, planStudent.Credit } into g
  203. join plan in RetakePlanRepository.GetList(x => x.RecordStatus == startStatusID
  204. && x.SchoolyearID == schoolyearID)
  205. on new { g.Key.CoursematerialID, g.Key.CourseTypeID, g.Key.Credit }
  206. equals new { plan.CoursematerialID, plan.CourseTypeID, plan.Credit }
  207. select plan);
  208. return query;
  209. }
  210. public IQueryable<RetakeStudentApplyView> GetRetakeStudentApplyViewQueryable(Expression<Func<ER_RetakePlanStudent, bool>> studentExp)
  211. {
  212. var query = (from plan in RetakePlanRepository.Entities
  213. join schoolyear in SchoolyearRepository.Entities on plan.SchoolyearID equals schoolyear.SchoolyearID
  214. join planstudent in RetakePlanStudentRepository.GetList(studentExp) on plan.RetakePlanID equals planstudent.RetakePlanID
  215. join student in StudentRepository.Entities on planstudent.UserID equals student.UserID
  216. join user in UserRepository.Entities on planstudent.UserID equals user.UserID
  217. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  218. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID
  219. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID
  220. join college in CollegeRepository.Entities on faculty.CollegeID equals college.CollegeID
  221. join course in CoursematerialRepository.Entities on plan.CoursematerialID equals course.CoursematerialID
  222. join mission in EducationMissionRepository.Entities on planstudent.EducationMissionID equals mission.EducationMissionID into dmission
  223. from emission in dmission.DefaultIfEmpty()
  224. join missionClass in EducationMissionClassRepository.Entities on emission.EducationMissionID equals missionClass.EducationMissionID into dmissionClass
  225. from emissionClass in dmissionClass.DefaultIfEmpty()
  226. join teachSetting in EducationMissionClassTeachingSettingRepository.Entities on emissionClass.EducationMissionClassID equals teachSetting.EducationMissionClassID into dTeachSetting
  227. from eteachSetting in dTeachSetting.DefaultIfEmpty()
  228. from coursesTime in emissionClass.EM_CoursesTime.DefaultIfEmpty()
  229. join schedule in
  230. (
  231. from schedule in AdultEducationScheduleRepository.Entities
  232. group schedule by new { schedule.EM_EducationSchedulingClass.EM_EducationMissionClass.EducationMissionID, schedule.ClassroomID, ClassroomName = schedule.CF_Classroom.Name } into g
  233. select new { g.Key.EducationMissionID, g.Key.ClassroomID, g.Key.ClassroomName }
  234. ) on emissionClass.EducationMissionID
  235. equals schedule.EducationMissionID into dschedule
  236. from eschedule in dschedule.DefaultIfEmpty()
  237. select new RetakeStudentApplyView
  238. {
  239. RetakePlanStudentID = planstudent.RetakePlanStudentID,
  240. CoursematerialID = plan.CoursematerialID,
  241. CourseCode = course.CourseCode,
  242. Abbreviation = course.Abbreviation,
  243. CourseName = course.CourseName,
  244. SchoolyearID = plan.SchoolyearID,
  245. CourseTypeID = plan.CourseTypeID,
  246. Credit = plan.Credit,
  247. UserID = planstudent.UserID,
  248. SchoolyearNumID = planstudent.SchoolyearNumID,
  249. StarttermID = planstudent.StarttermID,
  250. EducationMissionID = planstudent.EducationMissionID,
  251. TimeID = coursesTime.TimesSegment,
  252. CourseTimeID = coursesTime.CoursesTimeID,
  253. ScheduledTimes = (eteachSetting.TheoryCourse ?? 0) + (eteachSetting.Practicehours ?? 0),
  254. ClassroomID = eschedule.ClassroomID,
  255. ClassroomName = eschedule.ClassroomName,
  256. RecordStatus = planstudent.RecordStatus
  257. });
  258. return query;
  259. }
  260. public IQueryable<RetakePlanStudentTeacherView> GetRetakePlanStudentTeacherViewQueryable(Expression<Func<ER_RetakePlanStudent, bool>> studentExp)
  261. {
  262. var query = (from plan in RetakePlanRepository.Entities
  263. join schoolyear in SchoolyearRepository.Entities on plan.SchoolyearID equals schoolyear.SchoolyearID
  264. join planstudent in RetakePlanStudentRepository.GetList(studentExp) on plan.RetakePlanID equals planstudent.RetakePlanID
  265. join mission in EducationMissionRepository.Entities on planstudent.EducationMissionID equals mission.EducationMissionID
  266. join missionClass in EducationMissionClassRepository.Entities on mission.EducationMissionID equals missionClass.EducationMissionID
  267. join schedulingClass in EducationSchedulingClassRepository.Entities on missionClass.EducationMissionClassID equals schedulingClass.EducationSchedulingClassID
  268. join schedule in AdultEducationScheduleRepository.Entities on schedulingClass.EducationSchedulingClassID equals schedule.EducationSchedulingClassID
  269. join teacher in AdultEducationScheduleTeacherRepository.Entities on schedule.AdultEducationScheduleID equals teacher.AdultEducationScheduleID
  270. join user in UserRepository.Entities on teacher.UserID equals user.UserID
  271. select new RetakePlanStudentTeacherView
  272. {
  273. RetakePlanStudentID = planstudent.RetakePlanStudentID,
  274. UserID = teacher.UserID,
  275. Name = user.Name
  276. });
  277. return query;
  278. }
  279. public IQueryable<RetakeStudentApproveView> GetRetakeStudentApproveViewQueryable(Expression<Func<ER_RetakePlan, bool>> exp,
  280. Expression<Func<ER_RetakePlanStudent, bool>> studentExp)
  281. {
  282. var query = (from plan in RetakePlanRepository.GetList(exp)
  283. join schoolyear in SchoolyearRepository.Entities on plan.SchoolyearID equals schoolyear.SchoolyearID
  284. join planstudent in RetakePlanStudentRepository.GetList(studentExp) on plan.RetakePlanID equals planstudent.RetakePlanID
  285. join course in CoursematerialRepository.Entities on plan.CoursematerialID equals course.CoursematerialID
  286. join student in StudentRepository.Entities on planstudent.UserID equals student.UserID
  287. join user in UserRepository.Entities on planstudent.UserID equals user.UserID
  288. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  289. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID
  290. join facult in FacultymajorRepository.Entities on grade.FacultymajorID equals facult.FacultymajorID
  291. join college in CollegeRepository.Entities on facult.CollegeID equals college.CollegeID
  292. join mission in EducationMissionRepository.Entities on planstudent.EducationMissionID equals mission.EducationMissionID
  293. join missionclass in EducationMissionClassRepository.Entities on mission.EducationMissionID equals missionclass.EducationMissionID
  294. join teachSetting in EducationMissionClassTeachingSettingRepository.Entities on missionclass.EducationMissionClassID equals teachSetting.EducationMissionClassID
  295. join scheduleclass in EducationSchedulingClassRepository.Entities on missionclass.EducationMissionClassID equals scheduleclass.EducationMissionClassID
  296. from coursetime in missionclass.EM_CoursesTime
  297. join classroom in
  298. (
  299. from schedule in AdultEducationScheduleRepository.Entities
  300. group schedule by new { schedule.EM_EducationSchedulingClass.EM_EducationMissionClass.EducationMissionID, schedule.ClassroomID, ClassroomName = schedule.CF_Classroom.Name } into g
  301. select new { g.Key.EducationMissionID, g.Key.ClassroomID, g.Key.ClassroomName }
  302. ) on mission.EducationMissionID equals classroom.EducationMissionID
  303. select new RetakeStudentApproveView
  304. {
  305. RetakePlanStudentID = planstudent.RetakePlanStudentID,
  306. SchoolyearCode = schoolyear.Code,
  307. CoursematerialID = plan.CoursematerialID,
  308. Abbreviation = course.Abbreviation,
  309. CourseCode = course.CourseCode,
  310. CourseName = course.CourseName,
  311. SchoolyearID = schoolyear.SchoolyearID,
  312. CourseTypeID = plan.CourseTypeID,
  313. Credit = plan.Credit,
  314. UserID = planstudent.UserID,
  315. SchoolyearNumID = planstudent.SchoolyearNumID,
  316. StarttermID = planstudent.StarttermID,
  317. EducationMissionID = planstudent.EducationMissionID,
  318. LoginID = user.LoginID,
  319. UserName = user.Name,
  320. ClassmajorID = student.ClassmajorID,
  321. ClassmajorName = classmajor.Name,
  322. CollegeID = facult.CollegeID,
  323. CollegeNo = college.No,
  324. CollegeName = college.Name,
  325. ClassName = mission.ClassName,
  326. RetakePlanStudentTeacherView = scheduleclass.ES_AdultEducationSchedule.SelectMany(x => x.ES_AdultEducationScheduleTeacher.Select(w => w.CF_Staff.Sys_User)),
  327. ScheduleDate = scheduleclass.ES_AdultEducationSchedule.Select(x => x.ScheduleDate),
  328. TimeID = coursetime.TimesSegment,
  329. CourseTimeID = coursetime.CoursesTimeID,
  330. TotalHours = (teachSetting.TheoryCourse ?? 0)
  331. + (teachSetting.Practicehours ?? 0),
  332. ClassroomID = classroom.ClassroomID,
  333. ClassroomName = classroom.ClassroomName,
  334. RecordStatus = planstudent.RecordStatus
  335. }
  336. );
  337. return query;
  338. }
  339. }
  340. }