Selaa lähdekoodia

学生端活动数据返回

CrazyIter_Bin 4 vuotta sitten
vanhempi
commit
f7fa20b020

+ 8 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Syllabus.cs

@@ -34,5 +34,13 @@ namespace TEAMModelOS.SDK.Models
         public string tmdname { get; set; }
         public bool coedit { get; set; }
         public bool share { get; set; }
+        /// <summary>
+        /// 共编-是否同意
+        /// </summary>
+        public int cagree { get; set; } = 0;
+        /// <summary>
+        /// 分享-是否同意
+        /// </summary>
+        public int sagree { get; set; } = 0;
     }
 }

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

@@ -27,7 +27,7 @@ namespace TEAMModelOS.SDK.Models
         /// <summary>
         /// 学校编码或教师tmdid
         /// </summary>
-        [Required(ErrorMessage = "school 必须设置")]
+       // [Required(ErrorMessage = "school 必须设置")]
         public string school { get; set; }
         /// <summary>
         /// 投票名称

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/Teacher/Share.cs

@@ -68,11 +68,11 @@ namespace TEAMModelOS.SDK.Models
         /// <summary>
         /// 共编-是否同意
         /// </summary>
-        public bool cagree { get; set; } = false;
+        public int cagree { get; set; } = 0;
         /// <summary>
         /// 分享-是否同意
         /// </summary>
-        public bool sagree { get; set; } = false;
+        public int sagree { get; set; } =0;
     }
     /// <summary>
     /// 主动分享给谁,当接收者接收并完成相关资源复制后则删除本条数据。

+ 39 - 0
TEAMModelOS/Controllers/Common/CommonController.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.Controllers.Common
 {
@@ -250,5 +251,43 @@ namespace TEAMModelOS.Controllers.Common
                 return BadRequest();
             }
         }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("delete-activity")]
+        [AuthToken(Roles = "teacher,admin,student")]
+        public async Task<IActionResult> DeleteActivity(JsonElement element) {
+            try {
+                if (!element.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                if (!element.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                if (!element.TryGetProperty("role", out JsonElement role)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();
+                if (role.ValueKind.Equals(JsonValueKind.String))
+                {
+                    if (role.GetString().Equals("teacher") || role.GetString().Equals("admin"))
+                    {
+                        await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>($"{id}", new PartitionKey($"{code}"));
+                    }
+                    else if (role.GetString().Equals("student"))
+                    {
+                        await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuActivity>($"{id}", new PartitionKey($"{code}"));
+                    }
+                    else
+                    {
+                        return Ok(new { status = 500 });
+                    }
+                }
+                else {
+                    return Ok(new { status = 500 });
+                }
+                return Ok(new { status = 200 });
+            } catch (Exception ex) {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/delete-activity\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { status = 500 });
+            }
+        }
     }
 }

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

@@ -279,28 +279,30 @@ namespace TEAMModelOS.Controllers
         [AuthToken(Roles = "teacher,admin,student")]
         public async Task<IActionResult> FindById(JsonElement requert)
         {
+            Survey survey = null;
+            //活动id
+            if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+            //活动分区
+            if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
-                //活动id
-                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                //活动分区
-                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
-                Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.GetString(), new PartitionKey($"{code}"));
+               
+                survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.GetString(), new PartitionKey($"{code}"));
                 if (survey != null)
                 {
 
-                    return Ok(new { survey });
+                    return Ok(new { survey , status = 200 });
                 }
                 else
                 {
-                    return BadRequest("id,code不存在!");
+                    return Ok(new { survey, status = 404 });
                 }
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},common/survey/find-id()\n{ex.Message}{requert.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
-                return BadRequest(ex.StackTrace);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/survey/find-id\n{ex.Message}{ex.StackTrace}\n{id}\n{code}  ", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { survey, status = 404 });
             }
 
         }

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

@@ -281,28 +281,30 @@ namespace TEAMModelOS.Controllers.Learn
         [AuthToken(Roles = "teacher,admin,student")]
         public async Task<IActionResult> FindById(JsonElement requert)
         {
+            Vote vote = null;
+            //活动id
+            if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+            //活动分区
+            if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
-                //活动id
-                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                //活动分区
-                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
-                Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.GetString(), new PartitionKey($"{code}"));
+              
+                  vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.GetString(), new PartitionKey($"{code}"));
                 if (vote != null)
                 {
                     
-                    return Ok(new { vote });
+                    return Ok(new { vote, status = 200 });
                 }
                 else
                 {
-                    return BadRequest("id,code不存在!");
+                    return Ok(new { vote, status = 404 });
                 }
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
-                return BadRequest(ex.StackTrace);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find-id()\n{ex.Message}\n{id}\n{code}", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { vote,status=404 });
             }
 
         }

+ 15 - 3
TEAMModelOS/Controllers/Item/ItemController.cs

@@ -54,10 +54,22 @@ namespace TEAMModelOS.Controllers
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
-                if (!request.TryGetProperty("periodId", out JsonElement periodId)) return BadRequest();
+                request.TryGetProperty("periodId", out JsonElement periodId);
                 if (!request.TryGetProperty("schoolCode", out JsonElement schoolCode)) return BadRequest();
-                ItemCond itemCond = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemCond>($"{periodId}", new PartitionKey($"ItemCond-{schoolCode}"));
-                return Ok(new { itemCond });
+                if (periodId.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrEmpty(periodId.GetString()))
+                {
+                    ItemCond itemCond = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ItemCond>($"{periodId}", new PartitionKey($"ItemCond-{schoolCode}"));
+                    return Ok(new { itemConds = new List<ItemCond>() { itemCond } });
+                }
+                else {
+                    List<ItemCond> items = new List<ItemCond>();
+                    var queryslt = $"SELECT  value(c) FROM c ";
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ItemCond>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ItemCond-{schoolCode}") }))
+                    {
+                        items.Add(item);
+                    }
+                    return Ok(new { itemConds = items });
+                }
             } catch (Exception ex) {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},item/cond-count()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();

+ 146 - 6
TEAMModelOS/Controllers/Syllabus/ShareController.cs

@@ -2,6 +2,7 @@ using Azure.Cosmos;
 using HTEXLib.COMM.Helpers;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Options;
 using System;
 using System.Collections.Generic;
@@ -16,6 +17,7 @@ using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.Services.Common;
 
 namespace TEAMModelOS.Controllers
@@ -31,13 +33,16 @@ namespace TEAMModelOS.Controllers
         private readonly SnowflakeId _snowflakeId;
         private readonly DingDing _dingDing;
         private readonly Option _option;
-
-        public ShareController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
+        private readonly IConfiguration _configuration;
+        private readonly NotificationService _notificationService;
+        public ShareController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService)
         {
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
             _dingDing = dingDing;
-            _option = option?.Value;
+            _option = option?.Value; 
+            _configuration = configuration;
+            _notificationService = notificationService;
         }
         /*
          {
@@ -97,9 +102,47 @@ namespace TEAMModelOS.Controllers
                         (Syllabus syllabus, List<Share> shares) = DoAuth(request, syllabusD);
                         shares.ForEach(async x=> {
                             await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
+                            //发送共编或分享通知
+                            if (x.coedit == true) {
+                                Notification notification = new Notification
+                                {
+                                    hubName = "hita",
+                                    type = "msg",
+                                    from = $"ies5:{request.school}",
+                                    to = new List<string>() { x.code.Replace("Share-","") },
+                                    label = $"coedit_syllabus",
+                                    body = new { biz = "coedit", tmdid = x.issuer,  schoolcode = $"{request.school}",  status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
+                                    expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
+                                };
+                                var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
+                                var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
+                                var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
+                                var location = _option.Location;
+                                var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
+                            }
+                            if (x.share == true)
+                            {
+                                Notification notification = new Notification
+                                {
+                                    hubName = "hita",
+                                    type = "msg",
+                                    from = $"ies5:{request.school}",
+                                    to = new List<string>() { x.code.Replace("Share-", "") },
+                                    label = $"share_syllabus",
+                                    body = new { biz = "share", tmdid = x.issuer, schoolcode = $"{request.school}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
+                                    expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
+                                }; 
+                                var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
+                                var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
+                                var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
+                                var location = _option.Location;
+                                var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
+                            }
+                           
                         });
-                       
                         await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus, new PartitionKey($"Syllabus-{request.volumeId}"));
+
+                        
                     }
                 }
                 else if (request.scope.Equals("private"))
@@ -161,7 +204,9 @@ namespace TEAMModelOS.Controllers
                     school = request.school,
                     scope = request.scope,
                     coedit = request.coedit,
-                    share = request.share
+                    share = request.share,
+                    cagree = 0,
+                    sagree = 0
                 };
                 shares.Add(share);
             });
@@ -221,6 +266,101 @@ namespace TEAMModelOS.Controllers
             return (syllabus, shares);
         }
 
+        /// <summary>
+        /// {"code":"教师编码","id":"章节id","agree":1共编同意,2共编拒绝,3分享同意,4分享拒绝} 
+        /// 教师拉取自己收到的分享及共编
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("agree")]
+        // [AuthToken(Roles = "Teacher")]
+        public async Task<IActionResult> Agree(JsonElement request) {
+            try { 
+            if (!request.TryGetProperty("agree", out JsonElement agree)) { return BadRequest(); }
+            if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
+            if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
+            var client = _azureCosmos.GetCosmosClient();
+            Share share= await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{code}"));
+                if (agree.ValueKind.Equals(JsonValueKind.Number))
+                {
+                    int agreeNum = agree.GetInt32();
+                    if (agreeNum == 1)
+                    {
+                        share.cagree = 1;
+                    }
+                    else if (agreeNum == 2)
+                    {
+                        share.cagree = 2;
+                    }
+                    else if (agreeNum == 3)
+                    {
+                        share.sagree = 1;
+                    }
+                    else if (agreeNum == 4)
+                    {
+                        share.sagree = 2;
+                    }
+                    else
+                    {
+                        return Ok(new { status = 500 });
+                    }
+                    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{code}"));
+                    Syllabus syllabus = null;
+                    if (share.scope == "school")
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    }
+                    else if (share.scope == "private")
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    }
+                    if (syllabus.auth.IsNotEmpty())
+                    {
+                        syllabus.auth.ForEach(x =>
+                        {
+                            if (x.tmdid == $"{code}")
+                            {
+                                if (agreeNum == 1)
+                                {
+                                    x.cagree = 1;
+                                }
+                                else if (agreeNum == 2)
+                                {
+                                    x.cagree = 2;
+                                }
+                                else if (agreeNum == 3)
+                                {
+                                    x.sagree = 1;
+                                }
+                                else if (agreeNum == 4)
+                                {
+                                    x.sagree = 2;
+                                }
+                            }
+                        });
+                    }
+                    if (share.scope == "school")
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    }
+                    else if (share.scope == "private")
+                    {
+                        syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
+                    }
+                    return Ok(new { status = 200 });
+                }
+                else
+                {
+                    return Ok(new { status = 500 });
+                }
+            }  catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { status = 500 });
+            }
+
+        }
 
 
         /// <summary>
@@ -299,7 +439,7 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("view-share")]
-       // [AuthToken(Roles = "Teacher")]
+       [AuthToken(Roles = "teacher")]
         public async Task<IActionResult> View(ShareView request)
         {
             try