|
@@ -1,8 +1,10 @@
|
|
|
using Azure.Cosmos;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -31,12 +33,16 @@ namespace TEAMModelOS.Controllers
|
|
|
public readonly AzureCosmosFactory _azureCosmos;
|
|
|
private readonly Option _option;
|
|
|
private readonly DingDing _dingDing;
|
|
|
- public ClassController(AzureCosmosFactory azureCosmos, DingDing dingDing,
|
|
|
+ public IConfiguration _configuration { get; set; }
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ public ClassController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureServiceBusFactory serviceBus, IConfiguration configuration,
|
|
|
IOptionsSnapshot<Option> option)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_dingDing = dingDing;
|
|
|
_option = option?.Value;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _configuration = configuration;
|
|
|
}
|
|
|
[ProducesDefaultResponseType]
|
|
|
//[AuthToken(Roles = "teacher")]
|
|
@@ -209,48 +215,19 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- //if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
- //string school_code = code.ToString().Substring(6);
|
|
|
+
|
|
|
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>();
|
|
|
-
|
|
|
- //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}"));
|
|
|
- // }
|
|
|
- //}
|
|
|
+ Class classroom = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Class>(id.ToString(), new PartitionKey($"Class-{school_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 = "";
|
|
|
+ item.classId = null ;
|
|
|
students.Add(item);
|
|
|
}
|
|
|
List<Task<ItemResponse<Student>>> tasks = new List<Task<ItemResponse<Student>>>();
|
|
@@ -258,6 +235,30 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stu, stu.id, new PartitionKey(($"Base-{code}"))));
|
|
|
}
|
|
|
+
|
|
|
+ GroupChange change = new GroupChange();
|
|
|
+ if (students.IsNotEmpty()) {
|
|
|
+ change.stuleave.AddRange(students.Select(x=> new Member {
|
|
|
+ id = x.id,
|
|
|
+ type = 2,
|
|
|
+ nickname = x.name,
|
|
|
+ irs = x.irs,
|
|
|
+ no = x.no,
|
|
|
+ groupId = x.groupId,
|
|
|
+ groupName = x.groupName,
|
|
|
+ code = $"{code}"
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ change.listid = classroom.id;
|
|
|
+ change.scope = "school";
|
|
|
+ change.originCode = $"{code}";
|
|
|
+ change.school = classroom.school;
|
|
|
+ change.type = "class";
|
|
|
+ change.status = "delete";
|
|
|
+ var messageChange = new ServiceBusMessage(change.ToJsonString());
|
|
|
+ messageChange.ApplicationProperties.Add("name", "GroupChange");
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
//查询含有该班级的课程ID
|
|
|
List<string> cids = new List<string>();
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
|
|
@@ -303,7 +304,6 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
await Task.WhenAll(tasks);
|
|
|
await Task.WhenAll(taskCourses);
|
|
|
- //}
|
|
|
return Ok(new { classroom });
|
|
|
}
|
|
|
catch (Exception ex)
|