statistics.schema.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { z } from '@hono/zod-openapi';
  2. // 统计项通用Schema
  3. export const StatItemSchema = z.object({
  4. key: z.string().openapi({
  5. description: '统计项键名',
  6. example: '视力残疾'
  7. }),
  8. value: z.number().int().min(0).openapi({
  9. description: '统计数量',
  10. example: 10
  11. }),
  12. percentage: z.number().min(0).max(100).openapi({
  13. description: '占比百分比',
  14. example: 25.5
  15. })
  16. });
  17. // 年龄分组Schema
  18. export const AgeGroupSchema = z.enum(['18-25', '26-35', '36-45', '46+']).openapi({
  19. description: '年龄分组'
  20. });
  21. // 薪资范围分组Schema
  22. export const SalaryRangeSchema = z.enum(['<3000', '3000-5000', '5000-8000', '8000-12000', '12000+']).openapi({
  23. description: '薪资范围分组'
  24. });
  25. // 残疾类型分布响应Schema
  26. export const DisabilityTypeDistributionResponseSchema = z.object({
  27. companyId: z.number().int().positive().openapi({
  28. description: '企业ID',
  29. example: 1
  30. }),
  31. stats: z.array(StatItemSchema).openapi({
  32. description: '残疾类型分布统计'
  33. }),
  34. total: z.number().int().min(0).openapi({
  35. description: '总人数',
  36. example: 100
  37. })
  38. });
  39. // 性别分布响应Schema
  40. export const GenderDistributionResponseSchema = z.object({
  41. companyId: z.number().int().positive().openapi({
  42. description: '企业ID',
  43. example: 1
  44. }),
  45. stats: z.array(StatItemSchema).openapi({
  46. description: '性别分布统计'
  47. }),
  48. total: z.number().int().min(0).openapi({
  49. description: '总人数',
  50. example: 100
  51. })
  52. });
  53. // 年龄分布响应Schema
  54. export const AgeDistributionResponseSchema = z.object({
  55. companyId: z.number().int().positive().openapi({
  56. description: '企业ID',
  57. example: 1
  58. }),
  59. stats: z.array(
  60. StatItemSchema.extend({
  61. key: AgeGroupSchema
  62. })
  63. ).openapi({
  64. description: '年龄分布统计'
  65. }),
  66. total: z.number().int().min(0).openapi({
  67. description: '总人数',
  68. example: 100
  69. })
  70. });
  71. // 户籍分布项Schema(省市级)
  72. export const HouseholdStatItemSchema = StatItemSchema.extend({
  73. province: z.string().openapi({
  74. description: '省份',
  75. example: '江苏省'
  76. }),
  77. city: z.string().optional().openapi({
  78. description: '城市',
  79. example: '南京市'
  80. })
  81. });
  82. // 户籍分布响应Schema
  83. export const HouseholdDistributionResponseSchema = z.object({
  84. companyId: z.number().int().positive().openapi({
  85. description: '企业ID',
  86. example: 1
  87. }),
  88. stats: z.array(HouseholdStatItemSchema).openapi({
  89. description: '户籍分布统计'
  90. }),
  91. total: z.number().int().min(0).openapi({
  92. description: '总人数',
  93. example: 100
  94. })
  95. });
  96. // 在职状态分布响应Schema
  97. export const JobStatusDistributionResponseSchema = z.object({
  98. companyId: z.number().int().positive().openapi({
  99. description: '企业ID',
  100. example: 1
  101. }),
  102. stats: z.array(StatItemSchema).openapi({
  103. description: '在职状态分布统计'
  104. }),
  105. total: z.number().int().min(0).openapi({
  106. description: '总人数',
  107. example: 100
  108. })
  109. });
  110. // 薪资分布响应Schema
  111. export const SalaryDistributionResponseSchema = z.object({
  112. companyId: z.number().int().positive().openapi({
  113. description: '企业ID',
  114. example: 1
  115. }),
  116. stats: z.array(
  117. StatItemSchema.extend({
  118. key: SalaryRangeSchema
  119. })
  120. ).openapi({
  121. description: '薪资分布统计'
  122. }),
  123. total: z.number().int().min(0).openapi({
  124. description: '总人数',
  125. example: 100
  126. })
  127. });
  128. // 通用查询参数Schema
  129. export const StatisticsQuerySchema = z.object({
  130. companyId: z.coerce.number().int().positive().optional().openapi({
  131. description: '企业ID(从认证用户获取,可覆盖)',
  132. example: 1
  133. })
  134. });
  135. // 类型定义
  136. export type StatItem = z.infer<typeof StatItemSchema>;
  137. export type AgeGroup = z.infer<typeof AgeGroupSchema>;
  138. export type SalaryRange = z.infer<typeof SalaryRangeSchema>;
  139. export type DisabilityTypeDistributionResponse = z.infer<typeof DisabilityTypeDistributionResponseSchema>;
  140. export type GenderDistributionResponse = z.infer<typeof GenderDistributionResponseSchema>;
  141. export type AgeDistributionResponse = z.infer<typeof AgeDistributionResponseSchema>;
  142. export type HouseholdStatItem = z.infer<typeof HouseholdStatItemSchema>;
  143. export type HouseholdDistributionResponse = z.infer<typeof HouseholdDistributionResponseSchema>;
  144. export type JobStatusDistributionResponse = z.infer<typeof JobStatusDistributionResponseSchema>;
  145. export type SalaryDistributionResponse = z.infer<typeof SalaryDistributionResponseSchema>;
  146. export type StatisticsQuery = z.infer<typeof StatisticsQuerySchema>;