CrazyIter_Bin 3 anni fa
parent
commit
317f3ca360

+ 25 - 10
TEAMModelOS.SDK/Models/Cosmos/Teacher/Share.cs

@@ -58,7 +58,7 @@ namespace TEAMModelOS.SDK.Models
         /// 册别名称
         /// 册别名称
         /// </summary>
         /// </summary>
         public string volumeName { get; set; }
         public string volumeName { get; set; }
-       
+
         /// <summary>
         /// <summary>
         /// 分享  type=coedit共编,share分享
         /// 分享  type=coedit共编,share分享
         /// </summary>
         /// </summary>
@@ -67,6 +67,10 @@ namespace TEAMModelOS.SDK.Models
         /// 是否同意
         /// 是否同意
         /// </summary>
         /// </summary>
         public int agree { get; set; } = 0;
         public int agree { get; set; } = 0;
+        /// <summary>
+        /// 是否标记整册分享
+        /// </summary>
+        public int volumeAll { get; set; } = 0;
     }
     }
     /// <summary>
     /// <summary>
     /// 主动分享给谁,当接收者接收并完成相关资源复制后则删除本条数据。
     /// 主动分享给谁,当接收者接收并完成相关资源复制后则删除本条数据。
@@ -91,17 +95,11 @@ namespace TEAMModelOS.SDK.Models
 
 
         [Required(ErrorMessage = "tmdid 必须设置")]
         [Required(ErrorMessage = "tmdid 必须设置")]
         public List<ShareTmd> tmdInfo { get; set; } = new List<ShareTmd>();
         public List<ShareTmd> tmdInfo { get; set; } = new List<ShareTmd>();
-      
-        /// <summary>
-        /// 课纲章节的id
-        /// </summary>
-        [Required(ErrorMessage = "syllabusId 必须设置")]
-        public string syllabusId { get; set; }
+
         /// <summary>
         /// <summary>
-        /// 课纲章节的name
+        /// 是否标记整册分享
         /// </summary>
         /// </summary>
-        [Required(ErrorMessage = "syllabusName 必须设置")]
-        public string syllabusName { get; set; }
+        public int volumeAll { get; set; } = 0;
         /// <summary>
         /// <summary>
         /// 册别名称
         /// 册别名称
         /// </summary>
         /// </summary>
@@ -110,6 +108,8 @@ namespace TEAMModelOS.SDK.Models
         /// 册别id
         /// 册别id
         /// </summary>
         /// </summary>
         public string volumeId { get; set; }
         public string volumeId { get; set; }
+
+        public List<ShareSyllabus> syllabus { get; set; } = new List<ShareSyllabus>();
         /// <summary>
         /// <summary>
         /// 共编 分享权限颁发者
         /// 共编 分享权限颁发者
         /// </summary>
         /// </summary>
@@ -129,6 +129,7 @@ namespace TEAMModelOS.SDK.Models
         /// 是否同意
         /// 是否同意
         /// </summary>
         /// </summary>
         public int agree { get; set; } = 0;
         public int agree { get; set; } = 0;
+
     }
     }
     public class ShareTmd
     public class ShareTmd
     {
     {
@@ -136,4 +137,18 @@ namespace TEAMModelOS.SDK.Models
         public string tmdname { get; set; }
         public string tmdname { get; set; }
         public string picture { get; set; }
         public string picture { get; set; }
     }
     }
+    public class ShareSyllabus
+    {
+
+        /// <summary>
+        /// 课纲章节的id
+        /// </summary>
+        [Required(ErrorMessage = "syllabusId 必须设置")]
+        public string syllabusId { get; set; }
+        /// <summary>
+        /// 课纲章节的name
+        /// </summary>
+        [Required(ErrorMessage = "syllabusName 必须设置")]
+        public string syllabusName { get; set; }
+    }
 }
 }

+ 206 - 167
TEAMModelOS/Controllers/Syllabus/ShareController.cs

@@ -69,159 +69,185 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [HttpPost("to")]
         [HttpPost("to")]
         [AuthToken(Roles = "teacher,admin")]
         [AuthToken(Roles = "teacher,admin")]
-        public async Task<IActionResult> To(ShareData request) {
+        public async Task<IActionResult> To(ShareData request)
+        {
             // var (id, _, _, _) = HttpContext.GetAuthTokenInfo();
             // var (id, _, _, _) = HttpContext.GetAuthTokenInfo();
 
 
-            try {
+            try
+            {
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
-                Syllabus syllabusD = null;
+
                 //需要判断id== req.issuer  才能进行授权操作
                 //需要判断id== req.issuer  才能进行授权操作
                 if (request.scope.Equals("school"))
                 if (request.scope.Equals("school"))
                 {
                 {
-                    try {
-                          syllabusD = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Syllabus>(request.syllabusId, new PartitionKey($"Syllabus-{request.school}"));
-                    } catch (CosmosException ex) {
-                        if (ex.Status == 404) {
-                            await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.成都开发測試群組);
-                            return Ok(new { code = 404 });
-                        }
-                    }
-                    if (request.opt .Equals("del"))
+                    if (request.syllabus.IsNotEmpty())
                     {
                     {
-                        if (syllabusD.auth.IsNotEmpty())
+                        foreach (var quest in request.syllabus)
                         {
                         {
-                            List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
-                            syllabusD.auth.ForEach(x => {
-                                if (request.tmdInfo.Select(tmd => tmd.tmdid).Contains(x.tmdid)) {
-                                    syllabusAuths.Add(x);
+                            Syllabus syllabusD = null;
+                            try
+                            {
+                                syllabusD = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Syllabus>(quest.syllabusId, new PartitionKey($"Syllabus-{request.school}"));
+                            }
+                            catch (CosmosException ex)
+                            {
+                                if (ex.Status == 404)
+                                {
+                                    await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.成都开发測試群組);
+                                    return Ok(new { code = 404 });
                                 }
                                 }
-                            });
-                            syllabusAuths.ForEach(x => {
-                                syllabusD.auth.Remove(x);
-                            });
-                            await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<Syllabus>(syllabusD, request.syllabusId, new PartitionKey($"Syllabus-{request.school}"));
-                            request.tmdInfo.ForEach(async x => {
-                                await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Share>(request.syllabusId, new PartitionKey($"Share-{request.type}-{x.tmdid}"));
-                            });
-
-                        }
-                    }
-                    else if (request.opt.Equals("add") || request.opt.Equals("edit"))
-                    {
-                        var schresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(request.school.ToString(), new PartitionKey("Base"));
-                        string schname = string.Empty;
-                        if (schresponse.Status == 200)
-                        {
-                            using var schjson = await JsonDocument.ParseAsync(schresponse.ContentStream);
-                            schjson.RootElement.TryGetProperty("name", out JsonElement jsonschname);
-                            schname = jsonschname.ToString();
-                        }
-                        else
-                        {
-                            return BadRequest();
-                        }
-                        (Syllabus syllabus, List<Share> shares) = DoAuth(request, syllabusD);
-                        foreach (var x in shares)
-                        {
-                            await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
-                            //发送共编或分享通知
-                            string to = x.code.Replace("Share-", "").Replace($"{x.type}-", "");
-                            //如果被邀请人与邀请人相同 则不发通知。
-                            if (to.Equals(x.issuer))
+                            }
+                            if (request.opt.Equals("del"))
                             {
                             {
-                                continue;
+                                if (syllabusD.auth.IsNotEmpty())
+                                {
+                                    List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
+                                    syllabusD.auth.ForEach(x => {
+                                        if (request.tmdInfo.Select(tmd => tmd.tmdid).Contains(x.tmdid))
+                                        {
+                                            syllabusAuths.Add(x);
+                                        }
+                                    });
+                                    syllabusAuths.ForEach(x => {
+                                        syllabusD.auth.Remove(x);
+                                    });
+                                    await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<Syllabus>(syllabusD, quest.syllabusId, new PartitionKey($"Syllabus-{request.school}"));
+                                    request.tmdInfo.ForEach(async x => {
+                                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Share>(quest.syllabusId, new PartitionKey($"Share-{request.type}-{x.tmdid}"));
+                                    });
+
+                                }
                             }
                             }
-                            Notification notification = new Notification
+                            else if (request.opt.Equals("add") || request.opt.Equals("edit"))
                             {
                             {
-                                hubName = "hita",
-                                type = "msg",
-                                from = $"ies5:{_option.Location}:{request.school}",
-                                to = new List<string>() { x.code.Replace("Share-", "").Replace($"{x.type}-", "") },
-                                label = $"{x.type}_syllabus",
-                                body = new { location = _option.Location, biz = x.type, tmdid = x.issuer, tmdname=x.issuerName, schoolcode = $"{request.school}", schoolname = $"{schname}", 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);
+                                var schresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(request.school.ToString(), new PartitionKey("Base"));
+                                string schname = string.Empty;
+                                if (schresponse.Status == 200)
+                                {
+                                    using var schjson = await JsonDocument.ParseAsync(schresponse.ContentStream);
+                                    schjson.RootElement.TryGetProperty("name", out JsonElement jsonschname);
+                                    schname = jsonschname.ToString();
+                                }
+                                else
+                                {
+                                    return BadRequest();
+                                }
+                                (Syllabus syllabus, List<Share> shares) = DoAuth(request, syllabusD);
+                                foreach (var x in shares)
+                                {
+                                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
+                                    //发送共编或分享通知
+                                    string to = x.code.Replace("Share-", "").Replace($"{x.type}-", "");
+                                    //如果被邀请人与邀请人相同 则不发通知。
+                                    if (to.Equals(x.issuer))
+                                    {
+                                        continue;
+                                    }
+                                    Notification notification = new Notification
+                                    {
+                                        hubName = "hita",
+                                        type = "msg",
+                                        from = $"ies5:{_option.Location}:{request.school}",
+                                        to = new List<string>() { x.code.Replace("Share-", "").Replace($"{x.type}-", "") },
+                                        label = $"{x.type}_syllabus",
+                                        body = new { location = _option.Location, biz = x.type, tmdid = x.issuer, tmdname = x.issuerName, schoolcode = $"{request.school}", schoolname = $"{schname}", 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(Constant.TEAMModelOS, "School").UpsertItemAsync<Syllabus>(syllabus, new PartitionKey($"Syllabus-{request.school}"));
+                            }
                         }
                         }
-                        await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<Syllabus>(syllabus, new PartitionKey($"Syllabus-{request.school}"));
                     }
                     }
                 }
                 }
                 else if (request.scope.Equals("private"))
                 else if (request.scope.Equals("private"))
                 {
                 {
-                    try { 
-                      syllabusD = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Syllabus>(request.syllabusId, new PartitionKey($"Syllabus-{request.issuer}"));
-                    }
-                    catch (CosmosException ex)
+                    if (request.syllabus.IsNotEmpty())
                     {
                     {
-                        if (ex.Status == 404)
+                        foreach (var quest in request.syllabus)
                         {
                         {
-                            await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.成都开发測試群組);
-                            return Ok(new { code = 404 });
-                        }
-                    }
-                    if (request.opt .Equals("del"))
-                    {
-                        if (syllabusD.auth.IsNotEmpty())
-                        {
-                            List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
-                            syllabusD.auth.ForEach(x => {
-                                if (request.tmdInfo.Select(tmd => x.tmdid).Contains(x.tmdid))
+                            Syllabus syllabusD = null;
+                            try
+                            {
+                                syllabusD = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Syllabus>(quest.syllabusId, new PartitionKey($"Syllabus-{request.issuer}"));
+                            }
+                            catch (CosmosException ex)
+                            {
+                                if (ex.Status == 404)
                                 {
                                 {
-                                    syllabusAuths.Add(x);
+                                    await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.成都开发測試群組);
+                                    return Ok(new { code = 404 });
                                 }
                                 }
-                            });
-                            syllabusAuths.ForEach(x => {
-                                syllabusD.auth.Remove(x);
-                            });
-                            await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Syllabus>(syllabusD, request.syllabusId, new PartitionKey($"Syllabus-{request.issuer}"));
-                            request.tmdInfo.ForEach(async x => {
-                                try {
-                                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Share>(request.syllabusId, new PartitionKey($"Share-{request.type}-{x.tmdid}"));
-                                } catch 
+                            }
+                            if (request.opt.Equals("del"))
+                            {
+                                if (syllabusD.auth.IsNotEmpty())
                                 {
                                 {
-                                    //仅处理找不到数据的情况
+                                    List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
+                                    syllabusD.auth.ForEach(x => {
+                                        if (request.tmdInfo.Select(tmd => x.tmdid).Contains(x.tmdid))
+                                        {
+                                            syllabusAuths.Add(x);
+                                        }
+                                    });
+                                    syllabusAuths.ForEach(x => {
+                                        syllabusD.auth.Remove(x);
+                                    });
+                                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Syllabus>(syllabusD, quest.syllabusId, new PartitionKey($"Syllabus-{request.issuer}"));
+                                    request.tmdInfo.ForEach(async x => {
+                                        try
+                                        {
+                                            await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Share>(quest.syllabusId, new PartitionKey($"Share-{request.type}-{x.tmdid}"));
+                                        }
+                                        catch
+                                        {
+                                            //仅处理找不到数据的情况
+                                        }
+                                    });
                                 }
                                 }
-                            });
-                        }
-                    }
-                    else if (request.opt.Equals("add") || request.opt.Equals("edit"))
-                    {
-                        (Syllabus vlm, List<Share> shares) = DoAuth(request, syllabusD);
-                        foreach (var x in shares) {
-                            await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
-                            //发送共编或分享通知
-                            string to = x.code.Replace("Share-", "").Replace($"{x.type}-", "");
-                            //如果被邀请人与邀请人相同 则不发通知。
-                            if (to.Equals(x.issuer)) 
-                            { 
-                                continue;
                             }
                             }
-                            Notification notification = new Notification
+                            else if (request.opt.Equals("add") || request.opt.Equals("edit"))
                             {
                             {
-                                hubName = "hita",
-                                type = "msg",
-                                from = $"ies5:{_option.Location}:private",
-                                to = new List<string>() { x.code.Replace("Share-", "") .Replace($"{x.type}-", "") },
-                                label = $"{x.type}_syllabus",
-                                body = new { location = _option.Location, biz = x.type, tmdid = x.issuer, tmdname = x.issuerName, 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);
+                                (Syllabus vlm, List<Share> shares) = DoAuth(request, syllabusD);
+                                foreach (var x in shares)
+                                {
+                                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
+                                    //发送共编或分享通知
+                                    string to = x.code.Replace("Share-", "").Replace($"{x.type}-", "");
+                                    //如果被邀请人与邀请人相同 则不发通知。
+                                    if (to.Equals(x.issuer))
+                                    {
+                                        continue;
+                                    }
+                                    Notification notification = new Notification
+                                    {
+                                        hubName = "hita",
+                                        type = "msg",
+                                        from = $"ies5:{_option.Location}:private",
+                                        to = new List<string>() { x.code.Replace("Share-", "").Replace($"{x.type}-", "") },
+                                        label = $"{x.type}_syllabus",
+                                        body = new { location = _option.Location, biz = x.type, tmdid = x.issuer, tmdname = x.issuerName, 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(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Syllabus>(syllabusD, new PartitionKey($"Syllabus-{request.issuer}"));
+                            }
                         }
                         }
-                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<Syllabus>(syllabusD, new PartitionKey($"Syllabus-{request.issuer}"));
                     }
                     }
                 }
                 }
                 return Ok(new { code = 200 });
                 return Ok(new { code = 200 });
             }
             }
-            catch (Exception ex) {
+            catch (Exception ex)
+            {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
             }
             return Ok(new { code = 500 });
             return Ok(new { code = 500 });
@@ -232,24 +258,27 @@ namespace TEAMModelOS.Controllers
             long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             List<Share> shares = new List<Share>();
             List<Share> shares = new List<Share>();
             request.tmdInfo.ForEach(xmd => {
             request.tmdInfo.ForEach(xmd => {
-                var share = new Share
-                {
-                    id = request.syllabusId,
-                    volumeId = request.volumeId,
-                    volumeName = request.volumeName,
-                    syllabusName = request.syllabusName,
-                    code = $"Share-{request.type}-{xmd.tmdid}",
-                    pk = "Share",
-                    ttl = -1,
-                    issuer = request.issuer,
-                    issuerName=request.issuerName,
-                    createTime = now,
-                    school = request.school,
-                    scope = request.scope,
-                    type = request.type,
-                    agree = request.agree
-                };
-                shares.Add(share);
+                request.syllabus.ForEach(sbs => {
+                    var share = new Share
+                    {
+                        id = sbs.syllabusId,
+                        volumeId = request.volumeId,
+                        volumeName = request.volumeName,
+                        syllabusName = sbs.syllabusName,
+                        code = $"Share-{request.type}-{xmd.tmdid}",
+                        pk = "Share",
+                        ttl = -1,
+                        issuer = request.issuer,
+                        issuerName = request.issuerName,
+                        createTime = now,
+                        school = request.school,
+                        scope = request.scope,
+                        type = request.type,
+                        agree = request.agree,
+                        volumeAll = request.volumeAll,
+                    };
+                    shares.Add(share);
+                });
             });
             });
 
 
             if (syllabus.auth.IsNotEmpty())
             if (syllabus.auth.IsNotEmpty())
@@ -316,16 +345,20 @@ namespace TEAMModelOS.Controllers
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [HttpPost("agree-share")]
         [HttpPost("agree-share")]
         // [AuthToken(Roles = "Teacher")]
         // [AuthToken(Roles = "Teacher")]
-        public async Task<IActionResult> AgreeShare(JsonElement request) {
-            try {
+        public async Task<IActionResult> AgreeShare(JsonElement request)
+        {
+            try
+            {
                 if (!request.TryGetProperty("type", out JsonElement type)) { return BadRequest(); }
                 if (!request.TryGetProperty("type", out JsonElement type)) { return BadRequest(); }
                 if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
                 if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
                 if (!request.TryGetProperty("ids", out JsonElement ids)) { return BadRequest(); }
                 if (!request.TryGetProperty("ids", out JsonElement ids)) { return BadRequest(); }
                 if (!request.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
                 if (!request.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
-                if (ids.ValueKind.Equals(JsonValueKind.Array)) {
+                if (ids.ValueKind.Equals(JsonValueKind.Array))
+                {
                     List<string> idss = ids.ToObject<List<string>>();
                     List<string> idss = ids.ToObject<List<string>>();
-                    foreach (var id in idss) {
+                    foreach (var id in idss)
+                    {
                         Share share = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                         Share share = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                         if ($"{opt}".Equals("agree"))
                         if ($"{opt}".Equals("agree"))
                         {
                         {
@@ -338,7 +371,7 @@ namespace TEAMModelOS.Controllers
                         }
                         }
 
 
                         Syllabus syllabus = null;
                         Syllabus syllabus = null;
-                        if (share.scope .Equals("school"))
+                        if (share.scope.Equals("school"))
                         {
                         {
                             try
                             try
                             {
                             {
@@ -349,7 +382,7 @@ namespace TEAMModelOS.Controllers
                                 //仅处理差不到数据的情况
                                 //仅处理差不到数据的情况
                             }
                             }
                         }
                         }
-                        else if (share.scope .Equals("private"))
+                        else if (share.scope.Equals("private"))
                         {
                         {
                             try
                             try
                             {
                             {
@@ -379,11 +412,11 @@ namespace TEAMModelOS.Controllers
                                     }
                                     }
                                 });
                                 });
                             }
                             }
-                            if (share.scope .Equals("school"))
+                            if (share.scope.Equals("school"))
                             {
                             {
                                 syllabus = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.school}"));
                                 syllabus = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.school}"));
                             }
                             }
-                            else if (share.scope .Equals("private"))
+                            else if (share.scope.Equals("private"))
                             {
                             {
                                 syllabus = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.issuer}"));
                                 syllabus = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.issuer}"));
                             }
                             }
@@ -391,7 +424,9 @@ namespace TEAMModelOS.Controllers
                     }
                     }
                 }
                 }
                 return Ok(new { status = 200 });
                 return Ok(new { status = 200 });
-            } catch (Exception ex) {
+            }
+            catch (Exception ex)
+            {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return Ok(new { status = 500 });
                 return Ok(new { status = 500 });
             }
             }
@@ -404,7 +439,8 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [HttpPost("del-share")]
         [HttpPost("del-share")]
-        public async Task<IActionResult> DelShare(JsonElement request) {
+        public async Task<IActionResult> DelShare(JsonElement request)
+        {
             try
             try
             {
             {
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
@@ -413,7 +449,8 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
                 if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
                 return Ok(new { status = 200 });
                 return Ok(new { status = 200 });
-            } catch (Exception ex)
+            }
+            catch (Exception ex)
             {
             {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/del-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/del-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return Ok(new { status = 500 });
                 return Ok(new { status = 500 });
@@ -427,7 +464,7 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [HttpPost("find")]
         [HttpPost("find")]
-       // [AuthToken(Roles = "Teacher")]
+        // [AuthToken(Roles = "Teacher")]
         public async Task<IActionResult> Find(JsonElement request)
         public async Task<IActionResult> Find(JsonElement request)
         {
         {
             try
             try
@@ -439,7 +476,8 @@ namespace TEAMModelOS.Controllers
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
                 StringBuilder queryText = new StringBuilder("select value(c) from c");
                 StringBuilder queryText = new StringBuilder("select value(c) from c");
                 queryText.Append($" where c.type='{type}' ");
                 queryText.Append($" where c.type='{type}' ");
-                if (id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrEmpty(id.GetString())) {
+                if (id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrEmpty(id.GetString()))
+                {
                     queryText.Append($" and c.id='{id}'");
                     queryText.Append($" and c.id='{id}'");
                 }
                 }
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Share>(queryText: queryText.ToString(),
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Share>(queryText: queryText.ToString(),
@@ -447,13 +485,13 @@ namespace TEAMModelOS.Controllers
                 {
                 {
                     shares.Add(item);
                     shares.Add(item);
                 }
                 }
-                var sharesGp  =  shares.GroupBy(x => new {id= x.volumeId ,code=x.scope=="school"?x.school:x.issuer, issuerName=x.issuerName }).Select(y=>new { id=y.Key.id,code=y.Key.code, issuerName=y.Key.issuerName, list=y.ToList()});
-                return Ok(new { shares = sharesGp ,status=200});
+                var sharesGp = shares.GroupBy(x => new { id = x.volumeId, code = x.scope == "school" ? x.school : x.issuer, issuerName = x.issuerName }).Select(y => new { id = y.Key.id, code = y.Key.code, issuerName = y.Key.issuerName, list = y.ToList() });
+                return Ok(new { shares = sharesGp, status = 200 });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/find()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/find()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
-                return Ok(new {  status = 404 });
+                return Ok(new { status = 404 });
             }
             }
 
 
         }
         }
@@ -461,7 +499,7 @@ namespace TEAMModelOS.Controllers
         public record ShareView
         public record ShareView
         {
         {
             public string scope { get; set; }
             public string scope { get; set; }
-           // public string code { get; set; }
+            // public string code { get; set; }
             public string school { get; set; }
             public string school { get; set; }
             public string issuer { get; set; }
             public string issuer { get; set; }
             public string volumeId { get; set; }
             public string volumeId { get; set; }
@@ -484,7 +522,7 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [HttpPost("view-share")]
         [HttpPost("view-share")]
-       [AuthToken(Roles = "teacher")]
+        [AuthToken(Roles = "teacher")]
         public async Task<IActionResult> View(ShareView request)
         public async Task<IActionResult> View(ShareView request)
         {
         {
             try
             try
@@ -495,8 +533,8 @@ namespace TEAMModelOS.Controllers
                 string code = null;
                 string code = null;
                 List<string> sid = new List<string>();
                 List<string> sid = new List<string>();
                 request.syllabusId.ForEach(x => { sid.Add($"'{x}'"); });
                 request.syllabusId.ForEach(x => { sid.Add($"'{x}'"); });
-                var sidSql= string.Join(",", sid);
-                if (request.scope .Equals("school"))
+                var sidSql = string.Join(",", sid);
+                if (request.scope.Equals("school"))
                 {
                 {
                     code = request.school;
                     code = request.school;
                     var queryslt = $"SELECT  value(c) FROM c where c.id in ({sidSql})";
                     var queryslt = $"SELECT  value(c) FROM c where c.id in ({sidSql})";
@@ -508,9 +546,9 @@ namespace TEAMModelOS.Controllers
 
 
                     }
                     }
                     volume = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Volume>(request.volumeId, new PartitionKey($"Volume-{code}"));
                     volume = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Volume>(request.volumeId, new PartitionKey($"Volume-{code}"));
-                    
+
                 }
                 }
-                else if (request.scope .Equals("private"))
+                else if (request.scope.Equals("private"))
                 {
                 {
                     code = request.issuer;
                     code = request.issuer;
                     var queryslt = $"SELECT  value(c) FROM c where c.id in ({sidSql})";
                     var queryslt = $"SELECT  value(c) FROM c where c.id in ({sidSql})";
@@ -526,10 +564,11 @@ namespace TEAMModelOS.Controllers
                 {
                 {
                     return BadRequest();
                     return BadRequest();
                 }
                 }
-                
-                return Ok(new { volume,tree= treeNodes });
+
+                return Ok(new { volume, tree = treeNodes });
             }
             }
-            catch (Exception ex) {
+            catch (Exception ex)
+            {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/view()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/view()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
                 return BadRequest();
             }
             }
@@ -548,5 +587,5 @@ namespace TEAMModelOS.Controllers
             return Ok();
             return Ok();
         }
         }
     }
     }
-   
+
 }
 }