StudentChargeDAL.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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.ViewModel.ChargeManage.ChargeSituation;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel.Students;
  10. namespace EMIS.DataLogic.ChargeManage.ChargeSituation
  11. {
  12. public class StudentChargeDAL
  13. {
  14. public StudentChargeRepository StudentChargeRepository { get; set; }
  15. public UserRepository UserRepository { get; set; }
  16. public StudentRepository StudentRepository { get; set; }
  17. public ClassmajorRepository ClassmajorRepository { get; set; }
  18. public GrademajorRepository GrademajorRepository { get; set; }
  19. public FacultymajorRepository FacultymajorRepository { get; set; }
  20. public ChargeStandardRepository ChargeStandardRepository { get; set; }
  21. public ChargeDelayRepository ChargeDelayRepository { get; set; }
  22. public StudentChargePaymentRepository StudentChargePaymentRepository { get; set; }
  23. public ChargeProjectRepository ChargeProjectRepository { get; set; }
  24. /// <summary>
  25. /// 查询应收名单信息
  26. /// </summary>
  27. /// <param name="expStudentCharge"></param>
  28. /// <param name="expStudent"></param>
  29. /// <returns></returns>
  30. public IQueryable<StudentChargeView> GetStudentChargeViewQueryAble(Expression<Func<EC_StudentCharge, bool>> expStudentCharge,
  31. 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 stucp in
  45. (
  46. from cp in StudentChargePaymentRepository.Entities
  47. group cp by cp.StudentChargeID into g
  48. select new
  49. {
  50. StudentChargeID = g.Key,
  51. AmountCount = g.Sum(x => x.Amount)
  52. }
  53. )
  54. on sc.StudentChargeID equals stucp.StudentChargeID
  55. into tempcp
  56. from schcp in tempcp.DefaultIfEmpty()
  57. select new StudentChargeView
  58. {
  59. StudentChargeID = sc.StudentChargeID,
  60. ChargeYear = sc.ChargeYear,
  61. ChargeProjectID = sc.ChargeProjectID,
  62. ChargeProjectStr = sc.EC_ChargeProject.Name,
  63. Amount = sc.Amount,
  64. ChargeAmount = sc.ActualAmount - sc.Amount,
  65. ActualAmount = sc.ActualAmount,
  66. ChargeTag = sc.ChargeTag,
  67. UserID = sc.UserID,
  68. StudentNo = us.LoginID,
  69. UserName = us.Name,
  70. SexID = stu.SexID,
  71. IsDream = stu.CF_StudentProfile.IsDreamProject == true ? 1 : 0,
  72. InSchoolStatusID = stu.InSchoolStatusID,
  73. StudentStatusID = stu.StudentStatus,
  74. ClassID = stu.ClassmajorID,
  75. ClassNo = cl.No,
  76. ClassName = cl.Name,
  77. GradeStr = gr.GradeID,
  78. GradeMajorID = gr.GrademajorID,
  79. GradeMajorCode = gr.Code,
  80. GradeMajoyStr = gr.Name,
  81. CollegeID = fa.CollegeID,
  82. CollegeCode = fa.CF_College.No,
  83. CollegeStr = fa.CF_College.Name,
  84. StandardID = fa.StandardID,
  85. EducationID = fa.EducationID,
  86. LearningformID = fa.LearningformID,
  87. LearnSystem = fa.LearnSystem,
  88. Remark = sc.Remark,
  89. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount,
  90. IsArrear = ((schcp.AmountCount == null ? 0 : schcp.AmountCount) - sc.ActualAmount) >= 0 ? 0 : 1
  91. };
  92. return query;
  93. }
  94. /// <summary>
  95. /// 查询学生信息View
  96. /// </summary>
  97. /// <param name="exp"></param>
  98. /// <returns></returns>
  99. public IQueryable<StudentsView> GetStudentViewQueryAble(Expression<Func<CF_Student, bool>> exp)
  100. {
  101. var query = from stu in StudentRepository.GetList(exp)
  102. join cl in ClassmajorRepository.Entities
  103. on stu.ClassmajorID equals cl.ClassmajorID
  104. join gr in GrademajorRepository.Entities
  105. on cl.GrademajorID equals gr.GrademajorID
  106. join us in UserRepository.Entities
  107. on stu.UserID equals us.UserID
  108. select new StudentsView
  109. {
  110. UserID = stu.UserID,
  111. LoginID = us.LoginID,
  112. UserName = us.Name,
  113. SexID = stu.SexID,
  114. InSchoolStatusID = stu.InSchoolStatusID,
  115. StudentStatus = stu.StudentStatus,
  116. CertificatesType = stu.CertificatesType,
  117. IDNumber = stu.IDNumber,
  118. ClassMajorID = stu.ClassmajorID,
  119. ClassMajorCode = cl.No,
  120. ClassMajorName = cl.Name,
  121. GradeMajorID = cl.GrademajorID,
  122. GradeMajorCode = gr.Code,
  123. GradeMajorName = gr.Name
  124. };
  125. return query;
  126. }
  127. /// <summary>
  128. /// 查询应收名单对应的收费标准信息View
  129. /// </summary>
  130. /// <param name="expChargeStandard"></param>
  131. /// <returns></returns>
  132. public IQueryable<ChargeStandardView> GetStudentChargeChargeStandard(Expression<Func<EC_ChargeStandard, bool>> expChargeStandard)
  133. {
  134. var query = from ch in ChargeStandardRepository.GetList(expChargeStandard)
  135. join pr in ChargeProjectRepository.Entities
  136. on ch.ChargeProjectID equals pr.ChargeProjectID
  137. join gr in GrademajorRepository.Entities
  138. on ch.GrademajorID equals gr.GrademajorID
  139. join fa in FacultymajorRepository.Entities
  140. on gr.FacultymajorID equals fa.FacultymajorID
  141. select new ChargeStandardView
  142. {
  143. ChargeStandardID = ch.ChargeStandardID,
  144. GrademajorID = ch.GrademajorID,
  145. GradeMajorCode = gr.Code,
  146. GrademajorStr = gr.Name,
  147. ChargeProjectID = ch.ChargeProjectID,
  148. ChargeProjectStr = pr.Name,
  149. ChargeYear = ch.ChargeYear,
  150. Amount = ch.Amount,
  151. CollegeID = fa.CollegeID,
  152. CollegeCode = fa.CF_College.No,
  153. CollegeStr = fa.CF_College.Name,
  154. GradeStr = gr.GradeID,
  155. StandardID = fa.StandardID,
  156. EducationID = fa.EducationID,
  157. LearningformID = fa.LearningformID,
  158. LearnSystem = fa.LearnSystem
  159. };
  160. return query;
  161. }
  162. /// <summary>
  163. /// 查询应收名单对应的学生缴费信息View
  164. /// </summary>
  165. /// <param name="expStudentCharge"></param>
  166. /// <returns></returns>
  167. public IQueryable<StudentChargePaymenView> GetStudentChargePaymentView(Expression<Func<EC_StudentCharge, bool>> expStudentCharge)
  168. {
  169. var query = from sc in StudentChargeRepository.GetList(expStudentCharge)
  170. join pr in ChargeProjectRepository.Entities
  171. on sc.ChargeProjectID equals pr.ChargeProjectID
  172. join sp in StudentChargePaymentRepository.Entities
  173. on sc.StudentChargeID equals sp.StudentChargeID
  174. join us in UserRepository.Entities
  175. on sc.UserID equals us.UserID
  176. join stu in StudentRepository.Entities
  177. on sc.UserID equals stu.UserID
  178. join cl in ClassmajorRepository.Entities
  179. on stu.ClassmajorID equals cl.ClassmajorID
  180. join gr in GrademajorRepository.Entities
  181. on cl.GrademajorID equals gr.GrademajorID
  182. join fa in FacultymajorRepository.Entities
  183. on gr.FacultymajorID equals fa.FacultymajorID
  184. select new StudentChargePaymenView
  185. {
  186. StudentChargePaymentID = sp.StudentChargePaymentID,
  187. StudentChargeID = sc.StudentChargeID,
  188. UserID = sc.UserID,
  189. StudentNo = us.LoginID,
  190. UserName = us.Name,
  191. SexID = stu.SexID,
  192. InSchoolStatusID = stu.InSchoolStatusID,
  193. StudentStatusID = stu.StudentStatus,
  194. CollegeID = fa.CollegeID,
  195. CollegeCode = fa.CF_College.No,
  196. CollegeName = fa.CF_College.Name,
  197. ClassID = cl.ClassmajorID,
  198. ClassNo = cl.No,
  199. ClassName = cl.Name,
  200. GradeMajorID = gr.GrademajorID,
  201. GradeMajorCode = gr.Code,
  202. GradeMajorStr = gr.Name,
  203. GradeStr = gr.GradeID,
  204. StandardID = fa.StandardID,
  205. EducationID = fa.EducationID,
  206. LearningformID = fa.LearningformID,
  207. LearnSystem = fa.LearnSystem,
  208. ChargeYear = sc.ChargeYear,
  209. ChargeProjectID = sc.ChargeProjectID,
  210. ChargeProjectStr = pr.Name,
  211. Amount = sp.Amount, //学生缴费金额
  212. ChargeDate = sp.ChargeDate,
  213. Remark = sp.Remark
  214. };
  215. return query;
  216. }
  217. /// <summary>
  218. /// 查询应收名单中对应的缴费信息View(对应的缴费信息全部查询,内联)
  219. /// </summary>
  220. /// <param name="expStudentCharge"></param>
  221. /// <param name="expStudentChargePayment"></param>
  222. /// <returns></returns>
  223. public IQueryable<ChargeDelayView> GetStudentChargeChargeDelayView(Expression<Func<EC_StudentCharge, bool>> expStudentCharge)
  224. {
  225. var query = from sc in StudentChargeRepository.GetList(expStudentCharge)
  226. join stu in StudentRepository.Entities
  227. on sc.UserID equals stu.UserID
  228. join cl in ClassmajorRepository.Entities
  229. on stu.ClassmajorID equals cl.ClassmajorID
  230. join gr in GrademajorRepository.Entities
  231. on cl.GrademajorID equals gr.GrademajorID
  232. join fa in FacultymajorRepository.Entities
  233. on gr.FacultymajorID equals fa.FacultymajorID
  234. join us in UserRepository.Entities
  235. on sc.UserID equals us.UserID
  236. join cd in ChargeDelayRepository.Entities
  237. on sc.StudentChargeID equals cd.StudentChargeID
  238. join stucp in
  239. (
  240. from cp in StudentChargePaymentRepository.Entities
  241. group cp by cp.StudentChargeID into g
  242. select new
  243. {
  244. StudentChargeID = g.Key,
  245. AmountCount = g.Sum(x => x.Amount)
  246. }
  247. )
  248. on sc.StudentChargeID equals stucp.StudentChargeID
  249. into tempcp
  250. from schcp in tempcp.DefaultIfEmpty()
  251. select new ChargeDelayView
  252. {
  253. StudentChargeID = sc.StudentChargeID,
  254. ChargeYear = sc.ChargeYear,
  255. ChargeProjectID = sc.ChargeProjectID,
  256. ChargeProjectStr = sc.EC_ChargeProject.Name,
  257. Amount = sc.Amount,
  258. ChargeAmount = sc.ActualAmount - sc.Amount,
  259. ActualAmount = sc.ActualAmount,
  260. ChargeTag = sc.ChargeTag,
  261. UserID = sc.UserID,
  262. StudentNo = us.LoginID,
  263. UserName = us.Name,
  264. SexID = stu.SexID,
  265. InSchoolStatusID = stu.InSchoolStatusID,
  266. StudentStatusID = stu.StudentStatus,
  267. ClassID = stu.ClassmajorID,
  268. ClassNo = cl.No,
  269. ClassName = cl.Name,
  270. GradeStr = gr.GradeID,
  271. GradeMajorID = gr.GrademajorID,
  272. GradeMajorCode = gr.Code,
  273. GradeMajoyStr = gr.Name,
  274. CollegeID = fa.CollegeID,
  275. CollegeCode = fa.CF_College.No,
  276. CollegeStr = fa.CF_College.Name,
  277. StandardID = fa.StandardID,
  278. EducationID = fa.EducationID,
  279. LearningformID = fa.LearningformID,
  280. LearnSystem = fa.LearnSystem,
  281. ChargeDelayID = cd.ChargeDelayID,
  282. DelayAmount = cd.DelayAmount,
  283. DelayPercent = cd.DelayPercent,
  284. Reason = cd.Reason,
  285. RecordStatus = cd.RecordStatus,
  286. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount
  287. };
  288. return query;
  289. }
  290. /// <summary>
  291. /// 查询应收名单中对应的缴费信息View(对应的缴费信息全部查询,左联-待缓交金额、已缓交金额)
  292. /// </summary>
  293. /// <param name="expStudentCharge"></param>
  294. /// <param name="expChargeDelayApply"></param>
  295. /// <param name="expChargeDelayPass"></param>
  296. /// <returns></returns>
  297. public IQueryable<ChargeDelayView> GetStudentChargeChargeDelayView(Expression<Func<EC_StudentCharge, bool>> expStudentCharge,
  298. Expression<Func<EC_ChargeDelay, bool>> expChargeDelayApply, Expression<Func<EC_ChargeDelay, bool>> expChargeDelayPass)
  299. {
  300. var query = from sc in StudentChargeRepository.GetList(expStudentCharge)
  301. join stu in StudentRepository.Entities
  302. on sc.UserID equals stu.UserID
  303. join cl in ClassmajorRepository.Entities
  304. on stu.ClassmajorID equals cl.ClassmajorID
  305. join gr in GrademajorRepository.Entities
  306. on cl.GrademajorID equals gr.GrademajorID
  307. join fa in FacultymajorRepository.Entities
  308. on gr.FacultymajorID equals fa.FacultymajorID
  309. join us in UserRepository.Entities
  310. on sc.UserID equals us.UserID
  311. join stucp in
  312. (
  313. from cp in StudentChargePaymentRepository.Entities
  314. group cp by cp.StudentChargeID into g
  315. select new
  316. {
  317. StudentChargeID = g.Key,
  318. AmountCount = g.Sum(x => x.Amount)
  319. }
  320. )
  321. on sc.StudentChargeID equals stucp.StudentChargeID
  322. into tempcp
  323. from schcp in tempcp.DefaultIfEmpty()
  324. join stucdApply in
  325. (
  326. from cdApply in ChargeDelayRepository.GetList(expChargeDelayApply)
  327. group cdApply by cdApply.StudentChargeID into g
  328. select new
  329. {
  330. StudentChargeID = g.Key,
  331. ApplyDelayAmount = g.Sum(x => x.DelayAmount)
  332. }
  333. )
  334. on sc.StudentChargeID equals stucdApply.StudentChargeID
  335. into tempcdApply
  336. from schcdApply in tempcdApply.DefaultIfEmpty()
  337. join stucdPass in
  338. (
  339. from cdPass in ChargeDelayRepository.GetList(expChargeDelayPass)
  340. group cdPass by cdPass.StudentChargeID into g
  341. select new
  342. {
  343. StudentChargeID = g.Key,
  344. PassDelayAmount = g.Sum(x => x.DelayAmount)
  345. }
  346. )
  347. on sc.StudentChargeID equals stucdPass.StudentChargeID
  348. into tempcdPass
  349. from schcdPass in tempcdPass.DefaultIfEmpty()
  350. select new ChargeDelayView
  351. {
  352. StudentChargeID = sc.StudentChargeID,
  353. ChargeYear = sc.ChargeYear,
  354. ChargeProjectID = sc.ChargeProjectID,
  355. ChargeProjectStr = sc.EC_ChargeProject.Name,
  356. Amount = sc.Amount,
  357. ChargeAmount = sc.ActualAmount - sc.Amount,
  358. ActualAmount = sc.ActualAmount,
  359. ChargeTag = sc.ChargeTag,
  360. UserID = sc.UserID,
  361. StudentNo = us.LoginID,
  362. UserName = us.Name,
  363. SexID = stu.SexID,
  364. InSchoolStatusID = stu.InSchoolStatusID,
  365. StudentStatusID = stu.StudentStatus,
  366. ClassID = stu.ClassmajorID,
  367. ClassNo = cl.No,
  368. ClassName = cl.Name,
  369. GradeStr = gr.GradeID,
  370. GradeMajorID = gr.GrademajorID,
  371. GradeMajorCode = gr.Code,
  372. GradeMajoyStr = gr.Name,
  373. CollegeID = fa.CollegeID,
  374. CollegeCode = fa.CF_College.No,
  375. CollegeStr = fa.CF_College.Name,
  376. StandardID = fa.StandardID,
  377. EducationID = fa.EducationID,
  378. LearningformID = fa.LearningformID,
  379. LearnSystem = fa.LearnSystem,
  380. PaidAmount = schcp.AmountCount == null ? 0 : schcp.AmountCount,
  381. ApplyDelayAmount = schcdApply.ApplyDelayAmount == null ? 0 : schcdApply.ApplyDelayAmount,
  382. PassDelayAmount = schcdPass.PassDelayAmount == null ? 0 : schcdPass.PassDelayAmount,
  383. CanDelayAmount = sc.ActualAmount - (schcp.AmountCount == null ? 0 : schcp.AmountCount) - (schcdApply.ApplyDelayAmount == null ? 0 : schcdApply.ApplyDelayAmount) - (schcdPass.PassDelayAmount == null ? 0 : schcdPass.PassDelayAmount) > 0 ?
  384. sc.ActualAmount - (schcp.AmountCount == null ? 0 : schcp.AmountCount) - (schcdApply.ApplyDelayAmount == null ? 0 : schcdApply.ApplyDelayAmount) - (schcdPass.PassDelayAmount == null ? 0 : schcdPass.PassDelayAmount) : 0
  385. };
  386. return query;
  387. }
  388. }
  389. }