|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using System.Web.Routing;
|
|
|
using Server.Factory;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using Utils;
|
|
|
using VM;
|
|
|
|
|
|
namespace Web
|
|
|
{
|
|
|
public class MvcApplication : System.Web.HttpApplication
|
|
|
{
|
|
|
#pragma warning disable CS0414 // 字段“MvcApplication.isGetP2P”已被赋值,但从未使用过它的值
|
|
|
bool isGetP2P = false;
|
|
|
#pragma warning restore CS0414 // 字段“MvcApplication.isGetP2P”已被赋值,但从未使用过它的值
|
|
|
bool isCalcScore = false;
|
|
|
AssessmentCalculationBLL assessmentCalculationBLL = new AssessmentCalculationBLL();
|
|
|
|
|
|
|
|
|
protected void Application_Start()
|
|
|
{
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
|
|
|
|
GlobalFilters.Filters.Add(new IdentifyPermission());
|
|
|
GlobalFilters.Filters.Add(new ExceptionAttribute());
|
|
|
|
|
|
Initialize();
|
|
|
|
|
|
//定时更新考核状态
|
|
|
double time_1 = AppSettingsHelper.GetIntByKey("Time1", 3) * 60 * 1000;//3分钟
|
|
|
double time_2 = AppSettingsHelper.GetIntByKey("Time2", 60) * 60 * 1000;//60分钟
|
|
|
double time_3 = AppSettingsHelper.GetIntByKey("Time3", 180) * 60 * 1000;//180分钟
|
|
|
double time_5 = AppSettingsHelper.GetIntByKey("Time5", 30) * 60 * 1000;//一小时一次,但星期天的晚上才执行
|
|
|
|
|
|
#region 3分钟执行一次
|
|
|
//System.Timers.Timer timer_1 = new System.Timers.Timer();
|
|
|
//timer_1.Enabled = true;
|
|
|
//timer_1.Interval = time_1;//3分钟执行一次
|
|
|
//timer_1.Start();
|
|
|
//timer_1.Elapsed += new System.Timers.ElapsedEventHandler(Timer1_Elapsed);
|
|
|
#endregion
|
|
|
|
|
|
////////#region 60分钟执行一次 原本就被注释掉
|
|
|
////////System.Timers.Timer timer_2 = new System.Timers.Timer();
|
|
|
////////timer_2.Enabled = true;
|
|
|
////////timer_2.Interval = time_2; //1小时执行一次
|
|
|
////////timer_2.Start();
|
|
|
////////timer_2.Elapsed += new System.Timers.ElapsedEventHandler(Timer2_Elapsed);
|
|
|
////////#endregion
|
|
|
|
|
|
#region 180分钟执行一次
|
|
|
//System.Timers.Timer timer_3 = new System.Timers.Timer();
|
|
|
//timer_3.Enabled = true;
|
|
|
//timer_3.Interval = time_3; //3小时执行一次
|
|
|
//timer_3.Start();
|
|
|
//timer_3.Elapsed += new System.Timers.ElapsedEventHandler(Timer3_Elapsed);
|
|
|
#endregion
|
|
|
|
|
|
#region 1天一次
|
|
|
//System.Timers.Timer timer_5 = new System.Timers.Timer();
|
|
|
//timer_5.Enabled = true;
|
|
|
//timer_5.Interval = time_5;
|
|
|
//timer_5.Start();
|
|
|
//timer_5.Elapsed += new System.Timers.ElapsedEventHandler(Timer5_Elapsed);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
//////////////第一次启动时,异步获取P2P数据 原本就被注释掉
|
|
|
////////////if (!isGetP2P)
|
|
|
////////////{
|
|
|
//////////// Task.Run(() =>
|
|
|
//////////// {
|
|
|
//////////// P2PHelper p2p = new P2PHelper();
|
|
|
//////////// p2p.AddBlukP2PProduce();
|
|
|
//////////// });
|
|
|
//////////// isGetP2P = true;
|
|
|
////////////}
|
|
|
}
|
|
|
|
|
|
#region 定时器事件
|
|
|
/// <summary>
|
|
|
/// Time1定时器方法(默认5分钟执行)
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
if (!isCalcScore)
|
|
|
{
|
|
|
AutoCommitTrainExam();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
|
///// Time2定时器方法(默认60分钟执行)
|
|
|
///// </summary>
|
|
|
///// <param name="sender"></param>
|
|
|
///// <param name="e"></param>
|
|
|
//private void Timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
//{
|
|
|
// // 得到 hour minute second 如果等于某个值就开始执行某个程序。
|
|
|
// int intHour = e.SignalTime.Hour;
|
|
|
// int intMinute = e.SignalTime.Minute;
|
|
|
// int intSecond = e.SignalTime.Second;
|
|
|
|
|
|
// // 定制时间; 比如 在01:30 :00 的时候执行某个函数
|
|
|
// int iHour = 1;
|
|
|
// //晚上1点更新,只判断销售
|
|
|
// if (intHour == iHour)
|
|
|
// {
|
|
|
// P2PHelper p2p = new P2PHelper();
|
|
|
// p2p.AddBlukP2PProduce();
|
|
|
// isGetP2P = true;
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Time3定时器方法(默认180分钟执行)
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void Timer3_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
#region 定时清理Question假删
|
|
|
//获取假删数据
|
|
|
List<int> delete_question_list = ExamCaches.QuestionCache.Values.Where(x => x.Status == (int)QuestionStauts.Delete).Select(x => x.Id).ToList();
|
|
|
if (delete_question_list != null && delete_question_list.Count > 0)
|
|
|
{
|
|
|
//在数据库内进行查找,删除未组卷的,并把对应Id集合返回
|
|
|
List<int> remove_question_list = SvrFactory.Instance.ExamSvr.RemoveQuestion(delete_question_list);
|
|
|
//清除未组卷的缓存
|
|
|
if (remove_question_list != null && remove_question_list.Count > 0)
|
|
|
{
|
|
|
foreach (var item in remove_question_list)
|
|
|
{
|
|
|
ExamCaches.QuestionCache.SyncCache(item, null, true);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 备份数据库
|
|
|
/// </summary>
|
|
|
private void Timer5_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
TrainingCaches.P2PProductList1.Clear();
|
|
|
TrainingCaches.P2PProductList1 = new SynchronisedDictionary<int, P2PProductVM>(x => x.Id, SvrFactory.Instance.TrainingSvr.GetP2PProductbyCache());
|
|
|
|
|
|
//星期几,0表示星期天
|
|
|
int week = (int)e.SignalTime.DayOfWeek;
|
|
|
|
|
|
int ihour = e.SignalTime.Hour;
|
|
|
int iminu = e.SignalTime.Minute;
|
|
|
//星期天凌晨2点
|
|
|
if (week == 0 && (ihour == 2 && (iminu >= 0 && iminu <= 30)))
|
|
|
{
|
|
|
//DataInit.DelFolderBakFile();
|
|
|
//备份数据库
|
|
|
DataInit.CreateDataBak();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 私有方法
|
|
|
/// <summary>
|
|
|
/// 销售机会/实训考核自动提交
|
|
|
/// </summary>
|
|
|
private void AutoCommitTrainExam()
|
|
|
{
|
|
|
if (TrainingCaches.ExamIDList != null && TrainingCaches.ExamIDList.Count > 0)
|
|
|
{
|
|
|
//建立副本
|
|
|
List<int> tempList = new List<int>();
|
|
|
tempList.AddRange(TrainingCaches.ExamIDList);
|
|
|
|
|
|
foreach (int item in tempList)
|
|
|
{
|
|
|
var train = TrainingBLL.GetTrainExam(item);
|
|
|
//若实训已结束
|
|
|
if (train != null && train.EndDate.AddMinutes(1) <= DateTime.Now)
|
|
|
{
|
|
|
isCalcScore = true;
|
|
|
|
|
|
if (train.ExamTypeId == (int)ExamineType.TrainingEvaluation)
|
|
|
{
|
|
|
#region 实训考核
|
|
|
//参与考试,但未提交试卷的
|
|
|
var accessList = TrainingCaches.EntryAssessmentList.Where(x => x.TrainExamId == train.Id).ToList();
|
|
|
if (accessList != null && accessList.Count > 0)
|
|
|
{
|
|
|
#region 算分并提交试卷
|
|
|
//考核模块列表
|
|
|
List<ExamModuleVM> ExamModuleList = TrainingCaches.ExamModuleList.GetList();
|
|
|
//考核点列表
|
|
|
List<ExamPointVM> ExamPointList = TrainingCaches.ExamPointList.GetList();
|
|
|
//循环每个未手动交卷学生
|
|
|
foreach (var access in accessList)
|
|
|
{
|
|
|
//建议书
|
|
|
var proposal = ProposalBLL.GetProposal(train.Id, access.UserId);
|
|
|
if (proposal == null)
|
|
|
{
|
|
|
#region 只进入考试,然后什么都没干
|
|
|
proposal = new ProposalVM();
|
|
|
proposal.TrainExamId = train.Id;
|
|
|
proposal.UserId = access.UserId;
|
|
|
proposal.ProposalName = "";
|
|
|
proposal.ProposalNum = NumHelper.Instance.GetNum(NumberType.Proposal);
|
|
|
proposal.CreateDate = DateTime.Now;
|
|
|
//保存建议书
|
|
|
proposal.Id = SvrFactory.Instance.TrainingSvr.AddProposal(proposal);
|
|
|
//添加成功
|
|
|
if (proposal.Id > 0)
|
|
|
{
|
|
|
TrainingCaches.ProposalCache.SyncCache(proposal.Id, proposal, false);
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
#region 算分
|
|
|
//循环考核点算分
|
|
|
AssessmentResultsVM model = new AssessmentResultsVM();
|
|
|
foreach (var train_item in train.TrainExamDetail)
|
|
|
{
|
|
|
var detailInfo = assessmentCalculationBLL.AssessmentCalculation(train_item, proposal, ExamModuleList, ExamPointList);
|
|
|
if (detailInfo != null)
|
|
|
{
|
|
|
AssessmentResultsDetailVM assessmentResultsDetail = new AssessmentResultsDetailVM();
|
|
|
assessmentResultsDetail.AssessmentResultsId = detailInfo.AssessmentResultsId;
|
|
|
assessmentResultsDetail.ExamPointType = detailInfo.ExamPointType;
|
|
|
assessmentResultsDetail.ModularId = detailInfo.ModularId;
|
|
|
assessmentResultsDetail.AssessmentPoint = detailInfo.AssessmentPoint;
|
|
|
assessmentResultsDetail.Status = detailInfo.Status;
|
|
|
assessmentResultsDetail.Score = detailInfo.Score;
|
|
|
|
|
|
assessmentResultsDetail.ReferAnswer = detailInfo.ReferAnswer;
|
|
|
assessmentResultsDetail.StuAnswer = detailInfo.StuAnswer;
|
|
|
|
|
|
model.DetailList.Add(assessmentResultsDetail);
|
|
|
}
|
|
|
}
|
|
|
model.UserId = access.UserId;
|
|
|
model.ClassId = access.ClassId;
|
|
|
model.TrainExamId = train.Id;
|
|
|
model.TotalScore = train.TrainExamDetail.Sum(x => x.Score);//考核总分
|
|
|
model.SubjectiveResults = 0;
|
|
|
model.CreateTime = DateTime.Now;
|
|
|
if (model.DetailList != null && model.DetailList.Count > 0)
|
|
|
{
|
|
|
//客观成绩
|
|
|
model.ObjectiveResults = model.DetailList.Where(x => x.Status == (int)IsCorrect.Correct).Sum(x => x.Score);
|
|
|
}
|
|
|
var train_exampoint_list = train.TrainExamDetail.Select(x => x.ExamPointId).ToList();
|
|
|
int SubjectiveNum = ExamPointList.Count(x => train_exampoint_list.Contains(x.Id) && x.ExamPointType == (int)ExamPointType.Subjective);
|
|
|
//当存在主观题时,将考核状态更新为待评分,否则为已评分
|
|
|
proposal.UpdateDate = DateTime.Now;
|
|
|
if (SubjectiveNum > 0)
|
|
|
{
|
|
|
model.TrainExamStatus = (int)ExaminationStatus.WaitScore;
|
|
|
proposal.Status = (int)ProposalStatus.UnAudited;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
model.TrainExamStatus = (int)ExaminationStatus.AlreadyScore;
|
|
|
proposal.Status = (int)ProposalStatus.Audited;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 保存
|
|
|
//保存成绩
|
|
|
if (SvrFactory.Instance.TrainingSvr.AddAssessmentResults(model))
|
|
|
{
|
|
|
//更新建议书
|
|
|
SvrFactory.Instance.TrainingSvr.UpdateProposal(proposal);
|
|
|
//更新考核结束时间
|
|
|
access.EndTime = train.EndDate;
|
|
|
if (SvrFactory.Instance.TrainingSvr.UpdateEntryAssessment(access))
|
|
|
{
|
|
|
//成功则移除缓存
|
|
|
TrainingCaches.EntryAssessmentList.RemoveAll(x => x.TrainExamId == train.Id && x.UserId == access.UserId);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
#region 校验是否存在未评分列表,不存在则可以更新考核状态
|
|
|
List<int> count = SvrFactory.Instance.TrainingSvr.CountTrainExamStatus(item);
|
|
|
//重现获取最新的销售机会/实训考核
|
|
|
train = SvrFactory.Instance.TrainingSvr.GetTrainExam(item);
|
|
|
bool isChange = false;
|
|
|
if (count[0] <= 0 && count[1] > 0)
|
|
|
{
|
|
|
//未评数量小于等于0,已评数量大于0
|
|
|
train.TrainExamStatus = (int)TrainExamStatu.AlreadGrade;
|
|
|
isChange = true;
|
|
|
}
|
|
|
else if (count[0] <= 0 && count[1] <= 0)
|
|
|
{
|
|
|
//未评数量小于等于0,已评数量小于等于0
|
|
|
//没有人提交销售机会/实训考核,不显示
|
|
|
train.TrainExamStatus = (int)TrainExamStatu.NoShow;
|
|
|
isChange = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//未评数量大于0
|
|
|
//不用处理
|
|
|
}
|
|
|
|
|
|
if (isChange)
|
|
|
{
|
|
|
if (SvrFactory.Instance.TrainingSvr.UpdateTrainExam(train))
|
|
|
{
|
|
|
TrainingCaches.ExamIDList.RemoveAll(x => x == train.Id);
|
|
|
|
|
|
#region 销售机会根据分数,潜在客户转已有客户
|
|
|
if (train.ExamTypeId == (int)ExamineType.SalesOpportunities)
|
|
|
{
|
|
|
SvrFactory.Instance.TrainingSvr.UpdateCustomerTypeList(train.Id);
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
isCalcScore = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
private void Initialize()
|
|
|
{
|
|
|
//启动WCF服务
|
|
|
while (!SvrFactory.Instance.Initialize())
|
|
|
{
|
|
|
Thread.Sleep(50);//这里必须等WCF连接上
|
|
|
}
|
|
|
|
|
|
//初始化缓存
|
|
|
StructureCaches.Init();
|
|
|
ResourceCaches.Init();
|
|
|
ExamCaches.Init();
|
|
|
TrainingCaches.Init();
|
|
|
|
|
|
//初始化缓存定时清理
|
|
|
CacheCleaner.Instance.Init();
|
|
|
//初始化自动提交定时器
|
|
|
AutoCommit.Instance.Init();
|
|
|
|
|
|
//DataInit.DelFolderBakFile();
|
|
|
DataInit.CreateDataBak();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|