更新
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"level_go/internal/model"
|
||||
)
|
||||
|
||||
type CommonService struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func (s *CommonService) GetTradeCalendar() (model.CalendarResponse, error) {
|
||||
var results []struct {
|
||||
DateStr string `gorm:"column:ds"`
|
||||
}
|
||||
var resp model.CalendarResponse
|
||||
|
||||
err := s.DB.Model(&model.TradeCalendar{}).
|
||||
Select("DATE_FORMAT(cal_date, '%Y-%m-%d') as ds").
|
||||
Where("is_open = ? AND exchange = ?", 1, "SSE").
|
||||
Order("cal_date ASC").Scan(&results).Error
|
||||
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
for _, r := range results {
|
||||
resp.OpenDates = append(resp.OpenDates, r.DateStr)
|
||||
resp.MaxDate = r.DateStr
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user