|
@@ -24,6 +24,9 @@ using static TEAMModelOS.SDK.Models.Cosmos.School.ClassAnalysis;
|
|
|
using static TEAMModelOS.SDK.Models.Cosmos.School.GradeAnalysis;
|
|
|
using TEAMModelOS.Models.Dto;
|
|
|
using System.Text;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using TEAMModelOS.SDK.Context.Constant.Common;
|
|
|
+using HTEXLib.Translator;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Analysis
|
|
|
{
|
|
@@ -38,6 +41,9 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
private const string CacheCosmosPrefix = "Analysis:";
|
|
|
private const int timeoutSeconds = 3600;
|
|
|
public readonly AzureStorageFactory _azureStorage;
|
|
|
+ public DOXC2HTMLTranslator _DOXC2HTMLTranslator { get; set; }
|
|
|
+ //public PPTX2HTEXTranslator _PPTX2HTEXTranslator { get; set; }
|
|
|
+ public HTML2ITEMV3Translator _HTML2ITEMV3Translator { get; set; }
|
|
|
public AchievementController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
@@ -3590,84 +3596,24 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
ExamDto examDtos = new ExamDto();
|
|
|
examDtos = exam.ToObject<ExamDto>();
|
|
|
ExamInfo info = new ExamInfo();
|
|
|
- info.code = info.pk +"-"+ code;
|
|
|
- info.progress = "pending";
|
|
|
- info.id = examDtos.id;
|
|
|
+ info.code = info.pk + "-" + code;
|
|
|
+ info.progress = "finish";
|
|
|
+ info.id = Guid.NewGuid().ToString();
|
|
|
info.name = examDtos.name;
|
|
|
info.grades = examDtos.grades;
|
|
|
info.subjects = examDtos.subjects;
|
|
|
info.period = examDtos.period;
|
|
|
examDtos.targetClasses.ForEach(e =>
|
|
|
{
|
|
|
- info.classes.Add(e.id);
|
|
|
- });
|
|
|
- examDtos.papers.ForEach(p =>
|
|
|
- {
|
|
|
- PaperSimple simple = new PaperSimple
|
|
|
- {
|
|
|
- id = p.id,
|
|
|
- name = p.name
|
|
|
- };
|
|
|
- p.points.ForEach(po =>
|
|
|
- {
|
|
|
- simple.point.Add(double.Parse(po));
|
|
|
- });
|
|
|
- //List<List<string>> answers = new List<List<string>>();
|
|
|
- p.answers.ForEach(an =>
|
|
|
- {
|
|
|
- List<string> ans = new List<string>();
|
|
|
- if (an.Length > 1)
|
|
|
- {
|
|
|
- char[] aa = an.ToCharArray();
|
|
|
- foreach (char a in aa)
|
|
|
- {
|
|
|
- switch (a)
|
|
|
- {
|
|
|
- case '1':
|
|
|
- ans.Add("A");
|
|
|
- break;
|
|
|
- case '2':
|
|
|
- ans.Add("B");
|
|
|
- break;
|
|
|
- case '3':
|
|
|
- ans.Add("C");
|
|
|
- break;
|
|
|
- case '4':
|
|
|
- ans.Add("D");
|
|
|
- break;
|
|
|
- default:
|
|
|
- ans.Add("");
|
|
|
- break;
|
|
|
- }
|
|
|
- // answers.Add(ans);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- switch (an)
|
|
|
- {
|
|
|
- case "1":
|
|
|
- ans.Add("A");
|
|
|
- break;
|
|
|
- case "2":
|
|
|
- ans.Add("B");
|
|
|
- break;
|
|
|
- case "3":
|
|
|
- ans.Add("C");
|
|
|
- break;
|
|
|
- case "4":
|
|
|
- ans.Add("D");
|
|
|
- break;
|
|
|
- default:
|
|
|
- ans.Add("");
|
|
|
- break;
|
|
|
- }
|
|
|
- //answers.Add(ans);
|
|
|
- }
|
|
|
- simple.answers.Add(ans);
|
|
|
- });
|
|
|
- info.papers.Add(simple);
|
|
|
+ info.classes.Add(e);
|
|
|
});
|
|
|
+ info.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ info.startTime = examDtos.startTime;
|
|
|
+ info.endTime = examDtos.endTime;
|
|
|
+ info.school = code.GetString();
|
|
|
+ info.type = examDtos.type;
|
|
|
+ info.scope = "school";
|
|
|
+ info.examType = examDtos.examType;
|
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(info, new PartitionKey($"Exam-{code}"));
|
|
|
return Ok(new { info });
|
|
|
}
|
|
@@ -3677,6 +3623,187 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
+ public class FileDto
|
|
|
+ {
|
|
|
+ public string periodId { get; set; }
|
|
|
+ public string code { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public int multipleRule { get; set; }
|
|
|
+ public string examId { get; set; }
|
|
|
+ public string subjectId { get; set; }
|
|
|
+ public List<string> gradeIds { get; set; }
|
|
|
+ public IFormFile file { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ [HttpPost("parse-word")]
|
|
|
+ public async Task<IActionResult> ParseWord([FromForm] FileDto fileDto)
|
|
|
+ {
|
|
|
+ if (!FileType.GetExtention(fileDto.file.FileName).ToLower().Equals("docx"))
|
|
|
+ {
|
|
|
+ return BadRequest(new Dictionary<string, object> { { "msg", "type is not docx!" }, { "code", ResponseCode.FAILED } });
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(fileDto.examId, new PartitionKey($"Exam-{fileDto.code}"));
|
|
|
+ ExamInfo examInfo;
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ examInfo = json.ToObject<ExamInfo>();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 404, msg = "请先导入评测信息" });
|
|
|
+ }
|
|
|
+ foreach (PaperSimple paper in examInfo.papers)
|
|
|
+ {
|
|
|
+ if (paper.id.Contains(fileDto.subjectId))
|
|
|
+ {
|
|
|
+ return Ok(new { error = 500, msg = "该试卷信息已存在" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PaperSimple simple = new();
|
|
|
+ var doc = _DOXC2HTMLTranslator.Translate(fileDto.file.OpenReadStream());
|
|
|
+ (List<HTEXLib.DOCX.Models.ItemInfo> tests, List<string> error) = _HTML2ITEMV3Translator.Translate(doc);
|
|
|
+ List<Task<string>> tasks = new List<Task<string>>();
|
|
|
+ PaperDto paperDto = new PaperDto();
|
|
|
+ paperDto.id = Guid.NewGuid().ToString();
|
|
|
+ paperDto.name = fileDto.name;
|
|
|
+ paperDto.code = fileDto.code;
|
|
|
+ paperDto.scope = "school";
|
|
|
+ paperDto.multipleRule = fileDto.multipleRule;
|
|
|
+ paperDto.gradeIds = fileDto.gradeIds;
|
|
|
+ paperDto.subjectId = fileDto.subjectId;
|
|
|
+ paperDto.periodId = fileDto.periodId;
|
|
|
+ foreach (HTEXLib.DOCX.Models.ItemInfo item in tests)
|
|
|
+ {
|
|
|
+ Slides slides = new();
|
|
|
+ ItemDto dto = new();
|
|
|
+ TEAMModelOS.SDK.Models.Scoring scoring = new();
|
|
|
+ dto.id = Guid.NewGuid().ToString();
|
|
|
+ dto.exercise.answer = item.answer;
|
|
|
+ dto.exercise.explain = item.explain;
|
|
|
+ dto.exercise.type = item.type;
|
|
|
+ dto.exercise.opts = item.option.Count;
|
|
|
+ dto.exercise.knowledge = item.knowledge;
|
|
|
+ dto.exercise.field = item.field;
|
|
|
+ dto.exercise.level = item.level;
|
|
|
+ dto.exercise.subjectId = fileDto.subjectId;
|
|
|
+ dto.exercise.periodId = fileDto.periodId;
|
|
|
+ dto.exercise.gradeIds = fileDto.gradeIds;
|
|
|
+ slides.url = dto.id + ".json";
|
|
|
+ slides.type = dto.exercise.type;
|
|
|
+ scoring.ans = dto.exercise.answer;
|
|
|
+ scoring.score = dto.exercise.score;
|
|
|
+ scoring.knowledge = dto.exercise.knowledge;
|
|
|
+ scoring.field = dto.exercise.field;
|
|
|
+ slides.scoring = scoring;
|
|
|
+ //添加试卷信息
|
|
|
+ paperDto.slides.Add(slides);
|
|
|
+ if (!slides.type.Equals("compose"))
|
|
|
+ {
|
|
|
+ simple.point.Add(dto.exercise.score);
|
|
|
+ simple.answers.Add(dto.exercise.answer);
|
|
|
+ simple.knowledge.Add(dto.exercise.knowledge);
|
|
|
+ simple.type.Add(dto.exercise.type);
|
|
|
+ simple.field.Add((int)dto.exercise.field);
|
|
|
+ }
|
|
|
+ if (item.children.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (HTEXLib.DOCX.Models.ItemInfo its in item.children)
|
|
|
+ {
|
|
|
+ Slides cslides = new();
|
|
|
+ TEAMModelOS.SDK.Models.Scoring cscoring = new();
|
|
|
+ ItemDto dtoChildren = new ItemDto();
|
|
|
+ dtoChildren.id = Guid.NewGuid().ToString();
|
|
|
+ dtoChildren.pid = dto.id;
|
|
|
+ dtoChildren.exercise.answer = its.answer;
|
|
|
+ dtoChildren.exercise.explain = its.explain;
|
|
|
+ dtoChildren.exercise.type = its.type;
|
|
|
+ dtoChildren.exercise.opts = its.option.Count;
|
|
|
+ dtoChildren.exercise.knowledge = its.knowledge;
|
|
|
+ dtoChildren.exercise.field = its.field;
|
|
|
+ dtoChildren.exercise.level = its.level;
|
|
|
+ dtoChildren.exercise.scope = "school";
|
|
|
+ dtoChildren.exercise.score = its.score;
|
|
|
+ dtoChildren.exercise.subjectId = fileDto.subjectId;
|
|
|
+ dtoChildren.exercise.periodId = fileDto.periodId;
|
|
|
+ dtoChildren.exercise.gradeIds = fileDto.gradeIds;
|
|
|
+ dtoChildren.exercise.children.Add(dtoChildren.id);
|
|
|
+ info info1 = new();
|
|
|
+ info1.uid = dtoChildren.id;
|
|
|
+ info1.question = its.question;
|
|
|
+ info1.option = its.option;
|
|
|
+ dtoChildren.item.Add(info1);
|
|
|
+ dto.exercise.children.Add(dtoChildren.id);
|
|
|
+ //处理子题的slides
|
|
|
+ cslides.url = dtoChildren.id + ".json";
|
|
|
+ cslides.type = dtoChildren.exercise.type;
|
|
|
+ cscoring.ans = dtoChildren.exercise.answer;
|
|
|
+ cscoring.score = dtoChildren.exercise.score;
|
|
|
+ cscoring.knowledge = dtoChildren.exercise.knowledge;
|
|
|
+ cscoring.field = dtoChildren.exercise.field;
|
|
|
+ cslides.scoring = scoring;
|
|
|
+ paperDto.slides.Add(cslides);
|
|
|
+ //添加试卷信息
|
|
|
+ simple.point.Add(dtoChildren.exercise.score);
|
|
|
+ simple.answers.Add(dto.exercise.answer);
|
|
|
+ simple.knowledge.Add(dto.exercise.knowledge);
|
|
|
+ simple.type.Add(dto.exercise.type);
|
|
|
+ simple.field.Add((int)dto.exercise.field);
|
|
|
+
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ stringBuilder.Append(fileDto.examId).Append("/");
|
|
|
+ stringBuilder.Append("paper").Append("/");
|
|
|
+ stringBuilder.Append(fileDto.subjectId).Append("/");
|
|
|
+ stringBuilder.Append(dtoChildren.id + ".json");
|
|
|
+ tasks.Add(_azureStorage.UploadFileByContainer(fileDto.code, dtoChildren.ToJsonString(), "exam", stringBuilder.ToString(), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ info @info = new();
|
|
|
+ @info.uid = dto.id;
|
|
|
+ @info.question = item.question;
|
|
|
+ @info.option = item.option;
|
|
|
+ dto.item.Add(@info);
|
|
|
+ dto.exercise.scope = "school";
|
|
|
+ dto.exercise.score = item.score;
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ builder.Append(fileDto.examId).Append("/");
|
|
|
+ builder.Append("paper").Append("/");
|
|
|
+ builder.Append(fileDto.subjectId).Append("/");
|
|
|
+ builder.Append(dto.id + ".json");
|
|
|
+ tasks.Add(_azureStorage.UploadFileByContainer(fileDto.code, dto.ToJsonString(), "exam", builder.ToString(), false));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ StringBuilder paperBuilder = new StringBuilder();
|
|
|
+ paperBuilder.Append(fileDto.examId).Append("/");
|
|
|
+ paperBuilder.Append("paper").Append("/");
|
|
|
+ paperBuilder.Append(fileDto.subjectId).Append("/");
|
|
|
+ paperBuilder.Append("index.json");
|
|
|
+ tasks.Add(_azureStorage.UploadFileByContainer(fileDto.code, paperDto.ToJsonString(), "exam", paperBuilder.ToString(), false));
|
|
|
+
|
|
|
+ //开始给ExamInfo paper赋值
|
|
|
+ simple.id = fileDto.subjectId;
|
|
|
+ simple.code = "Paper-" + fileDto.code;
|
|
|
+ simple.name = fileDto.name;
|
|
|
+ simple.blob = paperBuilder.ToString().Replace("index.json", "");
|
|
|
+ simple.scope = "school";
|
|
|
+ simple.multipleRule = fileDto.multipleRule;
|
|
|
+
|
|
|
+ examInfo.papers.Add(simple);
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(examInfo, examInfo.id, new PartitionKey($"{examInfo.code}"));
|
|
|
+ await Task.WhenAll(tasks);
|
|
|
+
|
|
|
+ return Ok(new { code = 200 });
|
|
|
+ } catch (Exception e) {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},analysis/word()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
[HttpPost("importResult")]
|
|
|
public async Task<IActionResult> importClassResult(JsonElement request)
|
|
|
{
|
|
@@ -3838,7 +3965,7 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
List<object> info = new List<object>();
|
|
|
var query = $"select c.period,c.id,c.campuses from c where c.id = '{code}'";
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base")}))
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
@@ -3888,7 +4015,7 @@ namespace TEAMModelOS.Controllers.Analysis
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
//private List<Dictionary<string, dynamic>> getKnowledgePoint(List<ExamResult> examResults, ExamInfo info)
|
|
|
//{
|