拆分后台大厅汇总服务

This commit is contained in:
yml2213
2026-08-21 17:25:12 +08:00
parent 49f99e52f2
commit 2b79034a98
3 changed files with 60 additions and 52 deletions
@@ -18,7 +18,6 @@ import {
listWorkOrders,
listWorkProductRules,
listWorkProductRuleMappings,
listWorkerUsers,
updateWorkOrder,
type WorkOrderRow,
} from '../../repositories/worker-platform/index.js'
@@ -30,13 +29,11 @@ import { nowIso } from '../../utils/time.js'
import { safeParseJson } from '../admin/admin-query-utils.js'
import { getWorkerFinanceConfig } from './worker-finance-config-service.js'
import { getWorkerProductMatchConfig } from './worker-product-match-config-service.js'
import { getWorkerHallConfig, saveWorkerHallConfig } from './worker-hall-config-service.js'
import {
createWorkOrderMaterialAdminNotification,
resolveAdminNotificationEntity,
} from '../admin/admin-notification-service.js'
import {
publishWorkerHallRealtimeRefresh,
publishWorkerWalletRealtimeChange,
publishWorkOrderRealtimeChange,
} from '../realtime/realtime-event-service.js'
@@ -577,55 +574,11 @@ export async function cancelAdminWorkOrder(
return { order: mapWorkOrderAdmin(updated), action }
}
export async function getAdminWorkerPlatformSummary() {
const hallConfig = getWorkerHallConfig()
const [pendingWorkers, pendingMaterial, openOrders, 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.IN_PROGRESS],
useOperationalStatus: true,
}),
])
return {
pendingWorkerCount: pendingWorkers.total,
pendingMaterialCount: pendingMaterial.total,
openOrderCount: Math.min(openOrders.total, hallConfig.maxVisibleOrders),
queuedHallOrderCount: Math.max(0, openOrders.total - hallConfig.maxVisibleOrders),
hallMaxVisibleOrders: hallConfig.maxVisibleOrders,
inProgressOrderCount: inProgressOrders.total,
}
}
export async function getAdminWorkerHallConfig() {
const config = getWorkerHallConfig()
const openOrders = await listWorkOrders({
page: 1,
pageSize: 1,
statuses: [WORK_ORDER_STATUS.OPEN],
excludeFilledSharing: true,
})
return {
...config,
visibleOrderCount: Math.min(openOrders.total, config.maxVisibleOrders),
queuedOrderCount: Math.max(0, openOrders.total - config.maxVisibleOrders),
}
}
export async function saveAdminWorkerHallConfig(rawValue: unknown) {
await saveWorkerHallConfig(rawValue)
const config = await getAdminWorkerHallConfig()
publishWorkerHallRealtimeRefresh()
return config
}
export {
getAdminWorkerHallConfig,
getAdminWorkerPlatformSummary,
saveAdminWorkerHallConfig,
} from './admin-worker-platform-summary-service.js'
export async function syncWorkerOrdersForSourceOrder(
order: OrderRow,
@@ -0,0 +1,54 @@
import { WORK_ORDER_STATUS } from '../../domain/work-order-status.js'
import { listWorkOrders, 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, 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.IN_PROGRESS],
useOperationalStatus: true,
}),
])
return {
pendingWorkerCount: pendingWorkers.total,
pendingMaterialCount: pendingMaterial.total,
openOrderCount: Math.min(openOrders.total, hallConfig.maxVisibleOrders),
queuedHallOrderCount: Math.max(0, openOrders.total - hallConfig.maxVisibleOrders),
hallMaxVisibleOrders: hallConfig.maxVisibleOrders,
inProgressOrderCount: inProgressOrders.total,
}
}
export async function getAdminWorkerHallConfig() {
const config = getWorkerHallConfig()
const openOrders = await listWorkOrders({
page: 1,
pageSize: 1,
statuses: [WORK_ORDER_STATUS.OPEN],
excludeFilledSharing: true,
})
return {
...config,
visibleOrderCount: Math.min(openOrders.total, config.maxVisibleOrders),
queuedOrderCount: Math.max(0, openOrders.total - config.maxVisibleOrders),
}
}
export async function saveAdminWorkerHallConfig(rawValue: unknown) {
await saveWorkerHallConfig(rawValue)
const config = await getAdminWorkerHallConfig()
publishWorkerHallRealtimeRefresh()
return config
}
@@ -33,6 +33,7 @@ export * from './admin-work-order-realtime-service.js'
export * from './admin-work-order-material-service.js'
export * from './admin-mock-work-order-service.js'
export * from './admin-work-order-management-service.js'
export * from './admin-worker-platform-summary-service.js'
export {
acceptAdminWorkOrder,
acceptAdminWorkOrderShare,