BISchoolService.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Microsoft.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. /// 計算學校版本公式 ※計算邏輯變更:廢止原size+scale判斷邏輯
  39. /// </summary>
  40. public static Edition calSchoolEdition(School school, List<string> services)
  41. {
  42. int edition = 1;
  43. bool adminFlg = (services.Contains("IPDYZYLC")) ? true : false;
  44. bool analFlg = (services.Contains("YMPCVCIM")) ? true : false;
  45. bool fiveFlg = (services.Contains("YPXSJ6NJ")) ? true : false;
  46. if (adminFlg && analFlg && fiveFlg) edition = 3;
  47. else if (adminFlg && analFlg) edition = 2;
  48. else edition = 1;
  49. if (school.edition != null)
  50. {
  51. school.edition.current = edition;
  52. if (school.edition.record < edition)
  53. {
  54. school.edition.record = edition;
  55. }
  56. }
  57. else
  58. {
  59. Edition tempEdition = new()
  60. {
  61. current = edition,
  62. record = edition
  63. };
  64. school.edition = tempEdition;
  65. }
  66. return school.edition;
  67. }
  68. }
  69. }