Browse Source

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

Roc 1 month ago
parent
commit
ceb7a7c039
2 changed files with 60 additions and 39 deletions
  1. 50 39
      models/data_manage/chart_info.go
  2. 10 0
      models/data_manage/edb_info.go

+ 50 - 39
models/data_manage/chart_info.go

@@ -3,48 +3,59 @@ package data_manage
 import (
 	"eta/eta_chart_lib/global"
 	"eta/eta_chart_lib/utils"
+	"gorm.io/gorm"
 )
 
 type ChartEdbInfoMapping struct {
-	EdbInfoId           int     `description:"指标id"`
-	SourceName          string  `description:"来源名称"`
-	Source              int     `description:"来源id"`
-	EdbCode             string  `description:"指标编码"`
-	EdbName             string  `description:"指标名称"`
-	EdbAliasName        string  `description:"指标名称(别名)"`
-	EdbNameEn           string  `description:"英文指标名称"`
-	EdbAliasNameEn      string  `description:"英文指标名称(别名)"`
-	EdbType             int     `description:"指标类型:1:基础指标,2:计算指标"`
-	Frequency           string  `description:"频率"`
-	FrequencyEn         string  `description:"英文频率"`
-	Unit                string  `description:"单位"`
-	UnitEn              string  `description:"英文单位"`
-	StartDate           string  `description:"起始日期"`
-	EndDate             string  `description:"终止日期"`
-	ModifyTime          string  `description:"指标最后更新时间"`
-	ChartEdbMappingId   int     `description:"图表指标id"`
-	ChartInfoId         int     `description:"图表id"`
-	MaxData             float64 `description:"上限"`
-	MinData             float64 `description:"下限"`
-	IsOrder             bool    `description:"true:正序,false:逆序"`
-	IsAxis              int     `description:"1:左轴,0:右轴"`
-	EdbInfoType         int     `description:"1:标准指标,0:领先指标"`
-	EdbInfoCategoryType int     `description:"0:普通指标,1:预测指标"`
-	LeadValue           int     `description:"领先值"`
-	LeadUnit            string  `description:"领先单位"`
-	LeadUnitEn          string  `description:"领先英文单位"`
-	ChartStyle          string  `description:"图表类型"`
-	ChartColor          string  `description:"颜色"`
-	PredictChartColor   string  `description:"预测数据的颜色"`
-	ChartWidth          float64 `description:"线条大小"`
-	ChartType           int     `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
-	LatestDate          string  `description:"数据最新日期"`
-	LatestValue         float64 `description:"数据最新值"`
-	UniqueCode          string  `description:"指标唯一编码"`
-	MinValue            float64 `json:"-" description:"最小值"`
-	MaxValue            float64 `json:"-" description:"最大值"`
-	DataList            interface{}
-	IsNullData          bool `json:"-" description:"是否空数据"`
+	EdbInfoId           int         `description:"指标id"`
+	SourceName          string      `description:"来源名称"`
+	Source              int         `description:"来源id"`
+	EdbCode             string      `description:"指标编码"`
+	EdbName             string      `description:"指标名称"`
+	EdbAliasName        string      `description:"指标名称(别名)"`
+	EdbNameEn           string      `description:"英文指标名称"`
+	EdbAliasNameEn      string      `description:"英文指标名称(别名)"`
+	EdbType             int         `description:"指标类型:1:基础指标,2:计算指标"`
+	Frequency           string      `description:"频率"`
+	FrequencyEn         string      `description:"英文频率"`
+	Unit                string      `description:"单位"`
+	UnitEn              string      `description:"英文单位"`
+	StartDate           string      `description:"起始日期"`
+	EndDate             string      `description:"终止日期"`
+	ModifyTime          string      `description:"指标最后更新时间"`
+	ChartEdbMappingId   int         `description:"图表指标id"`
+	ChartInfoId         int         `description:"图表id"`
+	MaxData             float64     `description:"上限"`
+	MinData             float64     `description:"下限"`
+	IsOrder             bool        `description:"true:正序,false:逆序"`
+	IsAxis              int         `description:"1:左轴,0:右轴"`
+	EdbInfoType         int         `description:"1:标准指标,0:领先指标"`
+	EdbInfoCategoryType int         `description:"0:普通指标,1:预测指标"`
+	LeadValue           int         `description:"领先值"`
+	LeadUnit            string      `description:"领先单位"`
+	LeadUnitEn          string      `description:"领先英文单位"`
+	ChartStyle          string      `description:"图表类型"`
+	ChartColor          string      `description:"颜色"`
+	PredictChartColor   string      `description:"预测数据的颜色"`
+	ChartWidth          float64     `description:"线条大小"`
+	ChartType           int         `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
+	LatestDate          string      `description:"数据最新日期"`
+	LatestValue         float64     `description:"数据最新值"`
+	UniqueCode          string      `description:"指标唯一编码"`
+	MinValue            float64     `json:"-" description:"最小值"`
+	MaxValue            float64     `json:"-" description:"最大值"`
+	DataList            interface{} `gorm:"-"`
+	IsNullData          bool        `gorm:"-" json:"-" description:"是否空数据"`
+}
+
+// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
+func (m *ChartEdbInfoMapping) AfterFind(db *gorm.DB) (err error) {
+	m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
+	m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
+	m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
+	m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
+
+	return
 }
 
 // AreaExtraConf 面积图配置

+ 10 - 0
models/data_manage/edb_info.go

@@ -3,6 +3,7 @@ package data_manage
 import (
 	"eta/eta_chart_lib/global"
 	"eta/eta_chart_lib/utils"
+	"gorm.io/gorm"
 	"time"
 )
 
@@ -44,6 +45,15 @@ type EdbInfo struct {
 	StockCode        string  `description:"证券代码"`
 }
 
+// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
+func (m *EdbInfo) 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
+}
+
 type EdbInfoMaxAndMinInfo struct {
 	MinDate     string  `description:"最小日期"`
 	MaxDate     string  `description:"最大日期"`