ChargeControlDAL.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.ChargeManage.ArrearsSituation;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.ChargeManage.ArrearsSituation
  11. {
  12. public class ChargeControlDAL
  13. {
  14. public StudentChargeRepository StudentChargeRepository { get; set; }
  15. public StudentChargePaymentRepository StudentChargePaymentRepository { get; set; }
  16. public PassStudentRepository PassStudentRepository { 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(左连缴费信息表,只查询欠费金额大于0的欠费信息,不需考虑相应的缓交信息)
  24. /// 注:目前欠费金额的计算不包括通过缓交申请的缓交金额
  25. /// </summary>
  26. /// <param name="expStudentCharge"></param>
  27. /// <returns></returns>
  28. public IQueryable<ArrearsListView> GetArrearListViewAble(Expression<Func<EC_StudentCharge, bool>> expStudentCharge)
  29. {
  30. var query = from stugr in
  31. (
  32. from gr in
  33. (
  34. from sc in StudentChargeRepository.GetList(expStudentCharge)
  35. join stucp in
  36. (
  37. from cp in StudentChargePaymentRepository.Entities
  38. group cp by cp.StudentChargeID into g
  39. select new
  40. {
  41. StudentChargeID = g.Key,
  42. PaymentAmount = g.Sum(x => x.Amount)
  43. }
  44. )
  45. on sc.StudentChargeID equals stucp.StudentChargeID
  46. into tempcp
  47. from schcp in tempcp.DefaultIfEmpty()
  48. select new
  49. {
  50. StudentChargeID = sc.StudentChargeID,
  51. UserID = sc.UserID,
  52. ChargeYear = sc.ChargeYear,
  53. ChargeProjectID = sc.ChargeProjectID,
  54. Amount = sc.Amount,
  55. ChargeAmount = sc.ActualAmount - sc.Amount,
  56. ActualAmount = sc.ActualAmount,
  57. PaymentAmount = schcp.PaymentAmount ?? 0
  58. }
  59. )
  60. group gr by gr.UserID into g
  61. select new
  62. {
  63. UserID = g.Key,
  64. Amount = g.Sum(x => x.Amount),
  65. ChargeAmount = g.Sum(x => x.ChargeAmount),
  66. ActualAmount = g.Sum(x => x.ActualAmount),
  67. PaymentAmount = g.Sum(x => x.PaymentAmount)
  68. }
  69. )
  70. join stu in StudentRepository.Entities
  71. on stugr.UserID equals stu.UserID
  72. join cl in ClassmajorRepository.Entities
  73. on stu.ClassmajorID equals cl.ClassmajorID
  74. join gr in GrademajorRepository.Entities
  75. on cl.GrademajorID equals gr.GrademajorID
  76. join fa in FacultymajorRepository.Entities
  77. on gr.FacultymajorID equals fa.FacultymajorID
  78. join us in UserRepository.Entities
  79. on stu.UserID equals us.UserID
  80. join pass in PassStudentRepository.Entities
  81. on stugr.UserID equals pass.UserID
  82. into temppass
  83. from stuPass in temppass.DefaultIfEmpty()
  84. where (stugr.ActualAmount - stugr.PaymentAmount) > 0
  85. select new ArrearsListView
  86. {
  87. UserID = stugr.UserID,
  88. StudentNo = us.LoginID,
  89. UserName = us.Name,
  90. SexID = stu.SexID,
  91. InSchoolStatus = stu.InSchoolStatusID,
  92. StudentStatus = stu.StudentStatus,
  93. ClassID = stu.ClassmajorID,
  94. ClassNo = cl.No,
  95. ClassName = cl.Name,
  96. GradeMajorID = cl.GrademajorID,
  97. GradeMajorCode = gr.Code,
  98. GrademajorStr = gr.Name,
  99. GradeStr = gr.GradeID,
  100. CollegeID = fa.CollegeID,
  101. CollegeCode = fa.CF_College.No,
  102. CollegeStr = fa.CF_College.Name,
  103. StandardID = fa.StandardID,
  104. EducationID = fa.EducationID,
  105. LearningformID = fa.LearningformID,
  106. LearnSystem = fa.LearnSystem,
  107. Amount = stugr.Amount,
  108. ChargeAmount = stugr.ChargeAmount,
  109. ActualAmount = stugr.ActualAmount,
  110. PaidAmount = stugr.PaymentAmount,
  111. IsArrear = (stugr.PaymentAmount - stugr.ActualAmount) >= 0 ? 0 : 1,
  112. AmountSum = stugr.ActualAmount - stugr.PaymentAmount,
  113. IsControl = stuPass.UserID == null ? 1 : 0
  114. };
  115. return query;
  116. }
  117. /// <summary>
  118. /// 查询对应的控制放行信息View
  119. /// </summary>
  120. /// <param name="exp"></param>
  121. /// <returns></returns>
  122. public IQueryable<PassStudentView> GetPassStudentViewAble(Expression<Func<EC_PassStudent, bool>> exp)
  123. {
  124. var query = from stuPass in PassStudentRepository.GetList(exp)
  125. join us in UserRepository.Entities
  126. on stuPass.UserID equals us.UserID
  127. select new PassStudentView
  128. {
  129. PassStudentID = stuPass.PassStudentID,
  130. UserID = stuPass.UserID,
  131. LoginID = us.LoginID,
  132. Name = us.Name,
  133. Remark = stuPass.Remark,
  134. RecordStatus = stuPass.RecordStatus,
  135. CreateUserID = stuPass.CreateUserID,
  136. CreateTime = stuPass.CreateTime,
  137. ModifyUserID = stuPass.ModifyUserID,
  138. ModifyTime = stuPass.ModifyTime
  139. };
  140. return query;
  141. }
  142. /// <summary>
  143. /// 此处有误,后续修复。。。
  144. /// </summary>
  145. /// <param name="exp"></param>
  146. /// <returns></returns>
  147. public IQueryable<ArrearsListView> GetReatkePlanListViewAble(Expression<Func<EC_StudentCharge, bool>> exp)
  148. {
  149. var query = from a in StudentChargeRepository.GetList(exp)
  150. join b in StudentChargePaymentRepository.Entities
  151. on a.StudentChargeID equals b.StudentChargeID
  152. into c
  153. from p in c.DefaultIfEmpty()
  154. where (a.ActualAmount - (p.Amount == null ? 0 : p.Amount)) > 0 || (a.ActualAmount == 0 && a.Amount == 0)
  155. select new ArrearsListView
  156. {
  157. StudentChargeID = a.StudentChargeID,
  158. UserName = a.CF_Student.Sys_User.Name,
  159. StudentNo = a.CF_Student.Sys_User.LoginID,
  160. ClassName = a.CF_Student.CF_Classmajor.Name,
  161. UserID = a.UserID,
  162. AmountSum = a.ActualAmount - (p.Amount == null ? 0 : p.Amount)
  163. };
  164. return query;
  165. }
  166. /// <summary>
  167. /// 此处有误,后续修复。。。
  168. /// </summary>
  169. /// <param name="exp"></param>
  170. /// <param name="year"></param>
  171. /// <returns></returns>
  172. public IQueryable<decimal> GetRetakeArrearsAmountView(Expression<Func<CF_Student, bool>> exp, int year)
  173. {
  174. var query = from student in StudentRepository.GetList(exp)
  175. join charge in StudentChargeRepository.GetList(x => x.ChargeTag == (int)EC_ChargeTag.Retake)
  176. on new { UserID = (Guid?)student.UserID, ChargeYear = (int?)year } equals new { charge.UserID, charge.ChargeYear }
  177. into dcharge
  178. from charge in dcharge.DefaultIfEmpty()
  179. join payment in StudentChargePaymentRepository.Entities on charge.StudentChargeID equals payment.StudentChargeID
  180. into dpayment
  181. from payment in dpayment.DefaultIfEmpty()
  182. where ((charge.ActualAmount ?? 0) - (payment.Amount ?? 0)) > 0 || (charge.StudentChargeID == null) || (charge.Amount == 0)
  183. group new { Charge = charge, Payment = payment } by student.UserID into g
  184. select g.Sum(x => (x.Charge.StudentChargeID == null) ? 0 : (x.Charge.ActualAmount ?? 0) - (x.Charge.Amount ?? 0));
  185. return query;
  186. }
  187. }
  188. }