Browse Source

fix:python运算

Roc 5 months ago
parent
commit
07e3e5e0db
1 changed files with 15 additions and 1 deletions
  1. 15 1
      models/base_from_python.go

+ 15 - 1
models/base_from_python.go

@@ -7,6 +7,7 @@ import (
 	"eta_gn/eta_index_lib/utils"
 	"fmt"
 	"github.com/shopspring/decimal"
+	"gorm.io/gorm"
 	"strings"
 	"time"
 )
@@ -27,6 +28,19 @@ func (m *EdbDataPython) TableName() string {
 	return "edb_data_python"
 }
 
+// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
+func (m *EdbDataPython) AfterFind(db *gorm.DB) (err error) {
+	if m.DataTime == "" {
+		return
+	}
+	minDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.DataTime, time.Local)
+	if err != nil {
+		return
+	}
+	m.DataTime = minDateTmp.Format(utils.FormatDate)
+	return
+}
+
 // EdbDataFromPython 通过python代码获取到的指标数据
 type EdbDataFromPython struct {
 	Date  map[int]string  `json:"date"`
@@ -256,7 +270,7 @@ func EditEdbInfoCalculateMapping(edbInfo *EdbInfo, edbInfoList []*EdbInfo) (err
 // GetAllEdbDataPythonByEdbInfoId 根据指标id获取全部的数据
 func GetAllEdbDataPythonByEdbInfoId(edbInfoId int) (items []*EdbDataPython, err error) {
 	sql := ` SELECT * FROM edb_data_python WHERE edb_info_id=? ORDER BY data_time DESC `
-	err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).Scan(&items).Error
+	err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).Find(&items).Error
 	return
 }