/// <summary> /// 将<see cref="ExamUsers"/>类型转换为<see cref="UserExamSearchResultItem"/>类型数据 /// </summary> /// <param name="sourceData"><see cref="ExamUsers"/>源数据</param> /// <returns></returns> public IEnumerable <UserExamSearchResultItem> ConvertToSearchResult(IEnumerable <ExamUsers> sourceData) { if (sourceData == null) { yield break; } //得到用户集合 long[] userIds = sourceData.Select(p => p.UserId).ToArray(); var users = UsersAccessor.GetSimpleUsers(userIds); //得到考卷模板集合 long[] examIds = sourceData.Select(p => p.ExamId).ToArray(); var exams = ExamsAccessor.GetSimpleExams(examIds); //循环处理 foreach (var item in sourceData) { var user = users.FirstOrDefault(p => p.UserId == item.UserId); var exam = exams.FirstOrDefault(p => p.ExamId == item.ExamId); var result = new UserExamSearchResultItem { UserExamId = item.Id, UserId = item.UserId, ExamId = item.ExamId, ActualTime = item.Times, MarkingStatus = item.MarkingStatus, MarkingTime = item.MarkingTime, CreateTime = item.CreateTime, PostTime = item.PostTime, Score = item.Total }; if (user != null) { result.UserMobile = user.Mobile; result.UserName = user.Name; result.UserTitle = user.Title; } if (exam != null) { result.ExamTitle = exam.Title; result.ExamType = exam.ExamType; result.MaxTime = exam.Time; result.Total = exam.Total; result.Pass = exam.Pass; } yield return(result); } }
/// <summary> /// 获取指定用户的简要数据集合 /// </summary> /// <param name="status"></param> /// <returns></returns> public List <UserSimpleInfo> GetSimpleUsers(int?status = null) { return(UsersAccessor.GetSimpleUsers(status)); }