|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|