package data_manage import ( "eta/eta_hub/utils" "fmt" "strings" "time" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" ) type EdbInfo struct { EdbInfoId int `orm:"column(edb_info_id);pk"` EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"` SourceName string `description:"来源名称"` Source int `description:"来源ID"` EdbCode string `description:"指标编码"` EdbName string `description:"指标名称"` EdbNameEn string `description:"英文指标名称"` EdbNameSource string `description:"指标名称来源"` Frequency string `description:"频率"` Unit string `description:"单位"` UnitEn string `description:"英文单位"` StartDate string `description:"起始日期"` EndDate string `description:"终止日期"` ClassifyId int `description:"分类ID"` SysUserId int `description:"创建人ID"` SysUserRealName string `description:"创建人姓名"` UniqueCode string `description:"指标唯一编码"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` MinValue float64 `description:"指标最小值"` MaxValue float64 `description:"指标最大值"` CalculateFormula string `description:"计算公式"` EdbType int `description:"指标类型:1:基础指标,2:计算指标"` Sort int `description:"排序字段"` LatestDate string `description:"数据最新日期"` LatestValue float64 `description:"数据最新值"` MoveType int `description:"移动方式:1:领先(默认),2:滞后"` MoveFrequency string `description:"移动频度"` NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"` ServerUrl string `description:"服务器地址"` ChartImage string `description:"图表图片"` Calendar string `description:"公历/农历" orm:"default(公历);"` DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"` ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"` TerminalCode string `description:"终端编码,用于配置在机器上"` DataUpdateTime string `description:"最近一次数据发生变化的时间"` ErDataUpdateDate time.Time `description:"本次更新,数据发生变化的最早日期"` SourceIndexName string `description:"数据源中的指标名称"` SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"` SubSourceName string `description:"子数据来源名称"` IndicatorCode string `description:"指标代码"` StockCode string `description:"证券代码"` Extra string `description:"指标的额外配置"` } func (m *EdbInfo) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbInfo, err error) { o := orm.NewOrmUsingDB("data") fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } func (m *EdbInfo) GetItemsPageByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EdbInfo, err error) { o := orm.NewOrmUsingDB("data") fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM edb_info WHERE 1=1 %s %s`, fields, cond, order) sql += fmt.Sprintf(` LIMIT %d,%d`, startSize, pageSize) _, err = o.Raw(sql, pars).QueryRows(&items) return } func (m *EdbInfo) GetItemsTotal(cond string, pars []interface{}) (total int, err error) { o := orm.NewOrmUsingDB("data") sql := fmt.Sprintf(`SELECT COUNT(*) FROM edb_info WHERE 1=1 %s`, cond) err = o.Raw(sql, pars).QueryRow(&total) return } func (m *EdbInfo) GetItemByUniCode(code string) (item *EdbInfo, err error) { o := orm.NewOrmUsingDB("data") sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE unique_code = ? LIMIT 1`) err = o.Raw(sql, code).QueryRow(&item) return } func (m *EdbInfo) GetItemByEdbCode(code string) (item *EdbInfo, err error) { o := orm.NewOrmUsingDB("data") sql := fmt.Sprintf(`SELECT * FROM edb_info WHERE edb_code = ? LIMIT 1`) err = o.Raw(sql, code).QueryRow(&item) return } // EdbInfoItem 指标信息 type EdbInfoItem struct { EdbInfoId int `description:"指标信息ID"` UniqueCode string `description:"指标唯一编码"` EdbCode string `description:"指标编码"` EdbInfoType int `description:"指标类型: 0-普通指标; 1-预测指标"` EdbType int `description:"指标类型: 1-基础指标; 2-计算指标"` EdbName string `description:"指标名称"` ClassifyId int `description:"分类ID"` Source int `description:"来源ID"` SourceName string `description:"来源名称"` Frequency string `description:"频率"` Unit string `description:"单位"` StartDate string `description:"起始日期"` EndDate string `description:"终止日期"` MinValue float64 `description:"指标最小值"` MaxValue float64 `description:"指标最大值"` LatestDate string `description:"数据最新日期"` LatestValue float64 `description:"数据最新值"` ChartImage string `description:"图表图片"` Calendar string `description:"公历/农历"` DataDateType string `description:"数据日期类型: 交易日/自然日"` Sort int `description:"排序"` NoUpdate int `description:"是否停更: 0-继续更新; 1-停止更新"` CreateTime string `description:"创建时间"` ModifyTime string `description:"更新时间"` SysUserRealName string `description:"创建人姓名"` ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"` //EdbData []*EdbDataItem `description:"指标数据"` } type EdbInfoItemResp struct { List []*EdbInfoItem `description:"指标列表"` Paging *paging.PagingItem `description:"分页"` } func FormatEdbInfo2Item(origin *EdbInfo) (item *EdbInfoItem) { if origin == nil { return } item = new(EdbInfoItem) item.EdbInfoId = origin.EdbInfoId item.EdbInfoType = origin.EdbInfoType item.SourceName = origin.SourceName item.Source = origin.Source item.EdbCode = origin.EdbCode item.EdbName = origin.EdbName item.Frequency = origin.Frequency item.Unit = origin.Unit item.StartDate = origin.StartDate item.EndDate = origin.EndDate item.ClassifyId = origin.ClassifyId item.UniqueCode = origin.UniqueCode item.MinValue = origin.MinValue item.MaxValue = origin.MaxValue item.EdbType = origin.EdbType item.Sort = origin.Sort item.LatestDate = origin.LatestDate item.LatestValue = origin.LatestValue item.NoUpdate = int(origin.NoUpdate) item.ChartImage = origin.ChartImage item.Calendar = origin.Calendar item.DataDateType = origin.DataDateType item.SysUserRealName = origin.SysUserRealName item.ErDataUpdateDate = utils.TimeTransferString(utils.FormatDate, origin.ErDataUpdateDate) item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) //item.EdbData = edbData return } // TraceEdbInfoResp 指标追溯数据返回 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 GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM edb_info WHERE edb_info_id=? ` err = o.Raw(sql, edbInfoId).QueryRow(&item) return } // GetEdbInfoByIdList 根据指标id集合 获取 指标列表 func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) { num := len(edbInfoIdList) if num <= 0 { return } o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) ` _, err = o.Raw(sql, edbInfoIdList).QueryRows(&items) return } // GetEdbInfoByEdbCodeList 根据指标code集合获取指标列表 func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo, err error) { num := len(edbCodeList) if num <= 0 { return } o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) ` _, err = o.Raw(sql, source, edbCodeList).QueryRows(&items) return }