|
@@ -1,17 +1,134 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Azure.Cosmos;
|
|
|
using Microsoft.Azure.WebJobs;
|
|
|
using Microsoft.Azure.WebJobs.Host;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
|
|
|
namespace TEAMModelFunction
|
|
|
{
|
|
|
- public static class MonitorServicesBus
|
|
|
+ public class MonitorServicesBus
|
|
|
{
|
|
|
-/* [FunctionName("test_queue_activetask")]
|
|
|
- public static void Run([ServiceBusTrigger("test_topic_ActiveTask", Connection = "ServiceBusConnection")]string myQueueItem, ILogger log)
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ public MonitorServicesBus(AzureCosmosFactory azureCosmos, DingDing dingDing)
|
|
|
{
|
|
|
- ///ÖØÊÔ´ÎÊý
|
|
|
- log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
|
|
|
- }*/
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ }
|
|
|
+ [FunctionName("Exam")]
|
|
|
+ public async Task Exam([ServiceBusTrigger("active-task", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var json = JsonDocument.Parse(msg);
|
|
|
+ json.RootElement.TryGetProperty("id", out JsonElement id);
|
|
|
+ json.RootElement.TryGetProperty("name", out JsonElement name);
|
|
|
+ json.RootElement.TryGetProperty("code", out JsonElement code);
|
|
|
+ //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ /* 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)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"ServiceBus,ExamBus()\n{ex.Message}", GroupNames.é†�摩豆æœ�å‹™é�‹ç¶ç¾¤çµ„);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ [FunctionName("Vote")]
|
|
|
+ public async Task Vote([ServiceBusTrigger("active-task", "vote", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var jsonMsg = JsonDocument.Parse(msg);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("name", out JsonElement name);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
|
|
|
+ //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ /*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)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.é†�摩豆æœ�å‹™é�‹ç¶ç¾¤çµ„);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ [FunctionName("Survey")]
|
|
|
+ public async Task Survey([ServiceBusTrigger("active-task", "survey", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var jsonMsg = JsonDocument.Parse(msg);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("name", out JsonElement name);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
|
|
|
+ //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ /*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)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"ServiceBus,VoteBus()\n{ex.Message}", GroupNames.é†�摩豆æœ�å‹™é�‹ç¶ç¾¤çµ„);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|