GrademajorDAL.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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.Specialtyclass;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel.Students;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.Cache;
  12. using EMIS.ViewModel.UniversityInformationManage.Specialtyclass;
  13. namespace EMIS.DataLogic.Common.Specialtyclass
  14. {
  15. public class GrademajorDAL
  16. {
  17. public GrademajorRepository GrademajorRepository { get; set; }
  18. public FacultymajorRepository FacultymajorRepository { get; set; }
  19. public ClassmajorRepository ClassmajorRepository { get; set; }
  20. public SchoolyearRepository SchoolyearRepository { get; set; }
  21. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  22. public StudentRepository StudentRepository { get; set; }
  23. public UserRepository UserRepository { get; set; }
  24. /// <summary>
  25. /// 查询对应的年级专业信息View
  26. /// </summary>
  27. /// <param name="exp"></param>
  28. /// <returns></returns>
  29. public IQueryable<GrademajorView> GetGrademajorViwQueryable(Expression<Func<CF_Grademajor, bool>> expGrademajor)
  30. {
  31. var query = from gr in GrademajorRepository.GetList(expGrademajor)
  32. select new GrademajorView
  33. {
  34. GrademajorID = gr.GrademajorID,
  35. Code = gr.Code,
  36. Name = gr.Name,
  37. Abbreviation = gr.Abbreviation,
  38. FacultymajorID = gr.CF_Facultymajor.FacultymajorID,
  39. FacultymajorCode = gr.CF_Facultymajor.Code,
  40. FacultymajorName = gr.CF_Facultymajor.Name,
  41. CampusID = gr.CF_Facultymajor.CF_College.CampusID,
  42. CampusNo = gr.CF_Facultymajor.CF_College.CF_Campus.No,
  43. CampusName = gr.CF_Facultymajor.CF_College.CF_Campus.Name,
  44. CollegeID = gr.CF_Facultymajor.CollegeID,
  45. CollegeCode = gr.CF_Facultymajor.CF_College.No,
  46. CollegeName = gr.CF_Facultymajor.CF_College.Name,
  47. SchoolyearID = gr.SchoolyearID,
  48. SchoolcodeID = gr.SchoolcodeID,
  49. StandardID = gr.CF_Facultymajor.StandardID,
  50. EducationID = gr.CF_Facultymajor.EducationID,
  51. LearningformID = gr.CF_Facultymajor.LearningformID,
  52. LearnSystem = gr.CF_Facultymajor.LearnSystem,
  53. GraduatingSemesterID = gr.GraduatingSemesterID,
  54. Value = gr.CF_Schoolyear.Value,
  55. GraduatingSemesterCode = gr.CF_Schoolyear.Code,
  56. Professional = gr.Professional,
  57. SchoolAreaID = gr.SchoolAreaID,
  58. Remark = gr.Remark,
  59. RecordStatus = gr.RecordStatus,
  60. CreateUserID = gr.CreateUserID,
  61. CreateTime = gr.CreateTime,
  62. ModifyUserID = gr.ModifyUserID,
  63. ModifyTime = gr.ModifyTime
  64. };
  65. return query;
  66. }
  67. /// <summary>
  68. /// 查询对应的年级专业信息View(统计对应的班级个数、学生人数)
  69. /// </summary>
  70. /// <param name="expGrademajor"></param>
  71. /// <param name="expStudent"></param>
  72. /// <returns></returns>
  73. public IQueryable<GrademajorView> GetGrademajorViwQueryable(Expression<Func<CF_Grademajor, bool>> expGrademajor,
  74. Expression<Func<CF_Student, bool>> expStudent)
  75. {
  76. var query = from gr in GrademajorRepository.GetList(expGrademajor)
  77. join cl in
  78. (
  79. from cl in ClassmajorRepository.Entities
  80. group cl by cl.GrademajorID into gcl
  81. select new
  82. {
  83. GrademajorID = gcl.Key,
  84. ClassmajorCount = gcl.Count()
  85. }
  86. )
  87. on gr.GrademajorID equals cl.GrademajorID into tempcl
  88. from clgr in tempcl.DefaultIfEmpty()
  89. join sc in
  90. (
  91. from sc in StudentRepository.GetList(expStudent)
  92. group sc by sc.CF_Classmajor.CF_Grademajor.GrademajorID into gstu
  93. select new
  94. {
  95. GrademajorID = gstu.Key,
  96. StudentCount = gstu.Count()
  97. }
  98. )
  99. on gr.GrademajorID equals sc.GrademajorID into tempstu
  100. from grstu in tempstu.DefaultIfEmpty()
  101. select new GrademajorView
  102. {
  103. GrademajorID = gr.GrademajorID,
  104. Code = gr.Code,
  105. Name = gr.Name,
  106. Abbreviation = gr.Abbreviation,
  107. FacultymajorID = gr.CF_Facultymajor.FacultymajorID,
  108. FacultymajorCode = gr.CF_Facultymajor.Code,
  109. FacultymajorName = gr.CF_Facultymajor.Name,
  110. CampusID = gr.CF_Facultymajor.CF_College.CampusID,
  111. CampusNo = gr.CF_Facultymajor.CF_College.CF_Campus.No,
  112. CampusName = gr.CF_Facultymajor.CF_College.CF_Campus.Name,
  113. CollegeID = gr.CF_Facultymajor.CollegeID,
  114. CollegeCode = gr.CF_Facultymajor.CF_College.No,
  115. CollegeName = gr.CF_Facultymajor.CF_College.Name,
  116. SchoolyearID = gr.SchoolyearID,
  117. SchoolcodeID = gr.SchoolcodeID,
  118. StandardID = gr.CF_Facultymajor.StandardID,
  119. EducationID = gr.CF_Facultymajor.EducationID,
  120. LearningformID = gr.CF_Facultymajor.LearningformID,
  121. LearnSystem = gr.CF_Facultymajor.LearnSystem,
  122. GraduatingSemesterID = gr.GraduatingSemesterID,
  123. Value = gr.CF_Schoolyear.Value,
  124. GraduatingSemesterCode = gr.CF_Schoolyear.Code,
  125. Professional = gr.Professional,
  126. ClassmajorCount = clgr.ClassmajorCount == null ? 0 : clgr.ClassmajorCount,
  127. StudentCount = grstu.StudentCount == null ? 0 : grstu.StudentCount,
  128. SchoolAreaID = gr.SchoolAreaID,
  129. Remark = gr.Remark,
  130. RecordStatus = gr.RecordStatus,
  131. CreateUserID = gr.CreateUserID,
  132. CreateTime = gr.CreateTime,
  133. ModifyUserID = gr.ModifyUserID,
  134. ModifyTime = gr.ModifyTime
  135. };
  136. return query;
  137. }
  138. /// <summary>
  139. /// 查询对应的年级专业信息GrademajorView(根据班级信息)
  140. /// </summary>
  141. /// <param name="exp"></param>
  142. /// <returns></returns>
  143. public IQueryable<GrademajorView> GetGrademajorViwByClassQueryable(Expression<Func<CF_Classmajor, bool>> expClassmajor)
  144. {
  145. var query = from gr in GrademajorRepository.Entities
  146. join cl in ClassmajorRepository.GetList(expClassmajor)
  147. on gr.GrademajorID equals cl.GrademajorID
  148. select new GrademajorView
  149. {
  150. GrademajorID = gr.GrademajorID,
  151. Code = gr.Code,
  152. Name = gr.Name,
  153. Abbreviation = gr.Abbreviation,
  154. FacultymajorID = gr.CF_Facultymajor.FacultymajorID,
  155. FacultymajorCode = gr.CF_Facultymajor.Code,
  156. FacultymajorName = gr.CF_Facultymajor.Name,
  157. CampusID = gr.CF_Facultymajor.CF_College.CampusID,
  158. CampusNo = gr.CF_Facultymajor.CF_College.CF_Campus.No,
  159. CampusName = gr.CF_Facultymajor.CF_College.CF_Campus.Name,
  160. CollegeID = gr.CF_Facultymajor.CollegeID,
  161. CollegeCode = gr.CF_Facultymajor.CF_College.No,
  162. CollegeName = gr.CF_Facultymajor.CF_College.Name,
  163. SchoolyearID = gr.SchoolyearID,
  164. SchoolcodeID = gr.SchoolcodeID,
  165. StandardID = gr.CF_Facultymajor.StandardID,
  166. EducationID = gr.CF_Facultymajor.EducationID,
  167. LearningformID = gr.CF_Facultymajor.LearningformID,
  168. LearnSystem = gr.CF_Facultymajor.LearnSystem,
  169. GraduatingSemesterID = gr.GraduatingSemesterID,
  170. Value = gr.CF_Schoolyear.Value,
  171. GraduatingSemesterCode = gr.CF_Schoolyear.Code,
  172. Professional = gr.Professional,
  173. SchoolAreaID = gr.SchoolAreaID,
  174. Remark = gr.Remark,
  175. RecordStatus = gr.RecordStatus,
  176. CreateUserID = gr.CreateUserID,
  177. CreateTime = gr.CreateTime,
  178. ModifyUserID = gr.ModifyUserID,
  179. ModifyTime = gr.ModifyTime
  180. };
  181. return query;
  182. }
  183. /// <summary>
  184. /// 查询对应的班级信息View(根据年级专业信息,统计各班级信息对应的学生人数)
  185. /// </summary>
  186. /// <param name="expGrademajor"></param>
  187. /// <param name="expStudent"></param>
  188. /// <returns></returns>
  189. public IQueryable<ClassmajorView> GetClassmajorViewQueryable(Expression<Func<CF_Grademajor, bool>> expGrademajor,
  190. Expression<Func<CF_Student, bool>> expStudent)
  191. {
  192. var query = from gr in GrademajorRepository.GetList(expGrademajor)
  193. join cl in ClassmajorRepository.Entities
  194. on gr.GrademajorID equals cl.GrademajorID
  195. join sc in
  196. (
  197. from sc in StudentRepository.GetList(expStudent)
  198. group sc by sc.CF_Classmajor.ClassmajorID into g
  199. select new
  200. {
  201. ClassmajorID = g.Key,
  202. StudentCount = g.Count()
  203. })
  204. on cl.ClassmajorID equals sc.ClassmajorID into dsc
  205. from esc in dsc.DefaultIfEmpty()
  206. join c in UserRepository.Entities
  207. on cl.UserID equals c.UserID into gu
  208. from guser in gu.DefaultIfEmpty()
  209. join d in UserRepository.Entities
  210. on cl.AssistantUserID equals d.UserID into ga
  211. from gassis in ga.DefaultIfEmpty()
  212. select new ClassmajorView
  213. {
  214. ClassmajorID = cl.ClassmajorID,
  215. No = cl.No,
  216. Name = cl.Name,
  217. Abbreviation = cl.Abbreviation,
  218. EnglishName = cl.EnglishName,
  219. ClassNum = cl.ClassNum,
  220. FacultymajorID = cl.CF_Grademajor.CF_Facultymajor.FacultymajorID,
  221. FacultymajorCode = cl.CF_Grademajor.CF_Facultymajor.Code,
  222. FacultymajorName = cl.CF_Grademajor.CF_Facultymajor.Name,
  223. GrademajorID = cl.GrademajorID,
  224. GrademajorCode = cl.CF_Grademajor.Code,
  225. GrademajorName = cl.CF_Grademajor.Name,
  226. CampusID = cl.CF_Grademajor.CF_Facultymajor.CF_College.CampusID,
  227. CampusNo = cl.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.No,
  228. CampusName = cl.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.Name,
  229. CollegeID = cl.CF_Grademajor.CF_Facultymajor.CollegeID,
  230. CollegeCode = cl.CF_Grademajor.CF_Facultymajor.CF_College.No,
  231. CollegeName = cl.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  232. SchoolyearID = cl.CF_Grademajor.SchoolyearID,
  233. SchoolcodeID = cl.CF_Grademajor.SchoolcodeID,
  234. StandardID = cl.CF_Grademajor.CF_Facultymajor.StandardID,
  235. EducationID = cl.CF_Grademajor.CF_Facultymajor.EducationID,
  236. LearningformID = cl.CF_Grademajor.CF_Facultymajor.LearningformID,
  237. LearnSystem = cl.CF_Grademajor.CF_Facultymajor.LearnSystem,
  238. GraduatingSemesterID = cl.CF_Grademajor.GraduatingSemesterID,
  239. Value = cl.CF_Grademajor.CF_Schoolyear.Value,
  240. GraduatingSemesterCode = cl.CF_Grademajor.CF_Schoolyear.Code,
  241. UserID = cl.UserID,
  242. UserName = guser.Name,
  243. AssistantUserID = cl.AssistantUserID,
  244. AssistantUserName = gassis.Name,
  245. Fixedclassroom = cl.Fixedclassroom,
  246. StudentCount = esc.StudentCount == null ? 0 : esc.StudentCount,
  247. Remark = cl.Remark,
  248. RecordStatus = cl.RecordStatus,
  249. CreateUserID = cl.CreateUserID,
  250. CreateTime = cl.CreateTime,
  251. ModifyUserID = cl.ModifyUserID,
  252. ModifyTime = cl.ModifyTime
  253. };
  254. return query;
  255. }
  256. /// <summary>
  257. /// 查询年级专业所对应的学生信息BaseStudentView
  258. /// </summary>
  259. /// <param name="expGrademajor"></param>
  260. /// <param name="exp"></param>
  261. /// <returns></returns>
  262. public IQueryable<BaseStudentView> GetBaseStudentViewQueryable(Expression<Func<CF_Grademajor, bool>> expGrademajor,
  263. Expression<Func<CF_Student, bool>> exp)
  264. {
  265. var query = from stu in StudentRepository.GetList(exp)
  266. join cl in ClassmajorRepository.Entities
  267. on stu.ClassmajorID equals cl.ClassmajorID
  268. join gr in GrademajorRepository.GetList(expGrademajor)
  269. on cl.GrademajorID equals gr.GrademajorID
  270. join fa in FacultymajorRepository.Entities
  271. on gr.FacultymajorID equals fa.FacultymajorID
  272. join us in UserRepository.Entities
  273. on stu.UserID equals us.UserID
  274. select new BaseStudentView
  275. {
  276. UserID = stu.UserID,
  277. LoginID = us.LoginID,
  278. UserName = us.Name,
  279. Sex = stu.Sex,
  280. IDNumber = stu.IDNumber,
  281. StudentStatus = stu.StudentStatus,
  282. InSchoolStatusID = stu.InSchoolStatusID,
  283. ClassmajorID = stu.ClassmajorID,
  284. ClassmajorCode = cl.No,
  285. ClassmajorName = cl.Name,
  286. ClassNum = cl.ClassNum == null ? 1 : cl.ClassNum,
  287. SchoolyearID = gr.SchoolyearID,
  288. GrademajorID = cl.GrademajorID,
  289. GrademajorCode = gr.Code,
  290. GrademajorName = gr.Name,
  291. FacultymajorID = gr.FacultymajorID,
  292. FacultymajorCode = fa.Code,
  293. FacultymajorName = fa.Name
  294. };
  295. return query;
  296. }
  297. /// <summary>
  298. /// 查询年级专业对应的专业信息StandardView(去重)
  299. /// </summary>
  300. /// <param name="exp"></param>
  301. /// <returns></returns>
  302. public IQueryable<StandardView> GetStandardQueryable(Expression<Func<CF_Grademajor, bool>> exp)
  303. {
  304. var query = from gr in GrademajorRepository.GetList(exp)
  305. join fa in FacultymajorRepository.Entities
  306. on gr.FacultymajorID equals fa.FacultymajorID
  307. join dicst in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_Standard.ToString())
  308. on fa.StandardID equals dicst.Value into tempst
  309. from standard in tempst.DefaultIfEmpty()
  310. select new StandardView
  311. {
  312. StandardID = fa.StandardID,
  313. StandardName = standard.Name
  314. };
  315. return query.Distinct();
  316. }
  317. /// <summary>
  318. /// 查询年级专业对应的专业信息StandardView(去重)
  319. /// </summary>
  320. /// <param name="exp"></param>
  321. /// <returns></returns>
  322. public IQueryable<GrademajorView> GetStandardQueryableExcludeNotHaveStudent(Expression<Func<CF_Grademajor, bool>> exp, Expression<Func<CF_Student, bool>> expStudent)
  323. {
  324. var query = from gr in GrademajorRepository.GetList(exp)
  325. join cl in ClassmajorRepository.Entities
  326. on gr.GrademajorID equals cl.GrademajorID
  327. join sc in
  328. (
  329. from sc in StudentRepository.GetList(expStudent)
  330. group sc by sc.CF_Classmajor.ClassmajorID into g
  331. select new
  332. {
  333. ClassmajorID = g.Key,
  334. StudentCount = g.Count()
  335. })
  336. on cl.ClassmajorID equals sc.ClassmajorID
  337. join fa in FacultymajorRepository.Entities
  338. on gr.FacultymajorID equals fa.FacultymajorID
  339. join dicst in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_Standard.ToString())
  340. on fa.StandardID equals dicst.Value into tempst
  341. from standard in tempst.DefaultIfEmpty()
  342. where sc.StudentCount>0
  343. select new GrademajorView
  344. {
  345. StandardID = gr.CF_Facultymajor.StandardID,
  346. StandardNameStr = standard.Name
  347. };
  348. return query.Distinct();
  349. }
  350. /// <summary>
  351. /// 查询年级专业对应的专业信息StandardView(联动专业下拉,去重)
  352. /// </summary>
  353. /// <param name="exp"></param>
  354. /// <returns></returns>
  355. public IQueryable<StandardView> GetStandardForComboGridQueryable(Expression<Func<CF_Grademajor, bool>> exp)
  356. {
  357. var query = from gr in GrademajorRepository.GetList(exp)
  358. join fa in FacultymajorRepository.Entities
  359. on gr.FacultymajorID equals fa.FacultymajorID
  360. join dicst in DictionaryItemRepository.GetList(x => x.DictionaryCode == DictionaryItem.CF_Standard.ToString())
  361. on fa.StandardID equals dicst.Value into tempst
  362. from standard in tempst.DefaultIfEmpty()
  363. select new StandardView
  364. {
  365. StandardID = fa.StandardID,
  366. StandardName = standard.Name
  367. };
  368. return query.Distinct();
  369. }
  370. /// <summary>
  371. /// 查询年级专业对应的年级信息SchoolyearView(联动专业下拉,去重)
  372. /// </summary>
  373. /// <param name="exp"></param>
  374. /// <returns></returns>
  375. public IQueryable<SchoolyearView> GetSchoolyearForComboGridQueryable(Expression<Func<CF_Grademajor, bool>> exp)
  376. {
  377. var query = from gr in GrademajorRepository.GetList(exp)
  378. select new SchoolyearView
  379. {
  380. SchoolyearID = gr.SchoolyearID == null ? "" : gr.SchoolyearID.Value.ToString()
  381. };
  382. return query.Distinct();
  383. }
  384. }
  385. }