李昊 4 years ago
parent
commit
6b8d5c37ff
20 changed files with 260 additions and 24 deletions
  1. 4 4
      gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminCategoryController.cs
  2. 8 5
      gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminSystemLabelController.cs
  3. 5 2
      gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUtilsController.cs
  4. 24 0
      gx_api/GxPress/Model/GxPress.Entity/SystemLabel/SystemLableMedia.cs
  5. 7 1
      gx_api/GxPress/Model/GxPress.Entity/tede2/Category/Category.cs
  6. 5 0
      gx_api/GxPress/Model/GxPress.Entity/tede2/Media/Media.cs
  7. 21 0
      gx_api/GxPress/Model/GxPress.Request/SystemLabel/SystemLableMediaRequest.cs
  8. 5 1
      gx_api/GxPress/Model/GxPress.Result/Media/MediaResult.cs
  9. 6 1
      gx_api/GxPress/Model/GxPress.Result/SystemLabel/SystemLabelResult.cs
  10. 2 2
      gx_api/GxPress/Repository/GxPress.Repository.Implement/Category/CategoryRepository.cs
  11. 2 0
      gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs
  12. 11 4
      gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemLabel/SystemLabelRepository.cs
  13. 87 0
      gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemLabel/SystemLableMediaRepository.cs
  14. 1 1
      gx_api/GxPress/Repository/GxPress.Repository.Interface/Category/CategoryRepository.cs
  15. 2 1
      gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemLabel/ISystemLabelRepository.cs
  16. 26 0
      gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemLabel/ISystemLableMediaRepository.cs
  17. 1 1
      gx_api/GxPress/Service/GxPress.Service.Implement/Media/MediaService.cs
  18. 29 0
      gx_api/GxPress/Service/GxPress.Service.Implement/SystemLabel/SystemLabelService.cs
  19. 3 1
      gx_api/GxPress/Service/GxPress.Service.Interface/IService.cs
  20. 11 0
      gx_api/GxPress/Service/GxPress.Service.Interface/SystemLabel/ISystemLabelService.cs

+ 4 - 4
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminCategoryController.cs

@@ -91,13 +91,13 @@ namespace GxPress.Api.AdminControllers
             return success;
         }
         /// <summary>
-        /// 获取所有
+        /// 获取所有PC/APP端 0pc 1 app
         /// </summary>
         /// <returns></returns>
-        [HttpGet]
-        public async Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync()
+        [HttpGet("all/{typeId}")]
+        public async Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync(int typeId)
         {
-            return await categoryRepository.GetAllAsync();
+            return await categoryRepository.GetAllAsync(typeId);
         }
         /// <summary>
         /// 查询子集

+ 8 - 5
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminSystemLabelController.cs

@@ -1,8 +1,10 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
+using GxPress.Common.Page;
 using GxPress.Repository.Interface.SystemLabel;
 using GxPress.Request.SystemLabel;
 using GxPress.Result.SystemLabel;
+using GxPress.Service.Interface.SystemLabel;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 
@@ -17,10 +19,11 @@ namespace GxPress.Api.AdminControllers
     public class AdminSystemLabelController : ControllerBase
     {
         private readonly ISystemLabelRepository _repository;
-
-        public AdminSystemLabelController(ISystemLabelRepository repository)
+        private readonly ISystemLabelService systemLabelService;
+        public AdminSystemLabelController(ISystemLabelRepository repository, ISystemLabelService systemLabelService)
         {
             _repository = repository;
+            this.systemLabelService = systemLabelService;
         }
         /// <summary>
         /// 添加
@@ -46,10 +49,10 @@ namespace GxPress.Api.AdminControllers
         /// 获取标签列表
         /// </summary>
         /// <returns></returns>
-        [HttpGet]
-        public async Task<IEnumerable<SystemLabelResult>> GetAllAsync()
+        [HttpPost("list")]
+        public async Task<PagedList<SystemLabelResult>> GetAllAsync(Common.Page.PageParameter pageParameter)
         {
-            return await _repository.GetAllAsync();
+            return await systemLabelService.GetAllAsync(pageParameter);
         }
         /// <summary>
         /// 删除

File diff suppressed because it is too large
+ 5 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUtilsController.cs


+ 24 - 0
gx_api/GxPress/Model/GxPress.Entity/SystemLabel/SystemLableMedia.cs

@@ -0,0 +1,24 @@
+using Datory.Annotations;
+
+namespace GxPress.Entity.SystemLabel
+{
+    /// <summary>
+    /// 标签
+    /// </summary>
+    [DataTable("tede_system_lable_media")]
+    public class SystemLableMedia : Datory.Entity
+    {
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int LableId { get; set; }
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int MediaId { get; set; }
+    }
+}

+ 7 - 1
gx_api/GxPress/Model/GxPress.Entity/tede2/Category/Category.cs

@@ -27,6 +27,12 @@ namespace GxPress.Entity.tede2.Category
         /// <value></value>
         [DataColumn]
         public int ParentId { get; set; }
+        /// <summary>
+        /// 类型0 pc 1 app
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int TypeValue { get; set; }
 
         /// <summary>
         /// 排序
@@ -38,6 +44,6 @@ namespace GxPress.Entity.tede2.Category
         /// 是否存在子集
         /// </summary>
         /// <value></value>
-        public bool IsChildren{get;set;}
+        public bool IsChildren { get; set; }
     }
 }

+ 5 - 0
gx_api/GxPress/Model/GxPress.Entity/tede2/Media/Media.cs

@@ -101,6 +101,11 @@ namespace GxPress.Entity.tede2.Media
         [DataColumn]
         public string CategoryId { get; set; }
         /// <summary>
+        /// 分类ID
+        /// </summary>
+        [DataColumn]
+        public int AppCategoryId { get; set; }
+        /// <summary>
         /// 完整分类ID
         /// </summary>
         [DataColumn]

+ 21 - 0
gx_api/GxPress/Model/GxPress.Request/SystemLabel/SystemLableMediaRequest.cs

@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+
+namespace GxPress.Request.SystemLabel
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    public class SystemLableMediaRequest
+    {
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+        public int LableId { get; set; }
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public List<int> MediaIds { get; set; }
+    }
+}

+ 5 - 1
gx_api/GxPress/Model/GxPress.Result/Media/MediaResult.cs

@@ -219,7 +219,11 @@ namespace GxPress.Result.Media
         /// 分类ID
         /// </summary>
         public List<string> CategoryId { get; set; }
-
+        /// <summary>
+        /// app内容导航
+        /// </summary>
+        /// <value></value>
+        public int AppCategoryId { get; set; }
         /// <summary>
         /// 完整分类ID
         /// </summary>

+ 6 - 1
gx_api/GxPress/Model/GxPress.Result/SystemLabel/SystemLabelResult.cs

@@ -100,6 +100,11 @@ namespace GxPress.Result.SystemLabel
         /// </summary>
         /// <value></value>
         public int ResourceCount { get; set; }
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public IEnumerable<int> MediaIds { get; set; }
     }
     /// <summary>
     /// APP导航
@@ -110,7 +115,7 @@ namespace GxPress.Result.SystemLabel
         /// 
         /// </summary>
         /// <value></value>
-        public int Id{get;set;}
+        public int Id { get; set; }
         /// <summary>
         /// 显示数据
         /// </summary>

+ 2 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/Category/CategoryRepository.cs

@@ -38,9 +38,9 @@ namespace GxPress.Repository.Implement.Category
             return await _repository.DeleteAsync(id);
         }
 
-        public async Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync()
+        public async Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync(int typeValue)
         {
-            return await _repository.GetAllAsync();
+            return await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Category.Category.TypeValue),typeValue));
         }
 
         public async Task<Entity.tede2.Category.Category> GetAsync(int id)

+ 2 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -365,6 +365,8 @@ namespace GxPress.Repository.Implement.Media
                         model.JournalsCategory = result.JournalsCategory;
                     if (result.IsExercises > 0)
                         model.IsExercises = result.IsExercises == 1;
+                    if (result.AppCategoryId > 0)
+                        model.AppCategoryId = result.AppCategoryId;
                     await _repository.UpdateAsync(model);
                     if (result.MediaLibraryResults != null && result.MediaLibraryResults.Count > 0)
                     {

+ 11 - 4
gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemLabel/SystemLabelRepository.cs

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
 using AutoMapper;
 using Datory;
 using GxPress.Common.AppOptions;
+using GxPress.Common.Page;
 using GxPress.Common.Tools;
 using GxPress.Repository.Interface.SystemLabel;
 using GxPress.Request.SystemLabel;
@@ -87,12 +88,18 @@ namespace GxPress.Repository.Implement.SystemLabel
             return await _repository.UpdateAsync(query) > 0;
         }
 
-        public async Task<IEnumerable<SystemLabelResult>> GetAllAsync()
+        public async Task<PagedList<SystemLabelResult>> GetAllAsync(Common.Page.PageParameter request)
         {
-            var result = await _repository.GetAllAsync<SystemLabelResult>(Q.Where(nameof(Entity.SystemLabel.SystemLabel.IsDisable), false).OrderByDesc(nameof(Entity.Navigations.Navigation.Sort)));
-            foreach (var item in result)
+            var result = new PagedList<SystemLabelResult>();
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.SystemLabel.SystemLabel.IsDisable), false);
+            result.Total = await _repository.CountAsync(query);
+            query.OrderByDesc(nameof(Entity.Navigations.Navigation.Sort));
+            query.ForPage(request.Page, request.PerPage);
+            result.Items = await _repository.GetAllAsync<SystemLabelResult>(query);
+            foreach (var item in result.Items)
             {
-                var query = Q.NewQuery();
+                query = Q.NewQuery();
                 query.Where(nameof(Entity.tede2.Media.MediaLable.LableId), item.Id);
                 //获取资源数量
                 item.ResourceCount = await mediaLableRepository.CountAsync(query);

+ 87 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemLabel/SystemLableMediaRepository.cs

@@ -0,0 +1,87 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AutoMapper;
+using Datory;
+using GxPress.Common.AppOptions;
+using GxPress.Common.Tools;
+using GxPress.Repository.Interface.SystemLabel;
+using GxPress.Request.SystemLabel;
+using Microsoft.Extensions.Options;
+using System.Transactions;
+using Dapper;
+
+namespace GxPress.Repository.Implement.SystemLabel
+{
+    public class SystemLableMediaRepository : ISystemLableMediaRepository
+    {
+        private readonly Repository<Entity.SystemLabel.SystemLableMedia> _repository;
+        private readonly IMapper _mapper;
+        private readonly string _connectionString;
+        private readonly string _databaseTypestr;
+        private readonly Repository<Entity.SystemLabel.SystemLableMedia> mediaLableRepository;
+        public SystemLableMediaRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
+        {
+            _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
+            _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
+            var databaseType =
+                StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
+            var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
+            _repository = new Repository<Entity.SystemLabel.SystemLableMedia>(database);
+            _mapper = mapper;
+            mediaLableRepository = new Repository<Entity.SystemLabel.SystemLableMedia>(database);
+        }
+        public IDatabase Database => _repository.Database;
+        public string TableName => _repository.TableName;
+        public List<TableColumn> TableColumns => _repository.TableColumns;
+
+        public async Task<Entity.SystemLabel.SystemLableMedia> GetAsync(int id)
+        {
+            return await _repository.GetAsync(id);
+        }
+        /// <summary>
+        /// 根据标签ID获取媒体ID
+        /// </summary>
+        /// <param name="lableId"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<int>> GetMediaIdsAsync(int lableId)
+        {
+            return await _repository.GetAllAsync<int>(Q.Where(nameof(Entity.SystemLabel.SystemLableMedia.LableId), lableId).Select(nameof(Entity.SystemLabel.SystemLableMedia.MediaId)));
+        }
+        public async Task<bool> DeleteAsync(List<int> ids)
+        {
+            return await _repository.DeleteAsync(Q.WhereIn(nameof(Entity.SystemLabel.SystemLableMedia.Id), ids)) > 0;
+        }
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<bool> InsertAsync(SystemLableMediaRequest request)
+        {
+            try
+            {
+                using (var transactions = new TransactionScope())
+                {
+                    var sql = $@"INSERT INTO `tede_system_lable_media`(`Guid`,`CreatedDate`,`LastModifiedDate`,`LableId`,`MediaId`) VALUES";
+                    var createdDate = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
+                    foreach (var item in request.MediaIds)
+                    {
+                        var guid = System.Guid.NewGuid().ToString();
+                        sql += $@"('{guid}','{createdDate}','{createdDate}',{request.LableId},{item}),";
+                    }
+                    sql = sql.Remove(sql.Length - 1, 1);
+                    var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+                    var database = new Database(databaseType, _connectionString);
+                    var connection = database.GetConnection();
+                    await connection.ExecuteAsync(sql);
+                    transactions.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
+        }
+    }
+}

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/Category/CategoryRepository.cs

@@ -24,7 +24,7 @@ namespace GxPress.Repository.Interface.Category
         /// </summary>
         /// <returns></returns>
 
-        Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync();
+        Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync(int typeValue);
         /// <summary>
         /// 查询子集
         /// </summary>

+ 2 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemLabel/ISystemLabelRepository.cs

@@ -1,6 +1,7 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using Datory;
+using GxPress.Common.Page;
 using GxPress.Request.SystemLabel;
 using GxPress.Result.SystemLabel;
 
@@ -15,7 +16,7 @@ namespace GxPress.Repository.Interface.SystemLabel
         Task<int> InsertAsync(Entity.SystemLabel.SystemLabel note);
 
         Task<bool> UpdateAsync(SystemLabelUpRequest note);
-        Task<IEnumerable<SystemLabelResult>> GetAllAsync();
+        Task<PagedList<SystemLabelResult>> GetAllAsync(Common.Page.PageParameter request);
         Task<IEnumerable<Entity.SystemLabel.SystemLabel>> GetAllAsync(List<int> ids);
 
     }

+ 26 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemLabel/ISystemLableMediaRepository.cs

@@ -0,0 +1,26 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Datory;
+using GxPress.Request.SystemLabel;
+
+namespace GxPress.Repository.Interface.SystemLabel
+{
+    public interface ISystemLableMediaRepository : IRepository
+    {
+        Task<Entity.SystemLabel.SystemLableMedia> GetAsync(int id);
+        /// <summary>
+        /// 根据标签ID获取媒体ID
+        /// </summary>
+        /// <param name="lableId"></param>
+        /// <returns></returns>
+        Task<IEnumerable<int>> GetMediaIdsAsync(int lableId);
+        Task<bool> DeleteAsync(List<int> ids);
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<bool> InsertAsync(SystemLableMediaRequest request);
+    }
+
+}

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Media/MediaService.cs

@@ -48,7 +48,7 @@ namespace GxPress.Service.Implement.Media
             //获取媒体
             result = await mediaRepository.GetAsync(id);
             //获取类别
-            var categoryAll = await categoryRepository.GetAllAsync();
+            var categoryAll = await categoryRepository.GetAllAsync(0);
             result.CategoryResults = categoryAll.Where(n => n.ParentId == 0).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
             foreach (var item in result.CategoryResults)
             {

+ 29 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/SystemLabel/SystemLabelService.cs

@@ -0,0 +1,29 @@
+using GxPress.Service.Interface.SystemLabel;
+using GxPress.Repository.Interface.SystemLabel;
+using System.Threading.Tasks;
+using GxPress.Common.Page;
+using GxPress.Result.SystemLabel;
+
+namespace GxPress.Service.Implement.SystemLabel
+{
+    public class SystemLabelService : ISystemLabelService
+    {
+        private readonly ISystemLabelRepository systemLabelRepository;
+        private readonly ISystemLableMediaRepository systemLableMediaRepository;
+        public SystemLabelService(ISystemLabelRepository systemLabelRepository, ISystemLableMediaRepository systemLableMediaRepository)
+        {
+            this.systemLabelRepository = systemLabelRepository;
+            this.systemLableMediaRepository = systemLableMediaRepository;
+        }
+
+        public async Task<PagedList<SystemLabelResult>> GetAllAsync(Common.Page.PageParameter request)
+        {
+            var result = await systemLabelRepository.GetAllAsync(request);
+            foreach (var item in result.Items)
+            {
+                item.MediaIds = await systemLableMediaRepository.GetMediaIdsAsync(item.Id);
+            }
+            return result;
+        }
+    }
+}

+ 3 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/IService.cs

@@ -2,12 +2,14 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Threading.Tasks;
+using GxPress.Common.Page;
 using GxPress.Request.GroupChat;
+using GxPress.Result.SystemLabel;
 
 namespace GxPress.Service.Interface
 {
     public interface IService
     {
-       
+        
     }
 }

+ 11 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/SystemLabel/ISystemLabelService.cs

@@ -0,0 +1,11 @@
+using System.Threading.Tasks;
+using GxPress.Common.Page;
+using GxPress.Result.SystemLabel;
+
+namespace GxPress.Service.Interface.SystemLabel
+{
+    public interface ISystemLabelService : IService
+    {
+        Task<PagedList<SystemLabelResult>> GetAllAsync(Common.Page.PageParameter request);
+    }
+}