Browse Source

艺术评价、投票、问卷、研修update

zj 2 years ago
parent
commit
4283e1ff85

+ 247 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerArt.cs

@@ -0,0 +1,247 @@
+using Azure.Messaging.ServiceBus;
+using HTEXLib.COMM.Helpers;
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK;
+using Azure.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using Azure.Core;
+using TEAMModelOS.SDK.Models.Service;
+
+namespace TEAMModelOS.FunctionV4.CosmosDB
+{
+    internal class TriggerArt
+    {
+        public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+            CosmosClient client, JsonElement input, TriggerData tdata, AzureRedisFactory _azureRedis, IConfiguration _configuration)
+        {
+            try
+            {
+                if ((tdata.status != null && tdata.status.Value == 404))
+                {
+                    await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code));
+                    ActivityList data = input.ToObject<ActivityList>();
+                    await ActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data);
+                    var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id } });
+                    foreach (var record in records)
+                    {
+                        try
+                        {
+                            await table_cancel.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
+                            await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
+                        }
+                        catch (Exception)
+                        {
+                            continue;
+                        }
+                    }
+                    return;
+                }
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                var adid = tdata.id;
+                var adcode = "";
+                string blobcntr = null;
+                if (tdata.scope.Equals("school"))
+                {
+                    adcode = $"Activity-{tdata.school}";
+                    blobcntr = tdata.school;
+                }
+                else
+                {
+                    adcode = $"Activity-{tdata.creatorId}";
+                    blobcntr = tdata.creatorId;
+                }
+                ArtEvaluation art = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ArtEvaluation>(tdata.id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
+
+                if (art != null)
+                {
+                    string PartitionKey = string.Format("{0}{1}{2}", art.code, "-", art.progress);
+                    List<ChangeRecord> voteRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    switch (art.progress)
+                    {
+                        case "pending":
+                            var messageVote = new ServiceBusMessage(new { id = tdata.id, progress = "going", code = tdata.code }.ToJsonString());
+                            messageVote.ApplicationProperties.Add("name", "Art");
+                            if (voteRecords.Count > 0)
+                            {
+                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
+                                try
+                                {
+                                    await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), voteRecords[0].sequenceNumber);
+                                }
+                                catch (Exception)
+                                {
+                                }
+                                voteRecords[0].sequenceNumber = start;
+                                await table.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
+                            }
+                            else
+                            {
+                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
+                                ChangeRecord changeRecord = new ChangeRecord
+                                {
+                                    RowKey = tdata.id,
+                                    PartitionKey = PartitionKey,
+                                    sequenceNumber = start,
+                                    msgId = messageVote.MessageId
+                                };
+                                await table.Save<ChangeRecord>(changeRecord);
+                            }
+                            break;
+                        case "going":
+                            
+                            List<string> classes = ExamService.getClasses(art.classes, art.stuLists);
+                            (List<RMember> tmdIds, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, art.school, null);
+                            var addStudentsCls = tmdIds.FindAll(x => x.type == 2);
+                            var addTmdidsCls = tmdIds.FindAll(x => x.type == 1);
+                            List<string> tmds = new List<string>();
+                            if (addTmdidsCls.IsNotEmpty())
+                            {
+                                tmds.AddRange(addTmdidsCls.Select(x => x.id).ToList());
+                            }
+                            List<StuActivity> stuActivities = new List<StuActivity>();
+                            List<StuActivity> tmdActivities = new List<StuActivity>();
+                            List<StuActivity> tchActivities = new List<StuActivity>();
+                            List<string> sub = new();
+/*                            if (art.targets.Count > 0)
+                            {
+                                foreach (var course in art.targets)
+                                {
+                                    var info = course.ToObject<List<string>>();
+                                    if (info.Count > 1)
+                                    {
+                                        sub.Add(info[0]);
+                                    }
+                                }
+                            }*/
+                            if (tmds.IsNotEmpty())
+                            {
+                                tmds.ForEach(x =>
+                                {
+                                    HashSet<string> classIds = new HashSet<string>();
+                                    classLists.ForEach(z => {
+                                        z.members.ForEach(y => {
+                                            if (y.id.Equals(x) && y.type == 1)
+                                            {
+                                                classIds.Add(z.id);
+                                            }
+                                        });
+                                    });
+                                    tmdActivities.Add(new StuActivity
+                                    {
+                                        pk = "Activity",
+                                        id = art.id,
+                                        code = $"Activity-{x}",
+                                        type = "Art",
+                                        name = art.name,
+                                        startTime = art.startTime,
+                                        endTime = art.endTime,
+                                        scode = art.code,
+                                        scope = art.scope,
+                                        school = art.school,
+                                        creatorId = art.creatorId,
+                                        subjects = sub,
+                                        blob = null,
+                                        owner = art.owner,
+                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                        taskStatus = -1,
+                                        classIds = classIds.ToList()
+                                    });
+                                });
+                            }
+                            if (addStudentsCls.IsNotEmpty())
+                            {
+                                addStudentsCls.ForEach(x =>
+                                {
+                                    HashSet<string> classIds = new HashSet<string>();
+                                    classLists.ForEach(z => {
+                                        z.members.ForEach(y => {
+                                            if (y.id.Equals(x.id) && y.code.Equals(art.school) && y.type == 2)
+                                            {
+                                                classIds.Add(z.id);
+                                            }
+                                        });
+                                    });
+                                    stuActivities.Add(new StuActivity
+                                    {
+                                        pk = "Activity",
+                                        id = art.id,
+                                        code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
+                                        type = "Atr",
+                                        name = art.name,
+                                        startTime = art.startTime,
+                                        endTime = art.endTime,
+                                        scode = art.code,
+                                        scope = art.scope,
+                                        school = art.school,
+                                        creatorId = art.creatorId,
+                                        subjects = sub,
+                                        blob = null,
+                                        owner = art.owner,
+                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                        taskStatus = -1,
+                                        classIds = classIds.ToList()
+                                    });
+                                });
+                            }
+                            await ActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, tchActivities);
+                            //await StatisticsService.SendServiceBus(list, _configuration, _serviceBus, client);
+                            
+                            var messageVoteEnd = new ServiceBusMessage(new { id = tdata.id, progress = "finish", code = tdata.code }.ToJsonString());
+                            messageVoteEnd.ApplicationProperties.Add("name", "Art");
+                            if (voteRecords.Count > 0)
+                            {
+                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
+                                try
+                                {
+                                    await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), voteRecords[0].sequenceNumber);
+                                }
+                                catch (Exception)
+                                {
+                                }
+                                voteRecords[0].sequenceNumber = end;
+                                await table.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
+                            }
+                            else
+                            {
+                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
+                                ChangeRecord changeRecord = new()
+                                {
+                                    RowKey = tdata.id,
+                                    PartitionKey = PartitionKey,
+                                    sequenceNumber = end,
+                                    msgId = messageVoteEnd.MessageId
+                                };
+                                await table.Save<ChangeRecord>(changeRecord);
+                            }
+
+                            break;
+                        case "finish":
+
+                           
+                            
+                            break;
+                    }
+                }
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}艺术评价异常{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+    }
+}

+ 1 - 1
TEAMModelOS.FunctionV4/CosmosDB/TriggerStudy.cs

@@ -207,7 +207,7 @@ namespace TEAMModelOS.FunctionV4
                                 }
                             }
                             //处理教研活动结束统计账户信息
-                            List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, study.school, study.classes, study.stuLists, study.stuLists, gls);
+                            List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, study.school, study.classes, study.stuLists, study.tchLists, gls);
                             study.staffIds = idList;
                             await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Study>(study, study.id, new Azure.Cosmos.PartitionKey(study.code));
 

+ 9 - 6
TEAMModelOS.FunctionV4/CosmosDB/TriggerSurvey.cs

@@ -131,17 +131,20 @@ namespace TEAMModelOS.FunctionV4
                             List<StuActivity> tchActivities = new List<StuActivity>();
 
                             List<string> sub = new();
-                            if (survey.targets.Count > 0)
-                            {
-                                foreach (var course in survey.targets)
+                            if (survey.tchLists.Count == 0) {
+                                if (survey.targets.Count > 0)
                                 {
-                                    var info = course.ToObject<List<string>>();
-                                    if (info.Count > 1)
+                                    foreach (var course in survey.targets)
                                     {
-                                        sub.Add(info[0]);
+                                        var info = course.ToObject<List<string>>();
+                                        if (info.Count > 1)
+                                        {
+                                            sub.Add(info[0]);
+                                        }
                                     }
                                 }
                             }
+                                
                             if (addTmdidsCls.IsNotEmpty())
                             {
                                 addTmdidsCls.ForEach(x =>

+ 10 - 5
TEAMModelOS.FunctionV4/CosmosDB/TriggerVote.cs

@@ -17,6 +17,7 @@ using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using TEAMModelOS.SDK.Models.Service;
 using HTEXLib.COMM.Helpers;
 using Microsoft.Extensions.Configuration;
+using DocumentFormat.OpenXml.Office2013.Excel;
 
 namespace TEAMModelOS.FunctionV4
 {
@@ -131,17 +132,21 @@ namespace TEAMModelOS.FunctionV4
                             List<StuActivity> tmdActivities = new List<StuActivity>();
                             List<StuActivity> tchActivities = new List<StuActivity>();
                             List<string> sub = new();
-                            if (vote.targets.Count > 0)
+                            if (vote.tchLists.Count == 0)
                             {
-                                foreach (var course in vote.targets)
+                                if (vote.targets.Count > 0)
                                 {
-                                    var info = course.ToObject<List<string>>();
-                                    if (info.Count > 1)
+                                    foreach (var course in vote.targets)
                                     {
-                                        sub.Add(info[0]);
+                                        var info = course.ToObject<List<string>>();
+                                        if (info.Count > 1)
+                                        {
+                                            sub.Add(info[0]);
+                                        }
                                     }
                                 }
                             }
+                                
                             if (tmds.IsNotEmpty())
                             {
                                 tmds.ForEach(x =>