|
@@ -38,10 +38,10 @@ namespace TEAMModelOS.Services.Common
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) {
|
|
|
return msgid;
|
|
|
}
|
|
|
- List<string> option = new List<string>();
|
|
|
+ Dictionary<string, int> option = new Dictionary<string, int>();
|
|
|
if (request.TryGetProperty("option", out JsonElement joption))
|
|
|
{
|
|
|
- option = joption.ToObject<List<string>>();
|
|
|
+ option = joption.ToObject<Dictionary<string, int>>();
|
|
|
if (option.IsEmpty())
|
|
|
{
|
|
|
msgid = 6;
|
|
@@ -127,15 +127,33 @@ namespace TEAMModelOS.Services.Common
|
|
|
}
|
|
|
return msgid;
|
|
|
}
|
|
|
- public static async Task<byte> VoteIng(Vote vote, RedisValue value, byte msgid, List<string> option, string Field, long curr, AzureRedisFactory _azureRedis,string userid)
|
|
|
+ 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 (record.opt.Count + option.Count <= vote.voteNum)
|
|
|
+ if (addCount + crdCount <= vote.voteNum)
|
|
|
{
|
|
|
- record.opt.AddRange(option);
|
|
|
+ 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;
|
|
|
//保存投票记录
|
|
@@ -143,9 +161,9 @@ namespace TEAMModelOS.Services.Common
|
|
|
//单独保存每个人方便查询的记录
|
|
|
bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}_{vote.code}:{userid}", Field, record.ToJsonString());
|
|
|
//当前投票分组计数存入活动的Redis
|
|
|
- var group_opt= option.GroupBy(x => x);
|
|
|
- foreach (var opt in group_opt) {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}_{vote.code}", opt.Key, opt.Count());
|
|
|
+ foreach (var opt in option)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}_{vote.code}", opt.Key, opt.Value);
|
|
|
}
|
|
|
msgid = 1;
|
|
|
}
|
|
@@ -164,10 +182,9 @@ namespace TEAMModelOS.Services.Common
|
|
|
//单独保存每个人方便查询的记录
|
|
|
bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}_{vote.code}:{userid}", Field, record.ToJsonString());
|
|
|
//当前投票分组计数存入活动的Redis
|
|
|
- var group_opt = option.GroupBy(x => x);
|
|
|
- foreach (var opt in group_opt)
|
|
|
+ foreach (var opt in option)
|
|
|
{
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}_{vote.code}", opt.Key, opt.Count());
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}_{vote.code}", opt.Key, opt.Value);
|
|
|
}
|
|
|
if (status)
|
|
|
{
|
|
@@ -501,16 +518,24 @@ namespace TEAMModelOS.Services.Common
|
|
|
var value= azureRedis.GetRedisClient(8).HashGet($"Survey:Record:{survey.id}_{survey.code}",index);
|
|
|
if (value != default && !value.IsNullOrEmpty)
|
|
|
{
|
|
|
- Dictionary<string, int> dt = value.ToString().ToObject<Dictionary<string, int>>();
|
|
|
+ RdsRecord dt = value.ToString().ToObject<RdsRecord>();
|
|
|
foreach (var kp in dict)
|
|
|
- {
|
|
|
- if (dt.ContainsKey(kp.Key))
|
|
|
+ { //不建议放在reids
|
|
|
+ if (dt.srecord.ContainsKey(kp.Key))
|
|
|
+ {
|
|
|
+ dt.srecord[kp.Key] = dt.srecord[kp.Key] + kp.Value;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- dt[kp.Key] = dt[kp.Key] + kp.Value;
|
|
|
+ dt.srecord.Add(kp.Key, kp.Value);
|
|
|
+ }
|
|
|
+ if (dt.urecord.ContainsKey(userid))
|
|
|
+ {
|
|
|
+ dt.urecord[userid] = recs[index].ToArray();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dt.Add(kp.Key, kp.Value);
|
|
|
+ dt.urecord.Add(userid, recs[index].ToArray());
|
|
|
}
|
|
|
}
|
|
|
await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}_{survey.code}", index, dt.ToJsonString());
|
|
@@ -545,7 +570,10 @@ namespace TEAMModelOS.Services.Common
|
|
|
}
|
|
|
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;
|