diff --git a/furniture-3d-system/src/app/api/intake/oa-board/export/route.ts b/furniture-3d-system/src/app/api/intake/oa-board/export/route.ts index e318a2ca..4bad9b7a 100644 --- a/furniture-3d-system/src/app/api/intake/oa-board/export/route.ts +++ b/furniture-3d-system/src/app/api/intake/oa-board/export/route.ts @@ -28,6 +28,98 @@ function applyHeaderStyle(worksheet: ExcelJS.Worksheet) { } } +type TimelineMetricMap = Record< + string, + { + targetDays: number | null + actualDays: number | null + } +> + +type TimingDetailDefinition = { + header: string + metricKey: string + valueType: 'target' | 'actual' +} + +const TIMING_DETAIL_DEFINITIONS: TimingDetailDefinition[] = [ + { header: '目标-外观', metricKey: 'exterior', valueType: 'target' }, + { header: '实际-外观', metricKey: 'exterior', valueType: 'actual' }, + { header: '目标-结构', metricKey: 'structure', valueType: 'target' }, + { header: '实际-结构', metricKey: 'structure', valueType: 'actual' }, + { header: '目标-打样', metricKey: 'sample_prepare', valueType: 'target' }, + { header: '实际-打样', metricKey: 'sample_prepare', valueType: 'actual' }, + { header: '目标-审样', metricKey: 'sample_review', valueType: 'target' }, + { header: '实际-审样', metricKey: 'sample_review', valueType: 'actual' }, + { header: '目标-生产', metricKey: 'production', valueType: 'target' }, + { header: '实际-生产', metricKey: 'production', valueType: 'actual' }, + { header: '目标-商品资料', metricKey: 'material', valueType: 'target' }, + { header: '实际-商品资料', metricKey: 'material', valueType: 'actual' }, + { header: '企划更新市场分析', metricKey: 'market_analysis', valueType: 'actual' }, + { header: '目标-首单下单(线下签订合同)', metricKey: 'first_order', valueType: 'target' }, + { header: '实际-首单下单(线下签订合同)', metricKey: 'first_order', valueType: 'actual' }, + { header: '目标-产前样确认', metricKey: 'pre_production', valueType: 'target' }, + { header: '实际-产前样确认', metricKey: 'pre_production', valueType: 'actual' }, + { header: '目标-出货', metricKey: 'shipment', valueType: 'target' }, + { header: '实际-出货', metricKey: 'shipment', valueType: 'actual' }, + { header: '目标-核价', metricKey: 'pricing', valueType: 'target' }, + { header: '实际-核价', metricKey: 'pricing', valueType: 'actual' }, + { header: '实际-核价后并行用时', metricKey: 'pricing_parallel', valueType: 'actual' }, + { header: '目标-送仓质检', metricKey: 'warehouse_qc', valueType: 'target' }, + { header: '实际时效-送仓质检', metricKey: 'warehouse_qc', valueType: 'actual' }, + { header: '目标-安装图纸', metricKey: 'install_manual', valueType: 'target' }, + { header: '实际-安装图纸', metricKey: 'install_manual', valueType: 'actual' }, + { header: '目标-寄样', metricKey: 'sample_send', valueType: 'target' }, + { header: '实际-寄样', metricKey: 'sample_send', valueType: 'actual' }, + { header: '目标-出图', metricKey: 'art', valueType: 'target' }, + { header: '实际-出图', metricKey: 'art', valueType: 'actual' }, + { header: '目标-限价', metricKey: 'pricing_flow', valueType: 'target' }, + { header: '实际-限价', metricKey: 'pricing_flow', valueType: 'actual' }, + { header: '目标-运营上架', metricKey: 'listing', valueType: 'target' }, + { header: '实际-运营上架', metricKey: 'listing', valueType: 'actual' }, +] + +function formatDayValue(value: number | null | undefined) { + if (value === null || value === undefined || Number.isNaN(value)) return '' + return value +} + +function createTimelineMetricMap( + metrics: Array<{ key: string; targetDays: number | null; actualDays: number | null }>, +): TimelineMetricMap { + return Object.fromEntries( + metrics.map((metric) => [ + metric.key, + { targetDays: metric.targetDays, actualDays: metric.actualDays }, + ]), + ) +} + +function readMultiValueParam(searchParams: URLSearchParams, key: string) { + return searchParams + .getAll(key) + .flatMap((value) => value.split(',')) + .map((value) => value.trim()) + .filter(Boolean) +} + +function formatDateOnly(value: string | null | undefined) { + const text = String(value ?? '').trim() + return text ? text.slice(0, 10) : '' +} + +function readMetricValue( + metrics: TimelineMetricMap, + key: string, + valueType: 'target' | 'actual', +) { + const metric = metrics[key] + if (!metric) return '' + return valueType === 'target' + ? formatDayValue(metric.targetDays) + : formatDayValue(metric.actualDays) +} + export async function GET(request: NextRequest) { return handleRequest( request, @@ -42,9 +134,16 @@ export async function GET(request: NextRequest) { const dashboard = await oaBoardService.getDashboard({ keyword: searchParams.get('keyword') || undefined, approvalNumber: searchParams.get('approvalNumber') || undefined, - overallStatus: searchParams.get('overallStatus') || undefined, + overallStatus: readMultiValueParam(searchParams, 'overallStatus'), + createdDateStart: searchParams.get('createdDateStart') || undefined, + createdDateEnd: searchParams.get('createdDateEnd') || undefined, productType: searchParams.get('productType') || undefined, approvalStage: searchParams.get('approvalStage') || undefined, + productPlanner: searchParams.get('productPlanner') || undefined, + structureDesigner: searchParams.get('structureDesigner') || undefined, + appearanceDesigner: searchParams.get('appearanceDesigner') || undefined, + purchaseOwner: searchParams.get('purchaseOwner') || undefined, + spuOwner: searchParams.get('spuOwner') || undefined, owner: searchParams.get('owner') || undefined, nodeName: searchParams.get('nodeName') || undefined, timeoutOnly: searchParams.get('timeoutOnly') === '1', @@ -59,6 +158,7 @@ export async function GET(request: NextRequest) { { header: '序号', key: 'index', width: 8 }, { header: '审批编号', key: 'approvalNumber', width: 24 }, { header: '开款编号', key: 'openingCode', width: 22 }, + { header: '创建日期', key: 'createdDate', width: 14 }, { header: '总流程状态', key: 'totalFlowStatusLabel', width: 12 }, { header: '流程审批阶段', key: 'approvalStageDisplay', width: 20 }, { header: '当前负责人', key: 'currentOwnerDisplay', width: 18 }, @@ -85,6 +185,7 @@ export async function GET(request: NextRequest) { index: index + 1, approvalNumber: item.boardKey, openingCode: item.formSummary.openingCode || item.openingCode || '', + createdDate: formatDateOnly(item.createdDate), totalFlowStatusLabel: item.formSummary.totalFlowStatusLabel || '', approvalStageDisplay: item.formSummary.approvalStageDisplay || item.currentApprovalStageName || '', currentOwnerDisplay: item.formSummary.currentOwnerDisplay || '', @@ -109,9 +210,9 @@ export async function GET(request: NextRequest) { const detail = workbook.addWorksheet('流程明细') detail.columns = [ - { header: '审批编号', key: 'approvalNumber', width: 24 }, { header: '款式图片', key: 'firstImageUrl', width: 54 }, { header: '开款编号', key: 'openingCode', width: 22 }, + { header: '创建日期', key: 'createdDate', width: 14 }, { header: '总流程状态', key: 'totalFlowStatusLabel', width: 14 }, { header: '流程审批阶段', key: 'approvalStageDisplay', width: 20 }, { header: '当前审批节点', key: 'currentNodeDisplay', width: 24 }, @@ -147,19 +248,22 @@ export async function GET(request: NextRequest) { { header: 'SPU', key: 'spu', width: 14 }, { header: '开款品牌', key: 'openingBrand', width: 16 }, { header: '创建人', key: 'creatorLabel', width: 14 }, - { header: '创建日期', key: 'createdDate', width: 24 }, - { header: '结束日期', key: 'finishedDate', width: 24 }, { header: '总目标时效', key: 'overallTargetHours', width: 14 }, { header: '总实际时效', key: 'overallActualHours', width: 14 }, { header: '是否超时', key: 'isOvertime', width: 10 }, - { header: '详细时效JSON', key: 'timelineMetrics', width: 80 }, + ...TIMING_DETAIL_DEFINITIONS.map((field) => ({ + header: field.header, + key: field.header, + width: 18, + })), ] dashboard.items.forEach((item) => { + const metricMap = createTimelineMetricMap(item.timelineMetrics) detail.addRow({ - approvalNumber: item.boardKey, firstImageUrl: item.styleImages[0]?.url || '', openingCode: item.formSummary.openingCode || item.openingCode || '', + createdDate: formatDateOnly(item.createdDate), totalFlowStatusLabel: item.formSummary.totalFlowStatusLabel || '', approvalStageDisplay: item.formSummary.approvalStageDisplay || item.currentApprovalStageName || '', currentNodeDisplay: item.formSummary.currentNodeDisplay || '', @@ -195,12 +299,15 @@ export async function GET(request: NextRequest) { spu: item.formSummary.spu || item.spu || '', openingBrand: item.formSummary.openingBrand || '', creatorLabel: item.originatorDeptName || item.boardKeyType || '', - createdDate: item.createdDate || '', - finishedDate: item.finishedDate || '', overallTargetHours: item.overallTargetHours ?? '', overallActualHours: item.overallActualHours ?? '', isOvertime: item.overallTimeoutFlag ? '是' : '否', - timelineMetrics: JSON.stringify(item.timelineMetrics, null, 0), + ...Object.fromEntries( + TIMING_DETAIL_DEFINITIONS.map((field) => [ + field.header, + readMetricValue(metricMap, field.metricKey, field.valueType), + ]), + ), }) }) diff --git a/furniture-3d-system/src/app/intake/oa-board/OaBoardClient.tsx b/furniture-3d-system/src/app/intake/oa-board/OaBoardClient.tsx index bba95a36..e8ac5754 100644 --- a/furniture-3d-system/src/app/intake/oa-board/OaBoardClient.tsx +++ b/furniture-3d-system/src/app/intake/oa-board/OaBoardClient.tsx @@ -1,158 +1,404 @@ 'use client' -import { useState, useTransition } from 'react' +import { useMemo, useState, useTransition } from 'react' import { usePathname, useRouter, useSearchParams } from 'next/navigation' import { AlertTriangle, + ChevronLeft, + ChevronRight, + CheckCircle2, + Clock3, Download, + ExternalLink, Filter, LoaderCircle, + PackageSearch, RefreshCcw, - Rows3, Search, - Table2, - UserRoundSearch, + Sparkles, } from 'lucide-react' +import { PlatformMetricStrip } from '@/components/platform/PlatformMetricStrip' +import { PlatformSection } from '@/components/platform/PlatformSection' +import { OA_BOARD_DEFAULT_TRACKED_STATUSES } from '@/server/services/oa-board.constants' import type { OaBoardDashboardDTO, OaBoardProjectListItemDTO, OaBoardTimelineMetricDTO, } from '@/server/services/oa-board.service' -type OaBoardTabKey = 'overview' | 'detail' - type FilterState = { keyword: string approvalNumber: string - overallStatus: string - productType: string + overallStatus: string[] + createdDateStart: string + createdDateEnd: string approvalStage: string - owner: string - nodeName: string - timeoutOnly: boolean + productPlanner: string + structureDesigner: string + appearanceDesigner: string + purchaseOwner: string + spuOwner: string } +type FilterOption = { + value: string + label: string +} + +type TimelineMetricMap = Partial> + +type TimingDetailField = { + id: string + label: string + value: string +} + +type TimingDetailDefinition = { + id: string + label: string + metricKey: string + valueType: 'target' | 'actual' +} + +const PAGE_SIZE = 20 +const DEFAULT_TRACKED_STATUSES = [...OA_BOARD_DEFAULT_TRACKED_STATUSES] +const ALL_STATUS_OPTIONS: FilterOption[] = [ + { value: 'RUNNING', label: '进行中' }, + { value: 'COMPLETED', label: '已完成' }, + { value: 'REFUSED', label: '已驳回' }, + { value: 'TERMINATED', label: '已终止' }, +] +const COLUMN_WIDTHS = { + image: 110, + openingCode: 160, + status: 130, + createdDate: 120, + approvalStage: 190, + currentNode: 180, + currentOwner: 150, +} as const +const STICKY_LEFT = { + image: 0, + openingCode: COLUMN_WIDTHS.image, + status: COLUMN_WIDTHS.image + COLUMN_WIDTHS.openingCode, +} as const + +const TIMING_DETAIL_DEFINITIONS: TimingDetailDefinition[] = [ + { id: 'target-exterior', label: '目标-外观', metricKey: 'exterior', valueType: 'target' }, + { id: 'actual-exterior', label: '实际-外观', metricKey: 'exterior', valueType: 'actual' }, + { id: 'target-structure', label: '目标-结构', metricKey: 'structure', valueType: 'target' }, + { id: 'actual-structure', label: '实际-结构', metricKey: 'structure', valueType: 'actual' }, + { id: 'target-sample-prepare', label: '目标-打样', metricKey: 'sample_prepare', valueType: 'target' }, + { id: 'actual-sample-prepare', label: '实际-打样', metricKey: 'sample_prepare', valueType: 'actual' }, + { id: 'target-sample-review', label: '目标-审样', metricKey: 'sample_review', valueType: 'target' }, + { id: 'actual-sample-review', label: '实际-审样', metricKey: 'sample_review', valueType: 'actual' }, + { id: 'target-production', label: '目标-生产', metricKey: 'production', valueType: 'target' }, + { id: 'actual-production', label: '实际-生产', metricKey: 'production', valueType: 'actual' }, + { id: 'target-material', label: '目标-商品资料', metricKey: 'material', valueType: 'target' }, + { id: 'actual-material', label: '实际-商品资料', metricKey: 'material', valueType: 'actual' }, + { id: 'market-analysis', label: '企划更新市场分析', metricKey: 'market_analysis', valueType: 'actual' }, + { + id: 'target-first-order', + label: '目标-首单下单(线下签订合同)', + metricKey: 'first_order', + valueType: 'target', + }, + { + id: 'actual-first-order', + label: '实际-首单下单(线下签订合同)', + metricKey: 'first_order', + valueType: 'actual', + }, + { + id: 'target-pre-production', + label: '目标-产前样确认', + metricKey: 'pre_production', + valueType: 'target', + }, + { + id: 'actual-pre-production', + label: '实际-产前样确认', + metricKey: 'pre_production', + valueType: 'actual', + }, + { id: 'target-shipment', label: '目标-出货', metricKey: 'shipment', valueType: 'target' }, + { id: 'actual-shipment', label: '实际-出货', metricKey: 'shipment', valueType: 'actual' }, + { id: 'target-pricing', label: '目标-核价', metricKey: 'pricing', valueType: 'target' }, + { id: 'actual-pricing', label: '实际-核价', metricKey: 'pricing', valueType: 'actual' }, + { + id: 'actual-pricing-parallel', + label: '实际-核价后并行用时', + metricKey: 'pricing_parallel', + valueType: 'actual', + }, + { + id: 'target-warehouse-qc', + label: '目标-送仓质检', + metricKey: 'warehouse_qc', + valueType: 'target', + }, + { + id: 'actual-warehouse-qc', + label: '实际时效-送仓质检', + metricKey: 'warehouse_qc', + valueType: 'actual', + }, + { + id: 'target-install-manual', + label: '目标-安装图纸', + metricKey: 'install_manual', + valueType: 'target', + }, + { + id: 'actual-install-manual', + label: '实际-安装图纸', + metricKey: 'install_manual', + valueType: 'actual', + }, + { id: 'target-sample-send', label: '目标-寄样', metricKey: 'sample_send', valueType: 'target' }, + { id: 'actual-sample-send', label: '实际-寄样', metricKey: 'sample_send', valueType: 'actual' }, + { id: 'target-art', label: '目标-出图', metricKey: 'art', valueType: 'target' }, + { id: 'actual-art', label: '实际-出图', metricKey: 'art', valueType: 'actual' }, + { + id: 'target-pricing-flow', + label: '目标-限价', + metricKey: 'pricing_flow', + valueType: 'target', + }, + { + id: 'actual-pricing-flow', + label: '实际-限价', + metricKey: 'pricing_flow', + valueType: 'actual', + }, + { id: 'target-listing', label: '目标-运营上架', metricKey: 'listing', valueType: 'target' }, + { id: 'actual-listing', label: '实际-运营上架', metricKey: 'listing', valueType: 'actual' }, +] + function formatDayValue(value: number | null | undefined) { if (value === null || value === undefined || Number.isNaN(value)) return '-' return `${value} 天` } -function StatCard({ - label, - value, - description, - tone = 'default', -}: { - label: string - value: string | number - description: string - tone?: 'default' | 'warning' | 'danger' | 'success' -}) { - const toneClass = - tone === 'danger' - ? 'border-rose-200 bg-rose-50 text-rose-700' - : tone === 'warning' - ? 'border-amber-200 bg-amber-50 text-amber-700' - : tone === 'success' - ? 'border-emerald-200 bg-emerald-50 text-emerald-700' - : 'border-apple-separator bg-apple-bg-primary text-apple-label-primary' - - return ( -
-
- {label} - {value} -
-

{description}

-
- ) +function formatStatusLabel(status: string | null | undefined) { + if (!status) return '-' + if (status === 'RUNNING') return '进行中' + if (status === 'COMPLETED') return '已完成' + if (status === 'REFUSED') return '已驳回' + if (status === 'TERMINATED') return '已终止' + return status } -function TabButton({ - label, - active, - icon, - onClick, -}: { - label: string - active: boolean - icon: React.ReactNode - onClick: () => void -}) { - return ( - - ) +function formatCellText(value: string | null | undefined) { + const text = String(value ?? '').trim() + return text || '-' } -function SectionTitle({ - title, - description, -}: { - title: string - description: string -}) { - return ( -
-

{title}

-

{description}

-
- ) +function formatDateText(value: string | null | undefined) { + const text = String(value ?? '').trim() + return text ? text.slice(0, 10) : '-' +} + +function extractFirstUrl(value: string | null | undefined) { + const text = String(value ?? '').trim() + if (!text) return null + const matched = text.match(/https?:\/\/[^\s"'))】]+/i) + return matched?.[0] ?? null +} + +function formatCompetitorLinkSummary(value: string | null | undefined) { + const text = String(value ?? '').trim() + if (!text) return { href: null, summary: '-', title: '' } + + const href = extractFirstUrl(text) + if (!href) { + return { + href: null, + summary: text, + title: text, + } + } + + try { + const parsed = new URL(href) + const host = parsed.hostname.replace(/^www\./, '') + const identifier = + parsed.searchParams.get('id') ?? + parsed.pathname.match(/(\d{6,})/)?.[1] ?? + '' + + return { + href, + summary: identifier ? `${host} / ${identifier}` : host, + title: text, + } + } catch { + return { + href, + summary: href, + title: text, + } + } +} + +function buildOptionList(values: Array, allLabel: string) { + const unique = Array.from( + new Set( + values + .map((value) => String(value ?? '').trim()) + .filter(Boolean), + ), + ).sort((left, right) => left.localeCompare(right, 'zh-CN')) + + return [{ value: '', label: allLabel }, ...unique.map((value) => ({ value, label: value }))] +} + +function createTimelineMetricMap(metrics: OaBoardTimelineMetricDTO[]): TimelineMetricMap { + return Object.fromEntries(metrics.map((metric) => [metric.key, metric])) as TimelineMetricMap +} + +function stickyCellClass(left: number, extra = '') { + return ['sticky bg-white bg-clip-padding', extra].filter(Boolean).join(' ') +} + +function readMetricValue( + metrics: TimelineMetricMap, + key: string, + valueType: 'target' | 'actual', +) { + const metric = metrics[key] + if (!metric) return '-' + return valueType === 'target' + ? formatDayValue(metric.targetDays) + : formatDayValue(metric.actualDays) +} + +function readCreatorDisplay(item: OaBoardProjectListItemDTO) { + const initiator = item.nodeAssessments.find((node) => node.nodeName.includes('发起'))?.ownerLabel + return initiator || item.originatorDeptName || item.boardKeyType || '-' +} + +function buildTimingDetailFields(item: OaBoardProjectListItemDTO): TimingDetailField[] { + const metrics = createTimelineMetricMap(item.timelineMetrics) + + return TIMING_DETAIL_DEFINITIONS.map((field) => ({ + id: field.id, + label: field.label, + value: readMetricValue(metrics, field.metricKey, field.valueType), + })) } function FilterInput({ label, value, - onChange, placeholder, + type = 'text', + onChange, }: { label: string value: string - onChange: (value: string) => void placeholder: string + type?: 'text' | 'date' + onChange: (value: string) => void }) { return ( -