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

+ 11 - 1
TEAMModelFunction/TriggerSurvey.cs

@@ -1,5 +1,6 @@
 using Azure.Cosmos;
 using Azure.Messaging.ServiceBus;
+using Azure.Storage.Blobs.Models;
 using Microsoft.Azure.Documents;
 using System;
 using System.Collections.Generic;
@@ -116,14 +117,23 @@ namespace TEAMModelFunction
                     }
                     break;
                 case "finish":
-                    var records =await  _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{survey.id}_{survey.code}");
+                    var records =await  _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{survey.id}");
                     List<dynamic> recs = new List<dynamic>();
                     foreach (var rcd in records) {
                         var value = rcd.Value.ToString().ToObject<JsonElement>();
                         recs.Add(new { index = rcd.Name.ToString(), ans = value });
                     }
                     var cods = new { records = recs };
+                    //问卷整体情况
                     await  _azureStorage.UploadFileByContainer(survey.owner, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
+                    //结算每道题的答题情况
+                   
+                    var ContainerClient =   _azureStorage.GetBlobContainerClient(survey.owner);
+                    var route = ContainerClient.Uri.ToString();
+                    List<BlobItem> items = await ContainerClient.List($"survey/{survey.id}/urecord");
+                    items.ForEach(x => {
+                        var url = $"{route}/{x.Name}";
+                    });
                     break;
             }
         }

+ 17 - 0
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -40,6 +40,23 @@ namespace TEAMModelOS.SDK.DI
                 return size;
             }
         }
+
+        public static async Task<List<BlobItem>> List(this BlobContainerClient client, string prefix = null) {
+            try
+            {
+                List<BlobItem> items = new List<BlobItem>();
+                await foreach (BlobItem item in client.GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix)) {
+                    items.Add(item);
+                }
+                return items;
+            }
+            catch
+            {
+                return null;
+            }
+
+        }
+
         /// <summary>
         /// 取得指定前置詞的 Blob 名稱的總大小(Bytes),例如指定目錄名稱為前置詞
         /// </summary>      

+ 1 - 1
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -358,7 +358,7 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
             //获取问卷记录
-            var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{id}_{code}");
+            var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{id}");
             List<dynamic> res = new List<dynamic>();
             foreach (var rcd in records)
             {

+ 2 - 2
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -352,9 +352,9 @@ namespace TEAMModelOS.Controllers.Learn
                 return BadRequest();
             }
             //获取投票活动的所有投票记录
-            var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{id}_{code}");
+            var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{id}");
             //获取投票活动的选项及投票数
-            var counts = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Vote:Count:{id}_{code}");
+            var counts = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Vote:Count:{id}");
             List<OptionVote> options = new List<OptionVote>();
             if (counts != null && counts.Length > 0)
             {

+ 1 - 5
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -28,11 +28,7 @@ namespace TEAMModelOS.Controllers.XTest
         [ProducesDefaultResponseType]
         [HttpGet("multiple-blob")]
         public async Task<IActionResult> MultipleBlob() {
-            List<Task<string>> tasks = new List<Task<string>>();
-            for (int i = 0; i < 100; i++) {
-                tasks.Add(_azureStorage.UploadFileByContainer("hbcn", $"{i}", "test", $"index.json"));
-            }
-            await Task.WhenAll(tasks);
+            await  _azureStorage.GetBlobContainerClient("hbcn").List("other");
             return Ok();
         }
 

+ 30 - 37
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -76,7 +76,7 @@ namespace TEAMModelOS.Services.Common
                             case "once":
                                 // //如果是只能投票一次的活动则直接获取Redis的第一条 只能投一次
                                 Field = $"{userid}-once";
-                                HashEntry[] values = _azureRedis.GetRedisClient(8).HashGetAll($"Vote:Record:{vote.id}_{vote.code}");
+                                HashEntry[] values = _azureRedis.GetRedisClient(8).HashGetAll($"Vote:Record:{vote.id}");
                                 if (values != null  && values.Length > 0)
                                 {
                                     value = new RedisValue();
@@ -95,22 +95,22 @@ namespace TEAMModelOS.Services.Common
                                 break;
                             case "day": //周期内每天
                                 Field = $"{userid}-day-{now.ToString("yyyyMMdd")}";
-                                value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}_{vote.code}", Field);
+                                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}_{vote.code}", Field);
+                                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}_{vote.code}", Field);
+                                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}_{vote.code}", Field);
+                                value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
                                 msgid = await VoteIng(vote, value, msgid, option, Field, curr, _azureRedis, userid);
                                 break;
                         }
@@ -157,13 +157,13 @@ namespace TEAMModelOS.Services.Common
                     record.time = curr;
                     record.userid = userid;
                     //保存投票记录
-                    bool status = await _azureRedis.GetRedisClient(8).HashSetAsync($"Vote:Record:{vote.id}_{vote.code}", Field, record.ToJsonString());
+                    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}_{vote.code}:{userid}", 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}_{vote.code}", opt.Key, opt.Value);
+                        await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}", opt.Key, opt.Value);
                     }
                     msgid = 1;
                 }
@@ -178,13 +178,13 @@ namespace TEAMModelOS.Services.Common
                 {
                     //保存投票记录
                     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());
+                    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}_{vote.code}:{userid}", 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}_{vote.code}", opt.Key, opt.Value);
+                        await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Vote:Count:{vote.id}", opt.Key, opt.Value);
                     }
                     if (status)
                     {
@@ -487,7 +487,7 @@ namespace TEAMModelOS.Services.Common
                             if (recs.IsNotEmpty() && recs.Count == survey.ans.Count)
                             {
                                 //处理问卷调查表的每一题选项数
-                                List<Task<string>> tasks = new List<Task<string>>();
+                               // 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()) {
@@ -511,44 +511,37 @@ namespace TEAMModelOS.Services.Common
                                                 {
                                                     dict["other"] = 1;
                                                 }
-                                                tasks.Add(_azureStorage.UploadFileByContainer(survey.owner,new { other=x, userid, time =curr }.ToJsonString(), "survey", $"{survey.id}/other/{index}/{userid}.json", false));
+                                                //这里暂不处理, 结算再处理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}_{survey.code}",index);
+                                    var value= azureRedis.GetRedisClient(8).HashGet($"Survey:Record:{survey.id}",index);
                                     if (value != default && !value.IsNullOrEmpty)
                                     {
-                                        RdsRecord dt = value.ToString().ToObject<RdsRecord>();
+                                        Dictionary<string, int> dt = value.ToString().ToObject<Dictionary<string, int>>();
                                         foreach (var kp in dict)
                                         {   //不建议放在reids
-                                            if (dt.srecord.ContainsKey(kp.Key))
+                                            if (dt.ContainsKey(kp.Key))
                                             {
-                                                dt.srecord[kp.Key] = dt.srecord[kp.Key] + kp.Value;
+                                                dt[kp.Key] = dt[kp.Key] + kp.Value;
                                             }
                                             else
                                             {
-                                                dt.srecord.Add(kp.Key, kp.Value);
-                                            }
-                                            if (dt.urecord.ContainsKey(userid))
-                                            {
-                                                dt.urecord[userid] = recs[index].ToArray();
-                                            }
-                                            else
-                                            {
-                                                dt.urecord.Add(userid, recs[index].ToArray());
+                                                dt.Add(kp.Key, kp.Value);
                                             }
                                         }
-                                        await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}_{survey.code}", index, dt.ToJsonString());
+                                        await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}", index, dt.ToJsonString());
                                     }
                                     else {
-                                       await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}_{survey.code}", index, dict.ToJsonString());
+                                       await azureRedis.GetRedisClient(8).HashSetAsync($"Survey:Record:{survey.id}", index, dict.ToJsonString());
                                     }
                                 }
-                              
-                                //处理other
-                                await Task.WhenAll(tasks);
+
+                                //处理other ,这里暂不处理, 结算再处理other 
+                                //await Task.WhenAll(tasks);
                                 //保存当前提交人的记录
-                                await _azureStorage.UploadFileByContainer(survey.owner,new { record= record, userid, time = curr }.ToJsonString(), "survey", $"{survey.id}/record/{userid}.json");
+                                await _azureStorage.UploadFileByContainer(survey.owner,new { record= record, userid, time = curr }.ToJsonString(), "survey", $"{survey.id}/urecord/{userid}.json");
                                 msgid = 1;
                             }
                             else {
@@ -599,7 +592,7 @@ namespace TEAMModelOS.Services.Common
                         case "once":
                             // //如果是只能投票一次的活动则直接获取Redis的第一条 只能投一次
                             Field = $"{userid}-once";
-                            RedisValue[] values = _azureRedis.GetRedisClient(8).HashValues($"Vote:Record:{vote.id}_{vote.code}");
+                            RedisValue[] values = _azureRedis.GetRedisClient(8).HashValues($"Vote:Record:{vote.id}");
                             if (values != null && values.Length>0)
                             {
                                 value = values[0];
@@ -607,21 +600,21 @@ namespace TEAMModelOS.Services.Common
                             break;
                         case "day": //周期内每天
                             Field = $"{userid}-day-{now.ToString("yyyyMMdd")}";
-                            value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}_{vote.code}", Field);
+                            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}_{vote.code}", Field);
+                            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}_{vote.code}", Field);
+                            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}_{vote.code}", Field);
+                            value = _azureRedis.GetRedisClient(8).HashGet($"Vote:Record:{vote.id}", Field);
                            
                             break;
                     }