zhouj1203@hotmail.com 2 rokov pred
rodič
commit
61f320255b

+ 95 - 57
TEAMModelOS.FunctionV4/CosmosDB/TriggerArt.cs

@@ -18,6 +18,8 @@ using TEAMModelOS.SDK.Models.Service;
 using Microsoft.AspNetCore.Http;
 using OpenXmlPowerTools;
 using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Office2016.Excel;
+using static TEAMModelOS.SDK.Models.Cosmos.Student.StudentAnalysis;
 
 namespace TEAMModelOS.FunctionV4.CosmosDB
 {
@@ -243,55 +245,55 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                             {
                                 if (art.owner.Equals("area") && string.IsNullOrEmpty(art.pId))
                                 {
-                                   /* List<(string id, string code, List<Tasks> 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").GetItemQueryStreamIterator(queryText: ql))
-                                    {
-                                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                                        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<Tasks> settings = account.GetProperty("settings").ToObject<List<Tasks>>();
-                                                artSchools.Add((account.GetProperty("id").GetString(), account.GetProperty("school").GetString(), settings));
+                                    /* List<(string id, string code, List<Tasks> 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").GetItemQueryStreamIterator(queryText: ql))
+                                     {
+                                         using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                                         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<Tasks> settings = account.GetProperty("settings").ToObject<List<Tasks>>();
+                                                 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<string> stu)> stuInfo = await getLostAsync(ids, client, code);
-                                        List<string> 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);
+                                             }
+                                         }
+                                     }
+                                     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<string> stu)> stuInfo = await getLostAsync(ids, client, code);
+                                         List<string> 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<ArtEvaluation>(art, art.id, new PartitionKey(art.code));*/
+                                     }
+                                     art.pass = 1;
+                                     await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ArtEvaluation>(art, art.id, new PartitionKey(art.code));*/
                                 }
                                 else
                                 {
@@ -335,22 +337,58 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
                                 .GetItemQueryIterator<StudentArtResult>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{art.id}") }))
                             {
                                 studentArtResults.Add(item);
+                            }
+                            //根据学校编码去获取区级ID
+                            School scInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{art.school}", partitionKey: new Azure.Cosmos.PartitionKey("Base"));
+                            ArtSetting setting = null;
+                            try
+                            {
+                                setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<ArtSetting>($"{scInfo.areaId}", partitionKey: new Azure.Cosmos.PartitionKey("ArtSetting"));
+                            }
+                            catch (Exception e)
+                            {
+
                             }
                             List<Task<ItemResponse<StudentArtResult>>> tasks = new List<Task<ItemResponse<StudentArtResult>>>();
+                            //总分的占比情况
+
                             foreach (var rs in studentArtResults)
                             {
-                                if (rs.totalScore == 0)
-                                {
-                                    /*foreach (var sc in rs.subjectScores) {
-                                        if (sc.score == 0) { 
-                                            
-                                        }
-                                    }*/
+                                //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
+                                                {
+                                                    real = rs.results.Where(r => r.quotaId.Equals(c.id) && r.subjectId.Equals(sc.subjectId) && r.score > -1).FirstOrDefault()?.score * c.percent * 0.01,
+                                                    score = c.children.Select(s => new {
+                                                        real = 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.real) * c.percent * 0.01
+                                                }).Sum(n => n.real + n.score) * x.percent * 0.01
+                                            });
+                                            sc.score = (double)quotaPercent.Sum(c => c.score);
+                                        //}
+                                    }
                                     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)));
-                                }                 
+                                //}
                             }
-                            if (tasks.Count > 0) {
+                            if (tasks.Count > 0)
+                            {
                                 await Task.WhenAll(tasks);
                             }
                             break;
@@ -367,6 +405,6 @@ namespace TEAMModelOS.FunctionV4.CosmosDB
             }
 
         }
-        
+
     }
 }

+ 2 - 0
TEAMModelOS/Controllers/Common/ArtController.cs

@@ -489,6 +489,8 @@ namespace TEAMModelOS.Controllers.Common
                  }*/
                 var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
                 var client = _azureCosmos.GetCosmosClient();
+
+                //TODO 区级活动的联动删除评测活动
                 var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Art-{code}"));
                 if (sresponse.Status == 200)
                 {