ChargeAggregateDAL.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.ChargeManage.ChargeSituation;
  6. using EMIS.DataLogic.Repositories;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.ChargeManage.ChargeSituation
  11. {
  12. public class ChargeAggregateDAL
  13. {
  14. public StudentChargeRepository StudentChargeRepository { get; set; }
  15. public StudentChargePaymentRepository StudentChargePaymentRepository { get; set; }
  16. public ChargeDelayRepository ChargeDelayRepository { 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. /// 注:目前欠费金额的计算不包括通过缓交申请的缓交金额
  25. /// </summary>
  26. /// <param name="expStudentCharge"></param>
  27. /// <param name="expChargeDelay"></param>
  28. /// <param name="expStudent"></param>
  29. /// <returns></returns>
  30. public IQueryable<ChargeAggregateView> GetChargeAggregateView(Expression<Func<EC_StudentCharge, bool>> expStudentCharge,
  31. Expression<Func<EC_ChargeDelay, bool>> expChargeDelay, Expression<Func<CF_Student, bool>> expStudent)
  32. {
  33. var query = from sc in StudentChargeRepository.GetList(expStudentCharge)
  34. join stu in StudentRepository.GetList(expStudent)
  35. on sc.UserID equals stu.UserID
  36. join cl in ClassmajorRepository.Entities
  37. on stu.ClassmajorID equals cl.ClassmajorID
  38. join gr in GrademajorRepository.Entities
  39. on cl.GrademajorID equals gr.GrademajorID
  40. join fa in FacultymajorRepository.Entities
  41. on gr.FacultymajorID equals fa.FacultymajorID
  42. join us in UserRepository.Entities
  43. on sc.UserID equals us.UserID
  44. join head in UserRepository.Entities
  45. on cl.UserID equals head.UserID
  46. into temphead
  47. from headTea in temphead.DefaultIfEmpty()
  48. join stucp in
  49. (
  50. from cp in StudentChargePaymentRepository.Entities
  51. group cp by cp.StudentChargeID into g
  52. select new
  53. {
  54. StudentChargeID = g.Key,
  55. AmountCount = g.Sum(x => x.Amount)
  56. }
  57. )
  58. on sc.StudentChargeID equals stucp.StudentChargeID
  59. into tempcp
  60. from schcp in tempcp.DefaultIfEmpty()
  61. join stucd in
  62. (
  63. from cd in ChargeDelayRepository.GetList(expChargeDelay)
  64. group cd by cd.StudentChargeID into g
  65. select new
  66. {
  67. StudentChargeID = g.Key,
  68. DelayAmount = g.Sum(x => x.DelayAmount)
  69. }
  70. )
  71. on sc.StudentChargeID equals stucd.StudentChargeID
  72. into tempcd
  73. from schcdPass in tempcd.DefaultIfEmpty()
  74. select new ChargeAggregateView
  75. {
  76. StudentChargeID = sc.StudentChargeID,
  77. ChargeYear = sc.ChargeYear,
  78. ChargeProjectID = sc.ChargeProjectID,
  79. ChargeProjectName = sc.EC_ChargeProject.Name,
  80. Amount = sc.Amount,
  81. ChargeAmount = sc.ActualAmount - sc.Amount,
  82. ActualAmount = sc.ActualAmount,
  83. ChargeTag = sc.ChargeTag,
  84. UserID = sc.UserID,
  85. StudentNo = us.LoginID,
  86. ExamineeNum = stu.CF_Recruitstudents.ExamineeNum,
  87. UserName = us.Name,
  88. SexID = stu.SexID,
  89. IsDream = stu.CF_StudentProfile.IsDreamProject == true ? 1 : 0,
  90. InSchoolStatus = stu.InSchoolStatusID,
  91. StudentStatus = stu.StudentStatus,
  92. ClassID = stu.ClassmajorID,
  93. ClassNo = cl.No,
  94. ClassName = cl.Name,
  95. TeacherID = cl.UserID,
  96. TeacherNo = headTea.LoginID,
  97. TeacherName = headTea.Name,
  98. GradeStr = gr.GradeID,
  99. GradeMajorID = gr.GrademajorID,
  100. GradeMajorCode = gr.Code,
  101. GrademajorStr = gr.Name,
  102. CollegeID = fa.CollegeID,
  103. CollegeCode = fa.CF_College.No,
  104. CollegeStr = fa.CF_College.Name,
  105. StandardID = fa.StandardID,
  106. EducationID = fa.EducationID,
  107. LearningformID = fa.LearningformID,
  108. LearnSystem = fa.LearnSystem,
  109. DelayAmount = schcdPass.DelayAmount == null ? 0 : schcdPass.DelayAmount,
  110. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount,
  111. IsArrear = ((schcp.AmountCount == null ? 0 : schcp.AmountCount) - sc.ActualAmount) >= 0 ? 0 : 1,
  112. AmountSum = (sc.ActualAmount - (schcp.AmountCount == null ? 0 : schcp.AmountCount))
  113. };
  114. return query;
  115. }
  116. }
  117. }