EvaluationSettingServices.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.EvaluationManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel.EvaluationManage;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. using Bowin.Common.Utility;
  13. using Bowin.Common.Mapping;
  14. using EMIS.CommonLogic.SystemServices;
  15. using EMIS.DataLogic.Repositories;
  16. using EMIS.ViewModel.EducationManagement;
  17. using EMIS.Utility;
  18. namespace EMIS.CommonLogic.EvaluationManage
  19. {
  20. public class EvaluationSettingServices : BaseServices, IEvaluationSettingServices
  21. {
  22. public EvaluationSettingDAL EvaluationSettingDAL { get; set; }
  23. public ISerialNumberServices SerialNumberServices { get; set; }
  24. public SchoolyearRepository SchoolyearRepository { get; set; }
  25. public EducationSchedulingClassRepository educationSchedulingClassRepository { get; set; }
  26. public InSchoolSettingRepository inSchoolSettingRepository { get; set; }
  27. #region 1.0 查询评价设定列表信息
  28. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.EvaluationManage.EvaluationSettingView> GetEvaluationSettingViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? campusID, Guid? collegeID, int? openStatus, Guid? CoursematerialID, Guid? departmentID, Guid? userId, int? standardID, int? schoolyearCodeID, Guid? classmajorID,int? learningformID, int? education,string LearnSystem, int pageIndex, int pageSize)
  29. {
  30. bool hasClassmajorFilter = false;
  31. Expression<Func<EM_EvaluationSetting, bool>> filter = x => true;
  32. Expression<Func<CF_Classmajor, bool>> classmajorFilter = x => true;
  33. if (openStatus.HasValue && openStatus >= 0)
  34. {
  35. filter = filter.And(w => w.OpenStatus == openStatus);
  36. }
  37. if (schoolYearID.HasValue && schoolYearID != Guid.Empty)
  38. {
  39. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID);
  40. }
  41. if (campusID.HasValue && campusID != Guid.Empty)
  42. {
  43. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CampusID == campusID);
  44. }
  45. if (classmajorID.HasValue && classmajorID != Guid.Empty)
  46. {
  47. hasClassmajorFilter = true;
  48. classmajorFilter = x => x.ClassmajorID == classmajorID;
  49. }
  50. if (schoolyearCodeID.HasValue && schoolyearCodeID > 0)
  51. {
  52. hasClassmajorFilter = true;
  53. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == schoolyearCodeID);
  54. }
  55. if (learningformID.HasValue)
  56. {
  57. hasClassmajorFilter = true;
  58. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  59. }
  60. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  61. {
  62. hasClassmajorFilter = true;
  63. var LearnSystems = Convert.ToDecimal(LearnSystem);
  64. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  65. }
  66. if (education.HasValue)
  67. {
  68. hasClassmajorFilter = true;
  69. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  70. }
  71. if (standardID.HasValue && standardID > 0)
  72. {
  73. hasClassmajorFilter = true;
  74. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  75. }
  76. if (hasClassmajorFilter)
  77. {
  78. filter = filter.And(w => w.EM_EducationMissionClass.CF_Classmajor.AsQueryable().Any(classmajorFilter));
  79. }
  80. if (collegeID.HasValue && collegeID != Guid.Empty)
  81. {
  82. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CollegeID == collegeID);
  83. }
  84. if (CoursematerialID.HasValue && CoursematerialID != Guid.Empty)
  85. {
  86. filter = filter.And(w => w.EM_EducationMissionClass.CoursematerialID == CoursematerialID);
  87. }
  88. if (departmentID.HasValue && departmentID != Guid.Empty)
  89. {
  90. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_Department.DepartmentID == departmentID);
  91. }
  92. if (userId.HasValue && userId != Guid.Empty)
  93. {
  94. filter = filter.And(w => w.EM_EducationMissionClass.EM_MissionClassTeacher.Any(x => x.UserID == userId));
  95. }
  96. var query = EvaluationSettingDAL.GetEvaluationSettingQuery(filter);
  97. query = GetQueryByDataRangeByCollege(query);//以院系 区分
  98. if ((configuretView.Attribute != "UserNames" && !string.IsNullOrEmpty(configuretView.ConditionValue)) && (configuretView.Attribute != "UserCodes" && !string.IsNullOrEmpty(configuretView.ConditionValue)))
  99. {
  100. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  101. }
  102. var educationMissionClassIDList = query.Select(x => x.EducationMissionClassID).ToList();
  103. var missionClassTeacherList = EvaluationSettingDAL.GetMissionClassTeacherViewQueryable(x => educationMissionClassIDList.Contains(x.MissionClassID));
  104. var result = query.OrderBy(x => x.SchoolyearCode).OrderBy(x => x.CourseCode).OrderBy(x => x.EducationMissionClassName).
  105. ToGridResultSet<EvaluationSettingView>(pageIndex, pageSize);
  106. if (configuretView.Attribute == "UserCodes" && !string.IsNullOrEmpty(configuretView.ConditionValue))
  107. {
  108. missionClassTeacherList = missionClassTeacherList.Where(x => x.LoginID == configuretView.ConditionValue).ToList();
  109. var missionClassTeacherIDList = missionClassTeacherList.Select(x => x.EducationMissionClassID).ToList();
  110. result = query.Where(x => missionClassTeacherIDList.Contains(x.EducationMissionClassID)).OrderBy(x => x.SchoolyearCode).OrderBy(x => x.CourseCode).OrderBy(x => x.EducationMissionClassName).
  111. ToGridResultSet<EvaluationSettingView>(pageIndex, pageSize);
  112. }
  113. if (configuretView.Attribute == "UserNames" && !string.IsNullOrEmpty(configuretView.ConditionValue))
  114. {
  115. missionClassTeacherList = missionClassTeacherList.Where(x => x.Name == configuretView.ConditionValue).ToList();
  116. var missionClassTeacherIDList = missionClassTeacherList.Select(x => x.EducationMissionClassID).ToList();
  117. result = query.Where(x => missionClassTeacherIDList.Contains(x.EducationMissionClassID)).OrderBy(x => x.SchoolyearCode).OrderBy(x => x.CourseCode).OrderBy(x => x.EducationMissionClassName).
  118. ToGridResultSet<EvaluationSettingView>(pageIndex, pageSize);
  119. }
  120. result.rows.ForEach(x => x.EvaluationSettingMissionClassTeacherViewList =
  121. new HashSet<EvaluationSettingMissionClassTeacherView>(missionClassTeacherList.
  122. Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  123. return result;
  124. }
  125. #endregion
  126. #region 2.0 查询评价设定编辑信息
  127. public ViewModel.EvaluationManage.EvaluationSettingView GetEvaluationSettingView(Guid? id)
  128. {
  129. var result = new EvaluationSettingView();
  130. if (id.HasValue && id != Guid.Empty)
  131. result = EvaluationSettingDAL.GetEvaluationSettingQuery(x => x.EvaluationSettingID == id).FirstOrDefault();
  132. return result;
  133. }
  134. #endregion
  135. #region 3.0 保存评价设定数据信息
  136. public void AddOrUpdateEvaluationSetting(ViewModel.EvaluationManage.EvaluationSettingView model)
  137. {
  138. EM_EvaluationSetting entity;
  139. var courseQuery = EvaluationSettingDAL.EducationMissionClassRepository.Entities.Where(x => x.EducationMissionClassID == model.EducationMissionClassID && x.RecordStatus == (int)CF_ApprovalStatus.Submitted)
  140. .Select(s => new
  141. {
  142. s.EducationMissionClassID,
  143. s.EM_EducationMission.CF_Department,
  144. s.EM_Coursematerial
  145. });
  146. string YearCode = SchoolyearRepository.GetSingle(x => x.SchoolyearID == model.SchoolyearID).Code;
  147. string StrCode = courseQuery.FirstOrDefault().EM_Coursematerial.CourseCode + "(" + YearCode + ")";
  148. string settingCode = SerialNumberServices.GetSN(StrCode);//格式20160429
  149. #region 0.0 提取该教学任务班下对应的相关人员信息
  150. var evaluationTableEntity = EvaluationSettingDAL.EvaluationTableRepository.GetSingle(x => x.EvaluationTableID == model.EvaluationTableID, x => x.EM_EvaluationType);
  151. if (evaluationTableEntity == null)
  152. {
  153. throw new Exception("该评价表没指定参评类型!");
  154. }
  155. bool? IsApply = evaluationTableEntity.EM_EvaluationType.IsStudent;
  156. var evaluationByStudentUser = EvaluationSettingDAL.GetEvaluationByStudent(model.EducationMissionClassID);
  157. // var evaluationByStaffUser = EvaluationSettingDAL.GetEvaluationByStaff(model.EducationMissionClassID,null);
  158. #endregion
  159. if (model.EvaluationSettingID == Guid.Empty)
  160. {
  161. #region 1.0 评价设置基本信息 Add
  162. entity = new EM_EvaluationSetting();
  163. model.DynamicCloneTo(entity);
  164. //SetNewStatus方法去掉了设置ID的功能
  165. entity.EvaluationSettingID = Guid.NewGuid();
  166. //entity.ID = Function.NewPKGuid();
  167. SetNewStatus(entity);//EMIS.CommonLogic
  168. //是否适用于学生 否 默认同行
  169. //if ((bool)IsApply)
  170. //{
  171. foreach (var sysUser in evaluationByStudentUser)
  172. {
  173. entity.CF_Student.Add(sysUser);
  174. }
  175. //}
  176. //else
  177. //{
  178. //foreach (var sysUser in evaluationByStaffUser)
  179. //{
  180. // entity.CF_Staff.Add(sysUser);
  181. //}
  182. entity.EvaluationSettingCode = settingCode;//SerialNumberServices.SetSN(model.CourseCode + "(" + model.SchoolyearCode + ")");
  183. entity.CreateTime = DateTime.Now;
  184. entity.RecordStatus = evaluationTableEntity.EM_EvaluationType.IsStudent == true ? (int)CF_YesOrNoStatus.Yes : (int)CF_YesOrNoStatus.No;//是否适用学生
  185. entity.EvaluationTypeID = evaluationTableEntity.EvaluationTypeID;//参评类型
  186. UnitOfWork.Add(entity);
  187. #endregion
  188. }
  189. else
  190. {
  191. #region 2.0 评价设置基本信息 Update
  192. entity = EvaluationSettingDAL.EvaluationSettingRepository.GetSingle(x => x.EvaluationSettingID == model.EvaluationSettingID, (x => x.CF_Student), (x => x.CF_Staff));
  193. if (entity != null)
  194. {
  195. SetModifyStatus(entity);
  196. entity.CF_Student = new HashSet<CF_Student>();//该学生、对应的所有数据
  197. foreach (var sysUser in evaluationByStudentUser)
  198. {
  199. entity.CF_Student.Add(sysUser);
  200. }
  201. entity.CF_Staff = new HashSet<CF_Staff>();//该同行、对应的所有数据
  202. //foreach (var sysUser in evaluationByStaffUser)
  203. //{
  204. // entity.CF_Staff.Add(sysUser);
  205. //}
  206. entity.EvaluationSettingCode = settingCode;
  207. entity.EvaluationTypeID = evaluationTableEntity.EvaluationTypeID;//参评类型
  208. entity.OpenStatus = model.OpenStatus;
  209. entity.RecordStatus = evaluationTableEntity.EM_EvaluationType.IsStudent == true ? (int)CF_YesOrNoStatus.Yes : (int)CF_YesOrNoStatus.No;//是否适用学生
  210. UnitOfWork.Update(entity);
  211. }
  212. #endregion
  213. }
  214. UnitOfWork.Commit();//统一提交
  215. }
  216. #endregion
  217. #region 4.0 删除评价设定数据信息
  218. //4.0 删除评价设定信息
  219. public void DeleteEvaluationSetting(List<Guid> ids)
  220. {
  221. //var evaluationSettingList = EvaluationSettingDAL.EvaluationSettingRepository.GetList(w => ids.Contains(w.EvaluationSettingID)).ToList();
  222. //foreach (var evaluationSetting in evaluationSettingList)
  223. //{
  224. // if (evaluationSetting.OpenStatus == (int)CF_YesOrNoStatus.Yes)
  225. // {
  226. // throw new Exception("勾选信息包含开放状态为是,不能删除!");
  227. // }
  228. //}
  229. UnitOfWork.Delete<EM_EvaluationSetting>(w => ids.Contains(w.EvaluationSettingID));
  230. }
  231. //同时删除进入评价记录
  232. public void DeleteSettingWithRecord(List<Guid> ids)
  233. {
  234. var evaluationSettingList = EvaluationSettingDAL.EvaluationSettingRepository.GetList(w => ids.Contains(w.EvaluationSettingID)).ToList();
  235. foreach (var evaluationSetting in evaluationSettingList)
  236. {
  237. EM_EducationMissionClass edu = EvaluationSettingDAL.EducationMissionClassRepository.GetSingle(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID);
  238. List<Guid> tablelist = EvaluationSettingDAL.EvaluationTableRepository.GetList(x => x.EM_EvaluationIntType.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(edu.TeachingModeID ?? (int)CF_TeachingMode.Theory) && x.IsEnabled == true).Select(x => x.EvaluationTableID).ToList();
  239. List<EM_EvaluationEnter> lie = EvaluationSettingDAL.evaluationEnterRepository.GetList(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID && tablelist.Contains((Guid)x.EvaluationTableID)).ToList();
  240. if (lie != null)
  241. {
  242. List<Guid> idlist = lie.Select(x => x.EvaluationEnterID).ToList();
  243. UnitOfWork.Delete<EM_EvaluationEnter_EM_EvaluationProject>(x => idlist.Contains(x.EvaluationEnterID));
  244. UnitOfWork.Delete<EM_EvaluationEnter>(x => idlist.Contains(x.EvaluationEnterID));
  245. }
  246. }
  247. UnitOfWork.Delete<EM_EvaluationSetting>(w => ids.Contains(w.EvaluationSettingID));
  248. }
  249. public bool DeleteValidate(List<Guid> ids)//删除前提醒
  250. {
  251. bool val = false;
  252. var evaluationSettingList = EvaluationSettingDAL.EvaluationSettingRepository.GetList(w => ids.Contains(w.EvaluationSettingID)).ToList();
  253. foreach (var evaluationSetting in evaluationSettingList)
  254. {
  255. if (evaluationSetting.OpenStatus == (int)CF_YesOrNoStatus.Yes)
  256. {
  257. throw new Exception("勾选信息包含开放状态为是,不能删除!");
  258. }
  259. EM_EducationMissionClass edu = EvaluationSettingDAL.EducationMissionClassRepository.GetSingle(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID);
  260. List<Guid> tablelist = EvaluationSettingDAL.EvaluationTableRepository.GetList(x => x.EM_EvaluationIntType.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(edu.TeachingModeID ?? (int)CF_TeachingMode.Theory) && x.IsEnabled == true).Select(x => x.EvaluationTableID).ToList();
  261. List<EM_EvaluationEnter> lie = EvaluationSettingDAL.evaluationEnterRepository.GetList(x => x.EducationMissionClassID == evaluationSetting.EducationMissionClassID && tablelist.Contains((Guid)x.EvaluationTableID)).ToList();
  262. if (lie != null && lie.Count != 0)
  263. {
  264. val = true;
  265. }
  266. }
  267. return val;
  268. }
  269. #endregion
  270. #region 5.0 导出评价设定数据信息
  271. //Excel导出
  272. public IList<EvaluationSettingView> GetEvaluationSettingViewList(ConfiguretView configuretView, Guid? schoolYearID, Guid? campusID, Guid? collegeID, int? openStatus, Guid? CoursematerialID, Guid? departmentID, Guid? userId, int? standardID, int? schoolyearCodeID, Guid? classmajorID, int? learningformID, int? education, string LearnSystem)
  273. {
  274. bool hasClassmajorFilter = false;
  275. Expression<Func<EM_EvaluationSetting, bool>> filter = x => true;
  276. Expression<Func<CF_Classmajor, bool>> classmajorFilter = x => true;
  277. if (openStatus.HasValue&&openStatus >= 0)
  278. {
  279. filter= filter.And(w => w.OpenStatus == openStatus);
  280. }
  281. if (schoolYearID.HasValue && schoolYearID != Guid.Empty)
  282. {
  283. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolYearID);
  284. }
  285. if (campusID.HasValue && campusID != Guid.Empty)
  286. {
  287. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CampusID == campusID);
  288. }
  289. if (classmajorID.HasValue && classmajorID != Guid.Empty)
  290. {
  291. hasClassmajorFilter = true;
  292. classmajorFilter = x => x.ClassmajorID == classmajorID;
  293. }
  294. if (schoolyearCodeID.HasValue&&schoolyearCodeID>0)
  295. {
  296. hasClassmajorFilter = true;
  297. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.GradeID == schoolyearCodeID);
  298. }
  299. if (learningformID.HasValue)
  300. {
  301. hasClassmajorFilter = true;
  302. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  303. }
  304. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  305. {
  306. hasClassmajorFilter = true;
  307. var LearnSystems = Convert.ToDecimal(LearnSystem);
  308. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  309. }
  310. if (education.HasValue)
  311. {
  312. hasClassmajorFilter = true;
  313. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  314. }
  315. if (standardID.HasValue && standardID > 0)
  316. {
  317. hasClassmajorFilter = true;
  318. classmajorFilter = classmajorFilter.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  319. }
  320. if (hasClassmajorFilter)
  321. {
  322. filter = filter.And(w => w.EM_EducationMissionClass.CF_Classmajor.AsQueryable().Any(classmajorFilter));
  323. }
  324. if (collegeID.HasValue && collegeID != Guid.Empty)
  325. {
  326. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_College.CollegeID == collegeID);
  327. }
  328. if (CoursematerialID.HasValue && CoursematerialID != Guid.Empty)
  329. {
  330. filter = filter.And(w => w.EM_EducationMissionClass.EM_Coursematerial.CoursematerialID == CoursematerialID);
  331. }
  332. if (departmentID.HasValue && departmentID != Guid.Empty)
  333. {
  334. filter = filter.And(w => w.EM_EducationMissionClass.EM_EducationMission.CF_Department.DepartmentID == departmentID);
  335. }
  336. if (userId.HasValue && userId != Guid.Empty)
  337. {
  338. filter = filter.And(w => w.EM_EducationMissionClass.EM_MissionClassTeacher.Any(x => x.UserID == userId));
  339. }
  340. var query = EvaluationSettingDAL.GetEvaluationSettingQuery(filter);
  341. query = GetQueryByDataRangeByCollege(query);
  342. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  343. {
  344. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  345. }
  346. var educationMissionClassIDList = query.Select(x => x.EducationMissionClassID).ToList();
  347. var missionClassTeacherList = EvaluationSettingDAL.GetMissionClassTeacherViewQueryable(x => educationMissionClassIDList.Contains(x.MissionClassID));
  348. var result = query.OrderBy(o => o.CourseCode).ToList();
  349. result.ForEach(x => x.EvaluationSettingMissionClassTeacherViewList = new HashSet<EvaluationSettingMissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  350. return result;
  351. }
  352. #endregion
  353. #region 6.0 查询评价设定明细信息
  354. //学生明细
  355. public IList<EvaluationSettingDetailView> EvaluationSettingStudentDetail(Guid? evaluationSettingID, int pageIndex, int pageSize)
  356. {
  357. var query = EvaluationSettingDAL.GetEvaluationSettingStudentDetailQuery(evaluationSettingID).OrderBy(x => x.LoginID);
  358. return query.ToList();
  359. // return query.ToGridResultSet(pageIndex, pageSize);
  360. }
  361. //教职工明细
  362. public IList<EvaluationSettingDetailView> EvaluationSettingStaffDetail(Guid? evaluationSettingID, int pageIndex, int pageSize)
  363. {
  364. var query = EvaluationSettingDAL.GetEvaluationSettingStaffDetailQuery(evaluationSettingID).OrderBy(x => x.StaffCode);
  365. return query.ToList();
  366. // return query.ToGridResultSet(pageIndex, pageSize);
  367. }
  368. //教职工明细
  369. public IList<EvaluationSettingDetailView> EvaluationSettingStaffList(ConfiguretView configuretView, Guid? evaluationSettingID)
  370. {
  371. var query = EvaluationSettingDAL.GetEvaluationSettingStaffDetailList(evaluationSettingID).OrderBy(x => x.StaffCode);
  372. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  373. {
  374. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList();
  375. }
  376. return query.ToList();
  377. }
  378. //学生明细
  379. public IList<EvaluationSettingDetailView> EvaluationSettingStudentList(ConfiguretView configuretView, Guid? evaluationSettingID)
  380. {
  381. var query = EvaluationSettingDAL.GetEvaluationSettingStudentDetailList(evaluationSettingID).OrderBy(x => x.LoginID);
  382. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  383. {
  384. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList();
  385. }
  386. return query.ToList();
  387. }
  388. #endregion
  389. #region 7.0 创建评价设定清单信息
  390. //以学年学期生成评价信息
  391. public void CreateEvaluationInventory(Guid schoolyearID)
  392. {
  393. var inschoolStatus = inSchoolSettingRepository.GetList(w => w.IsSelected == true).Select(s => s.InSchoolStatusID).ToList();
  394. #region 1.0 以学年学期缩小对应的教学任务班数据范围、统一构建学生、同行清单操作
  395. List<EM_EvaluationSetting> listEvaluationSetting = new List<EM_EvaluationSetting>();//评价设定数据集合
  396. var evaluationSetting = EvaluationSettingDAL.GetCreateInventoryQuery(schoolyearID);//提取对应的评价相关数据
  397. List<EducationMissionClassView> educationMissionClassIDLsit = this.GetQueryByDataRangeByCollege(evaluationSetting).ToList();
  398. //获取所有的教学任务
  399. var allEducationMissionClass = EvaluationSettingDAL.GetEducationMissionClassQuery(schoolyearID);
  400. var existEvaluationSettingList = this.EvaluationSettingDAL.EvaluationSettingRepository.GetList(x =>
  401. x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == schoolyearID,
  402. (x => x.EM_EducationMissionClass),
  403. (x => x.EM_EducationMissionClass.EM_MissionClassTeacher)).ToList();
  404. var existCourseAndTeacher = (from es in existEvaluationSettingList
  405. from mct in es.EM_EducationMissionClass.EM_MissionClassTeacher
  406. select new { es.EM_EducationMissionClass.CoursematerialID, mct.UserID }).ToList();
  407. List<EducationMissionClassView> allEducationMissionClassList = this.GetQueryByDataRangeByCollege(allEducationMissionClass).ToList();
  408. if (educationMissionClassIDLsit.Count() < 0)
  409. {
  410. throw new Exception("没有相关的评价生成信息!");
  411. }
  412. string YearCode = SchoolyearRepository.GetSingle(x => x.SchoolyearID == schoolyearID).Code;
  413. List<CF_Staff> st = new List<CF_Staff>();
  414. //所有的老师
  415. var stall=EvaluationSettingDAL.StaffRepository.GetList(x=>x.RecordStatus==(int)SYS_STATUS.USABLE).ToList();
  416. //同教研室的老师
  417. #endregion
  418. #region 1.0 评价设置基本信息 Add
  419. EM_EvaluationSetting entity = null;
  420. foreach (var educationMissionEntity in educationMissionClassIDLsit)
  421. {
  422. if (educationMissionEntity.CF_Staff.FirstOrDefault() != null)//TODO:没有任课老师、将不做评价信息生成~
  423. {
  424. #region 1.1 主体数据构建
  425. string StrCode = educationMissionEntity.CourseCode + "(" + YearCode + ")";
  426. //string settingCode = SerialNumberServices.SetSN(StrCode, 3);//格式20160429 慢慢慢~~~
  427. entity = new EM_EvaluationSetting();
  428. entity.EvaluationTypeID = null;
  429. entity.CreateTime = DateTime.Now;
  430. entity.EvaluationSettingCode = StrCode;
  431. entity.OpenStatus = (int)CF_YesOrNoStatus.No;
  432. entity.EducationMissionClassID = educationMissionEntity.EducationMissionClassID;
  433. entity.EvaluationTableID = null;
  434. entity.EvaluationSettingID = Guid.NewGuid();
  435. SetNewStatus(entity);
  436. #endregion
  437. #region 1.2 学生清单写入
  438. if (educationMissionEntity.CF_Student.Count() > 0)
  439. {
  440. //过滤非在校状态学生
  441. educationMissionEntity.CF_Student = new HashSet<CF_Student>(educationMissionEntity.CF_Student.Where(x => inschoolStatus.Contains(x.InSchoolStatusID)));
  442. educationMissionEntity.CF_Student.ForEach(x => { entity.CF_Student.Add(x); });
  443. }
  444. #endregion
  445. #region 1.3 教师清单写入
  446. List<CF_Staff> StaffList = educationMissionEntity.CF_Staff.ToList();
  447. //去除已经生成过的课程
  448. StaffList.RemoveAll(x => existCourseAndTeacher.Any(w => w.CoursematerialID == educationMissionEntity.CoursematerialID
  449. && w.UserID == x.UserID));
  450. if (StaffList.Count > 0)//没有排课老师、直接不做同行查询
  451. {
  452. var staffid = StaffList.Select(x => x.UserID).ToList();
  453. //var staffDepartid=StaffList.Select(x=>x.DepartmentID).ToList();
  454. //同开课教研室的教师
  455. var stdepart = (from all in stall
  456. from staff in StaffList.Where(x => all.DepartmentID == x.DepartmentID && x.UserID != all.UserID)
  457. select all).ToList();
  458. //var stdepart = stall.Where(x => x.DepartmentID == educationMissionEntity.DepartmentID&&!staffid.Contains(x.UserID)).ToList();
  459. //var stdepartList = stall.Where(x => staffDepartid.Contains(x.DepartmentID)).ToList();
  460. //上同一门课的教师
  461. List<CF_Staff> stclass = new List<CF_Staff>();
  462. //上同一门课的教师,用教学任务是否控制配置来排除是只生成提交的还是全部都生成
  463. if (!Const.LOCAL_SETTING_MISSIONCLASS_CAN_SUBMIT_NOTEACHER)
  464. {
  465. foreach (var e in educationMissionClassIDLsit)
  466. {
  467. if (e.CoursematerialID == educationMissionEntity.CoursematerialID
  468. && e.EducationMissionID != educationMissionEntity.EducationMissionID)
  469. {
  470. List<CF_Staff> StaffLists = e.CF_Staff.ToList();
  471. foreach (var s in StaffLists)
  472. {
  473. if (!staffid.Contains(s.UserID))
  474. {
  475. stclass.Add(s);
  476. }
  477. }
  478. }
  479. }
  480. }
  481. else
  482. {
  483. foreach (var e in allEducationMissionClassList)
  484. {
  485. if (e.CoursematerialID == educationMissionEntity.CoursematerialID
  486. && e.EducationMissionClassID != educationMissionEntity.EducationMissionClassID)
  487. {
  488. List<CF_Staff> StaffLists = e.CF_Staff.ToList();
  489. foreach (var s in StaffLists)
  490. {
  491. if (!staffid.Contains(s.UserID))
  492. {
  493. stclass.Add(s);
  494. }
  495. }
  496. }
  497. }
  498. }
  499. List<CF_Staff> evaluationByStaffUser = new List<CF_Staff>();
  500. foreach (var sd in stdepart)
  501. {
  502. evaluationByStaffUser.Add(sd);
  503. }
  504. foreach (var sc in stclass)
  505. {
  506. evaluationByStaffUser.Add(sc);
  507. }
  508. //foreach(var sdd in stdepartList)
  509. //{
  510. // evaluationByStaffUser.Add(sdd);
  511. //}
  512. evaluationByStaffUser = evaluationByStaffUser.Distinct().ToList(); //EvaluationSettingDAL.GetEvaluationByStaff(educationMissionEntity.EducationMissionClassID, StaffList);
  513. if (evaluationByStaffUser.Count() > 0)
  514. {
  515. evaluationByStaffUser.ForEach(x => { entity.CF_Staff.Add(x); });
  516. }
  517. StaffList.ForEach(x => existCourseAndTeacher.Add(new { educationMissionEntity.CoursematerialID, UserID = (Guid?)x.UserID }));
  518. }
  519. #endregion
  520. #region 1.4 Add实体集合
  521. listEvaluationSetting.Add(entity);
  522. //UnitOfWork.Add(entity);
  523. #endregion
  524. }
  525. }
  526. if (listEvaluationSetting.Count > 0)
  527. {
  528. UnitOfWork.BulkInsert(listEvaluationSetting);
  529. UnitOfWork.BulkInsert(listEvaluationSetting, (x => x.CF_Student));//批量插入
  530. UnitOfWork.BulkInsert(listEvaluationSetting, (x => x.CF_Staff));
  531. }
  532. // UnitOfWork.Commit();//统一提交
  533. #endregion
  534. }
  535. #endregion
  536. #region 8.0 查询对应的评价表|评价类型信息
  537. //以教学任务班ID、查询对应的评价表、级评价类型信息
  538. public IGridResultSet<EvaluationTableView> GetEvaluationSettingByEducationMissionClassID(Guid? educationMissionClassID)
  539. {
  540. var query = EvaluationSettingDAL.GetTableByEducationMissionClassID(educationMissionClassID);
  541. return query.ToGridResultSet<EvaluationTableView>(0, 10);
  542. }
  543. #endregion
  544. public void Save(Guid? evaluationSettingID, IList<EvaluationSettingDetailView> list, string SaveType)
  545. {
  546. try
  547. {
  548. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  549. EM_EvaluationSetting entity = EvaluationSettingDAL.EvaluationSettingRepository
  550. .GetSingle(x => x.EvaluationSettingID == evaluationSettingID, x => x.CF_Student, x => x.CF_Staff);//有多对多关系、一定要指定属性
  551. var Userid = list.Select(x => x.UserID).ToList();
  552. if (entity != null && SaveType.Equals("Student"))
  553. {
  554. entity.CF_Student = new HashSet<CF_Student>();//该学生发放ID、对应的所有数据
  555. var queryStudent = EvaluationSettingDAL.StudentRepository.Entities.Where(x => Userid.Contains(x.UserID));
  556. foreach (var student in queryStudent)
  557. {
  558. entity.CF_Student.Add(student);
  559. }
  560. entity.ModifyUserID = curUser.UserID;
  561. UnitOfWork.Update(entity);
  562. }
  563. if (entity != null && SaveType.Equals("Staff"))
  564. {
  565. entity.CF_Staff = new HashSet<CF_Staff>();
  566. var queryStaff = EvaluationSettingDAL.StaffRepository.Entities.Where(x => Userid.Contains(x.UserID));
  567. foreach (var Staff in queryStaff)
  568. {
  569. entity.CF_Staff.Add(Staff);
  570. }
  571. entity.ModifyUserID = curUser.UserID;
  572. UnitOfWork.Update(entity);
  573. }
  574. UnitOfWork.Commit();
  575. }
  576. catch (Exception ex)
  577. {
  578. throw new Exception(ex.Message);
  579. }
  580. }
  581. }
  582. }