EvaluationEnterServices.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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.EvaluationEnter;
  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 Bowin.Common.JSON;
  16. using EMIS.Utility;
  17. using EMIS.DataLogic.SystemDAL;
  18. using EMIS.DataLogic.Repositories;
  19. namespace EMIS.CommonLogic.EvaluationManage
  20. {
  21. public class EvaluationEnterServices : BaseServices, IEvaluationEnterServices
  22. {
  23. public EvaluationTypeRepository EvaluationTypeRepository { get; set; }
  24. public DataRangeDAL DataRangeDAL { get; set; }
  25. public EvaluationEnterDAL EvaluationEnterDAL { get; set; }
  26. public Lazy<IEvaluationNormServices> EvaluationNormServices { get; set; }
  27. public Lazy<IEvaluationTargetServices> EvaluationTargetServices { get; set; }
  28. public Lazy<IEvaluationProjectServices> EvaluationProjectServices { get; set; }
  29. public IGridResultSet<EvaluationEnterView> GetEvaluationEnterViewGrid(ConfiguretView configuretView, Guid? schoolYearID, Guid? userID, Guid? roleID, bool isStudent, int pageIndex, int pageSize)
  30. {
  31. Expression<Func<EM_EvaluationSetting, bool>> expEvaluationSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.OpenStatus == (int)CF_YesOrNoStatus.Yes);
  32. Expression<Func<EM_EvaluationTable, bool>> expEvaluationTable = x => x.IsEnabled == true;
  33. Expression<Func<CF_Student, bool>> expStudent = x => true;
  34. if (schoolYearID.HasValue)
  35. expEvaluationSetting = expEvaluationSetting.And(x => x.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID == schoolYearID);
  36. if (isStudent)
  37. {
  38. expStudent = expStudent.And(x => x.UserID == userID);
  39. var studentEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == true).FirstOrDefault();
  40. if (studentEvaluationType == null)
  41. {
  42. throw new Exception("未找到对应的参评类型数据!");
  43. }
  44. expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == studentEvaluationType.EvaluationTypeID);
  45. }
  46. else
  47. {
  48. var staffEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == false)
  49. .OrderByDescending(w => w.IsStudent).FirstOrDefault();
  50. if (staffEvaluationType == null)
  51. {
  52. throw new Exception("未找到对应的参评类型数据!");
  53. }
  54. expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == staffEvaluationType.EvaluationTypeID);
  55. }
  56. Expression<Func<EM_EvaluationGradeControl, bool>> expEvaluationGradeControl = x => true;
  57. Expression<Func<EM_EvaluationEnter, bool>> expEvaluationEnter = x => true;// 如果是超级管理员、那么默认显示全部数据
  58. expEvaluationSetting = expEvaluationSetting.And(x => x.OpenStatus == (int)CF_YesOrNoStatus.Yes);
  59. var menuNo = HttpHelper.GetMenuNo();
  60. if (isStudent)//过滤属于自己的评价信息
  61. {
  62. expEvaluationEnter = expEvaluationEnter.And(x => x.StudentUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0);
  63. expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Student.Any(w => w.UserID == userID));
  64. expEvaluationGradeControl = expEvaluationGradeControl.And(x => x.CF_Schoolyear.SchoolyearID == schoolYearID);
  65. }
  66. else
  67. {
  68. SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo);
  69. if (!dataRange.Equals(SYS_DataRange.All) && !isStudent)//过滤属于自己的评价信息
  70. {
  71. expEvaluationEnter = expEvaluationEnter.And(x => x.StaffUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0);
  72. expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Staff.Any(w => w.UserID == userID));
  73. }
  74. }
  75. var query = EvaluationEnterDAL.GetEvaluationEnterQuery(expEvaluationSetting, expEvaluationEnter, expEvaluationTable);
  76. if (isStudent)
  77. {
  78. query = EvaluationEnterDAL.GetStudentEvaluationEnterQuery(expEvaluationSetting, expEvaluationEnter, expEvaluationTable, expEvaluationGradeControl, expStudent);
  79. }
  80. if (!isStudent)
  81. {
  82. //query = GetQueryByDataRangeByCollege(query);//以院系 区分
  83. }
  84. else
  85. {
  86. query = query.Where(x => x.IsStudentEvaluation == true && x.IsEvaluation == true);
  87. }
  88. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  89. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  90. query = query.OrderByDescending(o => o.SchoolyearCode).ThenByDescending(o => o.EntityCreateTime);
  91. return query.ToGridResultSet<EvaluationEnterView>(pageIndex, pageSize);
  92. }
  93. public IList<EvaluationEnterView> GetEvaluationEnterViewList(ConfiguretView configuretView, Guid? schoolYearID, Guid? userID, Guid? roleID, bool isStudent)
  94. {
  95. Expression<Func<EM_EvaluationSetting, bool>> expEvaluationSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  96. Expression<Func<EM_EvaluationTable, bool>> expEvaluationTable = x => x.IsEnabled == true;
  97. if (schoolYearID.HasValue)
  98. expEvaluationSetting = expEvaluationSetting.And(x => x.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID == schoolYearID);
  99. if (isStudent)
  100. {
  101. var studentEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == true).FirstOrDefault();
  102. if (studentEvaluationType == null)
  103. {
  104. throw new Exception("未找到对应的参评类型数据!");
  105. }
  106. expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == studentEvaluationType.EvaluationTypeID);
  107. }
  108. else
  109. {
  110. var staffEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == false)
  111. .OrderByDescending(w => w.IsStudent).FirstOrDefault();
  112. if (staffEvaluationType == null)
  113. {
  114. throw new Exception("未找到对应的参评类型数据!");
  115. }
  116. expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == staffEvaluationType.EvaluationTypeID);
  117. }
  118. Expression<Func<EM_EvaluationEnter, bool>> expEvaluationEnter = x => true;// 如果是超级管理员、那么默认显示全部数据
  119. expEvaluationSetting = expEvaluationSetting.And(x => x.OpenStatus == (int)CF_YesOrNoStatus.Yes);
  120. var menuNo = HttpHelper.GetMenuNo();
  121. if (isStudent)//过滤属于自己的评价信息
  122. {
  123. expEvaluationEnter = expEvaluationEnter.And(x => x.StudentUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0);
  124. expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Student.Any(w => w.UserID == userID));
  125. }
  126. else
  127. {
  128. SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo);
  129. if (!dataRange.Equals(SYS_DataRange.All) && !isStudent)//过滤属于自己的评价信息
  130. {
  131. expEvaluationEnter = expEvaluationEnter.And(x => x.StaffUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0);
  132. expEvaluationSetting = expEvaluationSetting.And(x => x.CF_Staff.Any(w => w.UserID == userID));
  133. }
  134. }
  135. var query = EvaluationEnterDAL.GetEvaluationEnterQuery(expEvaluationSetting, expEvaluationEnter, expEvaluationTable);
  136. query = GetQueryByDataRangeByCollege(query);//以院系 区分
  137. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  138. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  139. query = query.OrderByDescending(o => o.EntityCreateTime);
  140. return query.ToList();
  141. }
  142. public void Save(EvaluationEnterView model, bool isStudent)
  143. {
  144. var ProjectStrList = model.jsonDataStr.ToString().JsonToObject<List<EvaluationEnterView>>();//将json转实体集合
  145. EM_EvaluationEnter evaluationEnter = EvaluationEnterDAL.EvaluationEnterRepository.Entities.Where(x => x.EvaluationEnterID == model.EvaluationEnterID).FirstOrDefault();
  146. if (evaluationEnter == null)
  147. {
  148. //新增进入评价信息
  149. evaluationEnter = new EM_EvaluationEnter();
  150. evaluationEnter.EvaluationEnterID = Guid.NewGuid();
  151. evaluationEnter.EducationMissionClassID = model.EducationMissionClassID;
  152. evaluationEnter.EvaluationTableID = model.EvaluationTableID;
  153. evaluationEnter.Remark = model.Remark;
  154. evaluationEnter.TotalScore = model.TotalScore;
  155. if (isStudent)
  156. {
  157. evaluationEnter.StudentUserID = model.UserID;
  158. }
  159. else
  160. {
  161. evaluationEnter.StaffUserID = model.UserID;
  162. }
  163. this.SetNewStatus(evaluationEnter);
  164. foreach (var ProjectEntity in ProjectStrList)
  165. {
  166. EM_EvaluationEnter_EM_EvaluationProject evaluationEnterOrProject = new EM_EvaluationEnter_EM_EvaluationProject();
  167. evaluationEnterOrProject.ID = Guid.NewGuid();
  168. evaluationEnterOrProject.CreateUserID = model.UserID;
  169. evaluationEnterOrProject.CreateTime = DateTime.Now;
  170. evaluationEnterOrProject.ModifyUserID = model.UserID;
  171. evaluationEnterOrProject.ModifyTime = evaluationEnter.ModifyTime;// Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm"));
  172. evaluationEnterOrProject.ProjectID = (Guid)ProjectEntity.ProjectID;
  173. evaluationEnterOrProject.EvaluationScore = ProjectEntity.EvaluationScore;
  174. evaluationEnterOrProject.EvaluationEnterID = evaluationEnter.EvaluationEnterID;
  175. //SetNewStatus(evaluationEnterOrProject);
  176. //evaluationEnterOrProject.
  177. this.UnitOfWork.Add(evaluationEnterOrProject);
  178. }
  179. this.UnitOfWork.Add(evaluationEnter);
  180. }
  181. else
  182. {
  183. //更新进入评价信息
  184. this.SetModifyStatus(evaluationEnter);
  185. evaluationEnter.EducationMissionClassID = model.EducationMissionClassID;
  186. evaluationEnter.EvaluationTableID = model.EvaluationTableID;
  187. evaluationEnter.Remark = model.Remark;
  188. evaluationEnter.TotalScore = model.TotalScore;
  189. if (isStudent)
  190. {
  191. evaluationEnter.StudentUserID = model.UserID;
  192. }
  193. else
  194. {
  195. evaluationEnter.StaffUserID = model.UserID;
  196. }
  197. foreach (var ProjectEntity in ProjectStrList)
  198. {
  199. EM_EvaluationEnter_EM_EvaluationProject evaluationEnterOrProject = new EM_EvaluationEnter_EM_EvaluationProject();
  200. evaluationEnterOrProject.ID = Guid.NewGuid();
  201. evaluationEnterOrProject.CreateUserID = model.UserID;
  202. evaluationEnterOrProject.ModifyUserID = model.UserID;
  203. evaluationEnterOrProject.ModifyTime = evaluationEnter.ModifyTime;//Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm"));
  204. evaluationEnterOrProject.ProjectID = (Guid)ProjectEntity.ProjectID;
  205. evaluationEnterOrProject.EvaluationScore = ProjectEntity.EvaluationScore;
  206. evaluationEnterOrProject.EvaluationEnterID = evaluationEnter.EvaluationEnterID;
  207. //SetModifyStatus(evaluationEnterOrProject);
  208. this.UnitOfWork.Add(evaluationEnterOrProject);
  209. }
  210. this.UnitOfWork.Update(evaluationEnter);
  211. }
  212. this.UnitOfWork.Commit();
  213. }
  214. /// <summary>
  215. /// 查询进入评价基本信息
  216. /// </summary>
  217. /// <param name="evaluationEnterID"></param>
  218. /// <returns></returns>
  219. public EM_EvaluationEnter GetEvaluationEnterView(Guid? evaluationEnterID)
  220. {
  221. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  222. //查询条件
  223. Expression<Func<EM_EvaluationEnter, bool>> expression = (x => x.EvaluationEnterID == evaluationEnterID && x.CreateUserID == curUser.UserID);
  224. return EvaluationEnterDAL.EvaluationEnterRepository.GetSingle(expression);
  225. }
  226. /// <summary>
  227. /// 获取创建评价表集合
  228. /// </summary>
  229. /// <param name="evaluationTableID"></param>
  230. /// <returns></returns>
  231. public IList<CreateTable> GetCreateEvaluationEnterTable(Guid? evaluationTableID, ConfiguretView configuretView)
  232. {
  233. List<CreateTable> CreateTableList = new List<CreateTable>();
  234. //1.0 查询评价指标信息
  235. var dataTargetList = EvaluationTargetServices.Value.GetEvaluationTargetViewList(configuretView, evaluationTableID, null).Select(x => new
  236. {
  237. x.TargetID,
  238. x.NormID,
  239. x.Name,
  240. x.Weight
  241. }).ToList();
  242. CreateTable tables = null;
  243. foreach (var dataTarget in dataTargetList)
  244. {
  245. //2.0 查询评分标准明细
  246. var NormNames = string.Join(" ", EvaluationNormServices.Value.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select(s => s.Name + s.Weight));
  247. tables = new CreateTable();
  248. tables.OrderID = dataTarget.Name;
  249. tables.Weight = dataTarget.Weight + "";
  250. tables.NormNames = NormNames; //构建一级标题
  251. CreateTableList.Add(tables);
  252. //3.0 查询评分项目信息
  253. var dataProjectList = EvaluationProjectServices.Value.GetEvaluationProjectViewList(configuretView, dataTarget.TargetID, evaluationTableID, null).Select(x => new
  254. {
  255. x.ProjectID,
  256. x.OrderID,
  257. x.Name,
  258. x.Weight,
  259. x.Code
  260. }).ToList();
  261. foreach (var dataProject in dataProjectList)
  262. {
  263. tables = new CreateTable();
  264. //4.0 查询评分评分标准信息
  265. //格式: 优,中,差
  266. var NormNames1 = string.Join(",", EvaluationNormServices.Value.GetEvaluationNormDetailViewList(dataTarget.NormID.Value).Select((s, index) => s.Name));
  267. //构建一级标题下、标题
  268. tables.OrderID = dataProject.OrderID + "";
  269. tables.ProjectName = dataProject.Name;
  270. tables.Weight = dataProject.Weight + "";
  271. tables.NormNames = NormNames;
  272. CreateTableList.Add(tables);
  273. }
  274. }
  275. return CreateTableList;
  276. }
  277. /// <summary>
  278. /// 查询进入评价教研室、课程名称、教师名称相关信息
  279. /// </summary>
  280. /// <param name="educationMissionClassID">教学任务班ID</param>
  281. /// <param name="evaluationTableID">评价表ID</param>
  282. /// <returns></returns>
  283. public EvaluationEnterView GetEvaluationEnterByMissionClass(Guid? educationMissionClassID, Guid? evaluationTableID)
  284. {
  285. var queryView = EvaluationEnterDAL.GetEvaluationEnterTitleView(educationMissionClassID, evaluationTableID);
  286. return queryView;
  287. }
  288. //评价项目明细
  289. public IList<EvaluationEnterView> GetEvaluationEnterByNormDetail(Guid? evaluationEnterID, Guid? evaluationTableID, Guid? normID)
  290. {
  291. var queryView = EvaluationEnterDAL.GetEvaluationEnterView(evaluationEnterID, evaluationTableID);
  292. //if (normID.HasValue)
  293. //{
  294. // queryView = queryView.Where(x => x.NormID == normID);
  295. //}
  296. return queryView.ToList();
  297. }
  298. public IList<EM_EvaluationEnter_EM_EvaluationProject> GetEvaluationEnter_EM_EvaluationProjectList(Guid? evaluationEnterID)
  299. {
  300. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  301. var queryView = EvaluationEnterDAL.EvaluationEnter_EM_EvaluationProjectRepository.GetList(x => x.EvaluationEnterID == evaluationEnterID && x.CreateUserID == curUser.UserID);
  302. return queryView.ToList();
  303. }
  304. public EvaluationEnterView GetEvaluationSettingOrEnterView(Guid? evaluationSettingID, Guid userID, Guid? roleID, bool isStudent)
  305. {
  306. EM_EvaluationSetting evaluationSetting = EvaluationEnterDAL.EvaluationSettingRepository.Entities.Where(x => x.EvaluationSettingID == evaluationSettingID).FirstOrDefault();
  307. Expression<Func<EM_EvaluationTable, bool>> expEvaluationTable = x => x.IsEnabled == true;
  308. if (isStudent)
  309. {
  310. var studentEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == true).FirstOrDefault();
  311. if (studentEvaluationType == null)
  312. {
  313. throw new Exception("未找到对应的参评类型数据!");
  314. }
  315. expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == studentEvaluationType.EvaluationTypeID);
  316. }
  317. else
  318. {
  319. var staffEvaluationType = EvaluationTypeRepository.Entities.Where(w => w.IsStudent == false)
  320. .OrderByDescending(w => w.IsStudent).FirstOrDefault();
  321. if (staffEvaluationType == null)
  322. {
  323. throw new Exception("未找到对应的参评类型数据!");
  324. }
  325. expEvaluationTable = expEvaluationTable.And(x => x.EvaluationTypeID == staffEvaluationType.EvaluationTypeID);
  326. }
  327. Expression<Func<EM_EvaluationEnter, bool>> expEvaluationEnter = x => true;// 如果是超级管理员、那么默认显示全部数据
  328. var menuNo = HttpHelper.GetMenuNo();
  329. if (isStudent)//过滤属于自己的评价信息
  330. {
  331. expEvaluationEnter = expEvaluationEnter.And(x => x.StudentUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0);
  332. }
  333. else
  334. {
  335. SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo);
  336. if (!dataRange.Equals(SYS_DataRange.All) && !isStudent)//过滤属于自己的评价信息
  337. {
  338. expEvaluationEnter = expEvaluationEnter.And(x => x.StaffUserID == userID && x.EM_EvaluationEnter_EM_EvaluationProject.Count() > 0);
  339. }
  340. }
  341. var query = EvaluationEnterDAL.GetEvaluationEnterQuery(null, expEvaluationEnter, expEvaluationTable);
  342. if (isStudent)
  343. {
  344. Expression<Func<CF_Student, bool>> expStudent = x => true;
  345. Expression<Func<EM_EvaluationGradeControl, bool>> expEvaluationGradeControl = x => true;
  346. expStudent = expStudent.And(x => x.UserID == userID);
  347. //expEvaluationGradeControl = expEvaluationGradeControl.And(x => x.CF_Schoolyear.SchoolyearID == schoolYearID);
  348. query = EvaluationEnterDAL.GetStudentEvaluationEnterQuery(null, expEvaluationEnter, expEvaluationTable, expEvaluationGradeControl, expStudent);
  349. }
  350. //query = GetQueryByDataRangeByCollege(query);
  351. if (evaluationSettingID.HasValue && evaluationSettingID != Guid.Empty)
  352. {
  353. query = query.Where(w => w.EducationMissionClassID == evaluationSetting.EducationMissionClassID && w.EvaluationSettingID == evaluationSettingID);
  354. }
  355. return query.FirstOrDefault();
  356. }
  357. public bool GteDataRange(Guid? roleID)
  358. {
  359. bool IsView = true;
  360. var menuNo = HttpHelper.GetMenuNo();
  361. SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(roleID, menuNo);
  362. if (dataRange.Equals(SYS_DataRange.All))
  363. {
  364. IsView = false;
  365. }
  366. if (dataRange.Equals(SYS_DataRange.Campus))
  367. {
  368. IsView = true;
  369. }
  370. if (dataRange.Equals(SYS_DataRange.College))
  371. {
  372. IsView = true;
  373. }
  374. return IsView;
  375. }
  376. }
  377. }