CrazyIter_Bin 1 rok temu
rodzic
commit
744dd6f930

+ 3 - 0
TEAMModelOS.FunctionV4/CosmosDB/CommonTrigger.cs

@@ -106,6 +106,9 @@ namespace TEAMModelOS.FunctionV4
                                     case "Art":
                                         await TriggerArt.Trigger(_coreAPIHttpService, _serviceBus, _azureStorage, _dingDing, client, element, data, _azureRedis, _configuration);
                                         break;
+                                    case "ExamImport":
+                                        await TriggerExamImport.Trigger(_coreAPIHttpService, _azureCosmos, _serviceBus, _azureStorage, _dingDing, client, element, data, _httpClient, _configuration);
+                                        break;
                                 }
                             }
                         }

+ 122 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerExamImport.cs

@@ -0,0 +1,122 @@
+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;
+using Azure.Cosmos;
+using System.Net.Http;
+using TEAMModelOS.SDK.Models.Cosmos.School;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using HTEXLib.COMM.Helpers;
+
+namespace TEAMModelOS.FunctionV4.CosmosDB
+{
+    public class TriggerExamImport
+    {
+        public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+            CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration)
+        { 
+            ExamImport examImport= input.ToObject<ExamImport>();
+            if (examImport != null) {
+                HashSet<string> ids = new HashSet<string>();
+                foreach (var x in examImport.subjects)
+                {
+                    foreach (var y in x.students)
+                    {
+                        string id = $"{examImport.year}-{examImport.semesterId}-{y.id}";
+                        ids.Add(id);
+                    }
+                }
+                HashSet<OverallEducation> overallEducations = new HashSet<OverallEducation>();
+                string sql = $"select value c from  c where c.id in ({string.Join(",", ids.Select(z => $"'{z}'"))}) and c.periodId='{examImport.periodId}' ";
+                var result = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<OverallEducation>(sql, $"OverallEducation-{examImport.school}");
+                IEnumerable<string> notInDbIds = null;
+                if (result.list.IsNotEmpty())
+                {
+                    notInDbIds= ids.Except(result.list.Select(x => x.id));
+                    overallEducations = new HashSet<OverallEducation>(result.list);
+                }
+                else {
+                    notInDbIds = ids;
+                }
+                foreach (var x in examImport.subjects)
+                {
+                    foreach (var y in x.students)
+                    {
+                        string id = $"{examImport.year}-{examImport.semesterId}-{y.id}";
+                        var overallEducation =  overallEducations.Where(z => z.id.Equals(id)).First();
+                        if (overallEducation != null)
+                        {
+                            var exam = overallEducation.intelligence.Find(f => f.examId.Equals(x.id));
+                            if (exam != null)
+                            {
+                                var item = exam.itemScore.Find(f => f.id.Equals(x.id));
+                                if (item != null)
+                                {
+                                    item.name= x.name;
+                                    item.score = y.score;
+                                    item.totalScore = x.items.Sum(b => b.score);
+                                    item.type = examImport.type;
+                                }
+                                else {
+                                    exam.itemScore.Add(new ItemScore { name = x.name, score = y.score, totalScore = x.items.Sum(b => b.score), type = examImport.type, id = x.id });
+                                }
+                                exam.sumScore = examImport.subjects.SelectMany(z => z.students).Where(b => b.id.Equals(y.id)).Sum(v => v.score);
+                                exam.totalScore = examImport.subjects.SelectMany(t => t.items).Sum(n => n.score);
+                                exam.rate = examImport.subjects.SelectMany(z => z.students).Where(b => b.id.Equals(y.id)).Sum(v => v.score) * 1.0 / examImport.subjects.SelectMany(t => t.items).Sum(n => n.score);
+                                exam.examType = examImport.type;
+                                exam.examDate = examImport.time;
+                                exam.examName=examImport.name;
+                            }
+                            else {
+                                overallEducation.intelligence.Add(new EducationScore
+                                {
+                                    examName = examImport.name,
+                                    examId = examImport.id,
+                                    examDate = examImport.time,
+                                    examType = examImport.type,
+                                    totalScore = examImport.subjects.SelectMany(t => t.items).Sum(n => n.score),
+                                    sumScore = examImport.subjects.SelectMany(z => z.students).Where(b => b.id.Equals(y.id)).Sum(v => v.score),
+                                    rate = examImport.subjects.SelectMany(z => z.students).Where(b => b.id.Equals(y.id)).Sum(v => v.score) * 1.0 / examImport.subjects.SelectMany(t => t.items).Sum(n => n.score),
+                                    itemScore = new List<ItemScore> { new ItemScore { name = x.name, score = y.score, totalScore = x.items.Sum(b => b.score), type = examImport.type ,id=x.id} }
+                                });
+                            }
+                        }
+                        else {
+                            overallEducation = new OverallEducation {
+                                id = id,
+                                code = $"OverallEducation-{examImport.school}",
+                                pk = "OverallEducation",
+                                periodId = examImport.periodId,
+                                year = examImport.year,
+                                semesterId = examImport.semesterId,
+                                schoolCode = examImport.school,
+                                studentId = y.id,
+                                name = y.name,
+                                classId = y.classId,
+                                stuYear = y.stuYear,
+                                intelligence = new List<EducationScore> { new EducationScore {
+                                    examName=examImport.name,
+                                    examId=examImport.id,
+                                    examDate=examImport.time,
+                                    examType=examImport.type,
+                                    totalScore= examImport.subjects.SelectMany(t=>t.items).Sum(n=>n.score),
+                                    sumScore= examImport.subjects.SelectMany(z=>z.students).Where(b=>b.id.Equals(y.id)).Sum(v=>v.score),
+                                    rate=examImport.subjects.SelectMany(z=>z.students).Where(b=>b.id.Equals(y.id)).Sum(v=>v.score) *1.0 / examImport.subjects.SelectMany(t=>t.items).Sum(n=>n.score),
+                                    itemScore= new List<ItemScore>{ new ItemScore { name=x.name,score=y.score,totalScore=x.items.Sum(b=>b.score),type=examImport.type } }
+                                } }
+                            };
+                            overallEducations.Add(overallEducation);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 115 - 0
TEAMModelOS.FunctionV4/CosmosDB/TriggerVirtueImport.cs

@@ -0,0 +1,115 @@
+//using Microsoft.Extensions.Configuration;
+//using System;
+//using System.Collections.Generic;
+//using System.Linq;
+//using System.Net.Http;
+//using System.Text;
+//using System.Text.Json;
+//using System.Threading.Tasks;
+//using TEAMModelOS.SDK.DI;
+//using TEAMModelOS.SDK;
+//using Azure.Cosmos;
+//using TEAMModelOS.SDK.Models.Cosmos.School;
+//using TEAMModelOS.SDK.Models;
+//using TEAMModelOS.SDK.Extension;
+//using HTEXLib.COMM.Helpers;
+//using OpenXmlPowerTools;
+
+//namespace TEAMModelOS.FunctionV4.CosmosDB
+//{
+//    public class TriggerVirtueImport
+//    {
+//        public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
+//           CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration)
+//        {
+//            VirtueImport  virtueImport = input.ToObject<VirtueImport>();
+//            if (virtueImport != null)
+//            {
+//                HashSet<string> ids = new HashSet<string>();
+//                foreach (var x in virtueImport.students)
+//                {
+
+//                    string id = $"{virtueImport.year}-{virtueImport.semesterId}-{x.id}";
+//                    ids.Add(id);
+//                }
+//                HashSet<OverallEducation> overallEducations = new HashSet<OverallEducation>();
+//                string sql = $"select value c from  c where c.id in ({string.Join(",", ids.Select(z => $"'{z}'"))}) and c.periodId='{virtueImport.periodId}' ";
+//                var result = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<OverallEducation>(sql, $"OverallEducation-{virtueImport.school}");
+//                IEnumerable<string> notInDbIds = null;
+//                if (result.list.IsNotEmpty())
+//                {
+//                    notInDbIds = ids.Except(result.list.Select(x => x.id));
+//                    overallEducations = new HashSet<OverallEducation>(result.list);
+//                }
+//                else
+//                {
+//                    notInDbIds = ids;
+//                }
+//                foreach (var y in virtueImport.students)
+//                {
+//                    string id = $"{virtueImport.year}-{virtueImport.semesterId}-{y.id}";
+//                    var overallEducation = overallEducations.Where(z => z.id.Equals(id)).First();
+//                    if (overallEducation != null)
+//                    {
+//                        var exam = overallEducation.virtue.Find(f => f.examId.Equals(x.id));
+//                        if (exam != null)
+//                        {
+//                            var item = exam.itemScore.Find(f => f.id.Equals(x.id));
+//                            if (item != null)
+//                            {
+//                                item.name = y.name;
+//                                item.score = y.score;
+//                                item.type = virtueImport.type;
+//                            }
+//                            else
+//                            {
+//                                exam.itemScore.Add(new ItemScore { name = x.name, score = y.score, totalScore = x.items.Sum(b => b.score), type = virtueImport.type, id = x.id });
+//                            }
+//                            exam.examType = virtueImport.type;
+//                            exam.examDate = virtueImport.time;
+//                            exam.examName = virtueImport.name;
+//                        }
+//                        else
+//                        {
+//                            overallEducation.virtue.Add(new EducationScore
+//                            {
+//                                examName = virtueImport.name,
+//                                examId = virtueImport.id,
+//                                examDate = virtueImport.time,
+//                                examType = virtueImport.type,
+//                                itemScore = new List<ItemScore> { new ItemScore { name = x.name, score = y.score, totalScore = x.items.Sum(b => b.score), type = virtueImport.type, id = x.id } }
+//                            });
+//                        }
+//                    }
+//                    else
+//                    {
+//                        overallEducation = new OverallEducation
+//                        {
+//                            id = id,
+//                            code = $"OverallEducation-{virtueImport.school}",
+//                            pk = "OverallEducation",
+//                            periodId = virtueImport.periodId,
+//                            year = virtueImport.year,
+//                            semesterId = virtueImport.semesterId,
+//                            schoolCode = virtueImport.school,
+//                            studentId = y.id,
+//                            name = y.name,
+//                            classId = y.classId,
+//                            stuYear = y.stuYear,
+//                            virtue = new List<EducationScore> { new EducationScore {
+//                                    examName=virtueImport.name,
+//                                    examId=virtueImport.id,
+//                                    examDate=virtueImport.time,
+//                                    examType=virtueImport.type,
+//                                itemScore= new List<ItemScore>{ new ItemScore { name=x.name,score=y.score,totalScore=x.items.Sum(b=>b.score),type=virtueImport.type } }
+//                                } 
+//                            }
+//                        };
+//                        overallEducations.Add(overallEducation);
+//                    }
+//                }
+//            }
+//        }
+
+//    }
+//}