黄贺彬 hace 6 años
padre
commit
479cb4dd8e

+ 44 - 0
TEAMModelOS.Model/Syllabus/Dtos/BlockPointDto.cs

@@ -0,0 +1,44 @@
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.Model.Syllabus.Dtos
+{
+    [MessagePackObject(keyAsPropertyName: true)]
+    public class BlockPointDto
+    {
+        public string PartitionKey { get; set; }
+        public string RowKey { get; set; }
+        /// <summary>
+        /// 名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 描述
+        /// </summary>
+       // public string Description { get; set; }
+        /// <summary>
+        /// 上级ID
+        /// </summary>
+        public string Pid { get; set; } = "root";
+        /// <summary>
+        /// 学科
+        /// </summary>
+        public string SubjectCode { get; set; }
+        /// <summary>
+        /// 建议学段
+        /// </summary>
+        public string AdvicePeriodCode { get; set; }
+        public int Order { get; set; }
+        [IgnoreMember]
+        public List<PointDto> Points { get; set; }
+        [IgnoreMember]
+        public List<BlockPointDto> Children { get; set; }
+
+        public BlockPointDto()
+        {
+            Children = new List<BlockPointDto>();
+        }
+    }
+}

+ 3 - 1
TEAMModelOS.Model/Syllabus/Dtos/KnowledgeDto.cs

@@ -1,9 +1,11 @@
-using System;
+using MessagePack;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 
 
 namespace TEAMModelOS.Model.Syllabus.Dtos
 namespace TEAMModelOS.Model.Syllabus.Dtos
 {
 {
+    [MessagePackObject(keyAsPropertyName: true)]
     public class KnowledgeDto
     public class KnowledgeDto
     {
     {
         public List<string> Periods { get; set; }
         public List<string> Periods { get; set; }

+ 27 - 0
TEAMModelOS.Model/Syllabus/Dtos/PointDto.cs

@@ -0,0 +1,27 @@
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.Model.Syllabus.Dtos
+{
+    [MessagePackObject(keyAsPropertyName: true)]
+    public class PointDto
+    {   //public string Id { get; set; }
+        public string PointId { get; set; }
+        /// <summary>
+        /// 原始名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 建议学段
+        /// </summary>
+        public string AdvicePeriodCode { get; set; }
+        public int Order { get; set; }
+        /// <summary>
+        /// 学科
+        /// </summary>
+        public string SubjectCode { get; set; }
+        public string BlockId { get; set; }
+    }
+}

+ 1 - 1
TEAMModelOS.Model/Syllabus/Models/KnowledgeBlock.cs

@@ -18,7 +18,7 @@ namespace TEAMModelOS.Model.Syllabus.Models
         /// <summary>
         /// <summary>
         /// 描述
         /// 描述
         /// </summary>
         /// </summary>
-        public string Description { get; set; }
+       // public string Description { get; set; }
         /// <summary>
         /// <summary>
         /// 上级ID
         /// 上级ID
         /// </summary>
         /// </summary>

+ 1 - 1
TEAMModelOS.Model/Syllabus/Models/KnowledgePoint.cs

@@ -14,7 +14,7 @@ namespace TEAMModelOS.Model.Syllabus.Models
     [MessagePackObject(keyAsPropertyName: true)]
     [MessagePackObject(keyAsPropertyName: true)]
     public class KnowledgePoint : TableEntity
     public class KnowledgePoint : TableEntity
     {
     {
-       // public string Id { get; set; }
+        // public string Id { get; set; }
         //public string Key { get; set; }
         //public string Key { get; set; }
         /// <summary>
         /// <summary>
         /// 名称
         /// 名称

+ 2 - 1
TEAMModelOS.Service/Core/Implements/LoginInfoService.cs

@@ -67,6 +67,7 @@ namespace TEAMModelOS.Service.Core.Implements
                 }
                 }
 
 
                 ///不验证TmdID
                 ///不验证TmdID
+                #region
                 result.CheckTicket = true;
                 result.CheckTicket = true;
                 LoginInfo loginInfo = new LoginInfo
                 LoginInfo loginInfo = new LoginInfo
                 {
                 {
@@ -98,7 +99,7 @@ namespace TEAMModelOS.Service.Core.Implements
                 await Save<LoginInfo>(loginInfo);
                 await Save<LoginInfo>(loginInfo);
                 await SaveOrUpdate<TeamModelUser>(user);
                 await SaveOrUpdate<TeamModelUser>(user);
                 return result;
                 return result;
-
+                #endregion
                 /*
                 /*
                 JosnRPCRequest<Dictionary<string, object>> request = new JosnRPCRequest<Dictionary<string, object>>
                 JosnRPCRequest<Dictionary<string, object>> request = new JosnRPCRequest<Dictionary<string, object>>
                 {
                 {

+ 51 - 7
TEAMModelOS.Service/Syllabus/Implements/KnowledgeService.cs

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
 using TEAMModelOS.Model.Syllabus.Dtos;
 using TEAMModelOS.Model.Syllabus.Dtos;
 using TEAMModelOS.Model.Syllabus.Models;
 using TEAMModelOS.Model.Syllabus.Models;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
 using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
 using TEAMModelOS.Service.Core.Implements;
 using TEAMModelOS.Service.Core.Implements;
 using TEAMModelOS.Service.Syllabus.Interfaces;
 using TEAMModelOS.Service.Syllabus.Interfaces;
 
 
@@ -27,14 +28,14 @@ namespace TEAMModelOS.Service.Syllabus.Implements
             return points.OrderBy(x => x.Order).ToList(); 
             return points.OrderBy(x => x.Order).ToList(); 
         }
         }
 
 
-        public async Task<List<KnowledgePoint>> FindKnowledgeBlockAndPointByDict(KnowledgeDto knowledgePoint) {
+        public async Task<List<BlockPointDto>> FindKnowledgeBlockAndPointByDict(KnowledgeDto knowledgePoint) {
             List<KnowledgeBlock> blocks = await FindListByDict<KnowledgeBlock>(knowledgePoint.PointParams);
             List<KnowledgeBlock> blocks = await FindListByDict<KnowledgeBlock>(knowledgePoint.PointParams);
             List<KnowledgeBlockPoint> blockPoints = await FindListByDict<KnowledgeBlockPoint>(knowledgePoint.PointParams);
             List<KnowledgeBlockPoint> blockPoints = await FindListByDict<KnowledgeBlockPoint>(knowledgePoint.PointParams);
-            HashSet<KnowledgeBlock> knowledges = new HashSet<KnowledgeBlock>();
-            HashSet<KnowledgeBlockPoint> knowledgeBlocks = new HashSet<KnowledgeBlockPoint>();
+            
             if (knowledgePoint.Periods.IsNotEmpty())
             if (knowledgePoint.Periods.IsNotEmpty())
             {
             {
-               
+                HashSet<KnowledgeBlock> knowledges = new HashSet<KnowledgeBlock>();
+                HashSet<KnowledgeBlockPoint> knowledgeBlocks = new HashSet<KnowledgeBlockPoint>();
                 foreach (string period in knowledgePoint.Periods)
                 foreach (string period in knowledgePoint.Periods)
                 {
                 {
                     if (!string.IsNullOrEmpty(period))
                     if (!string.IsNullOrEmpty(period))
@@ -43,10 +44,53 @@ namespace TEAMModelOS.Service.Syllabus.Implements
                         knowledgeBlocks.UnionWith(blockPoints.Where(x => x.AdvicePeriodCode.Contains(period)).ToHashSet());
                         knowledgeBlocks.UnionWith(blockPoints.Where(x => x.AdvicePeriodCode.Contains(period)).ToHashSet());
                     }
                     }
                 }
                 }
-                //knowledges.OrderBy(x => x.Order).ToList();
-               // knowledgeBlocks.OrderBy(x => x.Order).ToList();
+                blocks= knowledges.OrderBy(x => x.Order).ToList();
+                blockPoints= knowledgeBlocks.OrderBy(x => x.Order).ToList();
+
+
+            }
+            
+            return ListToTree(blocks, blockPoints);
+        }
+
+        private List<BlockPointDto> ListToTree(List<KnowledgeBlock> blocks ,List<KnowledgeBlockPoint>  points)
+        {
+            List<PointDto> pointList = MessagePackHelper.JsonToObject<List<PointDto>>(MessagePackHelper.ObjectToJson(points));
+            List<BlockPointDto> blockList = MessagePackHelper.JsonToObject<List<BlockPointDto>>(MessagePackHelper.ObjectToJson(blocks));
+            Dictionary<string, List<PointDto>> pointDict = new Dictionary<string, List<PointDto>>();
+            List<string> keys = (pointList.GroupBy(c => c.BlockId).Select(group => group.Key)).ToList();
+            foreach (string key in keys) {
+                pointDict.Add(key, pointList.Where(x => x.BlockId.Equals(key)).ToList());
+            }
+            var blockDict = blockList.ToDictionary(n => n.RowKey, n => n);
+            return GetChild(blockList, blockDict , pointDict);
+        }
+        public List<BlockPointDto> GetChild(List<BlockPointDto> list, Dictionary<string, BlockPointDto> blockDict, Dictionary<string, List<PointDto>> pointDict)
+        {
+            List<PointDto> empt = new List<PointDto>();
+            list = list.OrderBy(m => m.Order).ToList();
+            List<BlockPointDto> trees = new List<BlockPointDto>();
+            foreach (BlockPointDto node in list)
+            {
+                bool fl= pointDict.TryGetValue(node.RowKey,out List<PointDto> points);
+                if (fl && points.IsNotEmpty())
+                {
+                    node.Points = points;
+                }
+                else {
+                    node.Points = empt;
+                }
+                bool flag = blockDict.TryGetValue(node.Pid, out BlockPointDto syllabus);
+                if (flag && syllabus != null)
+                {
+                    syllabus.Children.Add(node);
+                }
+                else
+                {
+                    trees.Add(node);
+                }
             }
             }
-            return null; 
+            return trees.OrderBy(x=>x.Order).ToList();
         }
         }
     }
     }
 }
 }

+ 1 - 1
TEAMModelOS.Service/Syllabus/Implements/SyllabusService.cs

@@ -64,7 +64,7 @@ namespace TEAMModelOS.Service.Syllabus.Implements
 
 
         public List<SyllabusTree> GetChild(List<SyllabusTree> list, Dictionary<string, SyllabusTree> dict)
         public List<SyllabusTree> GetChild(List<SyllabusTree> list, Dictionary<string, SyllabusTree> dict)
         {
         {
-            list = list.OrderByDescending(m => m.Order).ToList();
+            list = list.OrderBy(m => m.Order).ToList();
             List<SyllabusTree> trees = new List<SyllabusTree>();
             List<SyllabusTree> trees = new List<SyllabusTree>();
             foreach (SyllabusTree node in list)
             foreach (SyllabusTree node in list)
             {
             {

+ 1 - 1
TEAMModelOS.Service/Syllabus/Interfaces/IKnowledgeService.cs

@@ -11,6 +11,6 @@ namespace TEAMModelOS.Service.Syllabus.Interfaces
     public interface IKnowledgeService : IBusinessService, IBaseService
     public interface IKnowledgeService : IBusinessService, IBaseService
     {
     {
         Task<List<KnowledgePoint>> FindKnowledgePointByDict(KnowledgeDto knowledgePoint);
         Task<List<KnowledgePoint>> FindKnowledgePointByDict(KnowledgeDto knowledgePoint);
-        Task<List<KnowledgePoint>> FindKnowledgeBlockAndPointByDict(KnowledgeDto knowledgePoint);
+        Task<List<BlockPointDto>> FindKnowledgeBlockAndPointByDict(KnowledgeDto knowledgePoint);
     }
     }
 }
 }

+ 1 - 1
TEAMModelOS/Controllers/Syllabus/KnowledgeController.cs

@@ -51,7 +51,7 @@ namespace TEAMModelOS.Controllers.Syllabus
         {
         {
             request.@params.PointParams.TryAdd("PartitionKey", request.lang);
             request.@params.PointParams.TryAdd("PartitionKey", request.lang);
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
             JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-            List<KnowledgePoint> data = new List<KnowledgePoint>();
+            List<BlockPointDto> data = new List<BlockPointDto>();
             if (request.@params != null && request.@params.PointParams.TryGetValue("SubjectCode", out _))
             if (request.@params != null && request.@params.PointParams.TryGetValue("SubjectCode", out _))
             {
             {
                 data = await knowledgeService.FindKnowledgeBlockAndPointByDict(request.@params);
                 data = await knowledgeService.FindKnowledgeBlockAndPointByDict(request.@params);