浏览代码

Merge remote-tracking branch 'origin/dm' into debug

# Conflicts:
#	models/sandbox/sandbox.go
Roc 1 月之前
父节点
当前提交
c65858d2f0

+ 6 - 0
models/data_manage/edb_data_base.go

@@ -9,6 +9,7 @@ import (
 	"time"
 
 	"go.mongodb.org/mongo-driver/bson"
+	"gorm.io/gorm"
 )
 
 // GetEdbDataTableName 指标数据->存储表
@@ -234,6 +235,11 @@ type EdbDataBase struct {
 	DataTimestamp int64
 }
 
+func (e *EdbDataBase) AfterFind(tx *gorm.DB) (err error) {
+	e.DataTime = utils.GormDateStrToDateStr(e.DataTime)
+	return
+}
+
 func GetEdbDataAllByEdbCode(edbCode string, source, subSource, limit int) (items []*EdbInfoSearchData, err error) {
 	// 自有数据需要额外处理(从mongo获取)
 	if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {

+ 10 - 0
models/data_manage/edb_info_calculate.go

@@ -4,6 +4,7 @@ import (
 	"eta/eta_api/global"
 	"eta/eta_api/utils"
 	"fmt"
+	"gorm.io/gorm"
 
 	"strings"
 	"time"
@@ -84,6 +85,15 @@ type EdbInfoCalculateDetail struct {
 	ClassifyId         int       `description:"分类id"`
 }
 
+// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
+func (m *EdbInfoCalculateDetail) AfterFind(db *gorm.DB) (err error) {
+	m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
+	m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
+	m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
+
+	return
+}
+
 func GetEdbInfoCalculateDetail(edbInfoId, source int) (list []*EdbInfoCalculateDetail, err error) {
 	o := global.DbMap[utils.DbNameIndex]
 

+ 2 - 2
models/data_manage/predict_edb_conf.go

@@ -34,7 +34,7 @@ type PredictEdbConfDetail struct {
 	EndDate          time.Time                               `description:"截止日期"`
 	ModifyTime       time.Time                               `description:"修改时间"`
 	CreateTime       time.Time                               `description:"添加时间"`
-	CalculateList    []*PredictEdbConfCalculateMappingDetail `description:"配置与指标的关联信息"`
+	CalculateList    []*PredictEdbConfCalculateMappingDetail ` gorm:"-" description:"配置与指标的关联信息"`
 	EndNum           int                                     `description:"截止期数"`
 }
 
@@ -50,7 +50,7 @@ type PredictEdbConfAndData struct {
 	EndNum           int            `description:"截止期数"`
 	ModifyTime       time.Time      `description:"修改时间"`
 	CreateTime       time.Time      `description:"添加时间"`
-	DataList         []*EdbDataList `description:"动态数据"`
+	DataList         []*EdbDataList ` gorm:"-" description:"动态数据"`
 }
 
 // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息

+ 7 - 1
models/sandbox/sandbox.go

@@ -1,6 +1,7 @@
 package sandbox
 
 import (
+	sql2 "database/sql"
 	"eta/eta_api/global"
 	"eta/eta_api/models/system"
 	"eta/eta_api/utils"
@@ -384,7 +385,12 @@ FROM classify_tree`
 		sandbox_classify_id = vm._id `
 	}
 
-	err = o.Raw(sql, sandboxClassifyId).Scan(&ids).Error
+	var idStrNull sql2.NullString
+
+	err = o.Raw(sql, sandboxClassifyId).Scan(&idStrNull).Error
+	if err == nil && idStrNull.Valid {
+		ids = idStrNull.String
+	}
 	return
 }