package data_manage import ( "eta_gn/eta_chart_lib/global" "eta_gn/eta_chart_lib/utils" "gorm.io/gorm" "time" ) type EdbInfo struct { EdbInfoId int `gorm:"column:edb_info_id;primaryKey" description:"指标ID" orm:"column(edb_info_id);pk"` EdbInfoType int `gorm:"column:edb_info_type" description:"指标类型,0:普通指标,1:预测指标"` SourceName string `gorm:"column:source_name" description:"来源名称"` Source int `gorm:"column:source" description:"来源id"` EdbCode string `gorm:"column:edb_code" description:"指标编码"` EdbName string `gorm:"column:edb_name" description:"指标名称"` EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"` EdbNameSource string `gorm:"column:edb_name_source" description:"指标名称来源"` Frequency string `gorm:"column:frequency" description:"频率"` Unit string `gorm:"column:unit" description:"单位"` UnitEn string `gorm:"column:unit_en" description:"英文单位"` StartDate string `gorm:"column:start_date" description:"起始日期"` EndDate string `gorm:"column:end_date" description:"终止日期"` ClassifyId int `gorm:"column:classify_id" description:"分类id"` SysUserId int `gorm:"column:sys_user_id"` SysUserRealName string `gorm:"column:sys_user_real_name"` UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"` CreateTime time.Time `gorm:"column:create_time"` ModifyTime time.Time `gorm:"column:modify_time"` MinValue float64 `gorm:"column:min_value" description:"指标最小值"` MaxValue float64 `gorm:"column:max_value" description:"指标最大值"` CalculateFormula string `gorm:"column:calculate_formula" description:"计算公式"` EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"` Sort int `gorm:"column:sort" description:"排序字段"` LatestDate string `gorm:"column:latest_date" description:"数据最新日期"` LatestValue float64 `gorm:"column:latest_value" description:"数据最新值"` MoveType int `gorm:"column:move_type" description:"移动方式:1:领先(默认),2:滞后"` MoveFrequency string `gorm:"column:move_frequency" description:"移动频度"` NoUpdate int8 `gorm:"column:no_update" description:"是否停止更新,0:继续更新;1:停止更新"` DataDateType string `gorm:"column:data_date_type;size(255);null;default:交易日" description:"数据日期类型"` SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"` SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"` IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"` StockCode string `gorm:"column:stock_code" description:"证券代码"` } type EdbInfoMaxAndMinInfo struct { MinDate string `description:"最小日期"` MaxDate string `description:"最大日期"` MinValue float64 `description:"最小值"` MaxValue float64 `description:"最大值"` LatestValue float64 `description:"最新值"` } func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM edb_info WHERE edb_info_id=? ` err = o.Raw(sql, edbInfoId).First(&item).Error return } func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) { num := len(edbInfoIdList) if num <= 0 { return } o := global.DmSQL["data"] sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetGormInReplace(num) + `) ` err = o.Raw(sql, edbInfoIdList).Find(&items).Error return } func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) { calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source) if err != nil && !utils.IsErrNoRow(err) { return } for _, item := range calculateList { if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤 continue } if item.EdbType == 1 { baseEdbInfoArr = append(baseEdbInfoArr, item) } else { calculateInfoArr = append(calculateInfoArr, item) newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source) baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...) calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...) } } return } type EdbInfoSearchData struct { DataTime string `description:"数据日期"` Value float64 `description:"数据"` } type TraceEdbInfoResp struct { EdbInfoId int `description:"指标id"` EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"` EdbName string `description:"指标名称"` EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"` RuleTitle string `description:"指标规则"` UniqueCode string `description:"唯一编码"` ClassifyId int `description:"分类ID"` Child []TraceEdbInfoResp `description:"下级来源"` EdbInfo *EdbInfo `description:"指标信息" json:"-"` } func (e *EdbInfo) AfterFind(db *gorm.DB) (err error) { tmpLatestDate, err := time.Parse(utils.FormatDateWallWithLoc, e.LatestDate) if err != nil { return nil } tmpStartDate, err := time.Parse(utils.FormatDateWallWithLoc, e.StartDate) if err != nil { return nil } tmpEndDate, err := time.Parse(utils.FormatDateWallWithLoc, e.EndDate) if err != nil { return nil } e.LatestDate = utils.TimeTransferString(utils.FormatDate, tmpLatestDate) e.StartDate = utils.TimeTransferString(utils.FormatDate, tmpStartDate) e.EndDate = utils.TimeTransferString(utils.FormatDate, tmpEndDate) return nil }