feat: add recruitment fair statistics dashboard

This commit is contained in:
2026-07-23 18:13:30 +08:00
parent b4b17f2ada
commit 1c9216dbbb
2 changed files with 271 additions and 151 deletions

View File

@@ -1,209 +1,284 @@
import React, { useEffect, useMemo, useState } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { import {
Button,
Card, Card,
Col, Col,
DatePicker, DatePicker,
Empty, Empty,
Row, Row,
Segmented, Segmented,
Select,
Spin, Spin,
Statistic, Statistic,
Table, Table,
Typography,
message, message,
} from 'antd'; } from 'antd';
import { ArrowDownOutlined, ArrowUpOutlined } from '@ant-design/icons'; import { InfoCircleOutlined } from '@ant-design/icons';
import { PageContainer } from '@ant-design/pro-components'; import { PageContainer } from '@ant-design/pro-components';
import { Line } from '@ant-design/charts';
import type { ColumnsType } from 'antd/es/table'; import type { ColumnsType } from 'antd/es/table';
import { getOutdoorFairStatistics } from '@/services/jobportal/outdoorFair'; import { getPublicJobFairList } from '@/services/jobfair/publicJobFair';
import type { import { getOutdoorFairList } from '@/services/jobportal/outdoorFair';
OutdoorFairStatisticsResult, import {
OutdoorFairStatisticsSeriesItem, getFairStatisticsSummary,
} from '@/services/jobportal/outdoorFair'; type FairStatisticsFairItem,
type FairStatisticsSummary,
type RecruitmentFairType,
} from '@/services/jobfair/fairStatistics';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
const { Text } = Typography;
type Granularity = 'day' | 'week' | 'month' | 'year'; type StatisticsScope = 'single' | 'range';
const GRAN_OPTIONS: { label: string; value: Granularity }[] = [ interface FairOption {
{ label: '按日', value: 'day' }, value: string;
{ label: '按周', value: 'week' }, label: string;
{ label: '按月', value: 'month' },
{ label: '按年', value: 'year' },
];
const formatBound = (value: any, suffix: string): string | undefined => {
if (value && typeof value.format === 'function') {
return `${value.format('YYYY-MM-DD')} ${suffix}`;
} }
return undefined;
}; const formatDate = (value: any): string | undefined =>
value && typeof value.format === 'function' ? value.format('YYYY-MM-DD') : undefined;
const FairStatistics: React.FC = () => { const FairStatistics: React.FC = () => {
const [granularity, setGranularity] = useState<Granularity>('month'); const [fairType, setFairType] = useState<RecruitmentFairType>('online');
const [scope, setScope] = useState<StatisticsScope>('single');
const [fairOptions, setFairOptions] = useState<FairOption[]>([]);
const [selectedFairId, setSelectedFairId] = useState<string>();
const [dateRange, setDateRange] = useState<any>(null); const [dateRange, setDateRange] = useState<any>(null);
const [loading, setLoading] = useState(false); const [loadingFairs, setLoadingFairs] = useState(false);
const [result, setResult] = useState<OutdoorFairStatisticsResult | null>(null); const [loadingSummary, setLoadingSummary] = useState(false);
const [summary, setSummary] = useState<FairStatisticsSummary>();
const fetchStats = async (gran: Granularity, range: any) => { const interactionLabel = fairType === 'online' ? '投递岗位数' : '签到数';
setLoading(true); const interactionUnit = fairType === 'online' ? '个' : '人次';
const loadFairOptions = useCallback(async (type: RecruitmentFairType) => {
setLoadingFairs(true);
try { try {
const res = await getOutdoorFairStatistics({ if (type === 'online') {
granularity: gran, const res = await getPublicJobFairList({ pageNum: 1, pageSize: 1000, jobFairType: '1' });
startTime: formatBound(range?.[0], '00:00:00'), if (res.code !== 200) {
endTime: formatBound(range?.[1], '23:59:59'), message.error(res.msg || '线上招聘会列表加载失败');
}); setFairOptions([]);
if (res?.code === 200 && res.data) { return;
setResult(res.data); }
setFairOptions(
(res.rows || []).map((item) => ({
value: String(item.jobFairId),
label: `${item.jobFairTitle}${item.jobFairStartTime ? `${item.jobFairStartTime}` : ''}`,
})),
);
} else { } else {
message.error(res?.msg || '统计失败'); const res = await getOutdoorFairList({ current: 1, pageSize: 1000 });
if (res.code !== 200) {
message.error(res.msg || '户外招聘会列表加载失败');
setFairOptions([]);
return;
} }
} catch (e) { setFairOptions(
message.error('统计失败'); (res.rows || []).map((item) => ({
value: String(item.id),
label: `${item.title}${item.holdTime ? `${item.holdTime}` : ''}`,
})),
);
}
} catch {
message.error('招聘会列表加载失败,请稍后重试');
setFairOptions([]);
} finally { } finally {
setLoading(false); setLoadingFairs(false);
} }
}; }, []);
// 粒度或日期变化即查询;区间半选(只选了一端)不查询,避免中途无效查询
useEffect(() => { useEffect(() => {
const complete = dateRange && dateRange[0] && dateRange[1]; setSelectedFairId(undefined);
const empty = !dateRange || (!dateRange[0] && !dateRange[1]); setDateRange(null);
if (complete) { setSummary(undefined);
fetchStats(granularity, dateRange); loadFairOptions(fairType);
} else if (empty) { }, [fairType, loadFairOptions]);
fetchStats(granularity, null);
const queryReady = useMemo(() => {
if (scope === 'single') return Boolean(selectedFairId);
return Boolean(dateRange?.[0] && dateRange?.[1]);
}, [dateRange, scope, selectedFairId]);
const loadSummary = useCallback(async () => {
if (!queryReady) {
setSummary(undefined);
return;
} }
// eslint-disable-next-line react-hooks/exhaustive-deps setLoadingSummary(true);
}, [granularity, dateRange]); try {
const res = await getFairStatisticsSummary({
const chartData = useMemo(() => { fairType,
if (!result?.series) return []; fairId: scope === 'single' ? selectedFairId : undefined,
const rows: { time: string; category: string; value: number }[] = []; startDate: scope === 'range' ? formatDate(dateRange?.[0]) : undefined,
result.series.forEach((item: OutdoorFairStatisticsSeriesItem) => { endDate: scope === 'range' ? formatDate(dateRange?.[1]) : undefined,
rows.push({ time: item.time, category: '招聘会数', value: item.fairCount });
rows.push({ time: item.time, category: '参会单位数', value: item.companyCount });
rows.push({ time: item.time, category: '职位数', value: item.jobCount });
}); });
return rows; if (res.code === 200 && res.data) {
}, [result]); setSummary(res.data);
} else {
setSummary(undefined);
message.error(res.msg || '统计数据加载失败');
}
} catch {
setSummary(undefined);
message.error('统计数据加载失败,请稍后重试');
} finally {
setLoadingSummary(false);
}
}, [dateRange, fairType, queryReady, scope, selectedFairId]);
const columns: ColumnsType<OutdoorFairStatisticsSeriesItem> = [ useEffect(() => {
{ title: '时间', dataIndex: 'time', width: 140 }, loadSummary();
{ title: '招聘会数', dataIndex: 'fairCount', width: 120 }, }, [loadSummary]);
{ title: '参会单位数', dataIndex: 'companyCount', width: 120 },
{ title: '职位数', dataIndex: 'jobCount', width: 120 }, const columns: ColumnsType<FairStatisticsFairItem> = useMemo(
() => [
{ title: '招聘会名称', dataIndex: 'fairTitle', ellipsis: true },
{ title: '起始时间', dataIndex: 'startTime', width: 180, render: (value) => value || '--' },
{ title: '参会单位数', dataIndex: 'companyCount', width: 110, align: 'right' },
{ title: '职位数', dataIndex: 'jobCount', width: 90, align: 'right' },
{ title: '需求人数', dataIndex: 'demandCount', width: 100, align: 'right' },
{ title: interactionLabel, dataIndex: 'interactionCount', width: 120, align: 'right' },
],
[interactionLabel],
);
const statisticsCards = [
{ title: '参会单位数', value: summary?.companyCount ?? 0, suffix: '家' },
{ title: '职位数', value: summary?.jobCount ?? 0, suffix: '个' },
{ title: '需求人数', value: summary?.demandCount ?? 0, suffix: '人' },
{ title: interactionLabel, value: summary?.interactionCount ?? 0, suffix: interactionUnit },
]; ];
return ( return (
<PageContainer <PageContainer
header={{ title: '招聘会数据统计' }} header={{ title: '招聘会数据统计' }}
content="按年/周/月/日维度统计时间区间内的招聘会趋势,含累计发布招聘会数及同比、环比。" content="分别统计线上招聘会与户外招聘会;可查看单场招聘会,或按招聘会起始时间汇总一个时间段。"
> >
<Card style={{ marginBottom: 16 }}> <Card style={{ marginBottom: 16 }}>
<Row gutter={16} align="middle"> <Row gutter={[16, 16]} align="middle">
<Col> <Col>
<span style={{ marginRight: 8 }}></span> <Button.Group>
<Button
type={fairType === 'online' ? 'primary' : 'default'}
onClick={() => setFairType('online')}
>
线
</Button>
<Button
type={fairType === 'outdoor' ? 'primary' : 'default'}
onClick={() => setFairType('outdoor')}
>
</Button>
</Button.Group>
</Col>
<Col>
<span style={{ marginRight: 8 }}></span>
<Segmented <Segmented
value={granularity} value={scope}
onChange={(v) => setGranularity(v as Granularity)} options={[
options={GRAN_OPTIONS} { label: '统计单场', value: 'single' },
{ label: '按起始时间统计', value: 'range' },
]}
onChange={(value) => {
setScope(value as StatisticsScope);
setSummary(undefined);
}}
/> />
</Col> </Col>
<Col flex="auto"> <Col flex="auto">
<span style={{ marginRight: 8, marginLeft: 16 }}></span> {scope === 'single' ? (
<Select
allowClear
showSearch
placeholder={`请选择一场${fairType === 'online' ? '线上' : '户外'}招聘会`}
optionFilterProp="label"
loading={loadingFairs}
value={selectedFairId}
options={fairOptions}
onChange={(value) => setSelectedFairId(value)}
style={{ width: '100%', minWidth: 320 }}
/>
) : (
<RangePicker <RangePicker
value={dateRange} value={dateRange}
onChange={(v) => setDateRange(v)} onChange={(value) => setDateRange(value)}
style={{ width: 360 }} style={{ width: '100%', minWidth: 320 }}
placeholder={['起始日期', '结束日期']}
/> />
)}
</Col> </Col>
</Row> </Row>
</Card> </Card>
<Spin spinning={loading}> <Spin spinning={loadingSummary}>
{result ? ( <Card
<> title={
<Row gutter={16} style={{ marginBottom: 16 }}> summary
<Col span={8}> ? `统计结果(共 ${summary.fairCount}${fairType === 'online' ? '线上' : '户外'}招聘会)`
<Card> : '统计结果'
<Statistic title="累计发布招聘会数" value={result.totals.fairCount} /> }
<div style={{ marginTop: 8 }}> style={{ marginBottom: 16 }}
<RateText label="同比" rate={result.yoy?.rate} /> >
<span style={{ marginLeft: 16 }}> {queryReady ? (
<RateText label="环比" rate={result.mom?.rate} /> <Row gutter={[16, 16]}>
</span> {statisticsCards.map((item) => (
</div> <Col key={item.title} xs={24} sm={12} lg={6}>
</Card> <Card
</Col> size="small"
<Col span={8}> style={{ background: item.title === interactionLabel ? '#f0f5ff' : '#fafafa' }}
<Card> >
<Statistic title="参会单位数" value={result.totals.companyCount} /> <Statistic title={item.title} value={item.value} suffix={item.suffix} />
</Card>
</Col>
<Col span={8}>
<Card>
<Statistic title="职位数" value={result.totals.jobCount} />
</Card> </Card>
</Col> </Col>
))}
</Row> </Row>
<Card title="招聘会趋势" style={{ marginBottom: 16 }} bodyStyle={{ padding: 12 }}>
{chartData.length > 0 ? (
<Line
height={320}
data={chartData}
xField="time"
yField="value"
seriesField="category"
smooth
legend={{ position: 'bottom' }}
tooltip={{
fields: ['value'],
}}
/>
) : ( ) : (
<Empty description="所选区间无数据" /> <Empty
description={
scope === 'single' ? '请选择一场招聘会' : '请选择完整的起始日期和结束日期'
}
/>
)} )}
</Card> </Card>
<Card title="分时段明细" bordered={false}> {summary && (
<Table<OutdoorFairStatisticsSeriesItem> <Card title="涉及招聘会明细" style={{ marginBottom: 16 }} bodyStyle={{ paddingTop: 8 }}>
rowKey="time" <Table<FairStatisticsFairItem>
dataSource={result.series || []} rowKey="fairId"
columns={columns} columns={columns}
dataSource={summary.fairs || []}
pagination={false} pagination={false}
size="small" size="small"
scroll={{ x: 860 }}
/> />
</Card> </Card>
</>
) : (
<Empty description="暂无数据" />
)} )}
</Spin> </Spin>
<Card
size="small"
title={
<span>
<InfoCircleOutlined style={{ color: '#1677ff', marginRight: 8 }} />
</span>
}
>
<Row gutter={[24, 8]}>
<Col xs={24} lg={12}>
1
</Col>
<Col xs={24} lg={12}>
{fairType === 'online'
? '线上招聘会统计投递岗位数,即本场有效招聘会岗位中至少有一条有效投递记录的岗位数。'
: '户外招聘会不提供报名投递简历,统计现场签到记录数,不显示投递岗位数。'}
</Col>
</Row>
</Card>
</PageContainer> </PageContainer>
); );
}; };
const RateText: React.FC<{ label: string; rate?: number | null }> = ({ label, rate }) => {
if (rate === null || rate === undefined) {
return (
<Text type="secondary">
{label}--
</Text>
);
}
const up = rate >= 0;
const color = up ? '#cf1322' : '#3f8600';
const pct = `${(rate * 100).toFixed(1)}%`;
return (
<Text style={{ color }}>
{label}
{up ? <ArrowUpOutlined /> : <ArrowDownOutlined />} {pct}
</Text>
);
};
export default FairStatistics; export default FairStatistics;

View File

@@ -0,0 +1,45 @@
import { request } from '@umijs/max';
const BASE_URL = '/api/cms/fair-statistics';
export type RecruitmentFairType = 'online' | 'outdoor';
export interface FairStatisticsFairItem {
fairId: string;
fairTitle: string;
startTime?: string;
companyCount: number;
jobCount: number;
demandCount: number;
/** 线上为投递岗位数,户外为签到数。 */
interactionCount: number;
}
export interface FairStatisticsSummary {
fairType: RecruitmentFairType;
fairCount: number;
companyCount: number;
jobCount: number;
demandCount: number;
interactionCount: number;
fairs: FairStatisticsFairItem[];
}
export interface FairStatisticsSummaryParams {
fairType: RecruitmentFairType;
/** 传该值时统计一场招聘会。 */
fairId?: string;
/** 与 fairId 二选一,按招聘会起始时间统计。 */
startDate?: string;
endDate?: string;
}
export async function getFairStatisticsSummary(params: FairStatisticsSummaryParams) {
return request<{ code: number; msg?: string; data?: FairStatisticsSummary }>(
`${BASE_URL}/summary`,
{
method: 'GET',
params,
},
);
}