|
@@ -67,7 +67,9 @@ namespace TEAMModelOS.Controllers
|
|
//string status_str = (request.TryGetProperty("join_status", out JsonElement status_json)) ? status_json.ToString() : "join";
|
|
//string status_str = (request.TryGetProperty("join_status", out JsonElement status_json)) ? status_json.ToString() : "join";
|
|
//資料取得
|
|
//資料取得
|
|
List<ScTeacher> teachers = new List<ScTeacher>();
|
|
List<ScTeacher> teachers = new List<ScTeacher>();
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ScTeacher>(queryText: $"SELECT c.subjectIds, c.id, c.name, c.picture ,c.status, c.job, c.createTime, ARRAY_LENGTH(c.permissions) as permissionCount,c.permissions,c.roles , c.size FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ScTeacher>
|
|
|
|
+ (queryText: $"SELECT c.subjectIds, c.id, c.name, c.picture ,c.status, c.job, c.createTime, ARRAY_LENGTH(c.permissions) as permissionCount,c.permissions,c.roles , c.size FROM c",
|
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school_code}") }))
|
|
{
|
|
{
|
|
if ($"{item.createTime}".Length > 10) {
|
|
if ($"{item.createTime}".Length > 10) {
|
|
item.createTime = item.createTime / 1000;
|
|
item.createTime = item.createTime / 1000;
|
|
@@ -93,6 +95,141 @@ namespace TEAMModelOS.Controllers
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync($"{school_code}", new PartitionKey("TeacherImport"));
|
|
|
|
+ if (response.Status == 200) {
|
|
|
|
+ List<CoreUser> coreUsers = new List<CoreUser>();
|
|
|
|
+ TeacherImport teacherImport = JsonDocument.Parse(response.Content).RootElement.ToObject<TeacherImport>();
|
|
|
|
+ var idsIn = teacherImport.teachers.Where(x => !string.IsNullOrWhiteSpace(x.id));
|
|
|
|
+ //id是空 其他不是空的
|
|
|
|
+ var tmdidsi = teacherImport.teachers.Where(x => string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(x.tmdid)).Select(z => z.tmdid);
|
|
|
|
+ var phonesi = teacherImport.teachers.Where(x => string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(x.phone)).Select(z => z.phone);
|
|
|
|
+ var emailsi = teacherImport.teachers.Where(x => string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(x.email)).Select(z => z.email);
|
|
|
|
+ List<string> skeys = new List<string>();
|
|
|
|
+ if (idsIn.Any()) {
|
|
|
|
+ skeys.AddRange(idsIn.Select(x=>x.id));
|
|
|
|
+ }
|
|
|
|
+ if (tmdidsi.Any())
|
|
|
|
+ {
|
|
|
|
+ skeys.AddRange(tmdidsi);
|
|
|
|
+ }
|
|
|
|
+ if (phonesi.Any())
|
|
|
|
+ {
|
|
|
|
+ skeys.AddRange(phonesi);
|
|
|
|
+ }
|
|
|
|
+ if (emailsi.Any())
|
|
|
|
+ {
|
|
|
|
+ skeys.AddRange(emailsi);
|
|
|
|
+ }
|
|
|
|
+ if (skeys.Any())
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ var content = new StringContent(skeys.ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
|
+ string json = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(json))
|
|
|
|
+ {
|
|
|
|
+ coreUsers = json.ToObject<List<CoreUser>>();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ //await _dingDing.SendBotMsg($"{_option.Location},导入名单时,查验key信息错误{ex.Message}\n{ex.StackTrace}\n{skeys.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (coreUsers.Any())
|
|
|
|
+ {
|
|
|
|
+ teacherImport.teachers.ForEach(t => {
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.id))
|
|
|
|
+ {
|
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => x.searchKey.Equals(t.id) || x.id.Equals(t.id));
|
|
|
|
+ if (coreUser != null)
|
|
|
|
+ {
|
|
|
|
+ t.id = coreUser.id;
|
|
|
|
+ t.picture = coreUser.picture;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ t.id = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (string.IsNullOrWhiteSpace(t.id))
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.tmdid))
|
|
|
|
+ {
|
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => x.id.Equals(t.tmdid));
|
|
|
|
+ if (coreUser != null)
|
|
|
|
+ {
|
|
|
|
+ t.id = coreUser.id;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (string.IsNullOrWhiteSpace(t.id))
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.phone))
|
|
|
|
+ {
|
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => x.mobile.Equals(t.phone));
|
|
|
|
+ if (coreUser != null)
|
|
|
|
+ {
|
|
|
|
+ t.id = coreUser.id;
|
|
|
|
+ t.picture = coreUser.picture;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (string.IsNullOrWhiteSpace(t.id))
|
|
|
|
+ {
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.email))
|
|
|
|
+ {
|
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => x.mail.Equals(t.email));
|
|
|
|
+ if (coreUser != null)
|
|
|
|
+ {
|
|
|
|
+ t.id = coreUser.id;
|
|
|
|
+ t.picture = coreUser.picture;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.id))
|
|
|
|
+ {
|
|
|
|
+ var tch= teachers.Find(x => x.id.Equals(t.id));
|
|
|
|
+ if (tch == null) {
|
|
|
|
+ tch= new ScTeacher
|
|
|
|
+ {
|
|
|
|
+ id = t.id,
|
|
|
|
+ name = t.name,
|
|
|
|
+ picture = t.picture,
|
|
|
|
+ status = "import",
|
|
|
|
+ createTime = t.time,
|
|
|
|
+ permissionCount = 0,
|
|
|
|
+ size = 0,
|
|
|
|
+ permissions = new List<string>(),
|
|
|
|
+ roles = new List<string>(),
|
|
|
|
+ subjectIds = new List<string>(),
|
|
|
|
+ groups = new List<IdNameCode>(),
|
|
|
|
+ };
|
|
|
|
+ teachers.Add(tch);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ //teachers.Add();
|
|
|
|
+ var tch= new ScTeacher
|
|
|
|
+ {
|
|
|
|
+ id=t.id,
|
|
|
|
+ picture=t.picture,
|
|
|
|
+ name=t.name,
|
|
|
|
+ status="import",
|
|
|
|
+ createTime=t.time,
|
|
|
|
+ permissionCount=0,
|
|
|
|
+ size=0,
|
|
|
|
+ permissions= new List<string>(),
|
|
|
|
+ roles=new List<string>(),
|
|
|
|
+ subjectIds=new List<string>(),
|
|
|
|
+ groups= new List<IdNameCode>(),
|
|
|
|
+ };
|
|
|
|
+ teachers.Add(tch);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return Ok(new { teachers });
|
|
return Ok(new { teachers });
|
|
}
|
|
}
|
|
public class ScTeacher
|
|
public class ScTeacher
|
|
@@ -110,7 +247,7 @@ namespace TEAMModelOS.Controllers
|
|
public List<string> subjectIds { get; set; }
|
|
public List<string> subjectIds { get; set; }
|
|
public List<IdNameCode> groups { get; set; } = new List<IdNameCode>();
|
|
public List<IdNameCode> groups { get; set; } = new List<IdNameCode>();
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 取得某位老師的權限
|
|
/// 取得某位老師的權限
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -565,66 +702,92 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
|
|
var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
|
-
|
|
|
|
|
|
+ request.TryGetProperty("id", out JsonElement id);
|
|
|
|
+ request.TryGetProperty("name", out JsonElement name);
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
//在老師表找出老師,刪除該學校 (老師基本資料應該要存在)
|
|
//在老師表找出老師,刪除該學校 (老師基本資料應該要存在)
|
|
- Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id.ToString(), new PartitionKey("Base"));
|
|
|
|
- var school = teacher.schools.RemoveAll(x => x.schoolId.Equals(school_code.GetString(), StringComparison.OrdinalIgnoreCase));
|
|
|
|
- if (!string.IsNullOrEmpty(teacher.defaultSchool) && teacher.defaultSchool.Equals($"{school_code}")) {
|
|
|
|
- if (teacher.schools.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- teacher.defaultSchool = teacher.schools[0].schoolId;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- teacher.defaultSchool = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, id.ToString(), new PartitionKey("Base"));
|
|
|
|
- //移除學校表中的老師document
|
|
|
|
- var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Teacher-{school_code}"));
|
|
|
|
- //将教师移除学校,同时也移除研修名单,教研组。
|
|
|
|
- StringBuilder queryText = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain' or c.type='research' ");
|
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryText.ToString(),
|
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school_code.GetString()}") }))
|
|
|
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync($"{school_code}", new PartitionKey("TeacherImport"));
|
|
|
|
+ TeacherImport teacherImport = null;
|
|
|
|
+ if (response.Status == 200)
|
|
{
|
|
{
|
|
- bool exists = item.members.Exists(x => x.id.Equals(id.ToString()));
|
|
|
|
- if (exists) {
|
|
|
|
- item.members.RemoveAll(x => x.id.Equals(id.ToString()));
|
|
|
|
- await GroupListService.UpsertList(item, _azureCosmos, _configuration, _azureServiceBus);
|
|
|
|
- //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item,item.id,new PartitionKey(item.code));
|
|
|
|
|
|
+ teacherImport= JsonDocument.Parse(response.Content).RootElement.Deserialize<TeacherImport>();
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{name}") && teacherImport!= null) {
|
|
|
|
+ //移除同名的、其中一个
|
|
|
|
+ var ts= teacherImport.teachers.FindAll(x => !string.IsNullOrWhiteSpace(x.name ) && x.name.Equals($"{name}"));
|
|
|
|
+ if (ts.IsNotEmpty()) {
|
|
|
|
+ teacherImport.teachers.Remove(ts.First());
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(teacherImport, $"{school_code}", new PartitionKey("TeacherImport"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{id}")) {
|
|
|
|
|
|
- //await TmdUserService.LeaveSchool(client, $"{teacher.id}", $"{school_code}" );
|
|
|
|
- //取得學校資訊
|
|
|
|
- var schresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Base"));
|
|
|
|
- string schname = string.Empty;
|
|
|
|
- if (schresponse.Status == 200)
|
|
|
|
- {
|
|
|
|
- using var schjson = await JsonDocument.ParseAsync(schresponse.ContentStream);
|
|
|
|
- schjson.RootElement.TryGetProperty("name", out JsonElement jsonschname);
|
|
|
|
- schname = jsonschname.ToString();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- return BadRequest();
|
|
|
|
|
|
+ if (teacherImport != null) {
|
|
|
|
+ int count= teacherImport.teachers.RemoveAll(x => !string.IsNullOrWhiteSpace(x.id) && x.id.Equals($"{id}"));
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(teacherImport, $"{school_code}", new PartitionKey("TeacherImport"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id.ToString(), new PartitionKey("Base"));
|
|
|
|
+ var school = teacher.schools.RemoveAll(x => x.schoolId.Equals(school_code.GetString(), StringComparison.OrdinalIgnoreCase));
|
|
|
|
+ if (!string.IsNullOrEmpty(teacher.defaultSchool) && teacher.defaultSchool.Equals($"{school_code}"))
|
|
|
|
+ {
|
|
|
|
+ if (teacher.schools.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ teacher.defaultSchool = teacher.schools[0].schoolId;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ teacher.defaultSchool = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, id.ToString(), new PartitionKey("Base"));
|
|
|
|
+ //移除學校表中的老師document
|
|
|
|
+ var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Teacher-{school_code}"));
|
|
|
|
+ //将教师移除学校,同时也移除研修名单,教研组。
|
|
|
|
+ StringBuilder queryText = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain' or c.type='research' ");
|
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryText.ToString(),
|
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school_code.GetString()}") }))
|
|
|
|
+ {
|
|
|
|
+ bool exists = item.members.Exists(x => x.id.Equals(id.ToString()));
|
|
|
|
+ if (exists)
|
|
|
|
+ {
|
|
|
|
+ item.members.RemoveAll(x => x.id.Equals(id.ToString()));
|
|
|
|
+ await GroupListService.UpsertList(item, _azureCosmos, _configuration, _azureServiceBus);
|
|
|
|
+ //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item,item.id,new PartitionKey(item.code));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //await TmdUserService.LeaveSchool(client, $"{teacher.id}", $"{school_code}" );
|
|
|
|
+ //取得學校資訊
|
|
|
|
+ var schresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Base"));
|
|
|
|
+ string schname = string.Empty;
|
|
|
|
+ if (schresponse.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ using var schjson = await JsonDocument.ParseAsync(schresponse.ContentStream);
|
|
|
|
+ schjson.RootElement.TryGetProperty("name", out JsonElement jsonschname);
|
|
|
|
+ schname = jsonschname.ToString();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ Notification notification = new Notification
|
|
|
|
+ {
|
|
|
|
+ hubName = "hita",
|
|
|
|
+ type = "msg",
|
|
|
|
+ from = $"ies5:{_option.Location}:private",
|
|
|
|
+ to = new List<string> { teacher.id },
|
|
|
|
+ label = $"remove_school",
|
|
|
|
+ body = new { location = _option.Location, biz = "remove", tmdid = tid, tmdname = tname, schoolcode = $"{school_code}", schoolname = $"{schname}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
|
+ };
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
- Notification notification = new Notification
|
|
|
|
- {
|
|
|
|
- hubName = "hita",
|
|
|
|
- type = "msg",
|
|
|
|
- from = $"ies5:{_option.Location}:private",
|
|
|
|
- to = new List<string> { teacher.id },
|
|
|
|
- label = $"remove_school",
|
|
|
|
- body = new { location = _option.Location, biz = "remove", tmdid = tid, tmdname = tname, schoolcode = $"{school_code}", schoolname = $"{schname}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
|
- expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
|
- };
|
|
|
|
- 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);
|
|
|
|
return Ok(new { });
|
|
return Ok(new { });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|