|
@@ -3,33 +3,37 @@ using System.Collections.Generic;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using Azure.Cosmos;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
using Microsoft.Azure.WebJobs;
|
|
|
using Microsoft.Azure.WebJobs.Host;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using StackExchange.Redis;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
|
|
|
namespace TEAMModelFunction
|
|
|
{
|
|
|
public class MonitorServicesBus
|
|
|
{
|
|
|
+
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
- public MonitorServicesBus(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage
|
|
|
- , AzureRedisFactory azureRedis
|
|
|
- )
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ public MonitorServicesBus(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage , AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_dingDing = dingDing;
|
|
|
_azureStorage = azureStorage;
|
|
|
_azureRedis = azureRedis;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
}
|
|
|
[FunctionName("Exam")]
|
|
|
- public async Task Exam([ServiceBusTrigger("active-task", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ public async Task Exam([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -42,23 +46,6 @@ namespace TEAMModelFunction
|
|
|
ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
exam.progress = progress.ToString();
|
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
|
|
|
- /* keyValuePairs.TryGetValue("id", out object id);
|
|
|
- keyValuePairs.TryGetValue("name", out object name);
|
|
|
- keyValuePairs.TryGetValue("code", out object code);*/
|
|
|
- //keyValuePairs.TryGetValue("status", out object progress);
|
|
|
- /*if (name.ToString().Equals("Exam", StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
- if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0)
|
|
|
- {
|
|
|
- exam.progress = "going";
|
|
|
- }
|
|
|
- else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) > 0)
|
|
|
- {
|
|
|
- exam.progress = "finish";
|
|
|
- }
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
|
|
|
- }*/
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -67,7 +54,7 @@ namespace TEAMModelFunction
|
|
|
|
|
|
}
|
|
|
[FunctionName("Vote")]
|
|
|
- public async Task Vote([ServiceBusTrigger("active-task", "vote", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ public async Task Vote([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "vote", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -80,29 +67,6 @@ namespace TEAMModelFunction
|
|
|
Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
vote.progress = progress.ToString();
|
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
|
|
|
- /*keyValuePairs.TryGetValue("id", out object id);
|
|
|
- keyValuePairs.TryGetValue("name", out object name);
|
|
|
- keyValuePairs.TryGetValue("code", out object code);*/
|
|
|
- //keyValuePairs.TryGetValue("status", out object progress);
|
|
|
- /*if (name.ToString().Equals("Vote", StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- Vote vote;
|
|
|
- var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
- if (sresponse.Status == 200)
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
|
|
|
- vote = json.ToObject<Vote>();
|
|
|
- if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) < 0)
|
|
|
- {
|
|
|
- vote.progress = "going";
|
|
|
- }
|
|
|
- else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(vote.endTime) > 0)
|
|
|
- {
|
|
|
- vote.progress = "finish";
|
|
|
- }
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
|
|
|
- }
|
|
|
- }*/
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -111,7 +75,7 @@ namespace TEAMModelFunction
|
|
|
|
|
|
}
|
|
|
[FunctionName("Survey")]
|
|
|
- public async Task Survey([ServiceBusTrigger("active-task", "survey", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ public async Task Survey([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "survey", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -124,23 +88,6 @@ namespace TEAMModelFunction
|
|
|
Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
survey.progress = progress.ToString();
|
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
|
|
|
- /*keyValuePairs.TryGetValue("id", out object id);
|
|
|
- keyValuePairs.TryGetValue("name", out object name);
|
|
|
- keyValuePairs.TryGetValue("code", out object code);*/
|
|
|
- //keyValuePairs.TryGetValue("status", out object progress);
|
|
|
- /*if (name.ToString().Equals("Survey", StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
- if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
|
|
|
- {
|
|
|
- survey.progress = "going";
|
|
|
- }
|
|
|
- else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
|
|
|
- {
|
|
|
- survey.progress = "finish";
|
|
|
- }
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
|
|
|
- }*/
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -148,7 +95,7 @@ namespace TEAMModelFunction
|
|
|
}
|
|
|
}
|
|
|
[FunctionName("Blob")]
|
|
|
- public async Task Blob([ServiceBusTrigger("active-task", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
|
|
|
+ public async Task Blob([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
|
|
|
try
|
|
|
{
|
|
|
// await _dingDing.SendBotMsg($"ServiceBus,Blob(){msg}", GroupNames.醍摩豆服務運維群組);
|
|
@@ -163,8 +110,10 @@ namespace TEAMModelFunction
|
|
|
await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
}
|
|
|
+#if DEBUG
|
|
|
await _dingDing.SendBotMsg($"ServiceBus,Blob() 容器:{name}使用:{size.Item1},文件分类:{size.Item2.ToJsonString()}",
|
|
|
GroupNames.成都开发測試群組);
|
|
|
+#endif
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -172,5 +121,155 @@ namespace TEAMModelFunction
|
|
|
await _dingDing.SendBotMsg($"ServiceBus,Blob()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 完善课程变更,StuListChange, originCode是学校编码 则表示名单是学校自定义名单,如果是tmdid则表示醍摩豆的私有名单,scope=school,private。
|
|
|
+ /// </summary>
|
|
|
+ /// <data msg>
|
|
|
+ /// CourseChange
|
|
|
+ ///// </data>
|
|
|
+ /// <param name="msg"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [FunctionName("StuList")]
|
|
|
+ public async Task StuList([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "stulist", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"ServiceBus,StuList:{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ var jsonMsg = JsonDocument.Parse(msg);
|
|
|
+ StuListChange stuListChange = msg.ToObject<StuListChange>();
|
|
|
+ //名单变动修改学生课程关联信息
|
|
|
+ await StuListService.FixStuCourse(client, stuListChange);
|
|
|
+ //Vote投票 Survey问卷 Exam评测 Learn学习活动 Homework作业活动
|
|
|
+ //名单变动修改学生问卷关联信息
|
|
|
+ await StuListService.FixActivity(client, stuListChange, "Survey");
|
|
|
+ //名单变动修改学生投票关联信息
|
|
|
+ await StuListService.FixActivity(client, stuListChange, "Vote");
|
|
|
+ //名单变动修改学生评测关联信息
|
|
|
+ await StuListService.FixActivity(client, stuListChange, "Exam");
|
|
|
+ //TODO学习活动
|
|
|
+ //await FixActivity(client, stuListChange, "Learn");
|
|
|
+ //TODO作业活动
|
|
|
+ // await FixActivity(client, stuListChange, "Homework");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"StuListServiceBus-StuList\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ [FunctionName("Notice")]
|
|
|
+ public async Task Notice([ServiceBusTrigger("%Azure:ServiceBus:NoticeTask%", "notice", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+ var client = _azureRedis.GetRedisClient(8);
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ Console.WriteLine(msg);
|
|
|
+ // List<Task<string>> tasks = new List<Task<string>>();
|
|
|
+ //List<Task> sessionTasks = new List<Task>();
|
|
|
+ var jsonMsg = JsonDocument.Parse(msg);
|
|
|
+ Notice notice = msg.ToObject<Notice>();
|
|
|
+ var blobcntr = "";
|
|
|
+
|
|
|
+ if (notice.scope.Equals("school"))
|
|
|
+ {
|
|
|
+ blobcntr = notice.school;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ blobcntr = notice.creatorId;
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(blobcntr))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#if DEBUG
|
|
|
+ await _dingDing.SendBotMsg($"NoticeServiceBus-Notice:\n发起通知{msg}", GroupNames.成都开发測試群組);
|
|
|
+#endif
|
|
|
+ var urlNotice = $"{notice.msgId}.json";
|
|
|
+ var blobNotice = new
|
|
|
+ {
|
|
|
+ notice.type,
|
|
|
+ notice.priority,
|
|
|
+ notice.body,
|
|
|
+ notice.creation,
|
|
|
+ notice.expire,
|
|
|
+ notice.creatorId
|
|
|
+
|
|
|
+ };
|
|
|
+ await _azureStorage.UploadFileByContainer(blobcntr, blobNotice.ToJsonString(), "notice", urlNotice);
|
|
|
+ var urlReceiver = $"{notice.msgId}_receiver.json";
|
|
|
+ var blobReceiver = new
|
|
|
+ {
|
|
|
+ notice.stuids,
|
|
|
+ notice.tmdids
|
|
|
+ };
|
|
|
+ await _azureStorage.UploadFileByContainer(blobcntr, blobReceiver.ToJsonString(), "notice", urlReceiver);
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ // "ttl":2592000,不能超过30天(2592000),一天(3600),一周(25200)
|
|
|
+
|
|
|
+ if (notice.stuids.IsNotEmpty())
|
|
|
+ {
|
|
|
+ // List<Receiver> receivers = new List<Receiver>();
|
|
|
+ foreach (var stu in notice.stuids)
|
|
|
+ {
|
|
|
+ Receiver receiver = new Receiver
|
|
|
+ {
|
|
|
+ id = notice.msgId,
|
|
|
+ pk = "Receiver",
|
|
|
+ status = 0,
|
|
|
+ scope = "school",
|
|
|
+ ctime = now,
|
|
|
+ urlNotice = $"/notice/{urlNotice}",
|
|
|
+ rid = $"{stu.schoolId}-{stu.id}"
|
|
|
+ };
|
|
|
+ var url = $"{stu.id}/receive/{notice.msgId}.json";
|
|
|
+ await client.HashSetAsync($"Notice:Receiver:{stu.schoolId}-{stu.id}", notice.msgId, $"/student/{url}");
|
|
|
+ // await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync<Receiver>(receiver,new Azure.Cosmos.PartitionKey(receiver.code));
|
|
|
+ // /student/{stuid}/receive/{notice.sid}.json
|
|
|
+ //存放通知到学生容器空间
|
|
|
+
|
|
|
+ await _azureStorage.UploadFileByContainer(blobcntr, receiver.ToJsonString(), "student", url);
|
|
|
+ var messageBlob = new ServiceBusMessage(receiver.ToJsonString()) { SessionId = $"{stu.schoolId}-{stu.id}" };
|
|
|
+ // messageBlob.ApplicationProperties.Add("name", "Receiver");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync("notice-task", messageBlob);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (notice.tmdids.IsNotEmpty())
|
|
|
+ {
|
|
|
+ foreach (var tmdid in notice.tmdids)
|
|
|
+ {
|
|
|
+ Receiver receiver = new Receiver
|
|
|
+ {
|
|
|
+ id = notice.msgId,
|
|
|
+ pk = "Receiver",
|
|
|
+ status = 0,
|
|
|
+ //school = stu.schoolId,
|
|
|
+ scope = "school",
|
|
|
+
|
|
|
+ ctime = now,
|
|
|
+ urlNotice = $"/notice/{urlNotice}",
|
|
|
+ rid = $"{tmdid}"
|
|
|
+ };
|
|
|
+ var url = $"{notice.msgId}.json";
|
|
|
+ await client.HashSetAsync($"Notice:Receiver:{tmdid}", notice.msgId, new { now, url = $"/receive/{url}" }.ToJsonString());
|
|
|
+ //await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync<Receiver>(receiver, new Azure.Cosmos.PartitionKey(receiver.code));
|
|
|
+ // /student/{stuid}/receive/{notice.sid}.json
|
|
|
+ //存放通知到学生容器空间
|
|
|
+
|
|
|
+ await _azureStorage.UploadFileByContainer(blobcntr, receiver.ToJsonString(), "receive", url);
|
|
|
+ var messageBlob = new ServiceBusMessage(receiver.ToJsonString()) { SessionId = $"{tmdid}" };
|
|
|
+ //messageBlob.ApplicationProperties.Add("name", "Receiver");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync("notice-task", messageBlob);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"NoticeServiceBus-Notice\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|