using Azure.Messaging.ServiceBus; 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.Extension; using TEAMModelOS.SDK.Models; using TEAMModelOS.SDK; using Microsoft.Azure.Cosmos; using TEAMModelOS.SDK.Models.Cosmos.Common; using TEAMModelOS.Function; using static TEAMModelOS.SDK.Models.Cosmos.Student.StudentAnalysis; namespace TEAMModelOS.CosmosDBTriggers { public class TriggerArt { public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing, CosmosClient client, JsonElement input, TriggerData tdata, AzureRedisFactory _azureRedis, IConfiguration _configuration, HttpTrigger _httpTrigger) { try { if ((tdata.status != null && tdata.status.Value == 404)) { await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(tdata.id, new PartitionKey(tdata.code)); ActivityList data = input.ToObject(); //删除blob 相关资料 await _azureStorage.GetBlobServiceClient().DeleteBlobs(_dingDing, tdata.school, new List { $"art/{tdata.id}" }); // await IESActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, data); var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord"); List records = await table_cancel.FindListByDict(new Dictionary() { { "RowKey", tdata.id } }); foreach (var record in records) { try { await table_cancel.DeleteSingle(record.PartitionKey, record.RowKey); await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber); } catch (Exception) { continue; } } return; } var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord"); 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; } ArtEvaluation art = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync(tdata.id, new PartitionKey($"{tdata.code}")); if (art != null) { string PartitionKey = string.Format("{0}{1}{2}", art.code, "-", art.progress); List voteRecords = await table.FindListByDict(new Dictionary() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } }); switch (art.progress) { case "pending": var messageVote = new ServiceBusMessage(new { tdata.id, progress = "going", code = tdata.code }.ToJsonString()); messageVote.ApplicationProperties.Add("name", "Art"); if (voteRecords.Count > 0) { long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime)); try { await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), voteRecords[0].sequenceNumber); } catch (Exception) { } voteRecords[0].sequenceNumber = start; await table.SaveOrUpdate(voteRecords[0]); } else { long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime)); ChangeRecord changeRecord = new ChangeRecord { RowKey = tdata.id, PartitionKey = PartitionKey, sequenceNumber = start, msgId = messageVote.MessageId }; await table.Save(changeRecord); } break; case "going": /* if (art.classes.Count > 0) { List classes = ExamService.getClasses(art.classes, art.stuLists); (List tmdIds, List classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, art.school, null); var addStudentsCls = tmdIds.FindAll(x => x.type == 2); var addTmdidsCls = tmdIds.FindAll(x => x.type == 1); List tmds = new List(); if (addTmdidsCls.IsNotEmpty()) { tmds.AddRange(addTmdidsCls.Select(x => x.id).ToList()); } List stuActivities = new List(); List tmdActivities = new List(); List tchActivities = new List(); List sub = new(); if (art.subjects.Count > 0) { foreach (var course in art.subjects) { sub.Add(course.id); } } if (tmds.IsNotEmpty()) { tmds.ForEach(x => { HashSet classIds = new HashSet(); classLists.ForEach(z => { z.members.ForEach(y => { if (y.id.Equals(x) && y.type == 1) { classIds.Add(z.id); } }); }); tmdActivities.Add(new StuActivity { pk = "Activity", id = art.id, code = $"Activity-{x}", type = "Art", name = art.name, startTime = art.startTime, endTime = art.endTime, scode = art.code, scope = art.scope, school = art.school, creatorId = art.creatorId, subjects = sub, blob = null, owner = art.owner, createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), ext = new Dictionary() { { "subjects", art.subjects.ToJsonString().ToObject() } }, taskStatus = -1, classIds = classIds.ToList() }); }); } if (addStudentsCls.IsNotEmpty()) { addStudentsCls.ForEach(x => { HashSet classIds = new HashSet(); classLists.ForEach(z => { z.members.ForEach(y => { if (y.id.Equals(x.id) && y.code.Equals(art.school) && y.type == 2) { classIds.Add(z.id); } }); }); stuActivities.Add(new StuActivity { pk = "Activity", id = art.id, code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}", type = "Art", name = art.name, startTime = art.startTime, endTime = art.endTime, scode = art.code, scope = art.scope, school = art.school, creatorId = art.creatorId, subjects = sub, blob = null, owner = art.owner, createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), ext = new Dictionary() { { "subjects", art.subjects.ToJsonString().ToObject() } }, taskStatus = -1, classIds = classIds.ToList() }); }); } await IESActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, tchActivities); }*/ try { var messageVoteEnd = new ServiceBusMessage(new { tdata.id, progress = "finish", tdata.code }.ToJsonString()); messageVoteEnd.ApplicationProperties.Add("name", "Art"); if (voteRecords.Count > 0) { long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime)); try { await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), voteRecords[0].sequenceNumber); } catch (Exception) { } voteRecords[0].sequenceNumber = end; await table.SaveOrUpdate(voteRecords[0]); } else { long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime)); ChangeRecord changeRecord = new() { RowKey = tdata.id, PartitionKey = PartitionKey, sequenceNumber = end, msgId = messageVoteEnd.MessageId }; await table.Save(changeRecord); } } catch (Exception e) { await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-艺术评测going{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組); } finally { string pkey = string.Format("{0}{1}{2}", art.code, "-", "pending"); await table.DeleteSingle(pkey, tdata.id); } break; case "finish": //判定是否是区级创建的活动内容 /* if (art.lost.Count == 0 && art.pass == 0) { if (art.owner.Equals("area") && string.IsNullOrEmpty(art.pId)) { *//* List<(string id, string code, List settings)> artSchools = new(); string ql = $"select c.id,c.school,c.settings,c.classes from c where c.pk = 'Art' and c.pId = '{art.id}'"; await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIteratorSql(queryText: ql)) { using var json = await JsonDocument.ParseAsync(item.Content); if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0) { var accounts = json.RootElement.GetProperty("Documents").EnumerateArray(); while (accounts.MoveNext()) { JsonElement account = accounts.Current; List settings = account.GetProperty("settings").ToObject>(); artSchools.Add((account.GetProperty("id").GetString(), account.GetProperty("school").GetString(), settings)); } } } foreach (var (id, code, settings) in artSchools) { List<(string eId, string sId)> ids = new(); var examIds = settings.SelectMany(s => s.task).Where(a => a.type == 1).Select(z => new { z.acId, z.subject }).ToList(); examIds.ForEach(x => { ids.Add((x.acId, x.subject)); }); List<(string code, string sub, List stu)> stuInfo = await getLostAsync(ids, client, code); List stus = new(); foreach (var lost in stuInfo) { if (stus.Count == 0) { stus = stus.Union(lost.stu).ToList(); } else { stus = stus.Intersect(lost.stu).ToList(); } LostStudent lostStudent = new() { code = lost.code, subject = lost.sub, stu = lost.stu.Count }; art.lost.Add(lostStudent); } art.miss.Add(stus.Count); } art.pass = 1; await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(art, art.id, new PartitionKey(art.code));*//* } else { //获取当前艺术评价相关评测ID目前暂时排除区级发布的评测信息 *//*List<(string eId, string sId)> ids = new(); var examId = art.settings.SelectMany(x => x.task).Where(c => c.type == 1).Select(z => new { z.acId, z.subject }).ToList(); examId.ForEach(x => { ids.Add((x.acId, x.subject)); }); List<(string code, string sub, List stu)> stuInfo = await getLostAsync(ids, client, art.school); List stus = new(); foreach (var (code, sub, stu) in stuInfo) { if (stus.Count == 0) { stus = stus.Union(stu).ToList(); } else { stus = stus.Intersect(stu).ToList(); } LostStudent lostStudent = new() { code = code, subject = sub, stu = stu.Count }; art.lost.Add(lostStudent); } art.miss.Add(stus.Count); //art.miss = stus.Count; art.pass = 1; await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(art, art.id, new PartitionKey(art.code));*//* } }*/ //根据学校编码去获取区级ID try { School scInfo = new(); //School scInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync($"{art.school}", partitionKey: new PartitionKey("Base")); var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{art.school}", partitionKey: new PartitionKey("Base")); if (response.StatusCode == System.Net.HttpStatusCode.OK) { using var cJson = await JsonDocument.ParseAsync(response.Content); scInfo = cJson.ToObject(); } ArtSetting setting = new(); try { var artResponse = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{scInfo.areaId}", partitionKey: new PartitionKey("ArtSetting")); if (response.StatusCode == System.Net.HttpStatusCode.OK) { using var json = await JsonDocument.ParseAsync(artResponse.Content); setting = json.ToObject(); } } catch (Exception e) { } if (art.classes.Any()) { //获取该艺术评测的评测Id List<(string id, string subjectId)> ids = new(); List examClassResults = new(); var examId = art.settings.SelectMany(x => x.task).Where(c => c.type == 1).Select(z => new { z.acId, z.subject }).ToList(); examId.ForEach(x => { ids.Add((x.acId, x.subject)); }); List results = new(); results = ids.Select(x => x.id).ToList(); await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.examId in ({string.Join(",", results.Select(x => $"'{x}'"))})", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{art.school}") })) { using var json = await JsonDocument.ParseAsync(item.Content); if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0) { foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray()) { examClassResults.Add(obj.ToObject()); } } } //获取该艺术评测下面的评测活动 List exams = new(); await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIteratorSql(queryText: $"select value(c) from c where c.pk = 'Exam' and c.id in ({string.Join(",", results.Select(o => $"'{o}'"))})")) { exams.Add(item); } var sta = examClassResults.SelectMany(x => x.status).ToList(); var ansCount = sta.Where(x => x == 0).ToList(); var persent = ansCount.Count * 1.0 / sta.Count * 100; var period = scInfo.period.Where(x => x.id.Equals(art.period.id))?.FirstOrDefault(); List studentArtResults = new(); string sql = $"SELECT value c FROM c where c.pk='ArtResult'"; await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student) .GetItemQueryIteratorSql(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{art.id}") })) { studentArtResults.Add(item); } List>> tasks = new List>>(); //新增数据推送 obj => Portrait Portrait portrait = new() { schoolCode = art.school, periodId = art.period?.id, subjectId = "subject_art" }; //var period = scInfo.period.Where(x => x.id.Equals(art.period.id)).FirstOrDefault(); List<(string ptype, string subId, List<(string name, List kno)> knos)> knoledge = new(); //List subs = new List { "subject_painting", "subject_music" }; if (exams.Count == 0) return; foreach (var ss in art.subjects) { if (string.IsNullOrEmpty(exams[0].papers[0].periodId)) { knoledge.Add(await getKnowledge("university", "hbcn", client, ss.id, "be32942d-97a9-52ba-45d6-2e5b722583f5")); } else { knoledge.Add(await getKnowledge(art.periodType, exams.Where(c => c.subjects[0].id.Equals(ss.id))?.FirstOrDefault().papers[0].code, client, ss.id, exams.Where(c => c.subjects[0].id.Equals(ss.id))?.FirstOrDefault().papers[0].periodId)); } } List<(string name, double score, double aver, string subject)> blockScore = new(); List<(List<(string name, double score, double point, string subject)> studentScore, string stuId)> studentScores = new(); foreach (var exam in exams) { HashSet knowledge = new HashSet(); List point = new List(); List> result = new List>(); List classes = new List(); //求单个知识点所占分数 List per = new List(); if (exam.papers[0].knowledge != null && exam.papers[0].knowledge.Count > 0) { exam.papers[0].knowledge.ForEach(k => { k.ForEach(e => { knowledge.Add(e); }); }); } point = exam.papers[0].point; List knowledgeName = new List(); foreach (string cla in knowledge) { knowledgeName.Add(cla); } for (int k = 0; k < knowledgeName.Count; k++) { if (null == knowledgeName[k]) { knowledgeName.Remove(knowledgeName[k]); } } List Score = new List(); //List<(string name, double score, string subject)> pointScore = new(); List stus = examClassResults.Where(c => c.examId.Equals(exam.id)).SelectMany(z => z.studentIds).ToList(); List> stuScores = examClassResults.Where(c => c.examId.Equals(exam.id)).SelectMany(z => z.studentScores).ToList(); foreach (string id in stus) { //double scores = 0; List<(string name, double score, double point, string subject)> studentScore = new(); for (int k = 0; k < knowledgeName.Count; k++) { int n = 0; double OnePoint = 0; double scores = 0; exam.papers[0].knowledge.ForEach(kno => { if (kno.Contains(knowledgeName[k])) { var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0; OnePoint += point[n] * itemPersent; int index = stus.IndexOf(id); if (stuScores[index][n] > 0) { scores += stuScores[index][n] * itemPersent; } } n++; }); studentScore.Add((knowledgeName[k], Math.Round(scores, 2), OnePoint, exam.subjects[0].id)); } studentScores.Add((studentScore, id)); } for (int k = 0; k < knowledgeName.Count; k++) { double OnePoint = 0; int n = 0; double scores = 0; exam.papers[0].knowledge.ForEach(kno => { if (kno.Contains(knowledgeName[k])) { var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0; OnePoint += point[n] * itemPersent; foreach (string id in stus) { int index = stus.IndexOf(id); if (stuScores[index][n] > 0) { scores += stuScores[index][n] * itemPersent; } } } n++; }); double sc = stus.Count > 0 ? Math.Round(scores * 1.0 / stus.Count, 2) : 0; blockScore.Add((knowledgeName[k], OnePoint, sc, exam.subjects[0].id)); //blockScore.AddRange(pointScore); } } var bls = blockScore.GroupBy(x => x.subject).Select(v => new { subjectId = v.Key, knoScore = v.ToList().GroupBy(k => k.name).Select(z => new { knoName = z.Key, score = z.ToList().Sum(j => j.score), aver = z.ToList().Sum(j => j.aver) }) }); //List<(string subId,List<(string name, List kno)>)> subjectKnow = knoledge.Select(x => new { x.subId, x.knos }).ToList(); //var subjectKnow; var subjectKnow = string.IsNullOrEmpty(exams[0].papers[0].periodId) ? knoledge.Select(x => new { x.subId, x.knos }).ToList() : knoledge.Where(c => c.ptype.Equals(art.periodType)).Select(x => new { x.subId, x.knos }).ToList(); /*if (string.IsNullOrEmpty(exams[0].papers[0].periodId)) { var subjectKnow = knoledge.Select(x => new { x.subId, x.knos }).ToList(); } else { var subjectKnow = knoledge.Where(c => c.ptype.Equals(art.periodType)).Select(x => new { x.subId, x.knos }).ToList(); }*/ List<(string subjectId, List<(string name, double score, double persent, double aver, List dim)> bks)> bs = new(); List<(string subjectId, List<(string stuId, List<(string name, double score, double point, List dim)> values)> stuBks)> sbs = new(); List<(string name, double score, double av, string sId)> stuBlockScore = new(); foreach (var bb in subjectKnow) { var kno1 = bls.Where(c => c.subjectId.Equals(bb.subId)).SelectMany(x => x.knoScore).ToList(); var stuInfo = studentScores.Select(c => new { c.stuId, subInfo = c.studentScore.Where(x => x.subject.Equals(bb.subId)).ToList() }).Where(z => z.subInfo.Count > 0).ToList(); //var kno2 = dimensions.Where(c => c.subjectBind.Equals(bb.subId)).Select(x => new { x.dimension,x.blocks}).ToList(); List<(string name, double score, double aver)> blockScores = new(); foreach (var k2 in bb.knos) { double bsc = 0; double avs = 0; foreach (var k3 in kno1) { if (null != k2.kno && k2.kno.Contains(k3.knoName)) { bsc += k3.score; avs += k3.aver; } } foreach (var stu in stuInfo) { double realScore = 0; double realPoint = 0; foreach (var subScore in stu.subInfo) { if (null != k2.kno && k2.kno.Contains(subScore.name)) { realScore = subScore.score; realPoint = subScore.point; } } stuBlockScore.Add((k2.name, realScore, realPoint, stu.stuId)); } blockScores.Add((k2.name, bsc, avs)); } var stuBlock = stuBlockScore.GroupBy(x => (x.sId)).Select(c => new { stuId = c.Key, block = c.ToList().GroupBy(b => b.name).Select(q => new { name = q.Key, score = q.ToList().Sum(q => q.score), point = q.ToList().Sum(q => q.av), dimension = setting.dimensions.Where(s => s.blocks.Contains(q.Key)).Select(x => x.dimension).ToList() }) }).ToList(); var blk = blockScores.Select(x => new { x.name, x.score, persent = Math.Round(x.aver > 0 ? x.aver / x.score : 0, 2), x.aver, dimension = setting.dimensions.Where(s => s.blocks.Contains(x.name)).Select(x => x.dimension) }); List<(string name, double score, double persent, double aver, List dim)> bks = new(); List<(string stuId, List<(string name, double score, double point, List dim)> values)> stuBks = new(); foreach (var bk in blk) { bks.Add((bk.name, bk.score, bk.persent, bk.aver, bk.dimension.ToList())); } foreach (var stuBlk in stuBlock) { List<(string name, double score, double point, List dim)> values = new(); foreach (var lk in stuBlk.block) { values.Add((lk.name, lk.score, lk.point, lk.dimension)); } stuBks.Add((stuBlk.stuId, values)); } bs.Add((bb.subId, bks)); sbs.Add((bb.subId, stuBks)); } var blocks = bs.Select(x => new { x.subjectId, dim = x.bks.Select(z => new { z.name, z.score, z.persent, z.aver, z.dim }) }); var stuBlocks = sbs.Select(x => new { x.subjectId, dim = x.stuBks.Select(z => new { z.stuId, blk = z.values.Select(c => new { c.name, c.score, c.point, c.dim }) }) }); //获取维度得分率 var dim = setting.dimensions.GroupBy(a => a.subjectBind).Select(x => new { x.Key, dim = x.ToList().Select(c => new { c.dimension, persent = Math.Round(c.blocks.Select(z => new { persent = Math.Round(bs.Where(z => z.subjectId.Equals(x.Key)).SelectMany(k => k.bks).Where(q => q.name.Equals(z)).Sum(h => h.score) > 0 ? bs.Where(z => z.subjectId.Equals(x.Key)).SelectMany(k => k.bks).Where(q => q.name.Equals(z)).Sum(h => h.aver) / bs.Where(z => z.subjectId.Equals(x.Key)).SelectMany(k => k.bks).Where(q => q.name.Equals(z)).Sum(h => h.score) : 0, 2) }).Sum(o => o.persent) / c.blocks.Count, 2) }) }); //获取学期信息 var (currSemester, studyYear, currSemesterDate, date, nextSemester) = SchoolService.GetSemester(period, art.startTime); //总分的占比情况 foreach (var rs in studentArtResults) { foreach (var res in rs.results) { if (res.quotaId.Equals("quota_21") && res.score > -1 && res.score < 95) { /*res.score *= 1.5; if (res.score >= 95) { res.score = new Random().Next(90, 99); }*/ //res.score = Math.Round(res.score); } } //if (rs.totalScore == 0) //{ foreach (var sc in rs.subjectScores) { //if (sc.score == 0) //{ /* var subjectMore = rs.results.GroupBy(x => x.subjectId).Select(c => new { subject = c.Key, list = c.ToList().Select(m => new { m.quotaId,m.score}) }); var totalScore = subjectMore.Select(x => new { x.subject, quotaScroe = x.list.Select(c => new { c.quotaId, c.score }), });*/ /* var quotaPercent = setting.quotas.Select(x => new { x.id, x.percent, score = x.children.Select(c => new { realx = rs.results.Where(r => r.quotaId.Equals(c.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * c.percent * 0.01, scorex = c.children.Select(s => new { realy = rs.results.Where(r => r.quotaId.Equals(s.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * s.percent * 0.01 }).Sum(n => n.realy) * c.percent * 0.01 }).Sum(n => n.realx + n.scorex) * x.percent * 0.01 });*/ double scoreAll = 0; foreach (var quota in setting.quotas) { if (quota.children.Count != 0) { double score_2 = 0; foreach (var quota_1 in quota.children) { if (quota_1.children.Count != 0) { double score_3 = 0; foreach (var quota_2 in quota_1.children) { foreach (var result in rs.results) { if (result.quotaId.Equals(quota_2.id) && result.subjectId.Equals(sc.subjectId) && result.score > -1) { score_3 += result.score * quota_2.percent * 0.01; } } } score_2 += score_3 * quota_1.percent * 0.01; } else { foreach (var result in rs.results) { if (result.quotaId.Equals(quota_1.id) && result.subjectId.Equals(sc.subjectId) && result.score > -1) { score_2 += result.score * quota_1.percent * 0.01; } } } } scoreAll += score_2 * quota.percent * 0.01; } } double realScore = Math.Round(scoreAll, 2); sc.score = realScore; //} } rs.totalScore = Math.Round(rs.subjectScores.Where(m => m.score >= 0).Sum(z => z.score), 2); tasks.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(rs, rs.id, new PartitionKey(rs.code))); PortraitStudent student = new() { studentId = rs.studentId, name = rs.studentName, classId = rs.classIds[0] }; SemesterData semesterData = new() { examName = art.name, examId = art.id, examDate = art.startTime, examType = "", year = studyYear, semesterId = currSemester.id, totalScore = 200, sumScore = rs.totalScore, excellenceRate = 0, passRate = 0, }; int index = 0; foreach (var sj in art.subjects) { ItemScore item = new() { name = sj.name, score = rs.subjectScores.Where(x => x.subjectId.Equals(sj.id)).FirstOrDefault().score, time = art.startTime, totalScore = 100, id = sj.id, type = sj.id, block = stuBlocks.Where(c => c.subjectId.Equals(sj.id)).SelectMany(x => x.dim).Where(z => z.stuId.Equals(rs.studentId))?.FirstOrDefault().blk, kno = studentScores.Where(c => c.stuId.Equals(rs.studentId)).SelectMany(c => c.studentScore).Where( p => p.subject.Equals(sj.id)).Select(z => new { z.name, z.score, z.point, block = subjectKnow.Where(v => v.subId.Equals(sj.id)).SelectMany(k => k.knos).Where(c => null != c.kno && c.kno.Contains(z.name)).Select(x => x.name) }), dim = dim.Where(c => c.Key.Equals(sj.id))?.FirstOrDefault().dim }; index++; semesterData.itemScore.Add(item); } student.semesterData.Add(semesterData); portrait.students.Add(student); //} } if (tasks.Count > 0) { await Task.WhenAll(tasks); } //获取学生信息 //(List rmembers, List groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school); /* foreach (var member in studentArtResults) { }*/ if (null != period && persent >= 60) { string location = $"{Environment.GetEnvironmentVariable("Option:Location")}"; var responseData = await _httpTrigger.RequestHttpTrigger(portrait, location, "upsert-student-portrait"); } } } catch (Exception e) { await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-艺术评测finish{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組); } finally { string pk = string.Format("{0}{1}{2}", art.code, "-", "going"); await table.DeleteSingle(pk, tdata.id); } break; } } } catch (CosmosException e) { await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.StatusCode}", GroupNames.醍摩豆服務運維群組); } catch (Exception ex) { await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}艺术评价异常{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); } } private static async Task<(string key, string subId, List<(string name, List kno)>)> getKnowledge(string key, string school, CosmosClient client, string subjectBid, string pId) { try { var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school, new PartitionKey($"Base")); string subjectId = string.Empty; List knowledges = new(); List<(string name, List kno)> blocks = new(); if (response.StatusCode == System.Net.HttpStatusCode.OK) { using var json = await JsonDocument.ParseAsync(response.Content); School sc = json.ToObject(); var subjects = sc.period.Where(p => p.id.Equals(pId)).Select(x => x.subjects); foreach (var sj in subjects) { foreach (var s in sj) { if (!string.IsNullOrWhiteSpace(s.bindId) && s.bindId.Equals(subjectBid)) { subjectId = s.id; } } } string code = $"Knowledge-{school}-{subjectId}"; StringBuilder sql = new StringBuilder($"select value(c) from c"); if (!string.IsNullOrWhiteSpace(pId)) { sql.Append($" where c.periodId = '{pId}'"); } await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") })) { knowledges.Add(item); } } foreach (var know in knowledges) { foreach (var block in know.blocks) { blocks.Add((block.name, block.points)); } } return (key, subjectBid, blocks); } catch (Exception e) { return (null, null, null); } } } }