浏览代码

调整公告。

CrazyIter_Bin 3 年之前
父节点
当前提交
aee975c7f5

+ 3 - 1
TEAMModelOS.FunctionV4/CosmosDB/CommonTrigger.cs

@@ -57,7 +57,9 @@ namespace TEAMModelOS.FunctionV4
                         element.TryGetProperty("pk", out JsonElement jsond);
                         if (!string.IsNullOrWhiteSpace($"{jsond}"))
                         {
-                            if ($"{jsond}".Equals("Receiver", StringComparison.OrdinalIgnoreCase) || $"{jsond}".Equals("ExamClassResult", StringComparison.OrdinalIgnoreCase))
+                            if ($"{jsond}".Equals("Receiver", StringComparison.OrdinalIgnoreCase)
+                                ||$"{jsond}".Equals("Notice", StringComparison.OrdinalIgnoreCase)
+                                || $"{jsond}".Equals("ExamClassResult", StringComparison.OrdinalIgnoreCase))
                             {
                                 ///通知接收者的变更
                                 continue;

+ 6 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/Notice.cs

@@ -10,7 +10,12 @@ namespace TEAMModelOS.SDK.Models
         public string title { get; set; }
         public string content { get; set; }
         public string school { get; set; }
-        
+        /// <summary>
+        /// 发布状态
+        /// </summary>
+        [Required(ErrorMessage = "scope 必须设置")]
+        public string scope { get; set; }
+
         [Required(ErrorMessage = "creatorId 必须设置")]
         public string creatorId { get; set; }
         /// <summary>

+ 1 - 1
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -61,7 +61,7 @@ namespace TEAMModelOS.Controllers
         {
             var (userid, _name, _picture,school) = HttpContext.GetAuthTokenInfo();
             var client = _azureCosmos.GetCosmosClient();
-            object scope = null; ;
+            object scope = null;  
             HttpContext?.Items.TryGetValue("Scope", out scope);
             int memberType =2;
             if ($"{scope}".Equals(Constant.ScopeStudent))

+ 135 - 21
TEAMModelOS/Controllers/School/NoticeController.cs

@@ -62,8 +62,19 @@ namespace TEAMModelOS.Controllers
             {
                 var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
                 //新增
+                
                 var client = _azureCosmos.GetCosmosClient();
-                request.code =$"Notice-{request.code}";
+                if (request.scope.Equals("school") && (!string.IsNullOrEmpty(request.school)|| !string.IsNullOrEmpty(school)))
+                {
+                    request.school = string.IsNullOrWhiteSpace(request.school) ? school : request.school;
+                    request.code = $"Notice-{request.school}";
+                }
+                else if (request.scope.Equals("private") && (!string.IsNullOrEmpty(request.creatorId)|| !string.IsNullOrEmpty(userid)))
+                {
+                    request.creatorId = string.IsNullOrWhiteSpace(request.creatorId) ? userid : request.creatorId;
+                    request.code = $"Notice";
+                }
+               // request.code =$"Notice-{request.code}";
                 request.pk = "Notice";
                 request.ttl = -1;
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
@@ -87,20 +98,20 @@ namespace TEAMModelOS.Controllers
                 {
                     request.id = Guid.NewGuid().ToString();
                   
-                    request = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                    request = await client.GetContainer(Constant.TEAMModelOS,Constant.Common).CreateItemAsync(request, new PartitionKey($"{request.code}"));
                 }
                 else
                 {
-                    var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
+                    var response = await client.GetContainer(Constant.TEAMModelOS,   Constant.Common).ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
                  
                     if (response.Status == 200)
                     {
                        
-                        request = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
+                        request = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
                     }
                     else
                     {
-                        request = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                        request = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).CreateItemAsync(request, new PartitionKey($"{request.code}"));
                     }
                 }
                 return Ok(new { vote = request });
@@ -110,19 +121,12 @@ namespace TEAMModelOS.Controllers
                 await _dingDing.SendBotMsg($"OS,{_option.Location},school/Notice/upsert()\n{e.Message}\n{e.StackTrace}\n{e .StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest(e.StackTrace);
             }
-        }/// <summary>
-         /// 查询投票活动,用于列表,编辑,查看
-         /// </summary>
-         /// <data>
-         ///Vote-学校/教师编码  活动分区        !"code":"hbcn"/1606285227 
-         ///时间筛选范围开始时间 默认30天之前   ?"stime":1608274766154  
-         ///时间筛选范围结束时间 默认当前时间   ?"etime":1608274766666 
-         ///每页大小     ?"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\"}}]"
-         /// 当前状态    ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束  
-         /// </data>
-         /// <param name="request"></param>
-         /// <returns></returns>
+        } 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("find")]
         [Authorize(Roles = "IES")]
@@ -168,6 +172,17 @@ namespace TEAMModelOS.Controllers
                         publishsql = $" and c.publish={publish} ";
                     }
                 }
+
+                var creatorIdSql = "";
+                if (requert.TryGetProperty("creatorId", out JsonElement creatorId))
+                {
+
+                    if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.String))
+                    {
+                        publishsql = $" and c.creatorId='{creatorId}' ";
+                    }
+                }
+
                 var typesql = "";
                 if (requert.TryGetProperty("type", out JsonElement type))
                 {
@@ -197,8 +212,8 @@ namespace TEAMModelOS.Controllers
                 }
                 List<Notice> notices = new List<Notice>();
                 var client = _azureCosmos.GetCosmosClient();
-                var query = $"select distinct value(c) from c {joinSqlClasses} where  1=1 {etimestampsql} {stimestampsql} {publishsql }  {typesql} {andSqlClasses} ";
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Notice>(queryText: query,
+                var query = $"select distinct value(c) from c {joinSqlClasses} where  1=1 {etimestampsql} {stimestampsql} {publishsql }  {typesql} {andSqlClasses}  {creatorIdSql} ";
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
                     requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice-{code}") }))
                 {
                     notices.Add(item);
@@ -211,6 +226,105 @@ namespace TEAMModelOS.Controllers
                 return BadRequest(ex.StackTrace);
             }
         }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("find-by-student")]
+        [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "teacher,admin,student")]
+        public async Task<IActionResult> FindByStudent(JsonElement requert)
+        {
+            try
+            {
+                object scope = null;
+                HttpContext?.Items.TryGetValue("Scope", out scope);
+                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
+                //必须有学校或者教师编码
+               // if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+               
+                string stimestampsql = "";
+                string etimestampsql = "";
+                var stimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                if (requert.TryGetProperty("stime", out JsonElement stime))
+                {
+                    if (long.TryParse($"{stime}", out long data))
+                    {
+                        stimestamp = data;
+                    }
+                }
+                stimestampsql = $" and c.startTime <= {stimestamp} ";
+                //默认当前时间
+                var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                if (requert.TryGetProperty("etime", out JsonElement etime))
+                {
+                    if (long.TryParse($"{etime}", out long data))
+                    {
+                        etimestamp = data;
+                    }
+                }
+                etimestampsql = $" and c.endTime >= {etimestamp} ";
+                var publishsql = $" and c.publish=1 ";
+                string joinSqlClasses = "";
+                string andSqlClasses = "";
+                if (requert.TryGetProperty("classes", out JsonElement _classes))
+                {
+
+                    if (_classes.ValueKind is JsonValueKind.Array)
+                    {
+                        List<string> subjects = _classes.ToObject<List<string>>();
+                        if (subjects.IsNotEmpty())
+                        {
+                            joinSqlClasses = " join A2 in c.classes ";
+                            List<string> sqlList = new List<string>();
+                            subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
+                            string sql = string.Join(" , ", sqlList);
+                            andSqlClasses = $" and A2 in ({sql}) ";
+                        }
+                    }
+                }
+                else {
+                    return BadRequest();
+                }
+                List<Notice> notices = new List<Notice>();
+                var client = _azureCosmos.GetCosmosClient();
+                var query = $"select distinct value(c) from c {joinSqlClasses} where  1=1 {etimestampsql} {stimestampsql} {publishsql}    {andSqlClasses} ";
+
+                if ($"{scope}".Equals(Constant.ScopeTmdUser))
+                {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
+                        requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice") }))
+                    {
+                        notices.Add(item);
+                    }
+                }
+                else {
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
+                       requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice") }))
+                    {
+                        notices.Add(item);
+                    }
+                    if (!string.IsNullOrWhiteSpace(school)) {
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
+                           requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice-{school}") }))
+                        {
+                            notices.Add(item);
+                        }
+                    }
+                }
+               
+                return Ok(new { notices });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},school/Notice/find()\n", GroupNames.醍摩豆服務運維群組);
+                return BadRequest(ex.StackTrace);
+            }
+        }
+
         /// <summary>
         /// 删除
         /// </summary>
@@ -227,7 +341,7 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
-                await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Notice-{code}"));
+                await client.GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Notice-{code}"));
                 return Ok(new { status = 200 });
             }
             catch (Exception e)