BISchoolService.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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;
  9. using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
  10. namespace TEAMModelOS.SDK.Models.Service.BI
  11. {
  12. public static class BISchoolService
  13. {
  14. /// <summary>
  15. /// 更新版本信息
  16. /// </summary>
  17. /// <param name="cosmosClient"></param>
  18. /// <param name="server"></param>
  19. /// <param name="id"></param>
  20. /// <returns></returns>
  21. public static async Task UpSchoolEdition(CosmosClient cosmosClient, DingDing _dingDing, List<string> server, string id)
  22. {
  23. try
  24. {
  25. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
  26. int edition = 0;
  27. if (school.size <= 100 && school.scale == 0)
  28. {
  29. edition = 1;
  30. }
  31. else if (school.size >= 300 && school.scale >= 500 && server.Contains("YMPCVCIM"))
  32. {
  33. edition = 2;
  34. }
  35. else if (school.size >= 300 && school.scale >= 1000 && server.Contains("YMPCVCIM") && server.Count > 2)
  36. {
  37. edition = 3;
  38. }
  39. if (edition == 0)
  40. {
  41. edition = 1;
  42. }
  43. if (school.edition != null)
  44. {
  45. school.edition.current = edition;
  46. if (school.edition.record < edition)
  47. {
  48. school.edition.record = edition;
  49. }
  50. }
  51. else
  52. {
  53. Edition tempEdition = new()
  54. {
  55. current = edition,
  56. record = edition
  57. };
  58. school.edition = tempEdition;
  59. }
  60. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
  61. BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
  62. biRel.edition = school.edition;
  63. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, id, new PartitionKey("BIRel"));
  64. }
  65. catch (Exception ex)
  66. {
  67. _ = _dingDing.SendBotMsg($"BI, UpSchoolEdition() \n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
  68. }
  69. }
  70. }
  71. }