Explorar el Código

处理中间学校列表信息跟销售和顾问权限有关的接口。

Li hace 2 años
padre
commit
4e965dff18

+ 5 - 2
TEAMModelBI/Controllers/BINormal/AreaRelevantController.cs

@@ -36,8 +36,9 @@ namespace TEAMModelBI.Controllers.BINormal
         private readonly Option _option;
         private readonly IConfiguration _configuration;
         private readonly CoreAPIHttpService _coreAPIHttpService;
+        private readonly HttpTrigger _httpTrigger;
 
-        public AreaRelevantController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService)
+        public AreaRelevantController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, HttpTrigger httpTrigger)
         {
             _azureCosmos = azureCosmos;
             _azureStorage = azureStorage;
@@ -45,6 +46,7 @@ namespace TEAMModelBI.Controllers.BINormal
             _option = option?.Value;
             _configuration = configuration;
             _coreAPIHttpService = coreAPIHttpService;
+            _httpTrigger = httpTrigger;
         }
 
         /// <summary>
@@ -205,6 +207,8 @@ namespace TEAMModelBI.Controllers.BINormal
                 }
                 School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempSchool, tempSchool.id, new PartitionKey("Base"));
 
+                //创建/修改学校信息中间件
+                _ = _httpTrigger.RequestHttpTrigger(new { school = $"{school}" }, _option.Location, "set-sc-birelation");
                 //保存操作记录
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】已操作学校(ID:{schoolId})移除已区域(ID:{areaId})", _dingDing, httpContext: HttpContext);
                 return Ok(new { state = 200, school });
@@ -596,6 +600,5 @@ namespace TEAMModelBI.Controllers.BINormal
             public List<SchoolTeacherRoles> assists { get; set; } = new List<SchoolTeacherRoles>();
             public List<SchoolTeacherRoles> scAdmin { get; set; } = new List<SchoolTeacherRoles>();
         }
-
     }
 }

+ 2 - 4
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -1139,11 +1139,9 @@ namespace TEAMModelBI.Controllers.BISchool
                         biRel.areaName = aName;
                         foreach (var item in idInfos)
                         {
-                            var ser = biRel.assists.Find(f => f.Equals(item.id));
-                            if (string.IsNullOrEmpty(ser.id)) 
-                            {
+                            var tempAss = biRel.assists.Find(f => f.Equals(item.id));
+                            if (tempAss == null) 
                                 biRel.assists.Add(item);
-                            }
                         }
 
                         if (respRel.Status == 200)

+ 144 - 81
TEAMModelBI/Controllers/BITable/TableDingDingInfoController.cs

@@ -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

+ 27 - 3
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -693,15 +693,39 @@ namespace TEAMModelBI.Controllers.Census
         public async Task<IActionResult> GetScInfos(JsonElement jsonElement) 
         {
             var cosmosClient = _azureCosmos.GetCosmosClient();
-            List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
+            jsonElement.TryGetProperty("role", out JsonElement role);
+            jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
+            jsonElement.TryGetProperty("areaId", out JsonElement areaId);
+
+            StringBuilder sql = new($"select value(c.id) from c");
+
+            if (!string.IsNullOrEmpty($"{role}") && !string.IsNullOrEmpty($"{tmdId}") && string.IsNullOrEmpty($"{areaId}"))
+            {
+                switch ($"{role}")
+                {
+                    case "assist":
+                        sql.Append($" join a in c.assist where a.id='{tmdId}'");
+                        break;
+                    case "sales":
+                        sql.Append($" join a in c.sales where a.id='{tmdId}'");
+                        break;
+                }
+            }
+
+            if (!string.IsNullOrEmpty($"{areaId}") && !string.IsNullOrEmpty($"{role}")) 
+            {
+                sql.Append($" where c.areaId ='{areaId}'");
+            }
+
+            //List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
 
             List<BIRelation> scInfos = new();
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText:$"select value(c) from c",requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: sql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
             {
                 scInfos.Add(item);
             }
 
-            return Ok(new { state = RespondCode.Ok, allCnt = scId.Count, scInfos });
+            return Ok(new { state = RespondCode.Ok, allCnt = scInfos.Count, scInfos });
         }
 
         /// <summary>

+ 18 - 16
TEAMModelBI/Controllers/RepairApi/SchoolRepController.cs

@@ -111,7 +111,7 @@ namespace TEAMModelBI.Controllers.RepairApi
                 allSc.Add(item);
             }
 
-            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText:noPeriodScSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: noPeriodScSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
             {
                 allSc.Add(item);
             }
@@ -178,9 +178,9 @@ namespace TEAMModelBI.Controllers.RepairApi
                         if (subject.subjects.Count == 0)
                         {
                             subject.subjects = new List<Subject>() {
-                            new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
-                            new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
-                            new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
+                                new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
+                                new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
+                                new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
                             };
                         }
                     }
@@ -194,20 +194,24 @@ namespace TEAMModelBI.Controllers.RepairApi
                             id = Guid.NewGuid().ToString(),
                             name = scName,
                             campusId = campusId,
-                            semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
-                        new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },
+                            semesters = new List<Semester>() {
+                                new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
+                                new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() }
+                            },
                             subjects = new List<Subject>() {
-                        new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
-                        new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
-                        new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
-                        },
+                                new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
+                                new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
+                                new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
+                            },
                             grades = schoolConfig.grades,
                             analysis = new Analysis()
                             {
-                                type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
-                        new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[1].name },
-                        new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[2].name },
-                        new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[3].name } },
+                                type = new List<ExamSimple>() {
+                                    new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
+                                    new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[1].name },
+                                    new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[2].name },
+                                    new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[3].name }
+                                },
                                 income = schoolConfig.PresetExam[0].income,
                                 eugenics = schoolConfig.PresetExam[0].eugenics,
                                 touch = schoolConfig.PresetExam[0].touch
@@ -309,8 +313,6 @@ namespace TEAMModelBI.Controllers.RepairApi
             return Ok(new { state = RespondCode.Ok, school });
         }
 
-
-
         /// <summary>
         /// 学校信息中间件查询和修复接口
         /// </summary>

+ 169 - 120
TEAMModelBI/Tool/CosmosBank/SchoolWay.cs

@@ -8,6 +8,7 @@ using TEAMModelBI.Models;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
 
 namespace TEAMModelBI.Tool.CosmosBank
 {
@@ -45,142 +46,190 @@ namespace TEAMModelBI.Tool.CosmosBank
         /// <returns></returns>
         public async static Task<List<string>> SchoolAdviser(CosmosClient cosmosClient, DingDingUserInfo ddUserInfo,List<string> schoolIds ,string role,string busy) 
         {
-            Teacher teacher = null;
-            bool isReadTec = false;
-            bool isAddUpd = false;
             List<string> noSchool = new();
-            string joinStatus = "";
-            if (role.Equals("assist"))
-                joinStatus = "顾问";
-            if (role.Equals("sales"))
-                joinStatus = "销售";
-
-            var tecResponse = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(ddUserInfo.tmdId, new PartitionKey($"Base"));
-            if (tecResponse.Status == 200)
-            {
-                JsonDocument jsonDocument = JsonDocument.Parse(tecResponse.Content);
-                teacher = jsonDocument.RootElement.ToObject<Teacher>();
-            }
-            else 
-            {
-                teacher = new Teacher()
-                {
-                    id = ddUserInfo.tmdId,
-                    name = ddUserInfo.tmdName,
-                    picture = ddUserInfo.picture,
-                    size = 1,
-                    code = "Base",
-                    pk = "Base",
-                };
-                isAddUpd = true;
-            }
-            List<Task<ItemResponse<SchoolTeacher>>> addSchoolTeache = new();
-            List<Task<ItemResponse<SchoolTeacher>>> updSchoolTeache = new();
-
-            foreach (var schoolId in schoolIds)
+            foreach (var item in schoolIds)
             {
-                School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
-                var tempSc = teacher.schools.Find(x => x.schoolId == schoolId);
-                if (tempSc == null)
+                BIRelation bIRelation = new();
+                var resBiRel = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(item, new PartitionKey($"BIRel"));
+                if (resBiRel.Status == 200)
                 {
-                    teacher.schools.Add(new Teacher.TeacherSchool { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId });
-                    isReadTec = true;
+                    JsonDocument jsonD = JsonDocument.Parse(resBiRel.Content);
+                    bIRelation = jsonD.RootElement.ToObject<BIRelation>();
                 }
-                SchoolTeacher schoolTeacher = new();
-                var stResponse  = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(ddUserInfo.tmdId, new PartitionKey($"Teacher-{schoolId}"));
-                if (stResponse.Status == 200)
-                {
-                    JsonDocument tempJson = JsonDocument.Parse(stResponse.Content);
-                    schoolTeacher = tempJson.RootElement.ToObject<SchoolTeacher>();
 
-                    if ($"{busy}".Equals("add"))
-                    {
-                        if (!schoolTeacher.roles.Contains($"{role}"))
-                        {
-                            schoolTeacher.roles.Add($"{role}");
-                            addSchoolTeache.Add(cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolId}")));
-                        }
-                        else
-                            noSchool.Add(schoolId);
-                    }
-                    if ($"{busy}".Equals("del"))
-                    {
-                        if (schoolTeacher.roles.Contains($"{role}"))
-                        {
-                            schoolTeacher.roles.Remove($"{role}");
-                            teacher.schools.Remove(teacher.schools.Find(x => x.schoolId == schoolId));
-                            updSchoolTeache.Add(cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolId}")));
-                        }
-                        else
-                            noSchool.Add(schoolId);
-                    }
-                }
-                else 
-                {                
-                    schoolTeacher = new SchoolTeacher()
-                    {
-                        id = ddUserInfo.tmdId,
-                        name = ddUserInfo.tmdName,
-                        picture = ddUserInfo.picture,
-                        job = joinStatus,
-                        subjectIds = new List<string>(),
-                        roles = new List<string> { $"{role}" },
-                        permissions = new List<string>(),
-                        status = "join",
-                        code = $"Teacher-{schoolId}",
-                        pk = "Teacher",
-                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
-                    };
-
-                    addSchoolTeache.Add(cosmosClient.GetContainer("TEAMModelOS", "School").CreateItemAsync(schoolTeacher, new PartitionKey(schoolTeacher.code)));
-                }
-            }
-            if (isReadTec == true)
-            {
-                if (isAddUpd == true)
+                if (role.Equals("assist"))
                 {
-                    await cosmosClient.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey($"Base"));
-                }
-                else
-                {
-                    await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
-                }
-            }
-            if (updSchoolTeache.Count > 0)
-            {
-                if (updSchoolTeache.Count < 256)
-                {
-                    await Task.WhenAll(updSchoolTeache);
-                }
-                else
-                {
-                    int pages = (updSchoolTeache.Count + 255) / 256;
-                    for (int i = 0; i < pages; i++)
+                    switch ($"{busy}")
                     {
-                        List<Task<ItemResponse<SchoolTeacher>>> tempAbility = updSchoolTeache.Skip((i) * 256).Take(256).ToList();
-                        await Task.WhenAll(tempAbility);
+                        case "add":
+                            var addAss = bIRelation.assists.Find(f => f.Equals(ddUserInfo.tmdId));
+                            if (addAss == null)
+                                bIRelation.assists.Add(new IdInfo() { id = ddUserInfo.tmdId, name = ddUserInfo.tmdName, picture = ddUserInfo.picture });
+                            break;
+                        case "del":
+                            var delAss = bIRelation.assists.Find(f => f.Equals(ddUserInfo.tmdId));
+                            if (delAss != null)
+                                bIRelation.assists.Remove(new IdInfo() { id = ddUserInfo.tmdId, name = ddUserInfo.tmdName, picture = ddUserInfo.picture });
+                            break;
                     }
                 }
-            }
-
-            if (addSchoolTeache.Count > 0)
-            {
-                if (addSchoolTeache.Count < 256)
-                {
-                    await Task.WhenAll(addSchoolTeache);
-                }
-                else
+                if (role.Equals("sales"))
                 {
-                    int pages = (addSchoolTeache.Count + 255) / 256;
-                    for (int i = 0; i < pages; i++)
+                    switch ($"{busy}")
                     {
-                        List<Task<ItemResponse<SchoolTeacher>>> tempAbility = addSchoolTeache.Skip((i) * 256).Take(256).ToList();
-                        await Task.WhenAll(tempAbility);
+                        case "add":
+                            var tempSa = bIRelation.sales.Find(f => f.Equals(ddUserInfo.tmdId));
+                        if (tempSa == null)
+                            bIRelation.sales.Add(new IdInfo() { id = ddUserInfo.tmdId, name = ddUserInfo.tmdName, picture = ddUserInfo.picture });
+                            break;
+                        case "del":
+                            var delSa = bIRelation.sales.Find(f => f.Equals(ddUserInfo.tmdId));
+                            if (delSa != null)
+                                bIRelation.sales.Remove(new IdInfo() { id = ddUserInfo.tmdId, name = ddUserInfo.tmdName, picture = ddUserInfo.picture });
+                            break;
                     }
                 }
+                bIRelation.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<BIRelation>(bIRelation, bIRelation.id, new PartitionKey("BIRel"));
             }
 
             return noSchool; 
+
+            //List<string> noSchool = new();
+            //Teacher teacher = null;
+            //bool isReadTec = false;
+            //bool isAddUpd = false;
+            //string joinStatus = "";
+            //if (role.Equals("assist"))
+            //    joinStatus = "顾问";
+            //if (role.Equals("sales"))
+            //    joinStatus = "销售";
+            //var tecResponse = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(ddUserInfo.tmdId, new PartitionKey($"Base"));
+            //if (tecResponse.Status == 200)
+            //{
+            //    JsonDocument jsonDocument = JsonDocument.Parse(tecResponse.Content);
+            //    teacher = jsonDocument.RootElement.ToObject<Teacher>();
+            //}
+            //else 
+            //{
+            //    teacher = new Teacher()
+            //    {
+            //        id = ddUserInfo.tmdId,
+            //        name = ddUserInfo.tmdName,
+            //        picture = ddUserInfo.picture,
+            //        size = 1,
+            //        code = "Base",
+            //        pk = "Base",
+            //    };
+            //    isAddUpd = true;
+            //}
+            //List<Task<ItemResponse<SchoolTeacher>>> addSchoolTeache = new();
+            //List<Task<ItemResponse<SchoolTeacher>>> updSchoolTeache = new();
+
+            //foreach (var schoolId in schoolIds)
+            //{
+            //    School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
+            //    var tempSc = teacher.schools.Find(x => x.schoolId == schoolId);
+            //    if (tempSc == null)
+            //    {
+            //        teacher.schools.Add(new Teacher.TeacherSchool { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId });
+            //        isReadTec = true;
+            //    }
+            //    SchoolTeacher schoolTeacher = new();
+            //    var stResponse  = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(ddUserInfo.tmdId, new PartitionKey($"Teacher-{schoolId}"));
+            //    if (stResponse.Status == 200)
+            //    {
+            //        JsonDocument tempJson = JsonDocument.Parse(stResponse.Content);
+            //        schoolTeacher = tempJson.RootElement.ToObject<SchoolTeacher>();
+
+            //        if ($"{busy}".Equals("add"))
+            //        {
+            //            if (!schoolTeacher.roles.Contains($"{role}"))
+            //            {
+            //                schoolTeacher.roles.Add($"{role}");
+            //                addSchoolTeache.Add(cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolId}")));
+            //            }
+            //            else
+            //                noSchool.Add(schoolId);
+            //        }
+            //        if ($"{busy}".Equals("del"))
+            //        {
+            //            if (schoolTeacher.roles.Contains($"{role}"))
+            //            {
+            //                schoolTeacher.roles.Remove($"{role}");
+            //                teacher.schools.Remove(teacher.schools.Find(x => x.schoolId == schoolId));
+            //                updSchoolTeache.Add(cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolId}")));
+            //            }
+            //            else
+            //                noSchool.Add(schoolId);
+            //        }
+            //    }
+            //    else 
+            //    {                
+            //        schoolTeacher = new SchoolTeacher()
+            //        {
+            //            id = ddUserInfo.tmdId,
+            //            name = ddUserInfo.tmdName,
+            //            picture = ddUserInfo.picture,
+            //            job = joinStatus,
+            //            subjectIds = new List<string>(),
+            //            roles = new List<string> { $"{role}" },
+            //            permissions = new List<string>(),
+            //            status = "join",
+            //            code = $"Teacher-{schoolId}",
+            //            pk = "Teacher",
+            //            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+            //        };
+
+            //        addSchoolTeache.Add(cosmosClient.GetContainer("TEAMModelOS", "School").CreateItemAsync(schoolTeacher, new PartitionKey(schoolTeacher.code)));
+            //    }
+            //}
+            //if (isReadTec == true)
+            //{
+            //    if (isAddUpd == true)
+            //    {
+            //        await cosmosClient.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey($"Base"));
+            //    }
+            //    else
+            //    {
+            //        await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+            //    }
+            //}
+            //if (updSchoolTeache.Count > 0)
+            //{
+            //    if (updSchoolTeache.Count < 256)
+            //    {
+            //        await Task.WhenAll(updSchoolTeache);
+            //    }
+            //    else
+            //    {
+            //        int pages = (updSchoolTeache.Count + 255) / 256;
+            //        for (int i = 0; i < pages; i++)
+            //        {
+            //            List<Task<ItemResponse<SchoolTeacher>>> tempAbility = updSchoolTeache.Skip((i) * 256).Take(256).ToList();
+            //            await Task.WhenAll(tempAbility);
+            //        }
+            //    }
+            //}
+
+            //if (addSchoolTeache.Count > 0)
+            //{
+            //    if (addSchoolTeache.Count < 256)
+            //    {
+            //        await Task.WhenAll(addSchoolTeache);
+            //    }
+            //    else
+            //    {
+            //        int pages = (addSchoolTeache.Count + 255) / 256;
+            //        for (int i = 0; i < pages; i++)
+            //        {
+            //            List<Task<ItemResponse<SchoolTeacher>>> tempAbility = addSchoolTeache.Skip((i) * 256).Take(256).ToList();
+            //            await Task.WhenAll(tempAbility);
+            //        }
+            //    }
+            //}
+
+            //return noSchool; 
         }
 
     }

+ 5 - 5
TEAMModelOS.SDK/Models/Cosmos/BI/BISchool/BIRelation.cs

@@ -66,23 +66,23 @@ namespace TEAMModelOS.SDK.Models.Cosmos.BI.BISchool
         /// <summary>
         /// 学校顾问信息
         /// </summary>
-        public List<IdInfo> assists { get; set; }
+        public List<IdInfo> assists { get; set; } = new List<IdInfo>();
         /// <summary>
         /// 学校销售
         /// </summary>
-        public List<IdInfo> sales { get; set; }
+        public List<IdInfo> sales { get; set; } = new List<IdInfo>();
         /// <summary>
         /// 学校软体id
         /// </summary>
-        public List<string> serial { get; set; }
+        public List<string> serial { get; set; } = new List<string>();
         /// <summary>
         /// 学校服务id
         /// </summary>
-        public List<string> service { get; set; }
+        public List<string> service { get; set; } = new List<string>();
         /// <summary>
         /// 学校硬体
         /// </summary>
-        public List<string> hard { get; set; }
+        public List<string> hard { get; set; } = new List<string>();
         /// <summary>
         /// 本条数据更新时间
         /// </summary>

+ 24 - 24
TEAMModelOS/Controllers/School/SchoolController.cs

@@ -1,36 +1,32 @@
+using Azure.Cosmos;
+using HTEXLib.COMM.Helpers;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Options;
+using Newtonsoft.Json;
+using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
+using System.Dynamic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Net.Http.Json;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
-using System.Text.Json;
-using TEAMModelOS.SDK.Models;
-using TEAMModelOS.SDK.Extension;
-using Azure.Cosmos;
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.Options;
-using System.IO;
-using System.Dynamic;
-using System.Net.Http;
-using System.Net;
-using Newtonsoft.Json;
-using System.Linq;
-using StackExchange.Redis;
-using Microsoft.Extensions.Configuration;
-using TEAMModelOS.Filter;
-using Microsoft.AspNetCore.Authorization;
-using System.Net.Http.Headers;
-using System.Net.Http.Json;
-using HTEXLib.COMM.Helpers;
-using System.IdentityModel.Tokens.Jwt;
 using TEAMModelOS.SDK.DI.CoreAPI;
-using Microsoft.AspNetCore.Hosting;
-using DocumentFormat.OpenXml.Office2010.Excel;
-using static TEAMModelOS.SDK.SchoolService;
-using System.Xml;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
 
 namespace TEAMModelOS.Controllers
 {
@@ -190,6 +186,10 @@ namespace TEAMModelOS.Controllers
                     school.code = "Base";
                     schoolInfo = await schoolContainer.CreateItemAsync(school, new PartitionKey($"Base"));
                 }
+
+                //创建/修改学校信息中间件
+                _ = _httpTrigger.RequestHttpTrigger(new { school = $"{school}" }, _option.Location, "set-sc-birelation");
+
                 return Ok(new { schoolInfo });
             }
             catch (Exception ex)