perf: use container finance aggregate

This commit is contained in:
2026-09-08 21:09:25 +08:00
parent f25839c4b5
commit 9570e0fd18
4 changed files with 66 additions and 79 deletions
@@ -9,8 +9,7 @@ import DataTable, { type DataTableColumn } from '@/shared/components/DataTable.v
import LoadErrorState from '@/shared/components/LoadErrorState.vue'
import StatusBadge from '@/shared/components/StatusBadge.vue'
import { getApiErrorDetails, type ApiErrorDetails } from '@/shared/api/http'
import { getFinanceSettlement, listFinancePayableSettlements, listFinanceReceivableSettlements } from '@/modules/finance'
import { adjustContainerFee, adjustContainerFeeAllocationGroup, approveContainerFee, approveContainerFeeAllocationGroup, createContainerFee, createContainerFeeAllocationGroup, listApplicableFeeItems, listContainerCostDetails, listContainerFeeSupplierOptions, listContainerFees, rejectContainerFee, rejectContainerFeeAllocationGroup, uploadContainerFeePaymentVoucher, voidContainerFee, voidContainerFeeAllocationGroup, type ApplicableFeeItem, type ContainerCostDetail, type ContainerFeeAllocation, type ContainerFeeSupplierOption, type ContainerFeeResource, type ContainerFeeSaveRequest } from '../api/containerFees'
import { adjustContainerFee, adjustContainerFeeAllocationGroup, approveContainerFee, approveContainerFeeAllocationGroup, createContainerFee, createContainerFeeAllocationGroup, getContainerSettlementDetails, listApplicableFeeItems, listContainerFeeSupplierOptions, listContainerFees, rejectContainerFee, rejectContainerFeeAllocationGroup, uploadContainerFeePaymentVoucher, voidContainerFee, voidContainerFeeAllocationGroup, type ApplicableFeeItem, type ContainerCostDetail, type ContainerFeeAllocation, type ContainerFeeSupplierOption, type ContainerFeeResource, type ContainerFeeSaveRequest } from '../api/containerFees'
const props = defineProps<{
planId: string
@@ -203,10 +202,13 @@ async function loadFinanceDetails() {
try {
const containerIds = [...new Set(feeRows.map((item) => item.containerBookingId).filter((value): value is string => Boolean(value)))]
if (containerIds.some((value) => value !== props.containerBookingId)) throw new Error('柜次费用与装柜摘要的柜次标识不一致,已停止查询财务分摊')
await loadSettledFeeIds(requestedAccountId, feeRows, sequence)
if (sequence !== loadSequence || requestedAccountId !== accountId.value) return
costs.value = props.containerBookingId ? await listContainerCostDetails(requestedAccountId, props.containerBookingId) : []
const aggregate = await getContainerSettlementDetails(requestedAccountId, props.containerBookingId)
if (sequence !== loadSequence || requestedAccountId !== accountId.value) return
settledFeeIds.value = new Set([
...feeRows.filter((item) => item.settlementMode === 'DIRECT_PAID').map((item) => item.id),
...aggregate.settledSourceFeeIds,
])
costs.value = aggregate.costs
financeLoaded.value = true
} catch (cause) {
if (sequence === loadSequence && requestedAccountId === accountId.value) financeError.value = getApiErrorDetails(cause, '财务状态加载失败')
@@ -215,28 +217,6 @@ async function loadFinanceDetails() {
}
}
async function loadSettledFeeIds(customerId: string, feeRows: ContainerFeeResource[], sequence: number) {
const settled = new Set(feeRows.filter((item) => item.settlementMode === 'DIRECT_PAID').map((item) => item.id))
settledFeeIds.value = settled
const listRequests: Array<Promise<Awaited<ReturnType<typeof listFinanceReceivableSettlements>> | Awaited<ReturnType<typeof listFinancePayableSettlements>>>> = []
if (access.can('platform:finance:settlement-ar:list')) listRequests.push(listFinanceReceivableSettlements(customerId))
if (access.can('platform:finance:settlement-ap:list')) listRequests.push(listFinancePayableSettlements(customerId))
if (!listRequests.length) return
const settlementResults = await Promise.allSettled(listRequests)
const paidSettlements = settlementResults.flatMap((result) => result.status === 'fulfilled'
? result.value.filter((item) => item.status === 'PAID' || item.paymentStatus === 'PAID')
: [])
const detailResults = await Promise.allSettled(paidSettlements.map((item) => getFinanceSettlement(item.id)))
for (const result of detailResults) {
if (result.status !== 'fulfilled') continue
for (const line of result.value.lines) {
if (line.sourceType === 'CONTAINER_FEE' && line.sourceFeeId) settled.add(line.sourceFeeId)
}
}
if (sequence === loadSequence && customerId === accountId.value) settledFeeIds.value = settled
}
function openCreate() { if (!canEdit.value || !canViewFeeItems.value || !accountId.value) return; resetForm(); editorError.value = null; editorOpen.value = true; void loadFeeItems() }
async function openAdjust(item: ContainerFeeResource) {
if (!canEdit.value || !accountId.value) return