|
@@ -81,7 +81,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
|
|
|
- if (response.Status == 200)
|
|
|
+ if (response.Status == 200)
|
|
|
{
|
|
|
var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
string name = $"{json.RootElement.GetProperty("name")}";
|
|
@@ -109,15 +109,18 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
if (count > 0)
|
|
|
{
|
|
|
- schools.Add(new { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}" });
|
|
|
+ schools.Add(new { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}" });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
|
|
|
- return Ok(new { schools, teacher=new { name, picture, id, bloburl = tblob_uri, blobsas = tblob_sas , status = response.Status } });
|
|
|
+ return Ok(new { schools, teacher = new { name, picture, id, bloburl = tblob_uri, blobsas = tblob_sas } });
|
|
|
}
|
|
|
- return Ok(new { status = response.Status });
|
|
|
+ else {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
///<summary>
|
|
|
///查询教师的阅卷任务列表
|
|
@@ -128,110 +131,85 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("verify-qrcode")]
|
|
|
+ [HttpPost("get-examinfo")]
|
|
|
// [AuthToken(Roles = "teacher,admin")]
|
|
|
public async Task<IActionResult> VerifyQrcode(JsonElement request)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
-
|
|
|
- List<ScanSchool> schools = new List<ScanSchool>();
|
|
|
+ List<SheetConfig> configs = new List<SheetConfig>();
|
|
|
+ HashSet<string> classesSet = new HashSet<string>();
|
|
|
+ ScanSchool scanSchool = new ScanSchool ();
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- //TODO 取得Teacher 個人相關數據(課程清單、虛擬教室清單、歷史紀錄清單等),學校數據另外API處理,多校切換時不同
|
|
|
+ if (!request.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
|
|
|
- int size = 0;
|
|
|
- //老師個人資料(含初始化)
|
|
|
- if (response.Status == 200)
|
|
|
+ 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") }))
|
|
|
{
|
|
|
- HashSet<string> classesSet = new HashSet<string>();
|
|
|
- List<SheetConfig> configs = new List<SheetConfig>();
|
|
|
- var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- string name = $"{json.RootElement.GetProperty("name")}";
|
|
|
- string picture = $"{json.RootElement.GetProperty("picture")}";
|
|
|
- if (json.RootElement.TryGetProperty("schools", out JsonElement value))
|
|
|
- {
|
|
|
-
|
|
|
- if (json.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
|
|
|
- {
|
|
|
- size = _size.GetInt32();
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var obj in value.EnumerateArray())
|
|
|
- {
|
|
|
- string statusNow = obj.GetProperty("status").ToString();
|
|
|
- //正式加入才会有
|
|
|
- if (statusNow == "join")
|
|
|
- {
|
|
|
- //dynamic schoolExtobj = new ExpandoObject();
|
|
|
- var schoolJson = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{obj.GetProperty("schoolId")}", new PartitionKey("Base"));
|
|
|
- var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
|
|
|
- var schoolId = obj.GetProperty("schoolId");
|
|
|
- var schoolName = obj.GetProperty("name");
|
|
|
- var schoolPicture = school.RootElement.GetProperty("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;
|
|
|
- }
|
|
|
- if (count > 0)
|
|
|
- {
|
|
|
- //生成token
|
|
|
- var stoken = JwtAuthExtension.CreateAuthToken(_option.HostName, $"{id}", name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" }, schoolID: $"{schoolId}");
|
|
|
- //获取学校线下阅卷评测
|
|
|
- var sexams = await GetExam($"{schoolId}", client, configs, classesSet);
|
|
|
- var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS($"{schoolId}", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
- schools.Add(new ScanSchool { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}", exams = sexams.schools.Select(x => x.Value).ToList(), bloburl = sblob_uri, blobsas = sblob_sas });
|
|
|
- }
|
|
|
- }
|
|
|
+ count = item;
|
|
|
+ }
|
|
|
+ if (count > 0)
|
|
|
+ {
|
|
|
+ //获取学校线下阅卷评测
|
|
|
+ var sexams = await GetExam($"{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) { }
|
|
|
}
|
|
|
}
|
|
|
- var ttoken = JwtAuthExtension.CreateAuthToken(_option.HostName, $"{id}", name?.ToString(), picture?.ToString(), _option.JwtSecretKey, roles: new[] { "teacher" });
|
|
|
-
|
|
|
- //获取个人线下阅卷评测
|
|
|
- var exams = await GetExam($"{id}", client, configs, classesSet);
|
|
|
- List<dynamic> teacher = new List<dynamic>();
|
|
|
- var list = exams.schools.GroupBy(x => x.Key).Select(y => new { key = y.Key, val = y.ToList() }).ToList();
|
|
|
- foreach (var s in list)
|
|
|
- {
|
|
|
- var schoolJson = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{s.key}", new PartitionKey("Base"));
|
|
|
- if (schoolJson.Status == 200)
|
|
|
+ sexams.schools.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;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sexams.schools.SelectMany(y => y.papers).ToList().ForEach(z => {
|
|
|
+ if (z.sheet != null)
|
|
|
{
|
|
|
- var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
|
|
|
- var schoolName = school.RootElement.GetProperty("name");
|
|
|
- var schoolPicture = school.RootElement.GetProperty("picture");
|
|
|
- var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS($"{s.key}", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
|
|
|
- teacher.Add(new { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{s.key}", exams = s.val.Select(x => x.Value).ToList(), bloburl = sblob_uri, blobsas = sblob_sas });
|
|
|
+ var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
|
|
|
+ if (a != null) {
|
|
|
+ z.sheet = a;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
|
|
|
- teacher.Add(new { name, picture, id, exams = exams.personal, bloburl = tblob_uri, blobsas = tblob_sas });
|
|
|
- //換取AuthToken,提供給前端
|
|
|
- var lists= await TriggerStuActivity.GetStuList(client, _dingDing, classesSet.ToList(), "hbcn");
|
|
|
-
|
|
|
- var data = new { schools, teacher, lists.students,lists.tmdids};
|
|
|
- return Ok(data);
|
|
|
-
|
|
|
+ });
|
|
|
+ scanSchool = new ScanSchool { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}", exams = sexams.schools.ToList(), bloburl = sblob_uri, blobsas = sblob_sas };
|
|
|
}
|
|
|
+
|
|
|
+ var pexams = await GetExam($"{id}", client, configs, classesSet);
|
|
|
+ return Ok(new { school=scanSchool });
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},hiscan/verify-qrcode()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest();
|
|
|
}
|
|
|
- return Ok();
|
|
|
}
|
|
|
- private async Task<(List<KeyValuePair<string, ExamRcd>> schools, List<ExamRcd> personal)> GetExam(string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet)
|
|
|
+ private async Task<(List< ExamRcd> schools, List<ExamRcd> personal)> GetExam(string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet)
|
|
|
{
|
|
|
- List<KeyValuePair<string, ExamRcd>> schools = new List<KeyValuePair<string, ExamRcd>>();
|
|
|
+ List<ExamRcd> schools = new List<ExamRcd>();
|
|
|
List<ExamRcd> personal = new List<ExamRcd>();
|
|
|
+ int i= 1;
|
|
|
//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}") }))
|
|
|
{
|
|
|
- List<ExamClass> classes = new List<ExamClass>();
|
|
|
- exam.classes.ForEach(x => { classes.Add(new ExamClass { classId = x }); classesSet.Add(x); } );
|
|
|
+ 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>();
|
|
|
foreach (var pap in exam.papers)
|
|
|
{
|
|
@@ -254,34 +232,36 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
{
|
|
|
dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = null });
|
|
|
}
|
|
|
- if (exam.scope == "school")
|
|
|
+ }
|
|
|
+ if (exam.scope == "school")
|
|
|
+ {
|
|
|
+ schools.Add(new ExamRcd
|
|
|
{
|
|
|
- schools.Add(new KeyValuePair<string, ExamRcd>(exam.school, new ExamRcd
|
|
|
- {
|
|
|
- name = exam.name,
|
|
|
- startTime = exam.startTime,
|
|
|
- endTime = exam.endTime,
|
|
|
- period = exam.period,
|
|
|
- grades = exam.grades,
|
|
|
- subjects = exam.subjects,
|
|
|
- papers = dys,
|
|
|
- classes = classes
|
|
|
- }));
|
|
|
- }
|
|
|
- else
|
|
|
+ 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
|
|
|
{
|
|
|
- personal.Add(new ExamRcd
|
|
|
- {
|
|
|
- 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
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
return (schools, personal);
|
|
@@ -294,9 +274,9 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public SheetConfig sheet { get; set; }
|
|
|
}
|
|
|
|
|
|
- // pap.name, pap.answers, pap.point, sheet =pap.sheet
|
|
|
public record ExamRcd
|
|
|
{
|
|
|
+ public string id { get; set; }
|
|
|
public string name { get; set; }
|
|
|
public long startTime { get; set; }
|
|
|
public long endTime { get; set; }
|
|
@@ -304,7 +284,7 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public List<Grade> grades { get; set; }
|
|
|
public List<ExamSubject> subjects { get; set; }
|
|
|
public List<PaperRcd> papers { get; set; }
|
|
|
- public List<ExamClass> classes { get; set; }
|
|
|
+ public List<ClassListInfo> classes { get; set; }
|
|
|
}
|
|
|
|
|
|
public class ScanSchool
|
|
@@ -314,17 +294,6 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
public string name { get; set; }
|
|
|
public string picture { get; set; }
|
|
|
public string id { get; set; }
|
|
|
- // public string status { get; set; }
|
|
|
- //public string token { get; set; }
|
|
|
public List<ExamRcd> exams { get; set; }
|
|
|
- // public List<(Correct,ExamInfo, (List<string> tmdids, List<Students> stulist))> exams{ get; set; }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public class ExamClass {
|
|
|
- public string classId { get; set; }
|
|
|
- public string className { get; set; }
|
|
|
- public List<TmdInfo> tmdids { get; set; } = new List<TmdInfo>();
|
|
|
- public List<StuInfo> stulist { get; set; } = new List<StuInfo>();
|
|
|
}
|
|
|
}
|