StudentsOrderServices.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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.ViewModel.TeachingMaterial;
  7. using EMIS.DataLogic.Common.TeachingMaterial;
  8. using EMIS.DataLogic.Repositories;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using System.Diagnostics;
  12. using Bowin.Common.Linq;
  13. using System.Linq.Expressions;
  14. using System.Web;
  15. using EMIS.Utility;
  16. using EMIS.DataLogic.SystemDAL;
  17. using System.Collections;
  18. namespace EMIS.CommonLogic.TeachingMaterial
  19. {
  20. public class StudentsOrderServices : BaseServices, IStudentsOrderServices
  21. {
  22. #region --0.0 定义--
  23. public StudentsOrderDAL StudentsOrderDAL { get; set; }
  24. public StudentsOrderRepository StudentsOrderRepository { get; set; }
  25. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  26. public SchoolyearRepository SchoolyearRepository { get; set; }
  27. public UserRepository UserRepository { get; set; }
  28. public Lazy<StudentRepository> StudentRepository { get; set; }
  29. public CoursematerialRepository CoursematerialRepository { get; set; }
  30. public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
  31. public CollegeRepository CollegeRepository { get; set; }
  32. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  33. public GrademajorRepository GrademajorRepository { get; set; }
  34. public FacultymajorRepository FacultymajorRepository { get; set; }
  35. public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
  36. public ClassmajorRepository ClassmajorRepository { get; set; }
  37. public PublishRepository PublishRepository { get; set; }
  38. public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; }
  39. #region 1.0 查询学生征订记录
  40. /// <summary>
  41. /// 查询学生征订记录
  42. /// </summary>
  43. public IGridResultSet<StudentsOrderView> GetStudentsOrderViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID,
  44. Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID,
  45. Guid? teachingMaterialID, int pageIndex, int pageSize)
  46. {
  47. Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
  48. if (schoolyearID.HasValue)
  49. {
  50. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  51. }
  52. if (teachingMaterialID.HasValue)
  53. {
  54. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialID);
  55. }
  56. if (campusID.HasValue)
  57. {
  58. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  59. }
  60. if (collegeID.HasValue)
  61. {
  62. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  63. }
  64. if (years.HasValue)
  65. {
  66. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
  67. }
  68. if (grademajorID.HasValue)
  69. {
  70. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  71. }
  72. if (coursematerialID.HasValue)
  73. {
  74. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  75. }
  76. if (courseCategoryID.HasValue)
  77. {
  78. exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
  79. }
  80. if (isOrdered.HasValue && isOrdered > -1)
  81. {
  82. exp = exp.And(x => x.IsOrdered == (isOrdered == (int)CF_YesOrNoStatus.No ? false : true));
  83. }
  84. var query = StudentsOrderDAL.GetStudentsOrderGridView(exp);
  85. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  86. {
  87. var result = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).Distinct().OrderBy(x => x.CreateTime).ToGridResultSet<StudentsOrderView>(pageIndex, pageSize);
  88. var specialtyPlanIDLists = result.rows.Select(x => x.SpecialtyPlanID).ToList();
  89. List<SpecialtyPlanTeachingMaterPoolView> teachingMaterialPoolViews;
  90. //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出
  91. Expression<Func<EM_SpecialtyPlan, bool>> expSps = (w => true);
  92. if (schoolyearID.HasValue)
  93. {
  94. expSps = expSps.And(w => w.SchoolyearID == schoolyearID);
  95. }
  96. if (grademajorID.HasValue)
  97. {
  98. expSps = expSps.And(w => w.CF_Grademajor.GrademajorID == grademajorID);
  99. }
  100. if (collegeID.HasValue)
  101. {
  102. expSps = expSps.And(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  103. }
  104. if (coursematerialID.HasValue)
  105. {
  106. expSps = expSps.And(w => w.EM_Coursematerial.CoursematerialID == coursematerialID);
  107. }
  108. if (pageSize <= 20)
  109. {
  110. teachingMaterialPoolViews = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDLists.Contains(x.SpecialtyPlanID), w => true).ToList();
  111. }
  112. else
  113. {
  114. teachingMaterialPoolViews = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDLists.Contains(x.SpecialtyPlanID), expSps).Distinct().ToList();
  115. }
  116. result.rows.ForEach(x => x.SpecialtyPlanTeachingMaterPoolViewList = new HashSet<SpecialtyPlanTeachingMaterPoolView>(teachingMaterialPoolViews.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID).Distinct()));
  117. return result;
  118. }
  119. var resultSet = this.GetQueryByDataRangeByCollege(query).Distinct().OrderBy(x => x.SchoolyearCode).
  120. ThenByDescending(x => x.GrademajorCode).ToGridResultSet<StudentsOrderView>(pageIndex, pageSize);//.ThenByDescending(x => x.TeachingMaterialCode)
  121. var specialtyPlanIDList = resultSet.rows.Select(x => x.SpecialtyPlanID).ToList();
  122. List<SpecialtyPlanTeachingMaterPoolView> teachingMaterialPoolView;
  123. //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出
  124. Expression<Func<EM_SpecialtyPlan, bool>> expSp = (w => true);
  125. if (schoolyearID.HasValue)
  126. {
  127. expSp = expSp.And(w => w.SchoolyearID == schoolyearID);
  128. }
  129. if (grademajorID.HasValue)
  130. {
  131. expSp = expSp.And(w => w.CF_Grademajor.GrademajorID == grademajorID);
  132. }
  133. if (collegeID.HasValue)
  134. {
  135. expSp = expSp.And(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  136. }
  137. if (coursematerialID.HasValue)
  138. {
  139. expSp = expSp.And(w => w.EM_Coursematerial.CoursematerialID == coursematerialID);
  140. }
  141. if (pageSize <= 20)
  142. {
  143. teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), w => true).ToList();
  144. }
  145. else
  146. {
  147. teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), expSp).Distinct().ToList();
  148. }
  149. resultSet.rows.ForEach(x => x.SpecialtyPlanTeachingMaterPoolViewList = new HashSet<SpecialtyPlanTeachingMaterPoolView>(teachingMaterialPoolView.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID).Distinct()));
  150. return resultSet;
  151. }
  152. #endregion
  153. #region 2.0 生成征订计划
  154. /// <summary>
  155. /// 生成征订计划
  156. /// </summary>
  157. /// <param name="schoolyearID"></param>
  158. public void CreateStudentOrder(Guid schoolyearID, Guid userID)
  159. {
  160. //Stopwatch sw = new Stopwatch();//记录代码运行时间
  161. //Stopwatch sw2 = new Stopwatch();//记录代码运行时间
  162. try
  163. {
  164. //sw.Start();
  165. Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
  166. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  167. var planIdsList = StudentsOrderDAL.GetSpecialtyPlanBySchool(schoolyearID);
  168. var specialtyIdsList = planIdsList.Select(x => x.SpecialtyPlanID).ToList();
  169. var dbList = StudentsOrderDAL.GetStudentsOrderGridView(exp);
  170. var dbIdList = dbList.Select(x => x.SpecialtyPlanID).ToList();
  171. var newIdList = specialtyIdsList.Except(dbIdList).ToList();
  172. //if (specialtyIdsList.Count > 0)
  173. //{
  174. // UnitOfWork.Delete<ET_StudentsOrder>(x => specialtyIdsList.Contains(x.SpecialtyPlanID));//先删除、在生成、防止教材没有更新进去
  175. // //sw.Stop();
  176. //}
  177. //先删除再增加的做法不合适
  178. //TimeSpan TotalTime = sw.Elapsed;//sw.Elapsed记录了刚刚运行的代码段总时间
  179. var planQuery = StudentsOrderDAL.GetStudentsOrderBySpecialtyPlan(schoolyearID);
  180. var newplanQuery = planQuery.Where(x => newIdList.Contains(x.SpecialtyPlanID));
  181. List<StudentOrderPrePlanView> planList = this.GetQueryByDataRangeByCollege(newplanQuery).ToList();
  182. #region 0.0 废弃
  183. //foreach (var planView in planList)
  184. //{
  185. // var studentsOrderList = (from a in StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.TeachingMaterialPoolID == planView.TeachingMaterialPoolID)
  186. // group a by new { a.TeachingMaterialPoolID, a.SpecialtyPlanID, a.IsOrdered } into g
  187. // select new { SpecialtyPlanID = g.Key.SpecialtyPlanID, TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID, g.Key.IsOrdered }).ToList();
  188. // bool IsCreate = true;
  189. // foreach (var studentsOrder in studentsOrderList)
  190. // {
  191. // if (studentsOrder.IsOrdered != true)//已提交
  192. // {
  193. // IsCreate = false;
  194. // }
  195. // }
  196. // //如果该专业计划对应的课程信息 已提交、 那么可以再次生成、
  197. // if (IsCreate)
  198. // {
  199. // }
  200. // var StudentsOrderEntity = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.IsOrdered == false).FirstOrDefault();
  201. // if (StudentsOrderEntity != null && planView.TeachingMaterialPoolID != null)
  202. // {
  203. // StudentsOrderEntity.TeachingMaterialPoolID = planView.TeachingMaterialPoolID;
  204. // StudentsOrderEntity.ModifyTime = DateTime.Now;
  205. // StudentsOrderRepository.UnitOfWork.Update(StudentsOrderEntity);
  206. // }
  207. // else
  208. // {
  209. // var studentOrder = new ET_StudentsOrder
  210. // {
  211. // StudentsOrderID = Guid.NewGuid(),
  212. // IsOrdered = false,
  213. // OrderQty = planView.OrderQty.GetValueOrDefault(),
  214. // SpecialtyPlanID = planView.SpecialtyPlanID,
  215. // TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
  216. // CreateTime = DateTime.Now,
  217. // CreateUserID = userID,
  218. // ModifyUserID = userID,
  219. // ModifyTime = DateTime.Now
  220. // };
  221. // StudentsOrderRepository.UnitOfWork.Add(studentOrder);
  222. // }
  223. //}
  224. //StudentsOrderRepository.UnitOfWork.Commit();
  225. #endregion
  226. List<ET_StudentsOrder> listStudentsOrder = new List<ET_StudentsOrder>();//学生征订集合
  227. // sw2.Start();
  228. foreach (var planView in planList)
  229. {
  230. var studentOrder = new ET_StudentsOrder
  231. {
  232. StudentsOrderID = Guid.NewGuid(),
  233. IsOrdered = false,
  234. OrderQty = planView.OrderQty.GetValueOrDefault(),
  235. SpecialtyPlanID = planView.SpecialtyPlanID,
  236. TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
  237. CreateTime = DateTime.Now,
  238. CreateUserID = userID,
  239. ModifyUserID = userID,
  240. ModifyTime = DateTime.Now
  241. };
  242. listStudentsOrder.Add(studentOrder);
  243. // StudentsOrderRepository.UnitOfWork.Add(studentOrder);
  244. }
  245. UnitOfWork.BulkInsert(listStudentsOrder);
  246. // StudentsOrderRepository.UnitOfWork.Commit();
  247. //sw2.Stop();
  248. //TimeSpan TotalTime2 = sw2.Elapsed;//sw.Elapsed记录了刚刚运行的代码段总时间
  249. }
  250. catch (Exception ex)
  251. {
  252. throw ex;
  253. }
  254. }
  255. #endregion
  256. #region 3.0 指定征订教材
  257. /// <summary>
  258. /// 指定征订教材
  259. /// </summary>
  260. /// <param name="studentsOrderID"></param>
  261. /// <param name="teachingMaterialPoolID"></param>
  262. /// <param name="userID"></param>
  263. public void SpecifiedTeachingMaterialPool(List<Guid> studentsOrderID, List<Guid> teachingMaterialPoolID, List<Guid> specialtyPlanID, Guid userID)
  264. {
  265. try
  266. {
  267. List<ET_StudentsOrder> listStudentsOrder = new List<ET_StudentsOrder>();//学生征订集合
  268. //List<int> PreIncreaseQty = new List<int>();
  269. Hashtable QtyPre = new Hashtable();
  270. //指定教材后预加数量不变
  271. if (studentsOrderID.Count() > 0)
  272. {
  273. foreach (var ID in specialtyPlanID)
  274. {
  275. ET_StudentsOrder order = new ET_StudentsOrder();
  276. order = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == ID).FirstOrDefault();
  277. if (order != null)
  278. {
  279. //int qty = (int)(order.PreIncreaseQty == null ? 0 : order.PreIncreaseQty);
  280. QtyPre.Add(order.SpecialtyPlanID, order.PreIncreaseQty);
  281. }
  282. }
  283. }
  284. // var studentOrders = StudentsOrderDAL.GetStudentsOrderListByStudentsOrderIDs(studentsOrderID);
  285. List<EM_SpecialtyPlan> specialtyPlanList = SpecialtyPlanRepository.GetList(x => specialtyPlanID.Contains(x.SpecialtyPlanID), (x => x.CF_Grademajor), (x => x.EM_Coursematerial.CF_TeachingMaterialPool), (x => x.CF_Grademajor.CF_Classmajor)).ToList();
  286. // int studentCount = specialtyPlanEntity.CF_Grademajor.CF_Classmajor.Select(w => w.CF_Student).Count();
  287. if (specialtyPlanID.Count > 0)
  288. {
  289. UnitOfWork.Delete<ET_StudentsOrder>(x => specialtyPlanID.Contains(x.SpecialtyPlanID));//先删除、在生成、防止教材没有更新进去
  290. }
  291. if (specialtyPlanList.Count > 0)
  292. {
  293. foreach (var specialtyPlan in specialtyPlanList)
  294. {
  295. var ClassmajorIDList = specialtyPlan.CF_Grademajor.CF_Classmajor.Select(x => x.ClassmajorID).ToList();
  296. // var ClassmajorList = ClassmajorRepository.GetList(x => ClassmajorIDList.Contains(x.ClassmajorID), x => x.CF_Student).ToList();
  297. var studentCount = StudentRepository.Value.GetList(x => ClassmajorIDList.Contains((Guid)x.ClassmajorID)).Where(x => x.InSchoolStatusID==1).Count();
  298. //只获取在校的学生人数
  299. var specialtyTeachingMaterialPoolList = teachingMaterialPoolID;
  300. specialtyTeachingMaterialPoolList.ForEach(x =>
  301. {
  302. var studentOrder = new ET_StudentsOrder
  303. {
  304. StudentsOrderID = Guid.NewGuid(),
  305. IsOrdered = false,
  306. OrderQty = studentCount,
  307. PreIncreaseQty = (int?)QtyPre[specialtyPlan.SpecialtyPlanID],
  308. SpecialtyPlanID = specialtyPlan.SpecialtyPlanID,
  309. TeachingMaterialPoolID = x,
  310. CreateTime = DateTime.Now,
  311. CreateUserID = userID,
  312. ModifyUserID = userID,
  313. ModifyTime = DateTime.Now
  314. };
  315. listStudentsOrder.Add(studentOrder);
  316. });
  317. }
  318. }
  319. UnitOfWork.BulkInsert(listStudentsOrder);
  320. }
  321. catch (Exception ex)
  322. {
  323. throw ex;
  324. }
  325. }
  326. #endregion
  327. #region 4.0 删除征订的信息
  328. /// <summary>
  329. /// 删除征订的信息
  330. /// </summary>
  331. /// <param name="publishID"></param>
  332. public void DeleteStudentsOrders(List<Guid> specialtyPlanIDs)
  333. {
  334. try
  335. {
  336. //屏蔽已提交状态不可删除代码段
  337. //var stidentsOrderList = StudentsOrderRepository.GetList(x => studentsOrderIDs.Contains(x.StudentsOrderID)).ToList();
  338. //foreach (var stidentsOrder in stidentsOrderList)
  339. //{
  340. // if (stidentsOrder.IsOrdered == true)
  341. // {
  342. // throw new Exception("勾选信息包含已征订状态,不能删除!");
  343. // }
  344. //}
  345. UnitOfWork.Delete<ET_StudentsOrder>(x => specialtyPlanIDs.Contains(x.SpecialtyPlanID));
  346. }
  347. catch (Exception ex)
  348. {
  349. throw ex;
  350. }
  351. }
  352. #endregion
  353. #region 5.0 确认征订
  354. /// <summary>
  355. /// 确认征订
  356. /// </summary>
  357. /// <param name="studentsOrderID"></param>
  358. /// <param name="teachingMaterialPoolID"></param>
  359. /// <param name="userID"></param>
  360. public void ComfirmStudentOrder(List<Guid> specialtyPlanIs, Guid userID)
  361. {
  362. try
  363. {
  364. var studentOrders = StudentsOrderRepository.GetList(x => specialtyPlanIs.Contains(x.SpecialtyPlanID)).ToList();
  365. if (studentOrders.Any(x => x.TeachingMaterialPoolID == null))
  366. {
  367. throw new Exception("勾选的征订计划中,存在教材未指定。");
  368. }
  369. if (studentOrders.Any(x => x.IsOrdered == true))
  370. {
  371. throw new Exception("勾选的征订计划中,存在已征订状态。");
  372. }
  373. foreach (var studentOrder in studentOrders)
  374. {
  375. studentOrder.IsOrdered = true;
  376. studentOrder.ModifyTime = DateTime.Now;
  377. studentOrder.ModifyUserID = userID;
  378. }
  379. foreach (var studentsOrder in studentOrders.ToList())
  380. {
  381. UnitOfWork.Update(studentsOrder);
  382. }
  383. UnitOfWork.Commit();
  384. }
  385. catch (Exception ex)
  386. {
  387. throw ex;
  388. }
  389. }
  390. #endregion
  391. #region 6.0 查询学生征订记录(导出)
  392. /// <summary>
  393. /// 查询学生征订记录(导出)
  394. /// </summary>
  395. public IList<StudentsOrderView> GetStudentsOrderViewExcle(ViewModel.ConfiguretView configuretView, Guid? campusID,
  396. Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID, Guid? teachingMaterialID)
  397. {
  398. Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
  399. if (schoolyearID.HasValue)
  400. {
  401. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  402. }
  403. if (teachingMaterialID.HasValue)
  404. {
  405. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialID);
  406. }
  407. if (campusID.HasValue)
  408. {
  409. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  410. }
  411. if (collegeID.HasValue)
  412. {
  413. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  414. }
  415. if (years.HasValue)
  416. {
  417. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
  418. }
  419. if (grademajorID.HasValue)
  420. {
  421. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  422. }
  423. if (coursematerialID.HasValue)
  424. {
  425. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  426. }
  427. if (courseCategoryID.HasValue)
  428. {
  429. exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
  430. }
  431. if (isOrdered.HasValue && isOrdered > -1)
  432. {
  433. exp = exp.And(x => x.IsOrdered == (isOrdered == (int)CF_YesOrNoStatus.No ? false : true));
  434. }
  435. var query = StudentsOrderDAL.GetStudentsOrderGridView(exp);
  436. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  437. return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToList();
  438. // this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToList();
  439. var resultSet = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToList();//.ThenByDescending(x => x.TeachingMaterialCode)
  440. Expression<Func<EM_SpecialtyPlan, bool>> expSp = (w => true);
  441. var specialtyPlanIDList = resultSet.Select(x => x.SpecialtyPlanID).ToList();
  442. List<SpecialtyPlanTeachingMaterPoolView> teachingMaterialPoolView;
  443. //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出
  444. if (schoolyearID.HasValue)
  445. {
  446. expSp = expSp.And(w => w.SchoolyearID == schoolyearID);
  447. }
  448. if (grademajorID.HasValue)
  449. {
  450. expSp = expSp.And(w => w.CF_Grademajor.GrademajorID == grademajorID);
  451. }
  452. if (collegeID.HasValue)
  453. {
  454. expSp = expSp.And(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  455. }
  456. if (coursematerialID.HasValue)
  457. {
  458. expSp = expSp.And(w => w.EM_Coursematerial.CoursematerialID == collegeID);
  459. }
  460. if (resultSet.Count() <= 20)
  461. {
  462. teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), w => true).ToList();
  463. }
  464. else
  465. {
  466. teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), expSp).ToList();
  467. }
  468. resultSet.ForEach(x => x.SpecialtyPlanTeachingMaterPoolViewList = new HashSet<SpecialtyPlanTeachingMaterPoolView>(teachingMaterialPoolView.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID)));
  469. return resultSet;
  470. }
  471. #endregion
  472. #region 7.0 学生征订统计
  473. /// <summary>
  474. /// 学生征订统计
  475. /// </summary>
  476. public IGridResultSet<StudentsOrderShowReportView> GetStudentsOrderStatisticalViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID,
  477. Guid? collegeID, Guid? grademajorID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID,
  478. int pageIndex, int pageSize)
  479. {
  480. Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
  481. if (schoolyearID.HasValue)
  482. {
  483. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  484. }
  485. if (campusID.HasValue)
  486. {
  487. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  488. }
  489. if (collegeID.HasValue)
  490. {
  491. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  492. }
  493. if (teachingMaterialPoolID.HasValue)
  494. {
  495. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
  496. }
  497. if (grademajorID.HasValue)
  498. {
  499. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  500. }
  501. if (coursematerialID.HasValue)
  502. {
  503. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  504. }
  505. if (publishID.HasValue)
  506. {
  507. exp = exp.And(x => x.CF_TeachingMaterialPool.CF_Publish.PublishID == publishID);
  508. }
  509. var query = StudentsOrderDAL.GetStudentsOrderStatisticalView(exp.And(x => x.IsOrdered == true));
  510. //if (campusID.HasValue)
  511. // query = query.Where(x => x.CampusID == campusID);
  512. //if (collegeID.HasValue)
  513. // query = query.Where(x => x.CollegeID == collegeID);
  514. //if (schoolyearID.HasValue)
  515. // query = query.Where(x => x.SchoolyearID == schoolyearID);
  516. //if (grademajorID.HasValue)
  517. // query = query.Where(x => x.GrademajorID == grademajorID);
  518. //if (coursematerialID.HasValue)
  519. // query = query.Where(x => x.CoursematerialID == coursematerialID);
  520. //if (teachingMaterialPoolID.HasValue)
  521. // query = query.Where(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
  522. //if (publishID.HasValue)
  523. // query = query.Where(x => x.PublishID == publishID);
  524. IQueryable<StudentsOrderDataReportView> preGroupSql = null;
  525. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  526. {
  527. preGroupSql = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  528. }
  529. else { preGroupSql = this.GetQueryByDataRangeByCollege(query); }
  530. var studentsOrderShowReportView = (from pg in preGroupSql
  531. group pg by new
  532. {
  533. SchoolyearCode = pg.SchoolyearCode,
  534. CollegeName = pg.CollegeName,
  535. GrademajorName = pg.GrademajorName,
  536. CourseCode = pg.CourseCode,
  537. CourseName = pg.CourseName,
  538. TeachingMaterialCode = pg.TeachingMaterialCode,
  539. TeachingMaterialName = pg.TeachingMaterialName,
  540. ISBN = pg.ISBN,
  541. PublishTime = pg.PublishTime,
  542. PublishName = pg.PublishName,
  543. Author = pg.Author,
  544. Price = pg.Price,
  545. } into g
  546. select new StudentsOrderShowReportView
  547. {
  548. Price = g.Key.Price,
  549. Author = g.Key.Author,
  550. GrademajorName = g.Key.GrademajorName,
  551. CollegeName = g.Key.CollegeName,
  552. CourseCode = g.Key.CourseCode,
  553. CourseName = g.Key.CourseName,
  554. ISBN = g.Key.ISBN,
  555. PublishName = g.Key.PublishName,
  556. PublishTime = g.Key.PublishTime,
  557. SchoolyearCode = g.Key.SchoolyearCode,
  558. TeachingMaterialCode = g.Key.TeachingMaterialCode,
  559. OrderQty = g.Sum(x => x.OrderQty),
  560. PreIncreaseQty = g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty),
  561. Count = g.Sum(x => x.OrderQty) + (g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty)),
  562. ClassNum = g.Sum(x => x.ClassNum),
  563. TeachingMaterialName = g.Key.TeachingMaterialName
  564. }).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.CollegeName).ThenBy(x => x.GrademajorName).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<StudentsOrderShowReportView>(pageIndex, pageSize);
  565. return studentsOrderShowReportView;
  566. }
  567. #endregion
  568. #region 8.0 学生征订统计(导出)
  569. /// <summary>
  570. /// 学生征订统计(导出)
  571. /// </summary>
  572. public IList<StudentsOrderShowReportView> GetStudentsOrderStatisticalExcel(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID,
  573. Guid? collegeID, Guid? grademajorID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID)
  574. {
  575. Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
  576. if (schoolyearID.HasValue)
  577. {
  578. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  579. }
  580. if (campusID.HasValue)
  581. {
  582. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  583. }
  584. if (collegeID.HasValue)
  585. {
  586. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  587. }
  588. if (teachingMaterialPoolID.HasValue)
  589. {
  590. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
  591. }
  592. if (grademajorID.HasValue)
  593. {
  594. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  595. }
  596. if (coursematerialID.HasValue)
  597. {
  598. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  599. }
  600. if (publishID.HasValue)
  601. {
  602. exp = exp.And(x => x.CF_TeachingMaterialPool.CF_Publish.PublishID == publishID);
  603. }
  604. var query = StudentsOrderDAL.GetStudentsOrderStatisticalView(exp.And(x => x.IsOrdered == true));
  605. IQueryable<StudentsOrderDataReportView> preGroupSql = null;
  606. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  607. {
  608. preGroupSql = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  609. }
  610. else { preGroupSql = this.GetQueryByDataRangeByCollege(query); }
  611. var studentsOrderShowReportView = (from pg in preGroupSql
  612. group pg by new
  613. {
  614. SchoolyearCode = pg.SchoolyearCode,
  615. CollegeName = pg.CollegeName,
  616. GrademajorName = pg.GrademajorName,
  617. CourseCode = pg.CourseCode,
  618. CourseName = pg.CourseName,
  619. TeachingMaterialCode = pg.TeachingMaterialCode,
  620. TeachingMaterialName = pg.TeachingMaterialName,
  621. ISBN = pg.ISBN,
  622. PublishTime = pg.PublishTime,
  623. PublishName = pg.PublishName,
  624. PreIncreaseQty = pg.PreIncreaseQty,
  625. //Count = pg.Count,
  626. Author = pg.Author,
  627. Price = pg.Price
  628. } into g
  629. select new StudentsOrderShowReportView
  630. {
  631. Author = g.Key.Author,
  632. GrademajorName = g.Key.GrademajorName,
  633. CollegeName = g.Key.CollegeName,
  634. CourseCode = g.Key.CourseCode,
  635. CourseName = g.Key.CourseName,
  636. ISBN = g.Key.ISBN,
  637. PublishName = g.Key.PublishName,
  638. PublishTime = g.Key.PublishTime,
  639. Price = g.Key.Price,
  640. SchoolyearCode = g.Key.SchoolyearCode,
  641. TeachingMaterialCode = g.Key.TeachingMaterialCode,
  642. PreIncreaseQty = g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty),
  643. Count = g.Sum(x => x.OrderQty) + (g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty)),
  644. OrderQty = g.Sum(x => x.OrderQty),
  645. ClassNum = g.Sum(x => x.ClassNum),
  646. TeachingMaterialName = g.Key.TeachingMaterialName
  647. }).OrderBy(x => x.GrademajorName).ToList();
  648. return studentsOrderShowReportView;
  649. }
  650. #endregion
  651. /// <summary>
  652. /// 批量添加预加设置
  653. /// </summary>
  654. /// <param name="teachersOrderList"></param>
  655. /// <param name="preAddedValue"></param>
  656. /// <param name="userId"></param>
  657. public void BatchUpdatePreAddedValue(List<StudentsOrderView> studentsOrderList, int preAddedValue, Guid userId)
  658. {
  659. try
  660. {
  661. if (studentsOrderList.Count > 0)
  662. {
  663. //int? ApprovalStatus = (int)CF_TeachersOrderStatus.Completed;//提取已通过
  664. foreach (var studentsOrder in studentsOrderList)
  665. {
  666. var studentsPreOrderEnt = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == studentsOrder.SpecialtyPlanID);//.FirstOrDefault();//&& x.SchoolyearID == teachersOrder.SchoolyearID && x.ApprovalStatus == ApprovalStatus
  667. foreach (var s in studentsPreOrderEnt)
  668. {
  669. ET_StudentsOrder studentsPreOrder = s;
  670. studentsPreOrder.ModifyTime = DateTime.Now;
  671. studentsPreOrder.ModifyUserID = userId;
  672. //studentsPreOrder.Desc = "预加值";
  673. studentsPreOrder.PreIncreaseQty = preAddedValue;//设置预加值;
  674. StudentsOrderRepository.UnitOfWork.Update(studentsPreOrder);
  675. }
  676. }
  677. UnitOfWork.Commit();
  678. }
  679. }
  680. catch (Exception ex)
  681. {
  682. throw ex;
  683. }
  684. }
  685. /// <summary>
  686. /// 修改征订数量
  687. /// </summary>
  688. /// <param name="teachersOrderList"></param>
  689. /// <param name="preAddedValue"></param>
  690. /// <param name="userId"></param>
  691. public void UpdateOrderQty(List<StudentsOrderView> studentsOrderList, int orderQty, Guid userId)
  692. {
  693. try
  694. {
  695. if (studentsOrderList.Count > 0)
  696. {
  697. //int? ApprovalStatus = (int)CF_TeachersOrderStatus.Completed;//提取已通过
  698. foreach (var studentsOrder in studentsOrderList)
  699. {
  700. var studentsPreOrderEnt = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == studentsOrder.SpecialtyPlanID);//.FirstOrDefault();//&& x.SchoolyearID == teachersOrder.SchoolyearID && x.ApprovalStatus == ApprovalStatus
  701. foreach (var s in studentsPreOrderEnt)
  702. {
  703. ET_StudentsOrder studentsPreOrder = s;
  704. studentsPreOrder.ModifyTime = DateTime.Now;
  705. studentsPreOrder.ModifyUserID = userId;
  706. //studentsPreOrder.Desc = "预加值";
  707. studentsPreOrder.OrderQty = orderQty;//设置预加值;
  708. StudentsOrderRepository.UnitOfWork.Update(studentsPreOrder);
  709. }
  710. }
  711. UnitOfWork.Commit();
  712. }
  713. }
  714. catch (Exception ex)
  715. {
  716. throw ex;
  717. }
  718. }
  719. public IList<StudentsOrderShowReportView> GetStudentsOrderViewAggregateExcle(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID, Guid? teachingMaterialID)
  720. {
  721. Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
  722. if (schoolyearID.HasValue)
  723. {
  724. exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  725. }
  726. if (teachingMaterialID.HasValue)
  727. {
  728. exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialID);
  729. }
  730. if (campusID.HasValue)
  731. {
  732. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
  733. }
  734. if (collegeID.HasValue)
  735. {
  736. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
  737. }
  738. if (years.HasValue)
  739. {
  740. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
  741. }
  742. if (grademajorID.HasValue)
  743. {
  744. exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
  745. }
  746. if (coursematerialID.HasValue)
  747. {
  748. exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
  749. }
  750. if (courseCategoryID.HasValue)
  751. {
  752. exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
  753. }
  754. if (isOrdered.HasValue && isOrdered > -1)
  755. {
  756. exp = exp.And(x => x.IsOrdered == (isOrdered == (int)CF_YesOrNoStatus.No ? false : true));
  757. }
  758. var query = StudentsOrderDAL.GetStudentsOrderStatisticalView(exp);
  759. IQueryable<StudentsOrderDataReportView> preGroupSql = null;
  760. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  761. {
  762. preGroupSql = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  763. }
  764. else { preGroupSql = this.GetQueryByDataRangeByCollege(query); }
  765. var studentsOrderShowReportView = (from pg in preGroupSql
  766. group pg by new
  767. {
  768. SchoolyearCode = pg.SchoolyearCode,
  769. CollegeName = pg.CollegeName,
  770. GrademajorName = pg.GrademajorName,
  771. CourseCode = pg.CourseCode,
  772. CourseName = pg.CourseName,
  773. TeachingMaterialCode = pg.TeachingMaterialCode,
  774. TeachingMaterialName = pg.TeachingMaterialName,
  775. ISBN = pg.ISBN,
  776. PublishTime = pg.PublishTime,
  777. PublishName = pg.PublishName,
  778. Author = pg.Author,
  779. Price = pg.Price,
  780. TeachingMaterialTypeID = pg.TeachingMaterialTypeID,
  781. } into g
  782. select new StudentsOrderShowReportView
  783. {
  784. Author = g.Key.Author,
  785. GrademajorName = g.Key.GrademajorName,
  786. CollegeName = g.Key.CollegeName,
  787. CourseCode = g.Key.CourseCode,
  788. CourseName = g.Key.CourseName,
  789. ISBN = g.Key.ISBN,
  790. PublishName = g.Key.PublishName,
  791. PublishTime = g.Key.PublishTime,
  792. SchoolyearCode = g.Key.SchoolyearCode,
  793. TeachingMaterialCode = g.Key.TeachingMaterialCode,
  794. OrderQty = g.Sum(x => x.OrderQty),
  795. Count = g.Sum(x => x.Count),
  796. PreIncreaseQty = g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty),
  797. ClassNum = g.Sum(x => x.ClassNum),
  798. TeachingMaterialName = g.Key.TeachingMaterialName,
  799. Price = g.Key.Price,
  800. TeachingMaterialTypeID = g.Key.TeachingMaterialTypeID
  801. }).OrderBy(x => x.GrademajorName).ToList();
  802. return studentsOrderShowReportView;
  803. }
  804. }
  805. }
  806. #endregion