ProductWay.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Microsoft.Azure.Cosmos;
  2. using System.Collections.Generic;
  3. using System.Text.Json;
  4. using System.Threading.Tasks;
  5. using TEAMModelBI.Models;
  6. using TEAMModelOS.SDK.DI;
  7. using TEAMModelOS.SDK.Models;
  8. namespace TEAMModelBI.Tool.CosmosBank
  9. {
  10. public class ProductWay
  11. {
  12. /// <summary>
  13. /// 依据学校信息统计版本数量
  14. /// </summary>
  15. /// <param name="cosmosClient"></param>
  16. /// <param name="scIds"></param>
  17. /// <returns></returns>
  18. public async static Task<(int bCount, int sCount, int mCount)> GetVersionCount(CosmosClient cosmosClient, List<RecSchool> scIds)
  19. {
  20. int totals = 0;
  21. int basics = 0; //基础版数
  22. int standard = 0; //标准版数
  23. int major = 0; //专业版数
  24. foreach (var sc in scIds)
  25. {
  26. string sqlTxt = $"select array_length(c.service) as totals from c where c.id='{sc.id}'";
  27. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIteratorSql(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("ProductSum") }))
  28. {
  29. using var json = await JsonDocument.ParseAsync(item.Content);
  30. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
  31. {
  32. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  33. {
  34. totals += obj.GetProperty("totals").GetInt32();
  35. }
  36. }
  37. }
  38. if (totals > 0)
  39. major += 1;
  40. else if (sc.size >= 300 && sc.scale >= 500)
  41. standard += 1;
  42. else basics += 1;
  43. }
  44. return (basics, standard, major);
  45. }
  46. }
  47. }