SheetService.cs 3.0 KB

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