SurveyService.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. if (survey.startTime > now)
  23. {
  24. survey.progress = "pending";
  25. }
  26. else
  27. {
  28. survey.progress = "going";
  29. }
  30. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(survey, new PartitionKey($"{survey.code}"));
  31. }
  32. else
  33. {
  34. await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
  35. }
  36. return survey.id;
  37. }
  38. catch (Exception e)
  39. {
  40. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-SurveyService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  41. return "";
  42. }
  43. }
  44. }
  45. }