stock-data.entity.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
  2. import { z } from '@hono/zod-openapi';
  3. @Entity('stock_data')
  4. export class StockData {
  5. @PrimaryGeneratedColumn({ unsigned: true })
  6. id!: number;
  7. @Column({ name: 'code', type: 'varchar', length: 255, nullable: false, comment: '股票代码' })
  8. code!: string;
  9. @Column({ name: 'data', type: 'json', nullable: false, comment: '股票数据' })
  10. data!: Record<string, any>;
  11. @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  12. createdAt!: Date;
  13. @Column({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP' })
  14. updatedAt!: Date;
  15. }
  16. export const StockDataSchema = z.object({
  17. id: z.number().int().positive().openapi({ description: 'ID', example: 1 }),
  18. code: z.string().max(255).openapi({ description: '股票代码', example: '001339' }),
  19. data: z.record(z.any()).openapi({
  20. description: '股票数据',
  21. example: {
  22. date: '2025-05-21',
  23. open: 15.68,
  24. close: 16.25,
  25. high: 16.50,
  26. low: 15.50,
  27. volume: 1250000
  28. }
  29. }),
  30. createdAt: z.date().openapi({ description: '创建时间', example: '2025-05-21T16:44:36Z' }),
  31. updatedAt: z.date().openapi({ description: '更新时间', example: '2025-05-21T21:22:06Z' })
  32. });
  33. export const CreateStockDataDto = z.object({
  34. code: z.string().max(255).openapi({ description: '股票代码', example: '001339' }),
  35. data: z.record(z.any()).openapi({
  36. description: '股票数据',
  37. example: {
  38. date: '2025-05-21',
  39. open: 15.68,
  40. close: 16.25,
  41. high: 16.50,
  42. low: 15.50,
  43. volume: 1250000
  44. }
  45. })
  46. });
  47. export const UpdateStockDataDto = z.object({
  48. code: z.string().max(255).optional().openapi({ description: '股票代码', example: '001339' }),
  49. data: z.record(z.any()).optional().openapi({
  50. description: '股票数据',
  51. example: {
  52. date: '2025-05-21',
  53. open: 15.68,
  54. close: 16.25,
  55. high: 16.50,
  56. low: 15.50,
  57. volume: 1250000
  58. }
  59. })
  60. });