using Azure.Cosmos; using DocumentFormat.OpenXml.Bibliography; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TEAMModelOS.SDK.Models.Service.BI { public class JointlySingleQuery { /// /// 多个容器返回整数 使用 /// /// /// /// /// /// public static async Task GetValueInt(CosmosClient cosmosClient, List containerId, string code, string sqlTxt = null) { int totals = 0; try { string sql = $"select value(count(c.id)) from c"; if (!string.IsNullOrEmpty(sqlTxt)) { sql = sqlTxt; } foreach (string conId in containerId) { await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", conId).GetItemQueryIterator(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") })) { totals += itemInt; } } return totals; } catch (Exception) { return totals; } } /// /// 单个容器返回整数 统计使用 /// /// /// /// /// /// public static async Task GetValueInt(CosmosClient cosmosClient, string container, string code, string sqlTxt = null) { int totals = 0; try { string sql = $"select value(count(c.id)) from c"; if (!string.IsNullOrEmpty(sqlTxt)) { sql = sqlTxt; } await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", container).GetItemQueryIterator(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") })) { totals += itemInt; } return totals; } catch (Exception) { return totals; } } /// /// 返回字符集合 /// /// /// /// /// /// public static async Task> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code) { List strList = new(); await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", containerId).GetItemQueryIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") })) { strList.Add(itemInt); } return strList; } } }