using Microsoft.Azure.Cosmos;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TEAMModelOS.SDK.DI;
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).GetItemQueryIteratorSql(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).GetItemQueryIteratorSql(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).GetItemQueryIteratorSql(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
{
strList.Add(itemInt);
}
return strList;
}
}
}