李昊 4 år sedan
förälder
incheckning
58f82ae451

+ 9 - 8
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.Service.Interface.Navigation;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 
@@ -16,11 +17,11 @@ namespace GxPress.Api.AdminControllers
     public class AdminMiddleLableController : ControllerBase
     {
         private readonly IMiddleLableRepository middleLableRepository;
-
-        public AdminMiddleLableController(IMiddleLableRepository middleLableRepository)
+        private readonly IMiddleLableService middleLableService;
+        public AdminMiddleLableController(IMiddleLableRepository middleLableRepository, IMiddleLableService middleLableService)
         {
             this.middleLableRepository = middleLableRepository;
-
+            this.middleLableService = middleLableService;
         }
         /// <summary>
         /// 列表
@@ -44,12 +45,12 @@ namespace GxPress.Api.AdminControllers
         /// <summary>
         /// 添加导航中间件
         /// </summary>
-        /// /// <param name="note"></param>
+        /// /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<int> Insert(Entity.Navigations.MiddleLable note)
+        public async Task<bool> Insert(MiddleLableInRequest request)
         {
-            return await middleLableRepository.InsertAsync(note);
+            return await middleLableService.InsertAsync(request);
         }
         /// <summary>
         /// 删除中间件页面
@@ -59,7 +60,7 @@ namespace GxPress.Api.AdminControllers
         [HttpDelete("{id}")]
         public async Task<bool> Delete(int id)
         {
-            return await middleLableRepository.DeleteAsync(id);
+            return await middleLableService.DeleteAsync(id);
         }
         /// <summary>
         /// 修改导航中间件
@@ -69,7 +70,7 @@ namespace GxPress.Api.AdminControllers
         [HttpPut]
         public async Task<bool> Update(MiddleLableUpRequest request)
         {
-            return await middleLableRepository.UpdateAsync(request);
+            return await middleLableService.UpdateAsync(request);
         }
     }
 }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 5 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUtilsController.cs


+ 2 - 7
gx_api/GxPress/Model/GxPress.Entity/Navigations/MiddleLable.cs

@@ -3,7 +3,7 @@ using Datory.Annotations;
 namespace GxPress.Entity.Navigations
 {
     /// <summary>
-    /// 系统管理
+    /// 中间页面
     /// </summary>
     [DataTable("tede_middle_lable")]
     public class MiddleLable : Datory.Entity
@@ -14,12 +14,7 @@ namespace GxPress.Entity.Navigations
         /// <value></value>
         [DataColumn]
         public string Name { get; set; }
-        /// <summary>
-        /// 标签ID
-        /// </summary>
-        /// <value></value>
-        [DataColumn]
-        public string LabelId { get; set; }
+    
         /// <summary>
         /// 排序
         /// </summary>

+ 30 - 0
gx_api/GxPress/Model/GxPress.Entity/Navigations/MiddleLableNexus.cs

@@ -0,0 +1,30 @@
+using Datory.Annotations;
+
+namespace GxPress.Entity.Navigations
+{
+    /// <summary>
+    /// 中间页面关联标签
+    /// </summary>
+    [DataTable("tede_middle_lable_nexus")]
+    public class MiddleLableNexus : Datory.Entity
+    {
+        /// <summary>
+        /// 中间页面ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int MiddleLableId { get; set; }
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int LableId { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int Sort { get; set; }
+    }
+}

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

@@ -1,5 +1,6 @@
 using AutoMapper;
 using GxPress.Entity.Navigations;
+using GxPress.Request.Navigation;
 using GxPress.Result.Navigation;
 
 namespace GxPress.Mappings
@@ -9,6 +10,7 @@ namespace GxPress.Mappings
         public MiddleLableMapping()
         {
             CreateMap<MiddleLable, MiddleLableResult>();
+             CreateMap<MiddleLableInRequest, MiddleLable>();
         }
 
     }

+ 53 - 4
gx_api/GxPress/Model/GxPress.Request/Navigation/MiddleLableRequest.cs

@@ -1,8 +1,57 @@
 namespace GxPress.Request.Navigation
 {
-    public class MiddleLableRequest
+    /// <summary>
+    /// 添加
+    /// </summary>
+    public class MiddleLableInRequest
     {
+        /// <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>
     /// 修改
@@ -42,19 +91,19 @@ namespace GxPress.Request.Navigation
         /// 是否开启搜索
         /// </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; }
     }
 }

+ 99 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Navigation/MiddleLableNexusRepository.cs

@@ -0,0 +1,99 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AutoMapper;
+using Datory;
+using GxPress.Common.AppOptions;
+using GxPress.Common.Tools;
+using GxPress.Repository.Interface.Navigation;
+using Microsoft.Extensions.Options;
+using System.Transactions;
+
+namespace GxPress.Repository.Implement.Navigation
+{
+    public class MiddleLableNexusRepository : IMiddleLableNexusRepository
+    {
+        private readonly Repository<Entity.Navigations.MiddleLableNexus> _repository;
+        private readonly IMapper _mapper;
+        public MiddleLableNexusRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
+        {
+            var databaseType =
+                StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
+            var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
+            _repository = new Repository<Entity.Navigations.MiddleLableNexus>(database);
+            _mapper = mapper;
+        }
+
+        public IDatabase Database => _repository.Database;
+        public string TableName => _repository.TableName;
+        public List<TableColumn> TableColumns => _repository.TableColumns;
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="middleLableId"></param>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        public async Task<bool> InsertAsync(int middleLableId, List<int> ids)
+        {
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    foreach (var item in ids)
+                    {
+                        var model = new Entity.Navigations.MiddleLableNexus()
+                        {
+                            LableId = item,
+                            MiddleLableId = middleLableId
+                        };
+                        await _repository.InsertAsync(model);
+                    }
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="middleLableId"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<int>> 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);
+        }
+
+        public async Task<bool> DeleteByMiddleLableIdAsync(int middleLableId)
+        {
+            return await _repository.DeleteAsync(Q.Where(nameof(Entity.Navigations.MiddleLableNexus.MiddleLableId), middleLableId)) > 0;
+        }
+
+        public async Task<bool> UpdateAsync(int middleLableId, string lableId)
+        {
+            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);
+            }
+            catch
+            {
+                return false;
+
+            }
+            return true;
+        }
+
+    }
+}

+ 0 - 5
gx_api/GxPress/Repository/GxPress.Repository.Implement/Navigation/MiddleLableRepository.cs

@@ -4,7 +4,6 @@ using AutoMapper;
 using Datory;
 using GxPress.Common.AppOptions;
 using GxPress.Common.Tools;
-using GxPress.Entity.Navigations;
 using GxPress.Repository.Interface.Navigation;
 using GxPress.Request.Navigation;
 using Microsoft.Extensions.Options;
@@ -54,12 +53,8 @@ namespace GxPress.Repository.Implement.Navigation
                 var model = await GetAsync(request.Id);
                 if (request.IsDisable > 0)
                     model.IsDisable = request.IsDisable == 1;
-                if (!string.IsNullOrEmpty(request.LabelId))
-                    model.LabelId = request.LabelId;
                 if (!string.IsNullOrEmpty(request.Name))
                     model.Name = request.Name;
-                if (!string.IsNullOrEmpty(request.LabelId))
-                    model.LabelId = request.LabelId;
                 if (request.Sort > 0)
                     model.Sort = request.Sort;
                 if (request.IsSearch > 0)

+ 28 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Navigation/IMiddleLableNexusRepository.cs

@@ -0,0 +1,28 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Datory;
+
+namespace GxPress.Repository.Interface.Navigation
+{
+    public interface IMiddleLableNexusRepository : IRepository
+    {
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="middleLableId"></param>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        Task<bool> InsertAsync(int middleLableId, List<int> ids);
+
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="middleLableId"></param>
+        /// <returns></returns>
+        Task<IEnumerable<int>> GetAllTaskAsync(int middleLableId);
+        Task<bool> DeleteByMiddleLableIdAsync(int middleLableId);
+
+        Task<bool> UpdateAsync(int middleLableId, string lableId);
+
+    }
+}

+ 94 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Navigation/MiddleLableService.cs

@@ -0,0 +1,94 @@
+using System.Threading.Tasks;
+using GxPress.Repository.Interface.Navigation;
+using GxPress.Service.Interface.Navigation;
+using System.Transactions;
+using GxPress.Common.Tools;
+using System.Linq;
+using System.Collections.Generic;
+using GxPress.Request.Navigation;
+using AutoMapper;
+
+namespace GxPress.Service.Implement.Navigation
+{
+    public class MiddleLableService : IMiddleLableService
+    {
+        private readonly IMiddleLableRepository middleLableRepository;
+        private readonly IMiddleLableNexusRepository middleLableNexusRepository;
+        private readonly IMapper _mapper;
+        public MiddleLableService(IMiddleLableRepository middleLableRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMapper mapper)
+        {
+            this.middleLableRepository = middleLableRepository;
+            this.middleLableNexusRepository = middleLableNexusRepository;
+            _mapper = mapper;
+        }
+        /// <summary>
+        /// 添加中间件页面
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        public async Task<bool> InsertAsync(MiddleLableInRequest request)
+        {
+            try
+            {
+                using (var transactionScope = new System.Transactions.TransactionScope())
+                {
+                    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);
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<bool> DeleteAsync(int id)
+        {
+            try
+            {
+                using (var transactionScope = new System.Transactions.TransactionScope())
+                {
+                    await middleLableRepository.DeleteAsync(id);
+                    await middleLableNexusRepository.DeleteByMiddleLableIdAsync(id);
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+
+        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);
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+    }
+}

+ 9 - 8
gx_api/GxPress/Service/GxPress.Service.Implement/Navigation/NavigationService.cs

@@ -23,11 +23,11 @@ namespace GxPress.Service.Implement.Navigation
         private readonly ISystemLabelRepository _systemLabelRepository;
         private readonly IMediaRepository _mediaRepository;
         private readonly IMediaLableRepository _mediaLableRepository;
+        private readonly IMiddleLableNexusRepository middleLableNexusRepository;
         private readonly ISlideRepository slideRepository;
         private readonly ISpecialLabelRepository specialLabelRepository;
         private readonly ITeacherRepository teacherRepository;
-
-        public NavigationService(INavigationRepository _repository, IMapper _mapper, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMediaRepository _mediaRepository, IMediaLableRepository _mediaLableRepository, ISlideRepository slideRepository, ISpecialLabelRepository specialLabelRepository, ITeacherRepository teacherRepository)
+        public NavigationService(INavigationRepository _repository, IMapper _mapper, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMediaRepository _mediaRepository, IMediaLableRepository _mediaLableRepository, ISlideRepository slideRepository, ISpecialLabelRepository specialLabelRepository, ITeacherRepository teacherRepository, IMiddleLableNexusRepository middleLableNexusRepository)
         {
             this._navigationrepository = _repository;
             this._middleLableRepository = _middleLableRepository;
@@ -38,6 +38,7 @@ namespace GxPress.Service.Implement.Navigation
             this._mapper = _mapper;
             this.specialLabelRepository = specialLabelRepository;
             this.teacherRepository = teacherRepository;
+            this.middleLableNexusRepository = middleLableNexusRepository;
         }
         /// <summary>
         /// 获取导航栏数据
@@ -51,10 +52,10 @@ namespace GxPress.Service.Implement.Navigation
             {
                 //获取中间页面
                 var middleLable = await _middleLableRepository.GetAsync(navigation.MiddleLableId);
-                if (string.IsNullOrEmpty(middleLable.LabelId))
-                    return result;
                 result = _mapper.Map<MiddleLableResult>(middleLable);
                 result.NavigationLabelMediaResults = new List<NavigationLabelMediaResult>();
+                //获取中间页标签
+                var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(navigation.MiddleLableId);
                 //获取轮播
                 if (middleLable.IsSlide)
                 {
@@ -66,7 +67,7 @@ namespace GxPress.Service.Implement.Navigation
                     }
                 }
                 //获取标签
-                var systemLabels = await _systemLabelRepository.GetAllAsync(StringUtils.StringCollectionToIntList(middleLable.LabelId).ToList());
+                var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.ToList());
                 foreach (var item in systemLabels)
                 {
                     //获取常规数据
@@ -125,8 +126,8 @@ namespace GxPress.Service.Implement.Navigation
             var result = new MiddleLableResult();
             //获取中间页面
             var middleLable = await _middleLableRepository.GetAsync(middleLableId);
-            if (string.IsNullOrEmpty(middleLable.LabelId))
-                return result;
+            //获取中间页标签
+            var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLableId);
             result = _mapper.Map<MiddleLableResult>(middleLable);
             result.NavigationLabelMediaResults = new List<NavigationLabelMediaResult>();
             //获取轮播
@@ -140,7 +141,7 @@ namespace GxPress.Service.Implement.Navigation
                 }
             }
             //获取标签
-            var systemLabels = await _systemLabelRepository.GetAllAsync(StringUtils.StringCollectionToIntList(middleLable.LabelId).ToList());
+            var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.ToList());
             foreach (var item in systemLabels)
             {
                 //获取常规数据

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

@@ -0,0 +1,18 @@
+using System.Threading.Tasks;
+using GxPress.Request.Navigation;
+
+namespace GxPress.Service.Interface.Navigation
+{
+    public interface IMiddleLableService : IService
+    {
+        Task<bool> InsertAsync(MiddleLableInRequest request);
+          /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        Task<bool> DeleteAsync(int id);
+
+        Task<bool> UpdateAsync(MiddleLableUpRequest request);
+    }
+}