SheetService.cs 3.0 KB

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