李昊 4 lat temu
rodzic
commit
62793a1c7a

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

@@ -14,6 +14,7 @@ using Datory;
 using GxPress.Request.App.Middle;
 using System;
 using GxPress.Request.Inbox;
+using System.Linq;
 
 namespace GxPress.Repository.Implement
 {
@@ -296,5 +297,29 @@ namespace GxPress.Repository.Implement
             query.Where(nameof(Entity.Middle.Middle.AttributeValue), 2);
             return await _repository.GetAllAsync<int>(query);
         }
+        /// <summary>
+        /// 递归获取父级下面的所有子集
+        /// </summary>
+        /// <param name="id"></param>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<int>> GetAllMiddleChildrenByParentIdAsync(List<int> ids)
+        {
+            var middles = await _repository.GetAllAsync(Q.WhereIn(nameof(Entity.Middle.Middle.Id), ids));
+            if (middles == null || middles.Count == 0)
+                return ids;
+            foreach (var item in middles)
+            {
+                middles = await _repository.GetAllAsync(Q.Where(nameof(Entity.Middle.Middle.ParentId), item.Id));
+                if (middles == null || middles.Count == 0)
+                    continue;
+                ids.AddRange(middles.Select(n => n.Id).ToList());
+                foreach (var middle in middles)
+                {
+                    await GetAllMiddleChildrenByParentIdAsync(ids);
+                }
+            }
+            return ids;
+        }
     }
 }

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

@@ -91,5 +91,13 @@ namespace GxPress.Repository.Interface
         /// <param name="ids"></param>
         /// <returns></returns>
         Task<IEnumerable<int>> GetMiddleIsFolderAsync(IEnumerable<int> ids);
+
+        /// <summary>
+        /// 递归获取父级下面的所有子集
+        /// </summary>
+        /// <param name="id"></param>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+       Task<IEnumerable<int>> GetAllMiddleChildrenByParentIdAsync(List<int> ids);
     }
 }

+ 68 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Middle/MiddleService.cs

@@ -21,6 +21,8 @@ using GxPress.Repository.Interface.RecordFolder;
 using GxPress.Service.Interface.Analyze;
 using GxPress.Request.App.Analyze;
 using GxPress.EnumConst;
+using System.Transactions;
+using GxPress.Request.UserMiddle;
 
 namespace GxPress.Service.Implement.Middle
 {
@@ -422,13 +424,77 @@ namespace GxPress.Service.Implement.Middle
         {
             return await _middleRepository.RecoverDeleteAsync(request);
         }
-          
+        /// <summary>
+        /// 移动到
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
         public async Task<bool> SetMove(MiddleMoveRequest request)
         {
             if (request.ParentId == 0 && request.TypeId == -AllTypeConst.Note.GetHashCode())
                 request.Ids = await _middleRepository.GetMiddleIsFolderAsync(request.Ids);
-            return await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.ParentId), request.ParentId).WhereIn(nameof(Entity.Middle.Middle.Id), request.Ids));
+            try
+            {
+                using (var transactionScope = new TransactionScope())
+                {
+                    var middle = await _middleRepository.GetMiddleAsync(Q.Where(nameof(Entity.Middle.Middle.Id), request.ParentId));
+                    if (request.ParentId > 0 && middle != null)
+                    {
+                        //获取父级子集集合
+                        var ids = await _middleRepository.GetAllMiddleChildrenByParentIdAsync(request.Ids.ToList());
+                        //修改
+                        await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.ParentId), request.ParentId).Set(nameof(Entity.Middle.Middle.RoleId), middle.RoleId).WhereIn(nameof(Entity.Middle.Middle.Id), request.Ids));
+                        //修改共享
+                        await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.MiddleSonId), middle.MiddleSonId).WhereIn(nameof(Entity.Middle.Middle.Id), ids));
+                    }
+                    if (request.ParentId == 0)
+                    {
+                        middle = await _middleRepository.GetMiddleAsync(Q.Where(nameof(Entity.Middle.Middle.Id), request.Ids.First()));
+                        if (middle.RoleId == 3)
+                        {
+                            /// <summary>
+                            /// 获取共享人员
+                            /// </summary>
+                            /// <returns></returns>
+                            var userMiddles = await _userMiddleService.FindUserMiddlesAsync(middle.FolderType, middle.MiddleSonId);
+                            foreach (var id in request.Ids)
+                            {
+                                var userMiddleInRequest = new List<UserMiddleInRequest>();
+                                foreach (var userMiddle in userMiddles)
+                                {
+                                    userMiddleInRequest.Add(new UserMiddleInRequest
+                                    {
+                                        MiddleType = userMiddle.MiddleType,
+                                        SourceType = userMiddle.SourceType,
+                                        SourceId = userMiddle.SourceId,
+                                        SourceName = userMiddle.SourceName,
+                                        DataSourceId = userMiddle.DataSourceId,
+                                        SourceTypeValue = userMiddle.SourceTypeValue
+                                    });
+                                }
+                                //添加共享人员
+                                await _userMiddleService.AddUserMiddleAsync(userMiddleInRequest);
+                            }
+
+                        }
+                        //修改
+                        await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.ParentId), request.ParentId).WhereIn(nameof(Entity.Middle.Middle.Id), request.Ids));
+                        foreach (var item in request.Ids)
+                        {
+                            var ids = await _middleRepository.GetAllMiddleChildrenByParentIdAsync(new List<int> { item });
+                            await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.MiddleSonId), item).WhereIn(nameof(Entity.Middle.Middle.Id), ids));
+                        }
+                    }
+                    transactionScope.Complete();
+                }
+            }
+            catch
+            {
+                return false;
+            }
+            return true;
         }
+
         /// <summary>
         /// 恢复全部
         /// </summary>