Browse Source

新增教研组ID,新增函数处理新的活动类型

zhouj1203@hotmail.com 3 years ago
parent
commit
34c1eb0897

+ 86 - 0
TEAMModelFunction/TriggerExamLite.cs

@@ -0,0 +1,86 @@
+using Azure.Cosmos;
+using HTEXLib.COMM.Helpers;
+using Microsoft.Azure.Documents;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Models.Cosmos.School;
+
+namespace TEAMModelFunction
+{
+    public static class TriggerExamLite
+    {
+        public static async void Trigger(AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+                    CosmosClient client, Document input, TriggerData tdata, AzureRedisFactory _azureRedis)
+        {
+            try
+            {
+                if ((tdata.status != null && tdata.status.Value == 404) || tdata.ttl > 0)
+                {
+                    return;
+                }
+                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;
+                }
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修评测活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
+                ExamLite lite = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamLite>(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 } });
+                if (lite != null)
+                {
+                    (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, lite.tchLists, lite.school);
+                    List<StuActivity> tchActivities = new List<StuActivity>();
+
+                    if (tchList.IsNotEmpty())
+                    {
+                        tchList.ForEach(x =>
+                        {
+                            tchActivities.Add(new StuActivity
+                            {
+                                pk = "Activity",
+                                id = lite.id,
+                                code = $"Activity-{x.id}",
+                                type = "ExamLite",
+                                name = lite.name,
+                                startTime = lite.startTime,
+                                endTime = lite.endTime,
+                                scode = lite.code,
+                                scope = lite.scope,
+                                school = lite.school,
+                                creatorId = lite.creatorId,
+                                subjects = new List<string> { "" },
+                                blob = null,
+                                owner = lite.owner,
+                                createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                taskStatus = -1,
+                                classIds = lite.tchLists
+                            });
+                        });
+                    }
+                    await TriggerStuActivity.SaveStuActivity(client, _dingDing, null, null, tchActivities);
+
+
+                }
+
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修评测异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+
+        }
+    }
+}

+ 85 - 0
TEAMModelFunction/TriggerWork.cs

@@ -0,0 +1,85 @@
+using Azure.Cosmos;
+using HTEXLib.COMM.Helpers;
+using Microsoft.Azure.Documents;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+
+namespace TEAMModelFunction
+{
+    public static class TriggerWork
+    {
+        public static async void Trigger(AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+                    CosmosClient client, Document input, TriggerData tdata, AzureRedisFactory _azureRedis)
+        {
+            try
+            {
+                if ((tdata.status != null && tdata.status.Value == 404) || tdata.ttl > 0)
+                {
+                    return;
+                }
+                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;
+                }
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
+                TeacherWork work = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<TeacherWork>(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 } });
+                if (work != null)
+                {
+                    (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, work.tchLists, work.school);
+                    List<StuActivity> tchActivities = new List<StuActivity>();
+
+                    if (tchList.IsNotEmpty())
+                    {
+                        tchList.ForEach(x =>
+                        {
+                            tchActivities.Add(new StuActivity
+                            {
+                                pk = "Activity",
+                                id = work.id,
+                                code = $"Activity-{x.id}",
+                                type = "TeacherWork",
+                                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);
+
+
+                }
+
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+
+        }
+    }
+}

+ 40 - 0
TEAMModelOS.SDK/Models/Service/SurveyService.cs

@@ -0,0 +1,40 @@
+using Azure.Cosmos;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelOS.SDK.Models.Service
+{
+    public static class SurveyService
+    {
+        public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, Survey survey)
+        {
+            try
+            {
+                survey.ttl = -1;
+                survey.code = "Survey-" + survey.school;
+                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                survey.createTime = now;
+
+                if (string.IsNullOrEmpty(survey.id))
+                {
+                    survey.id = Guid.NewGuid().ToString();
+                    await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(survey, new PartitionKey($"{survey.code}"));
+                }
+                else
+                {
+                    await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
+                }
+                return survey.id;
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-SurveyService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return "";
+
+            }
+        }
+    }
+}

+ 45 - 124
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -226,51 +226,27 @@ namespace TEAMModelOS.Controllers
                     study.ttl = -1;
                     study.ttl = -1;
                     study.code = "Study-" + pa.sId;
                     study.code = "Study-" + pa.sId;
                     study.createTime = now;
                     study.createTime = now;
+                    study.tchLists = pa.gId;
                     study.pId = areaStudy.id;
                     study.pId = areaStudy.id;
                     if (pa.gName.Count == 0)
                     if (pa.gName.Count == 0)
                     {
                     {
-                       /* string sName = pa.sName + "-" + "所有老师(未分组)";
+                        string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
                         allName.Add(sName);
-                        study.targets.Add("所有老师(未分组)");*/
-                        List<teacherInfo> teacs = await GetTeacherAll("", pa.sId);
-                        if (teacs.Count > 0)
-                        {
-                            foreach (teacherInfo info in teacs)
-                            {
-                                Setting setting = new()
-                                {
-                                    id = info.id,
-                                    name = info.name,
-                                    groupName = info.groupName
-                                };
-                                study.teachers.Add(setting);
-                            }
-
-                        }
+                        string json = "所有老师(未分组)";
+                        study.targets.Add(json.ToJsonString().ToObject<JsonElement>());
+                        //study.targets.Add("所有老师(未分组)");
+                       
                     }
                     }
                     else
                     else
                     {
                     {
                         //study.targets = pa.gName;
                         //study.targets = pa.gName;
+                        var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
+                        study.targets = tn;
                         foreach (string name in pa.gName)
                         foreach (string name in pa.gName)
                         {
                         {
                             //处理区级target
                             //处理区级target
                             string sName = pa.sName + "-" + name;
                             string sName = pa.sName + "-" + name;
-                            allName.Add(sName);
-                            List<teacherInfo> teacs = await GetTeacherAll(name, pa.sId);
-                            if (teacs.Count > 0)
-                            {
-                                foreach (teacherInfo info in teacs)
-                                {
-                                    Setting setting = new()
-                                    {
-                                        id = info.id,
-                                        name = info.name,
-                                        groupName = info.groupName
-                                    };
-                                    study.teachers.Add(setting);
-                                }
-
-                            }
+                            allName.Add(sName);                          
 
 
                         }
                         }
 
 
@@ -284,6 +260,7 @@ namespace TEAMModelOS.Controllers
                             trExam.owner = "area";
                             trExam.owner = "area";
                             trExam.school = pa.sId;
                             trExam.school = pa.sId;
                             trExam.areaId = id.GetString();
                             trExam.areaId = id.GetString();
+                            trExam.tchLists = pa.gId;
                             trExam.blob = $"/{trExam.areaId}/exam/{study.pId}/index.json";
                             trExam.blob = $"/{trExam.areaId}/exam/{study.pId}/index.json";
                             //处理发布对象
                             //处理发布对象
                             await getMoreExam(pa, trExam);
                             await getMoreExam(pa, trExam);
@@ -305,17 +282,18 @@ namespace TEAMModelOS.Controllers
                             trSurvey.owner = "area";
                             trSurvey.owner = "area";
                             trSurvey.school = pa.sId;
                             trSurvey.school = pa.sId;
                             trSurvey.areaId = id.GetString();
                             trSurvey.areaId = id.GetString();
+                            trSurvey.tchLists = pa.gId;
                             trSurvey.blob = $"/{trSurvey.areaId}/survey/{study.pId}/index.json";
                             trSurvey.blob = $"/{trSurvey.areaId}/survey/{study.pId}/index.json";
                             await getMoreSurvey(pa, trSurvey);
                             await getMoreSurvey(pa, trSurvey);
-                            //string surveyId = await SurveyService.saveMoreAsync(client, _dingDing, trSurvey);
-                            /*if (string.IsNullOrEmpty(surveyId))
+                            string surveyId = await SurveyService.saveMoreAsync(client, _dingDing, trSurvey);
+                            if (string.IsNullOrEmpty(surveyId))
                             {
                             {
                                 return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "问卷信息异常" });
                                 return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "问卷信息异常" });
                             }
                             }
                             else
                             else
                             {
                             {
                                 study.surveyId = surveyId;
                                 study.surveyId = surveyId;
-                            }*/
+                            }
                         }
                         }
                     }
                     }
                     if (string.IsNullOrEmpty(study.id))
                     if (string.IsNullOrEmpty(study.id))
@@ -330,7 +308,9 @@ namespace TEAMModelOS.Controllers
                     studies.Add(study);
                     studies.Add(study);
                 }
                 }
                 //areaStudy.targets = allName;
                 //areaStudy.targets = allName;
-                await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaStudy, new PartitionKey($"{areaStudy.code}"));
+                var atn = allName.ToJsonString().ToObject<List<JsonElement>>();
+                areaStudy.targets = atn;
+                await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync(areaStudy, new PartitionKey($"{areaStudy.code}"));
                 var ids = studies.Select(s => new { s.id, s.school, s.examId, s.surveyId });
                 var ids = studies.Select(s => new { s.id, s.school, s.examId, s.surveyId });
                 return Ok(new { id, ids, code = (int)HttpStatusCode.OK, acId = areaStudy.id });
                 return Ok(new { id, ids, code = (int)HttpStatusCode.OK, acId = areaStudy.id });
             }
             }
@@ -727,22 +707,18 @@ namespace TEAMModelOS.Controllers
                     trVote.areaId = id.GetString();
                     trVote.areaId = id.GetString();
                     trVote.owner = "area";
                     trVote.owner = "area";
                     trVote.pId = areaVote.id;
                     trVote.pId = areaVote.id;
+                    trVote.tchLists = pa.gId;
                     if (pa.gName.Count == 0)
                     if (pa.gName.Count == 0)
                     {
                     {
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
                         allName.Add(sName);
                         string json = "所有老师(未分组)";
                         string json = "所有老师(未分组)";
                         //var json = new { name = "所有老师(未分组)" };
                         //var json = new { name = "所有老师(未分组)" };
-                        trVote.targets.Add(json.ToObject<JsonElement>());
+                        trVote.targets.Add(json.ToJsonString().ToObject<JsonElement>());
                     }
                     }
                     else
                     else
                     {
                     {
-                        var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
-                       /* List<JsonElement> tn = new List<JsonElement>();
-                        foreach (string gn in pa.gName)
-                        {
-                            tn.Add(gn.ToJsonString().ToObject<JsonElement>());
-                        }*/
+                        var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();                      
                         trVote.targets = tn;
                         trVote.targets = tn;
                         foreach (string name in pa.gName)
                         foreach (string name in pa.gName)
                         {
                         {
@@ -770,7 +746,7 @@ namespace TEAMModelOS.Controllers
                     atn.Add(agn.ToObject<JsonElement>());
                     atn.Add(agn.ToObject<JsonElement>());
                 }*/
                 }*/
                 areaVote.targets =atn;
                 areaVote.targets =atn;
-                await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaVote, new PartitionKey($"{areaVote.code}"));
+                await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync(areaVote, new PartitionKey($"{areaVote.code}"));
                 var ids = votes.Select(s => new { s.id, s.school });
                 var ids = votes.Select(s => new { s.id, s.school });
                 return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
                 return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
             }
             }
@@ -870,7 +846,7 @@ namespace TEAMModelOS.Controllers
                 Survey areaSurvey = survey.ToObject<Survey>();
                 Survey areaSurvey = survey.ToObject<Survey>();
                 areaSurvey.owner = "area";
                 areaSurvey.owner = "area";
                 areaSurvey.ttl = -1;
                 areaSurvey.ttl = -1;
-                areaSurvey.code = "TrSurvey-" + id.GetString();
+                areaSurvey.code = "Survey-" + id.GetString();
                 areaSurvey.createTime = now;
                 areaSurvey.createTime = now;
                 if (string.IsNullOrEmpty(areaSurvey.id))
                 if (string.IsNullOrEmpty(areaSurvey.id))
                 {
                 {
@@ -883,18 +859,23 @@ namespace TEAMModelOS.Controllers
                     string code = pa.sId;
                     string code = pa.sId;
                     trSurvey.ttl = -1;
                     trSurvey.ttl = -1;
                     trSurvey.school = code;
                     trSurvey.school = code;
-                    trSurvey.code = "TrSurvey-" + code;
+                    trSurvey.code = "Survey-" + code;
                     trSurvey.createTime = now;
                     trSurvey.createTime = now;
                     trSurvey.areaId = id.GetString();
                     trSurvey.areaId = id.GetString();
                     trSurvey.owner = "area";
                     trSurvey.owner = "area";
+                    trSurvey.tchLists = pa.gId;
                     trSurvey.pId = areaSurvey.id;
                     trSurvey.pId = areaSurvey.id;
                     if (pa.gName.Count == 0)
                     if (pa.gName.Count == 0)
                     {
                     {
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         string sName = pa.sName + "-" + "所有老师(未分组)";
                         allName.Add(sName);
                         allName.Add(sName);
+                        string json = "所有老师(未分组)";
+                        trSurvey.targets.Add(json.ToJsonString().ToObject<JsonElement>());
                     }
                     }
                     else
                     else
                     {
                     {
+                        var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
+                        trSurvey.targets = tn;
                         foreach (string name in pa.gName)
                         foreach (string name in pa.gName)
                         {
                         {
                             //处理区级target
                             //处理区级target
@@ -919,8 +900,9 @@ namespace TEAMModelOS.Controllers
                     surveys.Add(trSurvey);
                     surveys.Add(trSurvey);
                 }
                 }
                 //areaSurvey.targets = allName;
                 //areaSurvey.targets = allName;
-
-                await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(areaSurvey, new PartitionKey($"{areaSurvey.code}"));
+                var atn = allName.ToJsonString().ToObject<List<JsonElement>>();
+                areaSurvey.targets = atn;
+                await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync(areaSurvey, new PartitionKey($"{areaSurvey.code}"));
                 var ids = surveys.Select(s => new { s.id, s.school });
                 var ids = surveys.Select(s => new { s.id, s.school });
                 return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
                 return Ok(new { id, ids, code = (int)HttpStatusCode.OK });
             }
             }
@@ -1057,101 +1039,39 @@ namespace TEAMModelOS.Controllers
 
 
             return teachers;
             return teachers;
         }
         }
-        private async Task<ExamLite> getMoreExam(parameter pa, ExamLite trExam)
+        private Task<ExamLite> getMoreExam(parameter pa, ExamLite trExam)
         {
         {
             if (pa.gName.Count == 0)
             if (pa.gName.Count == 0)
             {
             {
 
 
-                //trExam.targets.Add("所有老师(未分组)");
-                List<teacherInfo> teacs = await GetTeacherAll("", pa.sId);
-                if (teacs.Count > 0)
-                {
-                    foreach (teacherInfo info in teacs)
-                    {
-                        Record record = new()
-                        {
-                            id = info.id,
-                            name = info.name,
-                            groupName = info.groupName
-                        };
-                        trExam.teachers.Add(record);
-                    }
-
-                }
+                string json = "所有老师(未分组)";
+                trExam.targets.Add(json.ToJsonString().ToObject<JsonElement>());
+                
             }
             }
             else
             else
             {
             {
-                //trExam.targets = pa.gName;
-                foreach (string name in pa.gName)
-                {
-                    List<teacherInfo> teacs = await GetTeacherAll(name, pa.sId);
-                    if (teacs.Count > 0)
-                    {
-                        foreach (teacherInfo info in teacs)
-                        {
-                            Record record = new()
-                            {
-                                id = info.id,
-                                name = info.name,
-                                groupName = info.groupName
-                            };
-                            trExam.teachers.Add(record);
-                        }
-
-                    }
-
-                }
+                var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
+                trExam.targets = tn;               
 
 
             }
             }
-            return trExam;
+            return Task.FromResult(trExam);
         }
         }
-        private async Task<Survey> getMoreSurvey(parameter pa, Survey trSurvey)
+        private Task<Survey> getMoreSurvey(parameter pa, Survey trSurvey)
         {
         {
             if (pa.gName.Count == 0)
             if (pa.gName.Count == 0)
             {
             {
 
 
                 //trSurvey.targets.Add("所有老师(未分组)");
                 //trSurvey.targets.Add("所有老师(未分组)");
-                List<teacherInfo> teacs = await GetTeacherAll("", pa.sId);
-                if (teacs.Count > 0)
-                {
-                    foreach (teacherInfo info in teacs)
-                    {
-                        Record record = new()
-                        {
-                            id = info.id,
-                            name = info.name,
-                            groupName = info.groupName
-                        };
-                        //trSurvey.teachers.Add(record);
-                    }
-
-                }
+                string json = "所有老师(未分组)";
+                trSurvey.targets.Add(json.ToJsonString().ToObject<JsonElement>());
             }
             }
             else
             else
             {
             {
-                //trSurvey.targets = pa.gName;
-                foreach (string name in pa.gName)
-                {
-                    List<teacherInfo> teacs = await GetTeacherAll(name, pa.sId);
-                    if (teacs.Count > 0)
-                    {
-                        foreach (teacherInfo info in teacs)
-                        {
-                            Record record = new()
-                            {
-                                id = info.id,
-                                name = info.name,
-                                groupName = info.groupName
-                            };
-                            //trSurvey.teachers.Add(record);
-                        }
-
-                    }
-
-                }
+                var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
+                trSurvey.targets = tn;
 
 
             }
             }
-            return trSurvey;
+            return Task.FromResult(trSurvey);
         }
         }
 
 
         private async Task<List<(string id, string name)>> getInfo(CosmosClient client, string id) {
         private async Task<List<(string id, string name)>> getInfo(CosmosClient client, string id) {
@@ -1177,6 +1097,7 @@ namespace TEAMModelOS.Controllers
             public string sId { get; set; }
             public string sId { get; set; }
             public string sName { get; set; }
             public string sName { get; set; }
             public List<string> gName { get; set; }
             public List<string> gName { get; set; }
+            public List<string> gId { get; set; }
         }
         }