|
@@ -139,37 +139,56 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
{
|
|
|
List<SheetConfig> configs = new List<SheetConfig>();
|
|
|
HashSet<string> classesSet = new HashSet<string>();
|
|
|
- ScanExam scanSchool = null;
|
|
|
- List<ExamRcd> sexamRcds = new List<ExamRcd>() ;
|
|
|
+
|
|
|
+ List<ExamRcd> sexamRcds = new List<ExamRcd>();
|
|
|
+
|
|
|
+ List<ExamRcd> psexamRcds = new List<ExamRcd>();
|
|
|
+ List<ExamRcd> ppexamRcds = new List<ExamRcd>();
|
|
|
+ List<ExamRcd> pexamRcds = 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();
|
|
|
- School school= await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
|
|
|
- var schoolId = $"{_schoolId}";
|
|
|
- var schoolName = school.name;
|
|
|
- var schoolPicture = school.picture;
|
|
|
- //检查学校购买的模组是否包含阅卷模组
|
|
|
- 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("TEAMModelOS", "School").GetItemQueryIterator<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
|
|
|
- {
|
|
|
- count = item;
|
|
|
+ School school = null;
|
|
|
+ try {
|
|
|
+ school= await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
|
|
|
+ } catch (CosmosException ex) {
|
|
|
+ if (ex.Status == 404) {
|
|
|
+ school = null;
|
|
|
+ }
|
|
|
}
|
|
|
- if (count > 0)
|
|
|
- {
|
|
|
- //获取学校线下阅卷评测
|
|
|
- sexamRcds = await GetExam("school",$"{schoolId}",$"{schoolId}", client, configs, classesSet);
|
|
|
- var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS($"{schoolId}", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
-
|
|
|
- scanSchool = new ScanExam { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}", /*exams = sexams.schools.ToList(),*/ bloburl = sblob_uri, blobsas = sblob_sas };
|
|
|
+ var response = await client.GetContainer("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("TEAMModelOS", "School").GetItemQueryIterator<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
|
|
|
+ {
|
|
|
+ count = item;
|
|
|
+ }
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ //获取学校线下阅卷评测
|
|
|
+ sexamRcds = await GetExam("school", $"{_schoolId}", $"{_schoolId}", client, configs, classesSet);
|
|
|
+ }
|
|
|
+ if (response.Status == 200) {
|
|
|
+ //获取scope=school
|
|
|
+ psexamRcds = await GetExam("school", $"{_schoolId}", $"{id}", client, configs, classesSet);
|
|
|
+ if (psexamRcds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ pexamRcds.AddRange(psexamRcds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- //获取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}");
|
|
|
+ if (response.Status == 200) {
|
|
|
+ //获取scope=private
|
|
|
+ ppexamRcds = await GetExam("private", null, $"{id}", client, configs, classesSet);
|
|
|
+ if (ppexamRcds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ pexamRcds.AddRange(ppexamRcds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (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)
|
|
|
{
|
|
@@ -191,28 +210,9 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
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;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- scanSchool.exams = sexamRcds;
|
|
|
- if (psexamRcds.IsNotEmpty()) {
|
|
|
- psexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
+ //处理学校发布的评测
|
|
|
+ if (sexamRcds.IsNotEmpty()) {
|
|
|
+ sexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
var a = classInfo.Where(m => m.id == z.id).FirstOrDefault();
|
|
|
if (a != null)
|
|
|
{
|
|
@@ -221,7 +221,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
z.tmdInfos = a.tmdInfos;
|
|
|
}
|
|
|
});
|
|
|
- psexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
+ sexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
if (z.sheet != null)
|
|
|
{
|
|
|
var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
|
|
@@ -231,17 +231,10 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- scanSchool.exams.AddRange(psexamRcds);
|
|
|
}
|
|
|
-
|
|
|
- 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())
|
|
|
- {
|
|
|
+
|
|
|
+ //处理教师发布的个人班级评测和学校班级评测
|
|
|
+ if (pexamRcds.IsNotEmpty()) {
|
|
|
pexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
|
|
|
var a = classInfo.Where(m => m.id == z.id).FirstOrDefault();
|
|
|
if (a != null)
|
|
@@ -261,9 +254,23 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- scanTeacher.exams.AddRange(psexamRcds);
|
|
|
}
|
|
|
- return Ok(new { school=scanSchool, teacher= scanTeacher });
|
|
|
+
|
|
|
+ ScanBlob teacherBlob = null;
|
|
|
+ if (ppexamRcds.IsNotEmpty()) {
|
|
|
+ var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ string name = $"{json.RootElement.GetProperty("name")}";
|
|
|
+ string picture = $"{json.RootElement.GetProperty("picture")}";
|
|
|
+ var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List );
|
|
|
+ teacherBlob = new ScanBlob { name = name, picture = picture, id = $"{id}", bloburl = tblob_uri, blobsas = tblob_sas };
|
|
|
+ }
|
|
|
+ ScanBlob schoolBlob = null;
|
|
|
+ if (psexamRcds.IsNotEmpty()|| sexamRcds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS(school.id, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
+ schoolBlob = new ScanBlob { name = school.name, picture = school.picture,id=school.id, bloburl = sblob_uri, blobsas = sblob_sas };
|
|
|
+ }
|
|
|
+ return Ok(new { teacherBlob= teacherBlob, schoolBlob= schoolBlob, schoolExam =sexamRcds.IsNotEmpty()?sexamRcds:null, teacherExam= pexamRcds.IsNotEmpty()? pexamRcds:null});
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -275,7 +282,6 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
private async Task<List<ExamRcd>> GetExam(string scope,string school,string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet)
|
|
|
{
|
|
|
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)) {
|
|
@@ -319,38 +325,9 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
grades = exam.grades,
|
|
|
subjects = exam.subjects,
|
|
|
papers = dys,
|
|
|
- classes = classes
|
|
|
+ classes = classes,
|
|
|
+ scope= exam.scope
|
|
|
});
|
|
|
- //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 examRcds;
|
|
|
}
|
|
@@ -373,15 +350,15 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public List<ExamSubject> subjects { get; set; }
|
|
|
public List<PaperRcd> papers { get; set; }
|
|
|
public List<ClassListInfo> classes { get; set; }
|
|
|
+ public string scope { get; set; }
|
|
|
}
|
|
|
|
|
|
- public class ScanExam
|
|
|
- {
|
|
|
+
|
|
|
+ public class ScanBlob{
|
|
|
public string blobsas { get; set; }
|
|
|
public string bloburl { get; set; }
|
|
|
public string name { get; set; }
|
|
|
public string picture { get; set; }
|
|
|
public string id { get; set; }
|
|
|
- public List<ExamRcd> exams { get; set; }
|
|
|
}
|
|
|
}
|