1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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
- {
- /// <summary>
- /// 多个容器返回整数 使用
- /// </summary>
- /// <param name="cosmosClient"></param>
- /// <param name="containerId"></param>
- /// <param name="sqlTxt"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public static async Task<int> GetValueInt(CosmosClient cosmosClient, List<string> 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<int>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- totals += itemInt;
- }
- }
- return totals;
- }
- catch (Exception)
- {
- return totals;
- }
- }
- /// <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> 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<int>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- totals += itemInt;
- }
- return totals;
- }
- catch (Exception)
- {
- return totals;
- }
- }
- /// <summary>
- /// 返回字符集合
- /// </summary>
- /// <param name="cosmosClient"></param>
- /// <param name="containerId"></param>
- /// <param name="sqlTxt"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public static async Task<List<string>> GetListString(CosmosClient cosmosClient, string containerId, string sqlTxt, string code)
- {
- List<string> strList = new();
- await foreach (var itemInt in cosmosClient.GetContainer("TEAMModelOS", containerId).GetItemQueryIteratorSql<string>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- strList.Add(itemInt);
- }
- return strList;
- }
- }
- }
|