瀏覽代碼

更新owner

CrazyIter_Bin 4 年之前
父節點
當前提交
27a6544ba5

+ 7 - 4
TEAMModelFunction/TriggerSurvey.cs

@@ -30,12 +30,15 @@ namespace TEAMModelFunction
             }
             }
             var adid = tdata.id;
             var adid = tdata.id;
             var adcode = "";
             var adcode = "";
+            string blobcntr = null;
             if (tdata.scope == "school")
             if (tdata.scope == "school")
             {
             {
                   adcode = $"Activity-{tdata.school}";
                   adcode = $"Activity-{tdata.school}";
+                blobcntr = tdata.school;
             }
             }
             else if (tdata.scope == "private"){
             else if (tdata.scope == "private"){
                 adcode = $"Activity-{tdata.creatorId}";
                 adcode = $"Activity-{tdata.creatorId}";
+                 blobcntr = tdata.creatorId;
             }
             }
             ActivityData data = null;
             ActivityData data = null;
             try
             try
@@ -159,9 +162,9 @@ namespace TEAMModelFunction
                         }
                         }
                         var cods = new { records = recs, userids };
                         var cods = new { records = recs, userids };
                         //问卷整体情况
                         //问卷整体情况
-                        await _azureStorage.UploadFileByContainer(survey.blobcntr, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
+                        await _azureStorage.UploadFileByContainer(blobcntr, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
                         //结算每道题的答题情况
                         //结算每道题的答题情况
-                        var ContainerClient =  _azureStorage.GetBlobContainerClient(survey.blobcntr);
+                        var ContainerClient =  _azureStorage.GetBlobContainerClient(blobcntr);
                         List<Task<string>> tasks = new List<Task<string>>();
                         List<Task<string>> tasks = new List<Task<string>>();
                         //获取
                         //获取
                         try {
                         try {
@@ -169,7 +172,7 @@ namespace TEAMModelFunction
                             List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
                             List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
                             foreach (string item in items)
                             foreach (string item in items)
                             {
                             {
-                                var Download = await _azureStorage.GetBlobContainerClient(survey.blobcntr).GetBlobClient(item).DownloadAsync();
+                                var Download = await _azureStorage.GetBlobContainerClient(blobcntr).GetBlobClient(item).DownloadAsync();
                                 var json = await JsonDocument.ParseAsync(Download.Value.Content);
                                 var json = await JsonDocument.ParseAsync(Download.Value.Content);
                                 var Record = json.RootElement.ToObject<SurveyRecord>();
                                 var Record = json.RootElement.ToObject<SurveyRecord>();
                                 surveyRecords.Add(Record);
                                 surveyRecords.Add(Record);
@@ -213,7 +216,7 @@ namespace TEAMModelFunction
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
-                                tasks.Add(  _azureStorage.UploadFileByContainer(survey.blobcntr, question.ToJsonString(), "survey", url));
+                                tasks.Add(  _azureStorage.UploadFileByContainer(blobcntr, question.ToJsonString(), "survey", url));
                             }
                             }
                             await Task.WhenAll(tasks);
                             await Task.WhenAll(tasks);
                         } catch (Exception ex) {
                         } catch (Exception ex) {

+ 5 - 2
TEAMModelFunction/TriggerVote.cs

@@ -28,13 +28,16 @@ namespace TEAMModelFunction
             }
             }
             var adid = tdata.id;
             var adid = tdata.id;
             var adcode = "";
             var adcode = "";
+            string blobcntr = null;
             if (tdata.scope == "school")
             if (tdata.scope == "school")
             {
             {
                 adcode = $"Activity-{tdata.school}";
                 adcode = $"Activity-{tdata.school}";
+                blobcntr = tdata.school;
             }
             }
             else if (tdata.scope == "private")
             else if (tdata.scope == "private")
             {
             {
                 adcode = $"Activity-{tdata.creatorId}";
                 adcode = $"Activity-{tdata.creatorId}";
+                blobcntr = tdata.creatorId;
             }
             }
             ActivityData data = null;
             ActivityData data = null;
             try
             try
@@ -168,11 +171,11 @@ namespace TEAMModelFunction
                         var gp = recordsBlob.GroupBy(x => x.userid).Select(x => new { key = x.Key, list = x.ToList() });
                         var gp = recordsBlob.GroupBy(x => x.userid).Select(x => new { key = x.Key, list = x.ToList() });
                         foreach (var g in gp)
                         foreach (var g in gp)
                         {
                         {
-                            tasks.Add(_azureStorage.UploadFileByContainer(vote.blobcntr, g.list.ToJsonString(), "vote", $"{vote.id}/urecord/{g.key}.json"));
+                            tasks.Add(_azureStorage.UploadFileByContainer(blobcntr, g.list.ToJsonString(), "vote", $"{vote.id}/urecord/{g.key}.json"));
                         }
                         }
                         //处理活动方的记录, 
                         //处理活动方的记录, 
                         string url = $"/vote/{vote.id}/record.json";
                         string url = $"/vote/{vote.id}/record.json";
-                        tasks.Add(_azureStorage.UploadFileByContainer(vote.blobcntr, new { options = countcds, records = recordsBlob }.ToJsonString(), "vote", $"{vote.id}/record.json"));
+                        tasks.Add(_azureStorage.UploadFileByContainer(blobcntr, new { options = countcds, records = recordsBlob }.ToJsonString(), "vote", $"{vote.id}/record.json"));
                         //处理投票者的记录
                         //处理投票者的记录
 
 
                         if (string.IsNullOrEmpty(vote.recordUrl))
                         if (string.IsNullOrEmpty(vote.recordUrl))

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/Common/Survey.cs

@@ -20,9 +20,9 @@ namespace TEAMModelOS.SDK.Models
             tmdids = new List<string>();
             tmdids = new List<string>();
         }
         }
         /// <summary>
         /// <summary>
-        /// blob容器名
+        ///发布层级 类型 school  teacher
         /// </summary>
         /// </summary>
-        public string blobcntr { get; set; }
+        public string owner { get; set; }
         /// <summary>
         /// <summary>
         /// 学校编码或教室tmdid
         /// 学校编码或教室tmdid
         /// </summary>
         /// </summary>

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/Common/Vote.cs

@@ -21,9 +21,9 @@ namespace TEAMModelOS.SDK.Models
 
 
         }
         }
         /// <summary>
         /// <summary>
-        /// blob容器名
+        /// 发布层级 类型 school  teacher
         /// </summary>
         /// </summary>
-        public string blobcntr { get; set; }
+        public string owner { get; set; }
         /// <summary>
         /// <summary>
         /// 学校编码或教师tmdid
         /// 学校编码或教师tmdid
         /// </summary>
         /// </summary>

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -23,9 +23,9 @@ namespace TEAMModelOS.SDK.Models
             classes = new List<string>();
             classes = new List<string>();
         }
         }
         /// <summary>
         /// <summary>
-        /// blob容器名
+        ///发布层级 类型 school  teacher
         /// </summary>
         /// </summary>
-        public string blobcntr { get; set; }
+        public string owner { get; set; }
         public string name { get; set; }
         public string name { get; set; }
         public string school { get; set; }
         public string school { get; set; }
         public string creatorId { get; set; }
         public string creatorId { get; set; }

+ 0 - 187
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -482,193 +482,6 @@ namespace TEAMModelOS.Controllers
             }
             }
             return Ok(new {records = res});
             return Ok(new {records = res});
         }
         }
-
-
-        /// <summary>
-        /// 问卷记录 当活动没结算且没有BlobUrl时则调用此接口
-        /// </summary>
-        /// <redis>
-        /// {"C":2,"A":2,"other":2}
-        /// </redis>
-        /// <param name="request">
-        /// !"id":"aaaa"
-        /// !"code":"Survey-hbcn"/"code":"Survey-1606285227"
-        /// </param>
-        /// <returns>
-        /// </returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("settlement")]
-        //[AuthToken(Roles = "teacher,student")]
-        public async Task<IActionResult> Settlement(JsonElement request)
-        {
-            try
-            {
-                var client = _azureCosmos.GetCosmosClient();
-                //活动id
-                if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                //活动分区
-                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
-                Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.GetString(), new PartitionKey($"{code}"));
-                List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", $"{id}" }, { "PartitionKey", survey.progress } });
-                ActivityData data = null;
-                if (survey != null)
-                {
-                    var adid = survey.id;
-                    var adcode = $"Activity-{survey.school}";
-                    try {
-                        if (survey.scope == "school")
-                        {
-                            data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                        }
-                        else if (survey.scope == "private")
-                        {
-                            data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                        }
-                    } catch {
-                        data = null;
-                    }
-                    if (survey.ttl >= 1)
-                    {
-                        _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
-                        _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
-                        if (data != null)
-                        {
-                            data.ttl = 1;
-                            if (survey.scope == "school")
-                            {
-                                data = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                            }
-                            else if (survey.scope == "private")
-                            {
-                                data = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
-                            }
-                        }
-                        await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.醍摩豆服務運維群組);
-                        return Ok();
-                    }
-                    else
-                    {
-                        switch (survey.progress)
-                        {
-
-                            case "finish":
-                                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.blobcntr, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
-                                //结算每道题的答题情况
-
-                                var ContainerClient = _azureStorage.GetBlobContainerClient(survey.blobcntr);
-                                var route = ContainerClient.Uri.ToString();
-
-                                //获取
-
-                                try
-                                {
-                                    List<string> items = await ContainerClient.List($"survey/{survey.id}/urecord");
-                                    List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
-                                    (string uri, string sas) blobAuth = _azureStorage.GetBlobContainerSAS(survey.blobcntr, BlobContainerSasPermissions.Read);
-                                    string sas = blobAuth.sas;
-                                    var rcode = await _clientFactory.CreateClient().GetAsync(new Uri($"{route}/survey/{survey.id}/record.json?{sas}"));
-                                    var jsonc = await JsonDocument.ParseAsync(await rcode.Content.ReadAsStreamAsync());
-                                    var Recordc = jsonc.RootElement.ToObject<JsonElement>();
-                                    HttpClient httpClient = _clientFactory.CreateClient();
-                                    await _dingDing.SendBotMsg($"问卷调查问题结算数据11111--->>{Recordc.ToJsonString()}", GroupNames.成都开发測試群組);
-                                    foreach (string item in items)
-                                    {
-                                        var url = $"{route}/{item}?{sas}";
-                                        var response = await httpClient.GetAsync(new Uri(url));
-                                        var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
-                                        var Record = json.RootElement.ToObject<SurveyRecord>();
-                                        surveyRecords.Add(Record);
-                                    }
-                                    await _dingDing.SendBotMsg($"问卷调查问题结算数据{surveyRecords.ToJsonString()}", GroupNames.成都开发測試群組);
-                                    for (int index = 0; index < survey.answers.Count; index++)
-                                    {
-                                        string url = $"{survey.id}/qrecord/{index}.json";
-                                        QuestionRecord question = new QuestionRecord() { index = index };
-                                        foreach (SurveyRecord record in surveyRecords)
-                                        {
-                                            if (record.ans.Count == survey.answers.Count)
-                                            {
-                                                foreach (var an in record.ans[index])
-                                                {
-                                                    //
-                                                    if (question.opt.ContainsKey(an))
-                                                    {
-                                                        if (question.opt[an] != null)
-                                                        {
-                                                            question.opt[an].Add(record.userid);
-                                                        }
-                                                        else
-                                                        {
-                                                            question.opt[an] = new HashSet<string>() { record.userid };
-                                                        }
-                                                    }
-                                                    else
-                                                    {
-                                                        if (survey.answers[index].Contains(an))
-                                                        {
-                                                            //如果是客观题code
-                                                            question.opt.Add(an, new HashSet<string> { record.userid });
-                                                        }
-                                                        else
-                                                        {
-                                                            //如果不是客观code
-                                                            question.other[record.userid] = an;
-                                                        }
-                                                    }
-                                                }
-                                            }
-                                        }
-                                        await _azureStorage.UploadFileByContainer(survey.blobcntr, question.ToJsonString(), "survey", url);
-                                    }
-                                }
-                                catch (Exception ex)
-                                {
-                                    await _dingDing.SendBotMsg($"问卷调查问题结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
-                                }
-                                if (string.IsNullOrEmpty(survey.recordUrl))
-                                {
-                                    survey.recordUrl = $"/survey/{survey.id}/record.json";
-                                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new Azure.Cosmos.PartitionKey(survey.code));
-                                }
-                                else
-                                {
-                                    //异动,且已经有结算记录则不必再继续。
-                                    //break;
-                                }
-                                // await Task.WhenAll(tasks);
-                                //更新结束状态
-                                data.progress = "finish";
-                                if (survey.scope == "school")
-                                {
-                                    await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                                }
-                                else if (survey.scope == "private")
-                                {
-                                    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                                }
-                                break;
-                        }
-                    }
-
-                }
-                return Ok();
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},common/survey/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
-                return BadRequest(ex.StackTrace);
-            }
-        }
-
     }
     }
     public class QuestionRecord
     public class QuestionRecord
     {
     {

+ 0 - 123
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -482,128 +482,5 @@ namespace TEAMModelOS.Controllers.Learn
             }
             }
             else { return Ok(new { msgid = 0 }); }
             else { return Ok(new { msgid = 0 }); }
         }
         }
-
-        /// <summary>
-        /// 问卷记录 当活动没结算且没有BlobUrl时则调用此接口
-        /// </summary>
-        /// <redis>
-        /// {"C":2,"A":2,"other":2}
-        /// </redis>
-        /// <param name="request">
-        /// !"id":"aaaa"
-        /// !"code":"Survey-hbcn"/"code":"Survey-1606285227"
-        /// </param>
-        /// <returns>
-        /// </returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("settlement")]
-        //[AuthToken(Roles = "teacher,student")]
-        public async Task<IActionResult> Settlement(JsonElement request)
-        {
-            try
-            {
-                var client = _azureCosmos.GetCosmosClient();
-                //活动id
-                if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                //活动分区
-                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
-                Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.GetString(), new PartitionKey($"{code}"));
-                if (vote != null)
-                {
-                    ActivityData data;
-
-                    if (vote.progress == "finish")
-                    {
-                        //获取投票活动的所有投票记录
-                        var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{vote.id}");
-                        //获取投票活动的选项及投票数
-                        var counts = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Vote:Count:{vote.id}");
-                        List<dynamic> countcds = new List<dynamic>();
-                        if (counts != null && counts.Length > 0)
-                        {
-                            foreach (var count in counts)
-                            {
-                                countcds.Add(new { code= count.Element.ToString() , count = (int)count.Score });
-                            }
-                        }
-                        List<Task<string>> tasks = new List<Task<string>>();
-                        List<VoteRecord> recordsBlob = new List<VoteRecord>();
-                        foreach (var rcd in records)
-                        {
-                            var value = rcd.Value.ToString().ToObject<VoteRecord>();
-                            recordsBlob.Add(value);
-                        }
-                        //分组每个人的 
-                        var gp = recordsBlob.GroupBy(x => x.userid).Select(x => new { key = x.Key, list = x.ToList() });
-                        foreach (var g in gp)
-                        {
-                            tasks.Add(_azureStorage.UploadFileByContainer(vote.blobcntr, g.list.ToJsonString(), "vote", $"{vote.id}/urecord/{g.key}.json"));
-                        }
-                        //处理活动方的记录, 
-                        string url = $"/vote/{vote.id}/record.json";
-                        vote.recordUrl = url;
-                        tasks.Add(_azureStorage.UploadFileByContainer(vote.blobcntr, new{ options = countcds, records = recordsBlob }   .ToJsonString(), "vote", $"{vote.id}/record.json"));
-                        //处理投票者的记录
-                        await Task.WhenAll(tasks);
-                        //
-                        if (string.IsNullOrEmpty(vote.recordUrl))
-                        {
-                            await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
-                        }
-                        //更新结束状态
-                        if (vote.scope == "school")
-                        {
-                            data = new ActivityData
-                            {
-                                id = vote.id,
-                                code = $"Activity-{vote.school}",
-                                type = "vote",
-                                name = vote.name,
-                                startTime = vote.startTime,
-                                endTime = vote.endTime,
-                                scode = vote.code,
-                                scope = vote.scope,
-                                progress = "finish",
-                                classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
-                                tmdids = vote.tmdids.IsNotEmpty() ? vote.tmdids : new List<string> { "" },
-                                subjects = new List<string> { "" }
-
-                            };
-                            await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                        }
-                        else if (vote.scope == "private")
-                        {
-                            //更新结束状态
-                            data = new ActivityData
-                            {
-                                id = vote.id,
-                                code = $"Activity-Common",
-                                type = "vote",
-                                name = vote.name,
-                                startTime = vote.startTime,
-                                endTime = vote.endTime,
-                                scode = vote.code,
-                                scope = vote.scope,
-                                progress = "finish",
-                                classes = vote.classes.IsNotEmpty() ? vote.classes : new List<string> { "" },
-                                tmdids = new List<string> { "" },
-                                subjects = new List<string> { "" }
-                            };
-                            await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
-                        }
-                    }
-                    return Ok(new { vote });
-                }
-                else
-                {
-                    return BadRequest("id,code不存在!");
-                }
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},common/survey/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
-                return BadRequest(ex.StackTrace);
-            }
-        }
     }
     }
 }
 }

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

@@ -547,7 +547,17 @@ namespace TEAMModelOS.Services.Common
                                 //处理other ,这里暂不处理, 结算再处理other 
                                 //处理other ,这里暂不处理, 结算再处理other 
                                 //await Task.WhenAll(tasks);
                                 //await Task.WhenAll(tasks);
                                 //保存当前提交人的记录
                                 //保存当前提交人的记录
-                                await _azureStorage.UploadFileByContainer(survey.blobcntr, new SurveyRecord { ans= recs, userid=userid, time = curr }.ToJsonString(), "survey", $"{survey.id}/urecord/{userid}.json");
+
+                                string blobcntr = null;
+                                if (survey.scope == "school")
+                                {
+                                    blobcntr = survey.school;
+                                }
+                                else if (survey.scope == "private")
+                                {
+                                    blobcntr = survey.creatorId;
+                                }
+                                await _azureStorage.UploadFileByContainer(blobcntr, 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);
                                 await azureRedis.GetRedisClient(8).SetAddAsync($"Survey:Submit:{survey.id}", userid);
                                 msgid = 1;
                                 msgid = 1;
                             }
                             }