lihao vor 4 Jahren
Ursprung
Commit
ccb80d52ce

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

@@ -221,5 +221,16 @@ namespace GxPress.Api.AppControllers
         {
             return await _middleService.GetLatelyNoteFolderAsync(_loginContext.AccountId);
         }
+
+        /// <summary>
+        /// 清空草稿箱
+        /// </summary>
+        /// <param name="typeValue">0 笔记 1 话题本</param>
+        /// <returns></returns>
+        [HttpPut("clear-draft")]
+        public async Task<bool> ClearDraftAsync([FromQuery] int typeValue)
+        {
+            return await _middleService.ClearDraftAsync(_loginContext.AccountId, typeValue);
+        }
     }
 }

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

@@ -133,5 +133,7 @@ namespace GxPress.Api.AppControllers
         {
             return await noteRepository.SetIsTopAsync(id);
         }
+
+        
     }
 }

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

@@ -232,5 +232,15 @@ namespace GxPress.Api.WebControllers
         {
             return await _middleService.GetLatelyNoteFolderAsync(_loginContext.AccountId);
         }
+        /// <summary>
+        /// 清空草稿箱
+        /// </summary>
+        /// <param name="typeValue">0 笔记 1 话题本</param>
+        /// <returns></returns>
+        [HttpPut("clear-draft")]
+        public async Task<bool> ClearDraftAsync([FromQuery] int typeValue)
+        {
+            return await _middleService.ClearDraftAsync(_loginContext.AccountId, typeValue);
+        }
     }
 }

+ 23 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/MiddleRepository.cs

@@ -15,6 +15,7 @@ using GxPress.Request.App.Middle;
 using System;
 using GxPress.Request.Inbox;
 using System.Linq;
+using GxPress.EnumConst;
 
 namespace GxPress.Repository.Implement
 {
@@ -322,5 +323,27 @@ namespace GxPress.Repository.Implement
             }
             return returnIds;
         }
+
+        /// <summary>
+        /// 清空草稿箱
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="typeValue"></param>
+        /// <returns></returns>
+        public async Task<bool> ClearDraftAsync(int userId, int typeValue)
+        {
+            //获取用户草稿
+            var sql = $"select Id from tede_note where UserId={userId} and IsDraft=1";
+            var databaseType = _databaseTypeStr.ToEnum<DatabaseType>(DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var noteIds = await connection.QueryAsync<int>(sql);
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.Middle.Middle.UserId), userId);
+            query.WhereIn(nameof(Entity.Middle.Middle.MiddleId), noteIds);
+            query.Where(nameof(Entity.Middle.Middle.FolderType), typeValue == 1 ? AllTypeConst.TopicNote.GetHashCode() : AllTypeConst.Note.GetHashCode());
+            query.Set(nameof(Entity.Middle.Middle.IsDelete), true);
+            return await UpdateAsync(query);
+        }
     }
 }

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

@@ -72,6 +72,7 @@ namespace GxPress.Repository.Implement.Note
             note.IsTop = !note.IsTop;
             return await _repository.UpdateAsync(note);
         }
+       
         /// <summary>
         /// 获取笔记分页
         /// </summary>

+ 11 - 4
gx_api/GxPress/Repository/GxPress.Repository.Interface/IMiddleRepository.cs

@@ -83,9 +83,9 @@ 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);
-          /// <summary>
+        Task<bool> ExistsAsync(SqlKata.Query query);
+        Task<int> GetSytemFolderAsync(int userId);
+        /// <summary>
         /// 排除不是文件夹的ID
         /// </summary>
         /// <param name="ids"></param>
@@ -98,6 +98,13 @@ namespace GxPress.Repository.Interface
         /// <param name="id"></param>
         /// <param name="ids"></param>
         /// <returns></returns>
-       Task<IEnumerable<int>> GetAllMiddleChildrenByParentIdAsync(List<int> ids,List<int> returnIds);
+        Task<IEnumerable<int>> GetAllMiddleChildrenByParentIdAsync(List<int> ids, List<int> returnIds);
+        /// <summary>
+        /// 清空草稿箱
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="typeValue"></param>
+        /// <returns></returns>
+        Task<bool> ClearDraftAsync(int userId, int typeValue);
     }
 }

+ 10 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Middle/MiddleService.cs

@@ -1014,5 +1014,15 @@ namespace GxPress.Service.Implement.Middle
             query.Where(nameof(Entity.Middle.Middle.IsDelete), true);
             return await _middleRepository.DeleteAsync(query);
         }
+        /// <summary>
+        /// 清空草稿箱
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="typeValue"></param>
+        /// <returns></returns>
+        public async Task<bool> ClearDraftAsync(int userId, int typeValue)
+        {
+            return await _middleRepository.ClearDraftAsync(userId, typeValue);
+        }
     }
 }

+ 5 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -594,8 +594,12 @@ namespace GxPress.Service.Implement.Note
             if (note.FolderId > 0)
             {
                 entity.FolderId = note.FolderId;
+                var query = Q.NewQuery();
+                query.Where(nameof(Entity.Middle.Middle.MiddleId), note.Id);
+                query.Where(nameof(Entity.Middle.Middle.FolderType), note.IsTopic ? AllTypeConst.TopicNote.GetHashCode() : AllTypeConst.Note.GetHashCode());
+                query.Where(nameof(Entity.Middle.Middle.UserId), entity.UserId);
                 //获取middle
-                var middle = await _middleRepository.GetMiddleAsync(Q.Where(nameof(Entity.Middle.Middle.MiddleId), note.Id).Where(nameof(Entity.Middle.Middle.FolderType), note.IsTopic ? AllTypeConst.TopicNote.GetHashCode() : AllTypeConst.Note.GetHashCode()).Where(nameof(Entity.Middle.Middle.UserId), entity.UserId));
+                var middle = await _middleRepository.GetMiddleAsync(query);
                 if (middle != null)
                 {
                     //修改middle

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

@@ -120,5 +120,12 @@ namespace GxPress.Service.Interface.Middle
         /// <param name="request"></param>
         /// <returns></returns>
         Task<List<MiddleSearchFolderResult>> GetLatelyTopicFolderAsync(int userId);
+        /// <summary>
+        /// 清空草稿箱
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="typeValue"></param>
+        /// <returns></returns>
+         Task<bool> ClearDraftAsync(int userId, int typeValue);
     }
 }