Browse Source

调整能力点标准接口。参数增加standard

CrazyIter_Bin 3 years ago
parent
commit
2fb59fc976

+ 4 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Debate.cs

@@ -10,6 +10,7 @@ namespace TEAMModelOS.SDK.Models
     /// </summary>
     public class Debate : CosmosEntity
     {
+        public string userType { get; set; }
         ///id设计  uuid
         /// code 设计  Debate-hbcn
         /// <summary>
@@ -103,6 +104,9 @@ namespace TEAMModelOS.SDK.Models
         /// 回复者的id
         /// </summary>
         public string tmdid { get; set; }
+        public string school { get; set; }
+        public string atUserType { get; set; }
+        public string userType { get; set; }
         /// <summary>
         /// 回复者的昵称
         /// </summary>

+ 6 - 2
TEAMModelOS/Controllers/Common/HomeworkController.cs

@@ -454,7 +454,6 @@ namespace TEAMModelOS.Controllers.Learn
                         byte msgid = 0;
                         if (content != null)
                         {
-
                             try
                             {
                                 HomeworkRecord record = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<HomeworkRecord>($"{_id}", new PartitionKey(partitionKey));
@@ -486,7 +485,7 @@ namespace TEAMModelOS.Controllers.Learn
                                     msgid = 1;
                                 }
                             }
-                            //TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO 
+                            //TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO 写入方便教师查看的作答记录
                             try
                             {
                                 if ($"{_scope}".Equals(Constant.ScopeStudent)) {
@@ -524,6 +523,7 @@ namespace TEAMModelOS.Controllers.Learn
                             // userType 为student 时,userid 为校内账号,且userSchool 需要有学校编码。
                             //userType 为tmdid 时,userid 为醍摩豆账号,且userSchool 可以为空。
                             if (!request.TryGetProperty("userid", out JsonElement __userid)) return BadRequest();
+                            if (!request.TryGetProperty("userName", out JsonElement __userName)) return BadRequest();
                             if (!request.TryGetProperty("userType", out JsonElement __userType)) return BadRequest();
                             string _partition = $"HomeworkRecord-{__userid}";
                             if ($"{__userType}".Equals("student"))
@@ -535,7 +535,11 @@ namespace TEAMModelOS.Controllers.Learn
                             if (!request.TryGetProperty("star", out JsonElement _star)) return BadRequest();
                             HomeworkRecord record = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<HomeworkRecord>($"{_id}", new PartitionKey(_partition));
                             ///话题对象,id为学生的作答记录的comid ,根据scope确定,  code 为Debate-{schoolId},作业活动所在的学校编码|Debate-{teacherId},作业活动所在的教师编码
+                            Homework homework= await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<Homework>($"{_id}", new PartitionKey(_partition));
+                            if(homework.scope.Equals("school"))
+                            { 
                             
+                            }
                             return Ok(new { error = 404 });
                         }
                         catch (CosmosException ex)

+ 20 - 9
TEAMModelOS/Controllers/Research/AbilityController.cs

@@ -49,9 +49,11 @@ namespace TEAMModelOS.Controllers.Research
         [AuthToken(Roles = "teacher,student,admin,area")]
         public async Task<IActionResult> FindId(JsonElement request)
         {
-            if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+             if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
             var client = _azureCosmos.GetCosmosClient();
             if (!request.TryGetProperty("abilityId", out JsonElement abilityId)) return BadRequest();
+           
             if (!request.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
            // if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
             Ability ability = null;
@@ -88,7 +90,8 @@ namespace TEAMModelOS.Controllers.Research
         {
             try
             {
-                if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+                //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+                if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 // if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
@@ -135,7 +138,8 @@ namespace TEAMModelOS.Controllers.Research
         {
             try
             {
-                if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+                //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+                if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 List<Ability> abilities = new List<Ability>();
                 request.TryGetProperty("dimension", out JsonElement _dimension);
                 
@@ -186,18 +190,25 @@ namespace TEAMModelOS.Controllers.Research
         [AuthToken(Roles = "area")]
         public async Task<IActionResult> Upsert(Ability request)
         {
-            if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
+
             request.pk = "Ability";
             request.ttl = -1;
-            request.code = $"Ability-{standard}";
+            if (string.IsNullOrEmpty(request.code))
+            {
+                request.code = request.code.StartsWith("Ability-") ? request.code : $"Ability-{request.code}";
+            }
+            else {
+                return BadRequest("参数异常");
+            }
             // 检查册别条件相同的是否存在
             ///表示更新
             if (!string.IsNullOrEmpty(request.id))
             {
                 try
                 {
-                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Ability>(request, request.id, new Azure.Cosmos.PartitionKey($"Ability-{standard}"));
-
+                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Ability>(request, request.id, new Azure.Cosmos.PartitionKey(request.code));
                 }
                 catch (Exception ex)
                 {
@@ -216,7 +227,7 @@ namespace TEAMModelOS.Controllers.Research
                         sql.Append($" and c.dimension = '{request.dimension}' and c.name = '{request.name}' ");
                         List<Ability> volumes = new List<Ability>();
                         await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
-                        .GetItemQueryIterator<Ability>(queryText: sql.ToString(), requestOptions: new Azure.Cosmos.QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Ability-{standard}") }))
+                        .GetItemQueryIterator<Ability>(queryText: sql.ToString(), requestOptions: new Azure.Cosmos.QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey(request.code) }))
                         {
                             volumes.Add(item);
                         }
@@ -230,7 +241,7 @@ namespace TEAMModelOS.Controllers.Research
                         return BadRequest(new { error = ResponseCode.PARAMS_ERROR });
                     }
                     request.id = System.Guid.NewGuid().ToString();
-                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"Ability-{standard}"));
+                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey(request.code));
                 }
                 catch (Exception ex)
                 {

+ 3 - 0
TEAMModelOS/Controllers/Research/AbilityStatisticsController.cs

@@ -410,6 +410,8 @@ namespace TEAMModelOS.Controllers.Research
                                 replyId = Guid.NewGuid().ToString();
                                 DebateReply debateReply = new DebateReply
                                 {
+                                    atUserType = "tmdid",
+                                    userType = "tmdid",
                                     id = replyId,
                                     pid = abilitySub.comid,
                                     tmdid = other.tmdid,
@@ -431,6 +433,7 @@ namespace TEAMModelOS.Controllers.Research
                                     {
                                         Debate debate = new Debate
                                         {
+                                            userType="tmdid",
                                             comid = $"{abilityA.comid}",
                                             code = $"Debate-{_school}",
                                             id = $"{abilitySub.comid}",

+ 27 - 15
TEAMModelOS/Controllers/Research/AbilityTaskController.cs

@@ -20,6 +20,7 @@ using TEAMModelOS.Services.Common;
 using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using HTEXLib.COMM.Helpers;
 using TEAMModelOS.Filter;
+using System.ComponentModel.DataAnnotations;
 
 namespace TEAMModelOS.Controllers.Research
 {
@@ -52,7 +53,8 @@ namespace TEAMModelOS.Controllers.Research
         [AuthToken(Roles = "area")]
         public async Task<IActionResult> CheckLink(JsonElement request)
         {
-            if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
             if (!request.TryGetProperty("links", out JsonElement _links)) return BadRequest();
             //if (!request.TryGetProperty("code", out JsonElement _code)) return BadRequest();
             //if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
@@ -109,6 +111,13 @@ namespace TEAMModelOS.Controllers.Research
             }
         ]
          */
+
+        public class UpdateAsTree { 
+            public List<AbilityTaskTreeNode> taskTrees { get; set; }
+            [Required(ErrorMessage = "standard 必须设置")]
+            public string standard { get; set; }
+        }
+
         /// <summary>
         /// 批量保存或更新课纲
         /// 
@@ -118,11 +127,12 @@ namespace TEAMModelOS.Controllers.Research
         [ProducesDefaultResponseType]
         [HttpPost("upsert-tree")]
         [AuthToken(Roles = "area")]
-        public async Task<IActionResult> SaveOrUpdateAsTree(List<AbilityTaskTreeNode> request)
+        public async Task<IActionResult> SaveOrUpdateAsTree(UpdateAsTree request)
         {
-            if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
             long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-            foreach (AbilityTaskTreeNode abilityTaskTree in request)
+            foreach (AbilityTaskTreeNode abilityTaskTree in request.taskTrees)
             {
 
                 if (!string.IsNullOrEmpty(abilityTaskTree.id))
@@ -130,7 +140,7 @@ namespace TEAMModelOS.Controllers.Research
                     AbilityTask abilityTask = null;
                     try
                     {
-                        abilityTask = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<AbilityTask>(abilityTaskTree.id, new Azure.Cosmos.PartitionKey($"AbilityTask-{standard}"));
+                        abilityTask = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<AbilityTask>(abilityTaskTree.id, new Azure.Cosmos.PartitionKey($"AbilityTask-{request.standard}"));
                     }
                     catch
                     {
@@ -146,14 +156,14 @@ namespace TEAMModelOS.Controllers.Research
                         abilityTask = new AbilityTask();
                         abilityTask.id = abilityTaskTree.id;
                         abilityTask.children = nodes;
-                        abilityTask.code = $"AbilityTask-{standard}";
+                        abilityTask.code = $"AbilityTask-{request.standard}";
                         abilityTask.pk = "AbilityTask";
                         abilityTask.ttl = -1;
                         abilityTask.abilityId = abilityTaskTree.abilityId;
                         abilityTask.scope = abilityTaskTree.scope;
-                        abilityTask.codeval = $"{standard}";
-                        abilityTask.standard = $"{standard}";
-                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync<AbilityTask>(abilityTask, new Azure.Cosmos.PartitionKey($"AbilityTask-{standard}"));
+                        abilityTask.codeval = $"{request.standard}";
+                        abilityTask.standard = $"{request.standard}";
+                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync<AbilityTask>(abilityTask, new Azure.Cosmos.PartitionKey($"AbilityTask-{request.standard}"));
                     }
                     else
                     {
@@ -165,7 +175,7 @@ namespace TEAMModelOS.Controllers.Research
                         AbilityService.TreeToList(abilityTaskTree.trees, nodes, now);
                         abilityTask.children = nodes;
                         abilityTaskTree.auth = abilityTask.auth;
-                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<AbilityTask>(abilityTask, abilityTask.id, new Azure.Cosmos.PartitionKey($"AbilityTask-{standard}"));
+                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<AbilityTask>(abilityTask, abilityTask.id, new Azure.Cosmos.PartitionKey($"AbilityTask-{request.standard}"));
                     }
 
 
@@ -183,15 +193,15 @@ namespace TEAMModelOS.Controllers.Research
                     AbilityTask abilityTask = new AbilityTask
                     {
                         id = id,
-                        code = $"AbilityTask-{standard}",
+                        code = $"AbilityTask-{request.standard}",
                         pk = "AbilityTask",
                         ttl = -1,
                         abilityId = abilityTaskTree.abilityId,
                         children = nodes,
                         scope = abilityTaskTree.scope,
-                        codeval= $"{standard}",standard = $"{standard}"
+                        codeval= $"{request.standard}",standard = $"{request.standard}"
                     };
-                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync<AbilityTask>(abilityTask, new Azure.Cosmos.PartitionKey($"AbilityTask-{standard}"));
+                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync<AbilityTask>(abilityTask, new Azure.Cosmos.PartitionKey($"AbilityTask-{request.standard}"));
                 }
             }
             return Ok(request);
@@ -211,7 +221,8 @@ namespace TEAMModelOS.Controllers.Research
         [AuthToken(Roles = "teacher,student,admin,area")]
         public async Task<IActionResult> Find(JsonElement request)
         {
-            if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+            if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
             var client = _azureCosmos.GetCosmosClient();
             if (!request.TryGetProperty("abilityId", out JsonElement abilityId)) return BadRequest();
            // if (!request.TryGetProperty("abilityCode", out JsonElement abilityCode)) return BadRequest();
@@ -287,7 +298,8 @@ namespace TEAMModelOS.Controllers.Research
         {
             try
             {
-                if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+                //if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
+                if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();

+ 2 - 1
TEAMModelOS/Controllers/Research/AppraiseController.cs

@@ -147,6 +147,7 @@ namespace TEAMModelOS.Controllers.Research
                             {
                                 debate = new Debate
                                 {
+                                    userType = "tmdid",
                                     comid = $"{_videoId}",
                                     code=debateCode,
                                     id = $"{_videoId}",
@@ -166,7 +167,7 @@ namespace TEAMModelOS.Controllers.Research
                             }
                         }
                         string replyId = Guid.NewGuid().ToString();
-                        DebateReply reply = new DebateReply { id = replyId, tmdid = $"{_tmdid}", tmdname = comment.tmdname, atTmdid = comment.atTmdid, atTmdname = comment.atTmdname, pid = debate.id, comment = comment.content, time = nowTime };
+                        DebateReply reply = new DebateReply { atUserType = "tmdid", userType = "tmdid", id = replyId, tmdid = $"{_tmdid}", tmdname = comment.tmdname, atTmdid = comment.atTmdid, atTmdname = comment.atTmdname, pid = debate.id, comment = comment.content, time = nowTime };
                         if (debate.replies.IsNotEmpty())
                         {
                             debate.replies.Add(reply);