using Microsoft.Azure.Cosmos; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using TEAMModelOS.SDK.DI; namespace TEAMModelOS.SDK.Models.Service { public static class SurveyService { public static async Task saveMoreAsync(CosmosClient client, DingDing _dingDing, Survey survey) { try { survey.ttl = -1; survey.code = "Survey-" + survey.school; long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); survey.createTime = now; if (string.IsNullOrEmpty(survey.id)) { survey.id = Guid.NewGuid().ToString(); if (survey.publish == 1) { survey.progress = "pending"; } else { if (survey.startTime > now) { survey.progress = "pending"; } else { survey.progress = "going"; } } await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(survey, new PartitionKey($"{survey.code}")); } else { await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}")); } return survey.id; } catch (Exception e) { await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-SurveyService-saveMore\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組); return ""; } } } }