zhouj1203@hotmail.com hace 1 año
padre
commit
2ba34f034e

+ 63 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/ArtAttachment.cs

@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Student
+{
+    public  class ArtAttachment : CosmosEntity
+    {
+        public ArtAttachment()
+        {
+            pk = "ArtAttachment";
+        }
+        public string artId { get; set; }
+        public string studentId { get; set; }
+        /// <summary>
+        /// 任务id
+        /// </summary>
+        public string taskId { get; set; }
+        /// <summary>
+        /// 任务名称
+        /// </summary>
+        public string taskName { get; set; }
+        /// <summary>
+        /// 科目id
+        /// </summary>
+        public string subjectId { get; set; }
+        /// <summary>
+        /// 科目名称
+        /// </summary>
+        public string subjectName { get; set; }
+        /// <summary>
+        /// 指标id
+        /// </summary>
+        public string quotaId { get; set; }
+        /// <summary>
+        /// 指标名称
+        /// </summary>
+        public string quotaName { get; set; }
+        /// <summary>
+        /// 指标类型-1未设定 0评分,1评测,2作业
+        /// </summary>
+        public int quotaType { get; set; }
+        public string address { get; set; }
+        public string time { get; set; }
+        public string duration { get; set; }
+        public string achievement { 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; }
+        public long uploadTime { get; set; }
+        public long updateTime { get; set; }
+        /// <summary>
+        /// 上传的文件
+        /// </summary>
+        public List<Attachment> files { get; set; }
+
+    }
+}

+ 2 - 15
TEAMModelOS.SDK/Models/Cosmos/Student/StudentArtResult.cs

@@ -72,22 +72,9 @@ namespace TEAMModelOS.SDK.Models
         /// <summary>
         /// 分数
         /// </summary>
-        public double score { get; set; } = -1;
-        public string address { get; set; }
-        public string time { get; set; }
-        public string duration { get; set; }
-        public string achievement { 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; }
-        /// <summary>
-        /// 上传的文件
-        /// </summary>
+        public double score { get; set; } = -1;      
+        public string name { get; set; }      
         public List<Attachment> files { get; set; }
-
         /// <summary>
         /// 分数结果来源    0醍摩豆系统分数结果   1智音传分数结果
         /// </summary>

+ 106 - 110
TEAMModelOS/Controllers/Client/AClassONEController.cs

@@ -23,12 +23,14 @@ using System.Reflection;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelOS.Controllers.Analysis;
 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.Models.Cosmos.Student;
 using TEAMModelOS.SDK.Services;
 using static TEAMModelOS.SDK.Services.BlobService;
 namespace TEAMModelOS.Controllers
@@ -453,6 +455,16 @@ namespace TEAMModelOS.Controllers
                     result = json.ToObject<StudentArtResult>();                 
                   
                 }
+                List<string> taskIds = new();
+                taskIds = result.results.Select(c => c.taskId).ToList();
+                List<ArtAttachment> artAttachments = new();
+                string sqlTask = $"select value(c)  from c where c.studentId = '{stuId}' and c.taskId in ({string.Join(",", taskIds.Select(s => $"'{s}'"))})";
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).
+                GetItemQueryIterator<ArtAttachment>(queryText: sqlTask, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtAttachment-{code}") }))
+                {
+                    artAttachments.Add(item);
+                }
+
                 var resArt = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(artId.ToString(), new PartitionKey($"Art-{code}"));
                 if (resArt.Status == 200)
                 {
@@ -460,7 +472,7 @@ namespace TEAMModelOS.Controllers
                     art = json.ToObject<ArtEvaluation>();
 
                 }
-                return Ok(new { result,art });
+                return Ok(new { result,art, artAttachments });
             }
             catch (Exception e)
             {
@@ -479,15 +491,11 @@ namespace TEAMModelOS.Controllers
             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("code", out JsonElement school)) return BadRequest();
                 if (!element.TryGetProperty("attachments", out JsonElement stus)) return BadRequest();
-                List<stuFiles> stuFiles = stus.ToObject<List<stuFiles>>();
+                stuFiles files = stus.ToObject<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()))
+                await foreach (var s in stuTask(files, client))
                 {
                     if (s.code == 1)
                     {
@@ -496,122 +504,104 @@ namespace TEAMModelOS.Controllers
                 }
                 if (value.Count > 0)
                 {
-                    return Ok(new { code = 1, msg = "学生ID上传异常", value = value });
+                    return Ok(new { code = 400, msg = "学生ID上传异常", value });
                 }
                 else
                 {
-                    return Ok(new { code = 0 });
+                    return Ok();
                 }
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},art/uploadAll()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},aclassone/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)
+        [ProducesDefaultResponseType]
+        [HttpPost("delete")]
+#if !DEBUG
+        [Authorize(Roles = "AClassONE")]
+#endif
+        public async Task<IActionResult> deleteFiels(JsonElement element)
+        {
+            try
             {
-                string value = "";
-                int code = 0;
-                try
+                var client = _azureCosmos.GetCosmosClient();
+                if (!element.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                if (!element.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(id.GetString(), new PartitionKey($"ArtAttachment-{code}"));
+                return Ok();
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},aclassone/delete()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { code = 500, msg = ex.Message });
+            }
+
+        }
+        private async IAsyncEnumerable<(int code, string value)> stuTask(stuFiles files, CosmosClient client)
+        {
+            string value = "";
+            int code = 0;
+            try {
+                if (string.IsNullOrEmpty(files.id))
                 {
-                    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)
+                    ArtAttachment attachment = new()
                     {
-                        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.address = request.address;
-                                    a.duration = request.duration;
-                                    a.achievement = request.achievement;
-                                    a.time = request.time;
-                                    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.address = request.address;
-                                            quotaResult.duration = request.duration;
-                                            quotaResult.achievement = request.achievement;
-                                            quotaResult.time = request.time;
-                                            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}"));
-                        }
-                    }
+                        id = Guid.NewGuid().ToString(),
+                        artId = files.artId,
+                        achievement = files.achievement,
+                        address = files.address,
+                        studentId = files.studentId,
+                        taskId = files.taskId,
+                        subjectId = files.subjectId,
+                        quotaId = files.quotaId,
+                        quotaName = files.quotaName,
+                        uploadTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                        duration = files.duration,
+                        name = files.name,
+                        des = files.des,
+                        artType = files.artType,
+                        level = files.level,
+                        files = files.files,
+                        ttl = -1,
+                        code = "ArtAttachment-" + files.school
+
+                    };
+                    await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(attachment, new PartitionKey($"{attachment.code}"));
                 }
-                catch (Exception e)
+                else
                 {
-                    value = request.stuId;
-                    code = 1;
+                    ArtAttachment attachment = new()
+                    {
+                        artId = files.artId,
+                        achievement = files.achievement,
+                        address = files.address,
+                        studentId = files.studentId,
+                        taskId = files.taskId,
+                        subjectId = files.subjectId,
+                        quotaId = files.quotaId,
+                        quotaName = files.quotaName,
+                        updateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                        duration = files.duration,
+                        name = files.name,
+                        des = files.des,
+                        artType = files.artType,
+                        level = files.level,
+                        files = files.files,
+                        ttl = -1,
+                        code = "ArtAttachment-" + files.school
+                    };
+                    await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(attachment, attachment.id, new PartitionKey($"{attachment.code}"));
                 }
-                yield return (code, value);
             }
+            catch (Exception e) {
+                value = files.studentId;
+                code = 1;
+            }
+            yield return (code, value);
         }
 
         private async Task<(int code, WeChatPhone phone)> GetWeChatPhoneNumber(string phoneCode) 
@@ -694,8 +684,14 @@ namespace TEAMModelOS.Controllers
         }
         private class stuFiles
         {
-            public string stuId { get; set; }
-            public int userType { get; set; }
+            public string id { get; set; }
+            public string school { get; set; }
+            public string artId { get; set; }
+            public string taskId { get; set; }
+            public string studentId { get; set; }
+            public string quotaId { get; set; }
+            public string quotaName { get; set; }
+            public string subjectId { get; set; }
             public string address { get; set; }
             public string time { get; set; }
             public string duration { get; set; }
@@ -703,11 +699,11 @@ namespace TEAMModelOS.Controllers
             public string name { get; set; }
             public string des { get; set; }
             //0 艺术特长  1 艺术体验
-            public int artType { get; set; }
+            public int artType { get; set; } = -1;
             // 0 校级 1 区级 2 市级 3 省级 4 国家级
             public int level { get; set; } = -1;
-
-            public List<Attachment> attachments { get; set; } = new List<Attachment>();
+            public long uploadTime { get; set; }
+            public List<Attachment> files { get; set; } = new List<Attachment>();
         }
 
     }

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

@@ -413,13 +413,6 @@ namespace TEAMModelOS.Controllers.Common
                                 if (a.taskId == acId)
                                 {
                                     a.name = request.name;
-                                    a.address = request.address;
-                                    a.duration = request.duration;
-                                    a.achievement = request.achievement;
-                                    a.time = request.time;
-                                    a.des = request.des;
-                                    a.artType = request.artType;
-                                    a.level = request.level;
                                     a.files = files;
                                 }
                             });
@@ -457,13 +450,6 @@ namespace TEAMModelOS.Controllers.Common
                                         if (quotaResult.taskId.Equals(acId))
                                         {
                                             quotaResult.name = request.name;
-                                            quotaResult.address = request.address;
-                                            quotaResult.duration = request.duration;
-                                            quotaResult.achievement = request.achievement;
-                                            quotaResult.time = request.time;
-                                            quotaResult.des = request.des;
-                                            quotaResult.artType = request.artType;
-                                            quotaResult.level = request.level;
                                             quotaResult.files = request.attachments;
                                         }
                                     }
@@ -1187,15 +1173,6 @@ namespace TEAMModelOS.Controllers.Common
             public string stuId { get; set; }
             public int userType { get; set; }
             public string name { get; set; }
-            public string des { get; set; }
-            public string address { get; set; }
-            public string time { get; set; }
-            public string duration { get; set; }
-            public string achievement { 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>();
         }
     }