|
@@ -31,6 +31,7 @@ using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Context.Constant;
|
|
|
using TEAMModelOS.SDK.Models.Dtos;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BITable
|
|
|
{
|
|
@@ -393,8 +394,9 @@ namespace TEAMModelBI.Controllers.BITable
|
|
|
|
|
|
var tempUser = await table.FindListByDict<DingDingUserInfo>(dic);
|
|
|
List<string> oldRoles = new();
|
|
|
+ List<Task<ItemResponse<BIRelation>>> upBIRel = new();
|
|
|
|
|
|
- List<Task<ItemResponse<SchoolTeacher>>> upScTch = new();
|
|
|
+ //List<Task<ItemResponse<SchoolTeacher>>> upScTch = new();
|
|
|
|
|
|
foreach (var item in tempUser)
|
|
|
{
|
|
@@ -414,59 +416,83 @@ namespace TEAMModelBI.Controllers.BITable
|
|
|
{
|
|
|
if(itemR.Equals("assist"))
|
|
|
{
|
|
|
- string sql = $"select value(c) from c where c.pk='Teacher' and c.id='{item.tmdId}'";
|
|
|
- await foreach (var scTch in cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions() { }))
|
|
|
- {
|
|
|
- if (scTch.roles.Contains("sales"))
|
|
|
- {
|
|
|
+ string tempSql = $"select value(c) from c join a in c.sales where a.id='{itemR}'";
|
|
|
|
|
|
- //int index = scTch.roles.FindIndex(fi => fi.Equals("sales"));
|
|
|
- //scTch.roles[index]= "assist";
|
|
|
- //scTch.job = "顾问";
|
|
|
- //upScTch.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTch, scTch.id, new PartitionKey($"{scTch.code}")));
|
|
|
-
|
|
|
- int index = scTch.roles.FindIndex(fi => fi.Equals("sales"));
|
|
|
- if (index >= 0)
|
|
|
- {
|
|
|
- scTch.roles[index] = "assist";
|
|
|
- scTch.job = "顾问";
|
|
|
+ await foreach (var itemRel in cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: tempSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
|
|
|
+ {
|
|
|
+ var tempRel = itemRel.sales.Find(f => f.id.Equals(itemR));
|
|
|
+ itemRel.sales.Remove(tempRel);
|
|
|
+ itemRel.assists.Add(tempRel);
|
|
|
+ itemRel.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ upBIRel.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(itemRel, itemRel.id, new PartitionKey("BIRel")));
|
|
|
+ }
|
|
|
|
|
|
- upScTch.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTch, scTch.id, new PartitionKey($"{scTch.code}")));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //string sql = $"select value(c) from c where c.pk='Teacher' and c.id='{item.tmdId}'";
|
|
|
+ //await foreach (var scTch in cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ //{
|
|
|
+ // if (scTch.roles.Contains("sales"))
|
|
|
+ // {
|
|
|
+
|
|
|
+ // //int index = scTch.roles.FindIndex(fi => fi.Equals("sales"));
|
|
|
+ // //scTch.roles[index]= "assist";
|
|
|
+ // //scTch.job = "顾问";
|
|
|
+ // //upScTch.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTch, scTch.id, new PartitionKey($"{scTch.code}")));
|
|
|
+
|
|
|
+ // int index = scTch.roles.FindIndex(fi => fi.Equals("sales"));
|
|
|
+ // if (index >= 0)
|
|
|
+ // {
|
|
|
+ // scTch.roles[index] = "assist";
|
|
|
+ // scTch.job = "顾问";
|
|
|
+
|
|
|
+ // upScTch.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTch, scTch.id, new PartitionKey($"{scTch.code}")));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|
|
|
if (itemR.Equals("sales"))
|
|
|
{
|
|
|
- string sql = $"select value(c) from c where c.pk='Teacher' and c.id='{item.tmdId}'";
|
|
|
- await foreach (var scTch in cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions() { }))
|
|
|
+
|
|
|
+
|
|
|
+ string tempSql = $"select value(c) from c join a in c.assists where a.id='{itemR}'";
|
|
|
+
|
|
|
+ await foreach (var itemRel in cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: tempSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
|
|
|
{
|
|
|
- if (scTch.roles.Contains("assist"))
|
|
|
- {
|
|
|
- int index = scTch.roles.FindIndex(fi => fi.Equals("assist"));
|
|
|
- if (index >= 0)
|
|
|
- {
|
|
|
- scTch.roles[index] = "sales";
|
|
|
- scTch.job = "销售";
|
|
|
- upScTch.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTch, scTch.id, new PartitionKey($"{scTch.code}")));
|
|
|
- }
|
|
|
- }
|
|
|
+ var tempRel = itemRel.sales.Find(f => f.id.Equals(itemR));
|
|
|
+ itemRel.assists.Remove(tempRel);
|
|
|
+ itemRel.sales.Add(tempRel);
|
|
|
+ itemRel.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ upBIRel.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(itemRel, itemRel.id, new PartitionKey("BIRel")));
|
|
|
}
|
|
|
+
|
|
|
+ //string sql = $"select value(c) from c where c.pk='Teacher' and c.id='{item.tmdId}'";
|
|
|
+ //await foreach (var scTch in cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ //{
|
|
|
+ // if (scTch.roles.Contains("assist"))
|
|
|
+ // {
|
|
|
+ // int index = scTch.roles.FindIndex(fi => fi.Equals("assist"));
|
|
|
+ // if (index >= 0)
|
|
|
+ // {
|
|
|
+ // scTch.roles[index] = "sales";
|
|
|
+ // scTch.job = "销售";
|
|
|
+ // upScTch.Add(cosmosCliet.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTch, scTch.id, new PartitionKey($"{scTch.code}")));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (upScTch.Count < 256)
|
|
|
+ if (upBIRel.Count < 256)
|
|
|
{
|
|
|
- await Task.WhenAll(upScTch);
|
|
|
+ await Task.WhenAll(upBIRel);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- int pages = (upScTch.Count + 255) / 256;
|
|
|
+ int pages = (upBIRel.Count + 255) / 256;
|
|
|
for (int i = 0; i < pages; i++)
|
|
|
{
|
|
|
- List<Task<ItemResponse<SchoolTeacher>>> temScTch = upScTch.Skip((i) * 256).Take(256).ToList();
|
|
|
- await Task.WhenAll(temScTch);
|
|
|
+ List<Task<ItemResponse<BIRelation>>> tempRel = upBIRel.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempRel);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1393,6 +1419,7 @@ namespace TEAMModelBI.Controllers.BITable
|
|
|
var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partKey)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("rowKey", out JsonElement rowKey)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("role", out JsonElement role)) return BadRequest();
|
|
|
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
var tableClient = _azureStorage.GetCloudTableClient();
|
|
@@ -1451,62 +1478,98 @@ namespace TEAMModelBI.Controllers.BITable
|
|
|
createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
};
|
|
|
}
|
|
|
- List<Task<ItemResponse<SchoolTeacher>>> schoolTeachers = new();
|
|
|
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>($"select value(c) from c where c.pk='Teacher' and c.id='{oldTmdId}'"))
|
|
|
- {
|
|
|
- item.id = coreUser.id;
|
|
|
- var resp = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{coreUser.id}", new PartitionKey($"{item.code}"));
|
|
|
- if (resp.Status == 200)
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(resp.ContentStream);
|
|
|
- SchoolTeacher scTeacher = json.ToObject<SchoolTeacher>();
|
|
|
- if (scTeacher.roles.Contains("sales"))
|
|
|
- scTeacher.roles.Remove("sales");
|
|
|
- if (scTeacher.roles.Contains("assist"))
|
|
|
- scTeacher.roles.Remove("assist");
|
|
|
- string scId = scTeacher.code.Substring(scTeacher.code.IndexOf("-") + 1);
|
|
|
-
|
|
|
- Teacher.TeacherSchool isExitId = null;
|
|
|
- isExitId = teacher.schools.Find(s => s.schoolId.Equals(scId));
|
|
|
- if (isExitId == null)
|
|
|
- {
|
|
|
- ScEasyInfo school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ScEasyInfo>(scId, new PartitionKey("Base"));
|
|
|
- msg.Append($"{school.name}[{school.id}],");
|
|
|
- teacher.schools.Add(new Teacher.TeacherSchool() { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId });
|
|
|
- }
|
|
|
|
|
|
- scTeacher.roles.Add(reole);
|
|
|
- schoolTeachers.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTeacher, scTeacher.id, new PartitionKey($"{scTeacher.code}")));
|
|
|
- }
|
|
|
- else
|
|
|
+ List<Task<ItemResponse<BIRelation>>> scRole = new();
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: $"select value(c) from c join a in c.assists join s in c.sales where c.code='BIRel' and s.id='{oldTmdId}' or a.id='{oldTmdId}'", requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
|
|
|
+ {
|
|
|
+ var tempAss = item.assists.Find(f => f.id.Equals($"{oldTmdId}"));
|
|
|
+ if (tempAss != null)
|
|
|
+ item.assists.Remove(tempAss);
|
|
|
+ var tempSa = item.sales.Find(f => f.id.Equals($"{oldTmdId}"));
|
|
|
+ if (tempSa != null)
|
|
|
+ item.sales.Remove(tempAss);
|
|
|
+
|
|
|
+ switch ($"{role}")
|
|
|
{
|
|
|
- item.name = coreUser.name;
|
|
|
- string scId = item.code.Substring(item.code.IndexOf("-") + 1);
|
|
|
- Teacher.TeacherSchool isExitId = null;
|
|
|
- isExitId = teacher.schools.Find(s => s.schoolId.Equals(scId));
|
|
|
- if (isExitId == null)
|
|
|
- {
|
|
|
- ScEasyInfo school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ScEasyInfo>(scId, new PartitionKey("Base"));
|
|
|
- msg.Append($"{school.name}[{school.id}],");
|
|
|
- teacher.schools.Add(new Teacher.TeacherSchool() { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId });
|
|
|
- }
|
|
|
-
|
|
|
- schoolTeachers.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(item, new PartitionKey($"{item.code}")));
|
|
|
+ case "assist":
|
|
|
+ item.assists.Add(new IdInfo() { id = coreUser.id, name = coreUser.name, picture = coreUser.picture });
|
|
|
+ break;
|
|
|
+ case "sales":
|
|
|
+ item.sales.Add(new IdInfo() { id = coreUser.id, name = coreUser.name, picture = coreUser.picture });
|
|
|
+ break;
|
|
|
}
|
|
|
+ item.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ scRole.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(item, item.id, new PartitionKey("BIRel")));
|
|
|
}
|
|
|
|
|
|
- if (schoolTeachers.Count < 256)
|
|
|
- await Task.WhenAll(schoolTeachers);
|
|
|
+ if (scRole.Count < 256)
|
|
|
+ await Task.WhenAll(scRole);
|
|
|
else
|
|
|
{
|
|
|
- int pages = (schoolTeachers.Count + 255) / 256;
|
|
|
+ int pages = (scRole.Count + 255) / 256;
|
|
|
for (int i = 0; i < pages; i++)
|
|
|
{
|
|
|
- List<Task<ItemResponse<SchoolTeacher>>> tempScTeachers = schoolTeachers.Skip((i) * 256).Take(256).ToList();
|
|
|
- await Task.WhenAll(tempScTeachers);
|
|
|
+ List<Task<ItemResponse<BIRelation>>> tempScRole = scRole.Skip((i) * 256).Take(256).ToList();
|
|
|
+ await Task.WhenAll(tempScRole);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //List<Task<ItemResponse<SchoolTeacher>>> schoolTeachers = new();
|
|
|
+ //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>($"select value(c) from c where c.pk='Teacher' and c.id='{oldTmdId}'"))
|
|
|
+ //{
|
|
|
+ // item.id = coreUser.id;
|
|
|
+ // var resp = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{coreUser.id}", new PartitionKey($"{item.code}"));
|
|
|
+ // if (resp.Status == 200)
|
|
|
+ // {
|
|
|
+ // using var json = await JsonDocument.ParseAsync(resp.ContentStream);
|
|
|
+ // SchoolTeacher scTeacher = json.ToObject<SchoolTeacher>();
|
|
|
+ // if (scTeacher.roles.Contains("sales"))
|
|
|
+ // scTeacher.roles.Remove("sales");
|
|
|
+ // if (scTeacher.roles.Contains("assist"))
|
|
|
+ // scTeacher.roles.Remove("assist");
|
|
|
+ // string scId = scTeacher.code.Substring(scTeacher.code.IndexOf("-") + 1);
|
|
|
+
|
|
|
+ // Teacher.TeacherSchool isExitId = null;
|
|
|
+ // isExitId = teacher.schools.Find(s => s.schoolId.Equals(scId));
|
|
|
+ // if (isExitId == null)
|
|
|
+ // {
|
|
|
+ // ScEasyInfo school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ScEasyInfo>(scId, new PartitionKey("Base"));
|
|
|
+ // msg.Append($"{school.name}[{school.id}],");
|
|
|
+ // teacher.schools.Add(new Teacher.TeacherSchool() { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // scTeacher.roles.Add(reole);
|
|
|
+ // schoolTeachers.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(scTeacher, scTeacher.id, new PartitionKey($"{scTeacher.code}")));
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // item.name = coreUser.name;
|
|
|
+ // string scId = item.code.Substring(item.code.IndexOf("-") + 1);
|
|
|
+ // Teacher.TeacherSchool isExitId = null;
|
|
|
+ // isExitId = teacher.schools.Find(s => s.schoolId.Equals(scId));
|
|
|
+ // if (isExitId == null)
|
|
|
+ // {
|
|
|
+ // ScEasyInfo school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ScEasyInfo>(scId, new PartitionKey("Base"));
|
|
|
+ // msg.Append($"{school.name}[{school.id}],");
|
|
|
+ // teacher.schools.Add(new Teacher.TeacherSchool() { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // schoolTeachers.Add(cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(item, new PartitionKey($"{item.code}")));
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (schoolTeachers.Count < 256)
|
|
|
+ // await Task.WhenAll(schoolTeachers);
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // int pages = (schoolTeachers.Count + 255) / 256;
|
|
|
+ // for (int i = 0; i < pages; i++)
|
|
|
+ // {
|
|
|
+ // List<Task<ItemResponse<SchoolTeacher>>> tempScTeachers = schoolTeachers.Skip((i) * 256).Take(256).ToList();
|
|
|
+ // await Task.WhenAll(tempScTeachers);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
if (respone.Status == 200)
|
|
|
await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
else
|