|
@@ -35,51 +35,48 @@ namespace TEAMModelOS.Services.Common
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
public static async Task<(List<ActivityData> datas, string continuationToken)> FindAsTch(JsonElement requert, string school, AzureCosmosFactory _azureCosmos, AzureRedisFactory _azureRedis)
|
|
public static async Task<(List<ActivityData> datas, string continuationToken)> FindAsTch(JsonElement requert, string school, AzureCosmosFactory _azureCosmos, AzureRedisFactory _azureRedis)
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ if (string.IsNullOrWhiteSpace(school))
|
|
|
|
+ {
|
|
|
|
+ school = requert.GetProperty("school").GetString();
|
|
|
|
+ }
|
|
//开始时间,默认最近三十天
|
|
//开始时间,默认最近三十天
|
|
var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
|
|
var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
|
|
-
|
|
|
|
-
|
|
|
|
- if (!requert.TryGetProperty("stime", out JsonElement stime))
|
|
|
|
|
|
+ if (requert.TryGetProperty("stime", out JsonElement stime))
|
|
{
|
|
{
|
|
- if (stime.TryGetInt64(out long data))
|
|
|
|
|
|
+ if (!stime.ValueKind.Equals(JsonValueKind.Undefined) && !stime.ValueKind.Equals(JsonValueKind.Null) && stime.TryGetInt64(out long data))
|
|
{
|
|
{
|
|
stimestamp = data;
|
|
stimestamp = data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ string stimesql = $" c.startTime >= {stimestamp} ";
|
|
|
|
+ //默认当前时间, 未开始的不能查询
|
|
|
|
+ var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
+ string etimesql = $" and c.startTime <= {etimestamp} ";
|
|
var progresssql = "";
|
|
var progresssql = "";
|
|
- if (!requert.TryGetProperty("progress", out JsonElement progress))
|
|
|
|
|
|
+ if (requert.TryGetProperty("progress", out JsonElement progress))
|
|
{
|
|
{
|
|
|
|
|
|
if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
|
|
if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
|
|
{
|
|
{
|
|
- progresssql = $" and c.progress='{progresssql}' ";
|
|
|
|
|
|
+ progresssql = $" and c.progress='{progress}' ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var typesql = "";
|
|
var typesql = "";
|
|
- if (!requert.TryGetProperty("type", out JsonElement type))
|
|
|
|
|
|
+ if (requert.TryGetProperty("type", out JsonElement type))
|
|
{
|
|
{
|
|
|
|
|
|
if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
|
|
if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
|
|
{
|
|
{
|
|
- typesql = $" and c.type='{typesql}' ";
|
|
|
|
|
|
+ typesql = $" and c.type='{type}' ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //默认当前时间, 未开始的不能查询
|
|
|
|
- var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
- //if (!requert.TryGetProperty("etime", out JsonElement etime))
|
|
|
|
- //{
|
|
|
|
- // if (etime.TryGetInt64(out long data))
|
|
|
|
- // {
|
|
|
|
- // etimestamp = data;
|
|
|
|
- // };
|
|
|
|
- //};
|
|
|
|
- string continuationToken = null;
|
|
|
|
|
|
+ string continuationTokenSchool = null;
|
|
//默认不指定返回大小
|
|
//默认不指定返回大小
|
|
int? topcout = null;
|
|
int? topcout = null;
|
|
- if (!requert.TryGetProperty("count", out JsonElement jcount))
|
|
|
|
|
|
+ if (requert.TryGetProperty("count", out JsonElement jcount))
|
|
{
|
|
{
|
|
- if (jcount.TryGetInt32(out int data))
|
|
|
|
|
|
+ if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
|
|
{
|
|
{
|
|
topcout = data;
|
|
topcout = data;
|
|
}
|
|
}
|
|
@@ -91,28 +88,44 @@ namespace TEAMModelOS.Services.Common
|
|
iscontinuation = true;
|
|
iscontinuation = true;
|
|
}
|
|
}
|
|
//如果指定了返回大小
|
|
//如果指定了返回大小
|
|
- if (!requert.TryGetProperty("continuationToken", out JsonElement continuation))
|
|
|
|
|
|
+ if (requert.TryGetProperty("continuationTokenSchool", out JsonElement continuationSchool))
|
|
{
|
|
{
|
|
- //指定了cancellationToken 表示需要进行分页
|
|
|
|
- if (!continuation.ValueKind.Equals(JsonValueKind.Null) && continuation.ValueKind.Equals(JsonValueKind.String))
|
|
|
|
|
|
+ //指定了cancellationToken continuationSchool
|
|
|
|
+ if (!continuationSchool.ValueKind.Equals(JsonValueKind.Null) && continuationSchool.ValueKind.Equals(JsonValueKind.String))
|
|
{
|
|
{
|
|
- continuationToken = continuation.GetString();
|
|
|
|
-
|
|
|
|
|
|
+ continuationTokenSchool = continuationSchool.GetString();
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//班级
|
|
//班级
|
|
|
|
+ string joinSqlClasses = "";
|
|
|
|
+ string andSqlClasses = "";
|
|
List<string> classes = null;
|
|
List<string> classes = null;
|
|
- if (!requert.TryGetProperty("classes", out JsonElement jclasses))
|
|
|
|
|
|
+ if (requert.TryGetProperty("classes", out JsonElement jclasses))
|
|
{
|
|
{
|
|
if (jclasses.ValueKind is JsonValueKind.Array)
|
|
if (jclasses.ValueKind is JsonValueKind.Array)
|
|
{
|
|
{
|
|
classes = jclasses.ToObject<List<string>>();
|
|
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 tgSql = "";
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(joinSqlClasses))
|
|
|
|
+ {
|
|
|
|
+ tgSql = $" and {andSqlClasses } ";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //科目
|
|
string joinSqlSubjects = "";
|
|
string joinSqlSubjects = "";
|
|
string andSqlSubjects = "";
|
|
string andSqlSubjects = "";
|
|
- if (!requert.TryGetProperty("subjects", out JsonElement jsubjects))
|
|
|
|
|
|
+ if (requert.TryGetProperty("subjects", out JsonElement jsubjects))
|
|
{
|
|
{
|
|
if (jsubjects.ValueKind is JsonValueKind.Array)
|
|
if (jsubjects.ValueKind is JsonValueKind.Array)
|
|
{
|
|
{
|
|
@@ -123,45 +136,39 @@ namespace TEAMModelOS.Services.Common
|
|
List<string> sqlList = new List<string>();
|
|
List<string> sqlList = new List<string>();
|
|
subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
string sql = string.Join(" , ", sqlList);
|
|
string sql = string.Join(" , ", sqlList);
|
|
- andSqlSubjects = $" and A2 in ('{sql}') ";
|
|
|
|
|
|
+ andSqlSubjects = $" and A2 in ({sql}) ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- string query = null;
|
|
|
|
- if (classes.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- List<string> sqlList = new List<string>();
|
|
|
|
- classes.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
|
|
- string sql = string.Join(" , ", sqlList);
|
|
|
|
- query = $" SELECT distinct value c FROM c JOIN A0 IN c.classes join A1 in c.tmdids {joinSqlSubjects} where c.startTime >= {stimestamp} and c.startTime <= {etimestamp} and c.pk='Activity' {typesql} {progresssql} {andSqlSubjects} and (A0 in('{sql}') or A1 ='{school} ') ";
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- query = $" SELECT distinct value c FROM c join A1 in c.tmdids {joinSqlSubjects} where c.startTime >= {stimestamp} and c.startTime <= {etimestamp} and c.pk='Activity' {typesql} {progresssql} {andSqlSubjects} and A1 ='{school}' ";
|
|
|
|
- }
|
|
|
|
|
|
|
|
List<ActivityData> datas = new List<ActivityData>();
|
|
List<ActivityData> datas = new List<ActivityData>();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+
|
|
//班主任 ,任课教师只需要查询两种校园活动 和班级活动 , 不查询私人教室创建的活动。
|
|
//班主任 ,任课教师只需要查询两种校园活动 和班级活动 , 不查询私人教室创建的活动。
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(query, continuationToken: continuationToken, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}") }))
|
|
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(school))
|
|
{
|
|
{
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
|
|
|
+ string querySchool = $" SELECT distinct value c FROM c {joinSqlClasses} {joinSqlSubjects} where {stimesql} {etimesql} and c.pk='Activity' {progresssql} {typesql} {andSqlSubjects} {tgSql}";
|
|
|
|
+ //查询数据归属学校的
|
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(querySchool, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}") }))
|
|
{
|
|
{
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
{
|
|
{
|
|
- datas.Add(obj.ToObject<ActivityData>());
|
|
|
|
- }
|
|
|
|
- //如果需要分页则跳出
|
|
|
|
- if (iscontinuation)
|
|
|
|
- {
|
|
|
|
- continuationToken = item.GetContinuationToken();
|
|
|
|
- break;
|
|
|
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
+ {
|
|
|
|
+ datas.Add(obj.ToObject<ActivityData>());
|
|
|
|
+ }
|
|
|
|
+ //如果需要分页则跳出
|
|
|
|
+ if (iscontinuation)
|
|
|
|
+ {
|
|
|
|
+ continuationTokenSchool = item.GetContinuationToken();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
bool tips = false;
|
|
bool tips = false;
|
|
- if (!requert.TryGetProperty("tips", out JsonElement jtips))
|
|
|
|
|
|
+ if (requert.TryGetProperty("tips", out JsonElement jtips))
|
|
{
|
|
{
|
|
if (!jtips.ValueKind.Equals(JsonValueKind.Null) && !jtips.ValueKind.Equals(JsonValueKind.True))
|
|
if (!jtips.ValueKind.Equals(JsonValueKind.Null) && !jtips.ValueKind.Equals(JsonValueKind.True))
|
|
{
|
|
{
|
|
@@ -170,50 +177,50 @@ namespace TEAMModelOS.Services.Common
|
|
}
|
|
}
|
|
if (tips)
|
|
if (tips)
|
|
{
|
|
{
|
|
- DoActivityTips activityTips;
|
|
|
|
- dynamic res = default;
|
|
|
|
- foreach (var data in datas)
|
|
|
|
- {
|
|
|
|
- //处理参与度,
|
|
|
|
- switch (data.type)
|
|
|
|
- {
|
|
|
|
- //投票
|
|
|
|
- case "vote":
|
|
|
|
- activityTips = DoVoteTips;
|
|
|
|
- //msgid, //0不能投票,1可以投票,2不在时间范围内,3周期内的可投票数不足
|
|
|
|
- //voteCount 可用投票数
|
|
|
|
- res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
- break;
|
|
|
|
- //问卷
|
|
|
|
- case "survey":
|
|
|
|
- //msgid 0 已作答, 1未作答,2,未完成
|
|
|
|
- activityTips = DoSurveyTips;
|
|
|
|
- res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
- break;
|
|
|
|
- //评测
|
|
|
|
- case "exam":
|
|
|
|
- //msgid 0 已作答, 1未作答,2,未完成, 用时间控制 相关发布状态,并且展示相应的结果
|
|
|
|
- activityTips = DoExamTips;
|
|
|
|
- res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
- break;
|
|
|
|
- //学习活动
|
|
|
|
- case "learn":
|
|
|
|
- //msgid 0 已完成, 1未开始,2,未完成
|
|
|
|
- activityTips = DoLearnTips;
|
|
|
|
- res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
- break;
|
|
|
|
- //作业活动
|
|
|
|
- case "homework":
|
|
|
|
- //msgid 0 已作答, 1未作答,2,未完成,3已批改,且有错误,4已批改,已完成
|
|
|
|
- //index:0,1,5 错误题序
|
|
|
|
- activityTips = DoHomeworkTips;
|
|
|
|
- res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
- break;
|
|
|
|
- default: break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //DoActivityTips activityTips;
|
|
|
|
+ // dynamic res = default;
|
|
|
|
+ //foreach (var data in datas)
|
|
|
|
+ //{
|
|
|
|
+ // //处理参与度,
|
|
|
|
+ // switch (data.type)
|
|
|
|
+ // {
|
|
|
|
+ // //投票
|
|
|
|
+ // case "vote":
|
|
|
|
+ // activityTips = DoVoteTips;
|
|
|
|
+ // //msgid, //0不能投票,1可以投票,2不在时间范围内,3周期内的可投票数不足
|
|
|
|
+ // //voteCount 可用投票数
|
|
|
|
+ // res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
+ // break;
|
|
|
|
+ // //问卷
|
|
|
|
+ // case "survey":
|
|
|
|
+ // //msgid 0 已作答, 1未作答,2,未完成
|
|
|
|
+ // activityTips = DoSurveyTips;
|
|
|
|
+ // res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
+ // break;
|
|
|
|
+ // //评测
|
|
|
|
+ // case "exam":
|
|
|
|
+ // //msgid 0 已作答, 1未作答,2,未完成, 用时间控制 相关发布状态,并且展示相应的结果
|
|
|
|
+ // activityTips = DoExamTips;
|
|
|
|
+ // res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
+ // break;
|
|
|
|
+ // //学习活动
|
|
|
|
+ // case "learn":
|
|
|
|
+ // //msgid 0 已完成, 1未开始,2,未完成
|
|
|
|
+ // activityTips = DoLearnTips;
|
|
|
|
+ // res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
+ // break;
|
|
|
|
+ // //作业活动
|
|
|
|
+ // case "homework":
|
|
|
|
+ // //msgid 0 已作答, 1未作答,2,未完成,3已批改,且有错误,4已批改,已完成
|
|
|
|
+ // //index:0,1,5 错误题序
|
|
|
|
+ // activityTips = DoHomeworkTips;
|
|
|
|
+ // res = activityTips(data, _azureCosmos, school, _azureRedis);
|
|
|
|
+ // break;
|
|
|
|
+ // default: break;
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
- return (datas, continuationToken);
|
|
|
|
|
|
+ return (datas, continuationTokenSchool);
|
|
}
|
|
}
|
|
|
|
|
|
private async static Task<dynamic> DoVoteTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string userid, AzureRedisFactory _azureRedis)
|
|
private async static Task<dynamic> DoVoteTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string userid, AzureRedisFactory _azureRedis)
|