李昊 4 年之前
父节点
当前提交
c4b91bbcbb

+ 11 - 0
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebTopicController.cs

@@ -97,7 +97,18 @@ namespace GxPress.Api.WebControllers
             request.UserId = _loginContext.AccountId;
             return await _topicService.GetTopicPageAsync(request);
         }
+        /// <summary>
+        /// Web小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
 
+        [HttpPost("user-list-page")]
+        public async Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _topicService.GetTopicByGroupAsync(request);
+        }
         /// <summary>
         /// 获取用户话题分组
         /// </summary>

+ 10 - 0
gx_api/GxPress/Model/GxPress.Result/App/Topic/TopicListPageResult.cs

@@ -116,6 +116,16 @@ namespace GxPress.Result.App.Topic
         /// </summary>
         /// <value></value>
         public string FolderName { get; set; }
+        /// <summary>
+        /// 小组ID
+        /// </summary>
+        /// <value></value>
+        public int GroupId { get; set; }
+        /// <summary>
+        /// 小组名称
+        /// </summary>
+        /// <value></value>
+        public string GroupName { get; set; }
     }
     /// <summary>
     /// 话题共享文件夹

+ 117 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/TopicRepository.cs

@@ -296,6 +296,123 @@ namespace GxPress.Repository.Implement
             connection.Dispose();
             return result;
         }
+
+        public async Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request)
+        {
+            var sql = $@"SELECT 
+                                a.*,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        TypeValue = 3 AND SourceId = a.Id
+                                            AND AnalyzeType = 1) AS PraiseCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = 3
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 1
+                                    LIMIT 0 , 1) AS IsPraise,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_comment
+                                    WHERE
+                                        ArticleId = a.Id AND TypeValue = 3
+                                            AND Pid = 0) AS CommentCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = 3
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4) AS RetransmissionCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = 3
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4
+                                    LIMIT 0 , 1) AS IsRetransmission,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = 3
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 3
+                                    LIMIT 0 , 1) AS IsCollect,
+                                b.Id as GroupId,
+                                b.Name,
+                                c.Name,
+                                c.AvatarUrl
+                            FROM
+                                tede_topic a
+                                    INNER JOIN
+                                tede_group b ON a.GroupId = b.id
+                                    INNER JOIN
+                                tede_user c ON a.UserId = c.Id
+                            WHERE
+                                a.GroupId > 0
+                                    AND b.Id IN (SELECT 
+                                        GroupId
+                                    FROM
+                                        tede_group_user
+                                    WHERE
+                                        UserId = {request.UserId})";
+            if (!string.IsNullOrWhiteSpace(request.Keyword))
+            {
+                sql += $@"  AND (c.Name LIKE '%{request.Keyword}%'
+                                    OR a.Title LIKE '%{request.Keyword}%'
+                                    OR a.HtmlContent LIKE '%{request.Keyword}%')";
+            }
+            sql += $@"  ORDER BY a.CreatedDate DESC
+                        LIMIT {(request.Page - 1) * request.PerPage} , {request.PerPage}";
+
+            var result = new PagedList<TopicListPageResult>();
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            result.Items = await connection.QueryAsync<TopicListPageResult, Entity.Group, User, TopicListPageResult>(sql, (topicListPageResult, group, user) =>
+               {
+                   topicListPageResult.AvatarUrl = user != null ? StringUtils.AddDomainMin(user.AvatarUrl) : "";
+                   topicListPageResult.GroupName = group != null ? group.Name : "";
+                   topicListPageResult.UserName = user != null ? user.Name : "";
+                   return topicListPageResult;
+               }, splitOn: "Id,GroupId,Name");
+            sql = $@"SELECT 
+                                count(1)
+                            FROM
+                                tede_topic a
+                                    INNER JOIN
+                                tede_group b ON a.GroupId = b.id
+                                    INNER JOIN
+                                tede_user c ON a.UserId = c.Id
+                            WHERE
+                                a.GroupId > 0
+                                    AND b.Id IN (SELECT 
+                                        GroupId
+                                    FROM
+                                        tede_group_user
+                                    WHERE
+                                        UserId = {request.UserId})";
+            if (!string.IsNullOrWhiteSpace(request.Keyword))
+            {
+                sql += $@"  AND (c.Name LIKE '%{request.Keyword}%'
+                                    OR a.Title LIKE '%{request.Keyword}%'
+                                    OR a.HtmlContent LIKE '%{request.Keyword}%')";
+            }
+            result.Total = await connection.ExecuteScalarAsync<int>(sql);
+            return result;
+        }
         public string AssembleSql(TopicPageSearchRequest request)
         {
             var sql = $@"SELECT 

+ 3 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/ITopicRepository.cs

@@ -43,12 +43,14 @@ namespace GxPress.Repository.Interface
         Task<bool> DeleteAsync(int id);
 
         Task<bool> UpdateAsync(Entity.Topic.Topic topic);
-         /// <summary>
+        /// <summary>
         /// 执行话题
         /// </summary>
         /// <returns></returns>
         Task<List<JobTopicResult>> ExecuteTopic();
 
         Task<PagedList<TopicListPageResult>> GetTopicPage(TopicPageSearchRequest request);
+
+        Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request);
     }
 }

+ 63 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Topic/TopicService.cs

@@ -94,7 +94,69 @@ namespace GxPress.Service.Implement.Topic
             return false;
         }
 
-
+        public async Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request)
+        {
+            var result = await _topicRepository.GetTopicByGroupAsync(request);
+            //获取数量
+            // result.Total = 10;
+            foreach (var item in result.Items)
+            {
+                if (string.IsNullOrWhiteSpace(item.UserName))
+                {
+                    item.Content = "[]";
+                    item.Data = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
+                    item.Content = "";
+                    continue;
+                }
+                if (string.IsNullOrWhiteSpace(item.Content))
+                    item.Content = "[]";
+                var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
+                foreach (var contentJsonDataItem in contentJsonData)
+                    contentJsonDataItem.File = StringUtils.AddDomain(contentJsonDataItem.File);
+                if (contentJsonData.Count == 0)
+                    item.DataType = 1;
+                item.Content = "";
+                if (contentJsonData.Count > 0)
+                {
+                    var imgData = new List<ContentJsonData>();
+                    var FileData = new List<ContentJsonData>();
+                    var forCount = 1;
+                    var firstContent = string.Empty;
+                    foreach (var jsonData in contentJsonData)
+                    {
+                        if (jsonData.Type == OldTextEditorTypeConst.Text.GetHashCode() && forCount == 1)
+                            //文本
+                            firstContent = jsonData.Text;
+                        else if (jsonData.Type == OldTextEditorTypeConst.Text.GetHashCode() && forCount > 1)
+                            //文本
+                            continue;
+                        //图片
+                        else if (jsonData.Type == OldTextEditorTypeConst.Image.GetHashCode() && FileData.Count == 0)
+                        {
+                            if (imgData.Count > 9)
+                                break;
+                            imgData.Add(jsonData);
+                        }
+                        //附件
+                        else
+                        {
+                            FileData.Add(jsonData);
+                            break;
+                        }
+                        forCount++;
+                    }
+                    item.Content = string.IsNullOrWhiteSpace(firstContent) ? "" : firstContent;
+                    if (imgData.Count > 0) { item.DataType = 2; item.Data = imgData; }
+                    else if (FileData.Count > 0) { item.DataType = 3; item.Data = FileData; }
+                    else item.DataType = 1;
+                    var contType = new List<int> { OldTextEditorTypeConst.Text.GetHashCode(), OldTextEditorTypeConst.Image.GetHashCode() };
+                    item.FileCount = contentJsonData.Count(n => !contType.Contains(n.Type));
+                }
+                if (item.Data == null || item.Data.Count == 0)
+                    item.Data = new List<ContentJsonData>();
+            }
+            return result;
+        }
         /// <summary>
         /// 获取话题列表
         /// </summary>

+ 1 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Topic/ITopicService.cs

@@ -82,5 +82,6 @@ namespace GxPress.Service.Interface.Topic
         /// <param name="request"></param>
         /// <returns></returns>
        Task<PagedList<TopicListPageResult>> GetTopicPageAsync(TopicPageSearchRequest request);
+        Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request);
     }
 }