private void UpdateAnswer(string scoreJson) { Application.Current.Dispatcher.Invoke(new Action(() => { string errStr = ""; ErrMsgLog msgInfo = new ErrMsgLog(); msgInfo.user = GlobalUser.USER.Mobile; if (GlobalUser.ErrScoreInfo == null) { GlobalUser.ErrScoreInfo = new Dictionary <string, ExamScoreNavigateMessage>(); } try { if (!GlobalUser.DoAnswer) { //errStr = $"评分失败 -- result: 当前不是做题过程!"; msgInfo.msginfo = "评分失败"; msgInfo.error = "当前不是做题过程"; msgInfo.isErr = true; GlobalUser.DoneScore = ScoreType.NoScore; Log4NetHelper.Error(msgInfo.ToJson()); return; } ScoreRoot score = JsonHelper.FromJson <ScoreRoot>(scoreJson.Replace("\"params\"", "\"param\"")); if (!string.IsNullOrEmpty(score.errId)) { //20009 网络无效 //20013 评分超时 //20010 调用顺序出错 //42003 请求顺序出错 //可以重评 if (_errIds.Contains(score.errId)) { ExamScore.SubmitNum++; } else { ExamScore.SubmitNum = 999; } if (!GlobalUser.ErrScoreInfo.ContainsKey(ExamScore.WaveFileName)) { GlobalUser.ErrScoreInfo.Add(ExamScore.WaveFileName, ExamScore); } throw new Exception($"评分失败 errID:{score.errId}"); } string scoreStr = "0"; if (ExamScore.EType == EngineType.CHOICE) { var answer = ExamScore.AnswerModel.item_answer.Split(new string[] { "|" }, StringSplitOptions.None); ExamScore.AnswerModel.item_answer = answer[answer.Length - 1]; if (score.result.confidence >= (ExamScore.AnswerModel.item_score * 0.45) && ExamScore.AnswerModel.item_answer.ToLower().Trim() .Equals(score.result.recognition.ToLower().Trim())) { scoreStr = ExamScore.AnswerModel.item_score.ToString("f2"); } } else { scoreStr = score.result.overall .ToString(); //((score.result.overall / 100) * ExamScore.AnswerModel.item_score).ToString("f2"); } ExamScore.AnswerModel.user_answer = scoreJson.TrimEnd('\0'); ExamScore.AnswerModel.exam_score = Convert.ToSingle(scoreStr); //Convert.ToSingle(scoreStr); if (ExamScore.AnswerModel.item_score < 0) { ExamScore.AnswerModel.exam_score = Math.Abs(ExamScore.AnswerModel.item_score); } var result = WebApiProxy.GetHtmlRespInfo(ExamScore.AnswerModel, ApiType.SubmitRecord, GlobalUser.USER.Token); Log4NetHelper.Info($"完成评分 -- result:{result.retCode == 1} {result.retCode} {result.retMsg}"); //Log4NetHelper.Info($"完成评分 -- 音频文件: {ExamScore.WaveFileName}"); GlobalUser.DoneItemExam = true; GlobalUser.DoneScore = ScoreType.ScoreSuccess; //评分 if (result?.retCode != 0) { //errStr = $"errmsg:上传评分失败,result:{result.retCode} {result.retCode} {result.retMsg}"; msgInfo.msginfo = "上传评分失败"; msgInfo.error = $"{result.retCode} {result.retCode} {result.retMsg}"; msgInfo.isErr = true; GlobalUser.DoneScore = ScoreType.ScoreFailure; Log4NetHelper.Error(msgInfo.ToJson()); if (result.retCode == 4001 && result.retMsg.Contains("密码")) { //回到登录 GlobalUser.CleanUp(); Messenger.Default.Send(new ExamScoreNavigateMessage(), "LoginFailure"); //errStr += ",LoginFailure:已在其他设备登录!"; msgInfo.error += ",已在其他设备登录"; msgInfo.isErr = true; } } else { msgInfo.isErr = false; if (GlobalUser.ErrScoreInfo != null && GlobalUser.ErrScoreInfo.Count > 0) { //移除异常记录 if (GlobalUser.ErrScoreInfo.ContainsKey(ExamScore.WaveFileName)) { GlobalUser.ErrScoreInfo.Remove(ExamScore.WaveFileName); } else { foreach (var key in GlobalUser.ErrScoreInfo.Keys) { if (GlobalUser.ErrScoreInfo.Values.ToList().Where(w => w.AnswerModel.exam_attend_id == GlobalUser.AttendPaperItemId && w.AnswerModel.item_id == ExamScore.AnswerModel.item_id).Any()) { GlobalUser.ErrScoreInfo.Remove(key); break; } } } GlobalUser.UpdateErrScore(GlobalUser.USER.Mobile, GlobalUser.SelectPaperNumber, GlobalUser.AttendPaperItemId); } if (File.Exists(Path.Combine(ExamScore.WaveFileName))) { File.Delete(ExamScore.WaveFileName); } if (GlobalUser.MenuType == MenuType.Sync) { //更新 当前 同步 评分 Messenger.Default.Send( new SyncScoreCallbckMessage(ExamScore.ModelTarget, score, ExamScore.EType), ExamScore.ModelTarget); //更新 左侧列表 得分 Messenger.Default.Send( new SyncUploadScoreCallbckMessage(ExamScore.ModelTarget, Convert.ToInt32(score.result.overall), ExamScore.AnswerModel.item_id), "SyncUploadScoreNavi"); } } } catch (Exception ex) { //errStr = $"[user:{GlobalUser.USER?.Mobile},error:{ex},scoreJson: {scoreJson}]"; msgInfo.msginfo = "上传评分失败"; msgInfo.error = ex; msgInfo.scoreJson = scoreJson; msgInfo.isErr = true; Log4NetHelper.Error(msgInfo.ToJson()); //Log4NetHelper.Error($"scoreJson: {scoreJson}"); Log4NetHelper.Error($"record url: {ExamScore.WaveFileName}"); } finally { if (msgInfo.isErr) { GlobalUser.DoneScore = ScoreType.ScoreFailure; if (!GlobalUser.ErrScoreInfo.ContainsKey(ExamScore.WaveFileName)) { ExamScore.SubmitNum++; GlobalUser.ErrScoreInfo.Add(ExamScore.WaveFileName, ExamScore); } GlobalUser.UpdateErrScore(GlobalUser.USER.Mobile, GlobalUser.SelectPaperNumber, GlobalUser.AttendPaperItemId); Log_Data log = new Log_Data(); log.log_desc = Log_Type.PC_Score.ToString(); log.log_text = msgInfo.ToJson(); log.log_device = JsonHelper.ToJson(GlobalUser.MACHINEINFO.GetDevice()); WebApiProxy.GetHtmlRespInfo(log, ApiType.SysLog, null, "Post"); } } })); }
private void DispatcherTimer_Tick(object sender, EventArgs e) { if (GlobalUser.MainWin == null) { _dispatcherTimer.Stop(); return; } _timeOut = _timeOut - _dispatcherTimer.Interval.Seconds; var allCount = GlobalUser.SelectPaperInfo.paper_detail.Sum(s => s.info.Sum(s1 => s1.items.Where(w => w.answers.Count > 0).Count())); var overCount = GlobalUser.ErrScoreInfo?.Count > 0 ? GlobalUser.ErrScoreInfo.Count : 1; ProgressValue = Convert.ToInt32(100 * (allCount - overCount) / allCount); TxtProgressValue = $"打分中{ProgressValue}%..."; //检查是否有评分(上传结果)异常,每个异常评分 执行超过3(SubmitNum-1)次 if (_timeOut > 0 && GlobalUser.ErrScoreInfo?.Keys.Count > 0 && GlobalUser.DoneScore != ScoreType.Scoring) { foreach (var key in GlobalUser.ErrScoreInfo.Keys) { //var key = GlobalUser.ErrScoreInfo?.Keys.FirstOrDefault(); if (GlobalUser.ErrScoreInfo[key].SubmitNum < 999) { Messenger.Default.Send(GlobalUser.ErrScoreInfo[key], "ExamScoreNavi"); return; } } } //保存 更新 ErrScore结果数据 GlobalUser.UpdateErrScore(User.Mobile, GlobalUser.SelectPaperNumber, GlobalUser.AttendPaperItemId); if (GlobalUser.ErrScoreInfo?.Count > 0 && GlobalUser.DoneScore != ScoreType.Scoring && _timeOut <= 0) { _dispatcherTimer.Stop(); //重评失败 无法操作 //判断有无 SubmitNum==999 无法重评 重新作答 if (GlobalUser.ErrScoreInfo.Values.Any(w => w.SubmitNum == 999)) { //显示重新 作答窗口 var view1 = new ScoreServiceErrDialog(); //view1.DataContext = new ScoreServiceErrDialogVM(); //打开 对话框 //DialogHost.Show(view1, "ExamMainDialog", ExamClosingEventHandler); ErrDialogContent = view1; IsErrDialogOpen = true; return; } //显示 重新评分窗口 var view2 = new ScoreNetErrDialog(); //view2.DataContext = new ScoreNetErrDialogVM(); //打开 对话框 //DialogHost.Show(view2, "ExamMainDialog", ExamClosingEventHandler); ErrDialogContent = view2; IsErrDialogOpen = true; return; } if (GlobalUser.DoneScore == ScoreType.ScoreSuccess) { //确认线上消息 返回完成进度100% --> true if (GetCompleteResult()) { //记录完整 展示 评分和答题窗口 _dispatcherTimer.Stop(); GoToResultView(); return; } else { if (_reCheckResult < 0) { //记录完整 展示 评分和答题窗口 _dispatcherTimer.Stop(); //操作失败 //todo ResubmitAnswerDialog dialog = new ResubmitAnswerDialog(); DialogHost.Show(dialog, "ExamMainDialog");//ResubmitDialogClosingEventHandler ErrMsgLog msgInfo = new ErrMsgLog(); msgInfo.user = GlobalUser.USER.Mobile; msgInfo.msginfo = "等待超时,作答正常完成,未正常返回结果消息"; msgInfo.isErr = true; Log4NetHelper.Error(msgInfo.ToJson());//$"[user:{GlobalUser.USER?.Mobile},msg:作答正常完成,未正常返回结果消息]"); { Log_Data log = new Log_Data(); log.log_desc = Log_Type.PC_Complete_Error.ToString(); log.log_text = msgInfo.ToJson();//$"[user:{GlobalUser.USER?.Mobile},msg:作答正常完成,未正常返回结果消息]";// $"评分异常,未正常返回结果消息"; log.log_device = JsonHelper.ToJson(GlobalUser.MACHINEINFO.GetDevice()); WebApiProxy.GetHtmlRespInfo(log, ApiType.SysLog, null, "Post"); } return; } _reCheckResult--; } } if (GlobalUser.DoneScore == ScoreType.ScoreFailure && (GlobalUser.ErrScoreInfo == null || !GlobalUser.ErrScoreInfo.Any())) { //记录完整 展示 评分和答题窗口 _dispatcherTimer.Stop(); if (GetCompleteResult()) { GoToResultView(); return; } else { //操作失败 //todo ResubmitAnswerDialog dialog = new ResubmitAnswerDialog(); DialogHost.Show(dialog, "ExamMainDialog"); //ResubmitDialogClosingEventHandler return; } } if (_timeOut <= 0) { _dispatcherTimer.Stop(); // 评分失败 if (GlobalUser.DoneScore != ScoreType.ScoreSuccess) { //超时后处理操作 //todo ResubmitAnswerDialog dialog = new ResubmitAnswerDialog(); DialogHost.Show(dialog, "ExamMainDialog");//ResubmitDialogClosingEventHandler return; } } }