using Azure; using 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 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++) { Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync($"{id}", new PartitionKey(sheetCode)); if (response.Status == 404) { 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 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 sheets = new List(); bool hasCurrFrom = false; await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator( 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; } } }