1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using Microsoft.Azure.Cosmos;
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelBI.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Models;
- namespace TEAMModelBI.Tool.CosmosBank
- {
- public class ProductWay
- {
- /// <summary>
- /// 依据学校信息统计版本数量
- /// </summary>
- /// <param name="cosmosClient"></param>
- /// <param name="scIds"></param>
- /// <returns></returns>
- public async static Task<(int bCount, int sCount, int mCount)> GetVersionCount(CosmosClient cosmosClient, List<RecSchool> scIds)
- {
- int totals = 0;
- int basics = 0; //基础版数
- int standard = 0; //标准版数
- int major = 0; //专业版数
- foreach (var sc in scIds)
- {
- string sqlTxt = $"select array_length(c.service) as totals from c where c.id='{sc.id}'";
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIteratorSql(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
- {
- using var json = await JsonDocument.ParseAsync(item.Content);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- totals += obj.GetProperty("totals").GetInt32();
- }
- }
- }
- if (totals > 0)
- major += 1;
- else if (sc.size >= 300 && sc.scale >= 500)
- standard += 1;
- else basics += 1;
- }
- return (basics, standard, major);
- }
- }
- }
|