瀏覽代碼

优化BI学校基础信息相关的接口

Li 2 年之前
父節點
當前提交
fab332d496

+ 152 - 96
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -37,6 +37,8 @@ using DocumentFormat.OpenXml.Wordprocessing;
 using DocumentFormat.OpenXml.Bibliography;
 using HTEXLib;
 using TEAMModelOS.SDK.Models.Service.BI;
+using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
+using DocumentFormat.OpenXml.Vml.Office;
 
 namespace TEAMModelBI.Controllers.BISchool
 {
@@ -1035,6 +1037,11 @@ namespace TEAMModelBI.Controllers.BISchool
                 jsonElement.TryGetProperty("dist", out JsonElement dist);
                 jsonElement.TryGetProperty("address", out JsonElement address);
 
+
+                jsonElement.TryGetProperty("assist", out JsonElement assist);
+                List<IdInfo> idInfos = assist.ToObject<List<IdInfo>>();
+
+
                 //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
@@ -1079,6 +1086,9 @@ namespace TEAMModelBI.Controllers.BISchool
                     //修改学校
                     await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
 
+                    //创建学校信息中间件
+                    _ = _httpTrigger.RequestHttpTrigger(new { school = $"{tempShool}" }, _option.Location, "set-sc-birelation");
+
                     //修改学校教师关联的信息
                     string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
                     List<Teacher> teachers = new();
@@ -1098,110 +1108,156 @@ namespace TEAMModelBI.Controllers.BISchool
                         await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
                     }
 
-                    if (assistId.Count > 0)
+                    ////需要重大修改后保留
+                    if (idInfos.Count > 0)
                     {
-                        //修改学校顾问
-                        string sqlTxt = $"SELECT value(c) From c WHERE ARRAY_CONTAINS(c.roles,'assist',true)";
-                        List<SchoolTeacher> schoolTeachers = new();
-                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempShool.id}") }))
+                        BIRelation biRel = new();
+                        var respRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(tempShool.id,new PartitionKey("BIRel"));
+                        if (respRel.Status == 200)
                         {
-                            if (!assistId.Contains(item.id))
-                            {
-                                if (item.roles.Contains("assist"))
-                                {
-                                    item.roles.Remove("assist");
-                                    if (item.roles.Count > 0)
-                                    {
-                                        await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(item, item.id, new PartitionKey(item.code));
-                                    }
-                                    else
-                                    {
-                                        await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>(item.id, new PartitionKey(item.code));
-                                    }
-                                }
-                            }
+                            using var fileJson = await JsonDocument.ParseAsync(respRel.ContentStream);
+                            biRel = fileJson.ToObject<BIRelation>();
                         }
-
-                        foreach (var itemTeacher in assistId)
+                        else
+                            biRel.id = tempShool.id;
+
+                        string aName = null;
+                        if (!string.IsNullOrEmpty($"{tempShool.areaId}"))
+                            aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{tempShool.areaId}'", "Base-Area");
+
+                        biRel.name = tempShool.name;
+                        biRel.picture = tempShool.picture;
+                        biRel.region = tempShool.region;
+                        biRel.province = tempShool.province;
+                        biRel.city = tempShool.city;
+                        biRel.dist = tempShool.dist;
+                        biRel.address = tempShool.address;
+                        biRel.areaId = tempShool.areaId;
+                        biRel.size = tempShool.size;
+                        biRel.scale = tempShool.scale;
+                        biRel.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                        biRel.areaName = aName;
+                        foreach (var item in idInfos)
                         {
-                            Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{itemTeacher}", new PartitionKey("Base"));
-                            if (tempTeacher != null)
+                            var ser = biRel.assists.Find(f => f.Equals(item.id));
+                            if (string.IsNullOrEmpty(ser.id)) 
                             {
-                                var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{_schoolId}"));
-                                if (haveTeacher == null)
-                                {
-                                    Teacher.TeacherSchool teacherSchool = new()
-                                    {
-                                        schoolId = tempShool.id,
-                                        name = tempShool.name,
-                                        status = "join",
-                                        time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                        picture = tempShool.picture,
-                                        areaId = tempShool.areaId
-                                    };
-                                    tempTeacher.schools.Add(teacherSchool);
-                                    //给醍摩豆顾问添加学校
-                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, tempTeacher.id, new PartitionKey($"Base"));
-
-                                    ////不存在则在原来的基础上添加顾问角色
-                                    //SchoolTeacher addSchoolTeacher = new()
-                                    //{
-                                    //    id = itemTeacher,
-                                    //    code = $"Teacher-{tempShool.id}",
-                                    //    pk = "Teacher",
-                                    //    status = "join",
-                                    //    roles = new List<string>() { "assist" },
-                                    //    name = tempTeacher.name,
-                                    //    job = $"{tempShool.name}-顾问",
-                                    //    size = 0,
-                                    //    createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
-                                    //};
-
-                                    //var resScTch = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
-                                    //if(resScTch.)
-
-                                    ////添加学校学校顾问
-                                    //await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
-                                }
-
-                                //查询该教师是否存在该校
-                                SchoolTeacher schoolTeacher = null;
-                                var resScTch = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
-                                if (resScTch.Status == 200)
-                                {
-                                    using var tchJson = await JsonDocument.ParseAsync(resScTch.ContentStream);
-                                    schoolTeacher = tchJson.ToObject<SchoolTeacher>();
-                                }
-
-                                if (schoolTeacher != null)
-                                {
-                                    if (!schoolTeacher.roles.Contains("assist"))
-                                    {
-                                        schoolTeacher.roles.Add("assist");
-                                        //添加顾问权限
-                                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{tempShool.id}"));
-                                    }
-                                }
-                                else
-                                {
-                                    SchoolTeacher addSchoolTeacher = new()
-                                    {
-                                        id = itemTeacher,
-                                        code = $"Teacher-{tempShool.id}",
-                                        pk = "Teacher",
-                                        status = "join",
-                                        roles = new List<string>() { "assist" },
-                                        name = tempTeacher.name,
-                                        job = $"{tempShool.name}-顾问",
-                                        size = 0,
-                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
-                                    };
-                                    //添加学校顾问
-                                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
-                                }
+                                biRel.assists.Add(item);
                             }
                         }
+
+                        if (respRel.Status == 200)
+                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, biRel.id, new PartitionKey("BIRel"));
+                        else
+                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(biRel, new PartitionKey("BIRel"));
                     }
+
+                    ////需要重大修改后移除
+                    //if (assistId.Count > 0)
+                    //{
+                    //    //修改学校顾问
+                    //    string sqlTxt = $"SELECT value(c) From c WHERE ARRAY_CONTAINS(c.roles,'assist',true)";
+                    //    List<SchoolTeacher> schoolTeachers = new();
+                    //    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempShool.id}") }))
+                    //    {
+                    //        if (!assistId.Contains(item.id))
+                    //        {
+                    //            if (item.roles.Contains("assist"))
+                    //            {
+                    //                item.roles.Remove("assist");
+                    //                if (item.roles.Count > 0)
+                    //                {
+                    //                    await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(item, item.id, new PartitionKey(item.code));
+                    //                }
+                    //                else
+                    //                {
+                    //                    await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>(item.id, new PartitionKey(item.code));
+                    //                }
+                    //            }
+                    //        }
+                    //    }
+
+                    //    foreach (var itemTeacher in assistId)
+                    //    {
+                    //        Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{itemTeacher}", new PartitionKey("Base"));
+                    //        if (tempTeacher != null)
+                    //        {
+                    //            var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{_schoolId}"));
+                    //            if (haveTeacher == null)
+                    //            {
+                    //                Teacher.TeacherSchool teacherSchool = new()
+                    //                {
+                    //                    schoolId = tempShool.id,
+                    //                    name = tempShool.name,
+                    //                    status = "join",
+                    //                    time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                    //                    picture = tempShool.picture,
+                    //                    areaId = tempShool.areaId
+                    //                };
+                    //                tempTeacher.schools.Add(teacherSchool);
+                    //                //给醍摩豆顾问添加学校
+                    //                await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, tempTeacher.id, new PartitionKey($"Base"));
+
+                    //                ////不存在则在原来的基础上添加顾问角色
+                    //                //SchoolTeacher addSchoolTeacher = new()
+                    //                //{
+                    //                //    id = itemTeacher,
+                    //                //    code = $"Teacher-{tempShool.id}",
+                    //                //    pk = "Teacher",
+                    //                //    status = "join",
+                    //                //    roles = new List<string>() { "assist" },
+                    //                //    name = tempTeacher.name,
+                    //                //    job = $"{tempShool.name}-顾问",
+                    //                //    size = 0,
+                    //                //    createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+                    //                //};
+
+                    //                //var resScTch = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
+                    //                //if(resScTch.)
+
+                    //                ////添加学校学校顾问
+                    //                //await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
+                    //            }
+
+                    //            //查询该教师是否存在该校
+                    //            SchoolTeacher schoolTeacher = null;
+                    //            var resScTch = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
+                    //            if (resScTch.Status == 200)
+                    //            {
+                    //                using var tchJson = await JsonDocument.ParseAsync(resScTch.ContentStream);
+                    //                schoolTeacher = tchJson.ToObject<SchoolTeacher>();
+                    //            }
+
+                    //            if (schoolTeacher != null)
+                    //            {
+                    //                if (!schoolTeacher.roles.Contains("assist"))
+                    //                {
+                    //                    schoolTeacher.roles.Add("assist");
+                    //                    //添加顾问权限
+                    //                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{tempShool.id}"));
+                    //                }
+                    //            }
+                    //            else
+                    //            {
+                    //                SchoolTeacher addSchoolTeacher = new()
+                    //                {
+                    //                    id = itemTeacher,
+                    //                    code = $"Teacher-{tempShool.id}",
+                    //                    pk = "Teacher",
+                    //                    status = "join",
+                    //                    roles = new List<string>() { "assist" },
+                    //                    name = tempTeacher.name,
+                    //                    job = $"{tempShool.name}-顾问",
+                    //                    size = 0,
+                    //                    createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+                    //                };
+                    //                //添加学校顾问
+                    //                await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
+                    //            }
+                    //        }
+                    //    }
+                    //}
+                
                 }
 
                 //保存操作记录

+ 11 - 1
TEAMModelOS.FunctionV4/HttpTrigger/BIHttpTrigger.cs

@@ -18,6 +18,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.BI;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
+using TEAMModelOS.SDK.Models.Service.BI;
 using TEAMModelOS.SDK.Models.Service.BIStatsWay;
 
 namespace TEAMModelOS.FunctionV4.HttpTrigger
@@ -39,6 +40,11 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             _httpClient = httpClient;
         }
 
+        /// <summary>
+        /// 学校信息BI中间件更新
+        /// </summary>
+        /// <param name="req"></param>
+        /// <returns></returns>
         [Function("set-sc-birelation")]
         public async Task<HttpResponseData> upSchoolBIRelation([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestData req)
         {
@@ -69,8 +75,11 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
 
                 }
                 else
-                    bIRelation.id = school.name;
+                    bIRelation.id = school.id;
 
+                string aName = null;
+                if (!string.IsNullOrEmpty($"{school.areaId}"))
+                    aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{school.areaId}'", "Base-Area");
                 bIRelation.name = school.name;
                 bIRelation.picture = school.picture;
                 bIRelation.region = school.region;
@@ -82,6 +91,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
                 bIRelation.size = school.size;
                 bIRelation.scale = school.scale;
                 bIRelation.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                bIRelation.areaName = aName;
 
                 if (resBiRel.Status == 200)
                 {

+ 333 - 0
TEAMModelOS.SDK/Models/Service/BI/CosmosQueryHelper.cs

@@ -0,0 +1,333 @@
+using Azure.Cosmos;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Service.BI
+{
+    public class CosmosQueryHelper
+    {
+        /// <summary>
+        /// 查询学校教师角色列表
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="schoolId">学校Id</param>
+        /// <param name="roles">查询的角色</param>
+        /// <returns>返回学校角色列表</returns>
+        public static async Task<List<SchoolTeacherRoles>> FindSchoolRoles(CosmosClient cosmosClient, string schoolId, string roles)
+        {
+            List<SchoolTeacherRoles> strs = new();
+            try
+            {
+                string managerSql = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId, c.id, c.name FROM c WHERE ARRAY_CONTAINS(c.roles, '{roles}', true) AND c.pk = 'Teacher' AND c.status = 'join' AND c.code = 'Teacher-{schoolId}'";
+                await foreach (var item in cosmosClient.GetContainer("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())
+                    {
+                        SchoolTeacherRoles str = new()
+                        {
+                            tmdId = obj.GetProperty("id").GetString(),
+                            tmdName = obj.GetProperty("name").GetString()
+                        };
+
+                        strs.Add(str);
+                    }
+                }
+                return strs;
+            }
+            catch
+            {
+                return strs;
+            }
+        }
+
+        /// <summary>
+        /// 通过醍摩豆账户查询关联学校ID
+        /// </summary>
+        /// <param name="cosmosClient">cosmosDB连接</param>
+        /// <param name="tmdId">醍摩豆账户</param>
+        /// <returns>返回顾问相关的学校ID集合</returns>
+        public static async Task<List<string>> FindSchoolIds(CosmosClient cosmosClient, string tmdId, string roles = "assist", bool isMany = false)
+        {
+            List<string> schoolIds = new();
+            //string schoolSql = $"SELECT DISTINCT REPLACE(c.code,'Teacher-','') AS schoolId,c.code,c.roles,c.id,c.name From c where ARRAY_CONTAINS(c.roles,'assist',true) AND c.status = 'join' AND c.id='{tmdId}'";
+            //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: schoolSql, requestOptions: new QueryRequestOptions() { }))
+            //{
+            //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+            //    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+            //    {
+            //        schoolIds.Add(obj.GetProperty("schoolId").GetString());
+            //    }
+            //}
+
+            StringBuilder schoolSql = new($"SELECT value(REPLACE(c.code, 'Teacher-', '')) FROM c where c.pk='Teacher' and c.id='{tmdId}'");
+            if (isMany == true)
+                schoolSql.Append($" and (array_contains(c.roles,'assist',true) or array_contains(c.roles,'sales',true))");
+            else
+                schoolSql.Append($" and array_contains(c.roles,'{roles}',true)");
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: schoolSql.ToString(), requestOptions: new QueryRequestOptions() { }))
+            {
+                schoolIds.Add(item);
+            }
+
+            return schoolIds;
+        }
+
+        /// <summary>
+        /// 通过sql语句查询单列集合
+        /// </summary>
+        /// <param name="cosmosClient">连接字符</param>
+        /// <param name="container">容器名称</param>
+        /// <param name="sqlTxt">sql语句 带value</param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<List<string>> GetValueSingle(CosmosClient cosmosClient, string container, string sqlTxt, string code = null)
+        {
+            List<string> ids = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: !string.IsNullOrEmpty(code) ? new QueryRequestOptions() { PartitionKey = new PartitionKey(code) } : new QueryRequestOptions() { }))
+            {
+                ids.Add(item);
+            }
+
+            return ids;
+        }
+
+        /// <summary>
+        /// 通过sql语句查询单列集合
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="single"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public async Task<List<string>> GetStreamSingle(CosmosClient cosmosClient, string container, string sqlTxt, string single = "id", string code = null)
+        {
+            List<string> ids = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: !string.IsNullOrEmpty(code) ? new QueryRequestOptions() { PartitionKey = new PartitionKey(code) } : new QueryRequestOptions() { }))
+            {
+                using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                {
+                    ids.Add(obj.GetProperty(single).GetString());
+                }
+            }
+
+            return ids;
+        }
+
+        /// <summary>
+        /// 通过语句查询学校ID
+        /// </summary>
+        /// <param name="cosmosClient">cosmosDB连接</param>
+        /// <param name="sqlTxt">sql语句</param>
+        /// <param name="code">数据分区键</param>
+        /// <returns>返回学校ID的集合</returns>
+        public static async Task<List<string>> FindScIds(CosmosClient cosmosClient, string sqlTxt, string code)
+        {
+            List<string> schoolIds = new();
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            {
+                schoolIds.Add(item);
+            }
+
+            //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            //{
+            //    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+            //    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+            //    {
+            //        schoolIds.Add(obj.GetProperty("id").GetString());
+            //    }
+            //}
+
+            return schoolIds;
+        }
+
+        /// <summary>
+        /// 依据学校查询教师列表
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="schools">学校列表</param>
+        /// <param name="roles">不传默认教师角色</param>
+        /// <returns></returns>
+        public static async Task<List<string>> FindRolesId(CosmosClient cosmosClient, List<string> schools, string roles = null)
+        {
+            string rolesName = "teacher";
+            if (roles != null)
+            {
+                rolesName = roles;
+            }
+
+            List<string> teachers = new();
+            foreach (var school in schools)
+            {
+                string sqlTxt = $"select value(c.id) from c where ARRAY_CONTAINS(c.roles,'{rolesName}',true) and c.status = 'join'";
+                await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
+                {
+                    teachers.Add(itemTeac);
+                }
+                //string sqlTxt = $"select c.id from c where ARRAY_CONTAINS(c.roles,'{rolesName}',true) and c.status = 'join'";
+                //await foreach (var itemTeac in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() {PartitionKey =new PartitionKey($"Teacher-{school}") }))
+                //{
+                //    using var json = await JsonDocument.ParseAsync(itemTeac.ContentStream);
+                //    foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                //    {
+                //        teachers.Add(obj.GetProperty("id").GetString());
+                //    }
+                //}
+            }
+            return teachers;
+        }
+
+        /// <summary>
+        /// 单个容器数据统计
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="SqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetSqlValueCount(CosmosClient cosmosClient, string container, string SqlTxt, string code = null)
+        {
+            int totals = 0;
+            try
+            {
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+                {
+                    totals = item;
+                }
+            }
+            catch { }
+
+            return totals;
+        }
+
+        /// <summary>
+        /// 多个容器数据统计
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="SqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<int> GetSqlValueCount(CosmosClient cosmosClient, List<string> containers, string SqlTxt, string code = null)
+        {
+            int totals = 0;
+            foreach (var container in containers)
+            {
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<int>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                {
+                    totals += item;
+                }
+            }
+
+            return totals;
+        }
+
+        /// <summary>
+        /// 单个容器数据统计  double
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="SqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<double> GetSqlValueDoubleCounnt(CosmosClient cosmosClient, string container, string SqlTxt, string code = null)
+        {
+            double totals = 0;
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<double>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            {
+                totals = item;
+            }
+
+            return totals;
+        }
+
+        /// <summary>
+        /// 多个容器数据统计  double
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="container"></param>
+        /// <param name="SqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<double> GetSqlValueDoubleCounnt(CosmosClient cosmosClient, List<string> containers, string SqlTxt, string code = null)
+        {
+            double totals = 0;
+            foreach (var container in containers)
+            {
+                await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<double>(queryText: SqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                {
+                    totals += item;
+                }
+            }
+
+            return totals;
+        }
+
+        /// <summary>
+        /// 通过SQL 语句返回实体信息
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<List<T>> GetObject<T>(CosmosClient cosmosClient, List<string> containers, string sqlTxt, string code = null)
+        {
+            List<T> temps = new();
+            foreach (var container in containers)
+            {
+                await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator<T>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+                {
+                    temps.Add(items);
+                }
+            }
+            return temps;
+        }
+
+        /// <summary>
+        /// 通过SQL 语句返回实体信息
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<List<T>> GetObject<T>(CosmosClient cosmosClient, string containers, string sqlTxt, string code = null)
+        {
+            List<T> temps = new();
+            await foreach (var items in cosmosClient.GetContainer("TEAMModelOS", containers).GetItemQueryIterator<T>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            {
+                temps.Add(items);
+            }
+            return temps;
+        }
+
+        /// <summary>
+        /// 查询某个字段信息
+        /// </summary>
+        /// <param name="cosmosClient"></param>
+        /// <param name="containers"></param>
+        /// <param name="sqlTxt"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static async Task<string> GetStr(CosmosClient cosmosClient, string containers, string sqlTxt, string code = null)
+        {
+            string str = null;
+
+            await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", containers).GetItemQueryIterator<string>(queryText: sqlTxt, requestOptions: string.IsNullOrEmpty(code) ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
+            {
+                str = item;
+            }
+
+            return str;
+        }
+    }
+}