RetakePlanListServices.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq.Entity;
  7. using Bowin.Common.Linq;
  8. using EMIS.DataLogic.RetakeManage;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.RetakeManage;
  12. using EMIS.Utility;
  13. using EMIS.CommonLogic.SystemServices;
  14. using EMIS.ViewModel.EducationManage;
  15. using EMIS.DataLogic.EducationManage;
  16. using EMIS.CommonLogic.EducationSchedule;
  17. using EMIS.DataLogic.SystemSetting;
  18. using EMIS.CommonLogic.RetakeManage.General;
  19. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  20. namespace EMIS.CommonLogic.RetakeManage.General
  21. {
  22. public class RetakePlanListServices : BaseServices, IRetakePlanListServices
  23. {
  24. public RetakePlanTaskDAL RetakePlanTaskDAL { get; set; }
  25. public IInSchoolSettingServices InSchoolSettingServices { get; set; }
  26. /// <summary>
  27. /// 查询重修任务名单View
  28. /// </summary>
  29. /// <param name="configuretView"></param>
  30. /// <param name="schoolyearID"></param>
  31. /// <param name="collegeID"></param>
  32. /// <param name="yearID"></param>
  33. /// <param name="standardID"></param>
  34. /// <param name="educationID"></param>
  35. /// <param name="learningformID"></param>
  36. /// <param name="learnSystem"></param>
  37. /// <param name="classmajorID"></param>
  38. /// <param name="coursematerialID"></param>
  39. /// <param name="inSchoolStatus"></param>
  40. /// <param name="retakePlanStatusID"></param>
  41. /// <param name="generalPurposeID"></param>
  42. /// <param name="pageIndex"></param>
  43. /// <param name="pageSize"></param>
  44. /// <returns></returns>
  45. public IGridResultSet<RetakeStudentListView> GetRetakePlanStudentView(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
  46. int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID,
  47. int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID, int pageIndex, int pageSize)
  48. {
  49. //重修计划
  50. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  51. if (coursematerialID.HasValue)
  52. {
  53. //课程信息
  54. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
  55. }
  56. if (schoolyearID.HasValue)
  57. {
  58. //重修学年学期
  59. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
  60. }
  61. if (retakePlanStatusID.HasValue)
  62. {
  63. //重修任务状态
  64. expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID);
  65. }
  66. //学生信息
  67. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  68. if (classmajorID.HasValue)
  69. {
  70. //班级信息
  71. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  72. }
  73. if (inSchoolStatus != null && inSchoolStatus > -1)
  74. {
  75. //在校状态
  76. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  77. if (inSchoolStatus == 1)
  78. {
  79. //表示在校
  80. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  81. }
  82. if (inSchoolStatus == 0)
  83. {
  84. //不在校
  85. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  86. }
  87. }
  88. var query = RetakePlanTaskDAL.GetRetakePlanTaskStudentView(expRetakePlan, x => true, expStudent);
  89. if (collegeID.HasValue)
  90. {
  91. //院系所
  92. query = query.Where(x => x.CollegeID == collegeID);
  93. }
  94. if (yearID.HasValue)
  95. {
  96. //年级
  97. query = query.Where(x => x.Gradeyear == yearID);
  98. }
  99. if (standardID.HasValue)
  100. {
  101. //专业名称
  102. query = query.Where(x => x.StandardID == standardID);
  103. }
  104. if (educationID.HasValue)
  105. {
  106. //培养层次
  107. query = query.Where(x => x.EducationID == educationID);
  108. }
  109. if (learningformID.HasValue)
  110. {
  111. //学习形式
  112. query = query.Where(x => x.LearningformID == learningformID);
  113. }
  114. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  115. {
  116. //学制
  117. var LearnSystems = Convert.ToDecimal(learnSystem);
  118. query = query.Where(x => x.LearnSystem == LearnSystems);
  119. }
  120. if (generalPurposeID.HasValue)
  121. {
  122. //报名状态
  123. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes)
  124. {
  125. query = query.Where(x => x.ApplyStatus == true);
  126. }
  127. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo)
  128. {
  129. query = query.Where(x => x.ApplyStatus == false);
  130. }
  131. }
  132. //查询条件
  133. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  134. {
  135. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  136. }
  137. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode)
  138. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  139. .ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit)
  140. .ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode)
  141. .ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID)
  142. .ToGridResultSet<RetakeStudentListView>(pageIndex, pageSize);
  143. }
  144. /// <summary>
  145. /// 查询重修任务名单List
  146. /// </summary>
  147. /// <param name="configuretView"></param>
  148. /// <param name="schoolyearID"></param>
  149. /// <param name="collegeID"></param>
  150. /// <param name="yearID"></param>
  151. /// <param name="standardID"></param>
  152. /// <param name="educationID"></param>
  153. /// <param name="learningformID"></param>
  154. /// <param name="learnSystem"></param>
  155. /// <param name="classmajorID"></param>
  156. /// <param name="coursematerialID"></param>
  157. /// <param name="inSchoolStatus"></param>
  158. /// <param name="retakePlanStatusID"></param>
  159. /// <param name="generalPurposeID"></param>
  160. /// <returns></returns>
  161. public List<RetakeStudentListView> GetRetakePlanStudentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
  162. int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID,
  163. int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID)
  164. {
  165. //重修计划
  166. Expression<Func<ER_RetakePlan, bool>> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  167. if (coursematerialID.HasValue)
  168. {
  169. //课程信息
  170. expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
  171. }
  172. if (schoolyearID.HasValue)
  173. {
  174. //重修学年学期
  175. expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
  176. }
  177. if (retakePlanStatusID.HasValue)
  178. {
  179. //重修任务状态
  180. expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID);
  181. }
  182. //学生信息
  183. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  184. if (classmajorID.HasValue)
  185. {
  186. //班级信息
  187. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  188. }
  189. if (inSchoolStatus != null && inSchoolStatus > -1)
  190. {
  191. //在校状态
  192. var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
  193. if (inSchoolStatus == 1)
  194. {
  195. //表示在校
  196. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  197. }
  198. if (inSchoolStatus == 0)
  199. {
  200. //不在校
  201. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  202. }
  203. }
  204. var query = RetakePlanTaskDAL.GetRetakePlanTaskStudentView(expRetakePlan, x => true, expStudent);
  205. if (collegeID.HasValue)
  206. {
  207. //院系所
  208. query = query.Where(x => x.CollegeID == collegeID);
  209. }
  210. if (yearID.HasValue)
  211. {
  212. //年级
  213. query = query.Where(x => x.Gradeyear == yearID);
  214. }
  215. if (standardID.HasValue)
  216. {
  217. //专业名称
  218. query = query.Where(x => x.StandardID == standardID);
  219. }
  220. if (educationID.HasValue)
  221. {
  222. //培养层次
  223. query = query.Where(x => x.EducationID == educationID);
  224. }
  225. if (learningformID.HasValue)
  226. {
  227. //学习形式
  228. query = query.Where(x => x.LearningformID == learningformID);
  229. }
  230. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  231. {
  232. //学制
  233. var LearnSystems = Convert.ToDecimal(learnSystem);
  234. query = query.Where(x => x.LearnSystem == LearnSystems);
  235. }
  236. if (generalPurposeID.HasValue)
  237. {
  238. //报名状态
  239. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes)
  240. {
  241. query = query.Where(x => x.ApplyStatus == true);
  242. }
  243. if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo)
  244. {
  245. query = query.Where(x => x.ApplyStatus == false);
  246. }
  247. }
  248. //查询条件
  249. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  250. {
  251. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  252. }
  253. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode)
  254. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  255. .ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit)
  256. .ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode)
  257. .ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID)
  258. .ToList();
  259. }
  260. /// <summary>
  261. /// 删除重修任务名单
  262. /// </summary>
  263. /// <param name="retakePlanStudentIDsList"></param>
  264. public void DeleteRetakePlanStudent(IList<Guid?> retakePlanStudentIDsList)
  265. {
  266. try
  267. {
  268. //查询对应的重修计划名单信息
  269. var retakePlanStudentViewList = RetakePlanTaskDAL.RetakePlanStudentRepository
  270. .GetList(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID),
  271. (x => x.ER_RetakePlan), (x => x.ER_RetakePlan.CF_Student)).ToList();
  272. if (retakePlanStudentViewList.Any(x => x.ER_RetakePlan.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated))
  273. {
  274. throw new Exception("不能删除已开班状态的重修任务名单。");
  275. }
  276. //查询对应的重修报名信息List
  277. var retakePlanStudentApplyList = RetakePlanTaskDAL.RetakePlanStudentRepository
  278. .GetList(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID),
  279. (x => x.ER_RetakePlan),
  280. (x => x.ER_RetakePlan.CF_Student))
  281. .Where(x => x.ER_RetakePlan.CF_Student.Any(w => w.UserID == x.UserID))
  282. .ToList();
  283. if (retakePlanStudentApplyList.Count() > 0)
  284. {
  285. //查询对应的重修计划信息
  286. var retakePlanViewList = retakePlanStudentApplyList
  287. .Select(x => x.ER_RetakePlan).Distinct().ToList();
  288. //重修报名表
  289. foreach (var retakePlan in retakePlanViewList)
  290. {
  291. //查询存在报名名单的重修计划名单对应的userIDList
  292. var userIDList = retakePlanStudentApplyList
  293. .Where(x => x.RetakePlanID == retakePlan.RetakePlanID)
  294. .Select(x => x.UserID).ToList();
  295. retakePlan.CF_Student.RemoveWhere(x => userIDList.Contains(x.UserID));
  296. }
  297. //throw new Exception("要删除的重修计划名单已进行重修报名。");
  298. }
  299. //重修计划名单表
  300. //UnitOfWork.RemoveRange(new HashSet<ER_RetakePlanStudent>(retakePlanStudentViewList));
  301. UnitOfWork.Remove<ER_RetakePlanStudent>(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID));
  302. UnitOfWork.Commit();
  303. }
  304. catch (Exception ex)
  305. {
  306. throw new Exception(ex.Message);
  307. }
  308. }
  309. }
  310. }