李昊 4 years ago
parent
commit
fa416bdbee

+ 18 - 2
GxPress/Repository/GxPress.Repository.Implement/WorkProcess/ProcessRepository.cs

@@ -15,6 +15,7 @@ using Microsoft.Extensions.Caching.Distributed;
 using Microsoft.Extensions.Options;
 using ProcessNode = GxPress.Entity.WorkProcess.ProcessNode;
 
+
 namespace GxPress.Repository.Implement.WorkProcess
 {
     public partial class ProcessRepository : IProcessRepository
@@ -31,7 +32,6 @@ namespace GxPress.Repository.Implement.WorkProcess
         private readonly IDepartmentRepository _departmentRepository;
         private readonly IRoleRepository _roleRepository;
         private readonly IUserRepository _userRepository;
-
         public ProcessRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper,
             IDistributedCache cache,
             IProcessFieldRepository processFieldRepository,
@@ -120,7 +120,8 @@ namespace GxPress.Repository.Implement.WorkProcess
 
         public async Task<IEnumerable<Process>> GetListByDepartmentIdAsync(int departmentId)
         {
-            var processIdList = await _processRequestLimitRepository.GetProcessIdListByDepartmentIdAsync(departmentId);
+            var departmentIds = await GetDepartmentIdsAsync(departmentId, new List<int>());
+            var processIdList = await _processRequestLimitRepository.GetProcessIdListByDepartmentIdAsync(departmentIds);
             var result = await _repository.GetAllAsync(Q
                 .WhereIn(nameof(Process.Id), processIdList)
                 .OrWhere(nameof(Process.LimitType), nameof(LimitTypeConst.NoLimit))
@@ -132,6 +133,21 @@ namespace GxPress.Repository.Implement.WorkProcess
             return result;
         }
 
+
+        public async Task<List<int>> GetDepartmentIdsAsync(int departmentId, List<int> departmentIds)
+        {
+            var department = await _departmentRepository.GetAsync(departmentId);
+            departmentIds.Add(department.Id);
+            if (department != null && department.ParentId > 0)
+            {
+                department = await _departmentRepository.GetAsync(department.ParentId);
+                departmentIds.Add(department.Id);
+                if (department.ParentId > 0)
+                    await GetDepartmentIdsAsync(department.ParentId, departmentIds);
+            }
+            return departmentIds;
+        }
+
         public async Task<ProcessBaseInfoResult> GetBaseInfoAsync(int id)
         {
             var process = await _repository.GetAsync(id);

+ 8 - 0
GxPress/Repository/GxPress.Repository.Implement/WorkProcess/ProcessRequestLimitRepository.cs

@@ -50,5 +50,13 @@ namespace GxPress.Repository.Implement.WorkProcess
                 .OrWhere(nameof(ProcessRequestLimit.DepartmentId), 0)
             );
         }
+        public async Task<IEnumerable<int>> GetProcessIdListByDepartmentIdAsync(List<int> departmentIds)
+        {
+            return await _repository.GetAllAsync<int>(Q
+                .Select(nameof(ProcessRequestLimit.ProcessId))
+                .WhereIn(nameof(ProcessRequestLimit.DepartmentId), departmentIds)
+                .OrWhere(nameof(ProcessRequestLimit.DepartmentId), 0)
+            );
+        }
     }
 }

+ 1 - 0
GxPress/Repository/GxPress.Repository.Interface/WorkProcess/IProcessRequestLimitRepository.cs

@@ -14,5 +14,6 @@ namespace GxPress.Repository.Interface.WorkProcess
         Task<IEnumerable<ProcessRequestLimit>> GetListAsync(int processId);
 
         Task<IEnumerable<int>> GetProcessIdListByDepartmentIdAsync(int departmentId);
+        Task<IEnumerable<int>> GetProcessIdListByDepartmentIdAsync(List<int> departmentIds);
     }
 }