优化接单平台工单查询性能
This commit is contained in:
@@ -55,12 +55,15 @@ export async function listAdminWorkOrders(query: JsonObject = {}) {
|
||||
...(createdFrom ? { createdFrom } : {}),
|
||||
...(createdTo ? { createdTo } : {}),
|
||||
}
|
||||
const { items, total } = await listWorkOrders({ page, pageSize, ...filters })
|
||||
const statistics = await getWorkOrderStatistics(filters)
|
||||
const pendingUnfreezeByOrderId = await sumPendingUnfreezeByOrderIds(
|
||||
items.map((item) => Number(item.id)),
|
||||
)
|
||||
const shares = await listWorkOrderSharesByOrderIds(items.map((item) => Number(item.id)))
|
||||
const [{ items }, statistics] = await Promise.all([
|
||||
listWorkOrders({ page, pageSize, includeTotal: false, ...filters }),
|
||||
getWorkOrderStatistics(filters),
|
||||
])
|
||||
const itemIds = items.map((item) => Number(item.id))
|
||||
const [pendingUnfreezeByOrderId, shares] = await Promise.all([
|
||||
sumPendingUnfreezeByOrderIds(itemIds),
|
||||
listWorkOrderSharesByOrderIds(itemIds),
|
||||
])
|
||||
const sharesByOrderId = new Map<number, typeof shares>()
|
||||
for (const share of shares) {
|
||||
const orderId = Number(share.work_order_id)
|
||||
@@ -73,7 +76,7 @@ export async function listAdminWorkOrders(query: JsonObject = {}) {
|
||||
...mapWorkOrderAdmin(item, sharesByOrderId.get(Number(item.id)) || []),
|
||||
pendingUnfreezeAmount: pendingUnfreezeByOrderId.get(Number(item.id)) || 0,
|
||||
})),
|
||||
pagination: { page, pageSize, total },
|
||||
pagination: { page, pageSize, total: statistics.totalCount },
|
||||
statistics,
|
||||
}
|
||||
}
|
||||
|
||||
+34
-39
@@ -1,57 +1,52 @@
|
||||
import { WORK_ORDER_STATUS } from '../../domain/work-order-status.js'
|
||||
import { listWorkOrders, listWorkerUsers } from '../../repositories/worker-platform/index.js'
|
||||
import { countWorkOrders, listWorkerUsers } from '../../repositories/worker-platform/index.js'
|
||||
import { publishWorkerHallRealtimeRefresh } from '../realtime/realtime-event-service.js'
|
||||
import { getWorkerHallConfig, saveWorkerHallConfig } from './worker-hall-config-service.js'
|
||||
|
||||
export async function getAdminWorkerPlatformSummary() {
|
||||
const hallConfig = getWorkerHallConfig()
|
||||
const [pendingWorkers, pendingMaterial, openOrders, visibleOpenOrders, inProgressOrders] =
|
||||
await Promise.all([
|
||||
listWorkerUsers({ page: 1, pageSize: 1, status: 'pending_review' }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, statuses: [WORK_ORDER_STATUS.PENDING_MATERIAL] }),
|
||||
listWorkOrders({
|
||||
page: 1,
|
||||
pageSize: 1,
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
excludeFilledSharing: true,
|
||||
}),
|
||||
listWorkOrders({
|
||||
page: 1,
|
||||
pageSize: 1,
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
hallCandidateLimit: hallConfig.maxVisibleOrders,
|
||||
hallCategoryLimits: hallConfig.categoryMaxVisibleOrders,
|
||||
excludeFilledSharing: true,
|
||||
}),
|
||||
listWorkOrders({
|
||||
page: 1,
|
||||
pageSize: 1,
|
||||
statuses: [WORK_ORDER_STATUS.IN_PROGRESS],
|
||||
useOperationalStatus: true,
|
||||
}),
|
||||
])
|
||||
const [
|
||||
pendingWorkers,
|
||||
pendingMaterialCount,
|
||||
openOrderCount,
|
||||
visibleOpenOrderCount,
|
||||
inProgressOrderCount,
|
||||
] = await Promise.all([
|
||||
listWorkerUsers({ page: 1, pageSize: 1, status: 'pending_review' }),
|
||||
countWorkOrders({ statuses: [WORK_ORDER_STATUS.PENDING_MATERIAL] }),
|
||||
countWorkOrders({
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
excludeFilledSharing: true,
|
||||
}),
|
||||
countWorkOrders({
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
hallCandidateLimit: hallConfig.maxVisibleOrders,
|
||||
hallCategoryLimits: hallConfig.categoryMaxVisibleOrders,
|
||||
excludeFilledSharing: true,
|
||||
}),
|
||||
countWorkOrders({
|
||||
statuses: [WORK_ORDER_STATUS.IN_PROGRESS],
|
||||
useOperationalStatus: true,
|
||||
}),
|
||||
])
|
||||
return {
|
||||
pendingWorkerCount: pendingWorkers.total,
|
||||
pendingMaterialCount: pendingMaterial.total,
|
||||
openOrderCount: visibleOpenOrders.total,
|
||||
queuedHallOrderCount: Math.max(0, openOrders.total - visibleOpenOrders.total),
|
||||
pendingMaterialCount,
|
||||
openOrderCount: visibleOpenOrderCount,
|
||||
queuedHallOrderCount: Math.max(0, openOrderCount - visibleOpenOrderCount),
|
||||
hallMaxVisibleOrders: hallConfig.maxVisibleOrders,
|
||||
inProgressOrderCount: inProgressOrders.total,
|
||||
inProgressOrderCount,
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAdminWorkerHallConfig() {
|
||||
const config = getWorkerHallConfig()
|
||||
const [openOrders, visibleOpenOrders] = await Promise.all([
|
||||
listWorkOrders({
|
||||
page: 1,
|
||||
pageSize: 1,
|
||||
const [openOrderCount, visibleOpenOrderCount] = await Promise.all([
|
||||
countWorkOrders({
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
excludeFilledSharing: true,
|
||||
}),
|
||||
listWorkOrders({
|
||||
page: 1,
|
||||
pageSize: 1,
|
||||
countWorkOrders({
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
hallCandidateLimit: config.maxVisibleOrders,
|
||||
hallCategoryLimits: config.categoryMaxVisibleOrders,
|
||||
@@ -60,8 +55,8 @@ export async function getAdminWorkerHallConfig() {
|
||||
])
|
||||
return {
|
||||
...config,
|
||||
visibleOrderCount: visibleOpenOrders.total,
|
||||
queuedOrderCount: Math.max(0, openOrders.total - visibleOpenOrders.total),
|
||||
visibleOrderCount: visibleOpenOrderCount,
|
||||
queuedOrderCount: Math.max(0, openOrderCount - visibleOpenOrderCount),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user