123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Models.Cosmos;
- using TEAMModelOS.SDK.Extension;
- using Azure.Cosmos;
- using TEAMModelOS.SDK.DI;
- using HTEXLib.COMM.Helpers;
- using System.Text;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
- using StackExchange.Redis;
- namespace TEAMModelOS.Services.Common
- {
- public static class ActivityStudentService
- {
- /// <summary>
- /// 活动委托
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- delegate dynamic DoActivityTips(ActivityData data, AzureCosmosFactory _azureCosmos,string id, AzureRedisFactory _azureRedis);
- public static async Task<int> Decide(JsonElement request,AzureCosmosFactory _azureCosmos,AzureRedisFactory _azureRedis,string userid ) {
- DateTimeOffset now = DateTimeOffset.UtcNow;
- long curr = now.ToUnixTimeMilliseconds();
- byte msgid = 0;//0投票失败,1投票成功,2不在时间范围内,3不在发布范围内,4投票周期内重复投票,5周期内的可投票数不足,6未设置投票项
- //活动id
- if (!request.TryGetProperty("id", out JsonElement id)) {
- return msgid;
- }
- //活动分区
- if (!request.TryGetProperty("code", out JsonElement code)) {
- return msgid;
- }
- Dictionary<string, int> option = new Dictionary<string, int>();
- if (request.TryGetProperty("option", out JsonElement joption))
- {
- option = joption.ToObject<Dictionary<string, int>>();
- if (option.IsEmpty())
- {
- msgid = 6;
- return msgid;
- }
- }
- else
- {
- return msgid;
- }
-
- try
- {
- //1.再次检查投票
- var client = _azureCosmos.GetCosmosClient();
- Vote vote = null;
- ///TODO 检查是否在投票范围内,包括在tmdids 及班级 但是需要处理认证金钥中的班级问题
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Vote>(queryText: $"select c.id,c.code , c.progress,c.times,c.voteNum,c.startTime,c.endTime from c where c.id = '{id}'",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- vote = item;
- break;
- }
- if (vote != null)
- {
- //判断投票时间是否在起止时间内
- if (curr >= vote.startTime && curr <= vote.endTime)
- {
- string Field = "";
- RedisValue value;
- switch (vote.times) {
- case "once":
- // //如果是只能投票一次的活动则直接获取Redis的第一条 只能投一次
- Field = $"{userid}-once";
- HashEntry[] values = _azureRedis.GetRedisClient(8).HashGetAll($"Vote:Record:{vote.id}");
- if (values != null && values.Length > 0)
- {
- value = new RedisValue();
- foreach (var val in values) {
- if (val.Name.ToString() == Field) {
- value = val.Value;
- break;
- }
- }
- msgid = await VoteIng(vote, value, msgid, option, Field, curr, _azureRedis, userid);
- }
- else
- {
- msgid = await VoteIng(vote, new RedisValue(), msgid, option, Field, curr, _azureRedis, userid);
- }
- break;
- case "day": //周期内每天
- Field = $"{userid}-day-{now.ToString("yyyyMMdd")}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
- msgid = await VoteIng(vote, value, msgid, option, Field, curr, _azureRedis,userid);
- break;
- case "week": //自然周
- Field = $"{userid}-week-{now.ToString("yyyy")}{GetWeek(now)}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
- msgid = await VoteIng(vote, value, msgid, option, Field, curr, _azureRedis, userid);
- break;
- case "month": //月份
- Field = $"{userid}-month-{now.ToString("yyyyMM")}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
- msgid = await VoteIng(vote, value, msgid, option, Field, curr, _azureRedis, userid);
- break;
- case "year"://年份
- Field = $"{userid}-year-{now.ToString("yyyy")}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
- msgid = await VoteIng(vote, value, msgid, option, Field, curr, _azureRedis, userid);
- break;
- }
- }
- else
- {
- msgid = 2;
- }
- }
- }
- catch (Exception e)
- {
- throw new Exception(e.StackTrace);
- }
- 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)
- {
- if (!value.IsNullOrEmpty)
- {
- VoteRecord record=value.ToString().ToObject<VoteRecord>();
- int addCount = 0;
- foreach (var op in option) {
- addCount +=op.Value;
- }
- int crdCount = 0;
- foreach (var op in record.opt)
- {
- crdCount += op.Value;
- }
- //处理记录投票+当前设置的投票是否小于等于周期内最大投票数
- if (addCount + crdCount <= vote.voteNum)
- {
- foreach (var op in option)
- {
- if (record.opt.ContainsKey(op.Key))
- {
- record.opt[op.Key] = record.opt[op.Key] + op.Value;
- }
- else {
- record.opt.Add(op.Key, op.Value);
- }
- }
- record.time = curr;
- record.userid = userid;
- //保存投票记录
- bool status = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}", Field, record.ToJsonString());
- //单独保存每个人方便查询的记录
- bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}:{userid}", Field, record.ToJsonString());
- //当前投票分组计数存入活动的Redis
- foreach (var opt in option)
- {
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}", opt.Key, opt.Value);
- }
- msgid = 1;
- }
- else
- {
- msgid = 5;
- }
- }
- else
- {
- if (option.Count <= vote.voteNum)
- {
- //保存投票记录
- VoteRecord record = new VoteRecord { opt = option, time = curr, userid = userid };
- bool status = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}", Field, record.ToJsonString());
- //单独保存每个人方便查询的记录
- bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}:{userid}", Field, record.ToJsonString());
- //当前投票分组计数存入活动的Redis
- foreach (var opt in option)
- {
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}", opt.Key, opt.Value);
- }
- if (status)
- {
- msgid = 1;
- }
- }
- else {
- msgid = 5;
- }
- }
- return msgid;
- }
- /// <summary>
- /// 获取时间的在当年的第几周
- /// </summary>
- /// <param name="dt"></param>
- /// <returns></returns>
- public static int GetWeek(DateTimeOffset dt)
- {
- DateTimeOffset time = Convert.ToDateTime(dt.ToString("yyyy") + "-01-01");
- TimeSpan ts = dt - time;
- int iii = (int)time.DayOfWeek;
- int day = int.Parse(ts.TotalDays.ToString("F0"));
- if (iii == 0)
- {
- day--;
- }
- else
- {
- day = day - (7 - iii) - 1;
- }
- int week = ((day + 7) / 7) + 1;
- return week;
- }
- /// <summary>
- /// 学生端查询
- /// </summary>
- /// <param name="containerId">容器</param>
- /// <param name="requert"></param>
- /// <param name="id">登录者ID</param>
- /// <param name="_azureCosmos"></param>
- /// <returns></returns>
- public static async Task<(List<ActivityData> datas, string continuationTokenSchool,string continuationTokenTeacher)> FindAsStu( JsonElement requert, string id,string school, AzureCosmosFactory _azureCosmos,AzureRedisFactory _azureRedis)
- {
- if (string.IsNullOrWhiteSpace(id)) {
- id = requert.GetProperty("userid").GetString();
- }
- if (string.IsNullOrWhiteSpace(school))
- {
- school = requert.GetProperty("school").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 typesql = "";
- if (requert.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 continuationTokenSchool = null;
- string continuationTokenTeacher = 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 (requert.TryGetProperty("continuationTokenSchool", out JsonElement continuationSchool))
- {
- //指定了cancellationToken continuationSchool
- if (!continuationSchool.ValueKind.Equals(JsonValueKind.Null) && continuationSchool.ValueKind.Equals(JsonValueKind.String))
- {
- continuationTokenSchool = continuationSchool.GetString();
- iscontinuation = true;
- }
- }
- //如果指定了返回大小
- if (requert.TryGetProperty("continuationTokenTeacher", out JsonElement continuationTeacher))
- {
- //指定了cancellationToken 表示需要进行分页
- if (!continuationTeacher.ValueKind.Equals(JsonValueKind.Null) && continuationTeacher.ValueKind.Equals(JsonValueKind.String))
- {
- continuationTokenTeacher = continuationTeacher.GetString();
- iscontinuation = true;
- }
- }
- //个人tmdid
- string joinSqlTmdids = $"join A0 in c.tmdids";
- string andSqlTmdids = $" A0 in('{id}')";
- //班级
- 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 tgSql = "";
- if (!string.IsNullOrWhiteSpace(joinSqlClasses))
- {
- tgSql = $"and ({andSqlTmdids} or {andSqlClasses } )";
- }
- else {
- tgSql = $"and {andSqlTmdids}";
- }
- //科目
- 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<ActivityData> datas = new List<ActivityData>();
- var client = _azureCosmos.GetCosmosClient();
- if (!string.IsNullOrWhiteSpace(school)) {
- string querySchool = $" SELECT distinct value c FROM c {joinSqlTmdids} {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}") }))
- {
- 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<ActivityData>());
- }
- //如果需要分页则跳出
- if (iscontinuation)
- {
- continuationTokenSchool = item.GetContinuationToken();
- break;
- }
- }
- }
- }
- //TODO会处理掉科目相关的
- //查询数据归属Common 私人教室的。
- string queryTeacher = $" SELECT distinct value c FROM c {joinSqlTmdids} {joinSqlClasses} where {stimesql} {etimesql} and c.pk='Activity' {progresssql} {typesql} {tgSql} ";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryTeacher, continuationToken: continuationTokenTeacher, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"Activity-Common") }))
- {
- 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<ActivityData>());
- }
- //如果需要分页则跳出
- if (iscontinuation)
- {
- continuationTokenTeacher = item.GetContinuationToken();
- break;
- }
- }
- }
- bool tips = false;
- if (requert.TryGetProperty("tips", out JsonElement jtips))
- {
- if (!jtips.ValueKind.Equals(JsonValueKind.Undefined) && !jtips.ValueKind.Equals(JsonValueKind.Null) && (jtips.ValueKind.Equals(JsonValueKind.True)|| jtips.ValueKind.Equals(JsonValueKind.False)))
- {
- tips = jtips.GetBoolean();
- }
- }
- if (tips)
- {
- DoActivityTips activityTips;
- //TODO 处理活动tips 的res
- dynamic res = default;
- foreach (var data in datas)
- {
- switch (data.type)
- {
- //投票
- case "vote":
- activityTips = DoVoteTips;
- //msgid, //0不能投票,1可以投票,2不在时间范围内,3周期内的可投票数不足
- //voteCount 可用投票数
- res =await activityTips(data, _azureCosmos, id, _azureRedis);
- break;
- //问卷
- case "survey":
- //msgid 0 已作答, 1未作答,2,未完成
- activityTips = DoSurveyTips;
- res = await activityTips(data, _azureCosmos, id, _azureRedis);
- break;
- //评测
- case "exam":
- //msgid 0 已作答, 1未作答,2,未完成, 用时间控制 相关发布状态,并且展示相应的结果
- activityTips = DoExamTips;
- res = await activityTips(data, _azureCosmos, id, _azureRedis);
- break;
- //学习活动
- case "learn":
- //msgid 0 已完成, 1未开始,2,未完成
- activityTips = DoLearnTips;
- res = await activityTips(data, _azureCosmos, id, _azureRedis);
- break;
- //作业活动
- case "homework":
- //msgid 0 已作答, 1未作答,2,未完成,3已批改,且有错误,4已批改,已完成
- //index:0,1,5 错误题序
- activityTips = DoHomeworkTips;
- res = await activityTips(data, _azureCosmos, id, _azureRedis);
- break;
- default: break;
- }
- }
- }
- return (datas, continuationTokenSchool,continuationTokenTeacher);
- }
- public static async Task<int> Answer(JsonElement request, AzureCosmosFactory _azureCosmos, AzureRedisFactory azureRedis, string userid, AzureStorageFactory _azureStorage)
- {
- DateTimeOffset now = DateTimeOffset.UtcNow;
- long curr = now.ToUnixTimeMilliseconds();
- byte msgid = 0;//
- //活动id
- if (!request.TryGetProperty("id", out JsonElement id))
- {
- return msgid;
- }
- //活动分区
- if (!request.TryGetProperty("code", out JsonElement code))
- {
- return msgid;
- }
- try
- {
- //1.再次检查投票
- var client = _azureCosmos.GetCosmosClient();
- Survey survey = null;
- ///TODO 检查是否在投票范围内,包括在tmdids 及班级 但是需要处理认证金钥中的班级问题
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Survey>(queryText: $"select c.id,c.owner, c.code ,c.ans , c.progress,c.times,c.startTime,c.endTime from c where c.id = '{id}'",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- survey = item;
- break;
- }
- if (survey != null)
- {
- //判断投票时间是否在起止时间内
- if (curr >= survey.startTime && curr <= survey.endTime)
- {
- if (request.TryGetProperty("record", out JsonElement record))
- {
- var recs = record.ToObject<List<List<string>>>();
- if (recs.IsNotEmpty() && recs.Count == survey.ans.Count)
- {
- //处理问卷调查表的每一题选项数
- // List<Task<string>> tasks = new List<Task<string>>();
- for (int index = 0; index < recs.Count; index++) {
- Dictionary<string, int> dict = new Dictionary<string, int>();
- if (recs[index].IsNotEmpty()) {
- recs[index].ForEach(x => {
- if (survey.ans[index].Contains(x))
- {
- if (dict.ContainsKey(x))
- {
- dict[x] = dict[x] + 1;
- }
- else {
- dict[x] = 1;
- }
- }
- else {
- if (dict.ContainsKey("other"))
- {
- dict["other"] = dict["other"] + 1;
- }
- else
- {
- dict["other"] = 1;
- }
- //这里暂不处理, 结算再处理other
- // tasks.Add(_azureStorage.UploadFileByContainer(survey.owner,new { other=x, userid, time =curr }.ToJsonString(), "survey", $"{survey.id}/other/{index}/{userid}.json", false));
- }
- });
- }
- var value= azureRedis.GetRedisClient(8).HashGet($"Survey:Record:{survey.id}",index);
- if (value != default && !value.IsNullOrEmpty)
- {
- Dictionary<string, int> dt = value.ToString().ToObject<Dictionary<string, int>>();
- foreach (var kp in dict)
- { //不建议放在reids
- if (dt.ContainsKey(kp.Key))
- {
- dt[kp.Key] = dt[kp.Key] + kp.Value;
- }
- else
- {
- dt.Add(kp.Key, kp.Value);
- }
- }
- await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}", index, dt.ToJsonString());
- }
- else {
- await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}", index, dict.ToJsonString());
- }
- }
- //处理other ,这里暂不处理, 结算再处理other
- //await Task.WhenAll(tasks);
- //保存当前提交人的记录
- await _azureStorage.UploadFileByContainer(survey.owner,new { record= record, userid, time = curr }.ToJsonString(), "survey", $"{survey.id}/urecord/{userid}.json");
- await azureRedis.GetRedisClient(8).SetAddAsync($"Survey:Submit:{survey.id}", userid);
- msgid = 1;
- }
- else {
- //提交的作答不符合问卷的答案长度。
- msgid = 3;
- }
- }
-
- }
- else
- {
- msgid = 2;
- }
- }
- }
- catch (Exception e)
- {
- throw new Exception(e.StackTrace);
- }
- return msgid;
- }
- public class RdsRecord {
- public Dictionary<string, int> srecord { get; set; } = new Dictionary<string, int>();
- public Dictionary<string, string[]> urecord { get; set; } = new Dictionary<string, string[]>();
- }
- private async static Task<dynamic> DoVoteTips(ActivityData commonData , AzureCosmosFactory _azureCosmos,string userid,AzureRedisFactory _azureRedis)
- {
- Vote vote=null;
- var client = _azureCosmos.GetCosmosClient();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Vote>($"select value c from c where c.id='{commonData.id}'",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(commonData.scode) }))
- {
- vote = item;
- break;
- }
- byte msgid = 0;
- int voteCount = 0;
- if (vote != null) {
- DateTimeOffset now = DateTimeOffset.UtcNow;
- long curr = now.ToUnixTimeMilliseconds();
- //判断投票时间是否在起止时间内
- if (curr >= vote.startTime && curr <= vote.endTime)
- {
- string Field = "";
- RedisValue value = default;
- switch (vote.times)
- {
- case "once":
- // //如果是只能投票一次的活动则直接获取Redis的第一条 只能投一次
- Field = $"{userid}-once";
- RedisValue[] values = _azureRedis.GetRedisClient(8).HashValues($"Vote:Record:{vote.id}");
- if (values != null && values.Length>0)
- {
- value = values[0];
- }
- break;
- case "day": //周期内每天
- Field = $"{userid}-day-{now.ToString("yyyyMMdd")}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
- break;
- case "week": //自然周
- Field = $"{userid}-week-{now.ToString("yyyy")}{GetWeek(now)}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
-
- break;
- case "month": //月份
- Field = $"{userid}-month-{now.ToString("yyyyMM")}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
-
- break;
- case "year"://年份
- Field = $"{userid}-year-{now.ToString("yyyy")}";
- value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
-
- break;
- }
- if (value != default && !value.IsNullOrEmpty)
- {
- List<string> opt = null;
- JsonElement record = value.ToString().ToObject<JsonElement>();
- if (record.TryGetProperty("opt", out JsonElement jopt)) {
- opt = jopt.ToObject<List<string>>();
- }
- if (opt != null)
- {
- //处理记录投票是否小于等于周期内最大投票数
- if (opt.Count <= vote.voteNum)
- {
- voteCount = vote.voteNum - opt.Count;
- msgid = 1;
- }
- else
- {
- //3周期内的可投票数不足
- msgid = 3;
- voteCount = 0;
- }
- }
- else {
- msgid = 1;
- voteCount = vote.voteNum;
- }
- }
- else {
- //未投票,可以投票
- msgid = 1;
- voteCount = vote.voteNum;
- }
- }
- else
- {
- msgid = 2;
- voteCount = 0;
- }
- }
- return new {msgid,voteCount };
- }
- private static dynamic DoHomeworkTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string id, AzureRedisFactory _azureRedis)
- {
- return null;
- }
- private static dynamic DoLearnTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string id, AzureRedisFactory _azureRedis)
- {
- return null;
- }
- private static dynamic DoExamTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string id, AzureRedisFactory _azureRedis)
- {
- return null;
- }
- private static dynamic DoSurveyTips(ActivityData commonData, AzureCosmosFactory _azureCosmos, string id, AzureRedisFactory _azureRedis)
- {
- return null;
- }
-
- }
- }
|