StudentChargePaymenServices.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel;
  6. using EMIS.Entities;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using Bowin.Common.Utility;
  10. using System.Linq.Expressions;
  11. using EMIS.ViewModel.CacheManage;
  12. using EMIS.DataLogic.ChargeManage.ChargeSituation;
  13. using System.Text.RegularExpressions;
  14. using EMIS.ViewModel.ChargeManage.ChargeSituation;
  15. using System.Data;
  16. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  17. namespace EMIS.CommonLogic.ChargeManage.ChargeSituation
  18. {
  19. public class StudentChargePaymenServices : BaseServices, IStudentChargePaymenServices
  20. {
  21. public StudentChargePaymenDAL StudentChargePaymenDAL { get; set; }
  22. public ChargeProjectDAL ChargeProjectDAL { get; set; }
  23. public IInSchoolSettingServices InSchoolSettingServices { get; set; }
  24. public IChargeDelayServices IChargeDelayServices { get; set; }
  25. /// <summary>
  26. /// 查询学生缴费信息列表
  27. /// </summary>
  28. /// <param name="configuretView"></param>
  29. /// <param name="collegeID"></param>
  30. /// <param name="yearID"></param>
  31. /// <param name="standardID"></param>
  32. /// <param name="educationID"></param>
  33. /// <param name="learningformID"></param>
  34. /// <param name="learnSystem"></param>
  35. /// <param name="chargeYearID"></param>
  36. /// <param name="chargeProjectID"></param>
  37. /// <param name="inSchoolStatus"></param>
  38. /// <param name="isDream"></param>
  39. /// <param name="remark"></param>
  40. /// <param name="pageIndex"></param>
  41. /// <param name="pageSize"></param>
  42. /// <returns></returns>
  43. public IGridResultSet<StudentChargePaymenView> GetStudentChargePamenViewGrid(ConfiguretView configuretView, Guid? collegeID, int? yearID,
  44. int? standardID, int? educationID, int? learningformID, string learnSystem,
  45. int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int? isDream, int? chargeTagID,
  46. string remark, int pageIndex, int pageSize)
  47. {
  48. //学生缴费信息
  49. Expression<Func<EC_StudentChargePayment, bool>> expStudentChargePayment = (x => true);
  50. if (!string.IsNullOrEmpty(remark) && remark != "-1")
  51. {
  52. expStudentChargePayment = expStudentChargePayment.And(x => x.Remark == remark);
  53. }
  54. //应收名单
  55. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  56. if (chargeYearID.HasValue)
  57. {
  58. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
  59. }
  60. if (chargeProjectID.HasValue)
  61. {
  62. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
  63. }
  64. if (chargeTagID.HasValue)
  65. {
  66. expStudentCharge = expStudentCharge.And(x => x.ChargeTag == chargeTagID);
  67. }
  68. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  69. if (isDream.HasValue)
  70. {
  71. //expStudent = expStudent.And(x => x.IsDreamProject == (isDream == 1 ? true : false));
  72. if (isDream.Value == (int)CF_GeneralPurpose.IsYes)
  73. {
  74. expStudent = expStudent.And(x => x.CF_StudentProfile.IsDreamProject == true);
  75. }
  76. if (isDream.Value == (int)CF_GeneralPurpose.IsNo)
  77. {
  78. expStudent = expStudent.And(x => x.CF_StudentProfile.IsDreamProject != true);
  79. }
  80. }
  81. if (inSchoolStatus != null && inSchoolStatus > -1)
  82. {
  83. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  84. if (inSchoolStatus == 1)
  85. {
  86. //表示在校
  87. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  88. }
  89. if (inSchoolStatus == 0)
  90. {
  91. //不在校
  92. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  93. }
  94. }
  95. var query = StudentChargePaymenDAL.GetStudentChargePaymentViewTable(expStudentChargePayment, expStudentCharge, expStudent);
  96. if (collegeID.HasValue)
  97. {
  98. query = query.Where(x => x.CollegeID == collegeID);
  99. }
  100. if (yearID.HasValue)
  101. {
  102. query = query.Where(x => x.GradeStr == yearID);
  103. }
  104. if (standardID.HasValue)
  105. {
  106. query = query.Where(x => x.StandardID == standardID);
  107. }
  108. if (educationID.HasValue)
  109. {
  110. query = query.Where(x => x.EducationID == educationID);
  111. }
  112. if (learningformID.HasValue)
  113. {
  114. query = query.Where(x => x.LearningformID == learningformID);
  115. }
  116. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  117. {
  118. var LearnSystems = Convert.ToDecimal(learnSystem);
  119. query = query.Where(x => x.LearnSystem == LearnSystems);
  120. }
  121. //查询条件()
  122. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  123. {
  124. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  125. }
  126. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StudentNo.Length)
  127. .ThenBy(x => x.StudentNo).ThenBy(x => x.ChargeProjectStr)
  128. .ThenByDescending(x => x.ChargeYear).ThenBy(x => x.ChargeDate)
  129. .ToGridResultSet<StudentChargePaymenView>(pageIndex, pageSize);
  130. }
  131. /// <summary>
  132. /// 查询学生缴费信息列表
  133. /// </summary>
  134. /// <param name="configuretView"></param>
  135. /// <param name="collegeID"></param>
  136. /// <param name="yearID"></param>
  137. /// <param name="standardID"></param>
  138. /// <param name="educationID"></param>
  139. /// <param name="learningformID"></param>
  140. /// <param name="learnSystem"></param>
  141. /// <param name="chargeYearID"></param>
  142. /// <param name="chargeProjectID"></param>
  143. /// <param name="inSchoolStatus"></param>
  144. /// <param name="isDream"></param>
  145. /// <param name="chargeTagID"></param>
  146. /// <param name="remark"></param>
  147. /// <returns></returns>
  148. public List<StudentChargePaymenView> GetStudentChargePaymenList(ConfiguretView configuretView, Guid? collegeID, int? yearID,
  149. int? standardID, int? educationID, int? learningformID, string learnSystem,
  150. int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int? isDream, int? chargeTagID,
  151. string remark)
  152. {
  153. //学生缴费信息
  154. Expression<Func<EC_StudentChargePayment, bool>> expStudentChargePayment = (x => true);
  155. if (!string.IsNullOrEmpty(remark) && remark != "-1")
  156. {
  157. expStudentChargePayment = expStudentChargePayment.And(x => x.Remark == remark);
  158. }
  159. //应收名单
  160. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  161. if (chargeYearID.HasValue)
  162. {
  163. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
  164. }
  165. if (chargeProjectID.HasValue)
  166. {
  167. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
  168. }
  169. if (chargeTagID.HasValue)
  170. {
  171. expStudentCharge = expStudentCharge.And(x => x.ChargeTag == chargeTagID);
  172. }
  173. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  174. if (isDream.HasValue)
  175. {
  176. //expStudent = expStudent.And(x => x.IsDreamProject == (isDream == 1 ? true : false));
  177. if (isDream.Value == (int)CF_GeneralPurpose.IsYes)
  178. {
  179. expStudent = expStudent.And(x => x.CF_StudentProfile.IsDreamProject == true);
  180. }
  181. if (isDream.Value == (int)CF_GeneralPurpose.IsNo)
  182. {
  183. expStudent = expStudent.And(x => x.CF_StudentProfile.IsDreamProject != true);
  184. }
  185. }
  186. if (inSchoolStatus != null && inSchoolStatus > -1)
  187. {
  188. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  189. if (inSchoolStatus == 1)
  190. {
  191. //表示在校
  192. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  193. }
  194. if (inSchoolStatus == 0)
  195. {
  196. //不在校
  197. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  198. }
  199. }
  200. var query = StudentChargePaymenDAL.GetStudentChargePaymentViewTable(expStudentChargePayment, expStudentCharge, expStudent);
  201. if (collegeID.HasValue)
  202. {
  203. query = query.Where(x => x.CollegeID == collegeID);
  204. }
  205. if (yearID.HasValue)
  206. {
  207. query = query.Where(x => x.GradeStr == yearID);
  208. }
  209. if (standardID.HasValue)
  210. {
  211. query = query.Where(x => x.StandardID == standardID);
  212. }
  213. if (educationID.HasValue)
  214. {
  215. query = query.Where(x => x.EducationID == educationID);
  216. }
  217. if (learningformID.HasValue)
  218. {
  219. query = query.Where(x => x.LearningformID == learningformID);
  220. }
  221. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  222. {
  223. var LearnSystems = Convert.ToDecimal(learnSystem);
  224. query = query.Where(x => x.LearnSystem == LearnSystems);
  225. }
  226. //查询条件()
  227. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  228. {
  229. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  230. }
  231. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StudentNo.Length)
  232. .ThenBy(x => x.StudentNo).ThenBy(x => x.ChargeProjectStr)
  233. .ThenByDescending(x => x.ChargeYear).ThenBy(x => x.ChargeDate)
  234. .ToList();
  235. }
  236. /// <summary>
  237. /// 学生缴费页面缴费金额统计
  238. /// </summary>
  239. /// <param name="configuretView"></param>
  240. /// <param name="collegeID"></param>
  241. /// <param name="yearID"></param>
  242. /// <param name="standardID"></param>
  243. /// <param name="educationID"></param>
  244. /// <param name="learningformID"></param>
  245. /// <param name="learnSystem"></param>
  246. /// <param name="chargeYearID"></param>
  247. /// <param name="chargeProjectID"></param>
  248. /// <param name="inSchoolStatus"></param>
  249. /// <param name="isDream"></param>
  250. /// <param name="chargeTagID"></param>
  251. /// <param name="remark"></param>
  252. /// <param name="pageIndex"></param>
  253. /// <param name="pageSize"></param>
  254. /// <returns></returns>
  255. public decimal? GetAmountCount(ConfiguretView configuretView, Guid? collegeID, int? yearID,
  256. int? standardID, int? educationID, int? learningformID, string learnSystem,
  257. int? chargeYearID, Guid? chargeProjectID, int? inSchoolStatus, int? isDream, int? chargeTagID,
  258. string remark, int pageIndex, int pageSize)
  259. {
  260. //学生缴费信息
  261. Expression<Func<EC_StudentChargePayment, bool>> expStudentChargePayment = (x => true);
  262. if (!string.IsNullOrEmpty(remark) && remark != "-1")
  263. {
  264. expStudentChargePayment = expStudentChargePayment.And(x => x.Remark == remark);
  265. }
  266. //应收名单
  267. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  268. if (chargeYearID.HasValue)
  269. {
  270. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
  271. }
  272. if (chargeProjectID.HasValue)
  273. {
  274. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
  275. }
  276. if (chargeTagID.HasValue)
  277. {
  278. expStudentCharge = expStudentCharge.And(x => x.ChargeTag == chargeTagID);
  279. }
  280. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  281. if (isDream.HasValue)
  282. {
  283. //expStudent = expStudent.And(x => x.IsDreamProject == (isDream == 1 ? true : false));
  284. if (isDream.Value == (int)CF_GeneralPurpose.IsYes)
  285. {
  286. expStudent = expStudent.And(x => x.CF_StudentProfile.IsDreamProject == true);
  287. }
  288. if (isDream.Value == (int)CF_GeneralPurpose.IsNo)
  289. {
  290. expStudent = expStudent.And(x => x.CF_StudentProfile.IsDreamProject != true);
  291. }
  292. }
  293. if (inSchoolStatus != null && inSchoolStatus > -1)
  294. {
  295. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  296. if (inSchoolStatus == 1)
  297. {
  298. //表示在校
  299. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  300. }
  301. if (inSchoolStatus == 0)
  302. {
  303. //不在校
  304. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  305. }
  306. }
  307. var query = StudentChargePaymenDAL.GetStudentChargePaymentViewTable(expStudentChargePayment, expStudentCharge, expStudent);
  308. if (collegeID.HasValue)
  309. {
  310. query = query.Where(x => x.CollegeID == collegeID);
  311. }
  312. if (yearID.HasValue)
  313. {
  314. query = query.Where(x => x.GradeStr == yearID);
  315. }
  316. if (standardID.HasValue)
  317. {
  318. query = query.Where(x => x.StandardID == standardID);
  319. }
  320. if (educationID.HasValue)
  321. {
  322. query = query.Where(x => x.EducationID == educationID);
  323. }
  324. if (learningformID.HasValue)
  325. {
  326. query = query.Where(x => x.LearningformID == learningformID);
  327. }
  328. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  329. {
  330. var LearnSystems = Convert.ToDecimal(learnSystem);
  331. query = query.Where(x => x.LearnSystem == LearnSystems);
  332. }
  333. //查询条件()
  334. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  335. {
  336. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  337. }
  338. var studentChargePaymenViewList = GetQueryByDataRangeByCollege(query)
  339. .ToList<StudentChargePaymenView>();
  340. decimal? amountCount = 0;
  341. foreach (var studentChargePaymenView in studentChargePaymenViewList)
  342. {
  343. amountCount += studentChargePaymenView.Amount;
  344. }
  345. return amountCount;
  346. }
  347. /// <summary>
  348. /// 查询对应的学生缴费信息实体
  349. /// </summary>
  350. /// <param name="studentChargePaymentID"></param>
  351. /// <returns></returns>
  352. public EC_StudentChargePayment GetStudentChargePaymen(Guid? studentChargePaymentID)
  353. {
  354. //查询条件
  355. Expression<Func<EC_StudentChargePayment, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  356. expression = (x => x.StudentChargePaymentID == studentChargePaymentID);
  357. return StudentChargePaymenDAL.StudentChargePaymentRepository.GetSingle(expression);
  358. }
  359. /// <summary>
  360. /// 查询对应的学生缴费信息View
  361. /// </summary>
  362. /// <param name="studentChargePaymentID"></param>
  363. /// <returns></returns>
  364. public StudentChargePaymenView GetStudentChargePaymenView(Guid? studentChargePaymentID)
  365. {
  366. //查询条件
  367. Expression<Func<EC_StudentChargePayment, bool>> expStudentChargePayment = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  368. expStudentChargePayment = (x => x.StudentChargePaymentID == studentChargePaymentID);
  369. var query = StudentChargePaymenDAL.GetStudentChargePaymentViewTable(expStudentChargePayment, x => true, x => true);
  370. return query.SingleOrDefault();
  371. }
  372. /// <summary>
  373. /// 新增、修改
  374. /// </summary>
  375. /// <param name="studentChargePaymenView"></param>
  376. public void StudentChargePaymenEdit(StudentChargePaymenView studentChargePaymenView)
  377. {
  378. try
  379. {
  380. //查询对应的应收名单信息View(统计已缴金额)
  381. var studentChargeView = StudentChargePaymenDAL.GetStudentChargeViewQueryAble(x => x.UserID == studentChargePaymenView.UserID
  382. && x.ChargeYear == studentChargePaymenView.ChargeYear
  383. && x.ChargeProjectID == studentChargePaymenView.ChargeProjectID)
  384. .SingleOrDefault();
  385. //验证缴费金额在实收金额范围内
  386. decimal? amountVerify = 0;
  387. //验证对应的应收名单信息
  388. if (studentChargeView != null)
  389. {
  390. //查询数据库进行验证(需排除自己)
  391. var studentChargePaymentVerification = StudentChargePaymenDAL.StudentChargePaymentRepository
  392. .GetList(x => x.StudentChargePaymentID != studentChargePaymenView.StudentChargePaymentID
  393. && x.StudentChargeID == studentChargeView.StudentChargeID
  394. && x.ChargeDate == studentChargePaymenView.ChargeDate)
  395. .SingleOrDefault();
  396. if (studentChargePaymentVerification == null)
  397. {
  398. //数据有误验证
  399. if (studentChargePaymenView.StudentChargePaymentID != Guid.Empty)
  400. {
  401. //表示修改
  402. var studentChargePayment = StudentChargePaymenDAL.StudentChargePaymentRepository
  403. .GetList(x => x.StudentChargePaymentID == studentChargePaymenView.StudentChargePaymentID)
  404. .SingleOrDefault();
  405. if (studentChargePayment == null)
  406. {
  407. throw new Exception("数据有误,请核查");
  408. }
  409. else
  410. {
  411. //缴费金额在实收金额范围内
  412. amountVerify = studentChargeView.PaidAmount - studentChargePayment.Amount + studentChargePaymenView.Amount;
  413. if (studentChargeView.ActualAmount >= amountVerify)
  414. {
  415. studentChargePayment.Amount = studentChargePaymenView.Amount;
  416. studentChargePayment.ChargeDate = studentChargePaymenView.ChargeDate;
  417. SetModifyStatus(studentChargePayment);
  418. }
  419. else
  420. {
  421. throw new Exception("缴费金额大于实收金额,请重新输入");
  422. }
  423. }
  424. }
  425. else
  426. {
  427. //表示新增
  428. //缴费金额在实收金额范围内
  429. amountVerify = studentChargeView.PaidAmount + studentChargePaymenView.Amount;
  430. if (studentChargeView.ActualAmount >= amountVerify)
  431. {
  432. EC_StudentChargePayment studentChargePayment = new EC_StudentChargePayment();
  433. studentChargePayment.StudentChargePaymentID = Guid.NewGuid();
  434. studentChargePayment.StudentChargeID = studentChargeView.StudentChargeID;
  435. studentChargePayment.Amount = studentChargePaymenView.Amount;
  436. studentChargePayment.ChargeDate = studentChargePaymenView.ChargeDate;
  437. studentChargePayment.Remark = studentChargePaymenView.Remark;
  438. SetNewStatus(studentChargePayment, (int)SYS_STATUS.USABLE);
  439. UnitOfWork.Add(studentChargePayment);
  440. }
  441. else
  442. {
  443. throw new Exception("缴费金额大于实收金额,请重新输入");
  444. }
  445. }
  446. }
  447. else
  448. {
  449. throw new Exception("已存在相同的学生缴费信息");
  450. }
  451. }
  452. else
  453. {
  454. throw new Exception("对应的应收名单不存在");
  455. }
  456. //事务提交
  457. UnitOfWork.Commit();
  458. }
  459. catch (Exception ex)
  460. {
  461. throw new Exception(ex.Message);
  462. }
  463. }
  464. /// <summary>
  465. /// 查询应收名单对应的缴费信息(根据应收名单业务主键)
  466. /// </summary>
  467. /// <param name="userID"></param>
  468. /// <param name="chargeYearID"></param>
  469. /// <param name="chargeProjectID"></param>
  470. /// <returns></returns>
  471. public StudentChargeView QueryStudentChargePaymenView(Guid? userID, int? chargeYearID, Guid? chargeProjectID)
  472. {
  473. try
  474. {
  475. //应收名单
  476. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  477. if (userID.HasValue)
  478. {
  479. expStudentCharge = expStudentCharge.And(x => x.UserID == userID);
  480. }
  481. if (chargeYearID.HasValue)
  482. {
  483. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
  484. }
  485. if (chargeProjectID.HasValue)
  486. {
  487. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
  488. }
  489. var studentChargeView = StudentChargePaymenDAL.GetStudentChargeViewQueryAble(expStudentCharge)
  490. .SingleOrDefault();
  491. return studentChargeView;
  492. }
  493. catch (Exception ex)
  494. {
  495. throw new Exception(ex.Message);
  496. }
  497. }
  498. /// <summary>
  499. /// 批量修改(重写)
  500. /// </summary>
  501. /// <param name="studentChargePaymentIDs"></param>
  502. /// <param name="amount"></param>
  503. /// <returns></returns>
  504. public string BatchModify(string studentChargePaymentIDs, decimal? amount)
  505. {
  506. try
  507. {
  508. List<Guid?> list = studentChargePaymentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  509. .Select(x => (Guid?)new Guid(x)).ToList();
  510. //对应的学生缴费信息List
  511. var studentChargePaymentList = StudentChargePaymenDAL.StudentChargePaymentRepository
  512. .GetList(x => list.Contains(x.StudentChargePaymentID)).ToList();
  513. //对应的应收名单IDList
  514. var studentChargeIDList = studentChargePaymentList.Select(x => x.StudentChargeID).ToList();
  515. //对应的应收名单信息List(需统计对应的已缴金额)
  516. var studentChargeViewList = StudentChargePaymenDAL.GetStudentChargeViewQueryAble(x => studentChargeIDList.Contains(x.StudentChargeID)).ToList();
  517. int success = 0; //成功
  518. int fail = 0; //失败
  519. string tipMessage = null; //提示消息
  520. List<EC_StudentChargePayment> studentChargePaymentUpList = new List<EC_StudentChargePayment>();
  521. foreach (var studentChargePayment in studentChargePaymentList)
  522. {
  523. //查询对应的应收名单信息(需统计对应的已缴金额)
  524. var studentCharge = studentChargeViewList.Where(x => x.StudentChargeID == studentChargePayment.StudentChargeID)
  525. .SingleOrDefault();
  526. //注:由于存在可多次缴费的情况,那么实收金额应大于等于所有的缴费金额之和
  527. //计算公式应为:实收金额 >= 所有的缴费金额之和 - 更新的缴费金额 + 修改的金额
  528. if (studentCharge.ActualAmount >= studentCharge.PaidAmount - studentChargePayment.Amount + amount)
  529. {
  530. //表示可修改
  531. studentChargePayment.Amount = amount;
  532. SetModifyStatus(studentChargePayment);
  533. studentChargePaymentUpList.Add(studentChargePayment);
  534. success++;
  535. }
  536. else
  537. {
  538. //表示不可修改
  539. fail++;
  540. }
  541. }
  542. //批量统一提交更新
  543. if (studentChargePaymentUpList != null && studentChargePaymentUpList.Count() > 0)
  544. {
  545. UnitOfWork.Commit();
  546. }
  547. if (success > 0 && fail <= 0)
  548. {
  549. tipMessage = success + "条";
  550. }
  551. else
  552. {
  553. tipMessage = success + "条," + fail + "条失败,原因:缴费金额大于实收金额,请检查";
  554. }
  555. return tipMessage;
  556. }
  557. catch (Exception ex)
  558. {
  559. throw new Exception(ex.Message);
  560. }
  561. }
  562. /// <summary>
  563. /// 删除
  564. /// </summary>
  565. /// <param name="studentChargePaymenIDs"></param>
  566. /// <returns></returns>
  567. public bool StudentChargePaymenDelete(List<Guid> studentChargePaymenIDs)
  568. {
  569. try
  570. {
  571. UnitOfWork.Delete<EC_StudentChargePayment>(x => studentChargePaymenIDs.Contains(x.StudentChargePaymentID));
  572. UnitOfWork.Commit();
  573. return true;
  574. }
  575. catch (Exception ex)
  576. {
  577. throw new Exception(ex.Message);
  578. }
  579. }
  580. /// <summary>
  581. /// 获取学生缴费备注信息
  582. /// </summary>
  583. /// <param name="configuretView"></param>
  584. /// <param name="Remark"></param>
  585. /// <param name="pageIndex"></param>
  586. /// <param name="pageSize"></param>
  587. /// <returns></returns>
  588. public IGridResultSet<StudentChargePaymenView> GetRemarkViewGrid(ConfiguretView configuretView, string Remark,
  589. int pageIndex, int pageSize)
  590. {
  591. Expression<Func<EC_StudentChargePayment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  592. if (!string.IsNullOrEmpty(Remark) && Remark != "-1")
  593. {
  594. exp = exp.And(x => x.Remark == Remark);
  595. }
  596. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  597. {
  598. return StudentChargePaymenDAL.GetRemarkViewTable(exp).DynamicWhere(configuretView.Attribute, configuretView.Condition,
  599. configuretView.ConditionValue.Trim()).OrderBy(x => x.Remark)
  600. .ToGridResultSet<StudentChargePaymenView>(pageIndex, pageSize);
  601. }
  602. return StudentChargePaymenDAL.GetRemarkViewTable(exp).OrderBy(x => x.Remark)
  603. .ToGridResultSet<StudentChargePaymenView>(pageIndex, pageSize);
  604. }
  605. /// <summary>
  606. /// Excel导入
  607. /// 同一应收名单,同一缴费日期,只有一条记录且判断缴费金额在实收金额范围内
  608. /// 由于存在可多次缴费的情况,那么需考虑实收金额应大于等于所有的缴费金额之和的情况
  609. /// </summary>
  610. /// <param name="cellheader"></param>
  611. /// <param name="inCount"></param>
  612. /// <param name="upCount"></param>
  613. /// <param name="errdataList"></param>
  614. /// <param name="errCount"></param>
  615. /// <param name="sourcePhysicalPath"></param>
  616. public void StudentChargePaymenImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount,
  617. out List<StudentChargePaymenView> errdataList, out int? errCount, string sourcePhysicalPath)
  618. {
  619. try
  620. {
  621. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  622. List<StudentChargePaymenView> errList = new List<StudentChargePaymenView>();
  623. // 1.1解析文件,存放到一个List集合里
  624. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  625. List<StudentChargePaymenView> enlist = NpoiExcelHelper
  626. .ExcelToEntityList<StudentChargePaymenView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  627. cellheader.Add("ErrorMessage", "未导入原因");
  628. //对List集合进行有效性校验
  629. if (enlist.Count() <= 0)
  630. {
  631. throw new Exception("Excel文件数据为空,请检查。");
  632. }
  633. //Regex reg = null; //正则表达式
  634. DateTime result; //用于返回判断日期字段格式
  635. decimal isDecimal; //用于返回判断decimal列格式
  636. inCount = 0; //导入个数
  637. upCount = 0; //更新个数
  638. errCount = 0; //失败个数
  639. string errorMsgStr = ""; //错误信息
  640. //学生缴费insert实体List
  641. List<EC_StudentChargePayment> studentChargePaymentInList = new List<EC_StudentChargePayment>();
  642. //学生缴费update实体List
  643. List<EC_StudentChargePayment> studentChargePaymentUpList = new List<EC_StudentChargePayment>();
  644. //移除InList
  645. List<EC_StudentChargePayment> removeInList = new List<EC_StudentChargePayment>();
  646. //移除UpList
  647. List<EC_StudentChargePayment> removeUpList = new List<EC_StudentChargePayment>();
  648. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  649. //学号
  650. var studentNoList = enlist.Where(x => !string.IsNullOrEmpty(x.StudentNo))
  651. .Select(x => x.StudentNo).ToList();
  652. //查询对应的学生信息List
  653. var studentList = StudentChargePaymenDAL.StudentRepository
  654. .GetList(x => studentNoList.Contains(x.Sys_User.LoginID), (x => x.Sys_User)).ToList();
  655. //对应的学生信息userIDList
  656. var userIDList = studentList.Select(x => x.UserID).ToList();
  657. //收费项目
  658. var chargeProjectNameList = enlist.Where(x => !string.IsNullOrEmpty(x.ChargeProjectStr))
  659. .Select(x => x.ChargeProjectStr).ToList();
  660. //查询对应的收费项目List
  661. var chargeProjectList = StudentChargePaymenDAL.ChargeProjectRepository
  662. .GetList(x => chargeProjectNameList.Contains(x.Name)).ToList();
  663. //缴费学年
  664. var chargeYearList = enlist.Where(x => !string.IsNullOrEmpty(x.ChargeYearStr))
  665. .Select(x => x.ChargeYearStr).ToList();
  666. //学年
  667. var schoolYearList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Year).ToList();
  668. //查询应收名单信息ViewList(考虑到数据量的问题,暂时先查询所有)
  669. var studentChargeViewList = StudentChargePaymenDAL
  670. .GetStudentChargeViewQueryAble(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  671. //查询相应的匹配信息studentChargeViewList
  672. studentChargeViewList = studentChargeViewList.Where(x => userIDList.Contains(x.UserID.Value)).ToList();
  673. //对应的应收名单studentChargeIDList
  674. var studentChargeIDList = studentChargeViewList.Select(x => x.StudentChargeID).ToList();
  675. //学生缴费信息List(根据应收名单信息)
  676. var studentChargePaymentList = StudentChargePaymenDAL.StudentChargePaymentRepository
  677. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  678. //查询相应的匹配信息studentChargePaymentList
  679. studentChargePaymentList = studentChargePaymentList
  680. .Where(x => studentChargeIDList.Contains(x.StudentChargeID.Value)).ToList();
  681. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  682. for (int i = 0; i < enlist.Count; i++)
  683. {
  684. StudentChargePaymenView en = enlist[i]; //Excel表数据视图
  685. //学生缴费实体
  686. EC_StudentChargePayment studentChargePayment = new EC_StudentChargePayment();
  687. //学号
  688. if (string.IsNullOrEmpty(en.StudentNo))
  689. {
  690. errCount++;
  691. errorMsgStr = "学号不能为空";
  692. en.ErrorMessage = errorMsgStr;
  693. errList.Add(en);
  694. errorMsg.AppendLine(errorMsgStr);
  695. continue;
  696. }
  697. else
  698. {
  699. var student = studentList.Where(x => x.Sys_User.LoginID == en.StudentNo.Trim()).SingleOrDefault();
  700. if (student == null)
  701. {
  702. errCount++;
  703. errorMsgStr = "学号不存在,请检查";
  704. en.ErrorMessage = errorMsgStr;
  705. errList.Add(en);
  706. errorMsg.AppendLine(errorMsgStr);
  707. continue;
  708. }
  709. else
  710. {
  711. //userID
  712. //studentChargePayment.UserID = student.UserID;
  713. en.UserID = student.UserID;
  714. }
  715. }
  716. //收费项目
  717. if (string.IsNullOrEmpty(en.ChargeProjectStr))
  718. {
  719. errCount++;
  720. errorMsgStr = "收费项目不能为空";
  721. en.ErrorMessage = errorMsgStr;
  722. errList.Add(en);
  723. errorMsg.AppendLine(errorMsgStr);
  724. continue;
  725. }
  726. else
  727. {
  728. var chargeProject = chargeProjectList.Where(x => x.Name == en.ChargeProjectStr.Trim()).SingleOrDefault();
  729. if (chargeProject == null)
  730. {
  731. errCount++;
  732. errorMsgStr = "收费项目不存在,请检查";
  733. en.ErrorMessage = errorMsgStr;
  734. errList.Add(en);
  735. errorMsg.AppendLine(errorMsgStr);
  736. continue;
  737. }
  738. else
  739. {
  740. //收费项目ID
  741. //studentChargePayment.ChargeProjectID = chargeProject.ChargeProjectID;
  742. en.ChargeProjectID = chargeProject.ChargeProjectID;
  743. }
  744. }
  745. //缴费学年
  746. if (string.IsNullOrEmpty(en.ChargeYearStr))
  747. {
  748. errCount++;
  749. errorMsgStr = "缴费学年不能为空";
  750. en.ErrorMessage = errorMsgStr;
  751. errList.Add(en);
  752. errorMsg.AppendLine(errorMsgStr);
  753. continue;
  754. }
  755. else
  756. {
  757. var year = schoolYearList.Where(x => x.Name == en.ChargeYearStr.Trim()).SingleOrDefault();
  758. if (year == null)
  759. {
  760. errCount++;
  761. errorMsgStr = "缴费学年不存在,请检查";
  762. en.ErrorMessage = errorMsgStr;
  763. errList.Add(en);
  764. errorMsg.AppendLine(errorMsgStr);
  765. continue;
  766. }
  767. else
  768. {
  769. //缴费学年
  770. //studentChargePayment.ChargeYear = year.Value;
  771. en.ChargeYear = year.Value;
  772. }
  773. }
  774. //缴费日期
  775. if (string.IsNullOrEmpty(en.ChargeDateStr))
  776. {
  777. errCount++;
  778. errorMsgStr = "缴费日期不能为空";
  779. en.ErrorMessage = errorMsgStr;
  780. errList.Add(en);
  781. errorMsg.AppendLine(errorMsgStr);
  782. continue;
  783. }
  784. else
  785. {
  786. if (!DateTime.TryParse(en.ChargeDateStr.Trim(), out result))
  787. {
  788. errCount++;
  789. errorMsgStr = "缴费日期格式不正确,请检查";
  790. en.ErrorMessage = errorMsgStr;
  791. errList.Add(en);
  792. errorMsg.AppendLine(errorMsgStr);
  793. continue;
  794. }
  795. else
  796. {
  797. //缴费日期
  798. studentChargePayment.ChargeDate = Convert.ToDateTime(en.ChargeDateStr.Trim());
  799. }
  800. }
  801. //缴费金额
  802. if (string.IsNullOrEmpty(en.AmountStr))
  803. {
  804. errCount++;
  805. errorMsgStr = "缴费金额不能为空";
  806. en.ErrorMessage = errorMsgStr;
  807. errList.Add(en);
  808. errorMsg.AppendLine(errorMsgStr);
  809. continue;
  810. }
  811. else
  812. {
  813. if (!Decimal.TryParse(en.AmountStr.Trim(), out isDecimal))
  814. {
  815. errCount++;
  816. errorMsgStr = "缴费金额格式不正确,请检查";
  817. en.ErrorMessage = errorMsgStr;
  818. errList.Add(en);
  819. errorMsg.AppendLine(errorMsgStr);
  820. continue;
  821. }
  822. else
  823. {
  824. //缴费金额
  825. if (isDecimal <= 0)
  826. {
  827. errCount++;
  828. errorMsgStr = "缴费金额不能小于等于0,请检查";
  829. en.ErrorMessage = errorMsgStr;
  830. errList.Add(en);
  831. errorMsg.AppendLine(errorMsgStr);
  832. continue;
  833. }
  834. else
  835. {
  836. studentChargePayment.Amount = Convert.ToDecimal(en.AmountStr.Trim());
  837. }
  838. }
  839. }
  840. //查询对应的应收名单View(统计对应的已缴金额)
  841. var studentChargeView = studentChargeViewList.Where(x => x.UserID == en.UserID
  842. && x.ChargeProjectID == en.ChargeProjectID
  843. && x.ChargeYear == en.ChargeYear
  844. ).SingleOrDefault();
  845. if (studentChargeView == null)
  846. {
  847. errCount++;
  848. errorMsgStr = "对应的应收名单不存在,请检查";
  849. en.ErrorMessage = errorMsgStr;
  850. errList.Add(en);
  851. errorMsg.AppendLine(errorMsgStr);
  852. continue;
  853. }
  854. else
  855. {
  856. //应收名单ID
  857. en.StudentChargeID = studentChargeView.StudentChargeID;
  858. //实收金额("减免后的实收金额)
  859. en.ActualAmount = studentChargeView.ActualAmount;
  860. //已缴金额
  861. en.PaidAmount = studentChargeView.PaidAmount;
  862. }
  863. //备注
  864. studentChargePayment.Remark = en.Remark;
  865. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  866. //for (int j = i + 1; j < enlist.Count; j++)
  867. //{
  868. // StudentChargePaymenView enA = enlist[j];
  869. // //根据Excel表中的业务主键进行去重(应收名单、缴费日期唯一)
  870. // if (en.StudentNo == enA.StudentNo
  871. // && en.ChargeProjectStr == enA.ChargeProjectStr
  872. // && en.ChargeYearStr == enA.ChargeYearStr
  873. // && en.ChargeDateStr == enA.ChargeDateStr)
  874. // {
  875. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  876. // }
  877. //}
  878. //注:由于存在可多次缴费的情况,那么实收金额应大于等于所有的缴费金额之和
  879. //计算公式应分为两种情况:
  880. //1、新增时,实收金额 >= 所有的缴费金额之和 + 缴费金额
  881. //2、更新时:实收金额 >= 所有的缴费金额之和 - 更新的缴费金额 + 缴费金额
  882. //数据表重复性验证(应收名单、缴费日期唯一)
  883. var payVerification = studentChargePaymentList
  884. .Where(x => x.StudentChargeID == en.StudentChargeID
  885. && x.ChargeDate == studentChargePayment.ChargeDate).FirstOrDefault();
  886. if (payVerification == null)
  887. {
  888. if (!removeInList.Any(x => x.StudentChargeID == en.StudentChargeID
  889. && x.ChargeDate == studentChargePayment.ChargeDate))
  890. {
  891. //新增
  892. if (!studentChargePaymentInList.Any(x => x.StudentChargeID == en.StudentChargeID
  893. && x.ChargeDate == studentChargePayment.ChargeDate))
  894. {
  895. if (!removeInList.Any(x => x.StudentChargeID == en.StudentChargeID))
  896. {
  897. //多次缴费情况处理
  898. if (!studentChargePaymentInList.Any(x => x.StudentChargeID == en.StudentChargeID))
  899. {
  900. //新增时,实收金额 >= 所有的缴费金额之和 + 缴费金额(一次性缴费)
  901. if (studentChargeView.ActualAmount >= studentChargeView.PaidAmount + studentChargePayment.Amount)
  902. {
  903. studentChargePayment.StudentChargePaymentID = Guid.NewGuid();
  904. studentChargePayment.StudentChargeID = en.StudentChargeID;
  905. SetNewStatus(studentChargePayment);
  906. studentChargePaymentInList.Add(studentChargePayment);
  907. inCount++;
  908. }
  909. else
  910. {
  911. errCount++;
  912. errorMsgStr = "导入失败,缴费金额大于实收金额";
  913. en.ErrorMessage = errorMsgStr;
  914. errList.Add(en);
  915. errorMsg.AppendLine(errorMsgStr);
  916. continue;
  917. }
  918. }
  919. else
  920. {
  921. //分组统计查询对应的应收名单缴费金额
  922. var scpInGroup = studentChargePaymentInList.GroupBy(x => x.StudentChargeID)
  923. .Select(x => new
  924. {
  925. key = x.Key,
  926. PaidInAmount = x.Sum(s => s.Amount).Value
  927. }).Where(w => w.key == en.StudentChargeID).SingleOrDefault();
  928. //新增时,实收金额 >= 所有的缴费金额之和 + 缴费金额之和(多次重复缴费)
  929. if (studentChargeView.ActualAmount >= studentChargeView.PaidAmount + scpInGroup.PaidInAmount
  930. + studentChargePayment.Amount)
  931. {
  932. studentChargePayment.StudentChargePaymentID = Guid.NewGuid();
  933. studentChargePayment.StudentChargeID = en.StudentChargeID;
  934. SetNewStatus(studentChargePayment);
  935. studentChargePaymentInList.Add(studentChargePayment);
  936. inCount++;
  937. }
  938. else
  939. {
  940. //新增(Excel中有重复且缴费金额之和超出实收金额范围
  941. //抛出到失败数据文件中进行处理,不进行新增)
  942. var scpInList = studentChargePaymentInList
  943. .Where(x => x.StudentChargeID == en.StudentChargeID).ToList();
  944. foreach (var scpIn in scpInList)
  945. {
  946. errCount++;
  947. errorMsgStr = "多次缴费金额之和大于实收金额,请检查";
  948. en.ErrorMessage = errorMsgStr;
  949. errList.Add(new StudentChargePaymenView()
  950. {
  951. StudentNo = en.StudentNo,
  952. ChargeProjectStr = en.ChargeProjectStr,
  953. ChargeYearStr = en.ChargeYearStr,
  954. ChargeDateStr = scpIn.ChargeDate.ToString(),
  955. AmountStr = scpIn.Amount.ToString(),
  956. Remark = scpIn.Remark,
  957. ErrorMessage = en.ErrorMessage
  958. });
  959. errorMsg.AppendLine(errorMsgStr);
  960. studentChargePaymentInList.Remove(scpIn);
  961. removeInList.Add(scpIn);
  962. inCount--;
  963. }
  964. errCount++;
  965. errorMsgStr = "多次缴费金额之和大于实收金额,请检查";
  966. en.ErrorMessage = errorMsgStr;
  967. errList.Add(en);
  968. errorMsg.AppendLine(errorMsgStr);
  969. continue;
  970. }
  971. }
  972. }
  973. else
  974. {
  975. errCount++;
  976. errorMsgStr = "多次缴费金额之和大于实收金额,请检查";
  977. en.ErrorMessage = errorMsgStr;
  978. errList.Add(en);
  979. errorMsg.AppendLine(errorMsgStr);
  980. continue;
  981. }
  982. }
  983. else
  984. {
  985. //Excel表重复性验证
  986. //(注:当数据表中没有此记录,但是Excel中有重复数据,抛出到失败数据文件中进行处理)
  987. var scpInList = studentChargePaymentInList
  988. .Where(x => x.StudentChargeID == en.StudentChargeID
  989. && x.ChargeDate == studentChargePayment.ChargeDate).ToList();
  990. foreach (var scpIn in scpInList)
  991. {
  992. errCount++;
  993. errorMsgStr = "数据重复,请检查";
  994. en.ErrorMessage = errorMsgStr;
  995. errList.Add(new StudentChargePaymenView()
  996. {
  997. StudentNo = en.StudentNo,
  998. ChargeProjectStr = en.ChargeProjectStr,
  999. ChargeYearStr = en.ChargeYearStr,
  1000. ChargeDateStr = en.ChargeDateStr,
  1001. AmountStr = scpIn.Amount.ToString(),
  1002. Remark = scpIn.Remark,
  1003. ErrorMessage = en.ErrorMessage
  1004. });
  1005. errorMsg.AppendLine(errorMsgStr);
  1006. studentChargePaymentInList.Remove(scpIn);
  1007. removeInList.Add(scpIn);
  1008. inCount--;
  1009. }
  1010. errCount++;
  1011. errorMsgStr = "数据重复,请检查";
  1012. en.ErrorMessage = errorMsgStr;
  1013. errList.Add(en);
  1014. errorMsg.AppendLine(errorMsgStr);
  1015. continue;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. errCount++;
  1021. errorMsgStr = "数据重复,请检查";
  1022. en.ErrorMessage = errorMsgStr;
  1023. errList.Add(en);
  1024. errorMsg.AppendLine(errorMsgStr);
  1025. continue;
  1026. }
  1027. }
  1028. else
  1029. {
  1030. //更新(Excel中有重复时,以数据重复抛出到失败数据文件中进行处理,不进行更新)
  1031. if (!removeUpList.Any(x => x.StudentChargeID == en.StudentChargeID
  1032. && x.ChargeDate == studentChargePayment.ChargeDate))
  1033. {
  1034. if (!studentChargePaymentUpList.Any(x => x.StudentChargeID == en.StudentChargeID
  1035. && x.ChargeDate == studentChargePayment.ChargeDate))
  1036. {
  1037. //更新时:实收金额 >= 所有的缴费金额之和 - 更新的缴费金额 + 缴费金额(缴费金额在实收金额范围内)
  1038. if (studentChargeView.ActualAmount >=
  1039. studentChargeView.PaidAmount - payVerification.Amount + studentChargePayment.Amount)
  1040. {
  1041. //更新(Excel中无重复时,以最后一条记录的更新为准)
  1042. payVerification.Amount = studentChargePayment.Amount;
  1043. payVerification.Remark = studentChargePayment.Remark;
  1044. SetModifyStatus(payVerification);
  1045. studentChargePaymentUpList.Add(payVerification);
  1046. upCount++;
  1047. }
  1048. else
  1049. {
  1050. errCount++;
  1051. errorMsgStr = "导入更新失败,缴费金额大于实收金额";
  1052. en.ErrorMessage = errorMsgStr;
  1053. errList.Add(en);
  1054. errorMsg.AppendLine(errorMsgStr);
  1055. continue;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. var scpUpList = studentChargePaymentUpList
  1061. .Where(x => x.StudentChargeID == en.StudentChargeID
  1062. && x.ChargeDate == studentChargePayment.ChargeDate).ToList();
  1063. foreach (var scpUp in scpUpList)
  1064. {
  1065. errCount++;
  1066. errorMsgStr = "数据重复,请检查";
  1067. en.ErrorMessage = errorMsgStr;
  1068. errList.Add(new StudentChargePaymenView()
  1069. {
  1070. StudentNo = en.StudentNo,
  1071. ChargeProjectStr = en.ChargeProjectStr,
  1072. ChargeYearStr = en.ChargeYearStr,
  1073. ChargeDateStr = en.ChargeDateStr,
  1074. AmountStr = scpUp.Amount.ToString(),
  1075. Remark = scpUp.Remark,
  1076. ErrorMessage = en.ErrorMessage
  1077. });
  1078. errorMsg.AppendLine(errorMsgStr);
  1079. studentChargePaymentUpList.Remove(scpUp);
  1080. removeUpList.Add(scpUp);
  1081. upCount--;
  1082. }
  1083. errCount++;
  1084. errorMsgStr = "数据重复,请检查";
  1085. en.ErrorMessage = errorMsgStr;
  1086. errList.Add(en);
  1087. errorMsg.AppendLine(errorMsgStr);
  1088. continue;
  1089. }
  1090. }
  1091. else
  1092. {
  1093. errCount++;
  1094. errorMsgStr = "数据重复,请检查";
  1095. en.ErrorMessage = errorMsgStr;
  1096. errList.Add(en);
  1097. errorMsg.AppendLine(errorMsgStr);
  1098. continue;
  1099. }
  1100. }
  1101. }
  1102. //移除In
  1103. if (removeInList != null && removeInList.Count() > 0)
  1104. {
  1105. foreach (var removeIn in removeInList)
  1106. {
  1107. studentChargePaymentInList.Remove(removeIn);
  1108. }
  1109. }
  1110. //移除Up
  1111. if (removeUpList != null && removeUpList.Count() > 0)
  1112. {
  1113. foreach (var removeUp in removeUpList)
  1114. {
  1115. studentChargePaymentUpList.Remove(removeUp);
  1116. }
  1117. }
  1118. UnitOfWork.BulkInsert(studentChargePaymentInList); //批量插入
  1119. //批量统一提交更新
  1120. if (studentChargePaymentUpList != null && studentChargePaymentUpList.Count() > 0)
  1121. {
  1122. UnitOfWork.BatchUpdate(studentChargePaymentUpList); //批量更新
  1123. }
  1124. errdataList = errList.ToList(); //错误列表List
  1125. }
  1126. catch (Exception ex)
  1127. {
  1128. //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
  1129. throw new Exception(ex.Message);
  1130. }
  1131. }
  1132. /// <summary>
  1133. /// 验证学生缴费信息(验证逻辑:同一应收名单,同一缴费日期,只有一条记录且判断缴费金额在实收金额范围内)
  1134. /// </summary>
  1135. /// <param name="studentChargePaymentID"></param>
  1136. /// <param name="userID"></param>
  1137. /// <param name="chargeYearID"></param>
  1138. /// <param name="chargeProjectID"></param>
  1139. /// <param name="amount"></param>
  1140. /// <param name="chargeDate"></param>
  1141. /// <returns></returns>
  1142. public string GetVerification(Guid? studentChargePaymentID, Guid? userID, int? chargeYearID,
  1143. Guid? chargeProjectID, decimal? amount, DateTime? chargeDate)
  1144. {
  1145. try
  1146. {
  1147. //查询对应的应收名单信息View(统计已缴金额)
  1148. var studentChargeView = StudentChargePaymenDAL.GetStudentChargeViewQueryAble(x => x.UserID == userID
  1149. && x.ChargeYear == chargeYearID
  1150. && x.ChargeProjectID == chargeProjectID)
  1151. .SingleOrDefault();
  1152. //验证缴费金额在实收金额范围内
  1153. decimal? amountVerify = 0;
  1154. //验证对应的应收名单信息
  1155. if (studentChargeView != null)
  1156. {
  1157. //查询数据库进行验证(需排除自己)
  1158. var studentChargePayment = StudentChargePaymenDAL.StudentChargePaymentRepository
  1159. .GetList(x => x.StudentChargePaymentID != studentChargePaymentID
  1160. && x.StudentChargeID == studentChargeView.StudentChargeID
  1161. && x.ChargeDate == chargeDate)
  1162. .SingleOrDefault();
  1163. if (studentChargePayment == null)
  1164. {
  1165. //数据有误验证
  1166. if (studentChargePaymentID.HasValue && studentChargePaymentID != Guid.Empty)
  1167. {
  1168. //表示修改
  1169. studentChargePayment = StudentChargePaymenDAL.StudentChargePaymentRepository
  1170. .GetList(x => x.StudentChargePaymentID == studentChargePaymentID)
  1171. .SingleOrDefault();
  1172. if (studentChargePayment == null)
  1173. {
  1174. return "数据有误,请核查";
  1175. }
  1176. else
  1177. {
  1178. amountVerify = studentChargeView.PaidAmount - studentChargePayment.Amount + amount;
  1179. if (studentChargeView.ActualAmount >= amountVerify)
  1180. {
  1181. return "成功";
  1182. }
  1183. else
  1184. {
  1185. return "缴费金额大于实收金额,请重新输入";
  1186. }
  1187. }
  1188. }
  1189. else
  1190. {
  1191. amountVerify = studentChargeView.PaidAmount + amount;
  1192. if (studentChargeView.ActualAmount >= amountVerify)
  1193. {
  1194. return "成功";
  1195. }
  1196. else
  1197. {
  1198. return "缴费金额大于实收金额,请重新输入";
  1199. }
  1200. }
  1201. }
  1202. else
  1203. {
  1204. return "已存在相同的学生缴费信息";
  1205. }
  1206. }
  1207. else
  1208. {
  1209. throw new Exception("对应的应收名单不存在");
  1210. }
  1211. }
  1212. catch (Exception ex)
  1213. {
  1214. throw new Exception(ex.Message);
  1215. }
  1216. }
  1217. }
  1218. }