/// <summary> /// 统一请求方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url"></param> /// <param name="postData"></param> /// <param name="methodType"></param> /// <returns></returns> public T Crawling <T>(string url, string postData = "", string methodType = "GET") { var next = true; var count = 0; do { httpItem.URL = url; httpItem.ContentType = "application/x-www-form-urlencoded"; httpItem.ResultType = ResultType.String; httpItem.PostEncoding = Encoding.UTF8; httpItem.Cookie = cookie; httpItem.Method = methodType; httpItem.Postdata = postData; httpResult = httpHelper.GetHtml(httpItem); if (httpResult.RedirectUrl.Contains("erp/login.do")) { next = false; Login(); } count++; } while (!next && count < maxCount); var result = JSONHelper.Decode <T>(httpResult.Html); return(result); }
private WorkAnswerContract listenPaperCorrect(WorkAnswerContract workAnswer, long doId, long versionId, int sid, int assess, decimal itemScore) { if (null == workAnswer) { var questionAnswers = new List <ListenAnswerEntity>() { new ListenAnswerEntity() { Sid = sid, AudioUrl = string.Empty, BlankContent = string.Empty } }; workAnswer = new WorkAnswerContract() { DoId = doId, VersionId = versionId, AnswerType = 1, ResourceType = ResourceModuleOptions.Question.ToString(), Assess = assess, Score = itemScore, AnswerContent = JSONHelper.Encode <List <ListenAnswerEntity> >(questionAnswers) }; } else { var questionAnswers = JSONHelper.Decode <List <ListenAnswerEntity> >(workAnswer.AnswerContent); if (null == questionAnswers || !questionAnswers.Any()) { questionAnswers.Add(new ListenAnswerEntity() { Sid = sid, AudioUrl = string.Empty, BlankContent = string.Empty }); workAnswer.AnswerContent = JSONHelper.Encode <List <ListenAnswerEntity> >(questionAnswers); } workAnswer.Assess = assess; workAnswer.Score = itemScore; } return(workAnswer); }
/// <summary> /// 订单页面内容解析 /// </summary> /// <param name="html"></param> public List <OrderDetail> LoadOrderDetail(string html) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNode sheetDateNode = doc.GetElementbyId("sheetDate"); //text日期 var sheetDate = sheetDateNode.Attributes["value"].Value; HtmlNode oldSheetNoNode = doc.GetElementbyId("oldSheetNo"); //text单号 var oldSheetNo = oldSheetNoNode.Attributes["value"].Value; HtmlNode remarksNode = doc.GetElementbyId("remarks"); //text备注 var remarks = remarksNode.Attributes["value"].Value; HtmlNode cusIdNode = doc.GetElementbyId("cusId"); //姓名 var cusId = cusIdNode.Attributes["value"].Value; HtmlNode cusNameNode = doc.GetElementbyId("cusName"); // var cusName = cusNameNode.Attributes["value"].Value; HtmlNode mobileNode = doc.GetElementbyId("mobile"); //电话 var mobile = mobileNode.Attributes["value"].Value; HtmlNode vipCardNoNode = doc.GetElementbyId("vipCardNo"); //卡号 var vipCardNo = vipCardNoNode.Attributes["value"].Value; HtmlNode vipCardLevelNode = doc.GetElementbyId("vipCardLevel"); //会员级别 var vipCardLevel = vipCardLevelNode.Attributes["value"].Value; HtmlNode canUsePointNode = doc.GetElementbyId("canUsePoint"); //可用积分 var canUsePoint = canUsePointNode.Attributes["value"].Value; HtmlNode joinPointNode = doc.GetElementbyId("joinPoint"); //checkbox本单参与积分 var joinPoint = joinPointNode.Attributes["value"].Value; HtmlNode ponitNode = doc.GetElementbyId("ponit"); //本次积分 var ponit = ponitNode.Attributes["value"].Value; HtmlNode sheetTotalMoneyNode = doc.GetElementbyId("sheetTotalMoney"); //本单金额 var sheetTotalMoney = sheetTotalMoneyNode.Attributes["value"].Value; Regex reg = new Regex(@"var saleDataItemJson=(.+?);"); var result = reg.Match(html).Groups; if (result.Count > 0) { var json = result[0].ToString().Replace("var saleDataItemJson=", ""); json = json.Substring(0, json.Length - 1); return(JSONHelper.Decode <List <OrderDetail> >(json)); } return(null); }
public JsonResult Correct() { var answerContent = Request.Form["content"]; List <WorkAnswerContract <QuestionAnswer> > userAnswer = null; try { userAnswer = JSONHelper.Decode <List <WorkAnswerContract <QuestionAnswer> > >(answerContent); } catch (Exception e) { return(Json(new ReturnResult("数据格式错误,exception:" + e.ToString()))); } var totalScore = 0m; var wikiQues = new List <Ques.Core.Models.Question>(); var result = correctService.WikiQuesCorrect(userAnswer, ref totalScore, ref wikiQues); return(Json(new ReturnResult <List <WorkAnswerContract> >(result))); }
private WorkAnswerContract paperCorrect(WorkAnswerContract workAnswer, long doId, long versionId, int sid, int assess, decimal itemScore) { if (null == workAnswer) { var questionAnswers = new List <QuestionAnswer>() { new QuestionAnswer() { Sid = sid, Assess = assess, ItemScore = itemScore, Content = string.Empty } }; workAnswer = new WorkAnswerContract() { DoId = doId, VersionId = versionId, AnswerType = 1, ResourceType = ResourceModuleOptions.Question.ToString(), Assess = assess, Score = itemScore, AnswerContent = JSONHelper.Encode <List <QuestionAnswer> >(questionAnswers) }; } else { var questionAnswers = JSONHelper.Decode <List <QuestionAnswer> >(workAnswer.AnswerContent); var currAnswer = questionAnswers.FirstOrDefault(t => t.Sid == sid); if (null == currAnswer) { questionAnswers.Add(new QuestionAnswer() { Sid = sid, Assess = assess, ItemScore = itemScore, Content = string.Empty }); } else { currAnswer.Assess = assess; currAnswer.ItemScore = itemScore; } if (questionAnswers.Count == 1) { workAnswer.Assess = questionAnswers[0].Assess; } else if (!questionAnswers.Any(t => t.Assess != 1)) { workAnswer.Assess = 1; } else if (questionAnswers.Any(t => t.Assess == 2)) { workAnswer.Assess = 2; } else if (!questionAnswers.Any(t => t.Assess != 3)) { workAnswer.Assess = 3; } else if (questionAnswers.Any(t => t.Assess == 4)) { workAnswer.Assess = 4; } workAnswer.Score = questionAnswers.Sum(t => t.ItemScore); workAnswer.AnswerContent = JSONHelper.Encode <List <QuestionAnswer> >(questionAnswers); } return(workAnswer); }
public T Deserialize <T>(IRestResponse response) { return(JSONHelper.Decode <T>(response.Content)); }
public virtual JsonResult SubmitWork(WorkParam baseParam, long doWorkId, long contentId) { if (baseParam.workStatus == 2 || baseParam.workStatus == 3) { //跟读作业通过接口调用,其他作业只允许提交一次 return(Json(new ReturnResult(101, "无法重复提交已完成的作业"))); } if (baseParam.DoWorkBase.WorkBaseStatus != 0) { return(Json(new ReturnResult(102, "这份作业已经被老师取消布置啦,再去作业系统看看有没有重新布置哦!"))); } var unitWorks = baseParam.UnitWork ?? new UnitWorksContract(); //第一次提交,baseParam.UnitWork是为null. var actualScore = 0m; var content = Request.Form["content"]; var answerList = new List <WorkAnswerContract>(); if (!string.IsNullOrWhiteSpace(content)) //目前只做试题批改,后期有新的类型再修改 { var questionCount = Convert.ToInt32(Request.Form["questionCount"]); var userAnswer = JSONHelper.Decode <List <WorkAnswerContract <QuestionAnswer> > >(content); var correctService = DependencyResolver.Current.GetService <CorrectService>(); var wikiQues = new List <Ques.Core.Models.Question>(); answerList = correctService.WikiQuesCorrect(userAnswer, ref actualScore, ref wikiQues); answerList.ForEach(t => t.ResourceType = ResourceModuleOptions.Question.ToString()); unitWorks.CorrectRate = questionCount > 0 ? answerList.Count(t => t.Assess == 1) * 1.0m / questionCount : 0; } if (!string.IsNullOrWhiteSpace(Request.Form["workScore"])) { unitWorks.WorkScore = Convert.ToDecimal(Request.Form["workScore"]); } unitWorks.ContentId = contentId; unitWorks.RecordId = baseParam.WorkResource.RecordId; unitWorks.WorkId = baseParam.DoWorkBase.WorkID; unitWorks.DoWorkId = doWorkId; unitWorks.SubmitUserId = baseParam.User.UserID; unitWorks.SubmitUserName = baseParam.User.UserName; unitWorks.ActualScore = actualScore; unitWorks.SubmitDate = DateTime.Now; unitWorks.IsTimeOut = unitWorks.SubmitDate > baseParam.DoWorkBase.EffectiveDate; unitWorks.SubmitCount = unitWorks.SubmitCount + 1; unitWorks.Status = 3; unitWorks.WorkLong = Convert.ToInt32(Request["workLong"]); unitWorks.WorkLong = unitWorks.WorkLong < 1 ? 1 : unitWorks.WorkLong; var doId = workService.DoUnitWorks(unitWorks, answerList, baseParam.DoWorkBase.TotalNum); #region 发送消息 if (doId > 0 && actualScore >= 70) { var msg = new CApi.Client.XiXinClient(); var workname = "我于" + unitWorks.SubmitDate.ToString("MM月dd日 HH:mm") + "提交了“" + baseParam.WorkResource.ResourceName + "”,得分" + actualScore + ","; if (actualScore >= 70 && actualScore < 80) { workname += "成绩中等。"; } else if (actualScore >= 80 && actualScore < 90) { workname += "成绩良好。"; } else if (actualScore >= 90) { workname += "成绩优秀。"; } //异步发送习信与书房消息 System.Threading.Tasks.Task.Factory.StartNew(() => msg.SendToFamily(baseParam.User.UserID, workname)); System.Threading.Tasks.Task.Factory.StartNew(() => SendMessage(baseParam.User, "作业消息", workname)); } #endregion return(Json(doId == 0 ? new ReturnResult("作业提交失败,请稍后再试") : new ReturnResult <long>(doId))); }