| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import { z } from '@hono/zod-openapi';
- // 统计项通用Schema
- export const StatItemSchema = z.object({
- key: z.string().openapi({
- description: '统计项键名',
- example: '视力残疾'
- }),
- value: z.number().int().min(0).openapi({
- description: '统计数量',
- example: 10
- }),
- percentage: z.number().min(0).max(100).openapi({
- description: '占比百分比',
- example: 25.5
- })
- });
- // 年龄分组Schema
- export const AgeGroupSchema = z.enum(['18-25', '26-35', '36-45', '46+']).openapi({
- description: '年龄分组'
- });
- // 薪资范围分组Schema
- export const SalaryRangeSchema = z.enum(['<3000', '3000-5000', '5000-8000', '8000-12000', '12000+']).openapi({
- description: '薪资范围分组'
- });
- // 残疾类型分布响应Schema
- export const DisabilityTypeDistributionResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- stats: z.array(StatItemSchema).openapi({
- description: '残疾类型分布统计'
- }),
- total: z.number().int().min(0).openapi({
- description: '总人数',
- example: 100
- })
- });
- // 性别分布响应Schema
- export const GenderDistributionResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- stats: z.array(StatItemSchema).openapi({
- description: '性别分布统计'
- }),
- total: z.number().int().min(0).openapi({
- description: '总人数',
- example: 100
- })
- });
- // 年龄分布响应Schema
- export const AgeDistributionResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- stats: z.array(
- StatItemSchema.extend({
- key: AgeGroupSchema
- })
- ).openapi({
- description: '年龄分布统计'
- }),
- total: z.number().int().min(0).openapi({
- description: '总人数',
- example: 100
- })
- });
- // 户籍分布项Schema(省市级)
- export const HouseholdStatItemSchema = StatItemSchema.extend({
- province: z.string().openapi({
- description: '省份',
- example: '江苏省'
- }),
- city: z.string().optional().openapi({
- description: '城市',
- example: '南京市'
- })
- });
- // 户籍分布响应Schema
- export const HouseholdDistributionResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- stats: z.array(HouseholdStatItemSchema).openapi({
- description: '户籍分布统计'
- }),
- total: z.number().int().min(0).openapi({
- description: '总人数',
- example: 100
- })
- });
- // 在职状态分布响应Schema
- export const JobStatusDistributionResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- stats: z.array(StatItemSchema).openapi({
- description: '在职状态分布统计'
- }),
- total: z.number().int().min(0).openapi({
- description: '总人数',
- example: 100
- })
- });
- // 薪资分布响应Schema
- export const SalaryDistributionResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- stats: z.array(
- StatItemSchema.extend({
- key: SalaryRangeSchema
- })
- ).openapi({
- description: '薪资分布统计'
- }),
- total: z.number().int().min(0).openapi({
- description: '总人数',
- example: 100
- })
- });
- // ============== 统计卡片相关 Schema ==============
- // 简化版本:只返回当前统计数据,不包含历史对比数据
- // 在职人数统计响应Schema(简化版)
- export const EmploymentCountResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- count: z.number().int().min(0).openapi({
- description: '在职人数',
- example: 24
- })
- });
- // 平均薪资统计响应Schema(简化版)
- export const AverageSalaryResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- average: z.number().min(0).openapi({
- description: '平均薪资',
- example: 4650
- })
- });
- // 在职率统计响应Schema(简化版)
- export const EmploymentRateResponseSchema = z.object({
- companyId: z.number().int().positive().openapi({
- description: '企业ID',
- example: 1
- }),
- rate: z.number().min(0).max(100).openapi({
- description: '在职率(百分比)',
- example: 92
- })
- });
- // ============== 查询参数 Schema ==============
- // 年月查询参数Schema(用于筛选特定年月的统计数据)
- export const YearMonthQuerySchema = z.object({
- year: z.coerce.number().int().min(2020).max(2030).optional().openapi({
- description: '年份(可选,默认为当前年份)',
- example: 2026
- }),
- month: z.coerce.number().int().min(1).max(12).optional().openapi({
- description: '月份(可选,默认为当前月份)',
- example: 1
- })
- });
- // 通用查询参数Schema(已移除companyId,企业ID强制从认证token获取)
- export const StatisticsQuerySchema = z.object({});
- // 企业统计查询参数Schema(简化版:无查询参数,只返回当前数据)
- export const EnterpriseStatisticsQuerySchema = z.object({});
- // 类型定义
- export type StatItem = z.infer<typeof StatItemSchema>;
- export type AgeGroup = z.infer<typeof AgeGroupSchema>;
- export type SalaryRange = z.infer<typeof SalaryRangeSchema>;
- export type DisabilityTypeDistributionResponse = z.infer<typeof DisabilityTypeDistributionResponseSchema>;
- export type GenderDistributionResponse = z.infer<typeof GenderDistributionResponseSchema>;
- export type AgeDistributionResponse = z.infer<typeof AgeDistributionResponseSchema>;
- export type HouseholdStatItem = z.infer<typeof HouseholdStatItemSchema>;
- export type HouseholdDistributionResponse = z.infer<typeof HouseholdDistributionResponseSchema>;
- export type JobStatusDistributionResponse = z.infer<typeof JobStatusDistributionResponseSchema>;
- export type SalaryDistributionResponse = z.infer<typeof SalaryDistributionResponseSchema>;
- export type StatisticsQuery = z.infer<typeof StatisticsQuerySchema>;
- export type YearMonthQuery = z.infer<typeof YearMonthQuerySchema>;
- export type EmploymentCountResponse = z.infer<typeof EmploymentCountResponseSchema>;
- export type AverageSalaryResponse = z.infer<typeof AverageSalaryResponseSchema>;
- export type EmploymentRateResponse = z.infer<typeof EmploymentRateResponseSchema>;
|