TriggerStudy.cs 3.7 KB

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