lihao 4 years ago
parent
commit
e559848434

+ 6 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/CollectionController.cs

@@ -86,5 +86,11 @@ namespace GxPress.Api.AppControllers
         {
             return await collectionRepository.SetTopAsync(id);
         }
+        [HttpGet("update-result")]
+        [AllowAnonymous]
+        public async Task<bool> UpdateResultJosnAsync()
+        {
+            return await _collectionService.UpdateResultJosnAsync();
+        }
     }
 }

+ 5 - 0
gx_api/GxPress/Model/GxPress.Result/App/Collection/CollectionListPageResult.cs

@@ -142,5 +142,10 @@ namespace GxPress.Result.App.Collection
         /// </summary>
         /// <value></value>
         public bool IsTop { get; set; }
+        /// <summary>
+        /// 收藏结果
+        /// </summary>
+        /// <value></value>
+        public string ResultJson { get; set; }
     }
 }

+ 6 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Collection/CollectionRepository.cs

@@ -59,6 +59,11 @@ namespace GxPress.Repository.Implement.Collection
             collction.IsTop = !collction.IsTop;
             return await _repository.UpdateAsync(collction);
         }
+
+        public async Task<bool> UpdateAsync(Entity.Collection collection)
+        {
+            return await _repository.UpdateAsync(collection);
+        }
         /// <summary>
         /// 查询结果
         /// </summary>
@@ -219,7 +224,7 @@ namespace GxPress.Repository.Implement.Collection
             query.OrderByDesc("a.LastModifiedDate");
             query.ForPage(request.Page, request.PerPage);
             query.Select(
-                "tede_collection.{UserId,Title,CollectionType,CollectionDataId,SourceUserId}",
+                "tede_collection.{UserId,Title,CollectionType,CollectionDataId,SourceUserId,ResultJson}",
                 "a.{IsTop,Id,MiddleId,ParentId as FolderId}"
             );
             query.Select(folderNameQuery, "FolderName");

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Collection/ICollectionRepository.cs

@@ -58,6 +58,7 @@ namespace GxPress.Repository.Interface.Collection
         /// <param name="collection"></param>
         /// <returns></returns>
         Task<bool> SetTopAsync(int id);
+        Task<bool> UpdateAsync(Entity.Collection collection);
     }
 
 }

+ 59 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Collection/CollectionService.cs

@@ -96,6 +96,11 @@ namespace GxPress.Service.Implement.Collection
                 EndCollectionType = request.CollectionType,
             };
             var resultJson = await StructCollectionData(request.CollectionDataId, request.CollectionType, request.SourceUserId);
+            if (resultJson.ArticleImgUrl != null && resultJson.ArticleImgUrl.Count > 0)
+            {
+                for (int i = 0; i < resultJson.ArticleImgUrl.Count; i++)
+                    resultJson.ArticleImgUrl[i] = StringUtils.RemoveDomain(resultJson.ArticleImgUrl[i]);
+            }
             collection.ResultJson = JsonConvert.SerializeObject(resultJson);
             var query = new SqlKata.Query();
             query.Where(nameof(Entity.Collection.UserId), request.UserId)
@@ -277,7 +282,23 @@ namespace GxPress.Service.Implement.Collection
             {
                 if (string.IsNullOrEmpty(item.FolderName))
                     item.FolderName = "根目录";
-                item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
+                //item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
+                item.Data = JsonConvert.DeserializeObject<CollectionContentJsonData>(item.ResultJson);
+                if (item.Data != null)
+                {
+                    item.Data.File = StringUtils.RemoveDomain(item.Data.File);
+                    item.Data.MinFile = StringUtils.RemoveDomain(item.Data.MinFile);
+                    item.Data.File = StringUtils.AddDomain(item.Data.File);
+                    item.Data.MinFile = StringUtils.AddDomain(item.Data.MinFile);
+                }
+                if (item.Data.ArticleImgUrl != null && item.Data.ArticleImgUrl.Count > 0)
+                {
+                    for (int i = 0; i < item.Data.ArticleImgUrl.Count; i++)
+                    {
+                        item.Data.ArticleImgUrl[i] = StringUtils.RemoveDomain(item.Data.ArticleImgUrl[i]);
+                        item.Data.ArticleImgUrl[i] = StringUtils.AddDomain(item.Data.ArticleImgUrl[i]);
+                    }
+                }
                 if (string.IsNullOrWhiteSpace(item.Title))
                 {
                     item.Title = "";
@@ -344,7 +365,23 @@ namespace GxPress.Service.Implement.Collection
             }
             foreach (var item in result.Items)
             {
-                item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
+                //item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
+                item.Data = JsonConvert.DeserializeObject<CollectionContentJsonData>(item.ResultJson);
+                if (item.Data != null)
+                {
+                    item.Data.File = StringUtils.RemoveDomain(item.Data.File);
+                    item.Data.MinFile = StringUtils.RemoveDomain(item.Data.MinFile);
+                    item.Data.File = StringUtils.AddDomain(item.Data.File);
+                    item.Data.MinFile = StringUtils.AddDomain(item.Data.MinFile);
+                }
+                if (item.Data.ArticleImgUrl != null && item.Data.ArticleImgUrl.Count > 0)
+                {
+                    for (int i = 0; i < item.Data.ArticleImgUrl.Count; i++)
+                    {
+                        item.Data.ArticleImgUrl[i] = StringUtils.RemoveDomain(item.Data.ArticleImgUrl[i]);
+                        item.Data.ArticleImgUrl[i] = StringUtils.AddDomain(item.Data.ArticleImgUrl[i]);
+                    }
+                }
                 if (string.IsNullOrWhiteSpace(item.Title))
                 {
                     item.Title = "";
@@ -782,5 +819,25 @@ namespace GxPress.Service.Implement.Collection
             }
             return "";
         }
+
+        public async Task<bool> UpdateResultJosnAsync()
+        {
+            var query = Q.NewQuery();
+            query.WhereNull(nameof(Entity.Collection.ResultJson));
+            query.Limit(100);
+            var result = await _collectionRepository.GetAllAsync(query);
+            foreach (var item in result)
+            {
+                var jsonResult = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
+                if (jsonResult.ArticleImgUrl != null && jsonResult.ArticleImgUrl.Count > 0)
+                {
+                    for (int i = 0; i < jsonResult.ArticleImgUrl.Count; i++)
+                        jsonResult.ArticleImgUrl[i] = StringUtils.RemoveDomain(jsonResult.ArticleImgUrl[i]);
+                }
+                item.ResultJson = JsonConvert.SerializeObject(jsonResult);
+                await _collectionRepository.UpdateAsync(item);
+            }
+            return true;
+        }
     }
 }

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Collection/ICollectionService.cs

@@ -17,11 +17,12 @@ namespace GxPress.Service.Interface.Collection
         /// <param name="id"></param>
         /// <returns></returns>
         Task<CollectionResult> GetCollectionDetailAsync(int id);
-          /// <summary>
+        /// <summary>
         /// 收藏无文件夹分页列表
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request);
+        Task<bool> UpdateResultJosnAsync();
     }
 }