ExamService.cs 2.1 KB

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