BISchoolService.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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> services, string id)
  22. {
  23. try
  24. {
  25. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
  26. school.edition = calSchoolEdition(school, services);
  27. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
  28. BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
  29. biRel.edition = school.edition;
  30. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, id, new PartitionKey("BIRel"));
  31. }
  32. catch (Exception ex)
  33. {
  34. _ = _dingDing.SendBotMsg($"BI,{Environment.GetEnvironmentVariable("Option:Location")},UpSchoolEdition() 服务列表:{services},学校id:{id}\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
  35. }
  36. }
  37. /// <summary>
  38. /// 計算學校版本公式
  39. /// </summary>
  40. public static Edition calSchoolEdition(School school, List<string> services)
  41. {
  42. int edition = 0;
  43. if (school.size <= 100 && school.scale == 0)
  44. {
  45. edition = 1;
  46. }
  47. else if (school.size >= 300 && school.scale >= 500 && school.scale < 100 && services.Contains("YMPCVCIM"))
  48. {
  49. edition = 2;
  50. }
  51. else if (school.size >= 300 && school.scale >= 1000 && services.Contains("YMPCVCIM") && services.Count > 2)
  52. {
  53. edition = 3;
  54. }
  55. if (edition == 0)
  56. {
  57. edition = 1;
  58. }
  59. if (school.edition != null)
  60. {
  61. school.edition.current = edition;
  62. if (school.edition.record < edition)
  63. {
  64. school.edition.record = edition;
  65. }
  66. }
  67. else
  68. {
  69. Edition tempEdition = new()
  70. {
  71. current = edition,
  72. record = edition
  73. };
  74. school.edition = tempEdition;
  75. }
  76. return school.edition;
  77. }
  78. }
  79. }