Commit 3fcff474 authored by 黄奎's avatar 黄奎

新增模板导入功能

parent 7f3b834c
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
namespace Edu.Common.Data
{
......@@ -116,14 +117,62 @@ namespace Edu.Common.Data
var questionList = Common.Plugin.WordHelper.GetWordData(filePath);
if (questionList != null && questionList.Count > 0)
{
foreach (var item in questionList)
foreach (var rootItem in questionList)
{
ImportModel model = new ImportModel();
if (rootItem.QuestionList != null && rootItem.QuestionList.Count > 0)
{
if (rootItem.BigTitle == "阅读理解")
{
foreach (var item in rootItem.QuestionList)
{
if(!string.IsNullOrEmpty(item))
{
string readStr = item.Replace("阅读理解", "").Trim();
if (!string.IsNullOrEmpty(readStr))
{
ImportModel model = new ImportModel
{
Category = rootItem.BigTitle,
SubQuestionList = new List<ImportModel>(),
QuestionTypeName= "阅读理解"
};
AnalysisReadingQuestion(item, model);
list.Add(model);
}
}
}
}
else
{
foreach (var item in rootItem.QuestionList)
{
ImportModel model = new ImportModel()
{
Category = rootItem.BigTitle
};
if (!string.IsNullOrEmpty(item))
{
AnalysisQuestionTitle(item, model);
list.Add(model);
}
}
}
}
}
}
return list;
}
/// <summary>
/// 解析问题题干
/// </summary>
/// <param name="item"></param>
/// <param name="model"></param>
private static void AnalysisQuestionTitle(string item, ImportModel model)
{
string pattern = @"\r\n";
var tempArray = Regex.Split(item, pattern);
var answerObj = "";//答案
string answerObj = "";//答案
if (tempArray != null && tempArray.Length > 0)
{
model.QuestionTitle = tempArray[0].Trim();
......@@ -131,9 +180,21 @@ namespace Edu.Common.Data
{
if (!string.IsNullOrEmpty(subItem))
{
if (subItem.Contains("答案解析:"))
if (subItem.Contains("答案解析:") || subItem.Contains("解析:"))
{
string answerReg1 = @"答案解析:";
string answerReg2 = @"解析:";
Regex reg = new Regex(answerReg1);
Regex reg2 = new Regex(answerReg2);
string[] answerAnalysisArray = null;
if (reg2.IsMatch(subItem))
{
var answerAnalysisArray = Regex.Split(subItem, "答案解析:");
answerAnalysisArray = Regex.Split(subItem, answerReg2);
}
if (reg.IsMatch(subItem))
{
answerAnalysisArray = Regex.Split(subItem, answerReg1);
}
if (answerAnalysisArray != null && answerAnalysisArray.Length > 0)
{
model.AnswerAnalysis = answerAnalysisArray.Length > 1 ? answerAnalysisArray[1] : "";
......@@ -148,9 +209,21 @@ namespace Edu.Common.Data
model.QuestionAnswer = answerArray.Length > 1 ? answerArray[1] : "";
}
}
if (subItem.Contains("难易程度:"))
if (subItem.Contains("难易程度:") || subItem.Contains("难易度:"))
{
var easyTypeArray = Regex.Split(subItem, "难易程度:");
string easyReg1 = @"难易程度:";
string easyReg2 = @"难易度:";
Regex reg = new Regex(easyReg1);
Regex reg2 = new Regex(easyReg2);
string[] easyTypeArray = null;
if (reg.IsMatch(subItem))
{
easyTypeArray = Regex.Split(subItem, easyReg1);
}
if (reg2.IsMatch(subItem))
{
easyTypeArray = Regex.Split(subItem, easyReg2);
}
if (easyTypeArray != null && easyTypeArray.Length > 0)
{
model.EasyType = easyTypeArray.Length > 1 ? easyTypeArray[1] : "易";
......@@ -161,23 +234,18 @@ namespace Edu.Common.Data
}
if (!string.IsNullOrEmpty(answerObj))
{
AnalysisQuestion(answerObj, tempArray, model);
list.Add(model);
}
}
AnalysisQuestionContent(answerObj, tempArray, model);
}
}
return list;
}
/// <summary>
/// 解析Word
/// 解析问题内容【判断题、选择题、填空题,简答题】
/// </summary>
/// <param name="answerObj"></param>
/// <param name="tempArray"></param>
/// <param name="model"></param>
/// <returns></returns>
private static void AnalysisQuestion(string answerObj, string[] tempArray, ImportModel model)
private static void AnalysisQuestionContent(string answerObj, string[] tempArray, ImportModel model)
{
//判断题
if (answerObj.Contains("答案:对") || answerObj.Contains("答案:错"))
......@@ -193,21 +261,24 @@ namespace Edu.Common.Data
if (model.QuestionAnswer.Length == 1)
{
model.QuestionTypeName = "单选题";
model.ChooseOptionCount = "1";
}
if (model.QuestionAnswer.Length > 1)
{
model.QuestionTypeName = "多选题";
model.ChooseOptionCount = model.QuestionAnswer.Trim().Length.ToString();
}
int index = 0;
int chooseCount = 0;
foreach (var item in tempArray)
{
string pattern = @"[ABCDEFGHI]";
string pattern = @"[ABCDEFGHI][.、]";
var tempArray2 = Regex.Split(item, pattern);
if (tempArray2 != null && tempArray2.Length == 2)
{
var tempStr = tempArray2[1].Replace(". ", "").Replace("、", "").Trim();
if (!string.IsNullOrEmpty(tempStr))
{
chooseCount++;
}
if (index == 0)
{
model.OptionA = tempStr;
......@@ -240,10 +311,14 @@ namespace Edu.Common.Data
{
model.OptionH = tempStr;
}
if (!string.IsNullOrEmpty(tempStr))
{
index++;
}
}
}
model.ChooseOptionCount = chooseCount.ToString();
}
//填空题
else if (model.QuestionTitle.Contains("_"))
{
......@@ -303,6 +378,47 @@ namespace Edu.Common.Data
model.ChooseOptionCount = "1";
}
}
/// <summary>
/// 解析Word中阅读理解
/// </summary>
/// <param name="questionStr"></param>
/// <param name="model"></param>
private static void AnalysisReadingQuestion(string questionStr, ImportModel model)
{
string[] tempArray = null;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
string pattern1 = @"\r\n[1234567890]*[、.]";
Regex reg1 = new Regex(pattern1);
tempArray = Regex.Split(questionStr, pattern1);
if (tempArray != null && tempArray.Length > 0)
{
model.QuestionTitle = tempArray[0];
int index = 0;
foreach (var item in tempArray)
{
if (index > 0)
{
ImportModel subQuestion = new ImportModel();
AnalysisQuestionTitle(item, subQuestion);
model.SubQuestionList.Add(subQuestion);
model.AnswerAnalysis += (index) + "、" + subQuestion.AnswerAnalysis;
}
index++;
}
if (model.SubQuestionList != null && model.SubQuestionList.Count > 0)
{
if (model.SubQuestionList.Where(qitem => qitem.EasyType == "中").Count() > 0)
{
model.EasyType = "中";
}
else if (model.SubQuestionList.Where(qitem => qitem.EasyType == "难").Count() > 0)
{
model.EasyType = "难";
}
}
}
}
}
/// <summary>
......@@ -384,5 +500,15 @@ namespace Edu.Common.Data
/// H
/// </summary>
public string OptionH { get; set; }
/// <summary>
/// 大分类分类名称
/// </summary>
public string Category { get; set; }
/// <summary>
/// 子项题目列表
/// </summary>
public List<ImportModel> SubQuestionList { get; set; }
}
}
......@@ -5,13 +5,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FreeSpire.Doc" Version="7.11.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NPOI" Version="2.5.1" />
<PackageReference Include="Spire.Doc" Version="8.12.14" />
</ItemGroup>
</Project>
using Edu.Common.Plugin;
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Common.Enum.Course
{
/// <summary>
/// 问题大类型
/// </summary>
public enum QuestionCategoryEnum
{
/// <summary>
/// 默认
/// </summary>
[EnumField("默认")]
Default = 0,
/// <summary>
/// 日语选择题
/// </summary>
[EnumField("日语选择题")]
JapaneseChoose = 1,
/// <summary>
/// 中文选择题
/// </summary>
[EnumField("中文选择题")]
ChineseChoose = 2,
/// <summary>
/// 阅读理解
/// </summary>
[EnumField("阅读理解")]
ReadingComprehensio = 3,
}
}
\ No newline at end of file
......@@ -231,5 +231,65 @@ namespace Edu.Common
return Convert.ToBase64String(imageBytes);
}
}
/// <summary>
/// 字符串转数字
/// </summary>
/// <param name="inputStr"></param>
/// <returns></returns>
public static int ConvertStringToNumber(string inputStr)
{
int result = 0;
var chatArray = inputStr.ToCharArray();
foreach (var cItem in chatArray)
{
switch (cItem)
{
case '一':
result += 1;
break;
case '二':
result += 2;
break;
case '三':
result += 3;
break;
case '四':
result += 4;
break;
case '五':
result += 5;
break;
case '六':
result += 6;
break;
case '七':
result += 7;
break;
case '八':
result += 8;
break;
case '九':
result += 9;
break;
case '十':
result += 10;
break;
}
}
return result;
}
/// <summary>
/// 拼接图片字符串
/// </summary>
/// <param name="base64"></param>
/// <returns></returns>
public static string GetImageString(string base64)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"<img src='data:image/png;base64,{0}' />", base64);
return builder.ToString();
}
}
}
\ No newline at end of file
......@@ -2,10 +2,10 @@
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace Edu.Common.Plugin
......@@ -20,12 +20,18 @@ namespace Edu.Common.Plugin
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static List<string> GetWordData(string filePath)
public static List<QuestionWordData> GetWordData(string filePath)
{
List<string> list = new List<string>();
List<QuestionWordData> list = new List<QuestionWordData>();
Spire.Doc.Document document = new Spire.Doc.Document();
document.LoadFromFile(filePath);
document.SaveToFile("toDoc.html", FileFormat.Html);
string basepath = AppContext.BaseDirectory;
string tempPath = basepath + "\\upfile\\temporary\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";
List<string> imageList = new List<string>();
if (!Directory.Exists(tempPath))
{
Directory.CreateDirectory(tempPath);
}
foreach (Section section in document.Sections)
{
foreach (Paragraph paragraph in section.Paragraphs)
......@@ -36,22 +42,130 @@ namespace Edu.Common.Plugin
var pic = docObject as DocPicture;
if (pic != null)
{
string imageName = string.Format(@"Image-{0}.png", DateTime.Now.Ticks);
string imageName = string.Format(@"WordImage_{0}.png", DateTime.Now.Ticks);
using (MemoryStream ms = new MemoryStream(pic.ImageBytes))
{
Image outputImg = Image.FromStream(ms);
outputImg.Save(@"D:\" + imageName, System.Drawing.Imaging.ImageFormat.Png);
string tempImagePath = tempPath + imageName;
imageList.Add(tempImagePath);
outputImg.Save(tempImagePath, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
}
}
string str = document.GetText();
str = str.Replace("Evaluation Warning: The document was created with Spire.Doc for .NET.", "");
//“\r\n”开始+“1234567890”出现1次到多次+“、”结尾
string pattern = @"\r\n[1234567890]*、";
var tempArray = Regex.Split(str, pattern);
//解析大类
string categoryRule1 = @"[第][一二三四五六七八九十][部][分]";
Regex categoryReg = new Regex(categoryRule1);
string[] tempArray = null;
if (categoryReg.IsMatch(str))
{
tempArray = Regex.Split(str, categoryRule1);
if (tempArray != null && tempArray.Length > 0)
{
foreach (var item in tempArray)
{
if (!string.IsNullOrEmpty(item))
{
list.Add(AnalysisQuestionCategory(item, imageList, isBigType: true));
}
}
}
}
else
{
list.Add(AnalysisQuestionCategory(str, imageList));
}
return list;
}
/// <summary>
/// 解析问题大类下面的问题列表
/// </summary>
/// <param name="questionStr"></param>
/// <param name="isBigType">是否是大类</param>
/// <returns></returns>
private static QuestionWordData AnalysisQuestionCategory(string questionStr, List<string> imageList, bool isBigType = false)
{
QuestionWordData questionWordData = new QuestionWordData();
// \r\n【图一】\r\n
string imgPattern = @"\r\n[【][图][一二三四五六七八九十]*[】]";
Regex imgReg = new Regex(imgPattern);
//有图片
if (imgReg.IsMatch(questionStr))
{
var matchs = Regex.Matches(questionStr, imgPattern);
if (matchs != null && matchs.Count > 0)
{
foreach (var item in matchs)
{
var numStr = item.ToString().Replace("【", "").Replace("】", "").Replace("图", "").Trim();
var newNumber= ConvertHelper.ConvertStringToNumber(numStr);
if (newNumber > 0)
{
string filePath = imageList != null && imageList.Count >= newNumber ? imageList[newNumber - 1] : "";
if (!string.IsNullOrEmpty(filePath))
{
string imageBase64 = ConvertHelper.ConvertImageToBase64(filePath);
if (!string.IsNullOrEmpty(imageBase64))
{
questionStr = questionStr.Replace(item.ToString(), ConvertHelper.GetImageString(imageBase64));
}
}
}
}
}
}
string[] tempArray = null;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
string pattern1 = @"\r\n[1234567890]*[、.]";
Regex reg1 = new Regex(pattern1);
if (isBigType)
{
string pattern2 = @"\r\n[(][一二三四五六七八九十]*[)]";
Regex reg2 = new Regex(pattern2);
if (reg2.IsMatch(questionStr))
{
tempArray = Regex.Split(questionStr, pattern2);
}
else if (reg1.IsMatch(questionStr))
{
tempArray = Regex.Split(questionStr, pattern1);
}
if (tempArray != null && tempArray.Length > 0)
{
string str = tempArray[0].Trim().Replace("、", "").Replace(".", "");
questionWordData.BigTitle = str;
ArrayList al = new ArrayList(tempArray);
al.RemoveAt(0);
var newQuestionArray = (string[])al.ToArray(typeof(string));
questionWordData.QuestionList = AnalysisQuestionList(newQuestionArray);
}
}
else
{
if (reg1.IsMatch(questionStr))
{
tempArray = Regex.Split(questionStr, pattern1);
}
questionWordData.BigTitle = "默认";
questionWordData.QuestionList = AnalysisQuestionList(tempArray);
}
return questionWordData;
}
/// <summary>
/// 解析问题列表
/// </summary>
/// <param name="tempArray"></param>
/// <returns></returns>
private static List<string> AnalysisQuestionList(string[] tempArray)
{
List<string> list = new List<string>();
if (tempArray != null && tempArray.Length > 0)
{
foreach (var item in tempArray)
......@@ -65,4 +179,20 @@ namespace Edu.Common.Plugin
return list;
}
}
/// <summary>
/// 问题数据
/// </summary>
public class QuestionWordData
{
/// <summary>
/// 大类名称
/// </summary>
public string BigTitle { get; set; }
/// <summary>
/// 问题列表
/// </summary>
public List<string> QuestionList { get; set; }
}
}
......@@ -8,18 +8,39 @@
".NETCoreApp,Version=v3.0": {
"Edu.Common/1.0.0": {
"dependencies": {
"FreeSpire.Doc": "7.11.0",
"Microsoft.AspNetCore.Http": "2.2.2",
"Microsoft.AspNetCore.Mvc.Formatters.Json": "2.2.0",
"Microsoft.Extensions.Configuration": "3.1.8",
"Microsoft.Extensions.Configuration.Json": "3.1.8",
"NPOI": "2.5.1",
"Newtonsoft.Json": "12.0.3",
"Spire.Doc": "8.12.14"
"Newtonsoft.Json": "12.0.3"
},
"runtime": {
"Edu.Common.dll": {}
}
},
"FreeSpire.Doc/7.11.0": {
"dependencies": {
"SkiaSharp": "1.68.0",
"System.Security.Cryptography.Xml": "4.5.0",
"System.Text.Encoding.CodePages": "4.5.0"
},
"runtime": {
"lib/netcoreapp2.0/Spire.Doc.dll": {
"assemblyVersion": "7.11.0.41420",
"fileVersion": "7.11.0.41420"
},
"lib/netcoreapp2.0/Spire.License.dll": {
"assemblyVersion": "1.3.7.320",
"fileVersion": "1.3.7.320"
},
"lib/netcoreapp2.0/Spire.Pdf.dll": {
"assemblyVersion": "5.11.0.2420",
"fileVersion": "5.11.0.2420"
}
}
},
"Microsoft.AspNetCore.Authentication.Abstractions/2.2.0": {
"dependencies": {
"Microsoft.AspNetCore.Http.Abstractions": "2.2.0",
......@@ -568,27 +589,6 @@
}
}
},
"Spire.Doc/8.12.14": {
"dependencies": {
"SkiaSharp": "1.68.0",
"System.Security.Cryptography.Xml": "4.5.0",
"System.Text.Encoding.CodePages": "4.5.0"
},
"runtime": {
"lib/netstandard2.0/Spire.Doc.dll": {
"assemblyVersion": "8.12.14.0",
"fileVersion": "8.12.14.4420"
},
"lib/netstandard2.0/Spire.License.dll": {
"assemblyVersion": "1.3.8.320",
"fileVersion": "1.3.8.320"
},
"lib/netstandard2.0/Spire.Pdf.dll": {
"assemblyVersion": "6.12.20.0",
"fileVersion": "6.12.20.2420"
}
}
},
"System.AppContext/4.1.0": {
"dependencies": {
"System.Runtime": "4.1.0"
......@@ -978,6 +978,13 @@
"serviceable": false,
"sha512": ""
},
"FreeSpire.Doc/7.11.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Rg7axyvwCU8PPuhsetIM4FZuuOL6PROJOXlhJo760wDS/4JJdo99JVDjqpGHej78yLYMSvtSuq0jjuTIYNEZgw==",
"path": "freespire.doc/7.11.0",
"hashPath": "freespire.doc.7.11.0.nupkg.sha512"
},
"Microsoft.AspNetCore.Authentication.Abstractions/2.2.0": {
"type": "package",
"serviceable": true,
......@@ -1293,13 +1300,6 @@
"path": "skiasharp/1.68.0",
"hashPath": "skiasharp.1.68.0.nupkg.sha512"
},
"Spire.Doc/8.12.14": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ZHJVAjEcPNvUbEIe+46zXlYG7J7T1Pua7jpsuH3yMllqD1xysMdVhR9hAywkGYnaHodv0gjIP33SiD4Kgh7ykQ==",
"path": "spire.doc/8.12.14",
"hashPath": "spire.doc.8.12.14.nupkg.sha512"
},
"System.AppContext/4.1.0": {
"type": "package",
"serviceable": true,
......
using Edu.Common.Enum;
using Edu.Common.Enum.Course;
using Edu.Common.Enum.Question;
using System;
using VT.FW.DB;
......@@ -101,5 +102,10 @@ namespace Edu.Model.Entity.Question
/// 填空题(答案顺序打乱也判正确)
/// </summary>
public int IsMutex { get; set; }
/// <summary>
/// 题目所属大类
/// </summary>
public QuestionCategoryEnum? Category { get; set; }
}
}
......@@ -91,6 +91,7 @@ namespace Edu.Module.Question
{nameof(RB_Question_ViewModel.UpdateTime),model.UpdateTime },
{nameof(RB_Question_ViewModel.Answer),model.Answer },
{nameof(RB_Question_ViewModel.IsMutex),model.IsMutex },
{nameof(RB_Question_ViewModel.Category),model.Category },
};
flag = questionRepository.Update(fileds, new WhereHelper(nameof(RB_Question_ViewModel.QuestionId), model.QuestionId));
}
......
......@@ -6,9 +6,15 @@ namespace Edu.Test
{
static void Main(string[] args)
{
//string filePath = @"C:/Users/qiaoyajun/Desktop/Word模板.docx";
//var data = Common.Data.QuestionHelper.GetWordQuestionData(filePath);
//Console.WriteLine(Common.Plugin.JsonHelper.Serialize(data));
string filePath = "";
filePath = @"C:/Users/qiaoyajun/Desktop/模板二.docx";
filePath = @"C:/Users/qiaoyajun/Desktop/EduWordTemplate.doc";
var data = Common.Data.QuestionHelper.GetWordQuestionData(filePath);
Console.WriteLine(Common.Plugin.JsonHelper.Serialize(data));
if (data != null && data.Count > 0)
{
Console.WriteLine("总共:" + data.Count);
}
}
}
}
......@@ -379,17 +379,21 @@ namespace Edu.WebApi.Controllers.Course
switch (item.QuestionTypeName)
{
case "单选题":
AnalysisSingle(ChooseOptionCount, item, model, questionTypeList);
break;
case "多选题":
AnalysisMultiple(ChooseOptionCount, item, model, questionTypeList);
break;
if(ChooseOptionCount>0)
case "填空题":
if (ChooseOptionCount > 0)
{
List<optionItem> singleList = new List<optionItem>();
List<fillInItem> fillInList = new List<fillInItem>();
for (var i = 0; i < ChooseOptionCount; i++)
{
var singleModel = new optionItem()
var singleModel = new fillInItem()
{
Name = Common.ConvertHelper.GetEnChar(i),
Content = "",
IsAnswer=item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
};
if (i == 0)
{
......@@ -419,38 +423,33 @@ namespace Edu.WebApi.Controllers.Course
{
singleModel.Content = item.OptionG;
}
if (i ==7)
if (i == 7)
{
singleModel.Content = item.OptionH;
}
if (singleModel.IsAnswer)
{
model.Answer = singleModel.Name;
}
singleList.Add(singleModel);
fillInList.Add(singleModel);
}
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(singleList);
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
}
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "single")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "fill-in")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "多选题":
case "判断题":
if (ChooseOptionCount > 0)
{
List<optionItem> multipleList = new List<optionItem>();
string answer = "";
List<optionItem> judgeList = new List<optionItem>();
for (var i = 0; i < ChooseOptionCount; i++)
{
var singleModel = new optionItem()
{
Name = Common.ConvertHelper.GetEnChar(i),
Content = "",
IsAnswer = item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
IsAnswer= item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
};
if (i == 0)
{
......@@ -486,26 +485,50 @@ namespace Edu.WebApi.Controllers.Course
}
if (singleModel.IsAnswer)
{
answer+=","+ singleModel.Name;
model.Answer = singleModel.Name;
}
multipleList.Add(singleModel);
judgeList.Add(singleModel);
}
if (!string.IsNullOrEmpty(answer))
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(judgeList);
}
if (model.QuestionTypeId == 0)
{
answer = answer.Substring(1);
var tempModel = questionTypeList.Where(qitem => qitem.Key == "judge")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
model.Answer = answer;
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(multipleList);
break;
case "简答题":
model.Answer = item.QuestionAnswer;
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "short-answer")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "名词解释":
model.Answer = item.QuestionAnswer;
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "multiple")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "noun-explanation")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "论述题":
model.Answer = item.QuestionAnswer;
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "essay-question")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "填空题":
case "分录题":
if (ChooseOptionCount > 0)
{
List<fillInItem> fillInList = new List<fillInItem>();
......@@ -553,23 +576,21 @@ namespace Edu.WebApi.Controllers.Course
}
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "fill-in")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "entry-problem")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "判断题":
case "资料题":
if (ChooseOptionCount > 0)
{
List<optionItem> judgeList = new List<optionItem>();
List<fillInItem> fillInList = new List<fillInItem>();
for (var i = 0; i < ChooseOptionCount; i++)
{
var singleModel = new optionItem()
var singleModel = new fillInItem()
{
Name = Common.ConvertHelper.GetEnChar(i),
Content = "",
IsAnswer= item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
};
if (i == 0)
{
......@@ -603,171 +624,103 @@ namespace Edu.WebApi.Controllers.Course
{
singleModel.Content = item.OptionH;
}
if (singleModel.IsAnswer)
{
model.Answer = singleModel.Name;
}
judgeList.Add(singleModel);
fillInList.Add(singleModel);
}
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(judgeList);
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
}
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "judge")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "data-question")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "简答题":
if (ChooseOptionCount > 0)
{
for (var i = 0; i < ChooseOptionCount; i++)
{
if (i == 0)
case "阅读理解":
List<readingComprehensioItem> readingList = new List<readingComprehensioItem>();
foreach (var subItem in item.SubQuestionList)
{
model.Answer = item.OptionA;
}
if (i == 1)
{
model.Answer = item.OptionB;
}
if (i == 2)
{
model.Answer = item.OptionC;
}
if (i == 3)
{
model.Answer = item.OptionD;
}
if (i == 4)
{
model.Answer = item.OptionE;
}
if (i == 5)
{
model.Answer = item.OptionF;
}
if (i == 6)
{
model.Answer = item.OptionG;
}
if (i == 7)
switch (subItem.QuestionTypeName)
{
model.Answer = item.OptionH;
}
}
}
if (model.QuestionTypeId == 0)
//单选题
case "单选题":
readingComprehensioItem readingModel = new readingComprehensioItem()
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "short-answer")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "名词解释":
if (ChooseOptionCount > 0)
QuestionKey = "single",
QuestionName = "单选题",
QuestionType = 1,
SubTitle = subItem.QuestionTitle,
SubAnwser=new object()
};
Int32.TryParse(subItem.ChooseOptionCount, out int subChooseCount);
List<optionItem> singleList = new List<optionItem>();
for (var i = 0; i < subChooseCount; i++)
{
for (var i = 0; i < ChooseOptionCount; i++)
var singleModel = new optionItem()
{
Name = Common.ConvertHelper.GetEnChar(i),
Content = "",
IsAnswer = subItem.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
};
if (i == 0)
{
model.Answer = item.OptionA;
singleModel.Content = subItem.OptionA;
}
if (i == 1)
{
model.Answer = item.OptionB;
singleModel.Content = subItem.OptionB;
}
if (i == 2)
{
model.Answer = item.OptionC;
singleModel.Content = subItem.OptionC;
}
if (i == 3)
{
model.Answer = item.OptionD;
}
if (i == 4)
{
model.Answer = item.OptionE;
}
if (i == 5)
{
model.Answer = item.OptionF;
singleModel.Content = subItem.OptionD;
}
if (i == 6)
if (singleModel.IsAnswer)
{
model.Answer = item.OptionG;
model.Answer += singleModel.Name + ",";
}
if (i == 7)
{
model.Answer = item.OptionH;
singleList.Add(singleModel);
}
readingModel.SubAnwser = singleList;
readingList.Add(readingModel);
break;
}
}
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(readingList);
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "noun-explanation")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "reading-comprehensio")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
case "论述题":
if (ChooseOptionCount > 0)
{
for (var i = 0; i < ChooseOptionCount; i++)
{
if (i == 0)
{
model.Answer = item.OptionA;
}
if (i == 1)
{
model.Answer = item.OptionB;
}
if (i == 2)
{
model.Answer = item.OptionC;
}
if (i == 3)
{
model.Answer = item.OptionD;
}
if (i == 4)
{
model.Answer = item.OptionE;
}
if (i == 5)
{
model.Answer = item.OptionF;
}
if (i == 6)
{
model.Answer = item.OptionG;
}
if (i == 7)
{
model.Answer = item.OptionH;
}
}
}
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "essay-question")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
model.QuestionContentObj = questionModule.ParsingQuestionModule(model.QuestionTypeKey, model.QuestionContent);
return model;
}
break;
case "分录题":
/// <summary>
/// 解析单选题
/// </summary>
/// <param name="ChooseOptionCount"></param>
/// <param name="item"></param>
/// <param name="model"></param>
/// <param name="questionTypeList"></param>
private void AnalysisSingle(int ChooseOptionCount, ImportModel item, RB_Question_ViewModel model, List<RB_Question_Type_ViewModel> questionTypeList)
{
if (ChooseOptionCount > 0)
{
List<fillInItem> fillInList = new List<fillInItem>();
List<optionItem> singleList = new List<optionItem>();
for (var i = 0; i < ChooseOptionCount; i++)
{
var singleModel = new fillInItem()
var singleModel = new optionItem()
{
Name = Common.ConvertHelper.GetEnChar(i),
Content = "",
IsAnswer = item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
};
if (i == 0)
{
......@@ -801,27 +754,42 @@ namespace Edu.WebApi.Controllers.Course
{
singleModel.Content = item.OptionH;
}
fillInList.Add(singleModel);
if (singleModel.IsAnswer)
{
model.Answer = singleModel.Name;
}
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
singleList.Add(singleModel);
}
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(singleList);
}
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "entry-problem")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "single")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
}
case "资料题":
/// <summary>
/// 解析多选题
/// </summary>
/// <param name="ChooseOptionCount"></param>
/// <param name="item"></param>
/// <param name="model"></param>
/// <param name="questionTypeList"></param>
private void AnalysisMultiple(int ChooseOptionCount, ImportModel item, RB_Question_ViewModel model, List<RB_Question_Type_ViewModel> questionTypeList)
{
if (ChooseOptionCount > 0)
{
List<fillInItem> fillInList = new List<fillInItem>();
List<optionItem> multipleList = new List<optionItem>();
string answer = "";
for (var i = 0; i < ChooseOptionCount; i++)
{
var singleModel = new fillInItem()
var singleModel = new optionItem()
{
Name = Common.ConvertHelper.GetEnChar(i),
Content = "",
IsAnswer = item.QuestionAnswer.Contains(Common.ConvertHelper.GetEnChar(i))
};
if (i == 0)
{
......@@ -855,23 +823,25 @@ namespace Edu.WebApi.Controllers.Course
{
singleModel.Content = item.OptionH;
}
fillInList.Add(singleModel);
if (singleModel.IsAnswer)
{
answer += "," + singleModel.Name;
}
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(fillInList);
multipleList.Add(singleModel);
}
if (!string.IsNullOrEmpty(answer))
{
answer = answer.Substring(1);
}
model.Answer = answer;
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(multipleList);
}
if (model.QuestionTypeId == 0)
{
var tempModel = questionTypeList.Where(qitem => qitem.Key == "data-question")?.FirstOrDefault();
var tempModel = questionTypeList.Where(qitem => qitem.Key == "multiple")?.FirstOrDefault();
model.QuestionTypeId = tempModel?.QId ?? 0;
model.QuestionTypeKey = tempModel?.Key ?? "";
}
break;
}
model.QuestionContentObj = questionModule.ParsingQuestionModule(model.QuestionTypeKey, model.QuestionContent);
return model;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment