|
@@ -133,13 +133,14 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("get-examinfo")]
|
|
|
// [AuthToken(Roles = "teacher,admin")]
|
|
|
- public async Task<IActionResult> VerifyQrcode(JsonElement request)
|
|
|
+ public async Task<IActionResult> GetExaminfo(JsonElement request)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
List<SheetConfig> configs = new List<SheetConfig>();
|
|
|
HashSet<string> classesSet = new HashSet<string>();
|
|
|
- ScanSchool scanSchool = new ScanSchool ();
|
|
|
+ ScanExam scanSchool = null;
|
|
|
+ List<ExamRcd> sexamRcds = new List<ExamRcd>() ;
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -157,40 +158,112 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
if (count > 0)
|
|
|
{
|
|
|
//获取学校线下阅卷评测
|
|
|
- var sexams = await GetExam($"{schoolId}", client, configs, classesSet);
|
|
|
+ sexamRcds = await GetExam("school",$"{schoolId}",$"{schoolId}", client, configs, classesSet);
|
|
|
var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS($"{schoolId}", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
- (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 == "school") {
|
|
|
- try {
|
|
|
- SheetConfig con = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
|
|
|
- configsN.Add(con);
|
|
|
- } catch (CosmosException ex) { }
|
|
|
+
|
|
|
+ scanSchool = new ScanExam { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}", /*exams = sexams.schools.ToList(),*/ bloburl = sblob_uri, blobsas = sblob_sas };
|
|
|
+ }
|
|
|
+ //获取scope=school
|
|
|
+ var psexamRcds = await GetExam("school", schoolId, $"{id}", client, configs, classesSet);
|
|
|
+
|
|
|
+ //获取scope=private
|
|
|
+ var pexamRcds = await GetExam("private", null, $"{id}", client, configs, classesSet);
|
|
|
+
|
|
|
+ (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 == "school")
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SheetConfig con = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
|
|
|
+ configsN.Add(con);
|
|
|
+ }
|
|
|
+ catch (CosmosException ex) { }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ SheetConfig con = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
|
|
|
+ configsN.Add(con);
|
|
|
+ }
|
|
|
+ catch (CosmosException ex) { }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
+ var a = classInfo.Where(m => m.id == z.id).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.name = a.name;
|
|
|
+ z.stuInfos = a.stuInfos;
|
|
|
+ z.tmdInfos = a.tmdInfos;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
+ if (z.sheet != null)
|
|
|
+ {
|
|
|
+ var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.sheet = a;
|
|
|
}
|
|
|
}
|
|
|
- sexams.schools.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
+ });
|
|
|
+ scanSchool.exams = sexamRcds;
|
|
|
+ if (psexamRcds.IsNotEmpty()) {
|
|
|
+ psexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
var a = classInfo.Where(m => m.id == z.id).FirstOrDefault();
|
|
|
- if (a != null) {
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
z.name = a.name;
|
|
|
z.stuInfos = a.stuInfos;
|
|
|
z.tmdInfos = a.tmdInfos;
|
|
|
}
|
|
|
});
|
|
|
- sexams.schools.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
+ psexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
if (z.sheet != null)
|
|
|
{
|
|
|
var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
|
|
|
- if (a != null) {
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
z.sheet = a;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- scanSchool = new ScanSchool { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}", exams = sexams.schools.ToList(), bloburl = sblob_uri, blobsas = sblob_sas };
|
|
|
+ scanSchool.exams.AddRange(psexamRcds);
|
|
|
}
|
|
|
-
|
|
|
- var pexams = await GetExam($"{id}", client, configs, classesSet);
|
|
|
- return Ok(new { school=scanSchool });
|
|
|
+
|
|
|
+ var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
|
|
|
+ var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ string name = $"{json.RootElement.GetProperty("name")}";
|
|
|
+ string picture = $"{json.RootElement.GetProperty("picture")}";
|
|
|
+ ScanExam scanTeacher = new ScanExam { name= name, picture= picture, id=$"{id}", bloburl = tblob_uri, blobsas = tblob_sas };
|
|
|
+ if (pexamRcds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ pexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
+ var a = classInfo.Where(m => m.id == z.id).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.name = a.name;
|
|
|
+ z.stuInfos = a.stuInfos;
|
|
|
+ z.tmdInfos = a.tmdInfos;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
+ if (z.sheet != null)
|
|
|
+ {
|
|
|
+ var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
|
|
|
+ if (a != null)
|
|
|
+ {
|
|
|
+ z.sheet = a;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ scanTeacher.exams.AddRange(psexamRcds);
|
|
|
+ }
|
|
|
+ return Ok(new { school=scanSchool, teacher= scanTeacher });
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -199,15 +272,18 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
- private async Task<(List< ExamRcd> schools, List<ExamRcd> personal)> GetExam(string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet)
|
|
|
+ private async Task<List<ExamRcd>> GetExam(string scope,string school,string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet)
|
|
|
{
|
|
|
- List<ExamRcd> schools = new List<ExamRcd>();
|
|
|
- List<ExamRcd> personal = new List<ExamRcd>();
|
|
|
+ List<ExamRcd> examRcds = new List<ExamRcd>();
|
|
|
+ //List<ExamRcd> personal = new List<ExamRcd>();
|
|
|
int i= 1;
|
|
|
+ StringBuilder sql = new StringBuilder($"SELECT * FROM c where c.progress='going' and c.scope='{scope}' ");
|
|
|
+ if (!string.IsNullOrEmpty(school)) {
|
|
|
+ sql.Append($" and c.school='{school}' ");
|
|
|
+ }
|
|
|
//await foreach (var item in client.GetContainer("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("TEAMModelOS", "Common").GetItemQueryIterator<ExamInfo>(queryText: "SELECT * FROM c where c.progress='going' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
|
|
|
+ await foreach (var exam in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<ExamInfo>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
|
|
|
{
|
|
|
- Console.WriteLine(i++);
|
|
|
List<ClassListInfo> classes = new List<ClassListInfo>();
|
|
|
exam.classes.ForEach(x => { classes.Add(new ClassListInfo { id = x }); classesSet.Add(x); } );
|
|
|
List<PaperRcd> dys = new List<PaperRcd>();
|
|
@@ -233,38 +309,50 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = null });
|
|
|
}
|
|
|
}
|
|
|
- if (exam.scope == "school")
|
|
|
+ examRcds.Add(new ExamRcd
|
|
|
{
|
|
|
- schools.Add(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
|
|
|
- });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- personal.Add(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
|
|
|
- });
|
|
|
- }
|
|
|
+ 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
|
|
|
+ });
|
|
|
+ //if (exam.scope == "school")
|
|
|
+ //{
|
|
|
+ // schools.Add(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
|
|
|
+ // });
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // personal.Add(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
|
|
|
+ // });
|
|
|
+ //}
|
|
|
}
|
|
|
- return (schools, personal);
|
|
|
+ return examRcds;
|
|
|
}
|
|
|
}
|
|
|
public record PaperRcd {
|
|
@@ -287,7 +375,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public List<ClassListInfo> classes { get; set; }
|
|
|
}
|
|
|
|
|
|
- public class ScanSchool
|
|
|
+ public class ScanExam
|
|
|
{
|
|
|
public string blobsas { get; set; }
|
|
|
public string bloburl { get; set; }
|