BISchoolService.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Azure.Cosmos;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using TEAMModelOS.SDK.DI;
  8. using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
  9. namespace TEAMModelOS.SDK.Models.Service.BI
  10. {
  11. public static class BISchoolService
  12. {
  13. /// <summary>
  14. /// 更新版本信息
  15. /// </summary>
  16. /// <param name="cosmosClient"></param>
  17. /// <param name="server"></param>
  18. /// <param name="id"></param>
  19. /// <returns></returns>
  20. public static async Task UpSchoolEdition(CosmosClient cosmosClient, List<object> server, string id)
  21. {
  22. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
  23. int edition = 0;
  24. if (school.size <= 100 && school.scale == 0)
  25. edition = 1;
  26. else if (school.size >= 300 && school.scale >= 500 && server.Contains("YMPCVCIM"))
  27. edition = 2;
  28. else if (school.size >= 300 && school.scale >= 1000 && server.Contains("YMPCVCIM") && server.Count > 2)
  29. edition = 3;
  30. if (school.edition != null)
  31. {
  32. school.edition.current = edition;
  33. if (school.edition.record < edition)
  34. school.edition.record = edition;
  35. }
  36. else
  37. {
  38. school.edition.current = edition;
  39. school.edition.record = edition;
  40. }
  41. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
  42. BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
  43. biRel.edition = school.edition;
  44. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, id, new PartitionKey("BIRel"));
  45. }
  46. }
  47. }