You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

476 lines
14 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
// ============================================
// 基础数据表
// ============================================
// 交易日历表
model TradeDate {
id Int @id @default(autoincrement())
date DateTime @unique @db.Date
week Int @default(0)
isTrade Boolean @default(true) @map("is_trade")
createdAt DateTime @default(now()) @map("created_at")
@@index([date])
@@index([isTrade])
@@map("trade_dates")
}
// 股票基础信息表(新表)
model StockBasic {
id String @id @default(uuid())
code String @unique
name String
// 东财行业分类
blemind2 String? @map("blemind2") // 东财行业指数2级
blemind3 String? @map("blemind3") // 东财行业指数3级
// 上市信息
listDate DateTime? @map("list_date") // 首发上市日期
tradeDays Int @default(0) @map("trade_days") // 上市天数
// 机构持股
agenciesHold Float? @map("agencies_hold") // 机构持股比例(%)
// 市场信息
market String? // 所属市场(SH/SZ/BJ)
industry String? // 所属行业
// 关联数据
dailyQuotes StockDailyQuote[]
momentumRecords StockMomentum[]
limitRecords StockLimit[]
newRecords StockNewRecord[]
// 时间戳
updatedAt DateTime @updatedAt @map("updated_at")
createdAt DateTime @default(now()) @map("created_at")
@@index([code])
@@index([blemind2])
@@index([blemind3])
@@index([listDate])
@@map("stock_basics")
}
// ============================================
// 交易数据表
// ============================================
// 股票日行情数据表(基础数据,从数据服务获取)
model StockDailyQuote {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
stock StockBasic @relation(fields: [stockCode], references: [code], onDelete: Cascade)
tradeDay DateTime @map("trade_day") @db.Date
// 基础价格数据
open Float // 开盘价
close Float // 收盘价
high Float // 最高价
low Float // 最低价
// 成交量额
volume BigInt // 成交量
amount BigInt // 成交额
// 涨跌幅
differrange Float // 当日涨跌幅(%)
// 状态标记
isLimit Boolean @default(false) @map("is_limit") // 是否涨停
isDrop Boolean @default(false) @map("is_drop") // 是否跌停
// 关联的多周期涨跌幅
returns StockReturn[]
createdAt DateTime @default(now()) @map("created_at")
@@unique([stockCode, tradeDay])
@@index([stockCode])
@@index([tradeDay])
@@index([stockCode, tradeDay])
@@map("stock_daily_quotes")
}
// 股票多周期涨跌幅表(计算数据)
model StockReturn {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
quoteId Int @map("quote_id")
quote StockDailyQuote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
tradeDay DateTime @map("trade_day") @db.Date
// 多周期涨跌幅
period Int // 周期(1,3,5,10,15,20,30,60)
returnRate Float @map("return_rate") // 涨跌幅(%)
// 计算来源
basePrice Float @map("base_price") // 基准价格(N日前收盘价)
createdAt DateTime @default(now()) @map("created_at")
@@unique([stockCode, tradeDay, period])
@@index([stockCode])
@@index([tradeDay])
@@index([period])
@@index([stockCode, tradeDay])
@@map("stock_returns")
}
// 涨停跌停记录表
model StockLimit {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
stock StockBasic @relation(fields: [stockCode], references: [code], onDelete: Cascade)
tradeDay DateTime @map("trade_day") @db.Date
blemind2 String? @map("blemind2")
isLimit Boolean @default(false) @map("is_limit") // 是否涨停
isDrop Boolean @default(false) @map("is_drop") // 是否跌停
createdAt DateTime @default(now()) @map("created_at")
@@unique([stockCode, tradeDay])
@@index([stockCode])
@@index([tradeDay])
@@index([blemind2])
@@map("stock_limits")
}
// 新高新低记录表
model StockNewRecord {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
stock StockBasic @relation(fields: [stockCode], references: [code], onDelete: Cascade)
tradeDay DateTime @map("trade_day") @db.Date
blemind2 String? @map("blemind2")
isHigh Boolean @default(false) @map("is_high") // 是否300天新高
isLow Boolean @default(false) @map("is_low") // 是否300天新低
daysToHigh Int @default(0) @map("days_to_high") // 距离前高天数
daysToLow Int @default(0) @map("days_to_low") // 距离前低天数
createdAt DateTime @default(now()) @map("created_at")
@@unique([stockCode, tradeDay])
@@index([stockCode])
@@index([tradeDay])
@@index([blemind2])
@@map("stock_new_records")
}
// ============================================
// 动量计算结果表
// ============================================
// 动量个股表(计算结果)
model StockMomentum {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
stock StockBasic @relation(fields: [stockCode], references: [code], onDelete: Cascade)
tradeDay DateTime @map("trade_day") @db.Date
// 动量排名信息
sort Int // 排名
type Int // 动量数据类型(1,3,5,10,15,20,30,60日)
// 股票基本信息(冗余存储,便于查询)
name String?
blemind2 String? @map("blemind2")
blemind3 String? @map("blemind3")
// 价格数据
open Float? // 开盘价
close Float? // 收盘价
differrange Float? @map("differrange") // 当日涨跌幅
// 多周期涨跌幅
differrange10 Float? @map("differrange10")
differrange20 Float? @map("differrange20")
differrange60 Float? @map("differrange60")
// 最大回撤
backdifferrange10 Float? @map("backdifferrange10")
backdifferrange20 Float? @map("backdifferrange20")
backdifferrange60 Float? @map("backdifferrange60")
// 筛选条件(记录当时的数据)
tradeDays Int? @map("trade_days") // 上市天数
agenciesHold Float? @map("agencies_hold") // 机构持股比例
createdAt DateTime @default(now()) @map("created_at")
@@unique([stockCode, tradeDay, type])
@@index([stockCode])
@@index([tradeDay])
@@index([type])
@@index([tradeDay, type])
@@index([blemind2, tradeDay, type])
@@index([sort])
@@map("stock_momentum")
}
// 板块动量结果表
model SectorMomentum {
id Int @id @default(autoincrement())
tradeDay DateTime @map("trade_day") @db.Date
blemind2 String @map("blemind2") // 所属东财行业指数2级
// 动量计算结果
stocksCount Int @map("stocks_count") // 动量个股数量
totalStocks Int @map("total_stocks") // 板块总个股数
trendValue Float @map("trend_value") // 动量值 = (stocksCount^2) / totalStocks
trendValueChange Float? @map("trend_value_change") // 动量值变化
// 排名信息
sort Int // 板块排名
sortChange Int @map("sort_change") // 板块排名变化
// 动量类型
type Int // 动量数据类型(1,3,5,10,15,20,30,60日)
// 昨日数据快照(用于计算变化)
lastTrendValue Float? @map("last_trend_value")
lastSort Int? @map("last_sort")
createdAt DateTime @default(now()) @map("created_at")
@@unique([tradeDay, blemind2, type])
@@index([tradeDay])
@@index([blemind2])
@@index([type])
@@index([tradeDay, type])
@@index([sort])
@@map("sector_momentum")
}
// ============================================
// 系统配置和任务表
// ============================================
// 数据同步任务记录
model DataSyncTask {
id Int @id @default(autoincrement())
taskType String @map("task_type") // 任务类型(daily_quote/momentum/etc)
tradeDay DateTime? @map("trade_day") @db.Date
status String // pending/running/completed/failed
startTime DateTime? @map("start_time")
endTime DateTime? @map("end_time")
message String? // 执行信息/错误信息
recordCount Int? @map("record_count") // 处理记录数
createdAt DateTime @default(now()) @map("created_at")
@@index([taskType])
@@index([status])
@@index([tradeDay])
@@map("data_sync_tasks")
}
// ============================================
// 保留原有表(保持兼容性)
// ============================================
// 市场指数
model MarketIndex {
id Int @id @default(autoincrement())
name String @unique
code String @unique
current Float
change Float
changePercent Float
volume BigInt
turnover BigInt
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
@@index([code])
@@map("market_indices")
}
// 版块信息(系统板块)- 保留原表名
model Sector {
id String @id @default(uuid())
name String @unique
code String @unique
stocks Stock[]
quotes SectorQuote[]
klines SectorKLine[]
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
@@index([code])
@@map("sectors")
}
// 版块行情(兼容原表)
model SectorQuote {
id Int @id @default(autoincrement())
sectorCode String @map("sector_code")
sector Sector @relation(fields: [sectorCode], references: [code])
current Float
change Float
changePercent Float
volume BigInt
turnover BigInt
momentumScore Float @default(50)
rank Int @default(0)
previousRank Int @default(0) @map("previous_rank")
quoteTime DateTime @map("quote_time")
@@index([sectorCode])
@@index([quoteTime])
@@map("sector_quotes")
}
// 版块K线数据兼容原表
model SectorKLine {
id Int @id @default(autoincrement())
sectorCode String @map("sector_code")
sector Sector @relation(fields: [sectorCode], references: [code])
period String // day/week/month
date DateTime
open Float
high Float
low Float
close Float
volume BigInt
@@unique([sectorCode, period, date])
@@index([sectorCode])
@@index([date])
@@map("sector_klines")
}
// 股票信息(兼容原表)
model Stock {
id String @id @default(uuid())
code String @unique
name String
sectorCode String? @map("sector_code")
sector Sector? @relation(fields: [sectorCode], references: [code])
marketCap BigInt? @map("market_cap")
pe Float?
pb Float?
quotes StockQuote[]
klines StockKLine[]
favorites UserFavorite[]
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
@@index([code])
@@index([sectorCode])
@@map("stocks")
}
// 股票行情(兼容原表)
model StockQuote {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
stock Stock @relation(fields: [stockCode], references: [code])
price Float
open Float
high Float
low Float
preClose Float @map("pre_close")
volume BigInt
turnover BigInt
changePercent Float @map("change_percent")
turnoverRate Float? @map("turnover_rate")
amplitude Float?
quoteTime DateTime @map("quote_time")
@@index([stockCode])
@@index([quoteTime])
@@map("stock_quotes")
}
// 股票K线数据兼容原表
model StockKLine {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
stock Stock @relation(fields: [stockCode], references: [code])
period String // day/week/month
date DateTime
open Float
high Float
low Float
close Float
volume BigInt
ma5 Float?
ma10 Float?
ma20 Float?
ma30 Float?
ma60 Float?
@@unique([stockCode, period, date])
@@index([stockCode])
@@index([date])
@@map("stock_klines")
}
// 用户
model User {
id String @id @default(uuid())
username String @unique
email String @unique
password String
favorites UserFavorite[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("users")
}
// 用户自选股
model UserFavorite {
id Int @id @default(autoincrement())
userId String @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
stockCode String @map("stock_code")
stock Stock @relation(fields: [stockCode], references: [code])
createdAt DateTime @default(now()) @map("created_at")
@@unique([userId, stockCode])
@@index([userId])
@@map("user_favorites")
}
// 新高新低股票记录(保留原表兼容性)
model HighLowStock {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
type String // high/low
price Float
date DateTime
daysToHighLow Int @map("days_to_highlow")
createdAt DateTime @default(now()) @map("created_at")
@@index([stockCode])
@@index([type])
@@index([date])
@@map("high_low_stocks")
}
// 动量股票推荐(保留原表兼容性)
model MomentumStock {
id Int @id @default(autoincrement())
stockCode String @map("stock_code")
momentumScore Float @map("momentum_score")
tags String? // JSON array
volumeRatio Float @map("volume_ratio")
breakThrough Boolean @default(false) @map("break_through")
date DateTime
createdAt DateTime @default(now()) @map("created_at")
@@unique([stockCode, date])
@@index([stockCode])
@@index([date])
@@map("momentum_stocks")
}