MinorSpecialtyServices.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.MinorManage.MinorPlanManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel.MinorManage.MinorPlanManage;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. using EMIS.CommonLogic.MinorManage.MinorApply;
  13. using EMIS.DataLogic.MinorManage.MinorApply;
  14. using EMIS.ViewModel.CacheManage;
  15. using EMIS.ViewModel.Students;
  16. namespace EMIS.CommonLogic.MinorManage.MinorPlanManage
  17. {
  18. public class MinorSpecialtyServices : BaseServices, IMinorSpecialtyServices
  19. {
  20. public MinorSpecialtyDAL MinorSpecialtyDAL { get; set; }
  21. public IMinorApplyServices minorApplyServices { get; set; }
  22. public MinorApplyDAL minorApplyDAL { get; set; }
  23. public IGridResultSet<MinorSpecialtyView> GetMinorSpecialtyViewGrid(ConfiguretView configuretView, int? yearID, int? standardID, Guid? collegeID, int? grademinorStatus, int pageIndex, int pageSize)
  24. {
  25. Expression<Func<CF_Grademinor, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  26. if (yearID.HasValue)
  27. exp = exp.And(x => x.YearID == yearID);
  28. if (standardID.HasValue)
  29. exp = exp.And(x => x.StandardID == standardID);
  30. if (collegeID.HasValue)
  31. exp = exp.And(x => x.CollegeID == collegeID);
  32. if (grademinorStatus.HasValue)
  33. exp = exp.And(x => x.RecordStatus == grademinorStatus);
  34. var query = MinorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp);
  35. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  36. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  37. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.YearID).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  38. .ThenByDescending(x => x.StandardID).ThenByDescending(x => x.CreateTime).ToGridResultSet<MinorSpecialtyView>(pageIndex, pageSize);
  39. return result;
  40. }
  41. public List<MinorSpecialtyView> GetMinorSpecialtyViewList(ConfiguretView configuretView, int? yearID, int? standardID, Guid? collegeID, int? grademinorStatus, List<Guid?> GrademinorIDList)
  42. {
  43. Expression<Func<CF_Grademinor, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  44. if (GrademinorIDList != null)
  45. exp = exp.And(x => GrademinorIDList.Contains(x.GrademinorID));
  46. if (yearID.HasValue)
  47. exp = exp.And(x => x.YearID == yearID);
  48. if (standardID.HasValue)
  49. exp = exp.And(x => x.StandardID == standardID);
  50. if (collegeID.HasValue)
  51. exp = exp.And(x => x.CollegeID == collegeID);
  52. if (grademinorStatus.HasValue)
  53. exp = exp.And(x => x.RecordStatus == grademinorStatus);
  54. var query = MinorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp);
  55. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  56. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  57. return this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.YearID).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  58. .ThenByDescending(x => x.StandardID).ThenByDescending(x => x.CreateTime).ToList();
  59. }
  60. public MinorSpecialtyView GetMinorSpecialtyView(Guid? GrademinorID)
  61. {
  62. Expression<Func<CF_Grademinor, bool>> exp = (x => x.GrademinorID == GrademinorID);
  63. var query = MinorSpecialtyDAL.GetMinorSpecialtyViewQueryable(exp).FirstOrDefault();
  64. return query;
  65. }
  66. public bool MinorSpecialtyOpen(List<Guid?> IDList)
  67. {
  68. try
  69. {
  70. if (IDList.Count > 0)
  71. {
  72. var MinorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => IDList.Contains(x.GrademinorID)).ToList();
  73. foreach (var MinorSpecialty in MinorSpecialtyList)
  74. {
  75. CF_Grademinor Grademinor = MinorSpecialty;
  76. Grademinor.RecordStatus = (int)CF_GrademinorStatus.Opened;
  77. SetModifyStatus(Grademinor);
  78. UnitOfWork.Commit();
  79. }
  80. }
  81. return true;
  82. }
  83. catch (Exception)
  84. {
  85. throw;
  86. }
  87. }
  88. public bool MinorSpecialtyCancel(List<Guid?> IDList)
  89. {
  90. try
  91. {
  92. if (IDList.Count > 0)
  93. {
  94. var MinorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => IDList.Contains(x.GrademinorID)).ToList();
  95. foreach (var MinorSpecialty in MinorSpecialtyList)
  96. {
  97. CF_Grademinor Grademinor = MinorSpecialty;
  98. Grademinor.RecordStatus = (int)CF_GrademinorStatus.NotOpened;
  99. SetModifyStatus(Grademinor);
  100. UnitOfWork.Commit();
  101. }
  102. }
  103. return true;
  104. }
  105. catch (Exception)
  106. {
  107. throw;
  108. }
  109. }
  110. /// <summary>
  111. /// 开班
  112. /// </summary>
  113. /// <param name="iDList"></param>
  114. public void OpenClass(List<Guid?> iDList)
  115. {
  116. try
  117. {
  118. if (iDList.Count > 0)
  119. {
  120. Expression<Func<EM_StudentMinorRegist, bool>> exp = x => true;
  121. Expression<Func<CF_Classmajor, bool>> expcla = x => true;
  122. Expression<Func<CF_College, bool>> expcol = x => true;
  123. var endStatusID = minorApplyServices.GetCorrectEndStatus();
  124. var inputStatus = minorApplyServices.GetStartApproveStatusList();
  125. //获取所有的辅修报名信息
  126. var minorStudentList = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol);
  127. var minorApplyViewList = this.GetQueryByDataRangeByCollege(minorStudentList).ToList();
  128. //var query = minorApplyViewList.GroupBy(x => new
  129. //{
  130. // x.GrademinorID,
  131. //}).ToList();
  132. List<CF_Classminor> classminorList = new List<CF_Classminor>();
  133. var minorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => iDList.Contains(x.GrademinorID)).ToList();
  134. foreach (var minorSpecialty in minorSpecialtyList)
  135. {
  136. if (minorSpecialty.RecordStatus != (int)CF_GrademinorStatus.Opened)
  137. {
  138. throw new Exception("只能对 已开放 状态的辅修专业进行开班");
  139. }
  140. //还有没有处理完的学生报名信息不让开班
  141. if (minorStudentList.Any(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID && inputStatus.Contains(x.RecordStatus)))
  142. {
  143. throw new Exception("所选辅修专业对应的学生报名信息存在未处理完的,请处理完再开班");
  144. }
  145. CF_Grademinor Grademinor = minorSpecialty;
  146. Grademinor.RecordStatus = (int)CF_GrademinorStatus.Confirmed;
  147. SetModifyStatus(Grademinor);
  148. UnitOfWork.Commit();
  149. //生成辅修班级
  150. var standardName = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard.ToString()).Where(x => x.Value == minorSpecialty.StandardID).Select(x => x.Name).FirstOrDefault();
  151. CF_Classminor classminor = new CF_Classminor();
  152. classminor.ClassminorID = Guid.NewGuid();
  153. classminor.GrademinorID = minorSpecialty.GrademinorID;
  154. classminor.Name = minorSpecialty.YearID.ToString() + standardName + "辅修班";
  155. classminor.Abbreviation = classminor.Name;
  156. classminor.ClassNum = 1;
  157. SetNewStatus(classminor);
  158. if (minorApplyViewList.Where(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID).Count() <= 0)
  159. {
  160. throw new Exception("所选的辅修专业没有学生报名,不能开班");
  161. }
  162. if (minorApplyViewList.Where(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID && x.RecordStatus == endStatusID).Count() > 0)
  163. {
  164. var Student = minorApplyViewList.Where(x => x.GrademinorID == minorSpecialty.GrademinorID && x.GradeYearID == minorSpecialty.YearID && x.RecordStatus == endStatusID).Select(x => new CF_ClassminorStudent
  165. {
  166. ClassminorStudentID = Guid.NewGuid(),
  167. ClassminorID = classminor.ClassminorID,
  168. UserID = x.UserID.Value,
  169. RecordStatus = (int)SYS_STATUS.USABLE,
  170. CreateTime = DateTime.Now,
  171. CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  172. ModifyTime = DateTime.Now,
  173. ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  174. });
  175. classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>(Student.ToList());
  176. }
  177. else
  178. {
  179. classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>();
  180. }
  181. classminorList.Add(classminor);
  182. }
  183. UnitOfWork.BulkInsert(classminorList);
  184. UnitOfWork.BulkInsert(classminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
  185. }
  186. }
  187. catch (Exception)
  188. {
  189. throw;
  190. }
  191. }
  192. /// <summary>
  193. /// 取消开班
  194. /// </summary>
  195. /// <param name="idList"></param>
  196. public void CancelClass(List<Guid?> idList)
  197. {
  198. try
  199. {
  200. if (idList.Count > 0)
  201. {
  202. var minorSpecialtyList = MinorSpecialtyDAL.GrademinorRepository.GetList(x => idList.Contains(x.GrademinorID)).ToList();
  203. foreach (var minorSpecialty in minorSpecialtyList)
  204. {
  205. if (minorSpecialty.RecordStatus != (int)CF_GrademinorStatus.Opened)
  206. {
  207. throw new Exception("只能对 已开放 状态的辅修专业取消开班");
  208. }
  209. CF_Grademinor grademinor = minorSpecialty;
  210. grademinor.RecordStatus = (int)CF_GrademinorStatus.Cancelled;
  211. SetModifyStatus(grademinor);
  212. UnitOfWork.Commit();
  213. }
  214. }
  215. }
  216. catch (Exception)
  217. {
  218. throw;
  219. }
  220. }
  221. public IGridResultSet<StudentsView> GetStudentsByGrademinorID(Guid grademinorID)
  222. {
  223. Expression<Func<EM_StudentMinorRegist, bool>> exp = x => x.GrademinorID == grademinorID;
  224. var query = MinorSpecialtyDAL.GetStudentsQueryable(exp);
  225. return query.OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>();
  226. }
  227. }
  228. }