StudentsDAL.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using EMIS.Entities;
  7. using EMIS.DataLogic.Repositories;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.SystemView;
  10. using System.Linq.Expressions;
  11. using EMIS.ViewModel.Students;
  12. using System.Data.Entity;
  13. using EMIS.DataLogic.SystemDAL;
  14. namespace EMIS.DataLogic.Common.Students
  15. {
  16. public class StudentsDAL
  17. {
  18. public StudentRepository StudentRepository { get; set; }
  19. public StudentContactRepository StudentContactRepository { get; set; }
  20. public StudentAccountRepository StudentAccountRepository { get; set; }
  21. public DictionaryDAL DictionaryDAL { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. //public EducationMissionRepository EducationMissionRepository { get; set; }//教学任务班主表
  24. //public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  25. //public EducationSchedulingClassRepository EducationSchedulingClassRepository { get; set; }
  26. public InSchoolSettingRepository InSchoolSettingRepository { get; set; }
  27. public RecruitstudentsRepository RecruitstudentsRepository { get; set; }
  28. public StudentProfileRepository StudentProfileRepository { get; set; }
  29. public ClassmajorRepository ClassmajorRepository { get; set; }
  30. public GrademajorRepository GrademajorRepository { get; set; }
  31. public FacultymajorRepository FacultymajorRepository { get; set; }
  32. public SchoolyearRepository SchoolyearRepository { get; set; }
  33. public UniversityRepository universityRepository { get; set; }
  34. public UniversityProfileRepository universityProfileRepository { get; set; }
  35. /// <summary>
  36. /// 获取当前学年学期所有学生信息
  37. /// </summary>
  38. /// <param name="filter"></param>
  39. /// <returns></returns>
  40. public IQueryable<StudentsView> GetStudentQueryable(Expression<Func<CF_Student, bool>> filter,
  41. Expression<Func<CF_Classmajor, bool>> classmajorExp = null,
  42. Expression<Func<CF_Grademajor, bool>> grademajorExp = null)
  43. {
  44. if (classmajorExp == null)
  45. {
  46. classmajorExp = (x => true);
  47. }
  48. if (grademajorExp == null)
  49. {
  50. grademajorExp = (x => true);
  51. }
  52. var query = from c in StudentRepository.GetList(filter)
  53. join classmajor in ClassmajorRepository.GetList(classmajorExp) on c.ClassmajorID equals classmajor.ClassmajorID
  54. join grade in GrademajorRepository.GetList(grademajorExp) on classmajor.GrademajorID equals grade.GrademajorID
  55. join studentProfile in StudentProfileRepository.Entities on c.UserID equals studentProfile.UserID
  56. into cstudentProfile
  57. from tcstudentProfile in cstudentProfile.DefaultIfEmpty()
  58. join recruitStudent in RecruitstudentsRepository.Entities on c.UserID equals recruitStudent.UserID
  59. into crecruitStudent
  60. from tcrecruitStudent in crecruitStudent.DefaultIfEmpty()
  61. select new StudentsView
  62. {
  63. UserID = c.UserID,
  64. LoginID = c.Sys_User.LoginID,
  65. StudentNo = c.StudentCardNo,
  66. UserName = c.Sys_User.Name,
  67. IDNumber = c.IDNumber,
  68. PhotoUrl = c.PhotoUrl,
  69. IsProofread = c.IsProofread,
  70. IsPhoto = c.PhotoUrl == null ? (int)CF_YesOrNoStatus.No : (int)CF_YesOrNoStatus.Yes,
  71. IsPhotoUrl = c.PhotoUrl == null ? "否" : "是",
  72. StudentCardNo = c.StudentCardNo,
  73. PlanningGraduateDate = c.PlanningGraduateDate,//预计毕业时间
  74. EntranceDate = c.CF_Recruitstudents.EntranceDate,
  75. EnteringSchoolYearID = c.CF_Recruitstudents.EnteringSchoolYearID,
  76. EnteringSchoolYearCode = c.CF_Recruitstudents.CF_Schoolyear.Code,
  77. Score = c.CF_Recruitstudents.Score,
  78. ExamineeNum = c.CF_Recruitstudents.ExamineeNum,
  79. AdmissionTicketNo = c.CF_Recruitstudents.AdmissionTicketNo,
  80. Area = c.CF_Recruitstudents.Area,
  81. Placebirth = c.CF_Recruitstudents.PlaceBirth,
  82. CardNo = c.CF_StudentAccount.CardNo,
  83. BankName = c.CF_StudentAccount.BankName,
  84. Territorial = tcrecruitStudent.Territorial,
  85. Sex = c.Sex,
  86. ClassMajorID = c.ClassmajorID,
  87. ClassMajorCode = classmajor.No,
  88. ClassMajorName = classmajor.Name,
  89. Grade = grade.SchoolyearID,
  90. StudentStatus = c.StudentStatus,
  91. InSchoolStatusID = c.InSchoolStatusID,
  92. UsedName = c.CF_StudentProfile.UsedName,
  93. DirectorName = c.CF_StudentProfile.DirectorName,
  94. BirthDate = c.CF_StudentProfile.BirthDate,
  95. Country = c.CF_StudentProfile.Country,
  96. Politics = c.CF_StudentProfile.Politics,
  97. Place = c.CF_StudentProfile.Place,
  98. //BornPlace = c.CF_StudentProfile.BornPlace,
  99. Specialty = c.CF_StudentProfile.Specialty,
  100. Height = c.CF_StudentProfile.Height,
  101. Weight = c.CF_StudentProfile.Weight,
  102. Remarks = c.CF_StudentProfile.Remarks,
  103. GraduationPictureUrl = c.CF_StudentProfile.GraduationPictureUrl,
  104. Email = c.CF_StudentContact.Email,
  105. QQ = c.CF_StudentContact.QQ,
  106. Mobile = c.CF_StudentContact.Mobile,
  107. Telephone = c.CF_StudentContact.Telephone,
  108. MicroMsgNo = c.CF_StudentContact.MicroMsgNo,
  109. ZipCode = c.CF_StudentContact.Zipcode,
  110. Address = c.CF_StudentContact.Address,
  111. WorkUnit = c.CF_StudentContact.WorkUnit,
  112. HomeAddress = c.CF_StudentContact.HomeAddress,
  113. Recipient = c.CF_StudentContact.Recipient,
  114. Dormitory = c.CF_StudentContact.Dormitory,
  115. LearnSystem = grade.CF_Facultymajor.LearnSystem,
  116. CampusID = grade.CF_Facultymajor.CF_College.CampusID,
  117. SchoolTypeID = grade.CF_Facultymajor.CF_College.CF_Campus.CF_University.CF_UniversityProfile.SchoolTypeID,
  118. CampusName = grade.CF_Facultymajor.CF_College.CF_Campus.Name,
  119. CollegeID = grade.CF_Facultymajor.CollegeID,
  120. CollegeCode = grade.CF_Facultymajor.CF_College.No,
  121. CollegeName = grade.CF_Facultymajor.CF_College.Name,
  122. EducationID = grade.CF_Facultymajor.EducationID,
  123. StandardID = grade.CF_Facultymajor.StandardID,
  124. LearningformID = grade.CF_Facultymajor.LearningformID,
  125. GradeMajorID = classmajor.GrademajorID,
  126. GradeMajorName = grade.Name,
  127. GradeMajorCode = grade.Code,
  128. StudentType = c.StudentType,
  129. CultureModel = c.CultureModel,
  130. BloodGroup = tcstudentProfile.BloodGroup,
  131. CertificatesType = c.CertificatesType,
  132. EntranceWay = tcrecruitStudent.EntranceWay,
  133. ExamineeType = tcrecruitStudent.ExamineeType,
  134. Features = tcrecruitStudent.Features,
  135. Healthy = tcstudentProfile.Healthy,
  136. Nation = tcstudentProfile.Nation,
  137. FacultymajorName = grade.CF_Facultymajor.Name,//院系所专业
  138. GraduateCardNo=c.GraduateCardNo,
  139. GraduateDate = c.GraduateDate,
  140. IsDreamProject = c.IsDreamProject == true,
  141. Career=c.Career,
  142. ReplaceGraduateNo=c.ReplaceGraduateNo,
  143. LiteracyLevels = c.CF_StudentProfile.LiteracyLevels,
  144. Years = c.CF_Classmajor.CF_Grademajor.SchoolyearID,
  145. SchoolAreaID = grade.SchoolAreaID,
  146. };
  147. return query;
  148. }
  149. public IQueryable<BaseStudentView> GetBaseStudentViewQueryable(Expression<Func<CF_Student, bool>> filter)
  150. {
  151. var query = from c in StudentRepository.GetList(filter)
  152. join studentProfile in StudentProfileRepository.Entities on c.UserID equals studentProfile.UserID
  153. join recruitStudent in RecruitstudentsRepository.Entities on c.UserID equals recruitStudent.UserID
  154. select new BaseStudentView
  155. {
  156. UserID = c.UserID,
  157. LoginID = c.Sys_User.LoginID,
  158. StudentNo = c.StudentCardNo,
  159. UserName = c.Sys_User.Name,
  160. Sex = c.Sex,
  161. IDNumber = c.IDNumber,
  162. InSchoolStatusID = c.InSchoolStatusID,
  163. StudentStatus = c.StudentStatus,
  164. ClassmajorID = c.CF_Classmajor.ClassmajorID,
  165. ClassmajorCode = c.CF_Classmajor.No,
  166. ClassmajorName = c.CF_Classmajor.Name,
  167. GrademajorID = c.CF_Classmajor.GrademajorID,
  168. GrademajorName = c.CF_Classmajor.CF_Grademajor.Name,
  169. CollegeID = c.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  170. Years = c.CF_Classmajor.CF_Grademajor.SchoolyearID,
  171. // GraduateCardNo=c.GraduateCardNo
  172. };
  173. return query;
  174. }
  175. public IQueryable<BaseStudentView> GetInSchoolStudentViewQueryable(Expression<Func<CF_Student, bool>> filter)
  176. {
  177. var query = from c in StudentRepository.GetList(filter)
  178. select new BaseStudentView
  179. {
  180. UserID = c.UserID,
  181. LoginID = c.Sys_User.LoginID,
  182. UserName = c.Sys_User.Name,
  183. Sex = c.Sex,
  184. StudentNo = c.StudentCardNo,
  185. IDNumber = c.IDNumber,
  186. InSchoolStatusID = c.InSchoolStatusID,
  187. StudentStatus = c.StudentStatus,
  188. ClassmajorID = c.CF_Classmajor.ClassmajorID,
  189. ClassmajorCode = c.CF_Classmajor.No,
  190. ClassmajorName = c.CF_Classmajor.Name,
  191. GrademajorID = c.CF_Classmajor.GrademajorID,
  192. GrademajorName = c.CF_Classmajor.CF_Grademajor.Name,
  193. CollegeID = c.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  194. CollegeName = c.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  195. Years = c.CF_Classmajor.CF_Grademajor.SchoolyearID,
  196. SchoolyearID = c.CF_Classmajor.CF_Grademajor.SchoolyearID,
  197. //GraduateCardNo=c.GraduateCardNo
  198. };
  199. return query;
  200. }
  201. public IQueryable<BaseStudentView> GetBaseStudentViewQueryable(Expression<Func<CF_Student, bool>> studentExp,
  202. Expression<Func<CF_Grademajor, bool>> gradeExp, Expression<Func<CF_Facultymajor, bool>> facultyExp)
  203. {
  204. var q = from student in this.GetBaseStudentViewQueryable(studentExp)
  205. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  206. join grade in GrademajorRepository.Entities.Where(gradeExp) on classmajor.GrademajorID equals grade.GrademajorID
  207. join faculty in FacultymajorRepository.Entities.Where(facultyExp) on grade.FacultymajorID equals faculty.FacultymajorID
  208. select student;
  209. return q;
  210. }
  211. //计算预计毕业设计时间
  212. public StudentsView GetPlanningGraduateDate(Guid GrademajorID)
  213. {
  214. var query = from g in GrademajorRepository.Entities.Where(x => x.GrademajorID == GrademajorID && x.GraduatingSemesterID != null)
  215. join f in FacultymajorRepository.Entities on g.FacultymajorID equals f.FacultymajorID
  216. join sn in SchoolyearRepository.Entities on new { Value = (int)((g.SchoolyearID * 2 - 1) + (g.SchoolcodeID - 1) + (f.LearnSystem * 2 - 1)) } equals new { Value = (int)sn.Value }
  217. into tsn
  218. from ctsn in tsn.DefaultIfEmpty()
  219. select new StudentsView { PlanningGraduateDate = (DateTime)ctsn.FirstWeek, WeeksNum = ctsn.WeeksNum * 7 };
  220. return query.FirstOrDefault();
  221. }
  222. //计算预计毕业设计时间 方案二 2016年10月25日14:19:25
  223. //public StudentsView GetPlanningGraduate(Guid GrademajorID)
  224. //{
  225. // var query = from g in GrademajorRepository.Entities.Where(x => x.GrademajorID == GrademajorID && x.GraduatingSemesterID != null)
  226. // join f in FacultymajorRepository.Entities on g.FacultymajorID equals f.FacultymajorID
  227. // select new StudentsView { LearnSystem = f.LearnSystem, Years=g.SchoolyearID };
  228. // return query.FirstOrDefault();
  229. //}
  230. public StudentsView GetPlanningGraduate(Guid GrademajorID)
  231. {
  232. var query = from g in GrademajorRepository.Entities.Where(x => x.GrademajorID == GrademajorID && x.GraduatingSemesterID != null)
  233. join f in FacultymajorRepository.Entities on g.FacultymajorID equals f.FacultymajorID
  234. join s in SchoolyearRepository.Entities on g.GraduatingSemesterID equals s.SchoolyearID
  235. join d in DictionaryDAL.GetDictionaryItemQuery(typeof(CF_Schoolcode).Name) on s.SchoolcodeID equals d.Value into dv
  236. from d in dv.DefaultIfEmpty()
  237. select new StudentsView {
  238. LearnSystem = f.LearnSystem,
  239. Years = g.SchoolyearID,
  240. Grade = g.SchoolyearID,
  241. PlanningGraduateYear=s.Years,
  242. PlanningGraduateSchoolYearID=g.GraduatingSemesterID,
  243. PlanningGraduateSchoolCodeID=s.SchoolcodeID,
  244. PlanningGraduateSchoolCode = d.Value,
  245. PlanningGraduateSchoolCodeName = d.Name,
  246. };
  247. return query.FirstOrDefault();
  248. }
  249. public IQueryable<StudentsView> GetPlanningGraduateDictionary()
  250. {
  251. var inSchoolStatusIDList = InSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();//获取选中的在校设定状态、
  252. var query = from a in StudentRepository.GetList(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID))
  253. group a by a.PlanningGraduateDate
  254. into b
  255. select new StudentsView
  256. {
  257. PlanningGraduateDate = b.Key,
  258. //PlanningGraduateStr = b.Key.Value,
  259. };
  260. return query;
  261. }
  262. /// <summary>
  263. /// 获取当前学年学期所有学生信息
  264. /// </summary>
  265. /// <param name="filter"></param>
  266. /// <returns></returns>
  267. public IQueryable<StudentsView> GetStudentForExcel(Expression<Func<CF_Student, bool>> filter,
  268. Expression<Func<CF_Classmajor, bool>> classmajorExp = null,
  269. Expression<Func<CF_Grademajor, bool>> grademajorExp = null)
  270. {
  271. if (classmajorExp == null)
  272. {
  273. classmajorExp = (x => true);
  274. }
  275. if (grademajorExp == null)
  276. {
  277. grademajorExp = (x => true);
  278. }
  279. var schoolquery = from uni in universityRepository.Entities
  280. join unip in universityProfileRepository.Entities
  281. on uni.UniversityID equals unip.UniversityID
  282. select new
  283. {
  284. SchoolCode = uni.Code,
  285. SchoolName = uni.Name,
  286. HeadMasterName = unip.HeadMasterName,
  287. };
  288. var query = from c in StudentRepository.GetList(filter)
  289. join classmajor in ClassmajorRepository.GetList(classmajorExp) on c.ClassmajorID equals classmajor.ClassmajorID
  290. join grade in GrademajorRepository.GetList(grademajorExp) on classmajor.GrademajorID equals grade.GrademajorID
  291. join studentProfile in StudentProfileRepository.Entities on c.UserID equals studentProfile.UserID
  292. into cstudentProfile
  293. from tcstudentProfile in cstudentProfile.DefaultIfEmpty()
  294. join recruitStudent in RecruitstudentsRepository.Entities on c.UserID equals recruitStudent.UserID
  295. into crecruitStudent
  296. from tcrecruitStudent in crecruitStudent.DefaultIfEmpty()
  297. select new StudentsView
  298. {
  299. UserID = c.UserID,
  300. LoginID = c.Sys_User.LoginID,
  301. StudentNo = c.StudentCardNo,
  302. UserName = c.Sys_User.Name,
  303. IDNumber = c.IDNumber,
  304. PhotoUrl = c.PhotoUrl,
  305. IsProofread = c.IsProofread,
  306. IsPhoto = c.PhotoUrl == null ? (int)CF_YesOrNoStatus.No : (int)CF_YesOrNoStatus.Yes,
  307. IsPhotoUrl = c.PhotoUrl == null ? "否" : "是",
  308. StudentCardNo = c.StudentCardNo,
  309. PlanningGraduateDate = c.PlanningGraduateDate,//预计毕业时间
  310. EntranceDate = c.CF_Recruitstudents.EntranceDate,
  311. EnteringSchoolYearID = c.CF_Recruitstudents.EnteringSchoolYearID,
  312. EnteringSchoolYearCode = c.CF_Recruitstudents.CF_Schoolyear.Code,
  313. Score = c.CF_Recruitstudents.Score,
  314. ExamineeNum = c.CF_Recruitstudents.ExamineeNum,
  315. AdmissionTicketNo = c.CF_Recruitstudents.AdmissionTicketNo,
  316. Area = c.CF_Recruitstudents.Area,
  317. Placebirth = c.CF_Recruitstudents.PlaceBirth,
  318. CardNo = c.CF_StudentAccount.CardNo,
  319. BankName = c.CF_StudentAccount.BankName,
  320. Territorial = tcrecruitStudent.Territorial,
  321. Sex = c.Sex,
  322. ClassMajorID = c.ClassmajorID,
  323. ClassMajorCode = classmajor.No,
  324. ClassMajorName = classmajor.Name,
  325. ClassNum = classmajor.ClassNum,
  326. Grade = grade.SchoolyearID,
  327. StudentStatus = c.StudentStatus,
  328. InSchoolStatusID = c.InSchoolStatusID,
  329. UsedName = c.CF_StudentProfile.UsedName,
  330. DirectorName = c.CF_StudentProfile.DirectorName,
  331. BirthDate = c.CF_StudentProfile.BirthDate,
  332. Country = c.CF_StudentProfile.Country,
  333. Politics = c.CF_StudentProfile.Politics,
  334. Place = c.CF_StudentProfile.Place,
  335. //BornPlace = c.CF_StudentProfile.BornPlace,
  336. Specialty = c.CF_StudentProfile.Specialty,
  337. Height = c.CF_StudentProfile.Height,
  338. Weight = c.CF_StudentProfile.Weight,
  339. Remarks = c.CF_StudentProfile.Remarks,
  340. GraduationPictureUrl = c.CF_StudentProfile.GraduationPictureUrl,
  341. Email = c.CF_StudentContact.Email,
  342. QQ = c.CF_StudentContact.QQ,
  343. Mobile = c.CF_StudentContact.Mobile,
  344. Telephone = c.CF_StudentContact.Telephone,
  345. MicroMsgNo = c.CF_StudentContact.MicroMsgNo,
  346. ZipCode = c.CF_StudentContact.Zipcode,
  347. Address = c.CF_StudentContact.Address,
  348. WorkUnit = c.CF_StudentContact.WorkUnit,
  349. HomeAddress = c.CF_StudentContact.HomeAddress,
  350. Recipient = c.CF_StudentContact.Recipient,
  351. Dormitory = c.CF_StudentContact.Dormitory,
  352. LearnSystem = grade.CF_Facultymajor.LearnSystem,
  353. CampusID = grade.CF_Facultymajor.CF_College.CampusID,
  354. SchoolTypeID = grade.CF_Facultymajor.CF_College.CF_Campus.CF_University.CF_UniversityProfile.SchoolTypeID,
  355. CampusName = grade.CF_Facultymajor.CF_College.CF_Campus.Name,
  356. CollegeID = grade.CF_Facultymajor.CollegeID,
  357. CollegeCode = grade.CF_Facultymajor.CF_College.No,
  358. CollegeName = grade.CF_Facultymajor.CF_College.Name,
  359. EducationID = grade.CF_Facultymajor.EducationID,
  360. StandardID = grade.CF_Facultymajor.StandardID,
  361. LearningformID = grade.CF_Facultymajor.LearningformID,
  362. GradeMajorID = classmajor.GrademajorID,
  363. GradeMajorName = grade.Name,
  364. GradeMajorCode = grade.Code,
  365. StudentType = c.StudentType,
  366. CultureModel = c.CultureModel,
  367. BloodGroup = tcstudentProfile.BloodGroup,
  368. CertificatesType = c.CertificatesType,
  369. EntranceWay = tcrecruitStudent.EntranceWay,
  370. ExamineeType = tcrecruitStudent.ExamineeType,
  371. Features = tcrecruitStudent.Features,
  372. Healthy = tcstudentProfile.Healthy,
  373. Nation = tcstudentProfile.Nation,
  374. FacultymajorName = grade.CF_Facultymajor.Name,//院系所专业
  375. GraduateCardNo = c.GraduateCardNo,
  376. IsDreamProject = c.IsDreamProject == true,
  377. Career = c.Career,
  378. SchoolCode = schoolquery.FirstOrDefault().SchoolCode,
  379. SchoolName = schoolquery.FirstOrDefault().SchoolName,
  380. HeadMasterName = schoolquery.FirstOrDefault().HeadMasterName
  381. };
  382. return query;
  383. }
  384. public IQueryable<RegistView> GetRegustViewQueryable(Expression<Func<CF_Student, bool>> exp)
  385. {
  386. var query = (from student in StudentRepository.GetList(exp)
  387. from contact in StudentContactRepository.Entities.Where(x => x.UserID == student.UserID)
  388. from user in UserRepository.Entities.Where(x => x.UserID == student.UserID)
  389. select new RegistView
  390. {
  391. UserID = user.UserID,
  392. LoginID = student.IDNumber,
  393. CertificatesType = student.CertificatesType,
  394. UserName = user.Name,
  395. Mobile = contact.Mobile,
  396. Email = contact.Email,
  397. PhotoUrl = student.PhotoUrl,
  398. Sex = student.Sex,
  399. BirthDate = student.CF_StudentProfile.BirthDate,
  400. });
  401. return query;
  402. }
  403. }
  404. }