فهرست منبع

处理第一次投票 数量问题

CrazyIter_Bin 4 سال پیش
والد
کامیت
68ae3ac612

+ 14 - 0
TEAMModelOS.SDK/DI/AzureRedis/AzureRedisFactory.cs

@@ -43,5 +43,19 @@ namespace TEAMModelOS.SDK.DI
                 return null;
             }
         }
+        //public (IDatabase db , IServer server ) GetRedisDbCmClient(int dbnum = -1, string name = "Default")
+        //{
+        //    try
+        //    {
+        //        var cm = ConnectionMultiplexers.GetOrAdd(name, x => ConnectionMultiplexer.Connect(_optionsMonitor.Get(name).RedisConnectionString));
+                
+        //        return (cm.GetDatabase(dbnum),cm.GetServer(cm.GetEndPoints()[0]));
+        //    }
+        //    catch (OptionsValidationException e)
+        //    {
+        //        _logger?.LogWarning(e, e.Message);
+        //        return (null,null);
+        //    }
+        //}
     }
 }

+ 15 - 7
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -13,22 +13,30 @@ namespace TEAMModelOS.Controllers.XTest
     [ApiController]
     public class TestController :ControllerBase
     {
+        private readonly AzureRedisFactory _azureRedis;
         private readonly AzureCosmosFactory _azureCosmos;
-        public TestController(AzureCosmosFactory azureCosmos) {
+        public TestController(AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis) {
             _azureCosmos = azureCosmos;
+            _azureRedis = azureRedis;
         }
 
         /// <summary>
-        /// 删除
+        /// 测试redis通配符
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "teacher")]
-        [HttpPost("test-dict-null")]
-        public async Task<IActionResult> DictNull(Dictionary<string, object> dict) {
-            
-            return Ok() ;
+        [HttpGet("test-redis")]
+        public async Task<IActionResult> DictNull( ) {
+
+           var db  = _azureRedis.GetRedisClient(8);
+            //var keys = server.Keys(pattern: "Vote*", database: db.Database);
+            //foreach (var key in keys) {
+            //    Console.WriteLine(key);
+            //}
+
+           // db.HashScanAsync()
+                return Ok() ;
         }
         /// <summary>
         /// 删除

+ 17 - 12
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -83,7 +83,7 @@ namespace TEAMModelOS.Services.Common
                                 }
                                 else
                                 {
-                                    msgid = 1;
+                                    msgid = await VoteIng(vote, new RedisValue(), msgid, option, Field, curr, _azureRedis, userid);
                                 }
                                 break;
                             case "day": //周期内每天
@@ -139,7 +139,6 @@ namespace TEAMModelOS.Services.Common
                         await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}_{vote.code}", opt.Key, opt.Count());
                     }
                     msgid = 1;
-                   
                 }
                 else
                 {
@@ -148,18 +147,24 @@ namespace TEAMModelOS.Services.Common
             }
             else
             {
-                //保存投票记录
-                VoteRecord record = new VoteRecord { opt = option, time = curr,userid= userid };
-                bool status = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}_{vote.code}", Field, record.ToJsonString());
-                //当前投票分组计数存入活动的Redis
-                var group_opt = option.GroupBy(x => x);
-                foreach (var opt in group_opt)
+                if (option.Count <= vote.voteNum)
                 {
-                    await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}_{vote.code}", opt.Key, opt.Count());
+                    //保存投票记录
+                    VoteRecord record = new VoteRecord { opt = option, time = curr, userid = userid };
+                    bool status = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}_{vote.code}", 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());
+                    }
+                    if (status)
+                    {
+                        msgid = 1;
+                    }
                 }
-                if (status)
-                {
-                    msgid = 1;
+                else {
+                    msgid = 5;
                 }
             }
             return msgid;