SurveyService.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Azure.Cosmos;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using TEAMModelOS.SDK.DI;
  7. namespace TEAMModelOS.SDK.Models.Service
  8. {
  9. public static class SurveyService
  10. {
  11. public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Survey survey)
  12. {
  13. try
  14. {
  15. survey.ttl = -1;
  16. survey.code = "Survey-" + survey.school;
  17. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  18. survey.createTime = now;
  19. if (string.IsNullOrEmpty(survey.id))
  20. {
  21. survey.id = Guid.NewGuid().ToString();
  22. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(survey, new PartitionKey($"{survey.code}"));
  23. }
  24. else
  25. {
  26. await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
  27. }
  28. return survey.id;
  29. }
  30. catch (Exception e)
  31. {
  32. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-SurveyService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  33. return "";
  34. }
  35. }
  36. }
  37. }