|
@@ -246,17 +246,19 @@ 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 c.id,c.groupIds,c.courseId from c ");
|
|
|
Dictionary<string ,object> dict = GetLessonCond(request);
|
|
|
AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
|
string tbname = "";
|
|
|
string code = "";
|
|
|
+ string school = null;
|
|
|
List<string> autoTch = new List<string>();
|
|
|
if (_scope.GetString().Equals("school"))
|
|
|
{
|
|
|
if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
|
|
|
if (!string.IsNullOrEmpty($"{_school}"))
|
|
|
{
|
|
|
+ school = $"{_school}";
|
|
|
code = $"LessonRecord-{_school}";
|
|
|
tbname = "School";
|
|
|
List<string> ids = new List<string>();
|
|
@@ -329,12 +331,40 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all') {autoSql} ) ";
|
|
|
}
|
|
|
- cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and ");
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
+ cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and array_length(c.groupIds)>0 {sqlShow} and ");
|
|
|
+ List<LessonRecord> records = new List<LessonRecord>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<LessonRecord>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
{
|
|
|
- count = item;
|
|
|
+ records.Add(item);
|
|
|
+ }
|
|
|
+ if (records.Any()) {
|
|
|
+ var groupIds= records.SelectMany(x => x.groupIds).ToHashSet();
|
|
|
+ if (groupIds.Any()) {
|
|
|
+ var groups = await GroupListService.GetGroupListListids(_azureCosmos.GetCosmosClient(), _dingDing, groupIds.ToList(), school," c.id ");
|
|
|
+ //获取已经被删除的名单。
|
|
|
+ var idsExp = groupIds.Except(groups.Select(x => x.id));
|
|
|
+ if (idsExp.Any()) {
|
|
|
+
|
|
|
+
|
|
|
+ foreach(var item in records)
|
|
|
+ {
|
|
|
+ int countRmv = item.groupIds.RemoveAll(x => idsExp.Contains(x));
|
|
|
+ if (countRmv > 0)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ LessonRecord record = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>(item.id, new PartitionKey(code));
|
|
|
+ record.groupIds = item.groupIds;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(record, item.id, new PartitionKey(code));
|
|
|
+ } catch (CosmosException ex) when (ex.Status == 404) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- return Ok(new { count=count });
|
|
|
+ count = records.Count;
|
|
|
+ return Ok(new { count=count, records });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -465,7 +495,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all') {autoSql} ) ";
|
|
|
}
|
|
|
- cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and ");
|
|
|
+ cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) and array_length(c.groupIds)>0 {sqlShow} 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) }))
|