StudentsOrderDAL.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.TeachingMaterial;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.CultureplanManage.PlanManagement;
  11. using Bowin.Common.Linq;
  12. using EMIS.DataLogic.SystemDAL;
  13. using EMIS.Utility;
  14. using EMIS.DataLogic.StudentManage.StudentStatistics;
  15. namespace EMIS.DataLogic.Common.TeachingMaterial
  16. {
  17. public class StudentsOrderDAL
  18. {
  19. public StudentsOrderRepository StudentsOrderRepository { get; set; }
  20. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. public CoursematerialRepository CoursematerialRepository { get; set; }
  24. public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
  25. public CollegeRepository CollegeRepository { get; set; }
  26. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  27. public GrademajorRepository GrademajorRepository { get; set; }
  28. public FacultymajorRepository FacultymajorRepository { get; set; }
  29. public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
  30. public ClassmajorRepository ClassmajorRepository { get; set; }
  31. public PublishRepository PublishRepository { get; set; }
  32. public StaffRepository StaffRepository { get; set; }
  33. public DataRangeDAL DataRangeDAL { get; set; }
  34. public InSchoolSettingDAL InSchoolSettingDAL { get; set; }
  35. /// <summary>
  36. /// 获取学生征订信息列表
  37. /// </summary>
  38. /// <param name="exp"></param>
  39. /// <returns></returns>
  40. public IQueryable<StudentsOrderView> GetStudentsOrderGridView(Expression<Func<ET_StudentsOrder, bool>> exporder)
  41. {
  42. var inSchoolStatusIDList = InSchoolSettingDAL.InSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();//获取选中的在校设定状态、
  43. var view = (from sp in SpecialtyPlanRepository.GetList(x => true, (x => x.ET_StudentsOrder.Select(w => w.CF_TeachingMaterialPool)))
  44. join so in StudentsOrderRepository.GetList(exporder) on sp.SpecialtyPlanID equals so.SpecialtyPlanID
  45. join u in UserRepository.Entities on so.CreateUserID equals u.UserID
  46. join fdi in DictionaryItemRepository.Entities on new { sp.CF_Grademajor.CF_Facultymajor.StandardID, DictionaryCode = DictionaryItem.CF_Standard.ToString() }
  47. equals new { StandardID = fdi.Value, fdi.DictionaryCode } into tfdi
  48. from cfdi in tfdi.DefaultIfEmpty()
  49. join sct in DictionaryItemRepository.Entities on new { sp.CourseCategoryID, DictionaryCode = DictionaryItem.CF_CourseCategory.ToString() }
  50. equals new { CourseCategoryID = sct.Value, sct.DictionaryCode } into tsct
  51. from csct in tsct.DefaultIfEmpty()
  52. join sctt in DictionaryItemRepository.Entities on new { sp.CourseTypeID, DictionaryCode = DictionaryItem.CF_CourseType.ToString() }
  53. equals new { CourseTypeID = sctt.Value, sctt.DictionaryCode } into tsctt
  54. from csctt in tsctt.DefaultIfEmpty()
  55. join scq in DictionaryItemRepository.Entities on new { sp.CourseQualityID, DictionaryCode = DictionaryItem.CF_CourseQuality.ToString() }
  56. equals new { CourseQualityID = scq.Value, scq.DictionaryCode } into tscq
  57. from cscq in tscq.DefaultIfEmpty()
  58. select new StudentsOrderView
  59. {
  60. // StudentsOrderID = so.StudentsOrderID,
  61. SpecialtyPlanID = so.SpecialtyPlanID,
  62. SchoolyearID = sp.CF_Schoolyear.SchoolyearID,
  63. SchoolyearCode = sp.CF_Schoolyear.Code,
  64. CollegeID = sp.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID,
  65. CollegeName = sp.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  66. CollegeNo = sp.CF_Grademajor.CF_Facultymajor.CF_College.No,
  67. Years = sp.CF_Grademajor.GradeID,
  68. GradeID = sp.CF_Grademajor.GradeID,
  69. GrademajorCode = sp.CF_Grademajor.Code,
  70. GrademajorName = sp.CF_Grademajor.Name,
  71. GrademajorID = sp.GrademajorID,
  72. StandardID = sp.CF_Grademajor.CF_Facultymajor.StandardID,
  73. StandardName = cfdi.Name,
  74. //ClassNum = so.OrderQty,
  75. ClassNum = sp.CF_Grademajor.CF_Classmajor.Sum(x => x.CF_Student.Where(e => inSchoolStatusIDList.Contains(e.InSchoolStatusID)).Count()),//修改学生人数查询
  76. OrderQty = so.OrderQty,
  77. CourseCode = sp.EM_Coursematerial.CourseCode,
  78. CourseName = sp.EM_Coursematerial.CourseName,
  79. CourseCategoryID = sp.CourseCategoryID,
  80. CourseCategoryName = csct.Name,
  81. CourseTypeID = sp.CourseTypeID,
  82. CourseTypeName = csctt.Name,
  83. CourseQualityID = sp.CourseQualityID,
  84. CourseQualityName = cscq.Name,
  85. PreIncreaseQty = so.PreIncreaseQty == null ? 0 : so.PreIncreaseQty,
  86. CampusID = sp.CF_Grademajor.CF_Facultymajor.CF_College.CampusID,
  87. IsOrdered = so.IsOrdered,
  88. IsOrderedName = so.IsOrdered == true ? "是" : "否",
  89. TeachingMaterialPoolID = so.TeachingMaterialPoolID,
  90. CoursematerialID = sp.CoursematerialID,
  91. CF_TeachingMaterialPool = so.CF_TeachingMaterialPool,
  92. CreateTime = so.CreateTime,
  93. CreateUserNo = u.LoginID,
  94. CreateUserName = u.Name,
  95. Count = so.OrderQty + (so.PreIncreaseQty == null ? 0 : so.PreIncreaseQty)
  96. });
  97. return view.GroupBy(x => x.SpecialtyPlanID).Select(x => x.FirstOrDefault());
  98. }
  99. /// <summary>
  100. /// 教材信息
  101. /// </summary>
  102. /// <param name="specialtyPlanID"></param>
  103. /// <returns></returns>
  104. public IQueryable<SpecialtyPlanTeachingMaterPoolView> GetSpecialtyPlanTeachingMaterPoolView(Expression<Func<ET_StudentsOrder, bool>> exp, Expression<Func<EM_SpecialtyPlan, bool>> expSp)
  105. {
  106. var view = (from so in StudentsOrderRepository.GetList(exp)
  107. join sp in SpecialtyPlanRepository.GetList(expSp)
  108. on so.SpecialtyPlanID equals sp.SpecialtyPlanID
  109. select new SpecialtyPlanTeachingMaterPoolView
  110. {
  111. TeachingMaterialCode = so.CF_TeachingMaterialPool.TeachingMaterialCode,
  112. TeachingMaterialName = so.CF_TeachingMaterialPool.TeachingMaterialName,
  113. SpecialtyPlanID = so.SpecialtyPlanID
  114. });
  115. return view;
  116. }
  117. public IList<StudentOrderPrePlanView> GetStudentsOrderIDsBySpecialtyPlan(Guid schoolyearID)
  118. {
  119. var planList = (from sd in StudentsOrderRepository.Entities.Where(x => x.IsOrdered == false && x.TeachingMaterialPoolID == null)
  120. join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sd.EM_SpecialtyPlan.SchoolyearID equals sy.SchoolyearID
  121. select new StudentOrderPrePlanView
  122. {
  123. SpecialtyPlanID = sd.SpecialtyPlanID
  124. });
  125. return planList.ToList();
  126. }
  127. public IList<StudentOrderPrePlanView> GetSpecialtyPlanBySchool(Guid schoolyearID)
  128. {
  129. var planList = from s in SpecialtyPlanRepository.Entities.Where(x => x.SchoolyearID == schoolyearID)
  130. select new StudentOrderPrePlanView
  131. {
  132. SpecialtyPlanID = s.SpecialtyPlanID
  133. };
  134. return planList.ToList();
  135. }
  136. /// <summary>
  137. /// 获取专业计划对应的需要征订的信息
  138. /// </summary>
  139. /// <param name="exp"></param>
  140. /// <returns></returns>
  141. public IQueryable<StudentOrderPrePlanView> GetStudentsOrderBySpecialtyPlan(Guid schoolyearID)
  142. {
  143. var inSchoolStatusIDList = InSchoolSettingDAL.InSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();//获取选中的在校设定状态、
  144. #region 0.0 废弃
  145. //var planList = (from sp in SpecialtyPlanRepository.Entities.Where(x => x.IsNeedMaterial == true)
  146. // join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sp.SchoolyearID equals sy.SchoolyearID
  147. // join gj in GrademajorRepository.Entities on sp.GrademajorID equals gj.GrademajorID
  148. // join sc in SpecialtyCourseRepository.Entities on sp.SpecialtyCourseID equals sc.SpecialtyCourseID
  149. // join cj in ClassmajorRepository.Entities on gj.GrademajorID equals cj.GrademajorID into tcj
  150. // from ccj in tcj.DefaultIfEmpty()
  151. // join tlpv in
  152. // (
  153. // from tlp in
  154. // (
  155. // from gtlp in TeachingMaterialPoolRepository.Entities.Where(x => x.IsLate != true)
  156. // group gtlp by gtlp.CoursematerialID into g
  157. // select new { CoursematerialID = g.Key, MaxDate = g.Max(x => x.CreateTime) }
  158. // )
  159. // join tlpo in TeachingMaterialPoolRepository.Entities.Where(x => x.IsLate != true)
  160. // on new { tlp.CoursematerialID, tlp.MaxDate } equals new { tlpo.CoursematerialID, MaxDate = tlpo.CreateTime }
  161. // select tlpo
  162. // ) on sc.CoursematerialID equals tlpv.CoursematerialID into ttlpv
  163. // from ctlpv in ttlpv.DefaultIfEmpty()
  164. // join so in StudentsOrderRepository.Entities on sp.SpecialtyPlanID equals so.SpecialtyPlanID into tso
  165. // from cso in tso.DefaultIfEmpty()
  166. // where cso == null // || cso.IsOrdered==true //如果已经提交征订、那么可以再次征订
  167. // group new { sp, sd = ccj.CF_Student, ctlpv }
  168. // by new { sp.SpecialtyPlanID, ctlpv.TeachingMaterialPoolID } into g
  169. // select new StudentOrderPrePlanView
  170. // {
  171. // SpecialtyPlanID = g.Key.SpecialtyPlanID,
  172. // OrderQty = g.Sum(x => x.sd.Count),
  173. // TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID
  174. // });
  175. //var planListinfo = planList;
  176. //return planList.ToList(); ;
  177. #endregion
  178. // var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  179. Expression<Func<EM_SpecialtyPlan, bool>> exp = x => x.IsNeedMaterial == true;
  180. var planList = (from sp in SpecialtyPlanRepository.GetList(exp)
  181. join sy in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyearID) on sp.SchoolyearID equals sy.SchoolyearID
  182. join gj in GrademajorRepository.Entities on sp.GrademajorID equals gj.GrademajorID
  183. join cj in ClassmajorRepository.Entities on sp.GrademajorID equals cj.GrademajorID into tcj
  184. from ccj in tcj.DefaultIfEmpty()
  185. from ctlpv in sp.EM_Coursematerial.CF_TeachingMaterialPool.Where(x => x.IsLate == false).DefaultIfEmpty()//只获取没过期的教材
  186. join so in StudentsOrderRepository.Entities on sp.SpecialtyPlanID equals so.SpecialtyPlanID into tso
  187. from cso in tso.DefaultIfEmpty()
  188. where cso == null
  189. group new { sp, ccj, ctlpv }
  190. by new { sp.SpecialtyPlanID, ctlpv.TeachingMaterialPoolID, sp.CF_Grademajor.CF_Facultymajor.CollegeID } into g
  191. select new StudentOrderPrePlanView
  192. {
  193. CollegeID = g.Key.CollegeID,
  194. SpecialtyPlanID = g.Key.SpecialtyPlanID,
  195. OrderQty = g.Sum(x => x.ccj.CF_Student.Where(e => inSchoolStatusIDList.Contains(e.InSchoolStatusID)).Count()),//只获取在校学生
  196. TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID
  197. });
  198. return planList;
  199. }
  200. /// <summary>
  201. /// 根据征订ID获取征订数据
  202. /// </summary>
  203. /// <param name="studentsOrderIDs"></param>
  204. /// <returns></returns>
  205. public IList<ET_StudentsOrder> GetStudentsOrderListByStudentsOrderIDs(List<Guid> studentsOrderIDs)
  206. {
  207. return StudentsOrderRepository.GetList(x => studentsOrderIDs.Contains(x.StudentsOrderID)).ToList();
  208. }
  209. /// <summary>
  210. /// 学生征订统计
  211. /// </summary>
  212. /// <param name="exp"></param>
  213. /// <returns></returns>
  214. public IQueryable<StudentsOrderDataReportView> GetStudentsOrderStatisticalView(Expression<Func<ET_StudentsOrder, bool>> exporder)
  215. {
  216. var view = (from so in StudentsOrderRepository.GetList(exporder)
  217. join sp in SpecialtyPlanRepository.Entities on so.SpecialtyPlanID equals sp.SpecialtyPlanID
  218. join sy in SchoolyearRepository.Entities on sp.SchoolyearID equals sy.SchoolyearID
  219. join gj in GrademajorRepository.Entities on sp.GrademajorID equals gj.GrademajorID
  220. join fj in FacultymajorRepository.Entities on gj.FacultymajorID equals fj.FacultymajorID
  221. join co in CollegeRepository.Entities on fj.CollegeID equals co.CollegeID
  222. join cos in CoursematerialRepository.Entities on sp.CoursematerialID equals cos.CoursematerialID
  223. join u in UserRepository.Entities on so.CreateUserID equals u.UserID
  224. join tmp in TeachingMaterialPoolRepository.Entities on so.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID
  225. into teps
  226. from Tep in teps.DefaultIfEmpty()
  227. join p in PublishRepository.Entities on Tep.PublishID equals p.PublishID
  228. into TepPublish
  229. from pb in TepPublish.DefaultIfEmpty()
  230. join cj in ClassmajorRepository.Entities on gj.GrademajorID equals cj.GrademajorID into tcj
  231. from ccj in tcj.DefaultIfEmpty()
  232. select new StudentsOrderDataReportView
  233. {
  234. SchoolyearID = sy.SchoolyearID,
  235. SchoolyearCode = sy.Code,
  236. CollegeID = co.CollegeID,
  237. CollegeName = co.Name,
  238. GrademajorCode = gj.Code,
  239. GrademajorName = gj.Name,
  240. GrademajorID = gj.GrademajorID,
  241. GradeID = gj.GradeID,
  242. SpecialtyValue = gj.CF_Facultymajor.StandardID,
  243. ClassNum = so.OrderQty,
  244. OrderQty = so.OrderQty,
  245. PreIncreaseQty = so.PreIncreaseQty,
  246. CourseCode = cos.CourseCode,
  247. CourseName = cos.CourseName,
  248. CampusID = co.CampusID,
  249. CoursematerialID = cos.CoursematerialID,
  250. TeachingMaterialCode = Tep.TeachingMaterialCode,
  251. TeachingMaterialName = Tep.TeachingMaterialName,
  252. Author = Tep.Author,
  253. ISBN = Tep.ISBN,
  254. TeachingMaterialPoolID = Tep.TeachingMaterialPoolID,
  255. PublishName = pb.UnitName,
  256. PublishTime = Tep.PublishTime,
  257. PublishID = Tep.PublishID,
  258. CreateTime = so.CreateTime,
  259. CreateUserName = u.Name,
  260. IsOrdered = so.IsOrdered,
  261. Price = Tep.Price ?? 0,
  262. Years = sp.CF_Grademajor.GradeID,
  263. TeachingMaterialTypeID = Tep.TeachingMaterialTypeID ?? 0,
  264. CourseCategory = sp.CourseCategoryID,
  265. Count = so.OrderQty + (so.PreIncreaseQty == null ? 0 : so.PreIncreaseQty)
  266. });
  267. return view.Distinct();
  268. }
  269. }
  270. }