ExamService.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  44. trExam.createTime = now;
  45. if (string.IsNullOrEmpty(trExam.id))
  46. {
  47. trExam.id = Guid.NewGuid().ToString();
  48. await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(trExam, new PartitionKey($"{trExam.code}"));
  49. }
  50. else
  51. {
  52. await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(trExam, new PartitionKey($"{trExam.code}"));
  53. }
  54. return trExam.id;
  55. }
  56. catch (Exception e)
  57. {
  58. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ExamService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
  59. return "";
  60. }
  61. }
  62. }
  63. }