Browse Source

添加状态查询条件

CrazyIter_Bin 4 years ago
parent
commit
a1433121d7

+ 46 - 3
TEAMModelFunction/TriggerVote.cs

@@ -58,14 +58,13 @@ namespace TEAMModelFunction
                         }
                         }
                         break;
                         break;
                     case "going":
                     case "going":
-                        var tcode = code.Replace("Vote-", "");
                         ActivityData data;
                         ActivityData data;
                         if (vote.scope == "school" || vote.scope == "teacher")
                         if (vote.scope == "school" || vote.scope == "teacher")
                         {
                         {
                             data = new ActivityData
                             data = new ActivityData
                             {
                             {
                                 id = vote.id,
                                 id = vote.id,
-                                code = $"Activity-{tcode}",
+                                code = $"Activity-{vote.owner}",
                                 type = "vote",
                                 type = "vote",
                                 name = vote.name,
                                 name = vote.name,
                                 startTime = vote.startTime,
                                 startTime = vote.startTime,
@@ -74,7 +73,8 @@ namespace TEAMModelFunction
                                 scope = vote.scope,
                                 scope = vote.scope,
                                 classes = vote.classes,
                                 classes = vote.classes,
                                 tmdids = vote.tmdids,
                                 tmdids = vote.tmdids,
-                                owner=vote.owner
+                                progress= "going",
+                                owner =vote.owner
                             };
                             };
                             await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
                             await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
                         }
                         }
@@ -90,6 +90,7 @@ namespace TEAMModelFunction
                                 endTime = vote.endTime,
                                 endTime = vote.endTime,
                                 scode = vote.code,
                                 scode = vote.code,
                                 scope = vote.scope,
                                 scope = vote.scope,
+                                progress = "going",
                                 classes = vote.classes,
                                 classes = vote.classes,
                                 owner = vote.owner
                                 owner = vote.owner
                                 // tmdids = vote.tmdids
                                 // tmdids = vote.tmdids
@@ -155,6 +156,48 @@ namespace TEAMModelFunction
                         {
                         {
                             await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
                             await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Vote>(vote, vote.id, new Azure.Cosmos.PartitionKey(vote.code));
                         }
                         }
+
+
+                        //更新结束状态
+                        if (vote.scope == "school" || vote.scope == "teacher")
+                        {
+                            data = new ActivityData
+                            {
+                                id = vote.id,
+                                code = $"Activity-{vote.owner}",
+                                type = "vote",
+                                name = vote.name,
+                                startTime = vote.startTime,
+                                endTime = vote.endTime,
+                                scode = vote.code,
+                                scope = vote.scope,
+                                classes = vote.classes,
+                                tmdids = vote.tmdids,
+                                progress = "finish",
+                                owner = vote.owner
+                            };
+                            await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(data, 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,
+                                owner = vote.owner
+                                // tmdids = vote.tmdids
+                            };
+                            await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(data, new Azure.Cosmos.PartitionKey(data.code));
+                        }
                         break;
                         break;
                 }
                 }
             }
             }

+ 4 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/ActivityData.cs

@@ -56,6 +56,10 @@ namespace TEAMModelOS.SDK.Models.Cosmos
         public long  startTime { get; set; }
         public long  startTime { get; set; }
         public long endTime { get; set; }
         public long endTime { get; set; }
         /// <summary>
         /// <summary>
+        /// pending 待发布|going 已发布|finish 已结束
+        /// </summary>
+        public string progress { get; set; }
+        /// <summary>
         /// 活动的分区键 Vote-hbcn/Vote-1606294378
         /// 活动的分区键 Vote-hbcn/Vote-1606294378
         /// </summary>
         /// </summary>
         public string scode { get; set; }
         public string scode { get; set; }

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

@@ -105,6 +105,7 @@ namespace TEAMModelOS.Controllers.Learn
         ///时间筛选范围结束时间 默认当前时间   ?"etime":1608274766666 
         ///时间筛选范围结束时间 默认当前时间   ?"etime":1608274766666 
         ///每页大小     ?"count":10/null/Undefined  
         ///每页大小     ?"count":10/null/Undefined  
         ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
         ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
+        /// 当前状态    ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束  
         /// </data>
         /// </data>
         /// <param name="request"></param>
         /// <param name="request"></param>
         /// <returns></returns>
         /// <returns></returns>
@@ -134,7 +135,15 @@ namespace TEAMModelOS.Controllers.Learn
                     };
                     };
 
 
                 };
                 };
-                
+                var progresssql = "";
+                if (!requert.TryGetProperty("progress", out JsonElement progress))
+                {
+
+                    if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        progresssql = $" and c.progress='{progresssql}' ";
+                    }
+                }
                 string continuationToken = null;
                 string continuationToken = null;
                 //默认不指定返回大小
                 //默认不指定返回大小
                 int? topcout=null;
                 int? topcout=null;
@@ -159,7 +168,7 @@ namespace TEAMModelOS.Controllers.Learn
                 List<object> votes = new List<object>();
                 List<object> votes = new List<object>();
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
              
              
-                var query =$"select   c.id,c.name,c.code,c.startTime,c.endTime,c.progress from c where c.createTime >= {stimestamp} and c.createTime <= {etimestamp} ";
+                var query =$"select   c.id,c.name,c.code,c.startTime,c.endTime,c.progress from c where c.createTime >= {stimestamp} and c.createTime <= {etimestamp}  {progresssql } ";
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query,
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query,
                     requestOptions: new QueryRequestOptions() {MaxItemCount = topcout, PartitionKey = new PartitionKey($"Vote-{code}") }))
                     requestOptions: new QueryRequestOptions() {MaxItemCount = topcout, PartitionKey = new PartitionKey($"Vote-{code}") }))
                 {
                 {

+ 1 - 0
TEAMModelOS/Controllers/School/StudentCommonController.cs

@@ -40,6 +40,7 @@ namespace TEAMModelOS.Controllers
         ///是否展示列表的 Tips                 ? "tips":true/false
         ///是否展示列表的 Tips                 ? "tips":true/false
         ///每页大小     ?"count":10/null/Undefined  
         ///每页大小     ?"count":10/null/Undefined  
         ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
         ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
+        /// 当前状态    ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束  
         /// </param>
         /// </param>
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]

+ 1 - 0
TEAMModelOS/Controllers/Teacher/TeacherCommonController.cs

@@ -41,6 +41,7 @@ namespace TEAMModelOS.Controllers
         ///是否展示列表的 Tips                 ? "tips":true/false
         ///是否展示列表的 Tips                 ? "tips":true/false
         ///每页大小     ?"count":10/null/Undefined  
         ///每页大小     ?"count":10/null/Undefined  
         ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
         ///分页Token    ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
+        /// 当前状态    ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束  
         /// </param>
         /// </param>
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]

+ 22 - 8
TEAMModelOS/Services/Common/ActivityService.cs

@@ -200,20 +200,34 @@ namespace TEAMModelOS.Services.Common
         {
         {
             //开始时间,默认最近三十天
             //开始时间,默认最近三十天
             var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
             var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
+           
+           
             if (!requert.TryGetProperty("stime", out JsonElement stime))
             if (!requert.TryGetProperty("stime", out JsonElement stime))
             {
             {
                 if (stime.TryGetInt64(out long data))
                 if (stime.TryGetInt64(out long data))
                 {
                 {
                     stimestamp = data;
                     stimestamp = data;
                 } 
                 } 
-            } 
+            }
+          
+            var progresssql = "";
+            if (!requert.TryGetProperty("progress", out JsonElement progress))
+            {
+
+                if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
+                {
+                    progresssql = $" and c.progress='{progresssql}' ";
+                }
+            }
+            var typesql = "";
             if (!requert.TryGetProperty("type", out JsonElement type))
             if (!requert.TryGetProperty("type", out JsonElement type))
             {
             {
-                //if (stime.TryGetInt64(out long data))
-                //{
-                //    stimestamp = data;
-                //} 
-            } 
+
+                if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
+                {
+                    typesql = $" and c.type='{typesql}' ";
+                }
+            }
             //默认当前时间,  未开始的不能查询
             //默认当前时间,  未开始的不能查询
             var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             //if (!requert.TryGetProperty("etime", out JsonElement etime))
             //if (!requert.TryGetProperty("etime", out JsonElement etime))
@@ -259,10 +273,10 @@ namespace TEAMModelOS.Services.Common
                 List<string> sqlList = new List<string>();
                 List<string> sqlList = new List<string>();
                 classes.ForEach( x => { sqlList.Add($" '{x}' "); });
                 classes.ForEach( x => { sqlList.Add($" '{x}' "); });
                 string sql = string.Join(" , ", sqlList);
                 string sql = string.Join(" , ", sqlList);
-                query = $" SELECT distinct  value c   FROM c   JOIN A0 IN c.classes join A1 in c.tmdids   where c.startTime >= {stimestamp} and c.startTime <= {etimestamp} and  c.pk='Activity'  and   (A0 in('{sql}') or A1 in ('{id}')) ";
+                query = $" SELECT distinct  value c   FROM c   JOIN A0 IN c.classes join A1 in c.tmdids   where c.startTime >= {stimestamp} and c.startTime <= {etimestamp} and  c.pk='Activity' {typesql} {progresssql} and   (A0 in('{sql}') or A1 in ('{id}')) ";
             }
             }
             else {
             else {
-                query = $" SELECT distinct  value c   FROM c    join A1 in c.tmdids   where c.startTime >= {stimestamp} and c.startTime <= {etimestamp}  and c.pk='Activity'  and   A1 ='{id}' ";
+                query = $" SELECT distinct  value c   FROM c    join A1 in c.tmdids   where c.startTime >= {stimestamp} and c.startTime <= {etimestamp}  and c.pk='Activity' {typesql} {progresssql} and   A1 ='{id}' ";
             }
             }
             
             
             List<ActivityData> datas = new List<ActivityData>();
             List<ActivityData> datas = new List<ActivityData>();