|
@@ -4,7 +4,7 @@ import (
|
|
|
"eta/eta_api/global"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
+ "gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
type GzData struct {
|
|
@@ -23,6 +23,7 @@ func GetEdbDataGzMaxOrMinDate(edbCode string) (minDate, maxDate string, err erro
|
|
|
}
|
|
|
minDate = maxAndMinDate.MinDate.Format(utils.FormatDate)
|
|
|
maxDate = maxAndMinDate.MaxDate.Format(utils.FormatDate)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -38,11 +39,29 @@ type GzIndexView struct {
|
|
|
Value float64 `description:"数据"`
|
|
|
}
|
|
|
|
|
|
+// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
+func (m *GzIndexView) AfterFind(db *gorm.DB) (err error) {
|
|
|
+ m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
|
|
|
+ m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+func (m *GzIndexView) ConvDateTimeStr() {
|
|
|
+ m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
|
|
|
+ m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetBaseInfoFromShByIndexCode 获取指标信息
|
|
|
func GetBaseInfoFromGzByIndexCode(indexCode string) (item *GzIndexView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT * FROM base_from_trade_guangzhou_index WHERE index_code=? `
|
|
|
sql = fmt.Sprintf(sql)
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, indexCode).First(&item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.ConvDateTimeStr()
|
|
|
+
|
|
|
return
|
|
|
}
|