Browse Source

问卷已作答接口

CrazyIter_Bin 4 years ago
parent
commit
18adcc5e62

+ 1 - 1
TEAMModelFunction/MonitorCosmosDB.cs

@@ -67,7 +67,7 @@ namespace TEAMModelFunction
                                 TriggerVote.Trigger(_azureCosmos, _serviceBus, _azureStorage, _dingDing, client, input, code, stime, etime, school, _azureRedis);
                                 break;
                             case "Survey":
-                                TriggerSurvey.Trigger(_azureCosmos, _serviceBus, _azureStorage, _dingDing, client, input, code, stime, etime, school, _azureRedis);
+                                TriggerSurvey.Trigger(_azureCosmos, _serviceBus, _azureStorage, _dingDing, client, input, code, stime, etime, school, _azureRedis, _clientFactory);
                                 break;
 
                         }

+ 14 - 4
TEAMModelFunction/TriggerSurvey.cs

@@ -4,6 +4,7 @@ using Azure.Storage.Blobs.Models;
 using Microsoft.Azure.Documents;
 using System;
 using System.Collections.Generic;
+using System.Net.Http;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
@@ -12,13 +13,15 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
+using TEAMModelOS.SDK.Module.AzureBlob.Configuration;
 
 namespace TEAMModelFunction
 {
    public class TriggerSurvey
     {
         public static async void Trigger(AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
-               CosmosClient client, Document input, string code, long stime, long etime, string school,AzureRedisFactory _azureRedis)
+               CosmosClient client, Document input, string code, long stime, long etime, string school,AzureRedisFactory _azureRedis, System.Net.Http.IHttpClientFactory _clientFactory)
         {
             Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
             List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", survey.progress } });
@@ -131,9 +134,16 @@ namespace TEAMModelFunction
                     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}";
-                    });
+                    List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
+                    //获取
+                    BlobAuth blobAuth = _azureStorage.GetBlobSasUriRead(survey.owner, $"survey/{survey.id}/record.json");
+                    foreach (BlobItem item in items) {
+                        var url = $"{route}/{item.Name}";
+                        var response = await _clientFactory.CreateClient().GetAsync(new Uri(url + blobAuth.sas));
+                        var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
+                        var Record = json.RootElement.ToObject<SurveyRecord>();
+                        surveyRecords.Add(Record);
+                    }
                     break;
             }
         }

+ 0 - 38
TEAMModelOS.SDK/Models/Cosmos/Student/SurveyRecord.cs

@@ -1,38 +0,0 @@
-using DocumentFormat.OpenXml.Math;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Text;
-using TEAMModelOS.SDK.Context.Attributes.Azure;
-using TEAMModelOS.SDK.DI;
-
-namespace TEAMModelOS.SDK.Models
-{    
-    public class SurveyRecord : CosmosEntity
-    {
-        public SurveyRecord() {
-            classroom = new ClassroomItem();
-        }
-
-        /// <summary>
-        /// 姓名
-        /// </summary>
-        public string name { get; set; }
-
-        /// <summary>
-        /// 上课班级
-        /// </summary>
-        public ClassroomItem classroom { get; set; }
-
-        /// <summary>
-        /// 提交时间
-        /// </summary>
-        public long submitTime { get; set; }
-
-        public List<SurveyAnswer> answers { get; set; }
-    }
-    public class SurveyAnswer { 
-        public int order { get; set; }
-        public List<string> answer { get; set; }
-    }
-}

+ 0 - 41
TEAMModelOS.SDK/Models/Cosmos/Student/VoteRecord.cs

@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Text;
-using TEAMModelOS.SDK.Context.Attributes.Azure;
-using TEAMModelOS.SDK.DI;
-
-namespace TEAMModelOS.SDK.Models
-{    
-    //public class VoteRecord : CosmosEntity
-    //{
-
-    //    public VoteRecord()
-    //    {
-    //        classroom = new ClassroomItem();
-    //    }
-
-    //    /// <summary>
-    //    /// 姓名
-    //    /// </summary>
-    //    public string name { get; set; }
-
-    //    /// <summary>
-    //    /// 上课班级
-    //    /// </summary>
-    //    public ClassroomItem classroom { get; set; }
-
-
-
-    //    /// <summary>
-    //    /// 提交时间
-    //    /// </summary>
-    //    public long submitTime { get; set; }
-
-    //    /// <summary>
-    //    /// 选项
-    //    /// </summary>
-    //    public string option { get; set; }
-
-    //}
-}

+ 9 - 4
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -340,7 +340,6 @@ namespace TEAMModelOS.Controllers
         /// <param name="request">
         /// !"id":"aaaa"
         /// !"code":"Survey-hbcn"/"code":"Survey-1606285227"
-        /// !"record":[["A","B"],["A"],["D"],[],["建议提升服务质量"]]
         /// </param>
         /// <returns>
         /// msgid=0投票失败,1提交成功,2不在时间范围内,3不在发布范围内,6未设置投票项
@@ -360,9 +359,15 @@ namespace TEAMModelOS.Controllers
             {
                 return BadRequest();
             }
-
-
-            else { return Ok(new { msgid = 0 }); }
+            List<string> userids = new List<string>();
+            var values= await _azureRedis.GetRedisClient(8).SetMembersAsync($"Survey:Submit:{id}");
+            if (values != default && values.Length>0) {
+                foreach(var val in values) {
+                    userids.Add(val);
+                }
+            }
+            return Ok(new { userids = userids }); 
+            
         }
 
 

+ 1 - 1
TEAMModelOS/Services/Common/ActivityStudentService.cs

@@ -541,7 +541,7 @@ namespace TEAMModelOS.Services.Common
                                 //处理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 _azureStorage.UploadFileByContainer(survey.owner,new SurveyRecord { ans= recs, userid=userid, time = curr }.ToJsonString(), "survey", $"{survey.id}/urecord/{userid}.json");
                                 await azureRedis.GetRedisClient(8).SetAddAsync($"Survey:Submit:{survey.id}", userid);
                                 msgid = 1;
                             }