فهرست منبع

Merge branch 'develop' into cmy/develop-bi

chenmy 3 سال پیش
والد
کامیت
94eb726f35
1فایلهای تغییر یافته به همراه41 افزوده شده و 6 حذف شده
  1. 41 6
      TEAMModelOS/Controllers/Both/LessonRecordController.cs

+ 41 - 6
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -93,8 +93,9 @@ namespace TEAMModelOS.Controllers
             }
             try
             {
-                LessonRecord lessonRecord = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>($"{_lessonId}", new PartitionKey(code));
+                Dictionary<string, object> dict = new Dictionary<string, object>();
                 if (_grant_types.ValueKind.Equals(JsonValueKind.Array)) {
+                    LessonRecord lessonRecord = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>($"{_lessonId}", new PartitionKey(code));
                     List<LessonUpdate> updates = _grant_types.ToObject<List<LessonUpdate>>();
                     foreach (var item in updates) {
                         if (item.grant_type.Equals("up-baseinfo")) {
@@ -124,20 +125,54 @@ namespace TEAMModelOS.Controllers
                             {
                                 lessonRecord.show = _show.ToObject<List<string>>();
                             }
+                            await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, $"{_lessonId}", new PartitionKey(code));
+                            dict["up-baseinfo"] = new { status= 1 ,code="ok"};
                         }
                         if (item.grant_type.Equals("up-expire")) {
-                            lessonRecord.expire = -1;
+                            if (_scope.Equals("private")) {
+                                Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{_tmdid}", new PartitionKey("Base"));
+                                HashSet<string> ids = new HashSet<string>();
+                                //未定义的 以及过期时间小于等于0 的 课例
+                                string private_count_sql = $"select value(c.id) from  c where  ( c.expire<=0 or IS_DEFINED(c.expire) = false  ) and c.tmdid='{_tmdid}'  ";
+                                await foreach (var lid in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<string>(
+                                    queryText: private_count_sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(code) }))
+                                {
+
+                                    ids.Add(lid);
+                                }
+                                //包含收藏的本人的个人课例
+                                string favorite_count_sql = $"select value(c.id) from  c where c.type='LessonRecord' and c.owner='{_tmdid}'   and c.scope='private' ";
+                                await foreach (var lid in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<string>(
+                                    queryText: favorite_count_sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Favorite-{_tmdid}") }))
+                                {
+                                    ids.Add(lid);
+                                }
+                                //教师个人预设的,可以通过设置的方式增加
+                                int limit = teacher.lessonLimit;
+                                if (teacher.lessonLimit == 0)
+                                {
+                                    //未设置的的采用系统设置的默认值50
+                                    limit = Constant.private_lesson_limit;
+                                }
+                                if (ids.Count < limit)
+                                {
+                                    lessonRecord.expire = -1;
+                                    await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, $"{_lessonId}", new PartitionKey(code));
+                                    dict["up-expire"] = new { status = 1, code = "ok" };
+                                }
+                                else {
+                                    dict["up-expire"] = new { status = 0, code = "lessonLimit" ,data= limit };
+                                }
+                            }
                         }
-                        await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(lessonRecord, $"{_lessonId}", new PartitionKey(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 });
+                    return Ok(new { status = 200,updateInfo= dict });
                 }
-               
-                return Ok(new { lessonRecord });
+                return BadRequest();
             }
             catch (CosmosException ex) when (ex.Status == 404)
             {