|
@@ -336,6 +336,228 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
return examRcds;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ///<summary>
|
|
|
+ ///查询教师的阅卷任务列表
|
|
|
+ /// </summary>
|
|
|
+ /// <data>
|
|
|
+ /// ! "code":"tmdid"
|
|
|
+ /// </data>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-exam-by-sheet")]
|
|
|
+ // [AuthToken(Roles = "teacher,admin")]
|
|
|
+ public async Task<IActionResult> GetExamBySheet(JsonElement request)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ List<SheetConfig> configs = new List<SheetConfig>();
|
|
|
+ HashSet<string> classesSet = new HashSet<string>();
|
|
|
+
|
|
|
+ ExamRcd pexamRcd = null;
|
|
|
+ ExamRcd sexamRcd = null;
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("sheetNo", out JsonElement _sheetNo)) return BadRequest();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ School school = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Status == 404)
|
|
|
+ {
|
|
|
+ school = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
|
|
|
+ if (school != null)
|
|
|
+ {
|
|
|
+ //检查学校购买的模组是否包含阅卷模组
|
|
|
+ int count = 0;
|
|
|
+ string sql = $" SELECT value(count(product)) FROM c join product in c.service.product where c.id ='{_schoolId}' and c.pk='Product' and product.prodCode='YMPCVCIM' ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
|
|
|
+ {
|
|
|
+ count = item;
|
|
|
+ }
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ //获取学校线下阅卷评测
|
|
|
+ sexamRcd = await GetExamBySheet("school", $"{_schoolId}", $"{_schoolId}", client, configs, classesSet, $"{_sheetNo}");
|
|
|
+ }
|
|
|
+ if (response.Status == 200 && sexamRcd == null)
|
|
|
+ {
|
|
|
+ //获取scope=school
|
|
|
+ sexamRcd = await GetExamBySheet("school", $"{_schoolId}", $"{id}", client, configs, classesSet, $"{_sheetNo}");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (response.Status == 200 )
|
|
|
+ {
|
|
|
+ //获取scope=private
|
|
|
+ pexamRcd = await GetExamBySheet("private", null, $"{id}", client, configs, classesSet, $"{_sheetNo}");
|
|
|
+ }
|
|
|
+ (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classInfo) = await TriggerStuActivity.GetStuList(client, _dingDing, classesSet.ToList(), $"{_schoolId}");
|
|
|
+ List<SheetConfig> configsN = new List<SheetConfig>();
|
|
|
+ foreach (var config in configs)
|
|
|
+ {
|
|
|
+ if (config.scope.Equals("school"))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SheetConfig con = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
|
|
|
+ configsN.Add(con);
|
|
|
+ }
|
|
|
+ catch (CosmosException ex) { }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SheetConfig con = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
|
|
|
+ configsN.Add(con);
|
|
|
+ }
|
|
|
+ catch (CosmosException ex) { }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sexamRcd != null)
|
|
|
+ {
|
|
|
+ sexamRcd.classes.ForEach(z => {
|
|
|
+ var a = classInfo.Where(m => m.id.Equals(z.id)).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.name = a.name;
|
|
|
+ z.stuInfos = a.stuInfos;
|
|
|
+ z.tmdInfos = a.tmdInfos;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sexamRcd.papers.ForEach(z => {
|
|
|
+ if (z.sheet != null)
|
|
|
+ {
|
|
|
+ var a = configsN.Where(m => m.id == z.sheet.id && m.scope.Equals(z.sheet.scope)).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.sheet = a;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (pexamRcd != null)
|
|
|
+ {
|
|
|
+ pexamRcd.classes.ForEach(z => {
|
|
|
+ var a = classInfo.Where(m => m.id.Equals(z.id)).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.name = a.name;
|
|
|
+ z.stuInfos = a.stuInfos;
|
|
|
+ z.tmdInfos = a.tmdInfos;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pexamRcd.papers.ForEach(z => {
|
|
|
+ if (z.sheet != null)
|
|
|
+ {
|
|
|
+ var a = configsN.Where(m => m.id == z.sheet.id && m.scope.Equals(z.sheet.scope)).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.sheet = a;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ string teacherBlobSas = null;
|
|
|
+ string teacherBlobUrl = null;
|
|
|
+ string schoolBlobSas = null;
|
|
|
+ string schoolBlobUrl = null;
|
|
|
+ if (sexamRcd != null)
|
|
|
+ {
|
|
|
+ var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS(school.id, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
+ schoolBlobUrl = sblob_uri;
|
|
|
+ schoolBlobSas = sblob_sas;
|
|
|
+ }
|
|
|
+ if (pexamRcd!=null)
|
|
|
+ {
|
|
|
+ var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
+ teacherBlobUrl = tblob_uri;
|
|
|
+ teacherBlobSas = tblob_sas;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { teacherBlobSas, teacherBlobUrl, schoolBlobSas, schoolBlobUrl, school=sexamRcd , teacher = pexamRcd });
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},get-exam-by-sheet\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<ExamRcd> GetExamBySheet(string scope, string school, string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet, string sheetNo)
|
|
|
+ {
|
|
|
+ ExamRcd examRcds = null;
|
|
|
+ int i = 1;
|
|
|
+ StringBuilder sql = new StringBuilder($"SELECT value(c) FROM c join papers in c.papers where c.scope='{scope}' and papers.sheetNo='{sheetNo}' ");
|
|
|
+ if (!string.IsNullOrEmpty(school))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.school='{school}' ");
|
|
|
+ }
|
|
|
+ //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<Correct>(queryText: "SELECT * FROM c where c.source='2' and c.progress='going' order by c.createTime ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
|
|
|
+ await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamInfo>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
|
|
|
+ {
|
|
|
+ List<ClassListInfo> classes = new List<ClassListInfo>();
|
|
|
+ if (exam.classes.IsNotEmpty())
|
|
|
+ {
|
|
|
+ exam.classes.ForEach(x => { classes.Add(new ClassListInfo { id = x }); classesSet.Add(x); });
|
|
|
+ }
|
|
|
+ if (exam.stuLists.IsNotEmpty())
|
|
|
+ {
|
|
|
+ exam.stuLists.ForEach(x => { classes.Add(new ClassListInfo { id = x }); classesSet.Add(x); });
|
|
|
+ }
|
|
|
+ List<PaperRcd> dys = new List<PaperRcd>();
|
|
|
+ foreach (var pap in exam.papers)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(pap.sheet))
|
|
|
+ {
|
|
|
+ if (exam.scope.Equals("school"))
|
|
|
+ {
|
|
|
+ SheetConfig config = new SheetConfig { id = pap.sheet, scope = exam.scope, code = $"SheetConfig-{exam.school}" };
|
|
|
+ dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });
|
|
|
+ sheet.Add(config);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SheetConfig config = new SheetConfig { id = pap.sheet, scope = exam.scope, code = $"SheetConfig-{code}" };
|
|
|
+ dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });
|
|
|
+ sheet.Add(config);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = null });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ examRcds = new ExamRcd
|
|
|
+ {
|
|
|
+ id = exam.id,
|
|
|
+ name = exam.name,
|
|
|
+ startTime = exam.startTime,
|
|
|
+ endTime = exam.endTime,
|
|
|
+ period = exam.period,
|
|
|
+ grades = exam.grades,
|
|
|
+ subjects = exam.subjects,
|
|
|
+ papers = dys,
|
|
|
+ classes = classes,
|
|
|
+ scope = exam.scope
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return examRcds;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
public record PaperRcd {
|
|
|
public string name { get; set; }
|