You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
4.5 KiB
C#
102 lines
4.5 KiB
C#
using Server.Factory;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using VM;
|
|
using Utils;
|
|
|
|
namespace Web
|
|
{
|
|
public class ExamBLL
|
|
{
|
|
/// <summary>
|
|
/// 理论考核自动组卷
|
|
/// </summary>
|
|
/// <param name="paper"></param>
|
|
public void TheoAutoFormPaper(PaperVM paper)
|
|
{
|
|
paper.Details = new List<PaperDetailVM>();
|
|
var scoreInfo = paper.ScoreInfo;
|
|
foreach (var item in scoreInfo)
|
|
{
|
|
var charpterList = item.CharpterID.Split(',').Select(l => int.Parse(l)).ToList();
|
|
var questions = (from x in ExamCaches.QuestionCache
|
|
where charpterList.Contains(x.Value.CharpterID) && (x.Value.Status != (int)QuestionStauts.Delete
|
|
&& x.Value.Status != (int)QuestionStauts.Close) && (x.Value.UserId == paper.UserId || x.Value.UserId == 0)
|
|
&& !(ExamCaches.QuestionHiddenCache.Values.Where(y => y.UserId == paper.UserId).Select(y => y.QuestionId).ToList()).Contains(x.Value.Id)
|
|
// &&x.Value.UserId==paper.UserId
|
|
orderby Guid.NewGuid()
|
|
select x.Key).Take(item.Count).ToList();
|
|
paper.Details.AddRange(questions.Select(l => new PaperDetailVM { QuesionId = l }));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 认证考试自动组卷
|
|
/// </summary>
|
|
/// <param name="paper"></param>
|
|
/// <param name="errCode"></param>
|
|
/// <returns></returns>
|
|
public bool CertAutoFromPaper(PaperVM paper, out string errCode)
|
|
{
|
|
//获取班级Id
|
|
int classId = MvcHelper.User.UserClassInfo[0].ClassId;
|
|
//根据班级Id获取教师Id
|
|
int teacherId = StructureCaches.ClassCache[classId].TeacherId;
|
|
|
|
errCode = string.Empty;
|
|
paper.Details = new List<PaperDetailVM>();
|
|
var scoreInfo = paper.ScoreInfo;
|
|
foreach (var item in scoreInfo)
|
|
{
|
|
var charpterList = item.CharpterID.Split(',').Select(l => int.Parse(l)).ToList();
|
|
var questions = (from x in ExamCaches.QuestionCache
|
|
where charpterList.Contains(x.Value.CharpterID) && (x.Value.Status != (int)QuestionStauts.Delete
|
|
&& x.Value.Status != (int)QuestionStauts.Close) && (x.Value.UserId == teacherId || x.Value.UserId == 0)
|
|
&& !(ExamCaches.QuestionHiddenCache.Values.Where(y => y.UserId == teacherId).Select(y=>y.QuestionId).ToList()).Contains(x.Value.Id)
|
|
orderby Guid.NewGuid()
|
|
select x.Key).Take(item.Count).ToList();
|
|
if (questions.Count < item.Count)
|
|
{
|
|
errCode = TrainingCaches.TheoryChapterCache[paper.CharpterList[0].CharpterID].ChapterName + "题量不足!";
|
|
return false;
|
|
}
|
|
paper.Details.AddRange(questions.Select(l => new PaperDetailVM { QuesionId = l }));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页获取用户总结信息
|
|
/// </summary>
|
|
/// <param name="paperId"></param>
|
|
/// <param name="classID"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="total"></param>
|
|
/// <returns></returns>
|
|
public List<PaperUserSummaryVM> PageGetUserSummary(int paperId, int? classID, bool sortWay, int pageIndex, int pageSize, out int total)
|
|
{
|
|
total = 0;
|
|
List<PaperUserSummaryVM> source = null;
|
|
if (!ExamCaches.UserSummaryCache.ContainsKey(paperId))
|
|
{
|
|
source = SvrFactory.Instance.ExamSvr.GetAllUserSummaryByPaperId(paperId);
|
|
if (source != null && source.Count > 0)
|
|
{
|
|
ExamCaches.UserSummaryCache.SyncCache(paperId, source, false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
source = ExamCaches.UserSummaryCache[paperId];
|
|
}
|
|
var res = (classID.HasValue ? source.Where(l => l.ClassId == classID.Value): source );
|
|
if (sortWay)
|
|
return res.OrderBy(x=>x.Score).Page(pageIndex, pageSize, out total);
|
|
else
|
|
return res.OrderByDescending(x => x.Score).Page(pageIndex, pageSize, out total);
|
|
}
|
|
}
|
|
} |