|
@@ -75,8 +75,183 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> FindTch(JsonElement requert)
|
|
|
{
|
|
|
var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
- (List<ActivityData> datas, string continuationToken) = await ActivityTeacherService.FindAsTch( requert, school, _azureCosmos, _azureRedis);
|
|
|
- return Ok(new { datas, continuationToken });
|
|
|
+ if (string.IsNullOrWhiteSpace(school))
|
|
|
+ {
|
|
|
+ if (requert.TryGetProperty("school", out JsonElement schoolcode))
|
|
|
+ {
|
|
|
+ if (!schoolcode.ValueKind.Equals(JsonValueKind.Undefined) && !schoolcode.ValueKind.Equals(JsonValueKind.Null) && schoolcode.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ school = schoolcode.GetString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(id))
|
|
|
+ {
|
|
|
+ if (requert.TryGetProperty("userid", out JsonElement userid))
|
|
|
+ {
|
|
|
+ if (!userid.ValueKind.Equals(JsonValueKind.Undefined) && !userid.ValueKind.Equals(JsonValueKind.Null) && userid.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ id = userid.GetString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
|
|
|
+ //if (requert.TryGetProperty("stime", out JsonElement stime))
|
|
|
+ //{
|
|
|
+ // if (!stime.ValueKind.Equals(JsonValueKind.Undefined) && !stime.ValueKind.Equals(JsonValueKind.Null) && stime.TryGetInt64(out long data))
|
|
|
+ // {
|
|
|
+ // stimestamp = data;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //string stimesql = $" c.startTime >= {stimestamp} ";
|
|
|
+ //var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ //string etimesql = $" and c.startTime <= {etimestamp} ";
|
|
|
+ //var progresssql = "";
|
|
|
+ //if (requert.TryGetProperty("progress", out JsonElement progress))
|
|
|
+ //{
|
|
|
+ // if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ // {
|
|
|
+ // progresssql = $" and c.progress='{progress}' ";
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ var pksql = "";
|
|
|
+ string type =null;
|
|
|
+ if (requert.TryGetProperty("pk", out JsonElement pk))
|
|
|
+ {
|
|
|
+ if (!pk.ValueKind.Equals(JsonValueKind.Undefined) && !pk.ValueKind.Equals(JsonValueKind.Null) && pk.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ pksql = $" c.pk='{pk}' ";
|
|
|
+ type = $"{pk}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (string.IsNullOrEmpty(type)) { return BadRequest("type is required!"); }
|
|
|
+ string continuationTokenSchool = null;
|
|
|
+ //默认不指定返回大小
|
|
|
+ int? topcout = null;
|
|
|
+ if (requert.TryGetProperty("count", out JsonElement jcount))
|
|
|
+ {
|
|
|
+ if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
|
|
|
+ {
|
|
|
+ topcout = data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //是否需要进行分页查询,默认不分页
|
|
|
+ bool iscontinuation = false;
|
|
|
+ if (topcout != null && topcout.Value > 0)
|
|
|
+ {
|
|
|
+ iscontinuation = true;
|
|
|
+ }
|
|
|
+ //如果指定了返回大小
|
|
|
+ if (requert.TryGetProperty("continuationTokenSchool", out JsonElement continuationSchool))
|
|
|
+ {
|
|
|
+ //指定了cancellationToken continuationSchool
|
|
|
+ if (!continuationSchool.ValueKind.Equals(JsonValueKind.Null) && continuationSchool.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ continuationTokenSchool = continuationSchool.GetString();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //班级
|
|
|
+ string joinSqlClasses = "";
|
|
|
+ string andSqlClasses = "";
|
|
|
+ List<string> classes = null;
|
|
|
+ if (requert.TryGetProperty("classes", out JsonElement jclasses))
|
|
|
+ {
|
|
|
+ if (jclasses.ValueKind is JsonValueKind.Array)
|
|
|
+ {
|
|
|
+ classes = jclasses.ToObject<List<string>>();
|
|
|
+ if (classes.IsNotEmpty())
|
|
|
+ {
|
|
|
+ joinSqlClasses = " join A1 in c.classes ";
|
|
|
+ List<string> sqlList = new List<string>();
|
|
|
+ classes.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
|
+ string sql = string.Join(" , ", sqlList);
|
|
|
+ andSqlClasses = $" A1 in ({sql}) ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string classesSql = "";
|
|
|
+ if (!string.IsNullOrWhiteSpace(joinSqlClasses))
|
|
|
+ {
|
|
|
+ classesSql = $" and {andSqlClasses } ";
|
|
|
+ }
|
|
|
+
|
|
|
+ //科目
|
|
|
+ //string joinSqlSubjects = "";
|
|
|
+ //string andSqlSubjects = "";
|
|
|
+ //if (requert.TryGetProperty("subjects", out JsonElement jsubjects))
|
|
|
+ //{
|
|
|
+ // if (jsubjects.ValueKind is JsonValueKind.Array)
|
|
|
+ // {
|
|
|
+ // List<string> subjects = jsubjects.ToObject<List<string>>();
|
|
|
+ // if (subjects.IsNotEmpty())
|
|
|
+ // {
|
|
|
+ // joinSqlSubjects = " join A2 in c.subjects ";
|
|
|
+ // List<string> sqlList = new List<string>();
|
|
|
+ // subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
|
+ // string sql = string.Join(" , ", sqlList);
|
|
|
+ // andSqlSubjects = $" and A2 in ({sql}) ";
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ List<JsonElement> datas = new List<JsonElement>();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ //班主任 ,任课教师只需要查询两种校园活动 和班级活动 , 不查询私人教室创建的活动。
|
|
|
+ if (!string.IsNullOrWhiteSpace(school) && classes.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //string querySchool = $" SELECT distinct value c FROM c {joinSqlClasses} {joinSqlSubjects} where {stimesql} {etimesql} {progresssql} {typesql} {andSqlSubjects} {tgSql}";
|
|
|
+ string querySchool = $" SELECT c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk FROM c {joinSqlClasses} where {pksql} {classesSql}";
|
|
|
+ //查询数据归属学校的
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(querySchool, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"{type}-{school}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ datas.Add(obj.ToObject<JsonElement>());
|
|
|
+ }
|
|
|
+ //如果需要分页则跳出
|
|
|
+ if (iscontinuation)
|
|
|
+ {
|
|
|
+ continuationTokenSchool = item.GetContinuationToken();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string continuationTokenTeacher = null;
|
|
|
+ //如果指定了返回大小
|
|
|
+ if (requert.TryGetProperty("continuationTokenTeacher", out JsonElement continuationTeacher))
|
|
|
+ {
|
|
|
+ //指定了cancellationToken continuationSchool
|
|
|
+ if (!continuationTeacher.ValueKind.Equals(JsonValueKind.Null) && continuationTeacher.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ continuationTokenTeacher = continuationTeacher.GetString();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string queryTeacher= $" SELECT c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk FROM c where {pksql} ";
|
|
|
+ //查询数据归属学校的
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryTeacher, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"{type}-{id}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ datas.Add(obj.ToObject<JsonElement>());
|
|
|
+ }
|
|
|
+ //如果需要分页则跳出
|
|
|
+ if (iscontinuation)
|
|
|
+ {
|
|
|
+ continuationTokenTeacher = item.GetContinuationToken();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(new { datas, continuationTokenSchool, continuationTokenTeacher });
|
|
|
}
|
|
|
}
|
|
|
}
|