|
|
using Server.Factory;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using Utils;
|
|
|
using VM;
|
|
|
|
|
|
namespace Web
|
|
|
{
|
|
|
public class AutoCommit
|
|
|
{
|
|
|
public static AutoCommit Instance = new AutoCommit();
|
|
|
|
|
|
private TimerEvent autoCommitEvent;
|
|
|
private AutoCommit()
|
|
|
{
|
|
|
autoCommitEvent = new TimerEvent("未完成试卷自动提交", new TimeSpan(0, 1, 0), Commmit, null);
|
|
|
}
|
|
|
|
|
|
public void Init()
|
|
|
{
|
|
|
autoCommitEvent.Start();
|
|
|
}
|
|
|
|
|
|
private void Commmit()
|
|
|
{
|
|
|
var now = DateTime.Now;
|
|
|
var tarPapers = (from x in ExamCaches.PaperCache.Values
|
|
|
where now >= x.EndDate.AddMinutes(1) && x.Status == (int)ExamPaperStatus.Publish
|
|
|
select x).ToList();
|
|
|
if (tarPapers != null && tarPapers.Count > 0)
|
|
|
{
|
|
|
for (int i = 0; i < tarPapers.Count; i++)
|
|
|
{
|
|
|
var paperInfo = tarPapers[i];
|
|
|
var answerInfo = SvrFactory.Instance.ExamSvr.GetPaperForScore(tarPapers[i].Id);
|
|
|
|
|
|
//只处理未自己交卷的部分
|
|
|
var summaryInfo = answerInfo.UserSummary.Where(l => l.Status != (int)PaperUserSummaryStatus.Marked);
|
|
|
foreach (var tarSummary in summaryInfo)
|
|
|
{
|
|
|
//计算待评分值
|
|
|
var count = (from x in paperInfo.Details
|
|
|
join y in ExamCaches.QuestionCache on x.QuesionId equals y.Key
|
|
|
where y.Value.StructType == (int)StructType.Synopsis || y.Value.StructType == (int)StructType.Sketchy
|
|
|
join z in answerInfo.UserAnswerResult on x.QuesionId equals z.QuesionId
|
|
|
where z.Result != (int)PaperUserAnswerStatus.Init && z.UserId == tarSummary.UserId && z.UserScore == null
|
|
|
select x).Count();
|
|
|
if (count > 0)
|
|
|
{
|
|
|
tarSummary.UnScoredCount = count;
|
|
|
tarSummary.Score = 0;
|
|
|
tarSummary.Status = (int)PaperUserSummaryStatus.Submitted;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tarSummary.UnScoredCount = 0;
|
|
|
tarSummary.Score = (from x in answerInfo.UserAnswerResult
|
|
|
where x.UserId == tarSummary.UserId && x.UserScore.HasValue
|
|
|
select x.UserScore.Value).Sum();
|
|
|
tarSummary.Status = (int)PaperUserSummaryStatus.Marked;
|
|
|
}
|
|
|
if (!tarSummary.FinishDate.HasValue)
|
|
|
{
|
|
|
tarSummary.FinishDate = paperInfo.EndDate;
|
|
|
}
|
|
|
|
|
|
var res = SvrFactory.Instance.ExamSvr.UpdatePaperUserSummary(tarSummary);
|
|
|
if (!res)
|
|
|
{
|
|
|
throw new Exception("自动交卷算分更新用户得分失败!1分钟后重试……");
|
|
|
}
|
|
|
}
|
|
|
if (answerInfo.UserSummary.Count(l => l.Status == (int)PaperUserSummaryStatus.Marked) == answerInfo.UserSummary.Count)
|
|
|
{
|
|
|
paperInfo.Status = (int)ExamPaperStatus.End;
|
|
|
if (SvrFactory.Instance.ExamSvr.UpdatePaper(paperInfo))
|
|
|
{
|
|
|
var cachePaperModel = ExamCaches.PaperCache[paperInfo.Id];
|
|
|
cachePaperModel.Status = (int)ExamPaperStatus.End;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |