|
@@ -14,12 +14,13 @@ using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
|
|
|
using StackExchange.Redis;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
using TEAMModelOS.Controllers;
|
|
|
+using TEAMModelOS.Models;
|
|
|
|
|
|
namespace TEAMModelOS.Services.Common
|
|
|
{
|
|
|
public static class ActivityStudentService
|
|
|
{
|
|
|
- public static async Task<(int msgid,int taskStatus)> Decide(JsonElement request,AzureCosmosFactory _azureCosmos,AzureRedisFactory _azureRedis , AzureStorageFactory _azureStorage, string userid ,string school) {
|
|
|
+ public static async Task<(int msgid,int taskStatus)> Decide(DingDing _dingDing, Option _option, JsonElement request,AzureCosmosFactory _azureCosmos,AzureRedisFactory _azureRedis , AzureStorageFactory _azureStorage, string userid ,string school) {
|
|
|
Vote vote = null;
|
|
|
DateTimeOffset now = DateTimeOffset.UtcNow;
|
|
|
long curr = now.ToUnixTimeMilliseconds();
|
|
@@ -164,9 +165,22 @@ namespace TEAMModelOS.Services.Common
|
|
|
{
|
|
|
if (ex.Status == 404)
|
|
|
{
|
|
|
- StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(vote.id, new PartitionKey($"Activity-{userid}"));
|
|
|
- activity.taskStatus = taskStatus;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuActivity>(activity, vote.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(vote.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ activity.taskStatus = taskStatus;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuActivity>(activity, vote.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ }
|
|
|
+ catch (CosmosException cex) {
|
|
|
+ try {
|
|
|
+ StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<StuActivity>(vote.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ activity.taskStatus = taskStatus;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<StuActivity>(activity, vote.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ }
|
|
|
+ catch(CosmosException cosex) {
|
|
|
+ taskStatus = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -176,9 +190,10 @@ namespace TEAMModelOS.Services.Common
|
|
|
return (msgid, -1);
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception e)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- throw new Exception(e.StackTrace);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},common/delete-activity\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ throw new Exception(ex.StackTrace);
|
|
|
}
|
|
|
if (msgid == 1 && vote!= null)
|
|
|
{
|
|
@@ -461,7 +476,7 @@ namespace TEAMModelOS.Services.Common
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static async Task<(int msgid,int taskStatus)> Answer(JsonElement request, AzureCosmosFactory _azureCosmos, AzureRedisFactory azureRedis, string userid,string school, AzureStorageFactory _azureStorage)
|
|
|
+ public static async Task<(int msgid,int taskStatus)> Answer(DingDing _dingDing, Option _option, JsonElement request, AzureCosmosFactory _azureCosmos, AzureRedisFactory azureRedis, string userid,string school, AzureStorageFactory _azureStorage)
|
|
|
{
|
|
|
|
|
|
DateTimeOffset now = DateTimeOffset.UtcNow;
|
|
@@ -684,9 +699,25 @@ namespace TEAMModelOS.Services.Common
|
|
|
{
|
|
|
if (ex.Status == 404)
|
|
|
{
|
|
|
- StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(survey.id, new PartitionKey($"Activity-{userid}"));
|
|
|
- activity.taskStatus = taskStatus;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuActivity>(activity, survey.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<StuActivity>(survey.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ activity.taskStatus = taskStatus;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StuActivity>(activity, survey.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ }
|
|
|
+ catch (CosmosException cex) {
|
|
|
+ if (cex.Status == 404) {
|
|
|
+ try {
|
|
|
+ StuActivity activity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<StuActivity>(survey.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ activity.taskStatus = taskStatus;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<StuActivity>(activity, survey.id, new PartitionKey($"Activity-{userid}"));
|
|
|
+ } catch (CosmosException cosex) {
|
|
|
+ if (cosex.Status == 404) {
|
|
|
+ taskStatus = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|