TriggerStudy.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using Microsoft.Azure.Documents;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using TEAMModelOS.SDK;
  8. using TEAMModelOS.SDK.DI;
  9. using TEAMModelOS.SDK.Models;
  10. using TEAMModelOS.SDK.Models.Cosmos.Common;
  11. namespace TEAMModelFunction
  12. {
  13. public static class TriggerStudy
  14. {
  15. public static async void Trigger(AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
  16. CosmosClient client, Document input, TriggerData tdata, AzureRedisFactory _azureRedis)
  17. {
  18. try
  19. {
  20. if ((tdata.status != null && tdata.status.Value == 404) || tdata.ttl > 0)
  21. {
  22. return;
  23. }
  24. var adid = tdata.id;
  25. var adcode = "";
  26. string blobcntr = null;
  27. if (tdata.scope.Equals("school"))
  28. {
  29. adcode = $"Activity-{tdata.school}";
  30. blobcntr = tdata.school;
  31. }
  32. else
  33. {
  34. adcode = $"Activity-{tdata.creatorId}";
  35. blobcntr = tdata.creatorId;
  36. }
  37. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
  38. Study study = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Study>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
  39. //List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", vote.progress } });
  40. if (study != null)
  41. {
  42. (List<TmdInfo> tchList,_ ) = await TriggerStuActivity.GetTchList(client, _dingDing, study.tchLists, study.school);
  43. List<StuActivity> tchActivities = new List<StuActivity>();
  44. if (tchList.IsNotEmpty())
  45. {
  46. tchList.ForEach(x =>
  47. {
  48. tchActivities.Add(new StuActivity
  49. {
  50. pk = "Activity",
  51. id = study.id,
  52. code = $"Activity-{x.id}",
  53. type = "Study",
  54. name = study.name,
  55. startTime = study.startTime,
  56. endTime = study.endTime,
  57. scode = study.code,
  58. scope = study.scope,
  59. school = study.school,
  60. creatorId = study.creatorId,
  61. subjects = new List<string> { "" },
  62. blob = null,
  63. owner = study.owner,
  64. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  65. taskStatus = -1,
  66. classIds = study.tchLists
  67. });
  68. });
  69. }
  70. await TriggerStuActivity.SaveStuActivity(client, _dingDing, null, null, tchActivities);
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修活动异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  76. }
  77. }
  78. }
  79. }