1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using Azure;
- using Microsoft.Azure.Cosmos;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- namespace TEAMModelOS.SDK.Services
- {
- public static class SheetService
- {
- public static async Task<string> genSheetId(CosmosClient client , DingDing _dingDing, TEAMModelOS.Models. Option _option, string sheetCode, string tbname)
- {
- string _num09 = "123456789";
- string id = $"{Utils.CreatSaltString(7, _num09)}";
- for (int i = 0; i < 10; i++)
- {
- var response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync($"{id}", new PartitionKey(sheetCode));
- if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
- {
- break;
- }
- else
- {
- if (i == 9)
- {
- string msg = "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
- await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
- throw new Exception(msg);
- }
- else
- {
- id = $"{Utils.CreatSaltString(7, _num09)}";
- }
- }
- }
- return id;
- }
- public static async Task<string> genSheetNo(CosmosClient client, DingDing _dingDing, TEAMModelOS.Models.Option _option, string sheetCode, string tbname,string from)
- {
- string _num09 = "123456789";
- string no = $"{Utils.CreatSaltString(7, _num09)}";
- for (int i = 0; i < 10; i++)
- {
- List<SheetConfig> sheets = new List<SheetConfig>();
- bool hasCurrFrom = false;
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIteratorSql<SheetConfig>(
- queryText: $"select value(c) from c where c.no='{no}'",
- requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(sheetCode) }))
- {
- hasCurrFrom = true;
- break;
- }
- if (hasCurrFrom)
- {
- if (i == 9)
- {
- string msg = "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
- await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
- throw new Exception(msg);
- }
- else
- {
- no = $"{Utils.CreatSaltString(7, _num09)}";
- }
- }
- else { break; }
- }
- return no;
- }
- }
- }
|