lihao 4 år sedan
förälder
incheckning
47c0055c6a

+ 29 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/ArticleRepository.cs

@@ -13,6 +13,7 @@ using GxPress.Request.Article;
 using GxPress.Result.Article;
 using Microsoft.Extensions.Options;
 using Datory;
+using Dapper;
 
 namespace GxPress.Repository.Implement
 {
@@ -23,9 +24,12 @@ namespace GxPress.Repository.Implement
         private readonly Repository<ArticleGroup> _articleGroupRepository;
         private readonly Repository<Entity.Analyze.Analyze> _analyzeRepository;
         private readonly IMapper _mapper;
-
+        private readonly string _connectionString;
+        private readonly string _databaseTypestr;
         public ArticleRepository(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<Article>(database);
@@ -49,6 +53,29 @@ namespace GxPress.Repository.Implement
             return await _repository.InsertAsync(process);
         }
 
+
+        public async Task<IEnumerable<ArticleResult>> GetArticleResults()
+        {
+            string sql = $@"SELECT Id,LastModifiedDate,Title,ImageUrls,Author,Source,AddDate,ReadCount,ContentJson FROM tede_article where IsChecked=1 order by IsTop desc,sort desc, LastModifiedDate desc limit 6";
+            var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var items = await connection.QueryAsync<Entity.Article.Article>(sql);
+            var result = items.Select(article =>
+               new ArticleResult
+               {
+                   Id = article.Id,
+                   Title = article.Title,
+                   ImageUrls = StringUtils.StringCollectionToStringList(article.ImageUrls),
+                   Summary = article.Summary,
+                   ArticleContent = StringUtils.JsonDeserialize<ArticleContent>(article.ContentJson),
+                   Author = article.Author,
+                   Source = article.Source,
+                   AddDate = article.AddDate,
+                   ReadCount = article.ReadCount,
+               }).ToList();
+            return result;
+        }
         public async Task<PagedList<ArticleResult>> GetUserListAsync(ArticleSearchRequest request, IEnumerable<BlacklistArticle> blacklistArticles)
         {
             var pagedList = new PagedList<ArticleResult>();
@@ -197,7 +224,7 @@ namespace GxPress.Repository.Implement
                     AddDate = article.AddDate,
                     Sort = article.Sort,
                     IsTop = article.IsTop,
-                    IsBlocks=article.IsBlocks
+                    IsBlocks = article.IsBlocks
                 });
 
             return pagedList;

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IArticleRepository.cs

@@ -29,5 +29,6 @@ namespace GxPress.Repository.Interface
         Task<int?> MaxAsync(string sort);
 
         Task<int> InsertAsync(Article article);
+        Task<IEnumerable<ArticleResult>> GetArticleResults();
     }
 }

+ 62 - 7
gx_api/GxPress/Service/GxPress.Service.Implement/Navigation/NavigationService.cs

@@ -11,7 +11,10 @@ using GxPress.Repository.Interface.SpecialLabel;
 using GxPress.Repository.Interface.SystemLabel;
 using GxPress.Repository.Interface.Teacher;
 using GxPress.Result.Navigation;
+using GxPress.Repository.Interface.Visit;
 using GxPress.Service.Interface.Navigation;
+using Datory;
+using GxPress.Entity.Article;
 
 namespace GxPress.Service.Implement.Navigation
 {
@@ -27,7 +30,15 @@ namespace GxPress.Service.Implement.Navigation
         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, IMiddleLableNexusRepository middleLableNexusRepository)
+        private readonly IArticleRepository articleRepository;
+        private readonly IVisitRepository visitRepository;
+
+        public NavigationService(INavigationRepository _repository, IMapper _mapper,
+        IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository,
+        IMediaRepository _mediaRepository, IMediaLableRepository _mediaLableRepository,
+        ISlideRepository slideRepository, ISpecialLabelRepository specialLabelRepository,
+        ITeacherRepository teacherRepository, IMiddleLableNexusRepository middleLableNexusRepository,
+        IArticleRepository articleRepository, IVisitRepository visitRepository)
         {
             this._navigationrepository = _repository;
             this._middleLableRepository = _middleLableRepository;
@@ -39,6 +50,8 @@ namespace GxPress.Service.Implement.Navigation
             this.specialLabelRepository = specialLabelRepository;
             this.teacherRepository = teacherRepository;
             this.middleLableNexusRepository = middleLableNexusRepository;
+            this.articleRepository = articleRepository;
+            this.visitRepository = visitRepository;
         }
         /// <summary>
         /// 获取导航栏数据
@@ -82,7 +95,7 @@ namespace GxPress.Service.Implement.Navigation
                             StyleType = item.StyleType,
                             ActionUrl = item.ActionUrl,
                             ControllerUrl = item.ControllerUrl,
-                            PageSize=item.PageSize,
+                            PageSize = item.PageSize,
                             IsPage = item.IsPage,
                             IsSkip = item.IsSkip,
                             LabelName = item.LabelName,
@@ -111,10 +124,52 @@ namespace GxPress.Service.Implement.Navigation
                             result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
                             continue;
                         }
-                        //获取媒体标签
-                        var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
-                        var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds,1,item.PageSize);
-                        navigationLabelMediaResult.MediaResults = medias.ToList();
+                        if (item.LabelName.Equals("推荐"))
+                        {
+                            var request = new List<Entity.BlacklistArticle>();
+                            var articleResult = await articleRepository.GetArticleResults();
+                            var articleResults = new List<Result.Media.NavigationMediaResult>();
+                            foreach (var article in articleResult)
+                            {
+                                var jsonContent = article.ArticleContent;
+                                var textContent = string.Empty;
+                                //新版json
+                                if (jsonContent != null && jsonContent.type.Count() > 0)
+                                {
+                                    foreach (var content in jsonContent.content)
+                                    {
+                                        foreach (var contentItem in content.content)
+                                        {
+                                            if (contentItem.type == "text")
+                                                textContent += contentItem.text;
+                                        }
+                                    }
+                                }
+                                var imageUrl = article.ImageUrls != null ? article.ImageUrls.FirstOrDefault() : "";
+                                articleResults.Add(
+                                    new Result.Media.NavigationMediaResult
+                                    {
+                                        Id = article.Id,
+                                        Title = article.Title,
+                                        ImageUrls = string.IsNullOrEmpty(imageUrl) ? StringUtils.AddDomain(imageUrl) : "",
+                                        Summary = textContent,
+                                        Author = article.Author,
+                                        CreatedDate = article.AddDate,
+                                        CollectCount = article.CollectCount,
+                                        ReadCount = article.ReadCount,
+                                        MediaType = AllTypeConst.Article.GetHashCode()
+                                    }
+                                );
+                            }
+                            navigationLabelMediaResult.MediaResults = articleResults;
+                        }
+                        else
+                        {
+                            //获取媒体标签
+                            var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
+                            var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds, 1, item.PageSize);
+                            navigationLabelMediaResult.MediaResults = medias.ToList();
+                        }
                         foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
                             itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);
                         result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
@@ -172,7 +227,7 @@ namespace GxPress.Service.Implement.Navigation
                 {
                     //获取特殊
                     navigationLabelMediaResult.IsSpecial = true;
-                    navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType,item.PageSize);
+                    navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType, item.PageSize);
                     foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults)
                         specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls);
                     result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);