|
@@ -12,6 +12,7 @@ using System.Text;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
|
|
|
using StackExchange.Redis;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
|
|
|
namespace TEAMModelOS.Services.Common
|
|
|
{
|
|
@@ -128,6 +129,9 @@ namespace TEAMModelOS.Services.Common
|
|
|
}
|
|
|
return msgid;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static async Task<byte> VoteIng(Vote vote, RedisValue value, byte msgid, Dictionary<string, int> option, string Field, long curr, AzureRedisFactory _azureRedis,string userid,string times,string endpoint)
|
|
|
{
|
|
|
if (!value.IsNullOrEmpty)
|
|
@@ -222,7 +226,141 @@ namespace TEAMModelOS.Services.Common
|
|
|
int week = ((day + 7) / 7) + 1;
|
|
|
return week;
|
|
|
}
|
|
|
+ public static async Task<(List<StuActivity> datas, string continuationToken)> FindActivity(JsonElement request, string id, string school, AzureCosmosFactory _azureCosmos, AzureRedisFactory azureRedis)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(id))
|
|
|
+ {
|
|
|
+ id = request.GetProperty("userid").GetString();
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(school))
|
|
|
+ {
|
|
|
+ school = request.GetProperty("school").GetString();
|
|
|
+ }
|
|
|
+ //开始时间,默认最近三十天
|
|
|
+ var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
|
|
|
+ if (request.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 typesql = "";
|
|
|
+ if (request.TryGetProperty("type", out JsonElement type))
|
|
|
+ {
|
|
|
|
|
|
+ if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ typesql = $" and c.type='{type}' ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string continuationToken = null;
|
|
|
+ //默认不指定返回大小
|
|
|
+ int? topcout = null;
|
|
|
+ if (request.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 (request.TryGetProperty("continuationToken", out JsonElement token))
|
|
|
+ {
|
|
|
+ //指定了cancellationToken continuationSchool
|
|
|
+ if (!token.ValueKind.Equals(JsonValueKind.Null) && token.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ continuationToken = token.GetString();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ////个人tmdid
|
|
|
+ //string joinSqlTmdids = $"join A0 in c.tmdids";
|
|
|
+ //string andSqlTmdids = $" A0 in('{id}')";
|
|
|
+ ////班级
|
|
|
+ //string joinSqlClasses = "";
|
|
|
+ //string andSqlClasses = "";
|
|
|
+ //List<string> classes = null;
|
|
|
+ //if (request.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 tgSql = "";
|
|
|
+ //if (!string.IsNullOrWhiteSpace(joinSqlClasses))
|
|
|
+ //{
|
|
|
+ // tgSql = $" and ({andSqlTmdids} or {andSqlClasses } )";
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // tgSql = $" and {andSqlTmdids}";
|
|
|
+ //}
|
|
|
+ //科目
|
|
|
+ string joinSqlSubjects = "";
|
|
|
+ string andSqlSubjects = "";
|
|
|
+ if (request.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<StuActivity> datas = new List<StuActivity>();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (!string.IsNullOrWhiteSpace(school))
|
|
|
+ {
|
|
|
+ string querySchool = $" SELECT distinct value c FROM c {joinSqlSubjects} where {stimesql} {etimesql} and c.pk='Activity' {typesql} {andSqlSubjects} ";
|
|
|
+
|
|
|
+ //查询数据归属学校的
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(querySchool, continuationToken: continuationToken, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-{school}-{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<StuActivity>());
|
|
|
+ }
|
|
|
+ //如果需要分页则跳出
|
|
|
+ if (iscontinuation)
|
|
|
+ {
|
|
|
+ continuationToken = item.GetContinuationToken();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return (datas, continuationToken);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 学生端查询
|