ChargeTotalDAL.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using EMIS.DataLogic.Repositories;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel.ChargeManage.ChargeTotal;
  9. namespace EMIS.DataLogic.ChargeManage.ChargeTotal
  10. {
  11. public class ChargeTotalDAL
  12. {
  13. public StudentChargeRepository StudentChargeRepository { get; set; }
  14. public StudentChargePaymentRepository StudentChargePaymentRepository { get; set; }
  15. public ChargeDelayRepository ChargeDelayRepository { get; set; }
  16. public ChargeProjectRepository ChargeProjectRepository { get; set; }
  17. public StudentRepository StudentRepository { get; set; }
  18. public UserRepository UserRepository { get; set; }
  19. public ClassmajorRepository ClassmajorRepository { get; set; }
  20. public GrademajorRepository GrademajorRepository { get; set; }
  21. public FacultymajorRepository FacultymajorRepository { get; set; }
  22. /// <summary>
  23. /// 查询对应的费用统计信息View(以班级信息、缴费学年、收费项目分组统计)
  24. /// </summary>
  25. /// <param name="expStudentCharge"></param>
  26. /// <param name="expChargeDelay"></param>
  27. /// <param name="expStudent"></param>
  28. /// <returns></returns>
  29. public IQueryable<ChargeTotalView> GetChargeTotalView(Expression<Func<EC_StudentCharge, bool>> expStudentCharge,
  30. Expression<Func<EC_ChargeDelay, bool>> expChargeDelay, Expression<Func<CF_Student, bool>> expStudent)
  31. {
  32. var query = from g in
  33. (
  34. from stucharge in
  35. (
  36. from sc in StudentChargeRepository.GetList(expStudentCharge)
  37. join stu in StudentRepository.GetList(expStudent)
  38. on sc.UserID equals stu.UserID
  39. join stucd in
  40. (
  41. from cd in ChargeDelayRepository.GetList(expChargeDelay)
  42. group cd by cd.StudentChargeID into g
  43. select new
  44. {
  45. StudentChargeID = g.Key,
  46. DelayAmount = g.Sum(x => x.DelayAmount)
  47. }
  48. )
  49. on sc.StudentChargeID equals stucd.StudentChargeID
  50. into tempcd
  51. from schcdPass in tempcd.DefaultIfEmpty()
  52. join stucp in
  53. (
  54. from cp in StudentChargePaymentRepository.Entities
  55. group cp by cp.StudentChargeID into g
  56. select new
  57. {
  58. StudentChargeID = g.Key,
  59. PaymenAmount = g.Sum(x => x.Amount)
  60. }
  61. )
  62. on sc.StudentChargeID equals stucp.StudentChargeID
  63. into tempcp
  64. from schcpgr in tempcp.DefaultIfEmpty()
  65. select new
  66. {
  67. StudentChargeID = sc.StudentChargeID,
  68. UserID = sc.UserID,
  69. SexID = stu.SexID,
  70. ClassmajorID = stu.ClassmajorID,
  71. InSchoolStatusID = stu.InSchoolStatusID,
  72. StudentStatus = stu.StudentStatus,
  73. ChargeYear = sc.ChargeYear,
  74. ChargeProjectID = sc.ChargeProjectID,
  75. ChargeTag = sc.ChargeTag,
  76. Amount = sc.Amount,
  77. ChargeAmount = sc.ActualAmount - sc.Amount,
  78. ActualAmount = sc.ActualAmount,
  79. DelayCount = schcdPass.StudentChargeID == null ? 0 : 1,
  80. DelayAmount = schcdPass.DelayAmount ?? 0,
  81. PaymenCount = schcpgr.StudentChargeID == null ? 0 : 1,
  82. PaymenAmount = schcpgr.PaymenAmount ?? 0
  83. }
  84. )
  85. group stucharge by
  86. new { stucharge.ClassmajorID, stucharge.ChargeYear, stucharge.ChargeProjectID }
  87. into gr
  88. select new
  89. {
  90. ClassmajorID = gr.Key.ClassmajorID,
  91. ChargeYear = gr.Key.ChargeYear,
  92. ChargeProjectID = gr.Key.ChargeProjectID,
  93. ChargeCount = gr.Count(),
  94. Amount = gr.Sum(x => x.Amount),
  95. ChargeAmount = gr.Sum(x => x.ChargeAmount),
  96. ActualAmount = gr.Sum(x => x.ActualAmount),
  97. DelayCount = gr.Sum(x => x.DelayCount),
  98. DelayAmount = gr.Sum(x => x.DelayAmount),
  99. PaymenCount = gr.Sum(x => x.PaymenCount),
  100. PaymenAmount = gr.Sum(x => x.PaymenAmount)
  101. }
  102. )
  103. join pr in ChargeProjectRepository.Entities
  104. on g.ChargeProjectID equals pr.ChargeProjectID
  105. join cl in ClassmajorRepository.Entities
  106. on g.ClassmajorID equals cl.ClassmajorID
  107. join gr in GrademajorRepository.Entities
  108. on cl.GrademajorID equals gr.GrademajorID
  109. join fa in FacultymajorRepository.Entities
  110. on gr.FacultymajorID equals fa.FacultymajorID
  111. join head in UserRepository.Entities
  112. on cl.UserID equals head.UserID
  113. into temphead
  114. from headTea in temphead.DefaultIfEmpty()
  115. select new ChargeTotalView
  116. {
  117. ClassID = g.ClassmajorID,
  118. ClassNo = cl.No,
  119. ClassName = cl.Name,
  120. GradeMajorID = cl.GrademajorID,
  121. GradeMajorCode = gr.Code,
  122. GradeMajoyStr = gr.Name,
  123. CollegeID = fa.CollegeID,
  124. CollegeCode = fa.CF_College.No,
  125. CollegeStr = fa.CF_College.Name,
  126. Grade = gr.GradeID,
  127. StandardID = fa.StandardID,
  128. EducationID = fa.EducationID,
  129. LearningformID = fa.LearningformID,
  130. LearnSystem = fa.LearnSystem,
  131. ChargeYear = g.ChargeYear,
  132. ChargeProjectID = g.ChargeProjectID,
  133. ChargeProjectStr = pr.Name,
  134. ChargeCount = g.ChargeCount,
  135. Amount = g.Amount,
  136. ChargeAmount = g.ChargeAmount,
  137. ActualAmount = g.ActualAmount,
  138. DelayCount = g.DelayCount,
  139. DelayAmount = g.DelayAmount,
  140. PaymenCount = g.PaymenCount,
  141. PaymenAmount = g.PaymenAmount,
  142. TeacherID = cl.UserID,
  143. TeacherNo = headTea.LoginID,
  144. TeacherName = headTea.Name,
  145. };
  146. return query;
  147. }
  148. }
  149. }