Ver Fonte

课纲阶段

CrazyIter_Bin há 4 anos atrás
pai
commit
1b652bc303

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

@@ -36,8 +36,9 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         [Required(ErrorMessage = "{0} 必须填写")]
 
         public int order { get; set; }
-        public List<string> points { get; set; } = new List<string> { "" };
+        //public List<string> points { get; set; } = new List<string> { "" };
         public List<Rnode> rnodes { get; set; } = new List<Rnode>();
+        public List<string> cids { get; set; } = new List<string>();
         //public string code { get; set; }
 
     }

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

@@ -19,6 +19,7 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         [Required(ErrorMessage = "{0} 必须填写")]
         public List<Tnode> children { get; set; }
+      
 
     }
 }

+ 19 - 2
TEAMModelOS.SDK/Models/Cosmos/Common/Volume.cs

@@ -67,7 +67,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// <summary>
         /// 共编使用者 的醍摩豆id
         /// </summary>
-        public List<string> editors { get; set; }
+       // public List<string> editors { get; set; }
 
         //public int resourceCount { get; set; }
         //public int itemCount { get; set; }
@@ -80,11 +80,28 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// </summary>
         [Required(ErrorMessage = "school 必须设置")]
         public string school { get; set; }
-        public bool repeat { get; set; }
+       // public bool repeat { get; set; }
         /// <summary>
         /// school|private
         /// </summary>
         [Required(ErrorMessage = "scope 必须设置")]
         public string scope { get; set; }
+        public List<SyllabusAuth> auth { get; set; } = new List<SyllabusAuth>();
+    }
+
+    /// <summary>
+    /// 只要创建课纲的creatorId 才能编辑课纲的分享,共编权限 25600 74200  27500 2000
+    /// ,共编者 谁创建的节点只能谁删除,而且删除时能删除子节点(包含不是自己创建的)。
+    /// </summary>
+    public class SyllabusAuth
+    {
+        public string tmdid { get; set; }
+        public string name { get; set; }
+        public bool coedit { get; set; }
+        public bool share { get; set; }
+        /// <summary>
+        ///分享的节点 all  或者節點id
+        /// </summary>
+        public List<string> snodes { get; set; } = new List<string>();
     }
 }

+ 105 - 14
TEAMModelOS.SDK/Models/Cosmos/Teacher/Favorite.cs

@@ -1,9 +1,10 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Text;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 
-namespace TEAMModelOS.SDK.Models.Cosmos.Teacher
+namespace TEAMModelOS.SDK.Models.Cosmos
 {
     /// <summary>
     /// 课纲-我喜欢的,我的收藏
@@ -15,7 +16,7 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Teacher
             ttl = -1;
             //code ="Favorite-tmdid"
         }
-        public List<Tnode> nodes { get; set; }
+        public SyllabusTree node { get; set; }
         /// <summary>
         /// 名称 默认选中节点名称,或者自定义输入名称
         /// </summary>
@@ -27,32 +28,122 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Teacher
         /// <summary>
         /// 引用来源课纲id
         /// </summary>
+        [Required(ErrorMessage = "引用来源课纲id 必须设置")]
         public string fromId { get; set; }
         /// <summary>
         /// 引用来源 课纲Code 分区键
         /// </summary>
+        [Required(ErrorMessage = "引用来源课纲code 必须设置")]
         public string fromCode { get; set; }
     }
-    public class FavoriteTree{
-        public string id { get; set; }
-        public string code { get; set; }
-        public string pk { get; set; } = "Favorite";
+
+    /*
+     {
+        "id":"课纲册别id",
+        "code":"Share-接收者tmdid",
+        "issuer":"分享者tmdid",
+        "createTime":分享时间,
+        "scode":"引用来源课纲册别code",
+        "scope":"school/private",
+        "school":"hbcn",
+        "issuer":"颁发权限的id"
+    }
+     */
+    /// <summary>
+    /// 主动分享给谁, 分享功能只会发生在个人课纲中
+    /// </summary>
+    public class Share : CosmosEntity {
+        public Share(){
+            pk = "Share";
+        }
+
+        public string scode { get; set; }
         /// <summary>
-        /// 名称 默认选中节点名称,或者自定义输入名称
+        /// 权限颁发者
+        /// </summary>
+        public string issuer { get; set; }
+        public long  createTime { get; set; }
+        /// <summary>
+        /// 学校编码或教师tmdid
+        /// </summary>
+        [Required(ErrorMessage = "school 必须设置")]
+        public string school { get; set; }
+        /// <summary>
+        /// school|private
+        /// </summary>
+        [Required(ErrorMessage = "scope 必须设置")]
+        public string scope { get; set; }
+        /// <summary>
+        /// 共编
+        /// </summary>
+        public bool coedit { get; set; }
+        /// <summary>
+        /// 分享
+        /// </summary>
+        public bool share { get; set; }
+        /// <summary>
+        /// 课纲名称
+        /// </summary>
+        public string sname { get; set; }
+    }
+         
+    /// <summary>
+    /// 主动分享给谁,当接收者接收并完成相关资源复制后则删除本条数据。
+    /// </summary>
+    public class ShareData
+    {
+        /// <summary>
+        /// 学校编码或教师tmdid
+        /// </summary>
+        [Required(ErrorMessage = "school 必须设置")]
+        public string school { get; set; }
+        /// <summary>
+        /// school|private
+        /// </summary>
+        [Required(ErrorMessage = "scope 必须设置")]
+        public string scope { get; set; }
+        /// <summary>
+        /// add/edit/del
+        /// </summary>
+        [Required(ErrorMessage = "opt 必须设置")]
+        public string opt { get; set; }
+        [Required(ErrorMessage = "tmdid 必须设置")]
+        public string tmdid { get; set; }
+        /// <summary>
+        /// tmdname
         /// </summary>
         public string name { get; set; }
         /// <summary>
-        /// 创建时间
+        /// 课纲的id
         /// </summary>
-        public long createTime { get; set; }
+        [Required(ErrorMessage = "sid 必须设置")]
+        public string sid { get; set; }
         /// <summary>
-        /// 引用来源课纲id
+        /// 课纲的分区键
         /// </summary>
-        public string fromId { get; set; }
+        [Required(ErrorMessage = "socde 必须设置")]
+        public string scode { get; set; }
         /// <summary>
-        /// 引用来源 课纲Code 分区键
+        /// 课纲的名称
         /// </summary>
-        public string fromCode { get; set; }
-        public List<SyllabusTree> nodes { get; set; }
+        [Required(ErrorMessage = "sname 必须设置")]
+        public string sname { get; set; }
+        /// <summary>
+        /// 共编权限
+        /// </summary>
+        public bool coedit { get; set; } = false;
+        /// <summary>
+        /// 分享权限
+        /// </summary>
+        public bool share { get; set; } = false;
+        /// <summary>
+        /// 分享的节点 all  或者節點id
+        /// </summary>
+        public List<string> snodes { get; set; } = new List<string>();
+        /// <summary>
+        /// 共编 分享权限颁发者
+        /// </summary>
+        [Required(ErrorMessage = "issuer 必须设置")]
+        public string issuer { get; set; }
     }
 }

+ 11 - 0
TEAMModelOS/Controllers/Common/SocialController.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.Controllers.Common
+{
+    public class SocialController
+    {
+    }
+}

+ 15 - 0
TEAMModelOS/Controllers/Syllabus/CoeditController.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.Controllers
+{
+    public class CoeditController
+    {
+        public CoeditController()
+        {
+
+        }
+    }
+}

+ 63 - 7
TEAMModelOS/Controllers/Syllabus/FavoriteController.cs

@@ -7,11 +7,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text.Json;
 using System.Threading.Tasks;
+using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
-using TEAMModelOS.SDK.Models.Cosmos.Teacher;
 using TEAMModelOS.Services.Common;
 
 namespace TEAMModelOS.Controllers
@@ -33,7 +34,7 @@ namespace TEAMModelOS.Controllers
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
             _dingDing = dingDing;
-            _option = option?.Value; ;
+            _option = option?.Value; 
         }
         /// <summary>
         /// 保存或更新 
@@ -42,16 +43,17 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("upsert")]
-        public async Task<IActionResult> Upsert(FavoriteTree request)
+        [AuthToken(Roles = "Teacher")]
+        public async Task<IActionResult> Upsert(Favorite request)
         {
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
                 request.pk = "Favorite";
                 request.code = request.pk + "-" + request.code;
-                //request.ttl = -1;
-                List<Tnode> nodes = new List<Tnode>();
-                SyllabusService.TreeToList(request.nodes, nodes);
+                request.ttl = -1;
+                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                request.createTime = now;
                 if (string.IsNullOrEmpty(request.id))
                 {
 
@@ -76,7 +78,61 @@ namespace TEAMModelOS.Controllers
             }
             catch (Exception e)
             {
-                await _dingDing.SendBotMsg($"OS,{_option.Location},common/teacher/favorite\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/favorite/upsert\n{e.Message}{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+        /// <summary>
+        /// {"code":"教师编码"} 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "Teacher")]
+        [HttpPost("find")]
+        public async Task<IActionResult> Find(JsonElement request)
+        {
+            try
+            {
+                List<Favorite> favorites = new List<Favorite>();
+                if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
+                var client = _azureCosmos.GetCosmosClient();
+              
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Favorite>(queryText: $"select value(c) from c ",
+                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Favorite-{code}") }))
+                {
+                    favorites.Add(item);
+                }
+                return Ok(new { favorites = favorites });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/favorite/find()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+        /// <summary>
+        /// {"id":"我的最爱id","code":"教师编码"} 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("delete")]
+        public async Task<IActionResult> Delete(JsonElement requert)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                //id
+                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                //
+                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                var room = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Favorite>(id.GetString(), new PartitionKey($"Favorite-{code}"));
+                return Ok();
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/favorite/delete()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
             }
         }

+ 316 - 0
TEAMModelOS/Controllers/Syllabus/ShareController.cs

@@ -0,0 +1,316 @@
+using Azure.Cosmos;
+using HTEXLib.COMM.Helpers;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Filter;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.Services.Common;
+
+namespace TEAMModelOS.Controllers
+{
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    //[Authorize(Roles = "IES5")]
+    [Route("teacher/share")]
+    [ApiController]
+    public class ShareController: ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly SnowflakeId _snowflakeId;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+
+        public ShareController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
+        {
+            _azureCosmos = azureCosmos;
+            _snowflakeId = snowflakeId;
+            _dingDing = dingDing;
+            _option = option?.Value;
+        }
+        /// <summary>
+        /// 分享及邀请共编,并设置TTL过期时间
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("to")]
+        [AuthToken(Roles = "Teacher")]
+        public async Task<IActionResult> To(ShareData request) {
+            // var (id, _, _, _) = HttpContext.GetAuthTokenInfo();
+
+            try {
+                var client = _azureCosmos.GetCosmosClient();
+                //需要判断id== req.issuer  才能进行授权操作
+                if (request.scope.Equals("school"))
+                {
+                    Volume volume = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Volume>(request.sid, new PartitionKey(request.scode));
+                    if (request.opt == "del")
+                    {
+                        if (volume.auth.IsNotEmpty())
+                        {
+                            var del = volume.auth.Where(x => x.tmdid == request.tmdid).FirstOrDefault();
+                            volume.auth.Remove(del);
+                            await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Volume>(volume, request.sid, new PartitionKey(request.scode));
+                            await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>(request.sid, new PartitionKey($"Share-{request.tmdid}"));
+                        }
+                    }
+                    else if (request.opt.Equals("add") || request.opt.Equals("edit"))
+                    {
+                        (Volume vlm, Share share) = DoAuth(request, volume);
+                        await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Share>(share, new PartitionKey($"Share-{request.tmdid}"));
+                        await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<Volume>(volume, new PartitionKey(request.scode));
+                    }
+                }
+                else if (request.scope.Equals("private"))
+                {
+                    Volume volume = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Volume>(request.sid, new PartitionKey(request.scode));
+                    if (request.opt == "del")
+                    {
+                        if (volume.auth.IsNotEmpty())
+                        {
+                            var del = volume.auth.Where(x => x.tmdid == request.tmdid).FirstOrDefault();
+                            volume.auth.Remove(del);
+                            await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Volume>(volume, request.sid, new PartitionKey(request.scode));
+                            await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>(request.sid, new PartitionKey($"Share-{request.tmdid}"));
+                        }
+                    }
+                    else if (request.opt.Equals("add") || request.opt.Equals("edit"))
+                    {
+                        (Volume vlm, Share share) = DoAuth(request, volume);
+                        await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Share>(share, new PartitionKey($"Share-{request.tmdid}"));
+                        await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Volume>(volume, new PartitionKey(request.scode));
+                    }
+                }
+                return Ok(new { code=200});
+            }
+            catch (Exception ex ) {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+            return Ok(new { code = 500 });
+        }
+
+        private (Volume,Share) DoAuth(ShareData request,Volume volume) {
+            long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            var share = new Share
+            {
+                id = request.sid,
+                code = $"Share-{request.tmdid}",
+                pk = "Share",
+                ttl = -1,
+                scode = request.scode,
+                issuer = request.issuer,
+                createTime = now,
+                school = request.school,
+                scope = request.scope,
+                coedit=request.coedit,
+                share=request.share,
+                sname=request.sname
+            };
+            if (volume.auth.IsNotEmpty())
+            {
+                bool flag = false;
+                int indx = 0;
+                for (int index = 0; index < volume.auth.Count; index++)
+                {
+                    if (volume.auth[index].tmdid == request.tmdid)
+                    {
+                        flag = true;
+                        indx = index;
+                        break;
+                    }
+                }
+                ///更新位置上的授权信息
+                if (flag)
+                {
+                    volume.auth[indx] = new SyllabusAuth
+                    {
+                        tmdid = request.tmdid,
+                        name = request.name,
+                        coedit = request.coedit,
+                        share = request.share,
+                        snodes = request.snodes
+                    };
+                }
+                //新增
+                else
+                {
+                    volume.auth.Add(new SyllabusAuth
+                    {
+                        tmdid = request.tmdid,
+                        name = request.name,
+                        coedit = request.coedit,
+                        share = request.share,
+                        snodes = request.snodes
+                    });
+                }
+            }
+            else
+            {
+                volume.auth = new List<SyllabusAuth>() {
+                    new SyllabusAuth {
+                        tmdid=request.tmdid,
+                        name=request.name,
+                        coedit=request.coedit,
+                        share=request.share,
+                        snodes=request.snodes
+                    }
+                };
+            }
+            return (volume, share);
+        }
+        /// <summary>
+        /// {"code":"教师编码"} 
+        /// 教师拉取自己收到的分享及共编
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("find")]
+        [AuthToken(Roles = "Teacher")]
+        public async Task<IActionResult> Find(JsonElement request)
+        {
+            try
+            {
+                List<Share> shares = new List<Share>();
+                if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
+                var client = _azureCosmos.GetCosmosClient();
+
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Share>(queryText: $"select value(c) from c ",
+                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Share-{code}") }))
+                {
+                    shares.Add(item);
+                }
+                return Ok(new { shares = shares });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/favorite/find()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+
+        }
+        /// <summary>
+        /// 查看分享
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("view")]
+       // [AuthToken(Roles = "Teacher")]
+        public async Task<IActionResult> View(Share request)
+        {
+            try
+            {
+                //var (id, _, _, school) = HttpContext.GetAuthTokenInfo();
+                //if (!request.code.Equals($"Share-{id}"))
+                //{
+                //    return BadRequest();
+                //}
+                Syllabus syllabus;
+                Volume volume;
+                var client = _azureCosmos.GetCosmosClient();
+                string code = null;
+                if (request.scope == "school")
+                {
+                    code = request.school;
+                    syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>(request.id, new PartitionKey(request.scode));
+                    volume = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Volume>(request.id, new PartitionKey($"Volume-{code}"));
+                }
+                else if (request.scope == "private")
+                {
+                    code = request.issuer;
+                    syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>(request.id, new PartitionKey(request.scode));
+                    volume = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Volume>(request.id, new PartitionKey($"Volume-{code}"));
+                }
+                else
+                {
+                    return BadRequest();
+                }
+                bool coedit = false;
+                bool share = false;
+                SyllabusTreeNode  etree = null;
+                List<string> snodes = null;
+                if (volume.auth.IsNotEmpty()) {
+                    foreach (var x in volume.auth) {
+                        if ($"Share-{x.tmdid }" == request.code)
+                        {
+                            coedit = x.coedit;
+                            share = x.share;
+                            snodes = x.snodes;
+                            break;
+                        }
+                    }
+                }
+                if (coedit)
+                {
+                    var treechd = SyllabusService.ListToTree(syllabus.children);
+                    etree = new SyllabusTreeNode() {
+                        id = syllabus.id,
+                        code = syllabus.code,
+                        trees = treechd
+                    };
+                }
+                SyllabusTreeNode stree = new SyllabusTreeNode();
+                if (share && snodes.IsNotEmpty()) {
+                    stree = new SyllabusTreeNode()
+                    {
+                        id = syllabus.id,
+                        code = syllabus.code
+                    };
+                    snodes.ForEach(x => {
+                        SyllabusTree syllabusTree = null;
+                        foreach (var node in syllabus.children) {
+                            if (node.id == x) {
+                                syllabusTree = new SyllabusTree { 
+                                    id=node.id,
+                                    pid=node.pid,
+                                    order=node.order,
+                                    rnodes=node.rnodes,
+                                    cids=node.cids
+                                };
+                                break;
+                            }
+                        }
+                        HashSet<Tnode> newNodes = new HashSet<Tnode>();
+                        SyllabusService.GetNewNode(syllabus.children, x, newNodes);
+                        var trees = SyllabusService.ListToTree(newNodes.ToList());
+                        if (syllabusTree != null) {
+                            syllabusTree.children.AddRange(trees);
+                            stree.trees.Add(syllabusTree);
+                        }
+                    });
+                }
+                return Ok(new { coedit, share, etree,stree });
+            }
+            catch (Exception ex) {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/view()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+
+        }
+        /// <summary>
+        ///二维码扫码方式
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("qrcode")]
+        [AuthToken(Roles = "Teacher")]
+        public async Task<IActionResult> Qrcode(Favorite request)
+        {
+            return Ok();
+
+        }
+    }
+}

+ 40 - 8
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -12,7 +12,9 @@ using System.Threading.Tasks;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.Controllers
@@ -36,7 +38,13 @@ namespace TEAMModelOS.Controllers
             _dingDing = dingDing;
             _option = option?.Value; ;
         }
-
+        /*
+        {
+            "id": "册别id",
+            "code": "学校编码/教师编码",
+            "scope": "school/private"
+        }
+         */
         /// <summary>
         /// 删除册别
         /// </summary>
@@ -69,7 +77,9 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
         }
-
+        /*
+         
+         */
         /// <summary>
         /// 查找册别
         /// </summary>
@@ -155,12 +165,12 @@ namespace TEAMModelOS.Controllers
         [HttpPost("upsert")]
         public async Task<IActionResult> Upsert(Volume request) {
 
-            var client = _azureCosmos.GetCosmosClient();
-            if (request.editors != null && request.editors.Count > 5)
-            {
-                return BadRequest("共编人数大于5人!");
-                // throw new BizException("共编人数大于5人!");
-            }
+            //var client = _azureCosmos.GetCosmosClient();
+            //if (request.editors != null && request.editors.Count > 5)
+            //{
+            //    return BadRequest("共编人数大于5人!");
+            //    // throw new BizException("共编人数大于5人!");
+            //}
             request.pk = "Volume";
             request.ttl = -1;
             request.code = "Volume-" + request.code;
@@ -181,6 +191,9 @@ namespace TEAMModelOS.Controllers
             if (!string.IsNullOrEmpty(request.id))
             {
                 try {
+                    Volume volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Volume>(request.id, new PartitionKey(request.code));
+                    //保留授权
+                    request.auth = volume.auth;
                     await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Volume>(request,request.id, new Azure.Cosmos.PartitionKey(request.code));
                 }
                 catch (Exception  ex) {
@@ -237,6 +250,25 @@ namespace TEAMModelOS.Controllers
                     await _dingDing.SendBotMsg($"OS,{_option.Location},VolumeController:Upsert\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
                 }
             }
+            ///处理更新 分享及共编的数据
+            //if (request.auth.IsNotEmpty()) {
+            //    long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            //    foreach (var au in request.auth) {
+            //      var share=  new Share
+            //        {
+            //            id = request.id,
+            //            code = $"Share-{au.tmdid}",
+            //            pk = "Share",
+            //            ttl = -1,
+            //            scode=request.code,
+            //            issuer=request.creatorId,
+            //            createTime= now,
+            //            school=request.school,
+            //            scope=request.scope
+            //        };
+            //        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(share, new PartitionKey($"{share.code}"));
+            //    }
+            //}
             return Ok(request);
         }
     }

+ 1 - 1
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -237,7 +237,7 @@ namespace TEAMModelOS.Controllers
 
             //取得班级
             List<object> school_classes = new List<object>();
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"SELECT c.id,c.x,c.y,c.name,c.teacher,c.periodId,c.gradeId,c.sn,c.no,c.style,c.status,c.openType,c.scope, ARRAY_LENGTH(c.students) AS studCount FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
+            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"SELECT c.id,c.x,c.y,c.name,c.teacher,c.periodId,c.gradeId,c.room,c.sn,c.no,c.style,c.status,c.openType,c.scope, ARRAY_LENGTH(c.students) AS studCount FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_code}") }))
             {
                 var jsonc = await JsonDocument.ParseAsync(item.ContentStream);
                 foreach (var classeinfo in jsonc.RootElement.GetProperty("Documents").EnumerateArray())

+ 50 - 1
TEAMModelOS/Services/Common/SyllabusService.cs

@@ -1,3 +1,4 @@
+using HTEXLib.COMM.Helpers;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -10,6 +11,35 @@ namespace TEAMModelOS.Services.Common
 {
     public static class SyllabusService
     {
+        /// <summary>
+        /// 根据id查询列表串联id pid的新的关系列表
+        /// </summary>
+        /// <param name="nodes"></param>
+        /// <param name="pid"></param>
+        /// <param name="newNodes"></param>
+        /// <returns></returns>
+        public static HashSet<Tnode> GetNewNode(List<Tnode> nodes, string pid, HashSet<Tnode> newNodes) {
+            bool flag = false;
+            string spid = "";
+            foreach (var node in nodes) {
+                if (node.pid == pid) {
+                    newNodes.Add(node);
+                    spid = node.id;
+                    GetNewNode(nodes, spid, newNodes);
+                    flag = true;
+                }
+            }
+            return newNodes;
+            //if (flag)
+            //{
+            //    return GetNewNode(nodes, spid, newNodes);
+            //}
+            //else {
+            //    return newNodes;
+            //}
+        }
+
+
         public static List<Tnode> TreeToList(List<SyllabusTree> trees, List<Tnode> nodes)
         {
             int index = 0;
@@ -19,7 +49,26 @@ namespace TEAMModelOS.Services.Common
                 index++;
             }
             trees = trees.OrderBy(x => x.order).ToList();
-            nodes.AddRange(trees.ToJsonString().ToObject<List<Tnode>>());
+            List<Tnode> list = new List<Tnode>();
+            //var list = trees.ToJsonString().ToObject<List<Tnode>>();
+            trees.ForEach(x=> {
+                List<string> cids = new List<string>();
+                if (x.children.IsNotEmpty()) {
+                    x.children.ForEach(y => cids.Add(y.id));
+                }
+                var node = new Tnode
+                {
+                    type = x.type,
+                    title = x.title,
+                    id = x.id,
+                    pid = x.pid,
+                    order = x.order,
+                    rnodes = x.rnodes,
+                    cids= cids
+                };
+                list.Add(node);
+            });
+            nodes.AddRange(list);
 
             foreach (SyllabusTree tree in trees)
             {