李昊 vor 4 Jahren
Ursprung
Commit
aef6eb2e91

+ 9 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/MiddleController.cs

@@ -203,5 +203,14 @@ namespace GxPress.Api.AppControllers
         {
             return await _middleService.GetEnjoyDefaultAsync(_loginContext.AccountId, folderType);
         }
+        /// <summary>
+        /// 获取话题最近使用的文件夹
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("lately-folder")]
+        public async Task<List<MiddleSearchFolderResult>> GetLatelyNoteFolderAsync()
+        {
+            return await _middleService.GetLatelyNoteFolderAsync(_loginContext.AccountId);
+        }
     }
 }

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

@@ -84,8 +84,6 @@ namespace GxPress.Api.AppControllers
             var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
             return topicDetail;
         }
-
-
         /// <summary>
         /// app笔记话题分页列表
         /// </summary>

+ 9 - 0
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebMiddleController.cs

@@ -203,5 +203,14 @@ namespace GxPress.Api.WebControllers
         {
             return await _middleService.GetEnjoyDefaultAsync(_loginContext.AccountId, folderType);
         }
+        /// <summary>
+        /// 获取话题最近使用的文件夹
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("lately-folder")]
+        public async Task<List<MiddleSearchFolderResult>> GetLatelyNoteFolderAsync()
+        {
+            return await _middleService.GetLatelyNoteFolderAsync(_loginContext.AccountId);
+        }
     }
 }

+ 6 - 0
gx_api/GxPress/Model/GxPress.Entity/Middle/Middle.cs

@@ -153,5 +153,11 @@ namespace GxPress.Entity.Middle
         /// <value></value>
         [DataColumn]
         public bool IsRecall { get; set; }
+        /// <summary>
+        /// 是否系统默认
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public bool IsSystemDefault { get; set; }
     }
 }

+ 15 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/MiddleRepository.cs

@@ -50,6 +50,11 @@ namespace GxPress.Repository.Implement
             return await _repository.InsertAsync(middle);
         }
 
+        public async Task<bool> ExistsAsync(SqlKata.Query query)
+        {
+            return await _repository.ExistsAsync(query);
+        }
+
         /// <summary>
         /// 添加
         /// </summary>
@@ -246,7 +251,16 @@ namespace GxPress.Repository.Implement
         {
             return await _repository.GetAllAsync(query);
         }
-
+        public async Task<int> GetSytemFolderAsync(int userId)
+        {
+            var query = Q.NewQuery();
+            query.Select(nameof(Entity.Middle.Middle.Id));
+            query.Where(nameof(Entity.Middle.Middle.UserId), userId);
+            query.Where(nameof(Entity.Middle.Middle.AttributeValue), 2);
+            query.Where(nameof(Entity.Middle.Middle.IsSystemDefault), true);
+            query.Where(nameof(Entity.Middle.Middle.FolderType), GxPress.EnumConst.AllTypeConst.Note.GetHashCode());
+            return await _repository.GetAsync<int>(query);
+        }
         public async Task<IEnumerable<Middle>> FindAsync(InboxSearchRequest request)
         {
             var query = new SqlKata.Query();

+ 16 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Note/NoteRepository.cs

@@ -68,7 +68,7 @@ namespace GxPress.Repository.Implement.Note
         public async Task<bool> SetIsTopAsync(int noteId)
         {
             var note = await _repository.GetAsync(noteId);
-            note.IsTop =!note.IsTop;
+            note.IsTop = !note.IsTop;
             return await _repository.UpdateAsync(note);
         }
         /// <summary>
@@ -721,6 +721,21 @@ namespace GxPress.Repository.Implement.Note
             result.Total = await connection.ExecuteScalarAsync<int>(sql);
             return result;
         }
+        /// <summary>
+        /// 获取用户最近使用的文件夹
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<int>> GetLatelyFolderIdAsync(int userId)
+        {
+            var query = Q.NewQuery();
+            query.Select(nameof(Entity.Note.Note.FolderId));
+            query.Where(nameof(Entity.Note.Note.UserId), userId);
+            query.Where(nameof(Entity.Note.Note.IsTop), true);
+            query.Where(nameof(Entity.Note.Note.FolderId), ">", 0);
+            query.OrderByDesc(nameof(Entity.Note.Note.CreatedDate));
+            return await _repository.GetAllAsync<int>(query);
+        }
     }
 }
 

+ 10 - 3
gx_api/GxPress/Repository/GxPress.Repository.Implement/Topic/TopicGroupRepository.cs

@@ -69,8 +69,15 @@ namespace GxPress.Repository.Implement.Topic
         /// <returns></returns>
         public async Task<IEnumerable<TopicGroup>> GetTopicGroupsAsync(int userId)
         {
-            return await _repository.GetAllAsync(Q.Where(nameof(TopicGroup.UserId), userId)
-                .OrderByDesc(nameof(TopicGroup.Sort)));
+            var result = new List<TopicGroup>() {
+                new TopicGroup {
+                Id=-1,Name="我的"
+            }, new TopicGroup { Id=-2,Name="同单位"},
+            new TopicGroup {Id=-3,Name="推荐" } ,
+            new TopicGroup {Id=0,Name="全部" }};
+            result.AddRange(await _repository.GetAllAsync(Q.Where(nameof(TopicGroup.UserId), userId)
+                .OrderByDesc(nameof(TopicGroup.Sort))));
+            return result;
         }
         /// <summary>
         /// 修改分组名称
@@ -124,7 +131,7 @@ namespace GxPress.Repository.Implement.Topic
 
         public async Task<bool> UpdateAsync(Query query)
         {
-            return await _repository.UpdateAsync(query)>0;
+            return await _repository.UpdateAsync(query) > 0;
         }
     }
 }

+ 2 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IMiddleRepository.cs

@@ -83,5 +83,7 @@ namespace GxPress.Repository.Interface
         Task<IEnumerable<Middle>> GetMiddleChildrenAsync(int id);
 
         Task<IEnumerable<Middle>> FindAsync(InboxSearchRequest request);
+         Task<bool> ExistsAsync(SqlKata.Query query);
+         Task<int> GetSytemFolderAsync(int userId);
     }
 }

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Note/INoteRepository.cs

@@ -69,5 +69,11 @@ namespace GxPress.Repository.Interface.Note
         /// <param name="noteId"></param>
         /// <returns></returns>
         Task<bool> SetIsTopAsync(int noteId);
+        /// <summary>
+        /// 获取用户最近使用的文件夹
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        Task<IEnumerable<int>> GetLatelyFolderIdAsync(int userId);
     }
 }

+ 51 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Middle/MiddleService.cs

@@ -664,11 +664,13 @@ namespace GxPress.Service.Implement.Middle
                 .Where(nameof(Entity.Middle.Middle.AttributeValue), 2)
                 .Where(nameof(Entity.Middle.Middle.FolderType), request.TypeId)
                 .Where(nameof(Entity.Middle.Middle.UserId), request.UserId)
-                .Where(nameof(Entity.Middle.Middle.IsDelete), false).WhereNotIn(nameof(Entity.Middle.Middle.Id), request.FolderIds).WhereIn(nameof(Entity.Middle.Middle.RoleId), new List<int>() { 1, 3 });
+                .Where(nameof(Entity.Middle.Middle.IsDelete), false);
+            if (request.FolderIds.Count > 0)
+                query.WhereNotIn(nameof(Entity.Middle.Middle.Id), request.FolderIds);
+            query.WhereIn(nameof(Entity.Middle.Middle.RoleId), new List<int>() { 1, 3 });
             if (!string.IsNullOrWhiteSpace(request.KeyWord))
                 query.Where(nameof(Entity.Middle.Middle.FolderName), request.KeyWord);
-
-            var middles = await _middleRepository.FindAsync(query.OrderByDesc(
+            var middles = await _middleRepository.FindAsync(query.OrderByDesc(nameof(Entity.Middle.Middle.IsSystemDefault),
                 nameof(Entity.Middle.Middle.AttributeValue), nameof(Entity.Middle.Middle.IsTop),
                 nameof(Entity.Middle.Middle.CreatedDate)));
             List<MiddleSearchFolderResult> result = new List<MiddleSearchFolderResult>();
@@ -698,6 +700,52 @@ namespace GxPress.Service.Implement.Middle
 
             return result;
         }
+        /// <summary>
+        /// 获取话题最近使用的文件夹
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<List<MiddleSearchFolderResult>> GetLatelyNoteFolderAsync(int userId)
+        {
+            //获取用户最近发布的话题
+            var folderIds = await _noteRepository.GetLatelyFolderIdAsync(userId);
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.Middle.Middle.AttributeValue), 2)
+                .Where(nameof(Entity.Middle.Middle.FolderType), AllTypeConst.Note.GetHashCode())
+                .Where(nameof(Entity.Middle.Middle.UserId), userId)
+                .Where(nameof(Entity.Middle.Middle.IsDelete), false)
+                .WhereIn(nameof(Entity.Middle.Middle.Id), folderIds);
+            query.WhereIn(nameof(Entity.Middle.Middle.RoleId), new List<int>() { 1, 3 });
+            var middles = await _middleRepository.FindAsync(query.OrderByDesc(nameof(Entity.Middle.Middle.IsSystemDefault),
+                nameof(Entity.Middle.Middle.AttributeValue), nameof(Entity.Middle.Middle.IsTop),
+                nameof(Entity.Middle.Middle.CreatedDate)));
+            List<MiddleSearchFolderResult> result = new List<MiddleSearchFolderResult>();
+            foreach (var item in middles)
+            {
+                MiddleSearchFolderResult middleSearchFolderResult = new MiddleSearchFolderResult
+                {
+                    Name = item.FolderName,
+                    Id = item.Id,
+                    IsDisable = false,
+                    RoleId = item.RoleId,
+                    IsFolder = await _middleRepository.IsFolderAsync(item.Id),
+                    IsTop = item.IsTop
+                };
+                if (item.RoleId == 3)
+                {
+                    var sourceId = item.Id;
+                    if (item.ParentId != 0)
+                        sourceId = item.MiddleSonId;
+                    var userMiddles = await _userMiddleService.FindUserMiddlesAsync(item.FolderType, sourceId);
+                    // var folderUsers = await _folderUserRepository.GetAllAsync(Q.Where(nameof(FolderUser.MiddleId), item.Id).OrderByDesc(nameof(FolderUser.CreatedDate)).Take(10));
+                    middleSearchFolderResult.EnjoyUser = StringUtils.ObjectCollectionToString(userMiddles.Select(n => n.SourceName), "、");
+                    //middleSearchFolderResult.EnjoyUser = StringUtils.ObjectCollectionToString(folderUsers.Select(n => n.UserName), "、");
+                }
+                result.Add(middleSearchFolderResult);
+            }
+
+            return result;
+        }
         /// <summary> =-
         /// 删除全部
         /// </summary>

+ 17 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -98,9 +98,24 @@ namespace GxPress.Service.Implement.Note
                     var noteContent = JsonConvert.DeserializeObject<List<ContentJsonData>>(request.Content);
                     foreach (var item in noteContent)
                         item.File = StringUtils.RemoveDomain(item.File);
+                    //获取公开
+                    if (request.FolderId == 0 && request.IsTopic)
+                        request.FolderId = await _middleRepository.GetSytemFolderAsync(request.UserId);
                     //添加笔记
                     var note = new Entity.Note.Note
-                    { Title = request.Title, Content = JsonConvert.SerializeObject(noteContent), HtmlContent = request.HtmlContent, UserId = request.UserId, IsDelete = false, IsTopic = request.IsTopic, FolderId = request.FolderId, MediaId = request.MediaId, MediaType = request.MediaType, CatalogId = request.CatalogId, ChapterId = request.ChapterId };
+                    {
+                        Title = request.Title,
+                        Content = JsonConvert.SerializeObject(noteContent),
+                        HtmlContent = request.HtmlContent,
+                        UserId = request.UserId,
+                        IsDelete = false,
+                        IsTopic = request.IsTopic,
+                        FolderId = request.FolderId,
+                        MediaId = request.MediaId,
+                        MediaType = request.MediaType,
+                        CatalogId = request.CatalogId,
+                        ChapterId = request.ChapterId
+                    };
                     var noteId = await _noteRepository.InsertAsync(note);
                     //添加中间件
                     var middleInsertTypes = new MiddleInsertTypeRequest
@@ -575,7 +590,7 @@ namespace GxPress.Service.Implement.Note
             {
                 if (string.IsNullOrEmpty(item.FolderName))
                     item.FolderName = "根目录";
-               // item.MiddleId = item.Id;
+                // item.MiddleId = item.Id;
                 //是否摘录
                 if (item.MediaId > 0)
                 {

+ 5 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Notice/NoticeService.cs

@@ -337,15 +337,17 @@ namespace GxPress.Service.Implement.Notice
             var result = await _noticeRepository.GetNoticeListPageAsync(request);
             foreach (var item in result.Items)
             {
-                if (item.TypeValue >= 15)
+                var typeValueIds = new List<int>{AllTypeConst.MyChecked.GetHashCode()
+                ,AllTypeConst.MyCc.GetHashCode(),AllTypeConst.MySubmitted.GetHashCode()};
+                if (typeValueIds.Contains(item.TypeValue))
                 {
                     if (item.TypeValue == AllTypeConst.MySubmitted.GetHashCode())
                         item.IsAdmin = true;
                     item.TodoId = item.SonId;
                     item.MiddleId = item.SourceId;
                     //item.UserName = item.SendUserName;
-                    item.ReadCount = item.CheckedCount+1;
-                    item.AllCount = item.UCheckedCount+1;
+                    item.ReadCount = item.CheckedCount + 1;
+                    item.AllCount = item.UCheckedCount + 1;
                     item.EnjoyUser = item.FlowUserName;
                     //我发起的
                     if (item.TypeValue == AllTypeConst.MySubmitted.GetHashCode())

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

@@ -259,7 +259,7 @@ namespace GxPress.Service.Implement.Topic
                     var firstContent = string.Empty;
                     foreach (var jsonData in contentJsonData)
                     {
-                        if (jsonData.TypeValue ==AllTypeConst.Text.GetHashCode() && forCount == 1)
+                        if (jsonData.TypeValue == AllTypeConst.Text.GetHashCode() && forCount == 1)
                             //文本
                             firstContent = jsonData.Text;
                         else if (jsonData.TypeValue == AllTypeConst.Text.GetHashCode() && forCount > 1)
@@ -290,6 +290,27 @@ namespace GxPress.Service.Implement.Topic
                 if (item.Data == null || item.Data.Count == 0)
                     item.Data = new List<ContentJsonData>();
             }
+            //查询系统默认的公开文件夹是否存在
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.Middle.Middle.UserId), request.UserId);
+            query.Where(nameof(Entity.Middle.Middle.AttributeValue), 2);
+            query.Where(nameof(Entity.Middle.Middle.FolderType), AllTypeConst.Note.GetHashCode());
+            query.Where(nameof(Entity.Middle.Middle.IsSystemDefault), true);
+            var isExists = await _middleRepository.ExistsAsync(query);
+            if (!isExists)
+            {
+                //生成系统默认的公开文件夹
+                await _middleRepository.InsertAsync(new Entity.Middle.Middle
+                {
+                    Id = 0,
+                    FolderName = "公开",
+                    AttributeValue = 2,
+                    UserId = request.UserId,
+                    FolderType = AllTypeConst.Note.GetHashCode(),
+                    RoleId = 1,
+                    IsSystemDefault = true
+                });
+            }
             return result;
         }
         /// <summary>

+ 6 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Middle/IMiddleService.cs

@@ -102,5 +102,11 @@ namespace GxPress.Service.Interface.Middle
         /// <param name="userId"></param>
         /// <returns></returns>
         Task<bool> DeleteAllAsync(int folderType, int userId);
+           /// <summary>
+        /// 获取话题最近使用的文件夹
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<List<MiddleSearchFolderResult>> GetLatelyNoteFolderAsync(int userId);
     }
 }