PurchasingStatisticsDAL.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. namespace EMIS.DataLogic.Common.ProcurementPlan
  11. {
  12. public class PurchasingStatisticsDAL
  13. {
  14. public TeachersOrderRepository TeachersOrderRepository { get; set; }//教师征订
  15. public StudentsOrderRepository StudentsOrderRepository { get; set; }//学生征订
  16. public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; }//预加设置
  17. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  18. public UserRepository UserRepository { get; set; }
  19. public CoursematerialRepository CoursematerialRepository { get; set; }
  20. public PublishRepository PublishRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public CollegeRepository CollegeRepository { get; set; }
  23. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  24. /// <summary>
  25. /// 查询采购统计列表页面
  26. /// </summary>
  27. /// <param name="exporder"></param>
  28. /// <returns></returns>
  29. public IQueryable<PurchasingStatisticsView> GetPurchasingStatisticsGridView(Expression<Func<ET_TeachersOrder, bool>> exporder,
  30. Expression<Func<ET_StudentsOrder, bool>> stuExporder)
  31. {
  32. //1.0 教师征订数据
  33. var teachersOrderList = from a in TeachersOrderRepository.GetList(exporder)
  34. join b in TeachersPreOrderRepository.Entities on new { a.TeachingMaterialPoolID, a.SchoolyearID } equals new { b.TeachingMaterialPoolID, b.SchoolyearID }
  35. into tcls
  36. from tacls in tcls.DefaultIfEmpty()
  37. group new { a, tacls } by new
  38. {
  39. a.TeachingMaterialPoolID,
  40. a.SchoolyearID,
  41. tacls.PreQty
  42. } into h
  43. select new
  44. {
  45. TeachingMaterialPoolID = h.Key.TeachingMaterialPoolID,
  46. SchoolyearID = h.Key.SchoolyearID,
  47. OrderQty = h.Sum(x => x.a.OrderQty) + (h.Key.PreQty == null ? 0 : h.Key.PreQty) //教师征订有预加值、
  48. };
  49. //2.0 学生征订数据
  50. var studentsOrderList = from a in StudentsOrderRepository.GetList(stuExporder).Where(x => x.IsOrdered == true)
  51. select new
  52. {
  53. TeachingMaterialPoolID = (Guid)a.TeachingMaterialPoolID,
  54. SchoolyearID = (Guid)a.EM_SpecialtyPlan.SchoolyearID,
  55. OrderQty = a.OrderQty + (int)(a.PreIncreaseQty == null ? 0 : a.PreIncreaseQty)
  56. };
  57. //3.0 合并统计输出
  58. var view = (from to in teachersOrderList.Concat(studentsOrderList)
  59. join tm in TeachingMaterialPoolRepository.Entities on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  60. join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
  61. join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
  62. group new { to, tm, sl, p } by new
  63. {
  64. SchoolyearID = to.SchoolyearID,
  65. TeachingMaterialPoolID = to.TeachingMaterialPoolID,
  66. PublishID = tm.PublishID,
  67. Code = sl.Code,
  68. TeachingMaterialCode = tm.TeachingMaterialCode,
  69. TeachingMaterialTypeID = tm.TeachingMaterialTypeID,
  70. ISBN = tm.ISBN,
  71. TeachingMaterialName = tm.TeachingMaterialName,
  72. PublishTime = tm.PublishTime,
  73. UnitName = p.UnitName,
  74. Author = tm.Author,
  75. Price = tm.Price
  76. } into h
  77. join tm in TeachingMaterialPoolRepository.Entities on h.Key.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  78. select new PurchasingStatisticsView
  79. {
  80. SchoolyearID = h.Key.SchoolyearID,
  81. TeachingMaterialPoolID = h.Key.TeachingMaterialPoolID,
  82. CoursematerialEntityList = tm.EM_Coursematerial,
  83. TeachingMaterialTypeID = h.Key.TeachingMaterialTypeID,
  84. PublishID = h.Key.PublishID,
  85. SchoolyearName = h.Key.Code,
  86. TeachingMaterialCode = h.Key.TeachingMaterialCode,
  87. ISBN = h.Key.ISBN,
  88. TeachingMaterialName = h.Key.TeachingMaterialName,
  89. PublishTime = h.Key.PublishTime,
  90. PublishName = h.Key.UnitName,
  91. Author = h.Key.Author,
  92. Price = h.Key.Price,
  93. CountNumber = h.Sum(x => x.to.OrderQty)//累计同一教材征订数量
  94. });//教材ID、为关联信息
  95. return view;
  96. }
  97. }
  98. }