|
@@ -1,4 +1,5 @@
|
|
|
using Azure.Cosmos;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using Microsoft.Azure.Documents;
|
|
|
using System;
|
|
@@ -6,8 +7,10 @@ using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using TEAMModelOS.SDK;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
|
|
|
namespace TEAMModelFunction
|
|
|
{
|
|
@@ -35,51 +38,156 @@ namespace TEAMModelFunction
|
|
|
adcode = $"Activity-{tdata.creatorId}";
|
|
|
blobcntr = tdata.creatorId;
|
|
|
}
|
|
|
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
|
|
|
Homework work = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
|
|
|
- //List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", vote.progress } });
|
|
|
+ List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", work.progress } });
|
|
|
if (work != null)
|
|
|
{
|
|
|
- (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, work.tchLists, work.school);
|
|
|
- List<StuActivity> tchActivities = new List<StuActivity>();
|
|
|
-
|
|
|
- if (tchList.IsNotEmpty())
|
|
|
+ switch (work.progress)
|
|
|
{
|
|
|
- tchList.ForEach(x =>
|
|
|
- {
|
|
|
- tchActivities.Add(new StuActivity
|
|
|
+ case "pending":
|
|
|
+ var messageWork = new ServiceBusMessage(new { id = input.Id, progress = "going", code = tdata.code }.ToJsonString());
|
|
|
+ messageWork.ApplicationProperties.Add("name", "Homework");
|
|
|
+ if (changeRecords.Count > 0)
|
|
|
{
|
|
|
- pk = "Activity",
|
|
|
- id = work.id,
|
|
|
- code = $"Activity-{x.id}",
|
|
|
- type = "Homework",
|
|
|
- name = work.name,
|
|
|
- startTime = work.startTime,
|
|
|
- endTime = work.endTime,
|
|
|
- scode = work.code,
|
|
|
- scope = work.scope,
|
|
|
- school = work.school,
|
|
|
- creatorId = work.creatorId,
|
|
|
- subjects = new List<string> { "" },
|
|
|
- blob = null,
|
|
|
- owner = work.owner,
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
- taskStatus = -1,
|
|
|
- classIds = work.tchLists
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- await TriggerStuActivity.SaveStuActivity(client, _dingDing, null, null, tchActivities);
|
|
|
+ await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
|
|
|
+ changeRecords[0].sequenceNumber = start;
|
|
|
+ await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = input.Id,
|
|
|
+ PartitionKey = "pending",
|
|
|
+ sequenceNumber = start,
|
|
|
+ msgId = messageWork.MessageId
|
|
|
+ };
|
|
|
+ await _azureStorage.Save<ChangeRecord>(changeRecord);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "going":
|
|
|
+ List<string> classes = ExamService.getClasses(work.classes, work.stuLists);
|
|
|
+ (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, work.school);
|
|
|
+ List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
+ List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
+ List<StuActivity> tchActivities = new List<StuActivity>();
|
|
|
+ if (tmdids.IsNotEmpty())
|
|
|
+ {
|
|
|
+ tmdids.ForEach(x =>
|
|
|
+ {
|
|
|
+ tmdActivities.Add(new StuActivity
|
|
|
+ {
|
|
|
+ pk = "Activity",
|
|
|
+ id = work.id,
|
|
|
+ code = $"Activity-{x.id}",
|
|
|
+ type = "work",
|
|
|
+ name = work.name,
|
|
|
+ startTime = work.startTime,
|
|
|
+ endTime = work.endTime,
|
|
|
+ scode = work.code,
|
|
|
+ scope = work.scope,
|
|
|
+ school = work.school,
|
|
|
+ creatorId = work.creatorId,
|
|
|
+ subjects = new List<string> { "" },
|
|
|
+ blob = work.blob,
|
|
|
+ owner = work.owner,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ taskStatus = -1,
|
|
|
+ classIds = classes
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (students.IsNotEmpty())
|
|
|
+ {
|
|
|
+ students.ForEach(x =>
|
|
|
+ {
|
|
|
+ stuActivities.Add(new StuActivity
|
|
|
+ {
|
|
|
+ pk = "Activity",
|
|
|
+ id = work.id,
|
|
|
+ code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
|
|
|
+ type = "work",
|
|
|
+ name = work.name,
|
|
|
+ startTime = work.startTime,
|
|
|
+ endTime = work.endTime,
|
|
|
+ scode = work.code,
|
|
|
+ scope = work.scope,
|
|
|
+ school = work.school,
|
|
|
+ creatorId = work.creatorId,
|
|
|
+ subjects = new List<string> { "" },
|
|
|
+ blob = work.blob,
|
|
|
+ owner = work.owner,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ taskStatus = -1,
|
|
|
+ classIds = classes
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, work.tchLists, work.school);
|
|
|
+ if (tchList.IsNotEmpty())
|
|
|
+ {
|
|
|
+ tchList.ForEach(x =>
|
|
|
+ {
|
|
|
+ tchActivities.Add(new StuActivity
|
|
|
+ {
|
|
|
+ pk = "Activity",
|
|
|
+ id = work.id,
|
|
|
+ code = $"Activity-{x.id}",
|
|
|
+ type = "work",
|
|
|
+ name = work.name,
|
|
|
+ startTime = work.startTime,
|
|
|
+ endTime = work.endTime,
|
|
|
+ scode = work.code,
|
|
|
+ scope = work.scope,
|
|
|
+ school = work.school,
|
|
|
+ creatorId = work.creatorId,
|
|
|
+ subjects = new List<string> { "" },
|
|
|
+ blob = work.blob,
|
|
|
+ owner = work.owner,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ taskStatus = -1,
|
|
|
+ classIds = work.tchLists
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ await TriggerStuActivity.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, tchActivities);
|
|
|
|
|
|
+ var messageWorkEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = tdata.code }.ToJsonString());
|
|
|
+ messageWorkEnd.ApplicationProperties.Add("name", "Homework");
|
|
|
+ if (changeRecords.Count > 0)
|
|
|
+ {
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
|
|
|
+ await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
|
|
|
+ changeRecords[0].sequenceNumber = end;
|
|
|
+ await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = input.Id,
|
|
|
+ PartitionKey = "going",
|
|
|
+ sequenceNumber = end,
|
|
|
+ msgId = messageWorkEnd.MessageId
|
|
|
+ };
|
|
|
+ await _azureStorage.Save<ChangeRecord>(changeRecord);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "finish":
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|