ExamService.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 ExamService
  10. {
  11. public static List<string> getClasses(List<string> cla, List<string> stus)
  12. {
  13. List<string> classes = new List<string>();
  14. try
  15. {
  16. if (cla.Count > 0)
  17. {
  18. foreach (string cl in cla)
  19. {
  20. classes.Add(cl);
  21. }
  22. }
  23. if (stus.Count > 0)
  24. {
  25. foreach (string stu in stus)
  26. {
  27. classes.Add(stu);
  28. }
  29. }
  30. return classes;
  31. }
  32. catch (Exception)
  33. {
  34. return classes;
  35. }
  36. }
  37. public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, ExamLite trExam)
  38. {
  39. try
  40. {
  41. trExam.ttl = -1;
  42. trExam.code = "ExamLite-" + trExam.school;
  43. trExam.scope = "school";
  44. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  45. trExam.createTime = now;
  46. if (trExam.startTime > now)
  47. {
  48. trExam.progress = "pending";
  49. }
  50. else
  51. {
  52. trExam.progress = "going";
  53. }
  54. if (string.IsNullOrEmpty(trExam.id))
  55. {
  56. trExam.id = Guid.NewGuid().ToString();
  57. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(trExam, new PartitionKey($"{trExam.code}"));
  58. }
  59. else
  60. {
  61. await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(trExam, new PartitionKey($"{trExam.code}"));
  62. }
  63. return trExam.id;
  64. }
  65. catch (Exception e)
  66. {
  67. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ExamService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  68. return "";
  69. }
  70. }
  71. }
  72. }