From 1f793aa004572ec999f6fd061d5a2ca0b518b73c Mon Sep 17 00:00:00 2001 From: 18631081161 <2088094923@qq.com> Date: Fri, 16 Jan 2026 17:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E8=80=97=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AllocationsController.cs | 29 ++++++++++++++--- .../Models/DTOs/AllocationDTOs.cs | 5 +++ .../Implementations/AllocationService.cs | 32 +++++++++++++++++++ .../Services/Interfaces/IAllocationService.cs | 6 ++++ .../src/views/allocations/AllocationList.vue | 11 ++++++- .../views/allocations/AllocationReport.vue | 29 ++++++++--------- 6 files changed, 91 insertions(+), 21 deletions(-) diff --git a/src/MilitaryTrainingManagement/Controllers/AllocationsController.cs b/src/MilitaryTrainingManagement/Controllers/AllocationsController.cs index f9ed8c2..6ca7219 100644 --- a/src/MilitaryTrainingManagement/Controllers/AllocationsController.cs +++ b/src/MilitaryTrainingManagement/Controllers/AllocationsController.cs @@ -50,11 +50,30 @@ public class AllocationsController : BaseApiController } var totalCount = allAllocations.Count(); - var items = allAllocations - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize) - .Select(MapToResponse) - .ToList(); + + // 对于营部及以下级别,需要过滤分配记录并计算可见范围内的上报总和 + List items; + if (unitLevel == OrganizationalLevel.Battalion || unitLevel == OrganizationalLevel.Company) + { + items = new List(); + foreach (var allocation in allAllocations.Skip((pageNumber - 1) * pageSize).Take(pageSize)) + { + var filteredAllocation = await FilterAllocationDistributions(allocation, unitId.Value, unitLevel.Value); + var response = MapToResponse(filteredAllocation); + // 计算可见范围内的上报总和 + response.VisibleActualCompletion = await _allocationService.GetVisibleActualCompletionAsync( + allocation.Id, unitId.Value, unitLevel.Value); + items.Add(response); + } + } + else + { + items = allAllocations + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .Select(MapToResponse) + .ToList(); + } return Ok(new { diff --git a/src/MilitaryTrainingManagement/Models/DTOs/AllocationDTOs.cs b/src/MilitaryTrainingManagement/Models/DTOs/AllocationDTOs.cs index 12ba5c3..bad31c3 100644 --- a/src/MilitaryTrainingManagement/Models/DTOs/AllocationDTOs.cs +++ b/src/MilitaryTrainingManagement/Models/DTOs/AllocationDTOs.cs @@ -119,6 +119,11 @@ public class AllocationResponse public string CreatedByUnitName { get; set; } = string.Empty; public DateTime CreatedAt { get; set; } public List Distributions { get; set; } = new(); + + /// + /// 用户可见范围内的上报总和(营部及以下级别使用) + /// + public decimal? VisibleActualCompletion { get; set; } } /// diff --git a/src/MilitaryTrainingManagement/Services/Implementations/AllocationService.cs b/src/MilitaryTrainingManagement/Services/Implementations/AllocationService.cs index a1e6998..6cc8aa5 100644 --- a/src/MilitaryTrainingManagement/Services/Implementations/AllocationService.cs +++ b/src/MilitaryTrainingManagement/Services/Implementations/AllocationService.cs @@ -416,4 +416,36 @@ public class AllocationService : IAllocationService // 检查目标单位是否在可见范围内 return visibleUnitIds.Contains(targetUnitId); } + + /// + /// 获取用户可见范围内的上报总和 + /// 营部及以下级别:只计算本单位及直接下级的上报 + /// + public async Task GetVisibleActualCompletionAsync(int allocationId, int userUnitId, Models.Enums.OrganizationalLevel userLevel) + { + // 获取用户可见的单位ID列表 + var visibleUnitIds = (await _organizationService.GetVisibleUnitIdsAsync(userUnitId, userLevel)).ToHashSet(); + + // 获取该配额的所有上报记录 + var allocation = await _context.MaterialAllocations + .Include(a => a.Distributions) + .FirstOrDefaultAsync(a => a.Id == allocationId); + + if (allocation == null) + { + return 0; + } + + // 获取所有分配记录的上报历史 + var distributionIds = allocation.Distributions.Select(d => d.Id).ToList(); + var allReports = await _context.ConsumptionReports + .Include(r => r.ReportedByUser) + .Where(r => distributionIds.Contains(r.AllocationDistributionId)) + .ToListAsync(); + + // 只计算上报人所属单位在用户可见范围内的上报 + return allReports + .Where(r => visibleUnitIds.Contains(r.ReportedByUser.OrganizationalUnitId)) + .Sum(r => r.ReportedAmount); + } } diff --git a/src/MilitaryTrainingManagement/Services/Interfaces/IAllocationService.cs b/src/MilitaryTrainingManagement/Services/Interfaces/IAllocationService.cs index 9b483a4..5b0e902 100644 --- a/src/MilitaryTrainingManagement/Services/Interfaces/IAllocationService.cs +++ b/src/MilitaryTrainingManagement/Services/Interfaces/IAllocationService.cs @@ -89,4 +89,10 @@ public interface IAllocationService /// 使用可见性过滤:营部及以下级别只能查看本单位及直接下级 /// Task CanViewDistributionAsync(int userUnitId, OrganizationalLevel userLevel, int targetUnitId); + + /// + /// 获取用户可见范围内的上报总和 + /// 营部及以下级别:只计算本单位及直接下级的上报 + /// + Task GetVisibleActualCompletionAsync(int allocationId, int userUnitId, OrganizationalLevel userLevel); } diff --git a/src/frontend/src/views/allocations/AllocationList.vue b/src/frontend/src/views/allocations/AllocationList.vue index 8d28cbc..b261cd0 100644 --- a/src/frontend/src/views/allocations/AllocationList.vue +++ b/src/frontend/src/views/allocations/AllocationList.vue @@ -106,7 +106,7 @@ - +