BuildingsInfoDAL.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using EMIS.Entities;
  7. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  8. using EMIS.DataLogic.Repositories;
  9. namespace EMIS.DataLogic.UniversityManage.ClassroomManage
  10. {
  11. public class BuildingsInfoDAL
  12. {
  13. public BuildingsInfoRepository BuildingsInfoRepository { get; set; }
  14. public ClassroomRepository ClassroomRepository { get; set; }
  15. public ClassroomReserveRepository ClassroomReserveRepository { get; set; }
  16. public CollegeClassroomRepository CollegeClassroomRepository { get; set; }
  17. public CampusRepository CampusRepository { get; set; }
  18. public CollegeRepository CollegeRepository { get; set; }
  19. /// <summary>
  20. /// 查询对应的建筑信息View(统计对应的教室数量)
  21. /// </summary>
  22. /// <param name="exp"></param>
  23. /// <returns></returns>
  24. public IQueryable<BuildingsInfoView> GetBuildingsInfoViewQueryable(Expression<Func<CF_BuildingsInfo, bool>> exp)
  25. {
  26. var query = from a in BuildingsInfoRepository.GetList(exp)
  27. join cr in
  28. (
  29. from cr in ClassroomRepository.Entities
  30. group cr by cr.BuildingsInfoID into gcr
  31. select new
  32. {
  33. BuildingsInfoID = gcr.Key,
  34. ClassroomCount = gcr.Count()
  35. }
  36. )
  37. on a.BuildingsInfoID equals cr.BuildingsInfoID into tempcr
  38. from bicr in tempcr.DefaultIfEmpty()
  39. select new BuildingsInfoView
  40. {
  41. BuildingsInfoID = a.BuildingsInfoID,
  42. Code = a.Code,
  43. Name = a.Name,
  44. CampusID = a.CF_Campus.CampusID,
  45. CampusCode = a.CF_Campus.No,
  46. CampusName = a.CF_Campus.Name,
  47. CollegeID = a.CF_College.CollegeID,
  48. CollegeCode = a.CF_College.No,
  49. CollegeName = a.CF_College.Name,
  50. CollegeCampusID = a.CF_College.CampusID,
  51. CollegeCampusCode = a.CF_College.CF_Campus.No,
  52. CollegeCampusName = a.CF_College.CF_Campus.Name,
  53. BuildingsTypeID = a.BuildingsTypeID,
  54. BuildingsStatusID = a.BuildingsStatusID,
  55. BuildingsLevel = a.BuildingsLevel,
  56. BuildingsArea = a.BuildingsArea,
  57. UseArea = a.UseArea,
  58. Position = a.Position,
  59. IsSpecial = a.IsSpecial ?? false,
  60. ClassroomCount = bicr.ClassroomCount == null ? 0 : bicr.ClassroomCount,
  61. Remark = a.Remark,
  62. RecordStatus = a.RecordStatus,
  63. CreateUserID = a.CreateUserID,
  64. CreateTime = a.CreateTime,
  65. ModifyUserID = a.ModifyUserID,
  66. ModifyTime = a.ModifyTime
  67. };
  68. return query;
  69. }
  70. /// <summary>
  71. /// 查询教室信息View(根据建筑信息查询,关联排课中教室预留信息、统计排课分配的院系个数)
  72. /// </summary>
  73. /// <param name="expBuildingsInfo"></param>
  74. /// <returns></returns>
  75. public IQueryable<ClassroomView> GetClassroomViewQueryable(Expression<Func<CF_BuildingsInfo, bool>> expBuildingsInfo)
  76. {
  77. var query = from bi in BuildingsInfoRepository.GetList(expBuildingsInfo)
  78. join cr in ClassroomRepository.Entities
  79. on bi.BuildingsInfoID equals cr.BuildingsInfoID
  80. join re in ClassroomReserveRepository.Entities
  81. on cr.ClassroomID equals re.ClassroomID into tempre
  82. from crre in tempre.DefaultIfEmpty()
  83. join cc in
  84. (
  85. from cc in CollegeClassroomRepository.Entities
  86. group cc by cc.ClassroomID into gcr
  87. select new
  88. {
  89. ClassroomID = gcr.Key,
  90. ScheduleCollegeCount = gcr.Count()
  91. }
  92. )
  93. on cr.ClassroomID equals cc.ClassroomID into tempcc
  94. from colcr in tempcc.DefaultIfEmpty()
  95. select new ClassroomView
  96. {
  97. ClassroomID = cr.ClassroomID,
  98. Code = cr.Code,
  99. Name = cr.Name,
  100. BuildingsInfoID = bi.BuildingsInfoID,
  101. BuildingsInfoCode = bi.Code,
  102. BuildingsInfoName = bi.Name,
  103. CampusID = bi.CampusID,
  104. CampusCode = bi.CF_Campus.No,
  105. CampusName = bi.CF_Campus.Name,
  106. CollegeID = cr.CollegeID,
  107. CollegeCode = cr.CF_College.No,
  108. CollegeName = cr.CF_College.Name,
  109. CollegeCampusID = cr.CF_College.CampusID,
  110. CollegeCampusCode = cr.CF_College.CF_Campus.No,
  111. CollegeCampusName = cr.CF_College.CF_Campus.Name,
  112. CF_ClassroomType = cr.CF_ClassroomType,
  113. ClassroomTypeIDList = cr.CF_ClassroomType.Select(x => x.ClassroomType).ToList(),
  114. LayoutTypeID = cr.LayoutTypeID,
  115. RoomUseID = cr.RoomUseID,
  116. FloorLevel = cr.FloorLevel,
  117. Acreage = cr.Acreage,
  118. RowCout = cr.RowCout,
  119. ColumnCount = cr.ColumnCount,
  120. Totalseating = cr.Totalseating,
  121. Effectiveseating = cr.Effectiveseating,
  122. Examinationseating = cr.Examinationseating,
  123. IsWrittenExam = cr.IsWrittenExam ?? false,
  124. IsMachinetest = cr.IsMachinetest ?? false,
  125. IsConcurrentUse = cr.IsConcurrentUse ?? false,
  126. IsReserve = crre.IsReserved == true ? true : false,
  127. IsAvailable = cr.IsAvailable ?? false,
  128. ScheduleCollegeCount = colcr.ScheduleCollegeCount == null ? 0 : colcr.ScheduleCollegeCount,
  129. Remark = cr.Remark,
  130. RecordStatus = cr.RecordStatus,
  131. CreateUserID = cr.CreateUserID,
  132. CreateTime = cr.CreateTime,
  133. ModifyUserID = cr.ModifyUserID,
  134. ModifyTime = cr.ModifyTime
  135. };
  136. return query;
  137. }
  138. }
  139. }