.
This commit is contained in:
55
internal/api/ssq_api.go
Normal file
55
internal/api/ssq_api.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ssq-desk/internal/service"
|
||||
"ssq-desk/internal/storage/repository"
|
||||
)
|
||||
|
||||
// SsqAPI 双色球查询 API
|
||||
type SsqAPI struct {
|
||||
queryService *service.QueryService
|
||||
}
|
||||
|
||||
// NewSsqAPI 创建双色球查询 API
|
||||
func NewSsqAPI() (*SsqAPI, error) {
|
||||
// 优先使用 MySQL(数据源)
|
||||
repo, err := repository.NewMySQLSsqRepository()
|
||||
if err != nil {
|
||||
// MySQL 连接失败,降级使用本地 SQLite
|
||||
repo, err = repository.NewSQLiteSsqRepository()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
queryService := service.NewQueryService(repo)
|
||||
|
||||
return &SsqAPI{
|
||||
queryService: queryService,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// QueryRequest 查询请求参数
|
||||
type QueryRequest struct {
|
||||
RedBalls []int `json:"red_balls"` // 红球列表
|
||||
BlueBall int `json:"blue_ball"` // 蓝球(0表示不限制)
|
||||
BlueBallRange []int `json:"blue_ball_range"` // 蓝球筛选范围
|
||||
}
|
||||
|
||||
// QueryHistory 查询历史数据
|
||||
func (api *SsqAPI) QueryHistory(req QueryRequest) (*service.QueryResult, error) {
|
||||
if api.queryService == nil {
|
||||
// 重新初始化
|
||||
newAPI, err := NewSsqAPI()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
api.queryService = newAPI.queryService
|
||||
}
|
||||
|
||||
return api.queryService.Query(service.QueryRequest{
|
||||
RedBalls: req.RedBalls,
|
||||
BlueBall: req.BlueBall,
|
||||
BlueBallRange: req.BlueBallRange,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user