消耗数量
This commit is contained in:
parent
b4c5ebc926
commit
1f793aa004
|
|
@ -50,11 +50,30 @@ public class AllocationsController : BaseApiController
|
|||
}
|
||||
|
||||
var totalCount = allAllocations.Count();
|
||||
var items = allAllocations
|
||||
|
||||
// 对于营部及以下级别,需要过滤分配记录并计算可见范围内的上报总和
|
||||
List<AllocationResponse> items;
|
||||
if (unitLevel == OrganizationalLevel.Battalion || unitLevel == OrganizationalLevel.Company)
|
||||
{
|
||||
items = new List<AllocationResponse>();
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -119,6 +119,11 @@ public class AllocationResponse
|
|||
public string CreatedByUnitName { get; set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public List<AllocationDistributionResponse> Distributions { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 用户可见范围内的上报总和(营部及以下级别使用)
|
||||
/// </summary>
|
||||
public decimal? VisibleActualCompletion { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -416,4 +416,36 @@ public class AllocationService : IAllocationService
|
|||
// 检查目标单位是否在可见范围内
|
||||
return visibleUnitIds.Contains(targetUnitId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户可见范围内的上报总和
|
||||
/// 营部及以下级别:只计算本单位及直接下级的上报
|
||||
/// </summary>
|
||||
public async Task<decimal> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,4 +89,10 @@ public interface IAllocationService
|
|||
/// 使用可见性过滤:营部及以下级别只能查看本单位及直接下级
|
||||
/// </summary>
|
||||
Task<bool> CanViewDistributionAsync(int userUnitId, OrganizationalLevel userLevel, int targetUnitId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户可见范围内的上报总和
|
||||
/// 营部及以下级别:只计算本单位及直接下级的上报
|
||||
/// </summary>
|
||||
Task<decimal> GetVisibleActualCompletionAsync(int allocationId, int userUnitId, OrganizationalLevel userLevel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@
|
|||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else label="已上报" width="120" align="center">
|
||||
<el-table-column v-else label="已消耗" width="120" align="center">
|
||||
<template #default="{ row }">
|
||||
<div class="report-cell">
|
||||
<span class="report-number">{{ formatNumber(getMyActualCompletion(row)) }}</span>
|
||||
|
|
@ -486,6 +486,11 @@ function getMyUnitQuota(allocation: MaterialAllocation): number {
|
|||
}
|
||||
|
||||
function getMyActualCompletion(allocation: MaterialAllocation): number {
|
||||
// 营部及以下级别使用后端计算的可见范围内的上报总和
|
||||
if (authStore.organizationalLevelNum >= 3 && (allocation as any).visibleActualCompletion !== undefined) {
|
||||
return (allocation as any).visibleActualCompletion || 0
|
||||
}
|
||||
|
||||
if (!authStore.user || !allocation.distributions) return 0
|
||||
// 先查找分配给当前单位的配额
|
||||
let myDistribution = allocation.distributions.find(d => d.targetUnitId === authStore.user?.organizationalUnitId)
|
||||
|
|
@ -508,6 +513,10 @@ function getTotalDistributed(): number {
|
|||
}
|
||||
|
||||
function getTotalConsumed(): number {
|
||||
// 营部及以下级别使用后端计算的可见范围内的上报总和
|
||||
if (authStore.organizationalLevelNum >= 3 && selectedAllocation.value) {
|
||||
return (selectedAllocation.value as any).visibleActualCompletion || 0
|
||||
}
|
||||
return distributions.value.reduce((sum, d) => sum + (d.actualCompletion || 0), 0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
<el-descriptions-item v-if="!isBattalionOrBelow" label="分配配额">
|
||||
<span class="quota-value">{{ formatNumber(distribution.unitQuota) }} {{ allocation?.unit }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="已上报数量">
|
||||
<el-descriptions-item :label="isBattalionOrBelow ? '已消耗数量' : '已上报数量'">
|
||||
<span :class="['completion-value', totalReportedAmount ? '' : 'no-data']">
|
||||
{{ totalReportedAmount ? formatNumber(totalReportedAmount) : '0' }} {{ allocation?.unit }}
|
||||
</span>
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
<!-- 上报表单 -->
|
||||
<div class="form-section">
|
||||
<h3 class="section-title">本次消耗上报</h3>
|
||||
<h3 class="section-title">{{ isBattalionOrBelow ? '本次消耗上报' : '本次消耗上报' }}</h3>
|
||||
<el-alert
|
||||
type="warning"
|
||||
:closable="false"
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
style="margin-bottom: 20px"
|
||||
>
|
||||
<template #title>
|
||||
<span>注意:本次上报数量将累加到已上报总数中</span>
|
||||
<span>{{ isBattalionOrBelow ? '注意:本次消耗数量将累加到已消耗总数中' : '注意:本次上报数量将累加到已上报总数中' }}</span>
|
||||
</template>
|
||||
</el-alert>
|
||||
<el-form
|
||||
|
|
@ -75,7 +75,7 @@
|
|||
label-width="120px"
|
||||
@submit.prevent="handleSubmit"
|
||||
>
|
||||
<el-form-item label="本次上报数量" prop="actualCompletion">
|
||||
<el-form-item :label="isBattalionOrBelow ? '本次消耗数量' : '本次上报数量'" prop="actualCompletion">
|
||||
<el-input-number
|
||||
v-model="form.actualCompletion"
|
||||
:min="0"
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
<el-form-item>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">
|
||||
<el-icon><Check /></el-icon>
|
||||
提交上报
|
||||
{{ isBattalionOrBelow ? '提交消耗' : '提交上报' }}
|
||||
</el-button>
|
||||
<el-button @click="handleBack">
|
||||
<el-icon><Close /></el-icon>
|
||||
|
|
@ -214,10 +214,9 @@ const isBattalionOrBelow = computed(() => {
|
|||
})
|
||||
|
||||
// 计算本单位和下属单位的上报数之和
|
||||
// 始终使用consumptionReports求和,因为它已经是经过可见性过滤的记录
|
||||
// 不再回退到distribution.actualCompletion,因为那是所有单位的总上报数
|
||||
const totalReportedAmount = computed(() => {
|
||||
if (consumptionReports.value.length === 0) {
|
||||
return distribution.value?.actualCompletion || 0
|
||||
}
|
||||
return consumptionReports.value.reduce((sum, report) => sum + report.reportedAmount, 0)
|
||||
})
|
||||
|
||||
|
|
@ -225,7 +224,7 @@ const totalReportedAmount = computed(() => {
|
|||
const formRules = computed<FormRules>(() => {
|
||||
const baseRules: FormRules = {
|
||||
actualCompletion: [
|
||||
{ required: true, message: '请输入本次上报数量', trigger: 'blur' },
|
||||
{ required: true, message: isBattalionOrBelow.value ? '请输入本次消耗数量' : '请输入本次上报数量', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
min: 0.01,
|
||||
|
|
@ -296,17 +295,17 @@ async function handleSubmit() {
|
|||
|
||||
const newTotal = (distribution.value?.actualCompletion || 0) + form.actualCompletion
|
||||
|
||||
// 营部及以下级别的确认信息不显示总数
|
||||
// 营部及以下级别的确认信息不显示总数,使用"消耗"文字
|
||||
const confirmMessage = isBattalionOrBelow.value
|
||||
? `本次上报数量:${form.actualCompletion} ${allocation.value?.unit}\n\n确认提交吗?`
|
||||
? `本次消耗数量:${form.actualCompletion} ${allocation.value?.unit}\n\n确认提交吗?`
|
||||
: `本次上报数量:${form.actualCompletion} ${allocation.value?.unit}\n上报后总数:${newTotal} ${allocation.value?.unit}\n\n确认提交吗?`
|
||||
|
||||
await ElMessageBox.confirm(
|
||||
confirmMessage,
|
||||
'确认上报',
|
||||
isBattalionOrBelow.value ? '确认消耗' : '确认上报',
|
||||
{
|
||||
type: 'warning',
|
||||
confirmButtonText: '确认上报',
|
||||
confirmButtonText: isBattalionOrBelow.value ? '确认消耗' : '确认上报',
|
||||
cancelButtonText: '取消'
|
||||
}
|
||||
)
|
||||
|
|
@ -320,11 +319,11 @@ async function handleSubmit() {
|
|||
actualCompletion: newTotal
|
||||
})
|
||||
|
||||
ElMessage.success('上报成功')
|
||||
ElMessage.success(isBattalionOrBelow.value ? '消耗提交成功' : '上报成功')
|
||||
router.back()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error(error.response?.data?.message || '上报失败')
|
||||
ElMessage.error(error.response?.data?.message || (isBattalionOrBelow.value ? '消耗提交失败' : '上报失败'))
|
||||
}
|
||||
} finally {
|
||||
submitting.value = false
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user