|
@@ -38,7 +38,7 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly Option _option;
|
|
|
- private readonly IConfiguration _configuration;
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
private readonly NotificationService _notificationService;
|
|
|
public InitController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService)
|
|
|
{
|
|
@@ -59,29 +59,33 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("set-teacher-info")]
|
|
|
[AuthToken(Roles = "admin,teacher,area")]
|
|
|
|
|
|
- public async Task<IActionResult> SetTeacherInfo(JsonElement request) {
|
|
|
+ public async Task<IActionResult> SetTeacherInfo(JsonElement request)
|
|
|
+ {
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
+
|
|
|
if (!request.TryGetProperty("opt", out JsonElement _opt))
|
|
|
{
|
|
|
return BadRequest();
|
|
|
}
|
|
|
var (userid, name, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(userid, new PartitionKey("Base"));
|
|
|
- switch (true) {
|
|
|
+ switch (true)
|
|
|
+ {
|
|
|
//修改默认学校
|
|
|
- case bool when $"{_opt}".Equals("UpdateDefaultSchool", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("defaultSchool", out JsonElement _defaultSchool)) :
|
|
|
+ case bool when $"{_opt}".Equals("UpdateDefaultSchool", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("defaultSchool", out JsonElement _defaultSchool)):
|
|
|
if (teacher.schools.Select(x => x.schoolId).Contains($"{_defaultSchool}") && !string.IsNullOrEmpty($"{_defaultSchool}"))
|
|
|
{
|
|
|
teacher.defaultSchool = $"{_defaultSchool}";
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, userid, new PartitionKey("Base"));
|
|
|
return Ok(new { teacher, status = 1 });
|
|
|
}
|
|
|
- else {
|
|
|
- return BadRequest(new { status=-1,msg="您未加入该学校!"});
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest(new { status = -1, msg = "您未加入该学校!" });
|
|
|
}
|
|
|
- case bool when $"{_opt}".Equals("TransferAdminRole", StringComparison.OrdinalIgnoreCase ) && (request.TryGetProperty("targerTecher", out JsonElement _targetTecher) ):
|
|
|
+ case bool when $"{_opt}".Equals("TransferAdminRole", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("targerTecher", out JsonElement _targetTecher)):
|
|
|
if (!string.IsNullOrEmpty(school) && !string.IsNullOrEmpty($"{_targetTecher}"))
|
|
|
{
|
|
|
SchoolTeacher schoolTeacher = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>(userid, new PartitionKey($"Teacher-{school}"));
|
|
@@ -89,19 +93,20 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
schoolTeacher.roles.Remove("admin");
|
|
|
SchoolTeacher newSchoolTeacher = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>($"{_targetTecher}", new PartitionKey($"Teacher-{school}"));
|
|
|
- if (!newSchoolTeacher.roles.Contains("admin")) {
|
|
|
+ if (!newSchoolTeacher.roles.Contains("admin"))
|
|
|
+ {
|
|
|
newSchoolTeacher.roles.Add("admin");
|
|
|
newSchoolTeacher = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(newSchoolTeacher, $"{_targetTecher}", new PartitionKey($"Teacher-{school}"));
|
|
|
}
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, userid, new PartitionKey($"Teacher-{school}"));
|
|
|
string code = "transfer-admin";
|
|
|
- School schoolBase= await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>( school, new PartitionKey($"Base"));
|
|
|
+ School schoolBase = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey($"Base"));
|
|
|
Notification notification = new Notification
|
|
|
{
|
|
|
hubName = "hita",
|
|
|
type = "msg",
|
|
|
from = $"ies5:{_option.Location}:{school}",
|
|
|
- to = new List<string> { $"{_targetTecher}"},
|
|
|
+ to = new List<string> { $"{_targetTecher}" },
|
|
|
label = $"{code}_school",
|
|
|
body = new { location = _option.Location, biz = code, tmdid = userid, tmdname = name, schoolcode = $"{school}", schoolname = $"{schoolBase.name}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
@@ -115,27 +120,28 @@ namespace TEAMModelOS.Controllers
|
|
|
var location = _option.Location;
|
|
|
await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
}
|
|
|
- return Ok(new { status = 1 });
|
|
|
+ return Ok(new { status = 1 });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return BadRequest(new { status = -1, msg = "当前登录账号没有admin权限" });
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return BadRequest(new { status = -1, msg = "参数异常!" });
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- catch(Exception ex)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},Teacher/init/set-teacher-info()\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest("teacher not exist");
|
|
|
|
|
|
}
|
|
|
return BadRequest();
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
//TODO 此API需處理對應前端返回的相關數據
|
|
|
[ProducesDefaultResponseType]
|
|
@@ -158,7 +164,8 @@ namespace TEAMModelOS.Controllers
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
int total = 0;
|
|
|
int tsize = 0;
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
|
|
|
teacher.name = $"{name}";
|
|
|
teacher.picture = $"{picture}";
|
|
@@ -168,87 +175,97 @@ namespace TEAMModelOS.Controllers
|
|
|
total = teacher.size;
|
|
|
areas = teacher.areas;
|
|
|
//检查是否有加入学校,如果加入学校,则当个人空间size是0G的时候,则免费获得一个G空间,但无论加入多少个学校,只能获取一次 1G的免费空间。没有加入学校则默认0G空间,除非自己购买空间
|
|
|
- if (teacher.schools.IsNotEmpty()) {
|
|
|
- foreach (var sc in teacher.schools) {
|
|
|
- string statusNow = sc.status!=null?sc.status:"";
|
|
|
- if (statusNow .Equals("join") || statusNow .Equals("invite") || statusNow.Equals("request")) {
|
|
|
- dynamic schoolExtobj = new ExpandoObject();
|
|
|
- var schoolJson = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{sc.schoolId}", new PartitionKey("Base"));
|
|
|
- var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
|
|
|
- schoolExtobj.schoolId = sc.schoolId;
|
|
|
- schoolExtobj.name = school.RootElement.GetProperty("name") ;
|
|
|
- schoolExtobj.status =sc.status;
|
|
|
- schoolExtobj.time = sc.time;
|
|
|
- schoolExtobj.picture = school.RootElement.GetProperty("picture");
|
|
|
- school.RootElement.TryGetProperty("areaId",out JsonElement areaId);
|
|
|
- schoolExtobj.areaId = $"{areaId}";
|
|
|
- Area area = null;
|
|
|
- if (!string.IsNullOrEmpty($"{areaId}"))
|
|
|
+ if (teacher.schools.IsNotEmpty())
|
|
|
+ {
|
|
|
+ foreach (var sc in teacher.schools)
|
|
|
+ {
|
|
|
+ string statusNow = sc.status != null ? sc.status : "";
|
|
|
+ if (statusNow.Equals("join") || statusNow.Equals("invite") || statusNow.Equals("request"))
|
|
|
{
|
|
|
-
|
|
|
- try
|
|
|
+ dynamic schoolExtobj = new ExpandoObject();
|
|
|
+ var schoolJson = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{sc.schoolId}", new PartitionKey("Base"));
|
|
|
+ var school = await JsonDocument.ParseAsync(schoolJson.ContentStream);
|
|
|
+ schoolExtobj.schoolId = sc.schoolId;
|
|
|
+ schoolExtobj.name = school.RootElement.GetProperty("name");
|
|
|
+ schoolExtobj.status = sc.status;
|
|
|
+ schoolExtobj.time = sc.time;
|
|
|
+ schoolExtobj.picture = school.RootElement.GetProperty("picture");
|
|
|
+ school.RootElement.TryGetProperty("areaId", out JsonElement areaId);
|
|
|
+ schoolExtobj.areaId = $"{areaId}";
|
|
|
+ Area area = null;
|
|
|
+ if (!string.IsNullOrEmpty($"{areaId}"))
|
|
|
+ {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ area = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Area>($"{areaId}", new PartitionKey("Base-Area"));
|
|
|
+ }
|
|
|
+ catch (CosmosException)
|
|
|
+ {
|
|
|
+ area = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ schoolExtobj.area = area;
|
|
|
+ var sctch = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(id, new PartitionKey($"Teacher-{sc.schoolId}"));
|
|
|
+ if (sctch.Status == 200)
|
|
|
{
|
|
|
- area = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Area>($"{areaId}", new PartitionKey("Base-Area"));
|
|
|
+ var jsonDoc = await JsonDocument.ParseAsync(sctch.ContentStream);
|
|
|
+ SchoolTeacher schoolTeacher = jsonDoc.RootElement.ToObject<SchoolTeacher>();
|
|
|
+ schoolTeacher.name = $"{name}";
|
|
|
+ schoolTeacher.picture = $"{picture}";
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(schoolTeacher, id, new PartitionKey($"Teacher-{sc.schoolId}"));
|
|
|
+ if (jsonDoc.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
|
|
|
+ {
|
|
|
+ total += _size.GetInt32();
|
|
|
+ schoolExtobj.size = _size.GetInt32();
|
|
|
+ }
|
|
|
+ else { schoolExtobj.size = 0; }
|
|
|
}
|
|
|
- catch (CosmosException )
|
|
|
+ else
|
|
|
{
|
|
|
- area = null;
|
|
|
+ schoolExtobj.size = 0;
|
|
|
}
|
|
|
- }
|
|
|
- schoolExtobj.area = area;
|
|
|
- var sctch = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(id, new PartitionKey($"Teacher-{sc.schoolId}"));
|
|
|
- if (sctch.Status == 200)
|
|
|
- {
|
|
|
- var jsonDoc = await JsonDocument.ParseAsync(sctch.ContentStream);
|
|
|
- SchoolTeacher schoolTeacher = jsonDoc.RootElement.ToObject<SchoolTeacher>();
|
|
|
- schoolTeacher.name = $"{name}";
|
|
|
- schoolTeacher.picture = $"{picture}";
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(schoolTeacher, id, new PartitionKey($"Teacher-{sc.schoolId}"));
|
|
|
- if (jsonDoc.RootElement.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
|
|
|
+ if (statusNow.Equals("join"))
|
|
|
{
|
|
|
- total += _size.GetInt32();
|
|
|
- schoolExtobj.size = _size.GetInt32();
|
|
|
+ //初始化
|
|
|
+ await TmdUserService.JoinSchool(client, teacher.id, teacher.picture, teacher.name, sc.schoolId, sc.name);
|
|
|
}
|
|
|
- else { schoolExtobj.size = 0; }
|
|
|
- }
|
|
|
- else {
|
|
|
- schoolExtobj.size=0;
|
|
|
- }
|
|
|
- if (statusNow.Equals("join")) {
|
|
|
- //初始化
|
|
|
- await TmdUserService.JoinSchool(client, teacher.id, teacher.picture, teacher.name, sc.schoolId, sc.name);
|
|
|
+ schools.Add(schoolExtobj);
|
|
|
}
|
|
|
- schools.Add(schoolExtobj);
|
|
|
}
|
|
|
- }
|
|
|
//如果包含任何申请,邀请,加入学校的记录 且个人空间未分配2G 则默认分配个人空间至2G.
|
|
|
- if ( teacher.size<2 && teacher.schools.Count > 0)
|
|
|
+ if (teacher.size < 2 && teacher.schools.Count > 0)
|
|
|
{
|
|
|
teacher.size = 2;
|
|
|
}
|
|
|
//如果未包含任何申请,邀请,加入学校的记录 且 个人空间没有分配1G 则默认赠送一个G
|
|
|
- if (teacher.schools.Count == 0 && teacher.size<1) {
|
|
|
+ if (teacher.schools.Count == 0 && teacher.size < 1)
|
|
|
+ {
|
|
|
teacher.size = 1;
|
|
|
}
|
|
|
}
|
|
|
- if (string.IsNullOrEmpty(teacher.defaultSchool) && teacher.schools.IsNotEmpty()) {
|
|
|
+ if (string.IsNullOrEmpty(teacher.defaultSchool) && teacher.schools.IsNotEmpty())
|
|
|
+ {
|
|
|
var tech = teacher.schools.FindAll(x => x.status.Equals("join"));
|
|
|
- if (tech.IsNotEmpty()) {
|
|
|
+ if (tech.IsNotEmpty())
|
|
|
+ {
|
|
|
teacher.defaultSchool = teacher.schools[0].schoolId;
|
|
|
}
|
|
|
}
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, id, new PartitionKey("Base"));
|
|
|
//預設學校ID
|
|
|
defaultschool = teacher.defaultSchool;
|
|
|
- } catch(CosmosException ex)
|
|
|
- {
|
|
|
- if (ex.Status == 404) {
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Status == 404)
|
|
|
+ {
|
|
|
//如果沒有,則初始化Teacher基本資料到Cosmos
|
|
|
Teacher teacher = new Teacher
|
|
|
{
|
|
|
- id = id,
|
|
|
+ id = id,
|
|
|
pk = "Base",
|
|
|
- code = "Base",
|
|
|
+ code = "Base",
|
|
|
name = name?.ToString(),
|
|
|
picture = picture?.ToString(),
|
|
|
//创建账号并第一次登录IES5则默认赠送1G
|
|
@@ -261,7 +278,7 @@ namespace TEAMModelOS.Controllers
|
|
|
teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
total = teacher.size;
|
|
|
tsize = teacher.size;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
//私人課程
|
|
|
List<object> courses = new List<object>();
|
|
@@ -279,9 +296,10 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//老師個人課綱 TODO 暂时不取
|
|
|
List<SyllabusRole> syllabus = new List<SyllabusRole>();
|
|
|
- List<string> roles= new List<string>() { "teacher" };
|
|
|
+ List<string> roles = new List<string>() { "teacher" };
|
|
|
Area areaa = null;
|
|
|
- if (areas.Count > 0) {
|
|
|
+ if (areas.Count > 0)
|
|
|
+ {
|
|
|
roles.Add("area");
|
|
|
if (!string.IsNullOrEmpty($"{areas[0]}"))
|
|
|
{
|
|
@@ -297,14 +315,15 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
//換取AuthToken,提供給前端
|
|
|
- var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, standard: areaa != null ? areaa.standard : "",roles: roles.ToArray());
|
|
|
+ var auth_token = JwtAuthExtension.CreateAuthToken(_option.HostName, id, name?.ToString(), picture?.ToString(), _option.JwtSecretKey, standard: areaa != null ? areaa.standard : "", roles: roles.ToArray());
|
|
|
//取得Teacher Blob 容器位置及SAS
|
|
|
await _azureStorage.GetBlobContainerClient(id).CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
|
|
|
var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(id, BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
|
|
|
var (osblob_uri, osblob_sas) = roles.Contains("area") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
return Ok(new { location = _option.Location, auth_token, blob_uri, blob_sas, schools, defaultschool, courses, total, osblob_uri, osblob_sas, tsize, status = 200, areas });
|
|
|
}
|
|
|
- catch (CosmosException ex) {
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},Teacher/GetTeacherInfo()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest();
|
|
|
}
|
|
@@ -317,7 +336,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
//TODO 此API需處理對應前端返回的相關數據
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("get-school-info")]
|
|
|
+ [HttpPost("get-school-info")]
|
|
|
public async Task<IActionResult> GetSchoolInfo(JsonElement request)
|
|
|
{
|
|
|
try
|
|
@@ -380,14 +399,17 @@ namespace TEAMModelOS.Controllers
|
|
|
//TODO JJ,调整为取得学校基础设置数据,取代下方學校學制、年級
|
|
|
|
|
|
School school_base = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{school_code}", new PartitionKey("Base"));
|
|
|
- foreach (var period in school_base.period) {
|
|
|
+ foreach (var period in school_base.period)
|
|
|
+ {
|
|
|
try
|
|
|
{
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemCond>($"{period.id}", new PartitionKey($"ItemCond-{school_code}"));
|
|
|
}
|
|
|
- catch (CosmosException ) {
|
|
|
- ItemCond itemCond = new ItemCond {
|
|
|
- id = period.id,
|
|
|
+ catch (CosmosException)
|
|
|
+ {
|
|
|
+ ItemCond itemCond = new ItemCond
|
|
|
+ {
|
|
|
+ id = period.id,
|
|
|
pk = "ItemCond",
|
|
|
code = $"ItemCond-{school_code}",
|
|
|
ttl = -1,
|
|
@@ -500,7 +522,8 @@ namespace TEAMModelOS.Controllers
|
|
|
var (osblob_uri, osblob_sas) = roles.Contains("area") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
return Ok(new { auth_token, blob_uri, blob_sas, school_base, school_courses, school_syllabus, school_classes, school_rooms, size, osblob_uri, osblob_sas, status = 200, areas });
|
|
|
}
|
|
|
- catch (CosmosException ex) {
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},Teacher/init/get-school-info()\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
return Ok(new { status = ex.Status });
|
|
|
}
|
|
@@ -533,12 +556,12 @@ namespace TEAMModelOS.Controllers
|
|
|
Dictionary<string, List<Dictionary<string, string>>> managerSchDic = new Dictionary<string, List<Dictionary<string, string>>>();
|
|
|
string managerWhereOption = (!string.IsNullOrWhiteSpace(sqlSchoolId)) ? $" AND c.code = 'Teacher-{sqlSchoolId}'" : string.Empty;
|
|
|
string managerSql = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId, c.id, c.name FROM c WHERE ARRAY_CONTAINS(c.roles, 'admin', true) AND c.pk = 'Teacher' AND c.status = 'join'{managerWhereOption}";
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() {} ))
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
|
|
|
{
|
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- string id = obj.GetProperty("id").GetString(); //管理者ID
|
|
|
+ string id = obj.GetProperty("id").GetString(); //管理者ID
|
|
|
string name = obj.GetProperty("name").GetString(); //管理者姓名
|
|
|
string schoolId = obj.GetProperty("schoolId").GetString(); //學校ID
|
|
|
Dictionary<string, string> managerDic = new Dictionary<string, string>();
|
|
@@ -598,19 +621,19 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
schoolExtobj.hasBaseModule = (baseModuleSchList.Contains(schoolExtobj.id)) ? true : false;
|
|
|
//學校輸出結果加入篩選
|
|
|
- if( (sqlHasManager && sqlHasMBaseModule) && (schoolExtobj.hasManager && schoolExtobj.hasBaseModule) )
|
|
|
+ if ((sqlHasManager && sqlHasMBaseModule) && (schoolExtobj.hasManager && schoolExtobj.hasBaseModule))
|
|
|
{
|
|
|
schools.Add(schoolExtobj);
|
|
|
}
|
|
|
- else if(sqlHasManager && schoolExtobj.hasManager)
|
|
|
+ else if (sqlHasManager && schoolExtobj.hasManager)
|
|
|
{
|
|
|
schools.Add(schoolExtobj);
|
|
|
}
|
|
|
- else if(sqlHasMBaseModule && schoolExtobj.hasBaseModule)
|
|
|
+ else if (sqlHasMBaseModule && schoolExtobj.hasBaseModule)
|
|
|
{
|
|
|
schools.Add(schoolExtobj);
|
|
|
}
|
|
|
- else if(!sqlHasManager && !sqlHasMBaseModule)
|
|
|
+ else if (!sqlHasManager && !sqlHasMBaseModule)
|
|
|
{
|
|
|
schools.Add(schoolExtobj);
|
|
|
}
|
|
@@ -664,9 +687,9 @@ namespace TEAMModelOS.Controllers
|
|
|
else
|
|
|
{
|
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- teacher.schools.Add(new Teacher.TeacherSchool() { schoolId = school_code.GetString(), name = school_name.GetString(), status = grant_type.GetString() ,time= now });
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool() { schoolId = school_code.GetString(), name = school_name.GetString(), status = grant_type.GetString(), time = now });
|
|
|
}
|
|
|
- if (grant_type.GetString() .Equals("leave") || grant_type.GetString() .Equals("cancel"))
|
|
|
+ if (grant_type.GetString().Equals("leave") || grant_type.GetString().Equals("cancel"))
|
|
|
{
|
|
|
if (teacher.schools.IsNotEmpty())
|
|
|
{
|
|
@@ -677,12 +700,12 @@ namespace TEAMModelOS.Controllers
|
|
|
inSchools.ForEach(x => teacher.schools.Remove(x));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (teacher.schools.Count > 0 && teacher.size <= 1)
|
|
|
{
|
|
|
teacher.size = 2;
|
|
|
}
|
|
|
- if (!string.IsNullOrEmpty(teacher.defaultSchool) &&teacher.defaultSchool.Equals($"{school_code}"))
|
|
|
+ if (!string.IsNullOrEmpty(teacher.defaultSchool) && teacher.defaultSchool.Equals($"{school_code}"))
|
|
|
{
|
|
|
if (teacher.schools.IsNotEmpty())
|
|
|
{
|
|
@@ -698,7 +721,8 @@ namespace TEAMModelOS.Controllers
|
|
|
//await TmdUserService.LeaveSchool(client, teacher.id, school.schoolId);
|
|
|
return Ok(new { stauts = 1 });
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
var dft = new List<string>() { "content-read", "exercise-read", "knowledge-read", "syllabus-read" };
|
|
|
if (teacher.schools.Count > 0 && teacher.size <= 1)
|
|
|
{
|
|
@@ -712,21 +736,24 @@ namespace TEAMModelOS.Controllers
|
|
|
using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
|
|
|
SchoolTeacher steacher = json.ToObject<SchoolTeacher>();
|
|
|
steacher.status = grant_type.GetString();
|
|
|
- if (grant_type.ToString().Equals("join")) {
|
|
|
+ if (grant_type.ToString().Equals("join"))
|
|
|
+ {
|
|
|
if (steacher.permissions.IsNotEmpty())
|
|
|
{
|
|
|
- foreach (var d in dft) {
|
|
|
+ foreach (var d in dft)
|
|
|
+ {
|
|
|
if (!steacher.permissions.Contains(d))
|
|
|
{
|
|
|
steacher.permissions.Add(d);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
steacher.permissions = dft;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(steacher, id, new PartitionKey($"Teacher-{school_code}"));
|
|
|
}
|
|
@@ -740,27 +767,30 @@ namespace TEAMModelOS.Controllers
|
|
|
id = id,
|
|
|
name = name.ToString(),
|
|
|
picture = picture?.ToString(),
|
|
|
- permissions = grant_type.ToString().Equals("join")? dft : null,
|
|
|
+ permissions = grant_type.ToString().Equals("join") ? dft : null,
|
|
|
roles = new List<string>() { "teacher" },
|
|
|
size = 0,
|
|
|
status = grant_type.GetString()
|
|
|
};
|
|
|
var response = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(st, new PartitionKey($"Teacher-{school_code}"));
|
|
|
}
|
|
|
- if (grant_type.ToString().Equals("join")) {
|
|
|
+ if (grant_type.ToString().Equals("join"))
|
|
|
+ {
|
|
|
await TmdUserService.JoinSchool(client, teacher.id, teacher.picture, teacher.name, school.schoolId, school.name);
|
|
|
}
|
|
|
Notification notification = null;
|
|
|
-
|
|
|
+
|
|
|
List<SchoolTeacher> teachers = new List<SchoolTeacher>();
|
|
|
var queryslt = $"SELECT value(c) FROM c join A1 in c.roles where A1 in ('admin')";
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
|
{
|
|
|
teachers.Add(item);
|
|
|
}
|
|
|
- if (teachers.IsNotEmpty()) {
|
|
|
+ if (teachers.IsNotEmpty())
|
|
|
+ {
|
|
|
string code = grant_type.GetString();
|
|
|
- if (grant_type.GetString() .Equals("join")) {
|
|
|
+ if (grant_type.GetString().Equals("join"))
|
|
|
+ {
|
|
|
code = "invite-join";
|
|
|
}
|
|
|
notification = new Notification
|
|
@@ -770,17 +800,18 @@ namespace TEAMModelOS.Controllers
|
|
|
from = $"ies5:{_option.Location}:private",
|
|
|
to = teachers.Select(x => x.id).ToList(),
|
|
|
label = $"{code}_school",
|
|
|
- body = new { location = _option.Location, biz = code, tmdid= id ,tmdname= name.ToString(), schoolcode=$"{school_code}", schoolname=$"{school_name}", status =1,time= DateTimeOffset.UtcNow .ToUnixTimeMilliseconds()}.ToJsonString(),
|
|
|
- expires= DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ body = new { location = _option.Location, biz = code, tmdid = id, tmdname = name.ToString(), schoolcode = $"{school_code}", schoolname = $"{school_name}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
- if (notification != null) {
|
|
|
- var url= _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
- var clientID= _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+
|
|
|
+ if (notification != null)
|
|
|
+ {
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
var location = _option.Location;
|
|
|
- var code = await _notificationService .SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
+ var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
}
|
|
|
return Ok(new { stauts = 1 });
|
|
|
}
|
|
@@ -800,7 +831,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
foreach (var syllabus in syllabuses)
|
|
|
{
|
|
|
- if (syllabus.pid .Equals(""))
|
|
|
+ if (syllabus.pid.Equals(""))
|
|
|
nodes.Add(new SyllabusNode { id = syllabus.id, name = syllabus.name });
|
|
|
else
|
|
|
{
|