ChargeStandardServices.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.DataLogic.ChargeManage.ChargeSituation;
  7. using EMIS.ViewModel;
  8. using EMIS.ViewModel.ChargeManage.ChargeSituation;
  9. using System.Text.RegularExpressions;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. using System.Linq.Expressions;
  13. using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
  14. using EMIS.ViewModel.Students;
  15. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  16. namespace EMIS.CommonLogic.ChargeManage.ChargeSituation
  17. {
  18. public class ChargeStandardServices : BaseServices, IChargeStandardServices
  19. {
  20. public ChargeStandardDAL ChargeStandardDAL { get; set; }
  21. public ChargeProjectDAL ChargeProjectDAL { get; set; }
  22. public StudentChargeDAL StudentChargeDAL { get; set; }
  23. public IInSchoolSettingServices InSchoolSettingServices { get; set; }
  24. /// <summary>
  25. /// 查询收费标准信息列表
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="pageIndex"></param>
  29. /// <param name="pageSize"></param>
  30. /// <returns></returns>
  31. public IGridResultSet<ViewModel.ChargeManage.ChargeSituation.ChargeStandardView> GetChargeStandardViewGrid(ConfiguretView configuretView,
  32. Guid? collegeID, int? yearID, int? chargeYearID, int? standardID, int? educationID, int? learningformID,
  33. Guid? chargeProjectID, string LearnSystem, int? inSchoolStatus, int pageIndex, int pageSize)
  34. {
  35. Expression<Func<EC_ChargeStandard, bool>> expChargeStandard = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  36. if (chargeYearID.HasValue)
  37. {
  38. //缴费学年
  39. expChargeStandard = expChargeStandard.And(x => x.ChargeYear == chargeYearID);
  40. }
  41. if (chargeProjectID.HasValue)
  42. {
  43. //收费项目
  44. expChargeStandard = expChargeStandard.And(x => x.ChargeProjectID == chargeProjectID);
  45. }
  46. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  47. if (inSchoolStatus != null && inSchoolStatus > -1)
  48. {
  49. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  50. if (inSchoolStatus == 1)
  51. {
  52. //表示在校
  53. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  54. }
  55. if (inSchoolStatus == 0)
  56. {
  57. //不在校
  58. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  59. }
  60. }
  61. var query = ChargeStandardDAL.GetChargeStandarViewQueryAble(expChargeStandard, expStudent);
  62. if (collegeID.HasValue)
  63. {
  64. query = query.Where(x => x.CollegeID == collegeID);
  65. }
  66. if (yearID.HasValue)
  67. {
  68. query = query.Where(x => x.GradeStr == yearID);
  69. }
  70. if (standardID.HasValue)
  71. {
  72. query = query.Where(x => x.StandardID == standardID);
  73. }
  74. if (educationID.HasValue)
  75. {
  76. query = query.Where(x => x.EducationID == educationID);
  77. }
  78. if (learningformID.HasValue)
  79. {
  80. query = query.Where(x => x.LearningformID == learningformID);
  81. }
  82. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  83. {
  84. var LearnSystems = Convert.ToDecimal(LearnSystem);
  85. query = query.Where(x => x.LearnSystem == LearnSystems);
  86. }
  87. ////去掉学生人数为0的数据
  88. //if (inSchoolStatus != null && inSchoolStatus > -1)
  89. //{
  90. // query = query.Where(x => x.StudentCount > 0);
  91. //}
  92. //查询条件()
  93. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  94. {
  95. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  96. }
  97. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.GrademajorStr)
  98. .ThenByDescending(x => x.ChargeYear).ThenBy(x => x.ChargeProjectStr)
  99. .ToGridResultSet<ChargeStandardView>(pageIndex, pageSize);
  100. }
  101. /// <summary>
  102. /// 查询收费标准信息列表
  103. /// </summary>
  104. /// <param name="configuretView"></param>
  105. /// <param name="standardID"></param>
  106. /// <param name="educationID"></param>
  107. /// <param name="learningformID"></param>
  108. /// <returns></returns>
  109. public List<ChargeStandardView> GetChargeStandardList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID,
  110. int? learningformID, int? chargeYearID, Guid? chargeProjectID, string LearnSystem, int? educationID, int? inSchoolStatus)
  111. {
  112. Expression<Func<EC_ChargeStandard, bool>> expChargeStandard = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  113. if (chargeYearID.HasValue)
  114. {
  115. //缴费学年
  116. expChargeStandard = expChargeStandard.And(x => x.ChargeYear == chargeYearID);
  117. }
  118. if (chargeProjectID.HasValue)
  119. {
  120. //收费项目
  121. expChargeStandard = expChargeStandard.And(x => x.ChargeProjectID == chargeProjectID);
  122. }
  123. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  124. if (inSchoolStatus != null && inSchoolStatus > -1)
  125. {
  126. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  127. if (inSchoolStatus == 1)
  128. {
  129. //表示在校
  130. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  131. }
  132. if (inSchoolStatus == 0)
  133. {
  134. //不在校
  135. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  136. }
  137. }
  138. var query = ChargeStandardDAL.GetChargeStandarViewQueryAble(expChargeStandard, expStudent);
  139. if (collegeID.HasValue)
  140. {
  141. query = query.Where(x => x.CollegeID == collegeID);
  142. }
  143. if (yearID.HasValue)
  144. {
  145. query = query.Where(x => x.GradeStr == yearID);
  146. }
  147. if (standardID.HasValue)
  148. {
  149. query = query.Where(x => x.StandardID == standardID);
  150. }
  151. if (educationID.HasValue)
  152. {
  153. query = query.Where(x => x.EducationID == educationID);
  154. }
  155. if (learningformID.HasValue)
  156. {
  157. query = query.Where(x => x.LearningformID == learningformID);
  158. }
  159. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  160. {
  161. var LearnSystems = Convert.ToDecimal(LearnSystem);
  162. query = query.Where(x => x.LearnSystem == LearnSystems);
  163. }
  164. ////去掉学生人数为0的数据
  165. //if (inSchoolStatus != null && inSchoolStatus > -1)
  166. //{
  167. // query = query.Where(x => x.StudentCount > 0);
  168. //}
  169. //查询条件
  170. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  171. {
  172. string conditionValue = string.Empty;
  173. Regex rg = new Regex(@"^[0-9]*$");
  174. if (rg.IsMatch(configuretView.ConditionValue))
  175. conditionValue = Convert.ToInt32(configuretView.ConditionValue).ToString();
  176. else
  177. conditionValue = configuretView.ConditionValue;
  178. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, conditionValue);
  179. }
  180. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.GrademajorStr).ThenByDescending(x => x.ChargeYear)
  181. .ThenBy(x => x.ChargeProjectStr).ToList();
  182. }
  183. /// <summary>
  184. /// 查询收费标准新增年级专业列表
  185. /// </summary>
  186. /// <param name="configuretView"></param>
  187. /// <param name="gradeMajorID"></param>
  188. /// <param name="collegeID"></param>
  189. /// <param name="yearID"></param>
  190. /// <param name="standardID"></param>
  191. /// <param name="educationID"></param>
  192. /// <param name="learningformID"></param>
  193. /// <param name="learnSystem"></param>
  194. /// <param name="inschoolstatus"></param>
  195. /// <param name="chargeYearID"></param>
  196. /// <param name="chargeProjectID"></param>
  197. /// <param name="pageIndex"></param>
  198. /// <param name="pageSize"></param>
  199. /// <returns></returns>
  200. public IGridResultSet<GrademajorView> GetGradeMajorViewGrid(ConfiguretView configuretView, Guid? gradeMajorID,
  201. Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID,
  202. string learnSystem, int? inSchoolStatus, int? chargeYearID, Guid? chargeProjectID, int pageIndex, int pageSize)
  203. {
  204. Expression<Func<EC_ChargeStandard, bool>> expChargeStandard = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  205. if (chargeYearID!=null && chargeYearID.HasValue)
  206. {
  207. //缴费学年
  208. expChargeStandard = expChargeStandard.And(x => x.ChargeYear == chargeYearID);
  209. }
  210. if (chargeProjectID != null && chargeProjectID.HasValue)
  211. {
  212. //收费项目
  213. expChargeStandard = expChargeStandard.And(x => x.ChargeProjectID == chargeProjectID);
  214. }
  215. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  216. if (inSchoolStatus != null && inSchoolStatus > -1)
  217. {
  218. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  219. if (inSchoolStatus == 1)
  220. {
  221. //表示在校
  222. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  223. }
  224. if (inSchoolStatus == 0)
  225. {
  226. //不在校
  227. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  228. }
  229. }
  230. var query = ChargeStandardDAL.GetGradeMajorViewQueryAble(expChargeStandard, expStudent);
  231. if (collegeID.HasValue)
  232. {
  233. query = query.Where(x => x.CollegeID == collegeID);
  234. }
  235. if (yearID.HasValue)
  236. {
  237. query = query.Where(x => x.GradeID == yearID);
  238. }
  239. if (standardID.HasValue)
  240. {
  241. query = query.Where(x => x.StandardID == standardID);
  242. }
  243. if (educationID.HasValue)
  244. {
  245. query = query.Where(x => x.EducationID == educationID);
  246. }
  247. if (learningformID.HasValue)
  248. {
  249. query = query.Where(x => x.LearningformID == learningformID);
  250. }
  251. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  252. {
  253. var LearnSystems = Convert.ToDecimal(learnSystem);
  254. query = query.Where(x => x.LearnSystem == LearnSystems);
  255. }
  256. //去掉学生人数为0的数据(去除人数为0的年级专业,但选全部时可不去除)
  257. if (inSchoolStatus != null && inSchoolStatus > -1)
  258. {
  259. query = query.Where(x => x.StudentCount > 0);
  260. }
  261. //查询条件()
  262. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  263. {
  264. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  265. }
  266. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.GradeID)
  267. .OrderBy(x=>x.StandardID).OrderBy(x=>x.EducationID).OrderBy(x=>x.LearningformID)
  268. .OrderBy(x=>x.LearnSystem).OrderBy(x=>x.Name)
  269. .ToGridResultSet<GrademajorView>(pageIndex, pageSize);
  270. }
  271. /// <summary>
  272. /// 刷新名单(生成对应的收费标准应收名单,注:目前只对不在应收名单中的学生进行插入操作)
  273. /// </summary>
  274. /// <param name="chargeStandardIDs"></param>
  275. /// <param name="inschoolstatus"></param>
  276. /// <returns></returns>
  277. public string CreatStudentChargeList(List<Guid?> chargeStandardIDs, int? inschoolStatus)
  278. {
  279. try
  280. {
  281. //查询收费标准信息
  282. var chargeStandardList = ChargeStandardDAL.ChargeStandardRepository
  283. .GetList(x => chargeStandardIDs.Contains(x.ChargeStandardID)).ToList();
  284. //获取年级专业列表
  285. var gradeMajorIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString()))
  286. .Select(x => x.GrademajorID).ToList();
  287. //获取缴费学年列表
  288. var chargeYearIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeYear.ToString()))
  289. .Select(x => x.ChargeYear).ToList();
  290. //获取收费项目列表
  291. var chargeProjectIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeProjectID.ToString()))
  292. .Select(x => x.ChargeProjectID).ToList();
  293. //应收名单
  294. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  295. if (chargeYearIDList != null && chargeYearIDList.Count() > 0)
  296. {
  297. expStudentCharge = expStudentCharge.And(x => chargeYearIDList.Contains(x.ChargeYear));
  298. }
  299. if (chargeProjectIDList != null && chargeProjectIDList.Count() > 0)
  300. {
  301. expStudentCharge = expStudentCharge.And(x => chargeProjectIDList.Contains(x.ChargeProjectID));
  302. }
  303. //查询当前应收名单信息(根据应收名单、年级专业查询)
  304. var studentChargeViewList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge,
  305. x => gradeMajorIDList.Contains(x.GrademajorID)).ToList();
  306. //在校状态
  307. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  308. if (inschoolStatus != null && inschoolStatus > -1)
  309. {
  310. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  311. if (inschoolStatus == 1)
  312. {
  313. //表示在校
  314. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  315. }
  316. if (inschoolStatus == 0)
  317. {
  318. //不在校
  319. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  320. }
  321. }
  322. //查询各年级专业对应的学生信息List(含在校状态)
  323. var gradeMajorStudentList = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => gradeMajorIDList.Contains(x.GrademajorID),
  324. expStudent).ToList();
  325. int success = 0; //成功
  326. int fail = 0; //失败
  327. string tipMessage = null; //提示消息
  328. //注:只对不在应收名单中的学生进行插入操作
  329. List<EC_StudentCharge> studentChargeInList = new List<EC_StudentCharge>();
  330. foreach (var chargeStandard in chargeStandardList)
  331. {
  332. //收费标准信息验证
  333. var chargeStandardVerify = chargeStandardList.Where(x => x.ChargeStandardID == chargeStandard.ChargeStandardID)
  334. .SingleOrDefault();
  335. if (chargeStandardVerify != null)
  336. {
  337. //查询对应的应收名单List
  338. var studentChargeList = studentChargeViewList.Where(x => x.ChargeYear == chargeStandardVerify.ChargeYear
  339. && x.ChargeProjectID == chargeStandardVerify.ChargeProjectID
  340. && x.GradeMajorID == chargeStandardVerify.GrademajorID).ToList();
  341. //查询年级专业对应的学生信息List(含在校状态)
  342. var studentIDList = gradeMajorStudentList.Where(x => x.GradeMajorID == chargeStandardVerify.GrademajorID)
  343. .Select(x => x.UserID).ToList();
  344. if (studentIDList != null && studentIDList.Count() > 0)
  345. {
  346. foreach (var studentID in studentIDList)
  347. {
  348. //对应的应收名单信息
  349. var studentChargeVerify = studentChargeList.Where(x => x.UserID == studentID)
  350. .SingleOrDefault();
  351. if (studentChargeVerify == null)
  352. {
  353. //表示不存在对应的应收名单
  354. EC_StudentCharge studentCharge = new EC_StudentCharge();
  355. studentCharge.StudentChargeID = Guid.NewGuid();
  356. studentCharge.UserID = studentID;
  357. studentCharge.ChargeProjectID = chargeStandardVerify.ChargeProjectID;
  358. studentCharge.ChargeYear = chargeStandardVerify.ChargeYear;
  359. studentCharge.Amount = chargeStandardVerify.Amount;
  360. studentCharge.ActualAmount = studentCharge.Amount; //减免后金额
  361. studentCharge.ChargeTag = (int)EC_ChargeTag.Normal; //默认为正常收费
  362. SetNewStatus(studentCharge, (int)SYS_STATUS.USABLE);
  363. studentChargeInList.Add(studentCharge);
  364. }
  365. else
  366. {
  367. //表示已存在对应的应收名单(可做更新)
  368. }
  369. }
  370. }
  371. else
  372. {
  373. //表示学生信息为空
  374. }
  375. success++;
  376. }
  377. else
  378. {
  379. //数据有误,刷新失败
  380. fail++;
  381. }
  382. }
  383. if (studentChargeInList != null && studentChargeInList.Count() > 0)
  384. {
  385. //批量插入
  386. UnitOfWork.BulkInsert<EC_StudentCharge>(studentChargeInList);
  387. }
  388. if (success > 0 && fail <= 0)
  389. {
  390. tipMessage = success + "条";
  391. }
  392. else
  393. {
  394. tipMessage = success + "条," + fail + "条失败,原因:选择刷新的数据有误,请检查";
  395. }
  396. return tipMessage;
  397. }
  398. catch (Exception ex)
  399. {
  400. throw new Exception(ex.Message);
  401. }
  402. }
  403. /// <summary>
  404. /// 收费标准新增(批量新增,同时生成应收名单)
  405. /// </summary>
  406. /// <param name="gradeMajorIDs"></param>
  407. /// <param name="chargeStandardView"></param>
  408. /// <returns></returns>
  409. public string ChargeStandardAdd(List<Guid?> gradeMajorIDs, ChargeStandardView chargeStandardView)
  410. {
  411. try
  412. {
  413. //收费标准信息List
  414. var chargeStandardList = ChargeStandardDAL.ChargeStandardRepository
  415. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  416. //在校状态
  417. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  418. if (chargeStandardView.InSchoolStatus != null && chargeStandardView.InSchoolStatus > -1)
  419. {
  420. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  421. if (chargeStandardView.InSchoolStatus == 1)
  422. {
  423. //表示在校
  424. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  425. }
  426. if (chargeStandardView.InSchoolStatus == 0)
  427. {
  428. //不在校
  429. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  430. }
  431. }
  432. //各年级专业对应的学生信息List(含在校状态)
  433. var gradeMajorStudentList = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => gradeMajorIDs.Contains(x.GrademajorID),
  434. expStudent).ToList();
  435. //应收名单
  436. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  437. if (chargeStandardView.ChargeYear != null && chargeStandardView.ChargeYear.HasValue)
  438. {
  439. //缴费学年
  440. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeStandardView.ChargeYear);
  441. }
  442. if (chargeStandardView.ChargeProjectID != null && chargeStandardView.ChargeProjectID.HasValue)
  443. {
  444. //收费项目
  445. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeStandardView.ChargeProjectID);
  446. }
  447. //查询应收名单信息
  448. var studentChargeViewList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge,
  449. x => gradeMajorIDs.Contains(x.GrademajorID)).ToList();
  450. int success = 0; //成功
  451. int fail = 0; //失败
  452. string tipMessage = null; //提示消息
  453. List<EC_ChargeStandard> chargeStandardInList = new List<EC_ChargeStandard>();
  454. List<EC_StudentCharge> studentChargeInList = new List<EC_StudentCharge>();
  455. //注:收费标准业务主键(年级专业ID、学年、收费项目ID)
  456. foreach (var gradeMajorID in gradeMajorIDs)
  457. {
  458. var chargeStandardVerify = chargeStandardList.Where(x => x.GrademajorID == gradeMajorID
  459. && x.ChargeYear == chargeStandardView.ChargeYear
  460. && x.ChargeProjectID == chargeStandardView.ChargeProjectID)
  461. .SingleOrDefault();
  462. if (chargeStandardVerify == null)
  463. {
  464. //表示收费标准不存在
  465. EC_ChargeStandard chargeStandard = new EC_ChargeStandard();
  466. chargeStandard.ChargeStandardID = Guid.NewGuid();
  467. chargeStandard.GrademajorID = gradeMajorID;
  468. chargeStandard.ChargeProjectID = chargeStandardView.ChargeProjectID;
  469. chargeStandard.ChargeYear = chargeStandardView.ChargeYear;
  470. chargeStandard.Amount = chargeStandardView.Amount;
  471. SetNewStatus(chargeStandard, (int)SYS_STATUS.USABLE);
  472. chargeStandardInList.Add(chargeStandard);
  473. //查询年级专业对应的学生信息ID(含在校状态)
  474. var studentIDList = gradeMajorStudentList.Where(x => x.GradeMajorID == gradeMajorID)
  475. .Select(x => x.UserID).ToList();
  476. if (studentIDList != null && studentIDList.Count() > 0)
  477. {
  478. foreach (var studentID in studentIDList)
  479. {
  480. //对应的应收名单信息
  481. var studentChargeVerify = studentChargeViewList.Where(x => x.UserID == studentID)
  482. .SingleOrDefault();
  483. if (studentChargeVerify == null)
  484. {
  485. //表示不存在对应的应收名单
  486. EC_StudentCharge studentCharge = new EC_StudentCharge();
  487. studentCharge.StudentChargeID = Guid.NewGuid();
  488. studentCharge.UserID = studentID;
  489. studentCharge.ChargeProjectID = chargeStandardView.ChargeProjectID;
  490. studentCharge.ChargeYear = chargeStandardView.ChargeYear;
  491. studentCharge.Amount = chargeStandardView.Amount;
  492. studentCharge.ActualAmount = studentCharge.Amount; //减免后金额
  493. studentCharge.ChargeTag = (int)EC_ChargeTag.Normal; //默认为正常收费
  494. SetNewStatus(studentCharge, (int)SYS_STATUS.USABLE);
  495. studentChargeInList.Add(studentCharge);
  496. }
  497. else
  498. {
  499. //表示已存在对应的应收名单(可做更新)
  500. }
  501. }
  502. }
  503. else
  504. {
  505. //表示学生信息为空
  506. }
  507. success++;
  508. }
  509. else
  510. {
  511. //表示已存在相同的收费标准
  512. fail++;
  513. }
  514. }
  515. //批量插入
  516. UnitOfWork.BulkInsert<EC_ChargeStandard>(chargeStandardInList);
  517. UnitOfWork.BulkInsert<EC_StudentCharge>(studentChargeInList);
  518. if (success > 0 && fail <= 0)
  519. {
  520. tipMessage = success + "条";
  521. }
  522. else
  523. {
  524. tipMessage = success + "条," + fail + "条失败,原因:已存在相同的收费标准,请检查";
  525. }
  526. return tipMessage;
  527. }
  528. catch (Exception ex)
  529. {
  530. throw new Exception(ex.Message);
  531. }
  532. }
  533. /// <summary>
  534. /// 获取年级专业各在校状态学生
  535. /// </summary>
  536. /// <param name="grademajorID"></param>
  537. /// <param name="inschoolStatus"></param>
  538. /// <param name="pageIndex"></param>
  539. /// <param name="pageSize"></param>
  540. /// <returns></returns>
  541. public IGridResultSet<StudentsView> GetGradeMajorStudentViewGrid(Guid? grademajorID, int? inschoolStatus, int pageIndex, int pageSize)
  542. {
  543. //在校状态
  544. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  545. if (inschoolStatus != null && inschoolStatus > -1)
  546. {
  547. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  548. if (inschoolStatus == 1)
  549. {
  550. //表示在校
  551. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  552. }
  553. if (inschoolStatus == 0)
  554. {
  555. //不在校
  556. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  557. }
  558. }
  559. var query = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => x.GrademajorID == grademajorID, expStudent);
  560. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassMajorCode.Length)
  561. .OrderBy(x => x.ClassMajorCode).OrderBy(x => x.LoginID)
  562. .ToGridResultSet<StudentsView>(pageIndex, pageSize);
  563. }
  564. /// <summary>
  565. /// 获取年级专业各在校状态学生
  566. /// </summary>
  567. /// <param name="grademajorID"></param>
  568. /// <param name="inschoolStatus"></param>
  569. /// <returns></returns>
  570. public List<StudentsView> GetGradeMajorStudentViewGrid(Guid? grademajorID, int? inschoolStatus)
  571. {
  572. //在校状态
  573. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  574. if (inschoolStatus != null && inschoolStatus > -1)
  575. {
  576. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  577. if (inschoolStatus == 1)
  578. {
  579. //表示在校
  580. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  581. }
  582. if (inschoolStatus == 0)
  583. {
  584. //不在校
  585. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  586. }
  587. }
  588. var query = ChargeStandardDAL.GetGradeMajorStudentViewQueryAble(x => x.GrademajorID == grademajorID, expStudent);
  589. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassMajorCode.Length)
  590. .OrderBy(x => x.ClassMajorCode).OrderBy(x => x.LoginID)
  591. .ToList();
  592. }
  593. /// <summary>
  594. /// 获取收费标准对应的年级专业应收名单
  595. /// </summary>
  596. /// <param name="grademajorID"></param>
  597. /// <param name="chargeYearID"></param>
  598. /// <param name="chargeProjectID"></param>
  599. /// <param name="inschoolStatus"></param>
  600. /// <param name="pageIndex"></param>
  601. /// <param name="pageSize"></param>
  602. /// <returns></returns>
  603. public IGridResultSet<StudentChargeView> GetGradeMajorStudentChargeViewGrid(Guid? grademajorID, int? chargeYearID, Guid? chargeProjectID, int? inschoolStatus, int pageIndex, int pageSize)
  604. {
  605. //应收名单
  606. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  607. if (chargeYearID != null && chargeYearID.HasValue)
  608. {
  609. //缴费学年
  610. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
  611. }
  612. if (chargeProjectID != null && chargeProjectID.HasValue)
  613. {
  614. //收费项目
  615. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
  616. }
  617. //在校状态
  618. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  619. if (inschoolStatus != null && inschoolStatus > -1)
  620. {
  621. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  622. if (inschoolStatus == 1)
  623. {
  624. //表示在校
  625. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  626. }
  627. if (inschoolStatus == 0)
  628. {
  629. //不在校
  630. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  631. }
  632. }
  633. //年级专业
  634. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => true);
  635. if (grademajorID != null && grademajorID.HasValue)
  636. {
  637. expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
  638. }
  639. var query = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor);
  640. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassNo.Length)
  641. .OrderBy(x => x.ClassNo).OrderBy(x => x.StudentNo)
  642. .ToGridResultSet<StudentChargeView>(pageIndex, pageSize);
  643. }
  644. /// <summary>
  645. /// 获取收费标准对应的年级专业应收名单
  646. /// </summary>
  647. /// <param name="grademajorID"></param>
  648. /// <param name="chargeYearID"></param>
  649. /// <param name="chargeProjectID"></param>
  650. /// <param name="inschoolStatus"></param>
  651. /// <returns></returns>
  652. public List<StudentChargeView> GetGradeMajorStudentChargeViewGrid(Guid? grademajorID, int? chargeYearID, Guid? chargeProjectID, int? inschoolStatus)
  653. {
  654. //应收名单
  655. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  656. if (chargeYearID != null && chargeYearID.HasValue)
  657. {
  658. //缴费学年
  659. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeYearID);
  660. }
  661. if (chargeProjectID != null && chargeProjectID.HasValue)
  662. {
  663. //收费项目
  664. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeProjectID);
  665. }
  666. //在校状态
  667. Expression<Func<CF_Student, bool>> expStudent = (x => true);
  668. if (inschoolStatus != null && inschoolStatus > -1)
  669. {
  670. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  671. if (inschoolStatus == 1)
  672. {
  673. //表示在校
  674. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  675. }
  676. if (inschoolStatus == 0)
  677. {
  678. //不在校
  679. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  680. }
  681. }
  682. //年级专业
  683. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => true);
  684. if (grademajorID != null && grademajorID.HasValue)
  685. {
  686. expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
  687. }
  688. var query = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor);
  689. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.ClassNo.Length)
  690. .OrderBy(x => x.ClassNo).OrderBy(x => x.StudentNo)
  691. .ToList();
  692. }
  693. /// <summary>
  694. /// 查询收费标准信息View(ChargeStandardView)
  695. /// </summary>
  696. /// <param name="chargeStandardID"></param>
  697. /// <returns></returns>
  698. public ChargeStandardView GetChargeStandardView(Guid? chargeStandardID)
  699. {
  700. var query = ChargeStandardDAL.GetChargeStandarViewQueryAble(x => x.ChargeStandardID == chargeStandardID, x => true);
  701. return query.FirstOrDefault();
  702. }
  703. /// <summary>
  704. /// 查询收费标准信息实体
  705. /// </summary>
  706. /// <param name="chargeStandardID"></param>
  707. /// <returns></returns>
  708. public Entities.EC_ChargeStandard GetChargeStandard(Guid? chargeStandardID)
  709. {
  710. System.Linq.Expressions.Expression<Func<EC_ChargeStandard, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  711. expression = (x => x.ChargeStandardID == chargeStandardID);
  712. return ChargeStandardDAL.ChargeStandardRepository.GetSingle(expression);
  713. }
  714. /// <summary>
  715. /// 查询应收名单实体
  716. /// </summary>
  717. /// <param name="studentChargeID"></param>
  718. /// <returns></returns>
  719. public EC_StudentCharge GetStudentCharge(Guid? studentChargeID)
  720. {
  721. System.Linq.Expressions.Expression<Func<EC_StudentCharge, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  722. expression = (x => x.StudentChargeID == studentChargeID);
  723. return ChargeStandardDAL.StudentChargeRepository.GetSingle(expression);
  724. }
  725. /// <summary>
  726. /// 新增、修改(处理方式:当存在对应的应收名单时,无法修改)
  727. /// </summary>
  728. /// <param name="chargeStandardView"></param>
  729. /// <returns></returns>
  730. public void ChargeStandardEdit(ChargeStandardView chargeStandardView)
  731. {
  732. try
  733. {
  734. //查询数据库进行验证(需排除自己)
  735. var chargeStandardVerification = ChargeStandardDAL.ChargeStandardRepository.GetList(x => x.ChargeStandardID != chargeStandardView.ChargeStandardID
  736. && x.GrademajorID == chargeStandardView.GrademajorID
  737. && x.ChargeYear == chargeStandardView.ChargeYear
  738. && x.ChargeProjectID == chargeStandardView.ChargeProjectID)
  739. .SingleOrDefault();
  740. if (chargeStandardVerification == null)
  741. {
  742. //数据有误验证
  743. if (chargeStandardView.ChargeStandardID != Guid.Empty)
  744. {
  745. //表示修改
  746. var chargeStandard = ChargeStandardDAL.ChargeStandardRepository
  747. .GetList(x => x.ChargeStandardID == chargeStandardView.ChargeStandardID)
  748. .SingleOrDefault();
  749. if (chargeStandard == null)
  750. {
  751. throw new Exception("数据有误,请核查");
  752. }
  753. else
  754. {
  755. //应收名单
  756. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  757. if (chargeStandard.ChargeYear != null && chargeStandard.ChargeYear.HasValue)
  758. {
  759. //缴费学年
  760. expStudentCharge = expStudentCharge.And(x => x.ChargeYear == chargeStandard.ChargeYear);
  761. }
  762. if (chargeStandard.ChargeProjectID != null && chargeStandard.ChargeProjectID.HasValue)
  763. {
  764. //收费项目
  765. expStudentCharge = expStudentCharge.And(x => x.ChargeProjectID == chargeStandard.ChargeProjectID);
  766. }
  767. //年级专业
  768. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => true);
  769. if (chargeStandard.GrademajorID != null && chargeStandard.GrademajorID.HasValue)
  770. {
  771. expGrademajor = expGrademajor.And(x => x.GrademajorID == chargeStandard.GrademajorID);
  772. }
  773. //查询应收名单信息(业务主键:年级专业ID、缴费学年、收费项目ID)
  774. var studentChargeList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor).ToList();
  775. if (studentChargeList != null && studentChargeList.Count() > 0)
  776. {
  777. //表示已存在应收名单
  778. throw new Exception("已生成应收名单,如需修改请删除相关的应收名单信息");
  779. }
  780. else
  781. {
  782. //chargeStandard.GrademajorID = chargeStandardView.GrademajorID;
  783. //chargeStandard.ChargeProjectID = chargeStandardView.ChargeProjectID;
  784. //chargeStandard.ChargeYear = chargeStandardView.ChargeYear;
  785. chargeStandard.Amount = chargeStandardView.Amount;
  786. SetModifyStatus(chargeStandard);
  787. }
  788. }
  789. }
  790. else
  791. {
  792. //表示新增
  793. EC_ChargeStandard chargeStandard = new EC_ChargeStandard();
  794. chargeStandard.ChargeStandardID = Guid.NewGuid();
  795. chargeStandard.GrademajorID = chargeStandardView.GrademajorID;
  796. chargeStandard.ChargeProjectID = chargeStandardView.ChargeProjectID;
  797. chargeStandard.ChargeYear = chargeStandardView.ChargeYear;
  798. chargeStandard.Amount = chargeStandardView.Amount;
  799. SetNewStatus(chargeStandard, (int)SYS_STATUS.USABLE);
  800. UnitOfWork.Add(chargeStandard);
  801. }
  802. }
  803. else
  804. {
  805. throw new Exception("已存在相同的收费标准,请核查");
  806. }
  807. //事务提交
  808. UnitOfWork.Commit();
  809. }
  810. catch (Exception ex)
  811. {
  812. throw new Exception(ex.Message);
  813. }
  814. }
  815. /// <summary>
  816. /// 删除(当选择删除的信息中存在的应收名单时,无法删除)
  817. /// </summary>
  818. /// <param name="chargeStandardIDs"></param>
  819. /// <returns></returns>
  820. public bool ChargeStandardDelete(List<Guid> chargeStandardIDs)
  821. {
  822. try
  823. {
  824. //查询收费标准信息List
  825. var chargeStandardList = ChargeStandardDAL.ChargeStandardRepository
  826. .GetList(x => chargeStandardIDs.Contains(x.ChargeStandardID)).ToList();
  827. //年级专业IDList
  828. var gradeMajorIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString()))
  829. .Select(x => x.GrademajorID).ToList();
  830. //缴费学年IDList
  831. var chargeYearIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeYear.ToString()))
  832. .Select(x => x.ChargeYear).ToList();
  833. //收费项目IDList
  834. var chargeProjectIDList = chargeStandardList.Where(x => !string.IsNullOrEmpty(x.ChargeProjectID.ToString()))
  835. .Select(x => x.ChargeProjectID).ToList();
  836. //年级专业
  837. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => true);
  838. if (gradeMajorIDList != null && gradeMajorIDList.Count() > 0)
  839. {
  840. expGrademajor = expGrademajor.And(x => gradeMajorIDList.Contains(x.GrademajorID));
  841. }
  842. //应收名单
  843. Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => true);
  844. if (chargeYearIDList != null && chargeYearIDList.Count() > 0)
  845. {
  846. //缴费学年
  847. expStudentCharge = expStudentCharge.And(x => chargeYearIDList.Contains(x.ChargeYear));
  848. }
  849. if (chargeProjectIDList != null && chargeProjectIDList.Count() > 0)
  850. {
  851. //收费项目
  852. expStudentCharge = expStudentCharge.And(x => chargeProjectIDList.Contains(x.ChargeProjectID));
  853. }
  854. //查询应收名单信息(业务主键:年级专业ID、缴费学年、收费项目ID)
  855. var studentChargeList = ChargeStandardDAL.GetGradeMajorStudentChargeViewQueryAble(expStudentCharge, expGrademajor).ToList();
  856. //注:由于用户会选择多条信息进行删除
  857. //目前的删除逻辑暂时不处理更进一步的删除操作(如:同时存在可删除、不可删除的信息)
  858. if (studentChargeList != null && studentChargeList.Count() > 0)
  859. {
  860. //表示已存在应收名单
  861. throw new Exception("选择删除的信息中存在相应的应收名单,如需删除,请删除相关的应收名单信息。");
  862. }
  863. else
  864. {
  865. UnitOfWork.Delete<EC_ChargeStandard>(x => chargeStandardIDs.Contains(x.ChargeStandardID));
  866. }
  867. return true;
  868. }
  869. catch (Exception ex)
  870. {
  871. throw new Exception(ex.Message);
  872. }
  873. }
  874. /// <summary>
  875. /// 收费标准验证(业务主键:年级专业ID、缴费学年、收费项目ID)
  876. /// </summary>
  877. /// <param name="chargeStandardID"></param>
  878. /// <param name="grademajorID"></param>
  879. /// <param name="chargeYearID"></param>
  880. /// <param name="chargeProjectID"></param>
  881. /// <returns></returns>
  882. public string GetVerification(Guid? chargeStandardID, Guid? grademajorID, int? chargeYearID, Guid? chargeProjectID)
  883. {
  884. //查询数据库进行验证(需排除自己)
  885. var chargeStandard = ChargeStandardDAL.ChargeStandardRepository.GetList(x => x.ChargeStandardID != chargeStandardID
  886. && x.GrademajorID == grademajorID
  887. && x.ChargeYear == chargeYearID
  888. && x.ChargeProjectID == chargeProjectID)
  889. .SingleOrDefault();
  890. if (chargeStandard == null)
  891. {
  892. //数据有误验证
  893. if (chargeStandardID.HasValue && chargeStandardID != Guid.Empty)
  894. {
  895. chargeStandard = ChargeStandardDAL.ChargeStandardRepository.GetList(x => x.ChargeStandardID == chargeStandardID)
  896. .SingleOrDefault();
  897. if (chargeStandard == null)
  898. {
  899. return "数据有误,请核查";
  900. }
  901. else
  902. {
  903. return "成功";
  904. }
  905. }
  906. else
  907. {
  908. return "成功";
  909. }
  910. }
  911. else
  912. {
  913. return "已存在相同的收费标准";
  914. }
  915. }
  916. }
  917. }