ChargeDelayDAL.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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.Students;
  10. namespace EMIS.DataLogic.ChargeManage.ChargeSituation
  11. {
  12. public class ChargeDelayDAL
  13. {
  14. public ChargeDelayRepository ChargeDelayRepository { get; set; }
  15. public StudentChargeRepository StudentChargeRepository { get; set; }
  16. public UserRepository UserRepository { get; set; }
  17. public StudentRepository StudentRepository { get; set; }
  18. public ClassmajorRepository ClassmajorRepository { get; set; }
  19. public GrademajorRepository GrademajorRepository { get; set; }
  20. public FacultymajorRepository FacultymajorRepository { get; set; }
  21. public ChargeStandardRepository ChargeStandardRepository { get; set; }
  22. public StudentChargePaymentRepository StudentChargePaymentRepository { get; set; }
  23. public ChargeProjectRepository ChargeProjectRepository { get; set; }
  24. /// <summary>
  25. /// 查询缓交名单信息View(关联应收名单、学生缴费)
  26. /// </summary>
  27. /// <param name="expChargeDelay"></param>
  28. /// <param name="expStudentCharge"></param>
  29. /// <param name="expStudent"></param>
  30. /// <returns></returns>
  31. public IQueryable<ChargeDelayView> GetChargeDelayQueryAble(Expression<Func<EC_ChargeDelay, bool>> expChargeDelay,
  32. Expression<Func<EC_StudentCharge, bool>> expStudentCharge, Expression<Func<CF_Student, bool>> expStudent)
  33. {
  34. var query = from cd in ChargeDelayRepository.GetList(expChargeDelay)
  35. join sc in StudentChargeRepository.GetList(expStudentCharge)
  36. on cd.StudentChargeID equals sc.StudentChargeID
  37. join stu in StudentRepository.GetList(expStudent)
  38. on sc.UserID equals stu.UserID
  39. join cl in ClassmajorRepository.Entities
  40. on stu.ClassmajorID equals cl.ClassmajorID
  41. join gr in GrademajorRepository.Entities
  42. on cl.GrademajorID equals gr.GrademajorID
  43. join fa in FacultymajorRepository.Entities
  44. on gr.FacultymajorID equals fa.FacultymajorID
  45. join us in UserRepository.Entities
  46. on sc.UserID equals us.UserID
  47. join stucp in
  48. (
  49. from cp in StudentChargePaymentRepository.Entities
  50. group cp by cp.StudentChargeID into g
  51. select new
  52. {
  53. StudentChargeID = g.Key,
  54. AmountCount = g.Sum(x => x.Amount)
  55. }
  56. )
  57. on cd.StudentChargeID equals stucp.StudentChargeID
  58. into tempcp
  59. from schcp in tempcp.DefaultIfEmpty()
  60. select new ChargeDelayView
  61. {
  62. ChargeDelayID = cd.ChargeDelayID,
  63. StudentChargeID = sc.StudentChargeID,
  64. ChargeYear = sc.ChargeYear,
  65. ChargeProjectID = sc.ChargeProjectID,
  66. ChargeProjectStr = sc.EC_ChargeProject.Name,
  67. Amount = sc.Amount,
  68. ChargeAmount = sc.ActualAmount - sc.Amount,
  69. ActualAmount = sc.ActualAmount,
  70. ChargeTag = sc.ChargeTag,
  71. UserID = sc.UserID,
  72. StudentNo = us.LoginID,
  73. UserName = us.Name,
  74. SexID = stu.SexID,
  75. InSchoolStatusID = stu.InSchoolStatusID,
  76. StudentStatusID = stu.StudentStatus,
  77. ClassID = stu.ClassmajorID,
  78. ClassNo = cl.No,
  79. ClassName = cl.Name,
  80. GradeStr = gr.GradeID,
  81. GradeMajorID = gr.GrademajorID,
  82. GradeMajorCode = gr.Code,
  83. GradeMajoyStr = gr.Name,
  84. CollegeID = fa.CollegeID,
  85. CollegeCode = fa.CF_College.No,
  86. CollegeStr = fa.CF_College.Name,
  87. StandardID = fa.StandardID,
  88. EducationID = fa.EducationID,
  89. LearningformID = fa.LearningformID,
  90. LearnSystem = fa.LearnSystem,
  91. DelayAmount = cd.DelayAmount,
  92. DelayPercent = cd.DelayPercent,
  93. Reason = cd.Reason,
  94. RecordStatus = cd.RecordStatus,
  95. CreateTime = cd.CreateTime,
  96. ModifyTime = cd.ModifyTime,
  97. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount
  98. };
  99. return query;
  100. }
  101. /// <summary>
  102. /// 查询对应的缓交名单信息View(根据缓交信息)
  103. /// </summary>
  104. /// <param name="exp"></param>
  105. /// <returns></returns>
  106. public IQueryable<ChargeDelayView> GetChargeDelayQueryAble(Expression<Func<EC_ChargeDelay, bool>> exp)
  107. {
  108. var query = from cd in ChargeDelayRepository.GetList(exp)
  109. join sc in StudentChargeRepository.Entities
  110. on cd.StudentChargeID equals sc.StudentChargeID
  111. join stu in StudentRepository.Entities
  112. on sc.UserID equals stu.UserID
  113. join cl in ClassmajorRepository.Entities
  114. on stu.ClassmajorID equals cl.ClassmajorID
  115. join gr in GrademajorRepository.Entities
  116. on cl.GrademajorID equals gr.GrademajorID
  117. join fa in FacultymajorRepository.Entities
  118. on gr.FacultymajorID equals fa.FacultymajorID
  119. join us in UserRepository.Entities
  120. on sc.UserID equals us.UserID
  121. join stucp in
  122. (
  123. from cp in StudentChargePaymentRepository.Entities
  124. group cp by cp.StudentChargeID into g
  125. select new
  126. {
  127. StudentChargeID = g.Key,
  128. AmountCount = g.Sum(x => x.Amount)
  129. }
  130. )
  131. on cd.StudentChargeID equals stucp.StudentChargeID
  132. into tempcp
  133. from schcp in tempcp.DefaultIfEmpty()
  134. select new ChargeDelayView
  135. {
  136. ChargeDelayID = cd.ChargeDelayID,
  137. StudentChargeID = sc.StudentChargeID,
  138. ChargeYear = sc.ChargeYear,
  139. ChargeProjectID = sc.ChargeProjectID,
  140. ChargeProjectStr = sc.EC_ChargeProject.Name,
  141. Amount = sc.Amount,
  142. ChargeAmount = sc.ActualAmount - sc.Amount,
  143. ActualAmount = sc.ActualAmount,
  144. ChargeTag = sc.ChargeTag,
  145. UserID = sc.UserID,
  146. StudentNo = us.LoginID,
  147. UserName = us.Name,
  148. SexID = stu.SexID,
  149. InSchoolStatusID = stu.InSchoolStatusID,
  150. StudentStatusID = stu.StudentStatus,
  151. ClassID = stu.ClassmajorID,
  152. ClassNo = cl.No,
  153. ClassName = cl.Name,
  154. GradeStr = gr.GradeID,
  155. GradeMajorID = gr.GrademajorID,
  156. GradeMajorCode = gr.Code,
  157. GradeMajoyStr = gr.Name,
  158. CollegeID = fa.CollegeID,
  159. CollegeCode = fa.CF_College.No,
  160. CollegeStr = fa.CF_College.Name,
  161. StandardID = fa.StandardID,
  162. EducationID = fa.EducationID,
  163. LearningformID = fa.LearningformID,
  164. LearnSystem = fa.LearnSystem,
  165. DelayAmount = cd.DelayAmount,
  166. DelayPercent = cd.DelayPercent,
  167. Reason = cd.Reason,
  168. RecordStatus = cd.RecordStatus,
  169. CreateTime = cd.CreateTime,
  170. ModifyTime = cd.ModifyTime,
  171. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount
  172. };
  173. return query;
  174. }
  175. /// <summary>
  176. /// 查询对应的缴交信息View(对应的应收名单信息全部查询,左联-待缓交金额、已缓交金额)
  177. /// </summary>
  178. /// <param name="expStudentCharge"></param>
  179. /// <param name="expChargeDelayApply"></param>
  180. /// <param name="expChargeDelayPass"></param>
  181. /// <returns></returns>
  182. public IQueryable<ChargeDelayView> GetChargeDelayQueryView(Expression<Func<EC_ChargeDelay, bool>> expChargeDelay,
  183. Expression<Func<EC_ChargeDelay, bool>> expChargeDelayApply, Expression<Func<EC_ChargeDelay, bool>> expChargeDelayPass)
  184. {
  185. var query = from cd in ChargeDelayRepository.GetList(expChargeDelay)
  186. join sc in StudentChargeRepository.Entities
  187. on cd.StudentChargeID equals sc.StudentChargeID
  188. join stu in StudentRepository.Entities
  189. on sc.UserID equals stu.UserID
  190. join cl in ClassmajorRepository.Entities
  191. on stu.ClassmajorID equals cl.ClassmajorID
  192. join gr in GrademajorRepository.Entities
  193. on cl.GrademajorID equals gr.GrademajorID
  194. join fa in FacultymajorRepository.Entities
  195. on gr.FacultymajorID equals fa.FacultymajorID
  196. join us in UserRepository.Entities
  197. on sc.UserID equals us.UserID
  198. join stucp in
  199. (
  200. from cp in StudentChargePaymentRepository.Entities
  201. group cp by cp.StudentChargeID into g
  202. select new
  203. {
  204. StudentChargeID = g.Key,
  205. AmountCount = g.Sum(x => x.Amount)
  206. }
  207. )
  208. on cd.StudentChargeID equals stucp.StudentChargeID
  209. into tempcp
  210. from schcp in tempcp.DefaultIfEmpty()
  211. join stucdApply in
  212. (
  213. from cdApply in ChargeDelayRepository.GetList(expChargeDelayApply)
  214. group cdApply by cdApply.StudentChargeID into g
  215. select new
  216. {
  217. StudentChargeID = g.Key,
  218. ApplyDelayAmount = g.Sum(x => x.DelayAmount)
  219. }
  220. )
  221. on cd.StudentChargeID equals stucdApply.StudentChargeID
  222. into tempcdApply
  223. from schcdApply in tempcdApply.DefaultIfEmpty()
  224. join stucdPass in
  225. (
  226. from cdPass in ChargeDelayRepository.GetList(expChargeDelayPass)
  227. group cdPass by cdPass.StudentChargeID into g
  228. select new
  229. {
  230. StudentChargeID = g.Key,
  231. PassDelayAmount = g.Sum(x => x.DelayAmount)
  232. }
  233. )
  234. on cd.StudentChargeID equals stucdPass.StudentChargeID
  235. into tempcdPass
  236. from schcdPass in tempcdPass.DefaultIfEmpty()
  237. select new ChargeDelayView
  238. {
  239. ChargeDelayID = cd.ChargeDelayID,
  240. StudentChargeID = sc.StudentChargeID,
  241. ChargeYear = sc.ChargeYear,
  242. ChargeProjectID = sc.ChargeProjectID,
  243. ChargeProjectStr = sc.EC_ChargeProject.Name,
  244. Amount = sc.Amount,
  245. ChargeAmount = sc.ActualAmount - sc.Amount,
  246. ActualAmount = sc.ActualAmount,
  247. ChargeTag = sc.ChargeTag,
  248. UserID = sc.UserID,
  249. StudentNo = us.LoginID,
  250. UserName = us.Name,
  251. SexID = stu.SexID,
  252. InSchoolStatusID = stu.InSchoolStatusID,
  253. StudentStatusID = stu.StudentStatus,
  254. ClassID = stu.ClassmajorID,
  255. ClassNo = cl.No,
  256. ClassName = cl.Name,
  257. GradeStr = gr.GradeID,
  258. GradeMajorID = gr.GrademajorID,
  259. GradeMajorCode = gr.Code,
  260. GradeMajoyStr = gr.Name,
  261. CollegeID = fa.CollegeID,
  262. CollegeCode = fa.CF_College.No,
  263. CollegeStr = fa.CF_College.Name,
  264. StandardID = fa.StandardID,
  265. EducationID = fa.EducationID,
  266. LearningformID = fa.LearningformID,
  267. LearnSystem = fa.LearnSystem,
  268. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount,
  269. DelayAmount = cd.DelayAmount,
  270. DelayPercent = cd.DelayPercent,
  271. Reason = cd.Reason,
  272. RecordStatus = cd.RecordStatus,
  273. CreateTime = cd.CreateTime,
  274. ModifyTime = cd.ModifyTime,
  275. ApplyDelayAmount = (schcdApply.ApplyDelayAmount == null ? 0 : schcdApply.ApplyDelayAmount) - (cd.DelayAmount == null ? 0 : cd.DelayAmount),
  276. PassDelayAmount = schcdPass.PassDelayAmount == null ? 0 : schcdPass.PassDelayAmount,
  277. CanDelayAmount = sc.ActualAmount - (schcp.AmountCount == null ? 0 : schcp.AmountCount) - (schcdApply.ApplyDelayAmount == null ? 0 : schcdApply.ApplyDelayAmount) - (schcdPass.PassDelayAmount == null ? 0 : schcdPass.PassDelayAmount) + (cd.DelayAmount == null ? 0 : cd.DelayAmount) > 0 ?
  278. sc.ActualAmount - (schcp.AmountCount == null ? 0 : schcp.AmountCount) - (schcdApply.ApplyDelayAmount == null ? 0 : schcdApply.ApplyDelayAmount) - (schcdPass.PassDelayAmount == null ? 0 : schcdPass.PassDelayAmount) + (cd.DelayAmount == null ? 0 : cd.DelayAmount) : 0
  279. };
  280. return query;
  281. }
  282. }
  283. }