liqk 3 anni fa
parent
commit
adf7f9a001

+ 1 - 1
TEAMModelFunction/TriggerStudy.cs

@@ -78,7 +78,7 @@ namespace TEAMModelFunction
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}投票活动异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修活动异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
 
         }

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/Teacher/TeacherWork.cs

@@ -97,6 +97,7 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         public int? status { get; set; } = 0;
         public long? size { get; set; } = 0;
+        public string areaId { get; set; }
         public List<Submits> teachers { get; set; } = new List<Submits>();
     }
     public class Submits {

+ 40 - 0
TEAMModelOS.SDK/Models/Service/TeacherWorkService.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 TeacherWorkService
+	{
+        public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, TeacherWork work)
+        {
+            try
+            {
+                work.ttl = -1;
+                work.code = "TeacherWork-" + work.school;
+                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                work.createTime = now;
+
+                if (string.IsNullOrEmpty(work.id))
+                {
+                    work.id = Guid.NewGuid().ToString();
+                    await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(work, new PartitionKey($"{work.code}"));
+                }
+                else
+                {
+                    await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(work, new PartitionKey($"{work.code}"));
+                }
+                return work.id;
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-TeacherWorkService-saveMore\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return "";
+
+            }
+        }
+    }
+}

+ 42 - 0
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -229,6 +229,7 @@ namespace TEAMModelOS.Controllers
                     study.createTime = now;
                     study.tchLists = pa.gId;
                     study.pId = areaStudy.id;
+                    study.scope = "school";
                     study.targetType = "research";
                     if (pa.gName.Count == 0)
                     {
@@ -263,6 +264,7 @@ namespace TEAMModelOS.Controllers
                             trExam.school = pa.sId;
                             trExam.areaId = id.GetString();
                             trExam.tchLists = pa.gId;
+                            trExam.scope = "school";
                             trExam.targetType = "research";
                             trExam.blob = $"/{trExam.areaId}/exam/{study.pId}/index.json";
                             //处理发布对象
@@ -286,6 +288,7 @@ namespace TEAMModelOS.Controllers
                             trSurvey.school = pa.sId;
                             trSurvey.areaId = id.GetString();
                             trSurvey.tchLists = pa.gId;
+                            trSurvey.scope = "school";
                             trSurvey.targetType = "research";
                             trSurvey.blob = $"/{trSurvey.areaId}/survey/{study.pId}/index.json";
                             await getMoreSurvey(pa, trSurvey);
@@ -299,6 +302,28 @@ namespace TEAMModelOS.Controllers
                                 study.surveyId = surveyId;
                             }
                         }
+                        if (setting.Equals("work"))
+                        {
+                            if (!request.TryGetProperty("work", out JsonElement work)) return BadRequest();
+                            TeacherWork teacherWork = work.ToObject<TeacherWork>();
+                            teacherWork.owner = "area";
+                            teacherWork.school = pa.sId;
+                            teacherWork.areaId = id.GetString();
+                            teacherWork.tchLists = pa.gId;
+                            teacherWork.scope = "school";
+                            teacherWork.targetType = "research";
+                            teacherWork.blob = $"/{teacherWork.areaId}/survey/{study.pId}/index.json";
+                            await getMoreWork(pa, teacherWork);
+                            string workId = await TeacherWorkService.saveMoreAsync(client, _dingDing, teacherWork);
+                            if (string.IsNullOrEmpty(workId))
+                            {
+                                return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "作业活动异常" });
+                            }
+                            else
+                            {
+                                study.workId = workId;
+                            }
+                        }
                     }
                     if (string.IsNullOrEmpty(study.id))
                     {
@@ -1165,6 +1190,23 @@ namespace TEAMModelOS.Controllers
             }
             return Task.FromResult(trSurvey);
         }
+        private Task<TeacherWork> getMoreWork(parameter pa, TeacherWork work)
+        {
+            if (pa.gName.Count == 0)
+            {
+
+                //trSurvey.targets.Add("所有老师(未分组)");
+                string json = "所有老师(未分组)";
+                work.targets.Add(json.ToJsonString().ToObject<JsonElement>());
+            }
+            else
+            {
+                var tn = pa.gName.ToJsonString().ToObject<List<JsonElement>>();
+                work.targets = tn;
+
+            }
+            return Task.FromResult(work);
+        }
 
         private async Task<List<(string id, string name)>> getInfo(CosmosClient client, string id) {
             List<(string id, string name)> scInfos = new List<(string id, string name)>();