李昊 4 년 전
부모
커밋
7dec754230

+ 13 - 2
gx_api/GxPress/Api/GxPress.Api/AppControllers/TopicController.cs

@@ -59,7 +59,7 @@ namespace GxPress.Api.AppControllers
             request.UserId = _loginContext.AccountId;
             return await _topicService.InsertTopicAsync(request);
         }
-        
+
         /// <summary>
         /// 获取话题详情
         /// </summary>
@@ -159,7 +159,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add-group-user")]
-        public async Task<bool> InsertAsync([FromBody]TopicGroupUserInRequest request)
+        public async Task<bool> InsertAsync([FromBody] TopicGroupUserInRequest request)
         {
             return await _topicService.InsertTopicGroupUserAsync(request.UserIds.Distinct().ToList(), request.TopicGroupId);
         }
@@ -236,5 +236,16 @@ namespace GxPress.Api.AppControllers
             request.UserId = _loginContext.AccountId;
             return await _topicService.UpdateAsync(request);
         }
+        /// <summary>
+        ///最新 小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("page")]
+        public async Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _topicService.GetGroupTopicPageAsync(request);
+        }
     }
 }

+ 12 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebTopicController.cs

@@ -110,6 +110,17 @@ namespace GxPress.Api.WebControllers
             return await _topicService.GetTopicByGroupAsync(request);
         }
         /// <summary>
+        ///最新 小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("page")]
+        public async Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _topicService.GetGroupTopicPageAsync(request);
+        }
+        /// <summary>
         /// 获取用户话题分组
         /// </summary>
         /// <returns></returns>
@@ -247,6 +258,6 @@ namespace GxPress.Api.WebControllers
             request.UserId = _loginContext.AccountId;
             return await _topicService.UpdateAsync(request);
         }
-        
+
     }
 }

+ 4 - 3
gx_api/GxPress/Model/GxPress.Request/App/Topic/TopicPageSearchRequest.cs

@@ -8,7 +8,7 @@ namespace GxPress.Request.App.Topic
     /// <summary>
     /// 查询
     /// </summary>
-  public  class TopicPageSearchRequest: PageParameter
+    public class TopicPageSearchRequest : PageParameter
     {
         /// <summary>
         /// 用户Id
@@ -33,12 +33,13 @@ namespace GxPress.Request.App.Topic
         /// </summary>
         public TopicPageSearchRequest()
         {
-            TopicGroupIds=new List<int>();
+            TopicGroupIds = new List<int>();
         }
         /// <summary>
         /// 是否查询自己
         /// </summary>
         /// <value></value>
-        public bool IsAdmin{get;set;}
+        public bool IsAdmin { get; set; }
+       
     }
 }

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

@@ -95,6 +95,11 @@ namespace GxPress.Result.App.Topic
         /// <value></value>
         public string DepartmentName { get; set; }
         /// <summary>
+        /// 部门ID
+        /// </summary>
+        /// <value></value>
+        public int DepartmentId { get; set; }
+        /// <summary>
         /// 文件夹ID
         /// </summary>
         /// <value></value>

+ 155 - 10
gx_api/GxPress/Repository/GxPress.Repository.Implement/TopicRepository.cs

@@ -16,6 +16,7 @@ using GxPress.Entity.Topic;
 using GxPress.Result;
 using SqlKata;
 using GxPress.Result.Job;
+using GxPress.EnumConst;
 
 namespace GxPress.Repository.Implement
 {
@@ -118,6 +119,7 @@ namespace GxPress.Repository.Implement
         /// <returns></returns>
         public async Task<PagedList<TopicListPageResult>> FindTopicByGroupIdAsync(TopicDetailListRequest request)
         {
+            var topicConts = GxPress.EnumConst.AllTypeConst.Topic.GetHashCode();
             //用户收件人
             var resultData = new PagedList<TopicListPageResult>();
             var showKey = $@"SELECT a.*,(SELECT 
@@ -125,7 +127,7 @@ namespace GxPress.Repository.Implement
                 FROM
                     tede_analyze
                 WHERE
-                      TypeValue =1
+                      TypeValue ={topicConts}
                         AND SourceId = a.Id
                         AND AnalyzeType = 1) AS PraiseCount,
             (SELECT 
@@ -133,7 +135,7 @@ namespace GxPress.Repository.Implement
                 FROM
                     tede_analyze
                 WHERE
-                    UserId = {request.UserId} AND TypeValue = 1
+                    UserId = {request.UserId} AND TypeValue = {topicConts}
                         AND SourceId = a.Id
                         AND AnalyzeType = 1
                 LIMIT 0 , 1) AS IsPraise,
@@ -149,7 +151,7 @@ namespace GxPress.Repository.Implement
                 FROM
                     tede_analyze
                 WHERE
-                    UserId = {request.UserId} AND TypeValue = 1
+                    UserId = {request.UserId} AND TypeValue = {topicConts}
                         AND SourceId = a.Id
                         AND AnalyzeType = 4) AS RetransmissionCount,
             (SELECT 
@@ -157,7 +159,7 @@ namespace GxPress.Repository.Implement
                 FROM
                     tede_analyze
                 WHERE
-                    UserId = {request.UserId} AND TypeValue = 1
+                    UserId = {request.UserId} AND TypeValue = {topicConts}
                         AND SourceId = a.Id
                         AND AnalyzeType = 4
                 LIMIT 0 , 1) AS IsRetransmission,
@@ -166,7 +168,7 @@ namespace GxPress.Repository.Implement
                 FROM
                     tede_analyze
                 WHERE
-                    UserId = {request.UserId} AND TypeValue = 1
+                    UserId = {request.UserId} AND TypeValue = {topicConts}
                         AND SourceId = a.Id
                         AND AnalyzeType = 4
                 LIMIT 0 , 1) AS IsCollect,
@@ -175,7 +177,7 @@ namespace GxPress.Repository.Implement
                 FROM
                     tede_analyze
                 WHERE
-                    UserId = {request.UserId} AND TypeValue = 1
+                    UserId = {request.UserId} AND TypeValue = {topicConts}
                         AND SourceId = a.Id
                         AND AnalyzeType = 4) AS CollectCount,b.Name,b.AvatarUrl,c.Name FROM";
             var countSql = $"SELECT count(1) FROM tede_topic a inner join tede_user b on a.UserId=b.Id inner join tede_Department c on c.Id=b.DepartmentId where a.GroupId={request.GroupId}";
@@ -205,8 +207,151 @@ namespace GxPress.Repository.Implement
             resultData.Items = topicListPageResults;
             return resultData;
         }
-
-
+        /// <summary>
+        ///最新 小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request)
+        {
+            var topicConst = AllTypeConst.Topic.GetHashCode();
+            var result = new PagedList<TopicListPageResult>();
+            var sqlStr = "";
+            if (request.GroupId == 0)
+            {
+                sqlStr += $@" AND a.GroupId IN (SELECT 
+                                        GroupId
+                                    FROM
+                                        tede_group_user
+                                    WHERE
+                                        UserId ={request.UserId})";
+            }
+            if (request.GroupId > 0)
+            {
+                sqlStr += $@" AND a.GroupId IN (SELECT 
+                                        GroupId
+                                    FROM
+                                        tede_group_user
+                                    WHERE
+                                        UserId ={request.UserId} AND GroupId = {request.GroupId}  )";
+            }
+            if (!string.IsNullOrEmpty(request.Key))
+            {
+                sqlStr += $@"AND (a.Title LIKE '%{request.Key}%'
+                          OR a.Content LIKE '%{request.Key}%')";
+            }
+            string sql = $@"SELECT 
+                                a.Id,
+                                a.Title,
+                                a.UserId,
+                                a.ReadCount,
+                                a.CreatedDate,
+                                a.Content,
+                                a.GroupId,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        TypeValue ={topicConst} AND SourceId = a.Id
+                                            AND AnalyzeType = 1) AS PraiseCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId ={request.UserId} AND TypeValue = {topicConst}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 1
+                                    LIMIT 0 , 1) AS IsPraise,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_comment
+                                    WHERE
+                                        ArticleId = a.Id AND pid = 0
+                                            AND TypeValue = 1) AS CommentCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId ={request.UserId} AND TypeValue ={topicConst}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4) AS RetransmissionCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId ={request.UserId} AND TypeValue ={topicConst}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4
+                                    LIMIT 0 , 1) AS IsRetransmission,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId ={request.UserId} AND TypeValue = {topicConst}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4
+                                    LIMIT 0 , 1) AS IsCollect,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId ={request.UserId} AND TypeValue = {topicConst}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4) AS CollectCount,
+                                b.Name,
+                                c.Name,
+                                c.AvatarUrl,
+                                d.Id,
+                                d.Name
+                            FROM
+                                tede_topic a
+                                    INNER JOIN
+                                tede_group b ON a.GroupId = b.Id
+                                    INNER JOIN
+                                tede_user c ON c.Id = a.UserId
+                                  INNER JOIN
+                                tede_department d ON d.Id = c.DepartmentId
+                            WHERE
+                                a.GroupId > 0
+                                    {sqlStr}
+                            ORDER BY a.CreatedDate DESC";
+            string countSql = $@"SELECT 
+                                count(1)
+                            FROM
+                                tede_topic a
+                                    INNER JOIN
+                                tede_group b ON a.GroupId = b.Id
+                                    INNER JOIN
+                                tede_user c ON c.Id = a.UserId
+                            WHERE
+                                a.GroupId > 0
+                                   {sqlStr}
+                            ORDER BY a.CreatedDate DESC";
+            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, Department, TopicListPageResult>(sql,
+                          (topicListPageResult, group, user, department) =>
+                          {
+                              topicListPageResult.GroupName = group != null ? group.Name : "";
+                              topicListPageResult.DepartmentName = department != null ? department.Name : "";
+                              topicListPageResult.DepartmentId = department != null ? department.Id : 0;
+                              topicListPageResult.UserName = user != null ? user.Name : "";
+                              topicListPageResult.AvatarUrl = user != null ? StringUtils.AddDomainMin(user.AvatarUrl) : "";
+                              return topicListPageResult;
+                          }, new { page = (request.Page - 1) * request.PerPage, pageSize = request.PerPage }, splitOn: "Id,Name,Name,Id");
+            result.Total = await connection.ExecuteScalarAsync<int>(countSql);
+            return result;
+        }
 
         /// <summary>
         /// 根据小组ID获取话题数量
@@ -455,7 +600,7 @@ namespace GxPress.Repository.Implement
         }
         public string AssembleSql(TopicPageSearchRequest request)
         {
-            var topicTypeValue=GxPress.EnumConst.AllTypeConst.Topic.GetHashCode();
+            var topicTypeValue = GxPress.EnumConst.AllTypeConst.Note.GetHashCode();
             var sql = $@"SELECT 
                                 a.*,
                                 (SELECT 
@@ -522,7 +667,7 @@ namespace GxPress.Repository.Implement
                                                             INNER JOIN
                                                         tede_middle c ON c.MiddleId = a.Id
                                                     WHERE
-                                                        c.FolderType = 4 AND a.IsTopic = 1
+                                                        c.FolderType = {topicTypeValue} AND a.IsTopic = 1
                                                             AND (a.FolderId IN (SELECT 
                                                                 MiddleId
                                                             FROM

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/ITopicRepository.cs

@@ -52,5 +52,11 @@ namespace GxPress.Repository.Interface
         Task<PagedList<TopicListPageResult>> GetTopicPage(TopicPageSearchRequest request);
 
         Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request);
+        /// <summary>
+        ///最新 小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+      Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request);
     }
 }

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

@@ -93,7 +93,74 @@ namespace GxPress.Service.Implement.Topic
 
             return false;
         }
-
+        /// <summary>
+        ///最新 小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request)
+        {
+            var result = await _topicRepository.GetGroupTopicPageAsync(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;
+        }
         public async Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request)
         {
             var result = await _topicRepository.GetTopicByGroupAsync(request);

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

@@ -83,5 +83,11 @@ namespace GxPress.Service.Interface.Topic
         /// <returns></returns>
        Task<PagedList<TopicListPageResult>> GetTopicPageAsync(TopicPageSearchRequest request);
         Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request);
+         /// <summary>
+        ///最新 小组话题分页列表
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request);
     }
 }