SheetService.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Azure;
  2. using Microsoft.Azure.Cosmos;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading.Tasks;
  6. using TEAMModelOS.SDK.DI;
  7. using TEAMModelOS.SDK.Extension;
  8. using TEAMModelOS.SDK.Models;
  9. namespace TEAMModelOS.SDK.Services
  10. {
  11. public static class SheetService
  12. {
  13. public static async Task<string> genSheetId(CosmosClient client , DingDing _dingDing, TEAMModelOS.Models. Option _option, string sheetCode, string tbname)
  14. {
  15. string _num09 = "123456789";
  16. string id = $"{Utils.CreatSaltString(7, _num09)}";
  17. for (int i = 0; i < 10; i++)
  18. {
  19. var response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync($"{id}", new PartitionKey(sheetCode));
  20. if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
  21. {
  22. break;
  23. }
  24. else
  25. {
  26. if (i == 9)
  27. {
  28. string msg = "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
  29. await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
  30. throw new Exception(msg);
  31. }
  32. else
  33. {
  34. id = $"{Utils.CreatSaltString(7, _num09)}";
  35. }
  36. }
  37. }
  38. return id;
  39. }
  40. public static async Task<string> genSheetNo(CosmosClient client, DingDing _dingDing, TEAMModelOS.Models.Option _option, string sheetCode, string tbname,string from)
  41. {
  42. string _num09 = "123456789";
  43. string no = $"{Utils.CreatSaltString(7, _num09)}";
  44. for (int i = 0; i < 10; i++)
  45. {
  46. List<SheetConfig> sheets = new List<SheetConfig>();
  47. bool hasCurrFrom = false;
  48. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIteratorSql<SheetConfig>(
  49. queryText: $"select value(c) from c where c.no='{no}'",
  50. requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(sheetCode) }))
  51. {
  52. hasCurrFrom = true;
  53. break;
  54. }
  55. if (hasCurrFrom)
  56. {
  57. if (i == 9)
  58. {
  59. string msg = "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
  60. await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
  61. throw new Exception(msg);
  62. }
  63. else
  64. {
  65. no = $"{Utils.CreatSaltString(7, _num09)}";
  66. }
  67. }
  68. else { break; }
  69. }
  70. return no;
  71. }
  72. }
  73. }