From 063bbca0efaa398af730c966857569ba6f0b7feb Mon Sep 17 00:00:00 2001 From: chenpei Date: Mon, 27 Jul 2026 10:28:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=80=83=E6=A0=B8?= =?UTF-8?q?=E8=B0=83=E7=A0=94=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/performance-survey/[...path]/route.ts | 12 +- .../PerformanceSurveyAdminConfig.test.tsx | 43 +- .../PerformanceSurveyAdminConfig.tsx | 537 +++++++++++++----- .../PerformanceSurveyAdminPeople.test.tsx | 123 ++++ .../PerformanceSurveyAdminPeople.tsx | 265 ++++++--- app/performance-survey/[[...path]]/page.tsx | 227 ++++++-- ...mance-survey-employee-sync-preview.test.ts | 310 ++++++++++ .../performance-survey-service-policy.test.ts | 50 ++ .../performance-survey-sync-route.test.ts | 100 ++++ lib/performance-survey-report-sync.ts | 419 +++++++++++++- lib/performance-survey-service.ts | 47 ++ 11 files changed, 1901 insertions(+), 232 deletions(-) create mode 100644 app/performance-survey/PerformanceSurveyAdminPeople.test.tsx create mode 100644 lib/__tests__/performance-survey-employee-sync-preview.test.ts create mode 100644 lib/__tests__/performance-survey-sync-route.test.ts diff --git a/app/api/performance-survey/[...path]/route.ts b/app/api/performance-survey/[...path]/route.ts index 6b1d78b2..1a37c450 100644 --- a/app/api/performance-survey/[...path]/route.ts +++ b/app/api/performance-survey/[...path]/route.ts @@ -30,6 +30,7 @@ import { submitPerformanceSurveyWorkItemScores, submitPerformanceSurveyWorkItemScore, submitPerformanceSurveyResponse, + previewPerformanceSurveyEmployeeProfiles, syncPerformanceSurveyEmployeeProfiles, updatePerformanceSurvey, savePerformanceSurveyAdminPositionGroup, @@ -248,7 +249,16 @@ export async function POST(request: Request, context: RouteContext) { return ok(await submitPerformanceSurveyWorkItemScore(session, path[1], path[3], body)) } - if (path[0] === 'admin' && path[1] === 'sync-employees') { + if ( + path[0] === 'admin' + && path[1] === 'sync-employees' + && path[2] === 'preview' + && path.length === 3 + ) { + return ok(await previewPerformanceSurveyEmployeeProfiles(session, body)) + } + + if (path[0] === 'admin' && path[1] === 'sync-employees' && path.length === 2) { return ok(await syncPerformanceSurveyEmployeeProfiles(session, body)) } diff --git a/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx b/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx index 1e84e84b..06c5339a 100644 --- a/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx +++ b/app/performance-survey/PerformanceSurveyAdminConfig.test.tsx @@ -153,15 +153,35 @@ describe('PerformanceSurveyAdminConfig', () => { test('概览展示岗位、人员、模板和月度方案状态', async () => { const request = createRequest() - render() + const onNavigate = jest.fn() + render() expect(screen.getByText('配置加载中...')).toBeInTheDocument() await waitFor(() => expect(screen.getByRole('heading', { name: '2026-07 配置概览' })).toBeInTheDocument()) - expect(screen.getByRole('rowheader', { name: '岗位' })).toBeInTheDocument() - expect(screen.getByText('未匹配 1 人')).toBeInTheDocument() + expect(screen.getByRole('heading', { name: '本月上线准备' })).toBeInTheDocument() + expect(screen.getByText(/1 人待确认/)).toBeInTheDocument() + fireEvent.click(screen.getByRole('button', { name: '处理人员' })) + expect(onNavigate).toHaveBeenCalledWith('people') expect(request).toHaveBeenCalledWith(expect.stringContaining('/admin/config-audit-logs')) }) + test('受控月份切换通过外层更新,保持管理工作区月份一致', async () => { + const request = createRequest() + const onMonthChange = jest.fn() + render( + , + ) + + await waitFor(() => expect(screen.getByRole('heading', { name: '2026-08 配置概览' })).toBeInTheDocument()) + fireEvent.change(screen.getByLabelText('查看月份'), { target: { value: '2026-09' } }) + expect(onMonthChange).toHaveBeenCalledWith('2026-09') + }) + test('岗位编辑产生 dirty 状态并保护岗位切换', async () => { const request = createRequest() const onDirtyChange = jest.fn() @@ -200,7 +220,7 @@ describe('PerformanceSurveyAdminConfig', () => { const request = createRequest() render() - await waitFor(() => expect(screen.getByText('张三')).toBeInTheDocument()) + await waitFor(() => expect(screen.getAllByText('张三').length).toBeGreaterThan(0)) fireEvent.click(screen.getByLabelText('选择 张三')) fireEvent.change(screen.getByLabelText('批量分配操作'), { target: { value: 'group-1' } }) fireEvent.change(screen.getByLabelText('本次调整原因'), { target: { value: '部门异动' } }) @@ -236,6 +256,21 @@ describe('PerformanceSurveyAdminConfig', () => { expect(screen.getByRole('button', { name: '归档模板' })).toBeInTheDocument() }) + test('模板编辑按基本信息、评分项、评审与计分分步展示', async () => { + const request = createRequest() + render() + await waitFor(() => expect(screen.getByRole('navigation', { name: '模板编辑步骤' })).toBeInTheDocument()) + + expect(screen.getByRole('heading', { name: '基本信息' })).toBeInTheDocument() + fireEvent.click(screen.getByRole('button', { name: '2. 评分项' })) + expect(screen.getByRole('heading', { name: '评分项' })).toBeInTheDocument() + expect(screen.getByLabelText('评分项名称')).toHaveValue('作品质量') + + fireEvent.click(screen.getByRole('button', { name: '3. 评审与计分' })) + expect(screen.getByRole('heading', { name: '评审与计分' })).toBeInTheDocument() + expect(screen.getByLabelText('最终成绩规则')).toBeInTheDocument() + }) + test('月度方案可添加排序模板并经过影响确认后发布', async () => { const request = createRequest() render() diff --git a/app/performance-survey/PerformanceSurveyAdminConfig.tsx b/app/performance-survey/PerformanceSurveyAdminConfig.tsx index d4fb2919..89c1541d 100644 --- a/app/performance-survey/PerformanceSurveyAdminConfig.tsx +++ b/app/performance-survey/PerformanceSurveyAdminConfig.tsx @@ -170,7 +170,7 @@ function clone(value: T): T { function newTemplateDefinition(): TemplateDefinition { return { - code: '', + code: `template_${Date.now().toString(36)}`, name: '', shortName: '', description: '', @@ -200,16 +200,31 @@ function reviewerSourceLabel(source: ReviewerSource) { }[source] } +function surveyTypeLabel(type: TemplateDefinition['surveyType']) { + return { + person_period: '人员周期评分', + visual_case: '视觉案例评分', + item_course: '事项 / 课程评分', + }[type] +} + export function PerformanceSurveyAdminConfig({ mode, request, onDirtyChange, + month: controlledMonth, + onMonthChange, + onNavigate, }: { mode: PerformanceSurveyAdminMode request: RequestFn onDirtyChange?: (dirty: boolean) => void + month?: string + onMonthChange?: (month: string) => void + onNavigate?: (mode: PerformanceSurveyAdminMode | 'launch') => void }) { - const [month, setMonth] = useState(currentMonth()) + const [internalMonth, setInternalMonth] = useState(controlledMonth || currentMonth()) + const month = controlledMonth || internalMonth const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) @@ -267,7 +282,8 @@ export function PerformanceSurveyAdminConfig({ if (!confirmDiscard('切换月份会放弃当前未保存修改,确定继续吗?')) return setDirtyState(false) setNotice(null) - setMonth(nextMonth) + if (onMonthChange) onMonthChange(nextMonth) + else setInternalMonth(nextMonth) } const changed = useCallback(async (message: string) => { @@ -291,7 +307,7 @@ export function PerformanceSurveyAdminConfig({ }[mode]}

- {dirty ? '有未保存修改' : '配置按月份查看;已发布版本保持不变'} + {dirty ? `${month} 有未保存修改` : `正在维护 ${month};已发布版本保持不变`}

- {notice &&
{notice}
} + {notice && ( + <> +
+ {notice} +
+
+ {notice} +
+ + )} {error && (
{error} {!data && }
)} - {loading && !data &&
配置加载中...
} + {loading && !data &&
配置加载中...
} {data && (
{mode === 'overview' && ( @@ -319,6 +344,7 @@ export function PerformanceSurveyAdminConfig({ data={data} month={month} request={request} + onNavigate={onNavigate} /> )} {mode === 'positions' && ( @@ -378,18 +404,84 @@ function AdminOverviewWorkspace({ data, month, request, + onNavigate, }: { data: AdminConfig month: string request: RequestFn + onNavigate?: (mode: PerformanceSurveyAdminMode | 'launch') => void }) { const [audits, setAudits] = useState([]) const [auditError, setAuditError] = useState(null) const [auditLoading, setAuditLoading] = useState(true) - const readyGroups = data.groups.filter((group) => group.status === 'ready').length + const activeGroups = data.groups.filter((group) => group.status !== 'disabled') + const groupsWithMatchingRules = activeGroups.filter((group) => group.rules.some((rule) => rule.isActive)).length const disabledGroups = data.groups.filter((group) => group.status === 'disabled').length const draftTemplates = data.templates.flatMap((template) => template.versions).filter((version) => version.status === 'draft').length const publishedTemplates = data.templates.flatMap((template) => template.versions).filter((version) => version.status === 'published').length + const availablePublishedTemplates = data.templates + .flatMap((template) => template.versions) + .filter((version) => ( + version.status === 'published' + && (!version.effectiveMonth || version.effectiveMonth <= month) + )).length + const effectivePlanCount = activeGroups.filter((group) => group.effectivePlan?.effectiveMonth === month).length + const draftPlanCount = activeGroups.filter((group) => group.draftPlan).length + const hasPeopleIssues = data.issues.unmatched.length > 0 || data.issues.conflicts.length > 0 + const positionsReady = activeGroups.length > 0 && groupsWithMatchingRules === activeGroups.length + const templatesReady = availablePublishedTemplates > 0 + const plansReady = activeGroups.length > 0 && effectivePlanCount === activeGroups.length + const launchReady = positionsReady && templatesReady && plansReady && data.issues.conflicts.length === 0 + const steps = [ + { + id: 'people', + label: '确认人员资料', + status: data.issues.conflicts.length > 0 ? 'blocked' : hasPeopleIssues ? 'attention' : 'done', + summary: data.issues.conflicts.length > 0 + ? `${data.issues.conflicts.length} 人同时匹配多个岗位,必须先处理` + : data.issues.unmatched.length > 0 + ? `${data.issues.unmatched.length} 人待确认:分配岗位,或明确标记为不参与` + : '人员岗位归属没有待处理异常', + action: '处理人员', + target: 'people' as const, + }, + { + id: 'positions', + label: '确认岗位', + status: positionsReady ? 'done' : 'attention', + summary: activeGroups.length === 0 + ? '还没有可用岗位' + : `${groupsWithMatchingRules}/${activeGroups.length} 个在用岗位已完成匹配规则${disabledGroups > 0 ? `,另有 ${disabledGroups} 个已归档` : ''}`, + action: '管理岗位', + target: 'positions' as const, + }, + { + id: 'templates', + label: '准备考核模板', + status: templatesReady ? (draftTemplates > 0 ? 'attention' : 'done') : 'blocked', + summary: templatesReady + ? `${availablePublishedTemplates} 个版本可用于 ${month}${draftTemplates > 0 ? `,${draftTemplates} 个草稿待确认` : ''}` + : `还没有可用于 ${month} 的已发布模板,月度方案无法完成${publishedTemplates > 0 ? `(另有 ${publishedTemplates} 个其它月份版本)` : ''}`, + action: '管理模板', + target: 'templates' as const, + }, + { + id: 'plans', + label: '发布月度方案', + status: plansReady ? 'done' : draftPlanCount > 0 ? 'attention' : 'blocked', + summary: `${effectivePlanCount}/${activeGroups.length} 个在用岗位已有 ${month} 方案${draftPlanCount > 0 ? `,${draftPlanCount} 个草稿待发布` : ''}`, + action: '配置方案', + target: 'plans' as const, + }, + { + id: 'launch', + label: '发起调研', + status: launchReady ? 'ready' : 'blocked', + summary: launchReady ? `${month} 的岗位、模板和方案已可用于发起调研` : '完成上面的必要配置后再发起,避免人员或模板选错', + action: '去发起调研', + target: 'launch' as const, + }, + ] const loadAudits = useCallback(async () => { setAuditLoading(true) @@ -420,49 +512,53 @@ function AdminOverviewWorkspace({

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
维护项当前状态需要处理
岗位{readyGroups}/{data.groups.length} 个岗位已就绪{disabledGroups > 0 ? `${disabledGroups} 个已归档` : '无归档岗位'}
人员未匹配 {data.issues.unmatched.length} 人 0 ? 'text-[#b42318]' : 'text-[#16794b]'}`}> - {data.issues.conflicts.length > 0 ? `重复匹配 ${data.issues.conflicts.length} 人` : '无重复匹配'} -
模板{publishedTemplates} 个已发布版本{draftTemplates > 0 ? `${draftTemplates} 个草稿待处理` : '无待发布草稿'}
月度方案 - {data.groups.filter((group) => group.effectivePlan?.effectiveMonth === month).length} 个岗位本月已有方案 - - {data.groups.filter((group) => group.draftPlan).length} 个岗位有未发布草稿 -
+
+
+

本月上线准备

+

按顺序完成;每一步都可以直接进入对应管理页面。

+
+
    + {steps.map((step, index) => { + const statusLabel = { + done: '已完成', + attention: '待确认', + blocked: '未完成', + ready: '可发起', + }[step.status] + const statusClass = { + done: 'bg-[#eaf7ef] text-[#16794b]', + attention: 'bg-[#fff4da] text-[#7a4b00]', + blocked: 'bg-[#f3f3f3] text-[#5f5e5e]', + ready: 'bg-[#e9efff] text-[#0050cb]', + }[step.status] + return ( +
  1. + +
    +
    +

    {step.label}

    + {statusLabel} +
    +

    {step.summary}

    +
    + +
  2. + ) + })} +
{(data.issues.unmatched.length > 0 || data.issues.conflicts.length > 0) && (
- 发布前请先处理人员分配:未匹配 {data.issues.unmatched.length} 人,重复匹配 {data.issues.conflicts.length} 人。 + “未匹配”不等于必须参与考核。请逐一确认:需要参与的人分配岗位,不参与的人明确标记为“不参与”;重复匹配人员必须先消除冲突。
)} @@ -473,7 +569,7 @@ function AdminOverviewWorkspace({ 刷新
- {auditLoading &&
记录加载中...
} + {auditLoading &&
记录加载中...
} {auditError && (
配置记录暂不可用:{auditError} @@ -886,6 +982,7 @@ function TemplateConfigWorkspace({ || null const [versionId, setVersionId] = useState(selectedVersion?.id || null) const [definition, setDefinition] = useState(() => clone(selectedVersion?.definition || newTemplateDefinition())) + const [editorStep, setEditorStep] = useState<'basics' | 'questions' | 'workflow'>('basics') const [saving, setSaving] = useState(false) const editorRef = useRef(null) @@ -895,6 +992,7 @@ function TemplateConfigWorkspace({ || null setVersionId(nextVersion?.id || null) setDefinition(clone(nextVersion?.definition || newTemplateDefinition())) + setEditorStep('basics') onDirtyChange(false) }, [onDirtyChange, selectedTemplate]) @@ -1036,6 +1134,7 @@ function TemplateConfigWorkspace({ onDirtyChange(false) setVersionId(item.id) setDefinition(clone(item.definition)) + setEditorStep('basics') }} className={`min-h-10 rounded border px-3 text-left text-[12px] font-bold ${versionId === item.id ? 'border-[#0050cb] bg-[#f1f4ff] text-[#0050cb]' : 'border-[#e2e2e2] text-[#5f5e5e]'}`} > @@ -1054,48 +1153,107 @@ function TemplateConfigWorkspace({
)} -
- updateDefinition((current) => ({ ...current, code: value }))} disabled={Boolean(selectedTemplate)} /> - updateDefinition((current) => ({ ...current, name: value }))} disabled={!editable} /> - updateDefinition((current) => ({ ...current, shortName: value }))} disabled={!editable} /> - -