李昊 лет назад: 4
Родитель
Сommit
c92ae7b204

+ 24 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebMediaController.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using GxPress.Auth;
 using GxPress.Repository.Interface.Media;
+using GxPress.Request.Media;
 using GxPress.Result.Media;
 using GxPress.Service.Interface.Media;
 using Microsoft.AspNetCore.Authorization;
@@ -37,8 +38,30 @@ namespace GxPress.Api.WebControllers
         [AllowAnonymous]
         public async Task<MediaResult> GetAsync(int id)
         {
-          
+
             return await mediaService.GetAsync(id);
         }
+        /// <summary>
+        /// 书籍详情
+        /// /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("book/{id}")]
+        [AllowAnonymous]
+        public async Task<BookMediaResult> GetBookMediaResult(int id)
+        {
+            return await mediaService.GetBookMediaResultAsync(id);
+        }
+        /// <summary>
+        /// 获取章节内容
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("book/content")]
+        [AllowAnonymous]
+        public async Task<string> GetBookMediaContentResultAsync(BookCatalogRequest request)
+        {
+            return await mediaService.GetBookMediaContentResultAsync(request);
+        }
     }
 }

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

@@ -15,6 +15,7 @@ namespace GxPress.Mappings
             CreateMap<MediaLibraryResult, MediaLibrary>();
             CreateMap<MediaLableResult, MediaLable>();
             CreateMap<MediaLable, MediaLableResult>();
+            CreateMap<Media,BookMediaResult>();
         }
 
     }

+ 159 - 0
gx_api/GxPress/Model/GxPress.Result/Media/BookMediaResult.cs

@@ -0,0 +1,159 @@
+using System.Collections.Generic;
+using GxPress.Result.Category;
+
+namespace GxPress.Result.Media
+{
+    /// <summary>
+    /// 媒体
+    /// </summary>
+    public class BookMediaResult
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        public int Id { get; set; }
+
+        /// <summary>
+        /// 媒体类型 文章100 书籍20,课程30,音频40,期刊50,视频60,名栏90,公众号110,刊期120
+        /// </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>
+        /// Json内容
+        /// </summary>
+        public string Blocks { get; set; }
+
+
+        /// <summary>
+        /// 添加时间
+        /// </summary>
+
+        public string AddDate { get; set; }
+
+        /// <summary>
+        /// 文章阅读量
+        /// </summary>
+
+        public int ReadCount { get; set; }
+
+        /// <summary>
+        /// 是否推荐 1 设置 2取消
+        /// </summary>
+
+        public int IsRecommend { get; set; }
+        /// <summary>
+        /// 出版社
+        /// </summary>
+
+        public string Press { get; set; }
+        /// <summary>
+        /// 出版时间
+        /// </summary>
+
+        public string PublishTime { get; set; }
+
+        /// <summary>
+        /// ios折扣价格打折
+        /// </summary>
+        public decimal IosDiscountPrice { get; set; }
+        /// <summary>
+        /// IOS价格
+        /// </summary>
+        public decimal IosPrice { get; set; }
+        /// <summary>
+        /// 其他折扣价格打折
+        /// </summary>
+        public decimal OtherDiscountPrice { get; set; }
+        /// <summary>
+        /// 其他价格
+        /// </summary>
+        public decimal OtherPrice { get; set; }
+        /// <summary>
+        /// 免费类容占比
+        /// </summary>
+        /// <value></value>
+        public decimal FreeProportion { get; set; }
+        /// <summary>
+        /// 收藏次数
+        /// </summary>
+        public int CollectCount { get; set; }
+        /// <summary>
+        /// 转发数量
+        /// </summary>
+        /// <value></value>
+        public int RetransmissionCount { get; set; }
+        /// <summary>
+        /// 评论数量
+        /// </summary>
+        /// <value></value>
+        public int CommentCount { get; set; }
+
+        /// <summary>
+        /// 书籍目录
+        /// </summary>
+        /// <value></value>
+        public List<BookCatalogResult> BookCatalogResults { get; set; }
+        /// <summary>
+        /// 评论分数
+        /// </summary>
+        /// <value></value>
+        public decimal CommentScore { get; set; }
+    }
+
+    /// <summary>
+    /// 返回书籍目录
+    /// </summary>
+    public class BookCatalogResult
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 目录名称
+        /// </summary>
+        /// <value></value>
+        public string CatalogNameg { get; set; }
+        /// <summary>
+        /// 目录ID
+        /// </summary>
+        /// <value></value>
+        public string CatalogId { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int ParentId { get; set; }
+    }
+}

+ 0 - 26
gx_api/GxPress/Model/GxPress.Result/Media/MediaResult.cs

@@ -305,30 +305,4 @@ namespace GxPress.Result.Media
         public string LableName { get; set; }
 
     }
-    /// <summary>
-    /// 返回书籍目录
-    /// </summary>
-    public class BookCatalogResult
-    {
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <value></value>
-        public int Id{get;set;}
-        /// <summary>
-        /// 目录名称
-        /// </summary>
-        /// <value></value>
-        public string CatalogNameg { get; set; }
-        /// <summary>
-        /// 目录ID
-        /// </summary>
-        /// <value></value>
-        public string CatalogId { get; set; }
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <value></value>
-        public int ParentId { get; set; }
-    }
 }

+ 6 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaLibraryRepository.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Threading.Tasks;
 using AutoMapper;
 using Datory;
 using GxPress.Common.AppOptions;
@@ -9,7 +10,7 @@ using Microsoft.Extensions.Options;
 
 namespace GxPress.Repository.Implement.Media
 {
-    public class MediaLibraryRepository:IMediaLibraryRepository
+    public class MediaLibraryRepository : IMediaLibraryRepository
     {
         private readonly Repository<Entity.tede2.Media.MediaLibrary> _repository;
         private readonly IMapper _mapper;
@@ -30,5 +31,9 @@ namespace GxPress.Repository.Implement.Media
         public string TableName => _repository.TableName;
         public List<TableColumn> TableColumns => _repository.TableColumns;
 
+        public async Task<Entity.tede2.Media.MediaLibrary> GetTaskAsync(int mediaId)
+        {
+            return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 1));
+        }
     }
 }

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

@@ -339,5 +339,16 @@ namespace GxPress.Repository.Implement.Media
         {
             return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.AutoNumber), autoNumber));
         }
+
+        /// <summary>
+        /// 获取书籍
+        /// </summary>
+        /// <param name="mediaId"></param>
+        /// <returns></returns>
+        public async Task<BookMediaResult> GetBookMediaResultAsync(int mediaId)
+        {
+            var result = await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), mediaId).Where(nameof(Entity.tede2.Media.Media.IsChecked), true).Where(nameof(Entity.tede2.Media.Media.IsDelete), false));
+            return _mapper.Map<BookMediaResult>(result);
+        }
     }
 }

+ 2 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaLibraryRepository.cs

@@ -1,9 +1,11 @@
 using System;
+using System.Threading.Tasks;
 using Datory;
 
 namespace GxPress.Repository.Interface.Media
 {
     public interface IMediaLibraryRepository:IRepository
     {
+        Task<Entity.tede2.Media.MediaLibrary> GetTaskAsync(int mediaId);
     }
 }

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaRepository.cs

@@ -29,5 +29,11 @@ namespace GxPress.Repository.Interface.Media
         Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request);
         Task<int> CountAsync(string beginTime, string endTiem);
         Task<int> CountAsync(SqlKata.Query query);
+        /// <summary>
+        /// 获取书籍
+        /// </summary>
+        /// <param name="mediaId"></param>
+        /// <returns></returns>
+        Task<BookMediaResult> GetBookMediaResultAsync(int mediaId);
     }
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Epub/EpubService.cs

@@ -46,7 +46,7 @@ namespace GxPress.Service.Implement.Epub
         /// 获取章节内容
         /// </summary>
         /// <returns></returns>
-        public string GetBookCatalogContext(BookCatalogRequest request)
+        public string GetBookCatalogContent(BookCatalogRequest request)
         {
             if (string.IsNullOrEmpty(request.Path))
                 return string.Empty;

+ 49 - 19
gx_api/GxPress/Service/GxPress.Service.Implement/Media/MediaService.cs

@@ -7,6 +7,7 @@ using AutoMapper;
 using System.Linq;
 using GxPress.Result.Category;
 using GxPress.Service.Interface.Epub;
+using GxPress.Request.Media;
 
 namespace GxPress.Service.Implement.Media
 {
@@ -16,12 +17,14 @@ namespace GxPress.Service.Implement.Media
         private readonly IMediaRepository mediaRepository;
         private readonly IMapper _mapper;
         private readonly IEpubService epubService;
-        public MediaService(ICategoryRepository categoryRepository, IMediaRepository mediaRepository, IMapper _mapper,IEpubService epubService)
+        private readonly IMediaLibraryRepository mediaLibraryRepository;
+        public MediaService(ICategoryRepository categoryRepository, IMediaRepository mediaRepository, IMapper _mapper, IEpubService epubService, IMediaLibraryRepository mediaLibraryRepository)
         {
             this.categoryRepository = categoryRepository;
             this.mediaRepository = mediaRepository;
             this._mapper = _mapper;
-            this.epubService=epubService;
+            this.epubService = epubService;
+            this.mediaLibraryRepository = mediaLibraryRepository;
         }
         public async Task<bool> InsertAsync(MediaResult result)
         {
@@ -53,25 +56,52 @@ namespace GxPress.Service.Implement.Media
                     }
                 }
             }
-            //如果是书籍
-            
+
+            return result;
+        }
+        /// <summary>
+        /// 获取书籍详情
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<BookMediaResult> GetBookMediaResultAsync(int id)
+        {
+            var result = await mediaRepository.GetBookMediaResultAsync(id);
+            if (result == null)
+                throw new Common.Exceptions.BusinessException("不存在");
+            if (result.MediaType != GxPress.EnumConst.ResourceTypeConst.Book.GetHashCode())
+                throw new Common.Exceptions.BusinessException("非书籍");
+            //获取书籍文件
+            var mediaLibrary = await mediaLibraryRepository.GetTaskAsync(id);
+            if (!mediaLibrary.FileUrl.Contains("epub"))
+                throw new Common.Exceptions.BusinessException("书籍不存在epub文件");
+            //书籍
+            result.BookCatalogResults = epubService.GetCatalog("wwwroot" + mediaLibrary.FileUrl);
+            //计算免费占比
+
             return result;
         }
+        /// <summary>
+        /// 获取章节内容
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<string> GetBookMediaContentResultAsync(BookCatalogRequest request)
+        {
+            if (request.MediaId == 0)
+                throw new Common.Exceptions.BusinessException("请检查参数");
+            if (string.IsNullOrEmpty(request.CatalogNameg))
+                throw new Common.Exceptions.BusinessException("请检查参数");
+            if (string.IsNullOrEmpty(request.CatalogId))
+                throw new Common.Exceptions.BusinessException("请检查参数");
+            //获取书籍文件
+            var mediaLibrary = await mediaLibraryRepository.GetTaskAsync(request.MediaId);
+            if (!mediaLibrary.FileUrl.Contains("epub"))
+                throw new Common.Exceptions.BusinessException("书籍不存在epub文件");
+            request.Path = mediaLibrary.FileUrl;
+            return epubService.GetBookCatalogContent(request);
+        }
+
 
-        // public List<CategoryResult> GetAllCategoryResult(IEnumerable<Entity.tede2.Category.Category> categorys, int id, List<CategoryResult> categoryResults)
-        // {
-        //     var result = new List<CategoryResult>();
-        //     result = categorys.Where(n => n.ParentId == id).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
-        //     foreach (var item in result)
-        //     {
-        //         item.IsChildren = categorys.Any(n => n.ParentId == item.Id);
-        //         item.Children = categorys.Where(n => n.ParentId == item.Id).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
-        //         foreach (var children in item.Children)
-        //         {
-        //             GetAllCategoryResult(categorys,children.Id,categoryResults);
-        //         }
-        //     }
-        //     return result;
-        // }
     }
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Epub/IEpubService.cs

@@ -15,6 +15,6 @@ namespace GxPress.Service.Interface.Epub
         /// 获取章节内容
         /// </summary>
         /// <returns></returns>
-        string GetBookCatalogContext(BookCatalogRequest request);
+        string GetBookCatalogContent(BookCatalogRequest request);
     }
 }

+ 17 - 3
gx_api/GxPress/Service/GxPress.Service.Interface/Media/IMediaService.cs

@@ -1,11 +1,25 @@
 using System.Threading.Tasks;
+using GxPress.Request.Media;
 using GxPress.Result.Media;
 
 namespace GxPress.Service.Interface.Media
 {
-    public interface IMediaService:IService
+    public interface IMediaService : IService
     {
-         Task<bool> InsertAsync(MediaResult result);
-         Task<MediaResult> GetAsync(int id);
+        Task<bool> InsertAsync(MediaResult result);
+        Task<MediaResult> GetAsync(int id);
+        /// <summary>
+        /// 获取书籍详情
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        Task<BookMediaResult> GetBookMediaResultAsync(int id);
+
+        /// <summary>
+        /// 获取章节内容
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+         Task<string> GetBookMediaContentResultAsync(BookCatalogRequest request);
     }
 }