浏览代码

更新课纲数据结构

CrazyIter_Bin 4 年之前
父节点
当前提交
0a0e3a121f

+ 3 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/Snode.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Text;
+using System.Text.Json;
 
 namespace TEAMModelOS.SDK.Models.Cosmos.Common
 {
@@ -63,6 +64,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// <summary>
         /// 存放地址 外部链接是绝对地址有http   blob是相对地址
         /// </summary>
-        public List<string> link { get; set; }
+        public string link { get; set; }
+       
     }
 }

+ 5 - 6
TEAMModelOS.SDK/Models/Cosmos/Common/Syllabus.cs

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

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Paper.cs

@@ -62,6 +62,7 @@ namespace TEAMModelOS.SDK.Models
         public int multipleRule { get; set; }
         //记录试卷大小
         public long? size { get; set; } = 0;
+        
         /// <summary>
         /// type:{
         ///     pointkey:[num1,num2....]

+ 12 - 28
TEAMModelOS.SDK/Models/Cosmos/Teacher/Share.cs

@@ -45,14 +45,6 @@ namespace TEAMModelOS.SDK.Models
         [Required(ErrorMessage = "scope 必须设置")]
         public string scope { get; set; }
         /// <summary>
-        /// 共编
-        /// </summary>
-        public bool coedit { get; set; }
-        /// <summary>
-        /// 分享
-        /// </summary>
-        public bool share { get; set; }
-        /// <summary>
         /// 册别id
         /// </summary>
         public string volumeId { get; set; }
@@ -65,18 +57,11 @@ namespace TEAMModelOS.SDK.Models
         /// 册别名称
         /// </summary>
         public string volumeName { get; set; }
-        /// <summary>
-        /// 共编-是否同意
-        /// </summary>
-        public int cagree { get; set; } = 0;
-        /// <summary>
-        /// 分享-是否同意
-        /// </summary>
-        public int sagree { get; set; } =0;
+       
         /// <summary>
         /// 分享  type=coedit共编,share分享
         /// </summary>
-        public bool type { get; set; }
+        public string type { get; set; }
         /// <summary>
         /// 是否同意
         /// </summary>
@@ -105,15 +90,7 @@ namespace TEAMModelOS.SDK.Models
 
         [Required(ErrorMessage = "tmdid 必须设置")]
         public List<TmdInfo> tmdInfo { get; set; } = new List<TmdInfo>();
-        
-        /// <summary>
-        /// 共编权限
-        /// </summary>
-        public bool coedit { get; set; } = false;
-        /// <summary>
-        /// 分享权限
-        /// </summary>
-        public bool share { get; set; } = false;
+      
         /// <summary>
         /// 课纲章节的id
         /// </summary>
@@ -137,7 +114,14 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         [Required(ErrorMessage = "issuer 必须设置")]
         public string issuer { get; set; }
-    }
-
 
+        /// <summary>
+        /// 分享  type=coedit共编,share分享
+        /// </summary>
+        public string type { get; set; }
+        /// <summary>
+        /// 是否同意
+        /// </summary>
+        public int agree { get; set; } = 0;
+    }
 }

+ 50 - 161
TEAMModelOS/Controllers/Syllabus/ShareController.cs

@@ -103,42 +103,21 @@ namespace TEAMModelOS.Controllers
                         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
                             {
-                                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);
-                            }
-                           
+                                hubName = "hita",
+                                type = "msg",
+                                from = $"ies5:{request.school}",
+                                to = new List<string>() { x.code.Replace("Share-","") },
+                                label = $"{x.type}_syllabus",
+                                body = new { biz = x.type, 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}"));
 
@@ -196,17 +175,15 @@ namespace TEAMModelOS.Controllers
                     volumeId = request.volumeId,
                     volumeName = request.volumeName,
                     syllabusName = request.syllabusName,
-                    code = $"Share-{xmd.tmdid}",
+                    code = $"Share-{request.type}-{xmd.tmdid}",
                     pk = "Share",
                     ttl = -1,
                     issuer = request.issuer,
                     createTime = now,
                     school = request.school,
                     scope = request.scope,
-                    coedit = request.coedit,
-                    share = request.share,
-                    cagree = 0,
-                    sagree = 0
+                    type =request.type,
+                    agree = request.agree
                 };
                 shares.Add(share);
             });
@@ -219,7 +196,7 @@ namespace TEAMModelOS.Controllers
                     int indx = 0;
                     for (int index = 0; index < syllabus.auth.Count; index++)
                     {
-                        if (syllabus.auth[index].tmdid == xmd.tmdid)
+                        if (syllabus.auth[index].tmdid == xmd.tmdid && request.type== syllabus.auth[index].type)
                         {
                             flag = true;
                             indx = index;
@@ -233,8 +210,8 @@ namespace TEAMModelOS.Controllers
                         {
                             tmdid = xmd.tmdid,
                             tmdname = xmd.tmdname,
-                            coedit = request.coedit,
-                            share = request.share,
+                            type = request.type,
+                            agree = request.agree,
                         };
                     }
                     //新增
@@ -244,8 +221,8 @@ namespace TEAMModelOS.Controllers
                         {
                             tmdid = xmd.tmdid,
                             tmdname = xmd.tmdname,
-                            coedit = request.coedit,
-                            share = request.share,
+                            type = request.type,
+                            agree = request.agree,
                         });
                     }
                 });
@@ -257,8 +234,8 @@ namespace TEAMModelOS.Controllers
                         new SyllabusAuth {
                             tmdid = xmd.tmdid,
                             tmdname = xmd.tmdname,
-                            coedit=request.coedit,
-                            share=request.share,
+                            type = request.type,
+                            agree = request.agree,
                         }
                     };
                 });
@@ -266,20 +243,23 @@ namespace TEAMModelOS.Controllers
             return (syllabus, shares);
         }
         /// <summary>
-        /// {"code":"教师编码","id":"章节id"} 
-        /// 教师删除自己收到的
+        /// {"code":"教师编码","id":"章节id","type":"coedit/share","opt":"ignore/agree"} 
+        /// 
+        /// 教师操作收到的分享及课纲共编, ignore 忽略,需要删除Share 数据 并更新syllabus.auth
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [HttpPost("del-share")]
+        [HttpPost("agree-share")]
         // [AuthToken(Roles = "Teacher")]
-        public async Task<IActionResult> DelShare(JsonElement request) {
+        public async Task<IActionResult> AgreeShare(JsonElement request) {
             try {
+                if (!request.TryGetProperty("type", out JsonElement type)) { return BadRequest(); }
                 if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
                 if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
+                if (!request.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
                 var client = _azureCosmos.GetCosmosClient();
-                Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{code}"));
+                Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                 Syllabus syllabus = null;
                 if (share.scope == "school")
                 {
@@ -293,9 +273,16 @@ namespace TEAMModelOS.Controllers
                 {
                     syllabus.auth.ForEach(x =>
                     {
-                        if (x.tmdid == $"{code}")
+                        if (x.tmdid == $"{code}" && x.type==$"{type}")
                         {
-                            x.sagree = 0;
+                            if ($"{opt}".Equals("ignore"))
+                            {
+                                x.agree = 0;
+                            }
+                            else if ($"{opt}".Equals("ignore")) {
+                                x.agree = 1;
+                            }
+                          
                         }
                     });
                 }
@@ -307,109 +294,22 @@ namespace TEAMModelOS.Controllers
                 {
                     syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
                 }
-                return Ok(new { status = 200 });
-            } catch (Exception ex) {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/del-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
-                return Ok(new { status = 500 });
-            }
-        }
-        /// <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))
+                if ($"{opt}".Equals("ignore"))
                 {
-                    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 });
+                    share.agree = 1;
+                    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share,$"{id}", new PartitionKey($"Share-{type}-{code}"));
                 }
-                else
+                else if ($"{opt}".Equals("ignore"))
                 {
-                    return Ok(new { status = 500 });
+                    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                 }
-            }  catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { status = 200 });
+            } catch (Exception ex) {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return Ok(new { status = 500 });
             }
-
         }
 
-
         /// <summary>
         /// {"code":"教师编码","type":"coedit/share"} 
         /// 教师拉取自己收到的分享及共编
@@ -429,18 +329,7 @@ namespace TEAMModelOS.Controllers
                 request.TryGetProperty("id", out JsonElement id);
                 var client = _azureCosmos.GetCosmosClient();
                 StringBuilder queryText = new StringBuilder("select value(c) from c");
-                if (type.ValueKind.Equals(JsonValueKind.String) && type.GetString() == "coedit")
-                {
-                    queryText.Append(" where c.coedit=true");
-                }
-                else if (type.ValueKind.Equals(JsonValueKind.String) && type.GetString() == "share")
-                {
-                    queryText.Append(" where c.share=true");
-                }
-                else {
-                    await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/find()\n type== coedit|share 参数必选一个", GroupNames.醍摩豆服務運維群組);
-                    return BadRequest();
-                }
+                queryText.Append($" where c.type='{type}' ");
                 if (id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrEmpty(id.GetString())) {
                     queryText.Append($" and c.id='{id}'");
                 }