perf(admin): streamline smart loading workbench

This commit is contained in:
2026-09-04 09:57:39 +08:00
parent 475b2a08e2
commit 2d14568caf
7 changed files with 97 additions and 90 deletions
@@ -1,5 +1,3 @@
import { getLoadingAssociationSummaryByInboundId, type LoadingAssociationSummary } from '@/shared/api/inboundCodeRelations'
import { groupSmartLoadingItems } from './smartLoadingItems'
import type { SmartLoadingPlan } from './types'
export interface SmartLoadingPlanCoLoadGroup {
@@ -11,37 +9,18 @@ export interface SmartLoadingPlanCoLoadGroup {
fullPackageCount: number
}
type AssociationLookup = (inboundId: string) => Promise<LoadingAssociationSummary>
export async function loadSmartLoadingPlanCoLoadGroups(
plan: SmartLoadingPlan,
lookup: AssociationLookup = getLoadingAssociationSummaryByInboundId,
) {
const inboundRows = groupSmartLoadingItems(plan.items || [])
if (!inboundRows.length) return new Map<string, SmartLoadingPlanCoLoadGroup>()
const associations = await Promise.all(inboundRows.map(async (row) => ({
row,
association: await lookup(row.inboundId),
})))
const membersByGroupId = new Map<string, typeof associations>()
for (const entry of associations) {
const groupId = String(entry.association.coLoadGroupId || '')
if (!groupId) continue
membersByGroupId.set(groupId, [...(membersByGroupId.get(groupId) || []), entry])
}
export function loadSmartLoadingPlanCoLoadGroups(plan: SmartLoadingPlan) {
const groupsByInboundId = new Map<string, SmartLoadingPlanCoLoadGroup>()
for (const [groupId, members] of membersByGroupId) {
for (const source of plan.coLoadGroups || []) {
const group = {
groupId,
groupNo: members.find((entry) => entry.association.coLoadGroupNo)?.association.coLoadGroupNo || '同柜不可拆组',
lockedPlanId: members.find((entry) => entry.association.loadingPlanId)?.association.loadingPlanId || plan.id,
memberOrderCount: new Set(members.map((entry) => entry.row.orderId)).size,
inboundFragmentCount: members.length,
fullPackageCount: members.reduce((sum, entry) => sum + entry.row.packageCount, 0),
groupId: source.groupId,
groupNo: source.groupNo || '同柜不可拆组',
lockedPlanId: source.lockedPlanId || plan.id,
memberOrderCount: source.memberOrderCount,
inboundFragmentCount: source.inboundFragmentCount,
fullPackageCount: source.fullPackageCount,
} satisfies SmartLoadingPlanCoLoadGroup
for (const { row } of members) groupsByInboundId.set(row.inboundId, group)
for (const inboundId of source.memberInboundIds) groupsByInboundId.set(inboundId, group)
}
return groupsByInboundId
}