李昊 4 years ago
parent
commit
7fa5d8c5e5

+ 3 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminMiddleLableController.cs

@@ -2,6 +2,7 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using GxPress.Repository.Interface.Navigation;
 using GxPress.Request.Navigation;
+using GxPress.Result.MiddleLable;
 using GxPress.Service.Interface.Navigation;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
@@ -38,9 +39,9 @@ namespace GxPress.Api.AdminControllers
         /// <param name="id"></param>
         /// <returns></returns>
         [HttpGet("{id}")]
-        public async Task<Entity.Navigations.MiddleLable> GetAsync(int id)
+        public async Task<MiddleLableResult> GetAsync(int id)
         {
-            return await middleLableRepository.GetAsync(id);
+            return await middleLableService.GetMiddleLableResultAsync(id);
         }
         /// <summary>
         /// 添加导航中间件

+ 2 - 1
gx_api/GxPress/Model/GxPress.Mappings/MiddleLableMapping.cs

@@ -10,7 +10,8 @@ namespace GxPress.Mappings
         public MiddleLableMapping()
         {
             CreateMap<MiddleLable, MiddleLableResult>();
-             CreateMap<MiddleLableInRequest, MiddleLable>();
+            CreateMap<MiddleLableInRequest, MiddleLable>();
+            CreateMap<MiddleLableNexusUpRequest, MiddleLableNexus>();
         }
 
     }

+ 38 - 11
gx_api/GxPress/Model/GxPress.Request/Navigation/MiddleLableRequest.cs

@@ -1,3 +1,5 @@
+using System.Collections.Generic;
+
 namespace GxPress.Request.Navigation
 {
     /// <summary>
@@ -16,12 +18,7 @@ namespace GxPress.Request.Navigation
         /// <value></value>
 
         public string Name { get; set; }
-        /// <summary>
-        /// 标签ID
-        /// </summary>
-        /// <value></value>
-
-        public string LabelId { get; set; }
+       
         /// <summary>
         /// 排序
         /// </summary>
@@ -52,6 +49,12 @@ namespace GxPress.Request.Navigation
         /// <value></value>
 
         public int TypeId { get; set; }
+
+         /// <summary>
+        ///  标签
+        /// </summary>
+        /// <value></value>
+        public List<MiddleLableNexusUpRequest> MiddleLableNexusUpRequests { get; set; }
     }
     /// <summary>
     /// 修改
@@ -69,12 +72,7 @@ namespace GxPress.Request.Navigation
         /// <value></value>
 
         public string Name { get; set; }
-        /// <summary>
-        /// 标签ID
-        /// </summary>
-        /// <value></value>
 
-        public string LabelId { get; set; }
         /// <summary>
         /// 排序
         /// </summary>
@@ -105,5 +103,34 @@ namespace GxPress.Request.Navigation
         /// <value></value>
 
         public int TypeId { get; set; }
+        /// <summary>
+        ///  标签
+        /// </summary>
+        /// <value></value>
+        public List<MiddleLableNexusUpRequest> MiddleLableNexusUpRequests { get; set; }
+    }
+    /// <summary>
+    /// 修改
+    /// </summary>
+    public class MiddleLableNexusUpRequest
+    {
+        /// <summary>
+        /// 中间页面ID
+        /// </summary>
+        /// <value></value>
+
+        public int MiddleLableId { get; set; }
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+
+        public int LableId { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+
+        public int Sort { get; set; }
     }
 }

+ 99 - 0
gx_api/GxPress/Model/GxPress.Result/MiddleLable/MiddleLableResult.cs

@@ -0,0 +1,99 @@
+using System.Collections.Generic;
+
+namespace GxPress.Result.MiddleLable
+{
+    /// <summary>
+    /// 查询
+    /// </summary>
+    public class MiddleLableResult
+    {
+        /// <summary>
+        /// id
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 导航栏ID
+        /// </summary>
+        /// <value></value>
+
+        public string Name { get; set; }
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+
+        public string LabelId { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+
+        public int Sort { get; set; }
+        /// <summary>
+        /// 是否禁用 1 设置 2取消
+        /// </summary>
+        /// <value></value>
+
+        public int IsDisable { get; set; }
+        /// <summary>
+        /// 是否开启搜索
+        /// </summary>
+        /// <value></value>
+
+        public int IsSearch { get; set; }
+        /// <summary>
+        /// 是否开启轮播
+        /// </summary>
+        /// <value></value>
+
+        public int IsSlide { get; set; }
+        /// <summary>
+        /// 1 APP 2 首页频道  3首页精选
+        /// </summary>
+        /// <value></value>
+
+        public int TypeId { get; set; }
+
+        /// <summary>
+        /// 标签
+        /// </summary>
+        /// <value></value>
+        public List<MiddleLableNexusResult> MiddleLableNexusResults { get; set; }
+    }
+    /// <summary>
+    /// 
+    /// </summary>
+    public class MiddleLableNexusResult
+    {
+        /// <summary>
+        /// id
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 中间页面ID
+        /// </summary>
+        /// <value></value>
+
+        public int MiddleLableId { get; set; }
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+
+        public int LableId { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public string MiddleLableName { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+
+        public int Sort { get; set; }
+    }
+
+}

+ 10 - 17
gx_api/GxPress/Repository/GxPress.Repository.Implement/Navigation/MiddleLableNexusRepository.cs

@@ -7,6 +7,7 @@ using GxPress.Common.Tools;
 using GxPress.Repository.Interface.Navigation;
 using Microsoft.Extensions.Options;
 using System.Transactions;
+using GxPress.Request.Navigation;
 
 namespace GxPress.Repository.Implement.Navigation
 {
@@ -32,20 +33,16 @@ namespace GxPress.Repository.Implement.Navigation
         /// <param name="middleLableId"></param>
         /// <param name="ids"></param>
         /// <returns></returns>
-        public async Task<bool> InsertAsync(int middleLableId, List<int> ids)
+        public async Task<bool> InsertAsync(List<MiddleLableNexusUpRequest> middleLableNexusUpRequests)
         {
             try
             {
                 using (var transactionScope = new TransactionScope())
                 {
-                    foreach (var item in ids)
+                    foreach (var item in middleLableNexusUpRequests)
                     {
-                        var model = new Entity.Navigations.MiddleLableNexus()
-                        {
-                            LableId = item,
-                            MiddleLableId = middleLableId
-                        };
-                        await _repository.InsertAsync(model);
+
+                        await _repository.InsertAsync(_mapper.Map<Entity.Navigations.MiddleLableNexus>(item));
                     }
                     transactionScope.Complete();
                 }
@@ -62,13 +59,12 @@ namespace GxPress.Repository.Implement.Navigation
         /// </summary>
         /// <param name="middleLableId"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<int>> GetAllTaskAsync(int middleLableId)
+        public async Task<IEnumerable<Entity.Navigations.MiddleLableNexus>> GetAllTaskAsync(int middleLableId)
         {
             var query = Q.NewQuery();
-            query.Select(nameof(Entity.Navigations.MiddleLableNexus.LableId));
             query.Where(nameof(Entity.Navigations.MiddleLableNexus.MiddleLableId), middleLableId);
             query.OrderByDesc(nameof(Entity.Navigations.MiddleLableNexus.Sort));
-            return await _repository.GetAllAsync<int>(query);
+            return await _repository.GetAllAsync(query);
         }
 
         public async Task<bool> DeleteByMiddleLableIdAsync(int middleLableId)
@@ -76,16 +72,13 @@ namespace GxPress.Repository.Implement.Navigation
             return await _repository.DeleteAsync(Q.Where(nameof(Entity.Navigations.MiddleLableNexus.MiddleLableId), middleLableId)) > 0;
         }
 
-        public async Task<bool> UpdateAsync(int middleLableId, string lableId)
+        public async Task<bool> UpdateAsync(int middleLableId, List<MiddleLableNexusUpRequest> middleLableNexusUpRequests)
         {
             try
             {
                 await DeleteByMiddleLableIdAsync(middleLableId);
-                var stringId = StringUtils.StringCollectionToStringList(lableId);
-                var intIds = new List<int>();
-                foreach (var item in stringId)
-                    intIds.Add(int.Parse(item));
-                await InsertAsync(middleLableId, intIds);
+
+                await InsertAsync(middleLableNexusUpRequests);
             }
             catch
             {

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemLabel/SystemLabelRepository.cs

@@ -88,7 +88,7 @@ namespace GxPress.Repository.Implement.SystemLabel
         }
         public async Task<IEnumerable<Entity.SystemLabel.SystemLabel>> GetAllAsync(List<int> ids)
         {
-            return await _repository.GetAllAsync(Q.WhereIn(nameof(Entity.SystemLabel.SystemLabel.Id), ids).OrderByDesc(nameof(Entity.SystemLabel.SystemLabel.Sort)));
+            return await _repository.GetAllAsync(Q.WhereIn(nameof(Entity.SystemLabel.SystemLabel.Id), ids));
         }
 
     }

+ 4 - 3
gx_api/GxPress/Repository/GxPress.Repository.Interface/Navigation/IMiddleLableNexusRepository.cs

@@ -1,6 +1,7 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using Datory;
+using GxPress.Request.Navigation;
 
 namespace GxPress.Repository.Interface.Navigation
 {
@@ -12,17 +13,17 @@ namespace GxPress.Repository.Interface.Navigation
         /// <param name="middleLableId"></param>
         /// <param name="ids"></param>
         /// <returns></returns>
-        Task<bool> InsertAsync(int middleLableId, List<int> ids);
+        Task<bool> InsertAsync(List<MiddleLableNexusUpRequest> middleLableNexusUpRequests);
 
         /// <summary>
         /// 查询
         /// </summary>
         /// <param name="middleLableId"></param>
         /// <returns></returns>
-        Task<IEnumerable<int>> GetAllTaskAsync(int middleLableId);
+        Task<IEnumerable<Entity.Navigations.MiddleLableNexus>> GetAllTaskAsync(int middleLableId);
         Task<bool> DeleteByMiddleLableIdAsync(int middleLableId);
 
-        Task<bool> UpdateAsync(int middleLableId, string lableId);
+        Task<bool> UpdateAsync(int middleLableId, List<MiddleLableNexusUpRequest> middleLableNexusUpRequests);
 
     }
 }

+ 42 - 10
gx_api/GxPress/Service/GxPress.Service.Implement/Navigation/MiddleLableService.cs

@@ -7,7 +7,8 @@ using System.Linq;
 using System.Collections.Generic;
 using GxPress.Request.Navigation;
 using AutoMapper;
-
+using GxPress.Result.MiddleLable;
+using GxPress.Repository.Interface.SystemLabel;
 namespace GxPress.Service.Implement.Navigation
 {
     public class MiddleLableService : IMiddleLableService
@@ -15,11 +16,13 @@ namespace GxPress.Service.Implement.Navigation
         private readonly IMiddleLableRepository middleLableRepository;
         private readonly IMiddleLableNexusRepository middleLableNexusRepository;
         private readonly IMapper _mapper;
-        public MiddleLableService(IMiddleLableRepository middleLableRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMapper mapper)
+        private readonly ISystemLabelRepository systemLabelRepository;
+        public MiddleLableService(IMiddleLableRepository middleLableRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMapper mapper, ISystemLabelRepository systemLabelRepository)
         {
             this.middleLableRepository = middleLableRepository;
             this.middleLableNexusRepository = middleLableNexusRepository;
             _mapper = mapper;
+            this.systemLabelRepository = systemLabelRepository;
         }
         /// <summary>
         /// 添加中间件页面
@@ -34,11 +37,9 @@ namespace GxPress.Service.Implement.Navigation
                 {
                     var model = _mapper.Map<Entity.Navigations.MiddleLable>(request);
                     var middleLableId = await middleLableRepository.InsertAsync(model);
-                    var ids = StringUtils.StringCollectionToStringList(request.LabelId);
-                    var idInts = new List<int>();
-                    foreach (var item in ids)
-                        idInts.Add(int.Parse(item));
-                    await middleLableNexusRepository.InsertAsync(middleLableId, idInts);
+                    foreach (var item in request.MiddleLableNexusUpRequests)
+                        item.MiddleLableId = middleLableId;
+                    await middleLableNexusRepository.InsertAsync(request.MiddleLableNexusUpRequests);
                     transactionScope.Complete();
                 }
             }
@@ -73,14 +74,12 @@ namespace GxPress.Service.Implement.Navigation
 
         public async Task<bool> UpdateAsync(MiddleLableUpRequest request)
         {
-
             try
             {
                 using (var transactionScope = new System.Transactions.TransactionScope())
                 {
                     await middleLableRepository.UpdateAsync(request);
-                    if (!string.IsNullOrEmpty(request.LabelId))
-                        await middleLableNexusRepository.UpdateAsync(request.Id, request.LabelId);
+                    await middleLableNexusRepository.UpdateAsync(request.Id, request.MiddleLableNexusUpRequests);
                     transactionScope.Complete();
                 }
             }
@@ -90,5 +89,38 @@ namespace GxPress.Service.Implement.Navigation
             }
             return true;
         }
+        /// <summary>
+        /// 详情
+        /// </summary>
+        /// <param name="middleLableId"></param>
+        /// <returns></returns>
+        public async Task<MiddleLableResult> GetMiddleLableResultAsync(int middleLableId)
+        {
+            var middleLable = await middleLableRepository.GetAsync(middleLableId);
+            var middleLableResult = _mapper.Map<MiddleLableResult>(middleLable);
+            middleLableResult.MiddleLableNexusResults = new List<MiddleLableNexusResult>();
+            var middleLableNexusList = await middleLableNexusRepository.GetAllTaskAsync(middleLableId);
+            var systemLabels = await systemLabelRepository.GetAllAsync(middleLableNexusList.Select(n => n.LableId).ToList());
+            foreach (var item in systemLabels)
+            {
+                foreach (var middleLableNexus in middleLableNexusList)
+                {
+                    if (middleLableNexus.LableId == item.Id)
+                    {
+                        var middleLableNexusResult = new MiddleLableNexusResult()
+                        {
+                            Id = middleLableNexus.Id,
+                            LableId = item.Id,
+                            MiddleLableId = middleLableId,
+                            MiddleLableName = item.LabelName,
+                            Sort = middleLableNexus.Sort
+                        };
+                        middleLableResult.MiddleLableNexusResults.Add(middleLableNexusResult);
+                    }
+                }
+
+            }
+            return middleLableResult;
+        }
     }
 }

+ 2 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Navigation/NavigationService.cs

@@ -67,7 +67,7 @@ namespace GxPress.Service.Implement.Navigation
                     }
                 }
                 //获取标签
-                var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.ToList());
+                var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n=>n.LableId).ToList());
                 foreach (var item in systemLabels)
                 {
                     //获取常规数据
@@ -141,7 +141,7 @@ namespace GxPress.Service.Implement.Navigation
                 }
             }
             //获取标签
-            var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.ToList());
+            var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n=>n.LableId).ToList());
             foreach (var item in systemLabels)
             {
                 //获取常规数据

+ 7 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Navigation/IMiddleLableService.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using GxPress.Request.Navigation;
+using GxPress.Result.MiddleLable;
 
 namespace GxPress.Service.Interface.Navigation
 {
@@ -14,5 +15,11 @@ namespace GxPress.Service.Interface.Navigation
         Task<bool> DeleteAsync(int id);
 
         Task<bool> UpdateAsync(MiddleLableUpRequest request);
+          /// <summary>
+        /// 详情
+        /// </summary>
+        /// <param name="middleLableId"></param>
+        /// <returns></returns>
+        Task<MiddleLableResult> GetMiddleLableResultAsync(int middleLableId);
     }
 }