HomeworkService.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 HomeworkService
  10. {
  11. public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Homework work)
  12. {
  13. try
  14. {
  15. work.ttl = -1;
  16. work.code = "Homework-" + work.school;
  17. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  18. work.createTime = now;
  19. if (string.IsNullOrEmpty(work.id))
  20. {
  21. work.id = Guid.NewGuid().ToString();
  22. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(work, new PartitionKey($"{work.code}"));
  23. }
  24. else
  25. {
  26. await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(work, new PartitionKey($"{work.code}"));
  27. }
  28. return work.id;
  29. }
  30. catch (Exception e)
  31. {
  32. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-HomeworkService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  33. return "";
  34. }
  35. }
  36. }
  37. }