|
@@ -23,7 +23,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
-
|
|
|
+
|
|
|
[Route("school/classroom")]
|
|
|
[ApiController]
|
|
|
public class ClassController : ControllerBase
|
|
@@ -47,7 +47,7 @@ namespace TEAMModelOS.Controllers
|
|
|
try
|
|
|
{
|
|
|
if (!requert.TryGetProperty("classroom", out JsonElement room)) return BadRequest();
|
|
|
- Class classroom = room.ToObject<Class>();
|
|
|
+ Class classroom = room.ToObject<Class>();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
classroom.code = "Class-" + classroom.school;
|
|
|
if (string.IsNullOrEmpty(classroom.id))
|
|
@@ -73,7 +73,8 @@ namespace TEAMModelOS.Controllers
|
|
|
classroom.id = Guid.NewGuid().ToString();
|
|
|
classroom = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(classroom, new PartitionKey(classroom.code));
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(classroom.id, new PartitionKey(classroom.code));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
@@ -214,48 +215,87 @@ namespace TEAMModelOS.Controllers
|
|
|
string school_code = code.ToString();
|
|
|
Class classroom = new Class();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- classroom = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Class>(id.ToString(), new PartitionKey($"Class-{school_code}"));
|
|
|
- //List<TeacherCourse> classes = new List<TeacherCourse>();
|
|
|
+ classroom = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Class>(id.ToString(), new PartitionKey($"Class-{school_code}"));
|
|
|
+ //List<TeacherCourse> classes = new List<TeacherCourse>();
|
|
|
|
|
|
- //await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"CourseManagement-{school_code}"));
|
|
|
- //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.classes where A0.id = '{id}'"))
|
|
|
- //{
|
|
|
- // using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- // {
|
|
|
- // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- // {
|
|
|
- // classes.Add(obj.ToObject<TeacherCourse>());
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //for (int i = 0; i < classes.Count; i++)
|
|
|
- //{
|
|
|
- // bool flag = false;
|
|
|
- // for (int j = 0; j < classes[i].classes.Count; j++)
|
|
|
- // {
|
|
|
- // if (classes[i].classes[j].id.Equals(id.ToString()))
|
|
|
- // {
|
|
|
- // classes[i].classes.Remove(classes[i].classes[j]);
|
|
|
- // flag = true;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // if (flag)
|
|
|
- // {
|
|
|
- // await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(classes[i], classes[i].id, new PartitionKey($"{classes[i].code}"));
|
|
|
- // }
|
|
|
- //}
|
|
|
- List<Student> students = new List<Student>();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select * from c where c.classId='{id}' ", requestOptions:new QueryRequestOptions { PartitionKey= new PartitionKey ($"Base-{code}") }))
|
|
|
+ //await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"CourseManagement-{school_code}"));
|
|
|
+ //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.classes where A0.id = '{id}'"))
|
|
|
+ //{
|
|
|
+ // using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ // if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ // {
|
|
|
+ // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ // {
|
|
|
+ // classes.Add(obj.ToObject<TeacherCourse>());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //for (int i = 0; i < classes.Count; i++)
|
|
|
+ //{
|
|
|
+ // bool flag = false;
|
|
|
+ // for (int j = 0; j < classes[i].classes.Count; j++)
|
|
|
+ // {
|
|
|
+ // if (classes[i].classes[j].id.Equals(id.ToString()))
|
|
|
+ // {
|
|
|
+ // classes[i].classes.Remove(classes[i].classes[j]);
|
|
|
+ // flag = true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (flag)
|
|
|
+ // {
|
|
|
+ // await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(classes[i], classes[i].id, new PartitionKey($"{classes[i].code}"));
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select * from c where c.classId='{id}' ", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{code}") }))
|
|
|
+ {
|
|
|
+ item.classId = "";
|
|
|
+ students.Add(item);
|
|
|
+ }
|
|
|
+ List<Task<ItemResponse<Student>>> tasks = new List<Task<ItemResponse<Student>>>();
|
|
|
+ foreach (var stu in students)
|
|
|
+ {
|
|
|
+ tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stu, stu.id, new PartitionKey(($"Base-{code}"))));
|
|
|
+ }
|
|
|
+ //查询含有该班级的课程ID
|
|
|
+ List<string> cids = new List<string>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
|
|
|
+ queryText: $"select distinct c.id from c join A0 in c.schedule where A0.classId = '{id}'",
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
{
|
|
|
- item.classId = "";
|
|
|
- students.Add(item);
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ cids.Add(account.GetProperty("id").GetString());
|
|
|
+ }
|
|
|
}
|
|
|
- List<Task<ItemResponse<Student>>> tasks = new List<Task<ItemResponse<Student>>>();
|
|
|
- foreach (var stu in students) {
|
|
|
- tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stu, stu.id, new PartitionKey(($"Base-{code}"))));
|
|
|
+ }
|
|
|
+ List<Task<ItemResponse<Course>>> taskCourses = new List<Task<ItemResponse<Course>>>();
|
|
|
+ List<Course> courses = new List<Course>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Course>(
|
|
|
+ queryText: $"select value(c) from c where c.id in ({string.Join(",", cids.Select(o => $"'{o}'"))})",
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ foreach (Course course in courses)
|
|
|
+ {
|
|
|
+ foreach (var sc in course.schedule)
|
|
|
+ {
|
|
|
+ if (sc.classId.Equals(id))
|
|
|
+ {
|
|
|
+ sc.classId = "";
|
|
|
+ }
|
|
|
}
|
|
|
- await Task.WhenAll(tasks);
|
|
|
+ taskCourses.Add(client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(course, course.id, new PartitionKey((course.code))));
|
|
|
+ }
|
|
|
+
|
|
|
+ await Task.WhenAll(tasks);
|
|
|
+ await Task.WhenAll(taskCourses);
|
|
|
//}
|
|
|
return Ok(new { classroom });
|
|
|
}
|
|
@@ -312,7 +352,7 @@ namespace TEAMModelOS.Controllers
|
|
|
deviceBound updDeviceBound = updSerialInfo.deviceBound.Where(d => d.uuid == uuid && d.uuid2 == uuid2).FirstOrDefault();
|
|
|
if (updDeviceBound != null)
|
|
|
{
|
|
|
- if (action .Equals("link"))
|
|
|
+ if (action.Equals("link"))
|
|
|
{
|
|
|
if (updDeviceBound.classId != null)
|
|
|
{
|
|
@@ -323,7 +363,7 @@ namespace TEAMModelOS.Controllers
|
|
|
updDeviceBound.classId = classId;
|
|
|
}
|
|
|
}
|
|
|
- else if (action .Equals("unLink"))
|
|
|
+ else if (action.Equals("unLink"))
|
|
|
{
|
|
|
updDeviceBound.classId = null;
|
|
|
}
|