Ver código fonte

课堂记录的删除接口。

CrazyIter_Bin 3 anos atrás
pai
commit
3d25fc5f0d

+ 6 - 2
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -884,6 +884,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                     lessonRecord = null;
                 }
 
+                bool isdelete = false;
                 if (updates.IsNotEmpty())
                 {
                     foreach (LessonUpdate update in updates)
@@ -960,6 +961,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     msgs.Add(update);
                                 }
                                 lessonRecord = null;
+                                isdelete = true;
                                 break;
                             case "create":
                                 oldlessonRecord = null;
@@ -1048,8 +1050,10 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                 break;
                         }
                     }
-                    //
-                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
+                    //如果被删除则不能再被更新
+                    if (!isdelete) {
+                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, lessonId, new PartitionKey(code));
+                    }
                     //计算课堂更新前后的差值
                     lessonDis = LessonService.DisLessonCount(oldlessonRecord, lessonRecord, lessonDis);
                     await LessonService.FixLessonCount(client, _dingDing, lessonRecord, oldlessonRecord, lessonDis);

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/LessonRecord.cs

@@ -112,6 +112,7 @@ namespace TEAMModelOS.SDK.Models
         /// 科技互动详细次数。[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
         /// </summary>
         public List<int> tech { get; set; } = new List<int>();
+        public int status { get; set; } = 0;
     }
 
     public class LessonActivityInfo

+ 1 - 0
TEAMModelOS/Controllers/Both/ItemController.cs

@@ -923,6 +923,7 @@ namespace TEAMModelOS.Controllers
                                 }
                                 //List<ItemInfo> items = await _azureCosmos.FindByDict<ItemInfo>(dict);
                                 //id去重
+                                Console.WriteLine(items.Count);
                                 items = items.Where((x, i) => items.FindIndex(z => z.id == x.id) == i).ToList();
                                 itemInfos.AddRange(items);
                                 //均分

+ 82 - 3
TEAMModelOS/Controllers/Common/LessonRecordController.cs

@@ -1,4 +1,5 @@
 using Azure.Cosmos;
+using Azure.Messaging.ServiceBus;
 using HTEXLib.COMM.Helpers;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
@@ -56,12 +57,89 @@ namespace TEAMModelOS.Controllers
             _configuration = configuration;
         }
 
+
+        /*
+        {
+            "scope":"school/private",
+            "tmdid":"1595321354", 
+            "delete_id":"asdeeeqq-adfghnlr-pfkcmsss-ssadffgtre",
+            "opt":"delete",
+            "school":"hbcn" //如果scope=school  这 school字段必须有值
+        }
+         */
+
         /// <summary>
         /// 获取开课记录
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
+        // [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("delete-lesson-record")]
+        public async Task<IActionResult> DeleteLessonRecord(JsonElement request)
+        {
+            string scope = "";
+            string tmdid = "";
+            string lessonId;
+            string school;
+            string tbname;
+            string code;
+            if (request.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
+                            && request.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
+                            && request.TryGetProperty("scope", out JsonElement _dscope) && !string.IsNullOrEmpty($"{_dscope}")
+                            && request.TryGetProperty("opt", out JsonElement _opt) && !string.IsNullOrEmpty($"{_opt}"))
+            {
+                request.TryGetProperty("school", out JsonElement _dschool);
+                school = $"{_dschool}";
+                var client = _azureCosmos.GetCosmosClient();
+                if ($"{_opt}".Equals("delete"))
+                {
+                    if ($"{_dscope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
+                    {
+                        code = $"LessonRecord-{school}";
+                        tbname = "School";
+                    }
+                    else if ($"{_dscope}".Equals("private"))
+                    {
+                        code = $"LessonRecord-{tmdid}";
+                        tbname = "Teacher";
+                    }
+                    else
+                    {
+                        return BadRequest() ;
+                    }
+                    lessonId = $"{_delete_id}";
+                    Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
+                    if (response.Status == 200)
+                    {
+                        LessonRecord lessonRecord ;
+                        var doc = JsonDocument.Parse(response.ContentStream);
+                        lessonRecord = doc.RootElement.ToObject<LessonRecord>();
+                        lessonRecord.status = -1;
+                        await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(lessonRecord, lessonRecord.id, new PartitionKey(lessonRecord.code));
+                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                        var messageChange = new ServiceBusMessage(request.ToJsonString());
+                        messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
+                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        return Ok(new { status = 200 });
+                    }
+                    else { return BadRequest(); }
+                }
+                else { return BadRequest() ; }
+            }
+            else
+            {
+                return BadRequest();
+            }
+        }
+
+
+        /// <summary>
+        /// 获取开课记录 (c.status<>-1 or IS_DEFINED(c.status)=false )
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher,admin")]
         [HttpPost("get-lesson-record-count")]
         public async Task<IActionResult> GetLessonRecordCont(JsonElement request)
@@ -69,7 +147,7 @@ namespace TEAMModelOS.Controllers
            
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             StringBuilder sql = new StringBuilder();
-            sql.Append("select value(count(1)) from c ");
+            sql.Append("select value(count(1)) from c   ");
             Dictionary<string ,object> dict =  GetLessonCond(request);
             AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
             string tbname = "";
@@ -105,6 +183,7 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
             int count=0;
+            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>-1 or IS_DEFINED(c.status) = false ) and  ");
             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
             {
                 count = item;
@@ -112,7 +191,7 @@ namespace TEAMModelOS.Controllers
             return Ok(new { count=count });
         }
 
-      
+
         /// <summary>
         /// 获取开课记录
         /// </summary>
@@ -186,6 +265,7 @@ namespace TEAMModelOS.Controllers
             }
             List<LessonRecord> lessonRecords = new List<LessonRecord>();
             try {
+                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>-1 or IS_DEFINED(c.status) = false ) and  ");
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                    .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
                    requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))
@@ -223,7 +303,6 @@ namespace TEAMModelOS.Controllers
                 continuationToken = null;
                 return Ok(new { currCount=0, continuationToken = continuationToken, lessonRecords });
             }
-           
         }
 
         private Dictionary<string, object> GetLessonCond(JsonElement request)

TEAMModelOS/Controllers/Normal/ClassVideoController.cs → TEAMModelOS/Controllers/Teacher/ClassVideoController.cs