ArrearsListDAL.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.ChargeManage.ArrearsSituation;
  6. using EMIS.DataLogic.Repositories;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.ChargeManage.ArrearsSituation
  11. {
  12. public class ArrearsListDAL
  13. {
  14. public StudentChargeRepository StudentChargeRepository { get; set; }
  15. public StudentChargePaymentRepository StudentChargePaymentRepository { get; set; }
  16. public ChargeDelayRepository ChargeDelayRepository { get; set; }
  17. public PassStudentRepository PassStudentRepository { get; set; }
  18. public StudentRepository StudentRepository { get; set; }
  19. public UserRepository UserRepository { get; set; }
  20. public ClassmajorRepository ClassmajorRepository { get; set; }
  21. public GrademajorRepository GrademajorRepository { get; set; }
  22. public FacultymajorRepository FacultymajorRepository { get; set; }
  23. /// <summary>
  24. /// 查询对应的欠费信息View(左连缴费信息表、缓交信息表,欠费信息全部查询)
  25. /// 注:目前欠费金额的计算不包括通过缓交申请的缓交金额
  26. /// </summary>
  27. /// <param name="expStudentCharge"></param>
  28. /// <param name="expChargeDelay"></param>
  29. /// <param name="expStudent"></param>
  30. /// <returns></returns>
  31. public IQueryable<ArrearsListView> GetArrearListView(Expression<Func<EC_StudentCharge, bool>> expStudentCharge,
  32. Expression<Func<EC_ChargeDelay, bool>> expChargeDelay, Expression<Func<CF_Student, bool>> expStudent)
  33. {
  34. var query = from stugr in
  35. (
  36. from gr in
  37. (
  38. from sc in StudentChargeRepository.GetList(expStudentCharge)
  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. PaymentAmount = g.Sum(x => x.Amount)
  60. }
  61. )
  62. on sc.StudentChargeID equals stucp.StudentChargeID
  63. into tempcp
  64. from schcp in tempcp.DefaultIfEmpty()
  65. select new
  66. {
  67. StudentChargeID = sc.StudentChargeID,
  68. UserID = sc.UserID,
  69. ChargeYear = sc.ChargeYear,
  70. ChargeProjectID = sc.ChargeProjectID,
  71. Amount = sc.Amount,
  72. ChargeAmount = sc.ActualAmount - sc.Amount,
  73. ActualAmount = sc.ActualAmount,
  74. DelayAmount = schcdPass.DelayAmount ?? 0,
  75. PaymentAmount = schcp.PaymentAmount ?? 0
  76. }
  77. )
  78. group gr by gr.UserID into g
  79. select new
  80. {
  81. UserID = g.Key,
  82. Amount = g.Sum(x => x.Amount),
  83. ChargeAmount = g.Sum(x => x.ChargeAmount),
  84. ActualAmount = g.Sum(x => x.ActualAmount),
  85. DelayAmount = g.Sum(x => x.DelayAmount),
  86. PaymentAmount = g.Sum(x => x.PaymentAmount)
  87. }
  88. )
  89. join stu in StudentRepository.GetList(expStudent)
  90. on stugr.UserID equals stu.UserID
  91. join cl in ClassmajorRepository.Entities
  92. on stu.ClassmajorID equals cl.ClassmajorID
  93. join gr in GrademajorRepository.Entities
  94. on cl.GrademajorID equals gr.GrademajorID
  95. join fa in FacultymajorRepository.Entities
  96. on gr.FacultymajorID equals fa.FacultymajorID
  97. join us in UserRepository.Entities
  98. on stu.UserID equals us.UserID
  99. join pass in PassStudentRepository.Entities
  100. on stugr.UserID equals pass.UserID
  101. into temppass
  102. from stuPass in temppass.DefaultIfEmpty()
  103. select new ArrearsListView
  104. {
  105. UserID = stugr.UserID,
  106. StudentNo = us.LoginID,
  107. UserName = us.Name,
  108. SexID = stu.SexID,
  109. InSchoolStatus = stu.InSchoolStatusID,
  110. StudentStatus = stu.StudentStatus,
  111. ClassID = stu.ClassmajorID,
  112. ClassNo = cl.No,
  113. ClassName = cl.Name,
  114. GradeMajorID = cl.GrademajorID,
  115. GradeMajorCode = gr.Code,
  116. GrademajorStr = gr.Name,
  117. GradeStr = gr.GradeID,
  118. CollegeID = fa.CollegeID,
  119. CollegeCode = fa.CF_College.No,
  120. CollegeStr = fa.CF_College.Name,
  121. StandardID = fa.StandardID,
  122. EducationID = fa.EducationID,
  123. LearningformID = fa.LearningformID,
  124. LearnSystem = fa.LearnSystem,
  125. Amount = stugr.Amount,
  126. ChargeAmount = stugr.ChargeAmount,
  127. ActualAmount = stugr.ActualAmount,
  128. DelayAmount = stugr.DelayAmount,
  129. PaidAmount = stugr.PaymentAmount,
  130. IsArrear = (stugr.PaymentAmount - stugr.ActualAmount) >= 0 ? 0 : 1,
  131. AmountSum = stugr.ActualAmount - stugr.PaymentAmount,
  132. IsControl = stuPass.UserID == null ? 1 : 0
  133. };
  134. return query;
  135. }
  136. /// <summary>
  137. /// 查询对应的欠费信息View(左连缴费信息表、缓交信息表,只查询欠费金额大于0的欠费信息,成绩录入、毕业申请中需考虑)
  138. /// 注:目前欠费金额的计算不包括通过缓交申请的缓交金额
  139. /// </summary>
  140. /// <param name="expStudentCharge"></param>
  141. /// <param name="expChargeDelay"></param>
  142. /// <returns></returns>
  143. public IQueryable<ArrearsListView> GetArrearListViewAble(Expression<Func<EC_StudentCharge, bool>> expStudentCharge,
  144. Expression<Func<EC_ChargeDelay, bool>> expChargeDelay)
  145. {
  146. var query = from stugr in
  147. (
  148. from gr in
  149. (
  150. from sc in StudentChargeRepository.GetList(expStudentCharge)
  151. join stucd in
  152. (
  153. from cd in ChargeDelayRepository.GetList(expChargeDelay)
  154. group cd by cd.StudentChargeID into g
  155. select new
  156. {
  157. StudentChargeID = g.Key,
  158. DelayAmount = g.Sum(x => x.DelayAmount)
  159. }
  160. )
  161. on sc.StudentChargeID equals stucd.StudentChargeID
  162. into tempcd
  163. from schcdPass in tempcd.DefaultIfEmpty()
  164. join stucp in
  165. (
  166. from cp in StudentChargePaymentRepository.Entities
  167. group cp by cp.StudentChargeID into g
  168. select new
  169. {
  170. StudentChargeID = g.Key,
  171. PaymentAmount = g.Sum(x => x.Amount)
  172. }
  173. )
  174. on sc.StudentChargeID equals stucp.StudentChargeID
  175. into tempcp
  176. from schcp in tempcp.DefaultIfEmpty()
  177. select new
  178. {
  179. StudentChargeID = sc.StudentChargeID,
  180. UserID = sc.UserID,
  181. ChargeYear = sc.ChargeYear,
  182. ChargeProjectID = sc.ChargeProjectID,
  183. Amount = sc.Amount,
  184. ChargeAmount = sc.ActualAmount - sc.Amount,
  185. ActualAmount = sc.ActualAmount,
  186. DelayAmount = schcdPass.DelayAmount ?? 0,
  187. PaymentAmount = schcp.PaymentAmount ?? 0
  188. }
  189. )
  190. group gr by gr.UserID into g
  191. select new
  192. {
  193. UserID = g.Key,
  194. Amount = g.Sum(x => x.Amount),
  195. ChargeAmount = g.Sum(x => x.ChargeAmount),
  196. ActualAmount = g.Sum(x => x.ActualAmount),
  197. DelayAmount = g.Sum(x => x.DelayAmount),
  198. PaymentAmount = g.Sum(x => x.PaymentAmount)
  199. }
  200. )
  201. join stu in StudentRepository.Entities
  202. on stugr.UserID equals stu.UserID
  203. join cl in ClassmajorRepository.Entities
  204. on stu.ClassmajorID equals cl.ClassmajorID
  205. join gr in GrademajorRepository.Entities
  206. on cl.GrademajorID equals gr.GrademajorID
  207. join fa in FacultymajorRepository.Entities
  208. on gr.FacultymajorID equals fa.FacultymajorID
  209. join us in UserRepository.Entities
  210. on stu.UserID equals us.UserID
  211. join pass in PassStudentRepository.Entities
  212. on stugr.UserID equals pass.UserID
  213. into temppass
  214. from stuPass in temppass.DefaultIfEmpty()
  215. where (stugr.ActualAmount - stugr.PaymentAmount) > 0
  216. select new ArrearsListView
  217. {
  218. UserID = stugr.UserID,
  219. StudentNo = us.LoginID,
  220. UserName = us.Name,
  221. SexID = stu.SexID,
  222. InSchoolStatus = stu.InSchoolStatusID,
  223. StudentStatus = stu.StudentStatus,
  224. ClassID = stu.ClassmajorID,
  225. ClassNo = cl.No,
  226. ClassName = cl.Name,
  227. GradeMajorID = cl.GrademajorID,
  228. GradeMajorCode = gr.Code,
  229. GrademajorStr = gr.Name,
  230. GradeStr = gr.GradeID,
  231. CollegeID = fa.CollegeID,
  232. CollegeCode = fa.CF_College.No,
  233. CollegeStr = fa.CF_College.Name,
  234. StandardID = fa.StandardID,
  235. EducationID = fa.EducationID,
  236. LearningformID = fa.LearningformID,
  237. LearnSystem = fa.LearnSystem,
  238. Amount = stugr.Amount,
  239. ChargeAmount = stugr.ChargeAmount,
  240. ActualAmount = stugr.ActualAmount,
  241. DelayAmount = stugr.DelayAmount,
  242. PaidAmount = stugr.PaymentAmount,
  243. IsArrear = (stugr.PaymentAmount - stugr.ActualAmount) >= 0 ? 0 : 1,
  244. AmountSum = stugr.ActualAmount - stugr.PaymentAmount,
  245. IsControl = stuPass.UserID == null ? 1 : 0
  246. };
  247. return query;
  248. }
  249. /// <summary>
  250. /// 查询对应的控制放行信息View
  251. /// </summary>
  252. /// <param name="exp"></param>
  253. /// <returns></returns>
  254. public IQueryable<PassStudentView> GetPassStudentView(Expression<Func<EC_PassStudent, bool>> exp)
  255. {
  256. var query = from stuPass in PassStudentRepository.GetList(exp)
  257. join us in UserRepository.Entities
  258. on stuPass.UserID equals us.UserID
  259. select new PassStudentView
  260. {
  261. PassStudentID = stuPass.PassStudentID,
  262. UserID = stuPass.UserID,
  263. LoginID = us.LoginID,
  264. Name = us.Name,
  265. Remark = stuPass.Remark,
  266. RecordStatus = stuPass.RecordStatus,
  267. CreateUserID = stuPass.CreateUserID,
  268. CreateTime = stuPass.CreateTime,
  269. ModifyUserID = stuPass.ModifyUserID,
  270. ModifyTime = stuPass.ModifyTime
  271. };
  272. return query;
  273. }
  274. }
  275. }