Jelajahi Sumber

[BI]IOT統計API 地理分項統計架構 改為"地理位置"+"月份"為統計Key

jeff 1 tahun lalu
induk
melakukan
bb5bd5b70e

+ 5 - 3
TEAMModelBI/Controllers/BIProductAnalysis/ProductAnalysisController.cs

@@ -167,9 +167,10 @@ namespace TEAMModelBI.Controllers.ProductAnalysis
                                 geoKey = resultRow.school.region + resultRow.school.province + resultRow.school.city + resultRow.school.dist;
                                 geoKey = resultRow.school.region + resultRow.school.province + resultRow.school.city + resultRow.school.dist;
                                 break;
                                 break;
                         }
                         }
-                        if(!string.IsNullOrWhiteSpace(geoKey))
+                        if (!string.IsNullOrWhiteSpace(geoKey))
                         {
                         {
-                            if(!geoDic.ContainsKey(geoKey)) geoDic.Add(geoKey, new ProdAnalysisApiResult());
+                            geoKey = $"{geoKey}-{resultRow.date}";
+                            if (!geoDic.ContainsKey(geoKey)) geoDic.Add(geoKey, new ProdAnalysisApiResult());
                             foreach (PropertyInfo propertyInfo in resultRow.GetType().GetProperties())
                             foreach (PropertyInfo propertyInfo in resultRow.GetType().GetProperties())
                             {
                             {
                                 if (calProperty.Contains(propertyInfo.Name))
                                 if (calProperty.Contains(propertyInfo.Name))
@@ -182,6 +183,7 @@ namespace TEAMModelBI.Controllers.ProductAnalysis
                                 }
                                 }
                             }
                             }
                             decimal learnParticipationTmp = (resultRow.learnParticipationCnt > 0) ? (decimal)resultRow.learnParticipationT / (decimal)resultRow.learnParticipationCnt : 0;
                             decimal learnParticipationTmp = (resultRow.learnParticipationCnt > 0) ? (decimal)resultRow.learnParticipationT / (decimal)resultRow.learnParticipationCnt : 0;
+                            geoDic[geoKey].date = resultRow.date;
                             geoDic[geoKey].learnParticipation = Math.Round(learnParticipationTmp, 2); //學習參與度指數(平均)
                             geoDic[geoKey].learnParticipation = Math.Round(learnParticipationTmp, 2); //學習參與度指數(平均)
                             geoDic[geoKey].deviceList = geoDic[geoKey].deviceList.Union(resultRow.deviceList).ToList();
                             geoDic[geoKey].deviceList = geoDic[geoKey].deviceList.Union(resultRow.deviceList).ToList();
                             geoDic[geoKey].deviceCnt = geoDic[geoKey].deviceList.Count;
                             geoDic[geoKey].deviceCnt = geoDic[geoKey].deviceList.Count;
@@ -204,7 +206,7 @@ namespace TEAMModelBI.Controllers.ProductAnalysis
                         var valNow = propertyInfo.GetValue(geoDicRow.Value);
                         var valNow = propertyInfo.GetValue(geoDicRow.Value);
                         propertyInfo.SetValue(geoResultRow, valNow);
                         propertyInfo.SetValue(geoResultRow, valNow);
                     }
                     }
-                    geoResultRow.geoInfo = geoDicRow.Key;
+                    geoResultRow.geoInfo = geoDicRow.Key.Split("-").First();
                     geoResult.Add(geoResultRow);
                     geoResult.Add(geoResultRow);
                 }
                 }
 
 

+ 222 - 311
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -2546,325 +2546,236 @@ namespace TEAMModelOS.Controllers
 
 
 
 
         /*
         /*
-             //自主學習綱領 資料架構測試
-            [HttpPost("test-selflearn-structure")]
-            public async Task<IActionResult> TestSelfLearnStructure(JsonElement json)
+        //自主學習綱領 資料架構測試
+        [HttpPost("test-selflearn-structure")]
+        public async Task<IActionResult> TestSelfLearnStructure(JsonElement json)
+        {
+            string tmid = "1595321354";
+            PaperSimple paper = new PaperSimple()
             {
             {
-                string tmid = "1595321354";
-                PaperSimple paper = new PaperSimple()
-                {
-                    id = "d774c93c-4af3-76ce-aca4-6e8a3254873b",
-                    subjectId = "c5f96ea0-e65c-f15c-dc59-410da564c185",
-                    code = "Paper-1595321354",
-                    name = "國文洩題試卷",
-                    blob = "/exam/0bfe6855-289b-4d7a-b5f5-9a027acf277c/paper/c5f96ea0-e65c-f15c-dc59-410da564c185",
-                    scope = "private",
-                    multipleRule = 1,
-                    point = new List<double>() { 25, 25, 25, 25 },
-                    answers = new List<List<string>>() { new List<string>() { "D", "C", "B", "A" } },
-                    type = new List<string>() { "single", "single", "single", "single" },
-                    field = new List<int>() { 1, 1, 1, 1 }
-                };
-                ////個人課程
-                //主體
-                SelfLearn selfLearnT = new SelfLearn();
-                selfLearnT.code = $"SelfLearn-{tmid}";
-                selfLearnT.id = "a6dc752f-7cae-44a5-9b7b-92cfe71cea14";
-                selfLearnT.scope = "private";
-                selfLearnT.name = "測試課程課綱";
-                selfLearnT.course = new IdName();
-                selfLearnT.course.id = "ae64e6a4-54f3-10df-a7f3-79dbe252d295";
-                selfLearnT.course.name = "測試課程001";
-                selfLearnT.creatorId = $"{tmid}";
-                selfLearnT.creatorName = "Miss Lo";
-                selfLearnT.release = true;
-                selfLearnT.groupLists.Add(new IdName { id = "a986bf87-da87-4bd3-bd90-19ee9fd52836", name = "測試課程名單" });
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnT);
-                //節點:章節
-                SelfLearnNode selfLearnNodeTChapter = new SelfLearnNode();
-                selfLearnNodeTChapter.code = $"SelfLearn-{tmid}";
-                selfLearnNodeTChapter.id = "0990cbb6-3228-41d0-aeb0-62209f37dc0d";
-                selfLearnNodeTChapter.name = "第一章節";
-                selfLearnNodeTChapter.selfLearnId = selfLearnT.id;
-                selfLearnNodeTChapter.nodeType = "chapter";
-                selfLearnNodeTChapter.openType = "order";
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeTChapter);
-                //節點:項目
-                SelfLearnNode selfLearnNodeTContent = new SelfLearnNode();
-                selfLearnNodeTContent.code = $"SelfLearn-{tmid}";
-                selfLearnNodeTContent.id = "5627184f-e9b4-4ceb-a1d0-47727db569b1";
-                selfLearnNodeTContent.name = "四則運算";
-                selfLearnNodeTContent.selfLearnId = selfLearnT.id;
-                selfLearnNodeTContent.selfLearnNodeId = selfLearnNodeTChapter.id;
-                selfLearnNodeTContent.nodeType = "content";
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeTContent);
-                //內容:評量
-                SelfLearnContentExam selfLearnTContentExam = new SelfLearnContentExam();
-                selfLearnTContentExam.code = $"SelfLearn-{tmid}";
-                selfLearnTContentExam.id = "07e6fdd2-6083-4eb6-ac6d-06421edb0b48";
-                selfLearnTContentExam.name = "隨堂測驗1";
-                selfLearnTContentExam.selfLearnNodeId = selfLearnNodeTContent.id;
-                selfLearnTContentExam.contentType = "exam";
-                selfLearnTContentExam.examInfo.code = $"Exam-{tmid}";
-                selfLearnTContentExam.examInfo.scope = "private";
-                selfLearnTContentExam.examInfo.owner = "teacher";
-                selfLearnTContentExam.examInfo.creatorId = tmid;
-                selfLearnTContentExam.examInfo.source = "0";
-                selfLearnTContentExam.examInfo.qamode = 0;
-                selfLearnTContentExam.examInfo.stuLists.Add("a986bf87-da87-4bd3-bd90-19ee9fd52836");
-                selfLearnTContentExam.examInfo.subjects = new List<ExamSubject>();
-                ExamSubject privateExamSubject = new ExamSubject();
-                privateExamSubject.id = "e1d817e5-71b3-bc50-52ac-fa828e5f38d6";
-                privateExamSubject.name = "test";
-                privateExamSubject.classCount = 0;
-                selfLearnTContentExam.examInfo.subjects.Add(privateExamSubject);
-                selfLearnTContentExam.examInfo.papers.Add(paper);
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnTContentExam);
-
-                ////學校課程
-                //主體
-                SelfLearn selfLearnS = new SelfLearn();
-                selfLearnS.pk = "SelfLearn";
-                selfLearnS.code = $"SelfLearn-{tmid}";
-                selfLearnS.id = "f05f79f2-c58d-4e27-8214-48385e2ac3cd";
-                selfLearnS.scope = "private";
-                selfLearnS.school = "hbgl";
-                selfLearnS.name = "數學一年級上學期課綱";
-                selfLearnS.subject = new IdName();
-                selfLearnS.subject.id = "c5f96ea0-e65c-f15c-dc59-410da564c185";
-                selfLearnS.subject.name = "數學";
-                selfLearnS.period = new IdName();
-                selfLearnS.period.id = "127e71a7-0ca8-82b8-476b-5269b78066f7";
-                selfLearnS.period.name = "測試國中";
-                selfLearnS.course = new IdName();
-                selfLearnS.course.id = "0d4fa541-ad4f-bee1-c604-764275f6d10e";
-                selfLearnS.course.name = "數學一";
-                selfLearnS.creatorId = $"{tmid}";
-                selfLearnS.creatorName = "Miss Lo";
-                selfLearnS.release = true;
-                selfLearnS.classes.Add(new IdName { id = "d3090c56-21de-4cc8-a962-a7e7eaa2e913", name = "2023年A班" });
-                selfLearnS.groupLists.Add(new IdName { id = "54a39ec1-be0b-43cd-a978-f3133552f291", name = "七年A班" });
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnS);
-                //節點:章節
-                SelfLearnNode selfLearnNodeSChapter = new SelfLearnNode();
-                selfLearnNodeSChapter.code = $"SelfLearn-{tmid}";
-                selfLearnNodeSChapter.id = "77172663-aa17-44c6-8259-61870c44121f";
-                selfLearnNodeSChapter.name = "第一章節";
-                selfLearnNodeSChapter.selfLearnId = selfLearnS.id;
-                selfLearnNodeSChapter.nodeType = "chapter";
-                selfLearnNodeSChapter.openType = "order";
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeSChapter);
-                //節點:項目
-                SelfLearnNode selfLearnNodeSContent = new SelfLearnNode();
-                selfLearnNodeSContent.code = $"SelfLearn-{tmid}";
-                selfLearnNodeSContent.id = "f28c6ecd-38a6-4edb-9160-363a116b8c3b";
-                selfLearnNodeSContent.name = "四則運算";
-                selfLearnNodeSContent.selfLearnId = selfLearnS.id;
-                selfLearnNodeSContent.selfLearnNodeId = selfLearnNodeSChapter.id;
-                selfLearnNodeSContent.nodeType = "content";
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeSContent);
-                //內容:評量
-                SelfLearnContentExam selfLearnSContentExam = new SelfLearnContentExam();
-                selfLearnSContentExam.code = $"SelfLearn-{tmid}";
-                selfLearnSContentExam.id = "3f088f49-fefa-4af5-a324-c577ffb6d1f8";
-                selfLearnSContentExam.name = "隨堂測驗1";
-                selfLearnSContentExam.selfLearnNodeId = selfLearnNodeSContent.id;
-                selfLearnSContentExam.contentType = "exam";
-                selfLearnSContentExam.examInfo.papers.Add(paper);
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnSContentExam);
+                id = "d774c93c-4af3-76ce-aca4-6e8a3254873b",
+                subjectId = "c5f96ea0-e65c-f15c-dc59-410da564c185",
+                code = "Paper-1595321354",
+                name = "國文洩題試卷",
+                blob = "/exam/0bfe6855-289b-4d7a-b5f5-9a027acf277c/paper/c5f96ea0-e65c-f15c-dc59-410da564c185",
+                scope = "private",
+                multipleRule = 1,
+                point = new List<double>() { 25, 25, 25, 25 },
+                answers = new List<List<string>>() { new List<string>() { "D", "C", "B", "A" } },
+                type = new List<string>() { "single", "single", "single", "single" },
+                field = new List<int>() { 1, 1, 1, 1 }
+            };
+            ////個人課程
+            //主體
+            SelfLearn selfLearnT = new SelfLearn();
+            selfLearnT.code = $"SelfLearn-{tmid}";
+            selfLearnT.id = "a6dc752f-7cae-44a5-9b7b-92cfe71cea14";
+            selfLearnT.scope = "private";
+            selfLearnT.name = "測試課程課綱";
+            selfLearnT.course = new IdName();
+            selfLearnT.course.id = "ae64e6a4-54f3-10df-a7f3-79dbe252d295";
+            selfLearnT.course.name = "測試課程001";
+            selfLearnT.creatorId = $"{tmid}";
+            selfLearnT.creatorName = "Miss Lo";
+            selfLearnT.release = true;
+            selfLearnT.groupLists.Add(new IdName { id = "a986bf87-da87-4bd3-bd90-19ee9fd52836", name = "測試課程名單" });
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnT);
+            //節點:章節
+            SelfLearnNode selfLearnNodeTChapter = new SelfLearnNode();
+            selfLearnNodeTChapter.code = $"SelfLearn-{tmid}";
+            selfLearnNodeTChapter.id = "0990cbb6-3228-41d0-aeb0-62209f37dc0d";
+            selfLearnNodeTChapter.name = "第一章節";
+            selfLearnNodeTChapter.selfLearnId = selfLearnT.id;
+            selfLearnNodeTChapter.nodeType = "chapter";
+            selfLearnNodeTChapter.openType = "order";
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeTChapter);
+            //節點:項目
+            SelfLearnNode selfLearnNodeTContent = new SelfLearnNode();
+            selfLearnNodeTContent.code = $"SelfLearn-{tmid}";
+            selfLearnNodeTContent.id = "5627184f-e9b4-4ceb-a1d0-47727db569b1";
+            selfLearnNodeTContent.name = "四則運算";
+            selfLearnNodeTContent.selfLearnId = selfLearnT.id;
+            selfLearnNodeTContent.selfLearnNodeId = selfLearnNodeTChapter.id;
+            selfLearnNodeTContent.nodeType = "content";
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeTContent);
+            //內容:評量
+            SelfLearnContentExam selfLearnTContentExam = new SelfLearnContentExam();
+            selfLearnTContentExam.code = $"SelfLearn-{tmid}";
+            selfLearnTContentExam.id = "07e6fdd2-6083-4eb6-ac6d-06421edb0b48";
+            selfLearnTContentExam.name = "隨堂測驗1";
+            selfLearnTContentExam.selfLearnId = selfLearnT.id;
+            selfLearnTContentExam.selfLearnNodeId = selfLearnNodeTContent.id;
+            selfLearnTContentExam.contentType = "exam";
+            ExamInfo examT = new ExamInfo();
+            examT.pk = "Exam";
+            examT.scope = "private";
+            examT.owner = "teacher";
+            examT.code = $"Exam-{tmid}";
+            examT.creatorId = $"{tmid}";
+            examT.name = "隨堂測驗1";
+            examT.papers.Add(paper);
+            selfLearnTContentExam.examInfo = examT;
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnTContentExam);
+
+            ////學校課程
+            //主體
+            SelfLearn selfLearnS = new SelfLearn();
+            selfLearnS.pk = "SelfLearn";
+            selfLearnS.code = $"SelfLearn-{tmid}";
+            selfLearnS.id = "f05f79f2-c58d-4e27-8214-48385e2ac3cd";
+            selfLearnS.scope = "private";
+            selfLearnS.school = "hbgl";
+            selfLearnS.name = "數學一年級上學期課綱";
+            selfLearnS.subject = new IdName();
+            selfLearnS.subject.id = "c5f96ea0-e65c-f15c-dc59-410da564c185";
+            selfLearnS.subject.name = "數學";
+            selfLearnS.period = new IdName();
+            selfLearnS.period.id = "127e71a7-0ca8-82b8-476b-5269b78066f7";
+            selfLearnS.period.name = "測試國中";
+            selfLearnS.course = new IdName();
+            selfLearnS.course.id = "0d4fa541-ad4f-bee1-c604-764275f6d10e";
+            selfLearnS.course.name = "數學一";
+            selfLearnS.creatorId = $"{tmid}";
+            selfLearnS.creatorName = "Miss Lo";
+            selfLearnS.release = true;
+            selfLearnS.classes.Add(new IdName { id = "d3090c56-21de-4cc8-a962-a7e7eaa2e913", name = "2023年A班" });
+            selfLearnS.groupLists.Add(new IdName { id = "54a39ec1-be0b-43cd-a978-f3133552f291", name = "七年A班" });
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnS);
+            //節點:章節
+            SelfLearnNode selfLearnNodeSChapter = new SelfLearnNode();
+            selfLearnNodeSChapter.code = $"SelfLearn-{tmid}";
+            selfLearnNodeSChapter.id = "77172663-aa17-44c6-8259-61870c44121f";
+            selfLearnNodeSChapter.name = "第一章節";
+            selfLearnNodeSChapter.selfLearnId = selfLearnS.id;
+            selfLearnNodeSChapter.nodeType = "chapter";
+            selfLearnNodeSChapter.openType = "order";
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeSChapter);
+            //節點:項目
+            SelfLearnNode selfLearnNodeSContent = new SelfLearnNode();
+            selfLearnNodeSContent.code = $"SelfLearn-{tmid}";
+            selfLearnNodeSContent.id = "f28c6ecd-38a6-4edb-9160-363a116b8c3b";
+            selfLearnNodeSContent.name = "四則運算";
+            selfLearnNodeSContent.selfLearnId = selfLearnS.id;
+            selfLearnNodeSContent.selfLearnNodeId = selfLearnNodeSChapter.id;
+            selfLearnNodeSContent.nodeType = "content";
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeSContent);
+            //內容:評量
+            SelfLearnContentExam selfLearnSContentExam = new SelfLearnContentExam();
+            selfLearnSContentExam.code = $"SelfLearn-{tmid}";
+            selfLearnSContentExam.id = "3f088f49-fefa-4af5-a324-c577ffb6d1f8";
+            selfLearnSContentExam.name = "隨堂測驗1";
+            selfLearnSContentExam.selfLearnId = selfLearnS.id;
+            selfLearnSContentExam.selfLearnNodeId = selfLearnNodeSContent.id;
+            selfLearnSContentExam.contentType = "exam";
+            ExamInfo examS = new ExamInfo();
+            examS.pk = "Exam";
+            examS.scope = "school";
+            examS.owner = "teacher";
+            examS.code = $"Exam-{tmid}";
+            examS.creatorId = $"{tmid}";
+            examS.name = "隨堂測驗1";
+            examS.papers.Add(paper);
+            selfLearnSContentExam.examInfo = examS;
+            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnSContentExam);
 
 
-                return Ok();
+            return Ok();
 
 
+        }
+        //自主學習綱領 生成評量架構測試
+        public async void TestSelfLearnCreateExam(JsonElement json)
+        {
+            //輸入項:startTime (-1 會以現在時間記入)
+            long startTime = (!json.TryGetProperty("startTime", out JsonElement startTimeJ)) ? startTimeJ.GetInt64() : -1;
+
+            var client = _azureCosmos.GetCosmosClient();
+            string tmid = "1595321354";
+            long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            //取得自主學習綱領內容、自主學習綱領主體
+            string code = $"SelfLearn-{tmid}";
+            string selfLearnContentExamId = "3f088f49-fefa-4af5-a324-c577ffb6d1f8";
+            SelfLearn selfLearn = new SelfLearn();
+            SelfLearnContentExam contentExam = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearnContentExam>(selfLearnContentExamId, new PartitionKey(code));
+            if (contentExam != null)
+            {
+                string selfLearnId = contentExam.selfLearnId;
+                selfLearn = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearn>(selfLearnId, new PartitionKey(code));
             }
             }
-            //自主學習綱領 生成評量架構測試
-            public async void TestSelfLearnCreateExam(JsonElement json)
+            if(!string.IsNullOrWhiteSpace(selfLearn.id))
             {
             {
-                string tmid = "1595321354";
-                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                //取得自主學習綱領內容
-                string contentExamCode = $"SelfLearn-{tmid}";
-                string contentExamId = "3f088f49-fefa-4af5-a324-c577ffb6d1f8";
-                SelfLearnContentExam contentExam = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearnContentExam>(contentExamId, new PartitionKey(contentExamCode));
-                if (contentExam != null)
+                //補足實體化需要項目
+                //targets.row:
+                //個人課程: [0]:課程ID(CourseBase.id)[1]stuListId(GroupList.id)
+                //學校課程 編制班[0]:課程ID(CourseBase.id)[1]"class"[2]classId
+                //學校課程 選課班[0]:課程ID(CourseBase.id)[1]"teach"[2]stuListId(GroupList.id)
+                ExamInfo actExamInfo = new ExamInfo(); //要生成的Exam
+                actExamInfo.creatorId = tmid;
+                IdName selfLearnSubject = selfLearn.subject;
+                IdName selfLearnCourse = selfLearn.course;
+                IdName selfLearnPeriod = selfLearn.period;
+                if(contentExam.examInfo.scope.Equals("school")) //學校 編制班、選課班
+                {
+                    actExamInfo.school = selfLearn.school;
+                    actExamInfo.period.id = selfLearnPeriod.id;
+                    actExamInfo.period.name = selfLearnPeriod.name;
+                    actExamInfo.subjects.Add(new ExamSubject() { id = selfLearnSubject.id, name = selfLearnSubject.name });
+                    foreach(IdName classRow in selfLearn.classes)
+                    {
+                        actExamInfo.classes.Add(classRow.id);
+                        List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", "class", classRow.id };
+                        actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
+                    }
+                    foreach (IdName groupRow in selfLearn.groupLists)
+                    {
+                        actExamInfo.stuLists.Add(groupRow.id);
+                        List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", "teach", groupRow.id };
+                        actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
+                    }
+                }
+                else if(contentExam.examInfo.scope.Equals("private"))
+                {
+                    foreach (IdName groupRow in selfLearn.groupLists)
+                    {
+                        actExamInfo.subjects.Add(new ExamSubject() { id = selfLearn.course.id, name = selfLearn.course.name });
+                        actExamInfo.stuLists.Add(groupRow.id);
+                        List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", groupRow.id };
+                        actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
+                    }
+                }
+                actExamInfo.papers = contentExam.papers;
+                //以下是ExamController生成評量邏輯
+                actExamInfo.createTime = now;
+                actExamInfo.startTime = startTime;
+                if (actExamInfo.startTime <= 0) actExamInfo.startTime = now;
+                List<string> classes = ExamService.getClasses(actExamInfo.classes, actExamInfo.stuLists);
+                (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, selfLearn.school);
+                actExamInfo.stuCount = tchList.Count;
+                actExamInfo.id = Guid.NewGuid().ToString(); //假設每次生成新的評量;實作的時候應該在Exam埋入自主課綱相關的ID,如果可取得此ID的評量則更新
+                actExamInfo.progress = (actExamInfo.startTime > now) ? "pending" : "going";
+                var messageBlob = new ServiceBusMessage();
+                if (actExamInfo.scope.Equals("school"))
                 {
                 {
-                    ExamInfo exam = new ExamInfo();
-                    exam.ttl = -1;
+                    actExamInfo.size = await _azureStorage.GetBlobContainerClient(actExamInfo.school).GetBlobsSize($"exam/{actExamInfo.id}");
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = actExamInfo.school }, _serviceBus, _configuration, _azureRedis);
                 }
                 }
-                //{
-                //  "pk": "Exam",
-                //  "id": null,
-                //  "code": "1595321354",
-                //  "school": "tbslgb",
-                //  "name": "國文洩題試卷",
-                //  "creatorId": "1595321354",
-                //  "type": "",
-                //  "subjects": [
-                //    {
-                //      "id": "e1d817e5-71b3-bc50-52ac-fa828e5f38d6",
-                //      "name": "test"
-                //    }
-                //  ],
-                //  "grades": [],
-                //  "papers": [
-                //    {
-                //      "id": "d774c93c-4af3-76ce-aca4-6e8a3254873b",
-                //      "code": "Paper-1595321354",
-                //      "name": "國文洩題試卷",
-                //      "blob": "/paper/國文洩題試卷",
-                //      "scope": "private",
-                //      "sheet": null,
-                //      "periodId": null,
-                //      "multipleRule": 1,
-                //      "answers": [
-                //        [
-                //          "D"
-                //        ],
-                //        [
-                //          "C"
-                //        ],
-                //        [
-                //          "B"
-                //        ],
-                //        [
-                //          "A"
-                //        ]
-                //      ],
-                //      "point": [
-                //        25,
-                //        25,
-                //        25,
-                //        25
-                //      ],
-                //      "knowledge": [
-                //        [],
-                //        [],
-                //        [],
-                //        []
-                //      ],
-                //      "field": [
-                //        1,
-                //        1,
-                //        1,
-                //        1
-                //      ],
-                //      "type": [
-                //        "single",
-                //        "single",
-                //        "single",
-                //        "single"
-                //      ],
-                //      "subjectName": "test",
-                //      "subjectId": "e1d817e5-71b3-bc50-52ac-fa828e5f38d6"
-                //    }
-                //  ],
-                //  "examType": null,
-                //  "year": 2024,
-                //  "source": "0",
-                //  "classes": [],
-                //  "stuLists": [
-                //    "4dd434a8-a94a-4373-9a05-1a1add533a71"
-                //  ],
-                //  "targets": [
-                //    [
-                //      "e1d817e5-71b3-bc50-52ac-fa828e5f38d6",
-                //      "4dd434a8-a94a-4373-9a05-1a1add533a71"
-                //    ]
-                //  ],
-                //  "startTime": -1,
-                //  "endTime": 1710604799999,
-                //  "scope": "private",
-                //  "createDate": 1710472208137,
-                //  "owner": "teacher",
-                //  "isCompletion": 0
-                //}{
-                //  "pk": "Exam",
-                //  "id": null,
-                //  "code": "1595321354",
-                //  "school": "tbslgb",
-                //  "name": "國文洩題試卷",
-                //  "creatorId": "1595321354",
-                //  "type": "",
-                //  "subjects": [
-                //    {
-                //      "id": "e1d817e5-71b3-bc50-52ac-fa828e5f38d6",
-                //      "name": "test"
-                //    }
-                //  ],
-                //  "grades": [],
-                //  "papers": [
-                //    {
-                //      "id": "d774c93c-4af3-76ce-aca4-6e8a3254873b",
-                //      "code": "Paper-1595321354",
-                //      "name": "國文洩題試卷",
-                //      "blob": "/paper/國文洩題試卷",
-                //      "scope": "private",
-                //      "sheet": null,
-                //      "periodId": null,
-                //      "multipleRule": 1,
-                //      "answers": [
-                //        [
-                //          "D"
-                //        ],
-                //        [
-                //          "C"
-                //        ],
-                //        [
-                //          "B"
-                //        ],
-                //        [
-                //          "A"
-                //        ]
-                //      ],
-                //      "point": [
-                //        25,
-                //        25,
-                //        25,
-                //        25
-                //      ],
-                //      "knowledge": [
-                //        [],
-                //        [],
-                //        [],
-                //        []
-                //      ],
-                //      "field": [
-                //        1,
-                //        1,
-                //        1,
-                //        1
-                //      ],
-                //      "type": [
-                //        "single",
-                //        "single",
-                //        "single",
-                //        "single"
-                //      ],
-                //      "subjectName": "test",
-                //      "subjectId": "e1d817e5-71b3-bc50-52ac-fa828e5f38d6"
-                //    }
-                //  ],
-                //  "examType": null,
-                //  "year": 2024,
-                //  "source": "0",
-                //  "classes": [],
-                //  "stuLists": [
-                //    "4dd434a8-a94a-4373-9a05-1a1add533a71"
-                //  ],
-                //  "targets": [
-                //    [
-                //      "e1d817e5-71b3-bc50-52ac-fa828e5f38d6",
-                //      "4dd434a8-a94a-4373-9a05-1a1add533a71"
-                //    ]
-                //  ],
-                //  "startTime": -1,
-                //  "endTime": 1710604799999,
-                //  "scope": "private",
-                //  "createDate": 1710472208137,
-                //  "owner": "teacher",
-                //  "isCompletion": 0
-                //}
+                else
+                {
+                    actExamInfo.size = await _azureStorage.GetBlobContainerClient(actExamInfo.creatorId).GetBlobsSize($"exam/{actExamInfo.id}");
+                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = actExamInfo.creatorId }, _serviceBus, _configuration, _azureRedis);
+                }
+                int n = 0;
+                List<string> sheetIds = new List<string>();
+                foreach (PaperSimple simple in actExamInfo.papers)
+                {
+                    simple.blob = $"/exam/{actExamInfo.id}/paper/{actExamInfo.subjects[n].id}";
+                    n++;
+                    simple.sheet = null;
+                }
+                ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(actExamInfo, new PartitionKey($"{actExamInfo.code}"));
+                await BIStats.SetTypeAddStats(client, _dingDing, exam.school, "Exam", 1);//BI统计增/减量
             }
             }
-         */
+
+        }
+        */
 
 
     }
     }
 }
 }