SurveyService.cs 1.9 KB

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