zhouj1203@hotmail.com 1 rok temu
rodzic
commit
e032baf780

+ 6 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/StudentArtResult.cs

@@ -73,6 +73,12 @@ namespace TEAMModelOS.SDK.Models
         /// 分数
         /// </summary>
         public double score { get; set; } = -1;
+        public string name { get; set; }
+        public string des { get; set; }
+        //0 艺术作品 1 等级证书
+        public int artType { get; set; }
+        // 0 校级 1 区级 2 市级 3 省级 4 国家级
+        public int level { get; set; }
         /// <summary>
         /// 上传的文件
         /// </summary>

+ 221 - 0
TEAMModelOS/Controllers/Client/AClassONEController.cs

@@ -1,5 +1,6 @@
 using Azure.Cosmos;
 using Azure.Storage.Blobs.Models;
+using DocumentFormat.OpenXml.Drawing.Charts;
 using HTEXLib.COMM.Helpers;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
@@ -21,9 +22,11 @@ using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Services;
 using static TEAMModelOS.SDK.Services.BlobService;
 namespace TEAMModelOS.Controllers
@@ -299,6 +302,212 @@ namespace TEAMModelOS.Controllers
         }
 
 
+
+        /// <summary>
+        /// 获取当前学生参与的活动列表
+        /// </summary>
+        /// <param name="json"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("find-children-activity")]
+#if !DEBUG
+        [Authorize(Roles = "AClassONE")]
+#endif
+        public async Task<IActionResult> getActivity(JsonElement request) {
+            try {
+                //if (!request.TryGetProperty("studentId", out JsonElement stuId)) return BadRequest();
+                if (!request.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
+                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();//学校编码
+
+                var client = _azureCosmos.GetCosmosClient();
+                StringBuilder stringBuilder = new($"select value(c) from c where (c.status<>404 or IS_DEFINED(c.status) = false )");
+                string continuationToken = string.Empty;
+                string token = default;
+                if (!string.IsNullOrWhiteSpace($"{classId}"))
+                {
+                    stringBuilder.Append($" and array_contains(c.classIds,'{classId}')");
+                }             
+                stringBuilder.Append("order by c.createTime desc");
+                //是否需要进行分页查询,默认不分页
+                bool iscontinuation = false;
+                if (request.TryGetProperty("token", out JsonElement token_1))
+                {
+                    token = token_1.GetString();
+                    iscontinuation = true;
+                };
+                //默认不指定返回大小
+                int? topcout = null;
+                if (request.TryGetProperty("count", out JsonElement jcount))
+                {
+                    if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
+                    {
+                        topcout = data;
+                    }
+                }
+
+                List<ArtEvaluation> arts = new();
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Art-{code}") }))
+                {
+
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            arts.Add(obj.ToObject<ArtEvaluation>());
+                        }
+                    }
+                    if (iscontinuation)
+                    {
+                        continuationToken = item.GetContinuationToken();
+                        break;
+                    }
+                }
+                arts = arts.Where((x, i) => arts.FindIndex(z => z.id == x.id) == i).ToList();
+                return Ok(new { arts });
+            } catch (Exception e) {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},art/find-children-activity()\n{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return BadRequest("500错误");
+            }
+        }
+
+        [ProducesDefaultResponseType]
+        [HttpPost("upload-all")]
+#if !DEBUG
+        [Authorize(Roles = "AClassONE")]
+#endif
+        public async Task<IActionResult> UploadAll(JsonElement element)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                if (!element.TryGetProperty("artId", out JsonElement artId)) return BadRequest();
+                if (!element.TryGetProperty("classId", out JsonElement classId)) return BadRequest();
+                if (!element.TryGetProperty("acId", out JsonElement acId)) return BadRequest();
+                if (!element.TryGetProperty("subject", out JsonElement subject)) return BadRequest();
+                if (!element.TryGetProperty("code", out JsonElement school)) return BadRequest();
+                if (!element.TryGetProperty("stus", out JsonElement stus)) return BadRequest();
+                List<stuFiles> stuFiles = stus.ToObject<List<stuFiles>>();
+                List<string> value = new List<string>();
+                await foreach (var s in stuTask(stuFiles, client, school.GetString(), artId.GetString(), classId.GetString(), acId.GetString(), subject.GetString()))
+                {
+                    if (s.code == 1)
+                    {
+                        value.Add(s.value);
+                    }
+                }
+                if (value.Count > 0)
+                {
+                    return Ok(new { code = 1, msg = "学生ID上传异常", value = value });
+                }
+                else
+                {
+                    return Ok(new { code = 0 });
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},art/uploadAll()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { code = 500, msg = ex.Message });
+            }
+
+        }
+        private async IAsyncEnumerable<(int code, string value)> stuTask(List<stuFiles> stuFiles, CosmosClient client, string school, string artId, string classId, string acId, string subject)
+        {
+
+            List<string> classIds = new List<string> { classId };
+            foreach (var request in stuFiles)
+            {
+                string value = "";
+                int code = 0;
+                try
+                {
+                    long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    StudentArtResult artResult;
+                    ArtEvaluation art;                                      
+                    string rId = string.Format("{0}{1}{2}", school, "-", request.stuId);
+                    //首先根据大ID获取整个活动得内容
+                    var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(artId, new PartitionKey($"Art-{school}"));
+                    if (aresponse.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(aresponse.ContentStream);
+                        art = json.ToObject<ArtEvaluation>();
+                        var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(rId, new PartitionKey($"ArtResult-{artId}"));
+                        if (response.Status == 200)
+                        {
+                            using var json_1 = await JsonDocument.ParseAsync(response.ContentStream);
+                            artResult = json_1.ToObject<StudentArtResult>();
+                            List<Attachment> files = new();
+                            files = request.attachments;
+                            //bool flage = artResult.results.Exists(a => a.taskId == request.acId);
+                            artResult.results.ForEach(a =>
+                            {
+                                if (a.taskId == acId)
+                                {
+                                    a.name = request.name;
+                                    a.des = request.des;
+                                    a.artType = request.artType;
+                                    a.level = request.level;
+                                    a.files = files;
+                                }
+                            });
+                            await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(artResult, artResult.id, new PartitionKey($"{artResult.code}"));
+                        }
+                        else
+                        {
+                            artResult = new StudentArtResult
+                            {
+                                id = rId,
+                                pk = "ArtResult",
+                                code = $"ArtResult-{artId}",
+                                studentId = request.stuId,
+                                //picture = picture,
+                                studentName = request.name,
+                                school = school,
+                                userType = request.userType,
+                                artId = artId,
+                                classIds = classIds,
+                            };
+                            foreach (var qIds in art.settings)
+                            {
+                                foreach (var task in qIds.task)
+                                {
+                                    ArtQuotaResult quotaResult = new()
+                                    {
+                                        quotaId = qIds.id,
+                                        quotaName = qIds.quotaname,
+                                        quotaType = (int)task.type,
+                                        subjectId = task.subject,
+                                        taskId = task.acId
+                                    };
+                                    if (!string.IsNullOrEmpty(quotaResult.taskId))
+                                    {
+                                        if (quotaResult.taskId.Equals(acId))
+                                        {
+                                            quotaResult.name = request.name;
+                                            quotaResult.des = request.des;
+                                            quotaResult.artType = request.artType;
+                                            quotaResult.level = request.level;
+                                            quotaResult.files = request.attachments;
+                                        }
+                                    }
+                                    artResult.results.Add(quotaResult);
+                                }
+                            }
+
+                            await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
+                        }
+                    }
+                }
+                catch (Exception e)
+                {
+                    value = request.stuId;
+                    code = 1;
+                }
+                yield return (code, value);
+            }
+        }
+
         private async Task<(int code, WeChatPhone phone)> GetWeChatPhoneNumber(string phoneCode) 
         {
             var wxappid = _configuration.GetValue<string>("HaBookAuth:WXMiniAPP:appid");
@@ -377,6 +586,18 @@ namespace TEAMModelOS.Controllers
             public string? errmsg { get; set; }
             public WeChatPhone? phone_info { get; set; }
         }
+        private class stuFiles
+        {
+            public string stuId { get; set; }
+            public int userType { get; set; }
+            public string name { get; set; }
+            public string des { get; set; }
+            //0 艺术作品 1 等级证书
+            public int artType { get; set; }
+            // 0 校级 1 区级 2 市级 3 省级 4 国家级
+            public int level { get; set; } = -1;
+            public List<Attachment> attachments { get; set; } = new List<Attachment>();
+        }
 
     }
 }

+ 13 - 5
TEAMModelOS/Controllers/Common/ArtController.cs

@@ -363,7 +363,7 @@ namespace TEAMModelOS.Controllers.Common
                 try
                 {
                     long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                    ArtRecord record = new()
+                    /*ArtRecord record = new()
                     {
                         school = school,
                         stuId = request.stuId,
@@ -375,7 +375,7 @@ namespace TEAMModelOS.Controllers.Common
                         createTime = now,
                         code = "ArtRecord",
                         attachments = request.attachments
-                    };
+                    };*/
                     StudentArtResult artResult;
                     ArtEvaluation art;
                     List<string> classIds = new();
@@ -393,7 +393,7 @@ namespace TEAMModelOS.Controllers.Common
                     {
                         record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
                     }*/
-                    string rId = string.Format("{0}{1}{2}", record.school, "-", record.stuId);
+                    string rId = string.Format("{0}{1}{2}", school, "-", request.stuId);
                     //首先根据大ID获取整个活动得内容
                     var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(artId, new PartitionKey($"Art-{school}"));
                     if (aresponse.Status == 200)
@@ -412,6 +412,10 @@ namespace TEAMModelOS.Controllers.Common
                             {
                                 if (a.taskId == acId)
                                 {
+                                    a.name = request.name;
+                                    a.des = request.des;
+                                    a.artType = request.artType;
+                                    a.level = request.level;
                                     a.files = files;
                                 }
                             });
@@ -448,6 +452,10 @@ namespace TEAMModelOS.Controllers.Common
                                     {
                                         if (quotaResult.taskId.Equals(acId))
                                         {
+                                            quotaResult.name = request.name;
+                                            quotaResult.des = request.des;
+                                            quotaResult.artType = request.artType;
+                                            quotaResult.level = request.level;
                                             quotaResult.files = request.attachments;
                                         }
                                     }
@@ -1171,11 +1179,11 @@ namespace TEAMModelOS.Controllers.Common
             public string stuId { get; set; }
             public int userType { get; set; }
             public string name { get; set; }
-            public string dis { get; set; }
+            public string des { get; set; }
             //0 艺术作品 1 等级证书
             public int  artType { get; set; }
             // 0 校级 1 区级 2 市级 3 省级 4 国家级
-            public int level { get; set; }
+            public int level { get; set; } = -1;
             public List<Attachment> attachments { get; set; } = new List<Attachment>();
         }
     }