/// <summary> /// 解析题目 /// </summary> /// <param name="file">文件路径</param> /// <param name="isCheck">是否检查段落</param> /// <param name="analysis">开启横向解析</param> /// <returns></returns> public Result Fun1(string file, bool isCheck, bool analysis) { return(RunFun(logPath => { string path = allPath + @"" + file + ".docx"; string tigerPath = allTiger + @"" + file + ".txt"; WriteLog(logPath, file + "," + isCheck); string exclude = allPath + "ExcludeList.json"; if (File.Exists(exclude)) { ExcludeList = ToolString.ConvertObject <List <string> >(File.ReadAllText(exclude)); } XWPFDocument document = ToolFile.ReadWord(path); StringBuilder builder = new StringBuilder(); string subject = ""; List <string> answerList = new List <string>(); List <string> itemList = new List <string>(); string[] typeArr = new string[] { "单项选择", "多项选择", "判断" }; int index = -1, nextIndex = -1; // 题目类型 int itemIndex = 0; // 答案索引 int subjectIndex = 1; // 题目索引 if (analysis) { fun1Str5 = @"[ ((]*[A-H]{1}[ .、.))::]+"; } foreach (XWPFParagraph para in document.Paragraphs) { string paragraphs = para.ParagraphText.Trim();//.Replace(" ", ""); for (int i = 0; i < typeArr.Length; i++) { if (ToolRegular.Contains(paragraphs, ".*" + typeArr[i] + @"题[((][\d]*.*[))]")) { nextIndex = i; subjectIndex = 1; if (index == -1) { index = i; } } } List <string> list = paragraphs.Split('\n').ToList(); foreach (var line in list) { // 判断是否是题目开头 Regex reg = new Regex(fun1Str1); if (IsSubject(para, isCheck) || (reg.IsMatch(line) && !isCheck)) { // 输出上一题 if (!string.IsNullOrWhiteSpace(subject)) { subject = ReplaceSubject(subject, "、", isCheck); if (!string.IsNullOrWhiteSpace(subject)) { answerList = AnswerList(subject); subject = answerList[0]; answerList.Remove(subject); if (index == -1) { index = 0; nextIndex = 0; } subject += "[" + typeArr[index] + "题]\n"; AnswerList(answerList, itemList, typeArr[index]); foreach (var item in itemList) { subject += item + "\n"; } builder.AppendLine(subject); index = nextIndex; WriteLog(allTiger + @"" + file + ".log", "[" + typeArr[index] + "题]\t" + ToolString.AddStrByLength(subjectIndex + "", " ", 3) + "\t" + ToolString.AddStrByLength(string.Join(",", answerList), " ", 10) + "\t[" + string.Join(",", itemList.Select(c => c[0])) + "]", true); subjectIndex++; } } // 开始下一题 itemList = new List <string>(); answerList = new List <string>(); subject = line; itemIndex = 0; } else { if (string.IsNullOrWhiteSpace(subject)) { continue; } // 判断是否是选项开头 else if (IsItem(para, isCheck) || new Regex(fun1Str3).IsMatch(line)) { itemList.AddRange(ItemList(line, para, isCheck, itemIndex++, analysis)); continue; } // 判断是否是换行题目 else if (itemList.Count <= 0 && !string.IsNullOrWhiteSpace(line) && (!isCheck || para.GetNumFmt() != "lowerRoman")) { subject += Br + line; } } } } // 输出最后一题 if (!string.IsNullOrWhiteSpace(subject)) { subject = ReplaceSubject(subject, "、", isCheck); if (!string.IsNullOrWhiteSpace(subject)) { answerList = AnswerList(subject); subject = answerList[0]; answerList.Remove(subject); subject += "[" + typeArr[index] + "题]\n"; AnswerList(answerList, itemList, typeArr[index]); foreach (var item in itemList) { subject += item + "\n"; } builder.AppendLine(subject); index = nextIndex; WriteLog(allTiger + @"" + file + ".log", "[" + typeArr[index] + "题]\t" + ToolString.AddStrByLength(subjectIndex + "", " ", 3) + "\t" + ToolString.AddStrByLength(string.Join(",", answerList), " ", 10) + "\t[" + string.Join(",", itemList.Select(c => c[0])) + "]", true); } } ToolFile.CreatFile(tigerPath, builder.ToString(), false); return Res; })); }
/// <summary> /// 返回所有请求成功的数据 /// </summary> /// <param name="date">几天之内</param> /// <returns></returns> private Result GetAllPost(int date) { return(RunFun((logpath, dataPath) => { string allSend = "AllSend.log"; string notSend = "NotSend.json"; List <GeelyField> notSendList; List <string> isSendList; // 读取数据库 if (!File.Exists(dataPath + notSend)) { string sqlDeclares = GetSqlParam($"Declare @Date int = {date}"); notSendList = GeelyField.GetAllPost(sqlDeclares, DbContent); // 初始化,将数据库中已经发送过请求的数据 notSendList = GeelyField.GetSendList(notSendList, c => true); // 放入待重新请求文件 ToolFile.CreatFile(dataPath + notSend, ToolString.ConvertJson(notSendList), false); } // 读取文件 else { notSendList = ToolString.ConvertObject <List <GeelyField> >(File.ReadAllText(dataPath + notSend)); } // 过滤已发送的数据 if (File.Exists(dataPath + allSend)) { // 所有获取所有已发送列表 isSendList = File.ReadAllLines(dataPath + allSend).ToList(); foreach (var item in isSendList) { GeelyField geely = notSendList.FirstOrDefault(c => c.cand == item); if (geely != null) { notSendList.Remove(geely); } } } // 已处理过的数据日志,用于更新 Res.Msg = dataPath + allSend; // 待处理的数据集 Res.Object = notSendList; //foreach (var item in notSendList) //{ // string url = "http://local.askform.cn/Custom/CampusRecruitment.aspx"; // url += "?name=" + item.firstName + "&cand=" + item.cand + "&instr=" + item.instr + "&pid=" + item.pid + "&valid=" + item.valid + "&keyword=" + item.EntryID; // string log = item.cand; // try // { // log += "\t发起请求"; // string res = ToolHttp.RequestUrl(url); // log += "\t请求成功"; // ToolFile.CreatFile(dataPath + allSend, item.cand, true); // } // catch (Exception ex) // { // log += "\t请求失败:" + ex.Message; // } // WriteLog(logpath, log); //} return Res; })); }