MinorClassServices.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.MinorManage.MinorClass;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel.MinorManage.MinorClass;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. using EMIS.DataLogic.MinorManage.MinorApply;
  13. using EMIS.CommonLogic.MinorManage.MinorApply;
  14. using EMIS.ViewModel.MinorManage.MinorApply;
  15. using EMIS.ViewModel.Students;
  16. using EMIS.DataLogic.MinorManage.MinorPlanManage;
  17. using EMIS.ViewModel.CacheManage;
  18. namespace EMIS.CommonLogic.MinorManage.MinorClass
  19. {
  20. public class MinorClassServices : BaseServices, IMinorClassServices
  21. {
  22. public MinorClassDAL minorClassDAL { get; set; }
  23. public MinorApplyDAL minorApplyDAL { get; set; }
  24. public IMinorApplyServices minorApplyServices { get; set; }
  25. public MinorSpecialtyDAL minorSpecialtyDAL { get; set; }
  26. /// <summary>
  27. /// 获取辅修班级信息
  28. /// </summary>
  29. /// <param name="configuretView"></param>
  30. /// <param name="collegeID"></param>
  31. /// <param name="yearID"></param>
  32. /// <param name="standardID"></param>
  33. /// <param name="approvalStatus"></param>
  34. /// <param name="pageIndex"></param>
  35. /// <param name="pageSize"></param>
  36. /// <returns></returns>
  37. public IGridResultSet<MinorClassView> GetMinorClassViewGrid(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int? classminorStatus, int pageIndex, int pageSize)
  38. {
  39. Expression<Func<CF_Classminor, bool>> exp = (x => true);
  40. Expression<Func<CF_Grademinor, bool>> expgm = (x => true);
  41. if (collegeID.HasValue)
  42. {
  43. expgm = expgm.And(x => x.CollegeID == collegeID);
  44. }
  45. if (yearID.HasValue)
  46. {
  47. expgm = expgm.And(x => x.YearID == yearID);
  48. }
  49. if (standardID.HasValue)
  50. {
  51. expgm = expgm.And(x => x.StandardID == standardID);
  52. }
  53. if (classminorStatus.HasValue)
  54. {
  55. exp = exp.And(x => x.RecordStatus == classminorStatus);
  56. }
  57. var query = minorClassDAL.GetMinorClassViewQueryable(exp, expgm);
  58. //查询条件
  59. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  60. {
  61. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  62. }
  63. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.GradeYearID).ThenBy(x => x.StandardID).ToGridResultSet<MinorClassView>(pageIndex, pageSize);
  64. return result;
  65. }
  66. /// <summary>
  67. /// 获取辅修班级信息(Excel)
  68. /// </summary>
  69. /// <param name="configuretView"></param>
  70. /// <param name="collegeID"></param>
  71. /// <param name="yearID"></param>
  72. /// <param name="standardID"></param>
  73. /// <param name="approvalStatus"></param>
  74. /// <param name="idList"></param>
  75. /// <returns></returns>
  76. public List<MinorClassView> GetMinorClassViewList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int? classminorStatus, List<Guid?> idList)
  77. {
  78. Expression<Func<CF_Classminor, bool>> exp = (x => true);
  79. Expression<Func<CF_Grademinor, bool>> expgm = (x => true);
  80. if (collegeID.HasValue)
  81. {
  82. expgm = expgm.And(x => x.CollegeID == collegeID);
  83. }
  84. if (yearID.HasValue)
  85. {
  86. expgm = expgm.And(x => x.YearID == yearID);
  87. }
  88. if (standardID.HasValue)
  89. {
  90. expgm = expgm.And(x => x.StandardID == standardID);
  91. }
  92. if (classminorStatus.HasValue)
  93. {
  94. exp = exp.And(x => x.RecordStatus == classminorStatus);
  95. }
  96. if (idList.Count > 0 && idList != null)
  97. {
  98. exp = exp.And(x => idList.Contains(x.ClassminorID));
  99. }
  100. var query = minorClassDAL.GetMinorClassViewQueryable(exp, expgm);
  101. //查询条件
  102. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  103. {
  104. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  105. }
  106. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.GradeYearID).ThenBy(x => x.StandardID).ToList();
  107. return result;
  108. }
  109. public void GenerateMinorClass()
  110. {
  111. try
  112. {
  113. Expression<Func<EM_StudentMinorRegist, bool>> exp = x => true;
  114. Expression<Func<CF_Classmajor, bool>> expcla = x => true;
  115. Expression<Func<CF_College, bool>> expcol = x => true;
  116. List<CF_Classminor> addClassminorList = new List<CF_Classminor>();
  117. List<CF_Classminor> updateClassminorList = new List<CF_Classminor>();
  118. var endStatusID = minorApplyServices.GetCorrectEndStatus();
  119. exp = exp.And(x => x.RecordStatus == endStatusID);
  120. var minorStudentList = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol);
  121. var dbClassList = minorClassDAL.GetMinorClassViewQueryable(x => true, x => true).ToList();
  122. //Expression<Func<CF_ClassminorStudent, bool>> stuexp = x => true;
  123. //var dbstudent = minorClassDAL.GetStudentsQueryable(stuexp);
  124. var gradeMinorList = minorSpecialtyDAL.GetMinorSpecialtyViewQueryable(x => x.RecordStatus == (int)CF_GrademinorStatus.Opened);
  125. var minorApplyViewList = this.GetQueryByDataRangeByCollege(minorStudentList).ToList();
  126. var gmquery = gradeMinorList.GroupBy(x => new
  127. {
  128. x.SchoolyearID,
  129. x.GrademinorID,
  130. x.YearID,
  131. x.StandardID,
  132. }).ToList();
  133. var query = minorApplyViewList.GroupBy(x => new
  134. {
  135. x.SchoolyearID,
  136. x.GrademinorID,
  137. x.GradeYearID,
  138. x.GrademinorName
  139. }).ToList();
  140. foreach (var grademinor in gmquery)
  141. {
  142. CF_Classminor classminor = new CF_Classminor();
  143. if (dbClassList.Any(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID && x.RecordStatus != (int)CF_ClassminorStatus.NotOpen))
  144. {
  145. continue;
  146. }
  147. //未开班的更新学生名单
  148. if (dbClassList.Any(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID && x.RecordStatus == (int)CF_ClassminorStatus.NotOpen))
  149. {
  150. classminor = minorClassDAL.classminorRepository.GetSingle(x => x.GrademinorID == grademinor.Key.GrademinorID && x.CF_Grademinor.YearID == grademinor.Key.YearID, (x => x.CF_Grademinor));
  151. UnitOfWork.Delete<CF_ClassminorStudent>(x => x.ClassminorID == classminor.ClassminorID);
  152. //UnitOfWork.Delete<CF_Classminor>(x => x.ClassminorID == classminor.ClassminorID);
  153. classminor.RecordStatus = (int)CF_ClassminorStatus.NotOpen;
  154. classminor.ModifyTime = DateTime.Now;
  155. classminor.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  156. if (minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Count() > 0)
  157. {
  158. var Student = minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Select(x => new CF_ClassminorStudent
  159. {
  160. ClassminorStudentID = Guid.NewGuid(),
  161. ClassminorID = classminor.ClassminorID,
  162. UserID = x.UserID.Value,
  163. RecordStatus = (int)SYS_STATUS.USABLE,
  164. CreateTime = DateTime.Now,
  165. CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  166. ModifyTime = DateTime.Now,
  167. ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  168. });
  169. classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>(Student.ToList());
  170. }
  171. else
  172. {
  173. classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>();
  174. }
  175. updateClassminorList.Add(classminor);
  176. //UnitOfWork.Update(classminorList);
  177. //UnitOfWork.BulkInsert(classminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
  178. }
  179. else {
  180. //未生成过班级的生成班级
  181. var standardName = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard.ToString()).Where(x => x.Value == grademinor.Key.StandardID).Select(x => x.Name).FirstOrDefault();
  182. classminor.ClassminorID = Guid.NewGuid();
  183. classminor.GrademinorID = grademinor.Key.GrademinorID;
  184. classminor.Name = grademinor.Key.YearID.ToString() + standardName + "辅修班";
  185. classminor.Abbreviation = classminor.Name;
  186. classminor.ClassNum = 1;
  187. classminor.RecordStatus = (int)CF_ClassminorStatus.NotOpen;
  188. classminor.CreateTime = DateTime.Now;
  189. classminor.CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  190. classminor.ModifyTime = DateTime.Now;
  191. classminor.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  192. if (minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Count() > 0)
  193. {
  194. var Student = minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Select(x => new CF_ClassminorStudent
  195. {
  196. ClassminorStudentID = Guid.NewGuid(),
  197. ClassminorID = classminor.ClassminorID,
  198. UserID = x.UserID.Value,
  199. RecordStatus = (int)SYS_STATUS.USABLE,
  200. CreateTime = DateTime.Now,
  201. CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  202. ModifyTime = DateTime.Now,
  203. ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  204. });
  205. classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>(Student.ToList());
  206. }
  207. else
  208. {
  209. classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>();
  210. }
  211. addClassminorList.Add(classminor);
  212. //UnitOfWork.BulkInsert(classminorList);
  213. //UnitOfWork.BulkInsert(classminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
  214. }
  215. }
  216. //UnitOfWork.BulkInsert(updateClassminorList);
  217. UnitOfWork.BulkInsert(updateClassminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
  218. UnitOfWork.BulkInsert(addClassminorList);
  219. UnitOfWork.BulkInsert(addClassminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
  220. //UnitOfWork.Commit();
  221. }
  222. catch (Exception)
  223. {
  224. throw;
  225. }
  226. }
  227. public void MinorClassEdit(MinorClassView minorClassView)
  228. {
  229. try
  230. {
  231. CF_Classminor classminor = new CF_Classminor();
  232. if (minorClassView.ClassminorID == null || minorClassView.ClassminorID == Guid.Empty)
  233. {
  234. //新增、复制新增
  235. classminor = minorClassDAL.classminorRepository
  236. .GetSingle(x => x.GrademinorID == minorClassView.GrademinorID && x.Name == minorClassView.Name);
  237. if (classminor != null)
  238. {
  239. throw new Exception("已存在名称相同的辅修班级信息。");
  240. }
  241. classminor = new CF_Classminor();
  242. classminor.ClassminorID = Guid.NewGuid();
  243. classminor.GrademinorID = minorClassView.GrademinorID;
  244. classminor.Name = minorClassView.Name;
  245. classminor.ClassNum = minorClassView.ClassNum ?? 1;
  246. classminor.Abbreviation = minorClassView.ClassAbbreviation ?? minorClassView.Name;
  247. SetNewStatus(classminor);
  248. UnitOfWork.Add(classminor);
  249. }
  250. else
  251. {
  252. //修改
  253. classminor = minorClassDAL.classminorRepository
  254. .GetSingle(x => x.ClassminorID != minorClassView.ClassminorID
  255. && x.GrademinorID == minorClassView.GrademinorID && x.Name == minorClassView.Name);
  256. if (classminor != null)
  257. {
  258. throw new Exception("已存在名称相同的辅修班级信息。");
  259. }
  260. classminor = minorClassDAL.classminorRepository
  261. .GetSingle(x => x.ClassminorID == minorClassView.ClassminorID);
  262. if (classminor == null)
  263. {
  264. throw new Exception("数据有误,请核查。");
  265. }
  266. classminor.GrademinorID = minorClassView.GrademinorID;
  267. classminor.Name = minorClassView.Name;
  268. classminor.ClassNum = minorClassView.ClassNum;
  269. classminor.Abbreviation = minorClassView.ClassAbbreviation;
  270. SetModifyStatus(classminor);
  271. }
  272. UnitOfWork.Commit();
  273. }
  274. catch (Exception ex)
  275. {
  276. throw new Exception(ex.Message);
  277. }
  278. }
  279. public void MinorClassDelete(IList<Guid?> minorClassIDList)
  280. {
  281. try
  282. {
  283. if (minorClassIDList.Count > 0)
  284. {
  285. UnitOfWork.Delete<CF_ClassminorStudent>(x => minorClassIDList.Contains(x.ClassminorID));
  286. UnitOfWork.Delete<CF_Classminor>(x => minorClassIDList.Contains(x.ClassminorID));
  287. }
  288. }
  289. catch (Exception ex)
  290. {
  291. throw new Exception(ex.Message);
  292. }
  293. }
  294. public IGridResultSet<StudentsView> GetStudentsByMinorClassID(Guid minorClassID)
  295. {
  296. Expression<Func<CF_ClassminorStudent, bool>> exp = x => x.ClassminorID == minorClassID;
  297. var query = minorClassDAL.GetStudentsQueryable(exp);
  298. return query.OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>();
  299. }
  300. public void OpenClassMinor(List<Guid?> minorClassIDList)
  301. {
  302. try
  303. {
  304. var classminorList = minorClassDAL.classminorRepository.GetList(x => minorClassIDList.Contains(x.ClassminorID));
  305. foreach (var classMinor in classminorList)
  306. {
  307. if (classMinor.RecordStatus != (int)CF_ClassminorStatus.NotOpen)
  308. {
  309. throw new Exception("只能对未开班的数据进行开班");
  310. }
  311. classMinor.RecordStatus = (int)CF_ClassminorStatus.Open;
  312. }
  313. UnitOfWork.Commit();
  314. }
  315. catch (Exception)
  316. {
  317. throw;
  318. }
  319. }
  320. public void CancelOpenClassMinor(List<Guid?> minorClassIDList)
  321. {
  322. try
  323. {
  324. var classminorList = minorClassDAL.classminorRepository.GetList(x => minorClassIDList.Contains(x.ClassminorID));
  325. foreach (var classMinor in classminorList)
  326. {
  327. if (classMinor.RecordStatus != (int)CF_ClassminorStatus.Open)
  328. {
  329. throw new Exception("只能对已开班的数据进行开班");
  330. }
  331. classMinor.RecordStatus = (int)CF_ClassminorStatus.Cancel;
  332. }
  333. UnitOfWork.Commit();
  334. }
  335. catch (Exception)
  336. {
  337. throw;
  338. }
  339. }
  340. }
  341. }