李昊 4 lat temu
rodzic
commit
f4f9a4864a

BIN
gx_api/GxPress/.DS_Store


BIN
gx_api/GxPress/Api/.DS_Store


Plik diff jest za duży
+ 5 - 2
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUtilsController.cs


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

@@ -0,0 +1,31 @@
+using Datory.Annotations;
+
+namespace GxPress.Entity.tede2.Media
+{
+    /// <summary>
+    /// 媒体标签
+    /// </summary>
+    [DataTable("tede_media_lable")]
+    public class MediaLable : Datory.Entity
+    {
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int MediaId { get; set; } 
+
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public int LableId { get; set; }
+        /// <summary>
+        /// 标签名称
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public string LableIdName { get; set; }
+    }
+}

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

@@ -13,6 +13,8 @@ namespace GxPress.Mappings
             CreateMap<MediaLibrary, MediaLibraryResult>();
             CreateMap<MediaResult, Media>();
             CreateMap<MediaLibraryResult, MediaLibrary>();
+            CreateMap<MediaLableResult, MediaLable>();
+            CreateMap<MediaLable, MediaLableResult>();
         }
 
     }

+ 54 - 21
gx_api/GxPress/Model/GxPress.Request/Media/MediaRequest.cs

@@ -3,6 +3,9 @@ using System.Collections.Generic;
 
 namespace GxPress.Request.Media
 {
+    /// <summary>
+    /// 媒体
+    /// </summary>
     public class MediaRequest
     {
         /// <summary>
@@ -19,36 +22,36 @@ namespace GxPress.Request.Media
         ////视频
         //Video=6
         /// </summary>
-        
+
         public int MediaType { get; set; }
         /// <summary>
         /// 标题
         /// </summary>
-        
+
         public string Title { get; set; }
 
         /// <summary>
         /// 标题图片
         /// </summary>
-        
+
         public string ImageUrls { get; set; }
 
         /// <summary>
         /// 简介
         /// </summary>
-        
+
         public string Summary { get; set; }
 
         /// <summary>
         /// 作者
         /// </summary>
-        
+
         public string Author { get; set; }
 
         /// <summary>
         /// 来源
         /// </summary>
-        
+
         public string Source { get; set; }
 
         /// <summary>
@@ -59,63 +62,73 @@ namespace GxPress.Request.Media
         /// <summary>
         /// 审核状态
         /// </summary>
-        
+
         public bool IsChecked { get; set; }
 
         /// <summary>
         /// 添加时间
         /// </summary>
-        
+
         public DateTime AddDate { get; set; }
         /// <summary>
         /// 排序
         /// </summary>
-        
+
         public int Sort { get; set; }
         /// <summary>
         /// 文章阅读量
         /// </summary>
-        
+
         public int ReadCount { get; set; }
         /// <summary>
         /// 是否置顶
         /// </summary>
-        
+
         public bool IsTop { get; set; }
         /// <summary>
         /// 分类ID
         /// </summary>
-        
+
         public int CategoryId { get; set; }
         /// <summary>
         /// 标签ID
         /// </summary>
-        
+
         public int LableId { get; set; }
         /// <summary>
         /// 是否推荐
         /// </summary>
-        
+
         public bool IsRecommend { get; set; }
         /// <summary>
         /// 出版社
         /// </summary>
-        
+
         public string Press { get; set; }
         /// <summary>
         /// 出版时间
         /// </summary>
-        
+
         public string PublishTime { get; set; }
 
         /// <summary>
         /// 媒体类
         /// </summary>
         public List<MediaLibraryRequest> MediaLibraryRequest { get; set; }
-
+        /// <summary>
+        /// 媒体标签
+        /// </summary>
+        public List<MediaLableRequest> MediaLableRequests { get; set; }
     }
-
-    public class MediaLibraryRequest {
+    /// <summary>
+    /// 媒体库
+    /// </summary>
+    public class MediaLibraryRequest
+    {
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
         public int MediaId { get; set; }
         /// <summary>
         /// 文件路径
@@ -124,12 +137,32 @@ namespace GxPress.Request.Media
         /// <summary>
         /// 文件名称
         /// </summary>
-        
+
         public string Name { get; set; }
         /// <summary>
         /// 排序
         /// </summary>
-        
+
         public int Sort { get; set; }
     }
+
+    /// <summary>
+    /// 媒体标签
+    /// </summary>
+    public class MediaLableRequest
+    {
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public int MediaId { get; set; }
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        public string LableId { get; set; }
+        /// <summary>
+        /// 标签名称
+        /// </summary>
+        public string LableName { get; set; }
+    }
 }

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

@@ -119,8 +119,12 @@ namespace GxPress.Result.Media
         /// <summary>
         /// 媒体类
         /// </summary>
-        public List<MediaLibraryResult> MediaLibraryRequest { get; set; }
-
+        public List<MediaLibraryResult> MediaLibraryResults { get; set; }
+        /// <summary>
+        /// 媒体标签
+        /// </summary>
+        /// <value></value>
+        public List<MediaLableResult> MediaLableResults { get; set; }
         /// <summary>
         ///  操作人ID
         /// </summary>
@@ -156,9 +160,25 @@ namespace GxPress.Result.Media
         /// <summary>
         /// 排序
         /// </summary>
-
         public int Sort { get; set; }
-
-
+    }
+    /// <summary>
+    /// 媒体标签
+    /// </summary>
+    public class MediaLableResult
+    {
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public int MediaId { get; set; }
+        /// <summary>
+        /// 标签ID
+        /// </summary>
+        public string LableId { get; set; }
+        /// <summary>
+        /// 标签名称
+        /// </summary>
+        public string LableName { get; set; }
     }
 }

+ 32 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaLableRepository.cs

@@ -0,0 +1,32 @@
+using System.Collections.Generic;
+using AutoMapper;
+using Datory;
+using GxPress.Common.AppOptions;
+using GxPress.Common.Tools;
+using GxPress.Repository.Interface.Media;
+using Microsoft.Extensions.Options;
+
+namespace GxPress.Repository.Implement.Media
+{
+    public class MediaLableRepository : IMediaLableRepository
+    {
+        private readonly Repository<Entity.tede2.Media.MediaLable> _repository;
+        private readonly IMapper _mapper;
+        private readonly string _connectionString;
+        private readonly string _databaseTypestr;
+        public MediaLableRepository(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.tede2.Media.MediaLable>(database);
+            _mapper = mapper;
+        }
+
+        public IDatabase Database => _repository.Database;
+        public string TableName => _repository.TableName;
+        public List<TableColumn> TableColumns => _repository.TableColumns;
+    }
+}

+ 48 - 7
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -9,6 +9,7 @@ using GxPress.Repository.Interface.Media;
 using GxPress.Result.Media;
 using Microsoft.Extensions.Options;
 using System.Transactions;
+using GxPress.Common.Exceptions;
 
 namespace GxPress.Repository.Implement.Media
 {
@@ -16,6 +17,7 @@ namespace GxPress.Repository.Implement.Media
     {
         private readonly Repository<Entity.tede2.Media.Media> _repository;
         private readonly Repository<Entity.tede2.Media.MediaLibrary> mediaLibraryRepository;
+        private readonly Repository<Entity.tede2.Media.MediaLable> mediaLableRepository;
         private readonly IMapper _mapper;
         private readonly string _connectionString;
         private readonly string _databaseTypestr;
@@ -28,6 +30,7 @@ namespace GxPress.Repository.Implement.Media
             var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
             _repository = new Repository<Entity.tede2.Media.Media>(database);
             mediaLibraryRepository = new Repository<Entity.tede2.Media.MediaLibrary>(database);
+            mediaLableRepository = new Repository<Entity.tede2.Media.MediaLable>(database);
             _mapper = mapper;
         }
 
@@ -43,13 +46,36 @@ namespace GxPress.Repository.Implement.Media
             result = _mapper.Map<MediaResult>(media);
             //获取媒体库资源
             var mediaLibrarys = await mediaLibraryRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
-            result.MediaLibraryRequest = mediaLibrarys.ToList().Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
+            result.MediaLibraryResults = mediaLibrarys.ToList().Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
+            //获取媒体标签
+            var mediaLables = await mediaLableRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
+            result.MediaLableResults = mediaLables.Select(n => _mapper.Map<MediaLableResult>(n)).ToList();
             return result;
         }
-
+        /// <summary>
+        /// 删除媒体
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
         public async Task<bool> DeleteAsync(int id)
         {
-            return await _repository.DeleteAsync(id);
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    //删除媒体库
+                    await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
+                    //删除媒体标签
+                    await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
+                    await _repository.DeleteAsync(id);
+                    transactionScope.Complete();
+                }
+            }
+            catch (System.Exception ex)
+            {
+                throw new BusinessException(ex.Message);
+            }
+            return true;
         }
         /// <summary>
         /// 添加媒体
@@ -66,15 +92,22 @@ namespace GxPress.Repository.Implement.Media
                     var id = await _repository.InsertAsync(model);
                     if (id > 0)
                     {
-                        foreach (var item in result.MediaLibraryRequest)
+                        foreach (var item in result.MediaLibraryResults)
                         {
                             var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
                             await mediaLibraryRepository.InsertAsync(mediaLibrary);
                         }
                     }
-                    if(result.Id==0&&result.TeacherId==0&&!string.IsNullOrEmpty(result.Author)){
+                    //添加标签
+                    foreach (var item in result.MediaLableResults)
+                    {
+                        var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
+                        await mediaLableRepository.InsertAsync(mediaLable);
+                    }
+                    if (result.Id == 0 && result.TeacherId == 0 && !string.IsNullOrEmpty(result.Author))
+                    {
                         //新增名师
-                        
+
                     }
                     //提交事务
                     transactionScope.Complete();
@@ -112,11 +145,19 @@ namespace GxPress.Repository.Implement.Media
                     await _repository.UpdateAsync(model);
                     //删除媒体库
                     await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), result.Id));
-                    foreach (var item in result.MediaLibraryRequest)
+                    //删除媒体标签
+                    await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), result.Id));
+                    foreach (var item in result.MediaLibraryResults)
                     {
                         var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
                         await mediaLibraryRepository.InsertAsync(mediaLibrary);
                     }
+                    //添加标签
+                    foreach (var item in result.MediaLableResults)
+                    {
+                        var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
+                        await mediaLableRepository.InsertAsync(mediaLable);
+                    }
                     //提交事务
                     transactionScope.Complete();
                 }

+ 9 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaLableRepository.cs

@@ -0,0 +1,9 @@
+using Datory;
+
+namespace GxPress.Repository.Interface.Media
+{
+    public interface IMediaLableRepository:IRepository
+    {
+         
+    }
+}