package data_source import ( "eta/eta_task/utils" "fmt" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "strings" "time" ) // SearchDataSource 数据源ES搜索 type SearchDataSource struct { PrimaryId int `description:"主键ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` ClassifyId int `description:"分类ID"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` LatestValue float64 `description:"最新值"` Source int `description:"来源"` SourceName string `description:"数据源名称"` SubSource int `description:"子来源"` IsDeleted int `description:"是否已删除:0-正常;1-已删除"` CreateTime string `description:"创建时间"` ModifyTime string `description:"修改时间"` } // SearchDataSourceItem 数据源ES搜索 type SearchDataSourceItem struct { SearchDataSource SearchText string `description:"搜索结果(含高亮)"` } // ToMap 为了方便前端那边的修改,这里兼容一下部分Key的变动,不然改动量很大 func (s *SearchDataSourceItem) ToMap(primaryIdKey, indexNameKey, classifyIdKey string) map[string]interface{} { data := make(map[string]interface{}) if primaryIdKey != "" { data[primaryIdKey] = s.PrimaryId } else { data["PrimaryId"] = s.PrimaryId } if indexNameKey != "" { data[indexNameKey] = s.IndexName } else { data["IndexName"] = s.IndexName } if classifyIdKey != "" { data[classifyIdKey] = s.ClassifyId } else { data["ClassifyId"] = s.ClassifyId } data["IndexCode"] = s.IndexCode data["Unit"] = s.Unit data["Frequency"] = s.Frequency data["StartDate"] = s.StartDate data["EndDate"] = s.EndDate data["LatestValue"] = s.LatestValue data["Source"] = s.Source data["SourceName"] = s.SourceName data["IsDeleted"] = s.IsDeleted data["CreateTime"] = s.CreateTime data["ModifyTime"] = s.ModifyTime data["SearchText"] = s.SearchText return data } // SearchDataSourceResp 数据源ES-分页搜索响应 type SearchDataSourceResp struct { Paging *paging.PagingItem List []map[string]interface{} } // SearchEsCols 数据源ES搜索字段 type SearchEsCols struct { PrimaryId string IndexCode string IndexName string ClassifyId string Unit string Frequency string StartDate string EndDate string LatestValue string CreateTime string ModifyTime string } // EsBaseFromIndex 数据源ES统一实现的接口 type EsBaseFromIndex interface { EsCols() SearchEsCols SourceInfo() (int, int, string) } // GetEsBaseFromIndexByTableName 根据表名获取对应数据源 func GetEsBaseFromIndexByTableName(tableName string) EsBaseFromIndex { switch tableName { case "base_from_rzd_index": return &BaseFromRzdIndex{} case "base_from_hisugar_index": return &BaseFromHisugarIndex{} case "base_from_ly_index": return &BaseFromLyIndex{} case "base_from_sci_hq_index": return &BaseFromSciHqIndex{} case "base_from_oilchem_index": return &BaseFromOilchemIndex{} case "base_from_ths_hf_index": return &BaseFromThsHfIndex{} case "base_from_ccf_index": return &BaseFromCcfIndex{} case "base_from_usda_fas_index": return &BaseFromUsdaFasIndex{} case "base_from_mysteel_chemical_index": return &BaseFromMysteelChemicalIndex{} case "base_from_smm_index": return &BaseFromSmmIndex{} case "base_from_baiinfo_index": return &BaseFromBaiinfoIndex{} case "base_from_sci_index": return &BaseFromSciIndex{} case "base_from_coalmine_mapping": return &BaseFromCoalmineMapping{} case "base_from_eia_steo_index": return &BaseFromEiaSteoIndex{} case "base_from_icpi_index": return &BaseFromIcpiIndex{} case "base_from_yongyi_index": return &BaseFromYongyiIndex{} case "base_from_fenwei_index": return &BaseFromFenweiIndex{} case "base_from_sci99_index": return &BaseFromSci99Index{} case "mb_index_main_info": return &BaseFromGlIndex{} case "edbinfo": return &BaseFromManualEdb{} case "base_from_business_index": return &BaseFromBusinessIndex{} case "base_from_bloomberg_index": return &BaseFromBloombergIndex{} case "base_from_mtjh_mapping": return &BaseFromMtjhMapping{} } return nil } // BaseFromRzdIndex 睿咨得 type BaseFromRzdIndex struct { BaseFromRzdIndexId int `orm:"column(base_from_rzd_index_id);pk"` BaseFromRzdClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromRzdIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_RZD, 0, "睿咨得" } func (m *BaseFromRzdIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_rzd_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "base_from_rzd_classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromRzdIndex) Format2SearchDataSource(origin *BaseFromRzdIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromRzdIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.BaseFromRzdClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromRzdIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromRzdIndex, 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 base_from_rzd_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromHisugarIndex 泛糖科技 type BaseFromHisugarIndex struct { BaseFromHisugarIndexId int `orm:"column(base_from_hisugar_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` Source string `description:"数据来源"` Describe string `description:"指标描述"` Sort int `description:"排序"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromHisugarIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_HISUGAR, 0, "泛糖科技" } func (m *BaseFromHisugarIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_hisugar_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromHisugarIndex) Format2SearchDataSource(origin *BaseFromHisugarIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromHisugarIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromHisugarIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromHisugarIndex, 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 base_from_hisugar_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromLyIndex 粮油商务网 type BaseFromLyIndex struct { BaseFromLyIndexId int `orm:"column(base_from_ly_index_id);pk"` BaseFromLyClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` EdbExist int `description:"指标库是否已添加:0-否;1-是"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromLyIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_LY, 0, "粮油商务网" } func (m *BaseFromLyIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_ly_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "base_from_ly_classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromLyIndex) Format2SearchDataSource(origin *BaseFromLyIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromLyIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.BaseFromLyClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromLyIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromLyIndex, 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 base_from_ly_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromSciHqIndex 卓创红期 type BaseFromSciHqIndex struct { BaseFromSciHqIndexId int `orm:"column(base_from_sci_hq_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` Sort int `description:"排序"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` LatestDate time.Time `description:"最新更新时间"` TerminalCode string `description:"指标描述"` FilePath string `description:"文件路径"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromSciHqIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_SCI_HQ, 0, "卓创红期" } func (m *BaseFromSciHqIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_sci_hq_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromSciHqIndex) Format2SearchDataSource(origin *BaseFromSciHqIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromSciHqIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromSciHqIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSciHqIndex, 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 base_from_sci_hq_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromOilchemIndex 隆众资讯 type BaseFromOilchemIndex struct { BaseFromOilchemIndexId int `orm:"column(base_from_oilchem_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromOilchemIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_OILCHEM, 0, "隆众资讯" } func (m *BaseFromOilchemIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_oilchem_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromOilchemIndex) Format2SearchDataSource(origin *BaseFromOilchemIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromOilchemIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromOilchemIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromOilchemIndex, 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 base_from_oilchem_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromThsHfIndex 同花顺高频数据 type BaseFromThsHfIndex struct { BaseFromThsHfIndexId int `orm:"column(base_from_ths_hf_index_id);pk"` BaseFromThsHfClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Source string `description:"数据来源"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期(至时分秒)"` EndDate time.Time `description:"结束日期(至时分秒)"` Describe string `description:"指标描述"` Sort int `description:"排序"` IsStop int `description:"是否停更:0-否;1-停更"` TerminalCode string `description:"所属终端编码"` StockCode string `description:"证券代码"` Indicator string `description:"同花顺指标代码"` ApiPars string `description:"API请求参数"` LatestValue float64 `description:"最新值"` SysUserId int `description:"创建人ID"` SysUserRealName string `description:"创建人姓名"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } func (m *BaseFromThsHfIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_THS, utils.DATA_SUB_SOURCE_HIGH_FREQUENCY, "同花顺高频" } func (m *BaseFromThsHfIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_ths_hf_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "base_from_ths_hf_classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromThsHfIndex) Format2SearchDataSource(origin *BaseFromThsHfIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromThsHfIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.BaseFromThsHfClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDateTime, origin.StartDate) // 高频这里是到时分秒 item.EndDate = utils.TimeTransferString(utils.FormatDateTime, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromThsHfIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromThsHfIndex, 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 base_from_ths_hf_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromCcfIndex CCF化纤信息 type BaseFromCcfIndex struct { BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromCcfIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_CCF, 0, "CCF化纤信息" } func (m *BaseFromCcfIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_ccf_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromCcfIndex) Format2SearchDataSource(origin *BaseFromCcfIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromCcfIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromCcfIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromCcfIndex, 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 base_from_ccf_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromUsdaFasIndex 美国农业部 type BaseFromUsdaFasIndex struct { BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromUsdaFasIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_USDA_FAS, 0, "美国农业部" } func (m *BaseFromUsdaFasIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_usda_fas_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "end_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromUsdaFasIndex) Format2SearchDataSource(origin *BaseFromUsdaFasIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromUsdaFasIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromUsdaFasIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromUsdaFasIndex, 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, end_value AS latest_value FROM base_from_usda_fas_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromMysteelChemicalIndex 上海钢联 type BaseFromMysteelChemicalIndex struct { BaseFromMysteelChemicalIndexId int `orm:"column(base_from_mysteel_chemical_index_id);pk"` BaseFromMysteelChemicalClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromMysteelChemicalIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, "上海钢联" } func (m *BaseFromMysteelChemicalIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_mysteel_chemical_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "base_from_mysteel_chemical_classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "end_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromMysteelChemicalIndex) Format2SearchDataSource(origin *BaseFromMysteelChemicalIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromMysteelChemicalIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.BaseFromMysteelChemicalClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromMysteelChemicalIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromMysteelChemicalIndex, 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, end_value AS latest_value FROM base_from_mysteel_chemical_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromSmmIndex 有色原始数据库 type BaseFromSmmIndex struct { BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromSmmIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_YS, 0, "SMM原始数据库" } func (m *BaseFromSmmIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_smm_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "end_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromSmmIndex) Format2SearchDataSource(origin *BaseFromSmmIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromSmmIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromSmmIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSmmIndex, 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, end_value AS latest_value FROM base_from_smm_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromBaiinfoIndex 百川盈孚 type BaseFromBaiinfoIndex struct { BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromBaiinfoIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_BAIINFO, 0, "百川盈孚" } func (m *BaseFromBaiinfoIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_baiinfo_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromBaiinfoIndex) Format2SearchDataSource(origin *BaseFromBaiinfoIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromBaiinfoIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromBaiinfoIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromBaiinfoIndex, 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 base_from_baiinfo_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromSciIndex 卓创数据(红桃3) type BaseFromSciIndex struct { BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromSciIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_SCI, 0, "卓创数据(红桃3)" } func (m *BaseFromSciIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_sci_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromSciIndex) Format2SearchDataSource(origin *BaseFromSciIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromSciIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromSciIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSciIndex, 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 base_from_sci_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromCoalmineMapping 中国煤炭市场网 type BaseFromCoalmineMapping struct { BaseFromCoalmineMappingId int `orm:"column(base_from_coalmine_mapping_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromCoalmineMapping) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_COAL, 0, "中国煤炭市场网" } func (m *BaseFromCoalmineMapping) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_coalmine_mapping_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "", Unit: "", Frequency: "", StartDate: "", EndDate: "", LatestValue: "", CreateTime: "create_time", ModifyTime: "", } } func (m *BaseFromCoalmineMapping) Format2SearchDataSource(origin *BaseFromCoalmineMapping) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromCoalmineMappingId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromCoalmineMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromCoalmineMapping, 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 base_from_coalmine_mapping WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromEiaSteoIndex EIA STEO报告 type BaseFromEiaSteoIndex struct { BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"` BaseFromEiaSteoClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromEiaSteoIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_EIA_STEO, 0, "EIA STEO报告" } func (m *BaseFromEiaSteoIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_eia_steo_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "base_from_eia_steo_classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromEiaSteoIndex) Format2SearchDataSource(origin *BaseFromEiaSteoIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromEiaSteoIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.BaseFromEiaSteoClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromEiaSteoIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromEiaSteoIndex, 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 base_from_eia_steo_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromIcpiIndex ICPI消费价格指数 type BaseFromIcpiIndex struct { BaseFromIcpiIndexId int `orm:"column(base_from_icpi_index_id);pk"` BaseFromIcpiClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromIcpiIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_ICPI, 0, "ICPI消费价格指数" } func (m *BaseFromIcpiIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_icpi_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "base_from_icpi_classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromIcpiIndex) Format2SearchDataSource(origin *BaseFromIcpiIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromIcpiIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.BaseFromIcpiClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromIcpiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromIcpiIndex, 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 base_from_icpi_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromYongyiIndex 涌益咨询 type BaseFromYongyiIndex struct { YongyiIndexId int `orm:"column(yongyi_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromYongyiIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_YONYI, 0, "涌益咨询" } func (m *BaseFromYongyiIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "yongyi_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromYongyiIndex) Format2SearchDataSource(origin *BaseFromYongyiIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.YongyiIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromYongyiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromYongyiIndex, 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 base_from_yongyi_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromFenweiIndex 汾渭数据 type BaseFromFenweiIndex struct { FenweiIndexId int `orm:"column(fenwei_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromFenweiIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_FENWEI, 0, "汾渭数据" } func (m *BaseFromFenweiIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "fenwei_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromFenweiIndex) Format2SearchDataSource(origin *BaseFromFenweiIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.FenweiIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromFenweiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromFenweiIndex, 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 base_from_fenwei_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromSci99Index 卓创资讯 type BaseFromSci99Index struct { BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"` ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromSci99Index) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_SCI99, 0, "卓创资讯" } func (m *BaseFromSci99Index) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_sci_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "classify_id", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromSci99Index) Format2SearchDataSource(origin *BaseFromSci99Index) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromSciIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromSci99Index) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromSci99Index, 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 base_from_sci99_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromGlIndex 钢联原始指标库 type BaseFromGlIndex struct { PrimaryId int `orm:"column(ID);pk"` IndexCode string `orm:"column(INDEX_CODE)" description:"指标编码"` IndexName string `orm:"column(INDEX_NAME)" description:"指标名称"` Unit string `orm:"column(UNIT_NAME)" description:"单位"` Frequency string `orm:"column(FREQUENCY_NAME)" description:"频度"` StartDate time.Time `orm:"column(BEGIN_DATE)" description:"开始日期"` EndDate time.Time `orm:"column(END_DATE)" description:"结束日期"` LatestValue float64 `orm:"column(DATA_VALUE)" description:"最新值"` CreateTime time.Time `orm:"column(CREATE_TIME)" description:"创建时间"` ModifyTime time.Time `orm:"column(UPDATE_TIME)" description:"更新时间"` } func (m *BaseFromGlIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_GL, 0, "钢联原始数据库" } func (m *BaseFromGlIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "ID", IndexCode: "INDEX_CODE", IndexName: "INDEX_NAME", ClassifyId: "", Unit: "UNIT_NAME", Frequency: "FREQUENCY_NAME", StartDate: "BEGIN_DATE", EndDate: "END_DATE", LatestValue: "DATA_VALUE", CreateTime: "CREATE_TIME", ModifyTime: "UPDATE_TIME", } } func (m *BaseFromGlIndex) Format2SearchDataSource(origin *BaseFromGlIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.PrimaryId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName //item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromGlIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromGlIndex, err error) { o := orm.NewOrmUsingDB("gl") 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 mb_index_main_info WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromManualEdb 手工数据录入 type BaseFromManualEdb struct { //PrimaryId int `orm:"column(TRADE_CODE)"` // 注手工指标没自增ID... IndexCode string `orm:"column(TRADE_CODE)" description:"指标编码"` IndexName string `orm:"column(SEC_NAME)" description:"指标名称"` ClassifyId int `orm:"column(classify_id)" description:"分类ID"` Unit string `orm:"column(UNIT)" description:"单位"` Frequency string `orm:"column(frequency)" description:"频度"` StartDate time.Time `orm:"column(start_date)" description:"开始日期"` EndDate time.Time `orm:"column(end_date)" description:"结束日期"` LatestValue float64 `orm:"column(latest_value)" description:"最新值"` CreateTime time.Time `orm:"column(create_date)" description:"创建时间"` ModifyTime time.Time `orm:"column(modify_time)" description:"更新时间"` } func (m *BaseFromManualEdb) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_MANUAL, 0, "手工指标录入" } func (m *BaseFromManualEdb) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "", IndexCode: "TRADE_CODE", IndexName: "SEC_NAME", ClassifyId: "classify_id", Unit: "UNIT", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_date", ModifyTime: "modify_time", } } func (m *BaseFromManualEdb) Format2SearchDataSource(origin *BaseFromManualEdb) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) //item.PrimaryId = origin.PrimaryId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromManualEdb) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromManualEdb, err error) { o := orm.NewOrmUsingDB("edb") fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_date DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM edbinfo WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromBusinessIndex 自有数据 type BaseFromBusinessIndex struct { BaseFromBusinessIndexId int `orm:"column(base_from_business_index_id);pk"` //ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromBusinessIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_BUSINESS, 0, "自有数据" } func (m *BaseFromBusinessIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_business_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromBusinessIndex) Format2SearchDataSource(origin *BaseFromBusinessIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromBusinessIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName //item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromBusinessIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromBusinessIndex, 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 base_from_business_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromBloombergIndex Bloomberg type BaseFromBloombergIndex struct { BaseFromBloombergIndexId int `orm:"column(base_from_bloomberg_index_id);pk"` //ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromBloombergIndex) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_BLOOMBERG, 0, "Bloomberg" } func (m *BaseFromBloombergIndex) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_bloomberg_index_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromBloombergIndex) Format2SearchDataSource(origin *BaseFromBloombergIndex) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromBloombergIndexId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName //item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromBloombergIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromBloombergIndex, 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 base_from_bloomberg_index WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseFromMtjhMapping 煤炭江湖 type BaseFromMtjhMapping struct { BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"` //ClassifyId int `description:"分类ID"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` } func (m *BaseFromMtjhMapping) SourceInfo() (int, int, string) { return utils.DATA_SOURCE_MTJH, 0, "煤炭江湖" } func (m *BaseFromMtjhMapping) EsCols() SearchEsCols { return SearchEsCols{ PrimaryId: "base_from_mtjh_mapping_id", IndexCode: "index_code", IndexName: "index_name", ClassifyId: "", Unit: "unit", Frequency: "frequency", StartDate: "start_date", EndDate: "end_date", LatestValue: "latest_value", CreateTime: "create_time", ModifyTime: "", } } func (m *BaseFromMtjhMapping) Format2SearchDataSource(origin *BaseFromMtjhMapping) (item *SearchDataSource) { if origin == nil { return } source, subSource, sourceName := m.SourceInfo() item = new(SearchDataSource) item.PrimaryId = origin.BaseFromMtjhMappingId item.IndexCode = origin.IndexCode item.IndexName = origin.IndexName //item.ClassifyId = origin.ClassifyId item.Unit = origin.Unit item.Frequency = origin.Frequency item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.LatestValue = origin.LatestValue item.Source = source item.SubSource = subSource item.SourceName = sourceName item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return } func (m *BaseFromMtjhMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromMtjhMapping, 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 base_from_mtjh_mapping WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // BaseIndexDataMinMax 数据源极值信息 type BaseIndexDataMinMax struct { MinDate string `description:"最小日期"` MaxDate string `description:"最大日期"` LatestValue float64 `description:"最新值"` //MinValue float64 `description:"最小值"` //MaxValue float64 `description:"最大值"` } // GetBaseIndexDataTableName 根据来源获取原始指标表和数据表名(很大一部分来源不存在原始指标) func GetBaseIndexDataTableName(source, subSource int) (indexTable, dataTable string) { switch source { case utils.DATA_SOURCE_THS: if subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY { indexTable = "base_from_ths_hf_index" dataTable = "base_from_ths_hf_data" } case utils.DATA_SOURCE_RZD: indexTable = "base_from_rzd_index" dataTable = "base_from_rzd_data" case utils.DATA_SOURCE_HISUGAR: indexTable = "base_from_hisugar_index" dataTable = "base_from_hisugar_data" case utils.DATA_SOURCE_LY: indexTable = "base_from_ly_index" dataTable = "base_from_ly_data" case utils.DATA_SOURCE_SCI_HQ: indexTable = "base_from_sci_hq_index" dataTable = "base_from_sci_hq_data" case utils.DATA_SOURCE_OILCHEM: indexTable = "base_from_oilchem_index" dataTable = "base_from_oilchem_data" case utils.DATA_SOURCE_CCF: indexTable = "base_from_ccf_index" dataTable = "base_from_ccf_data" case utils.DATA_SOURCE_USDA_FAS: indexTable = "base_from_usda_fas_index" dataTable = "base_from_usda_fas_data" case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: indexTable = "base_from_mysteel_chemical_index" dataTable = "base_from_mysteel_chemical_data" case utils.DATA_SOURCE_YS: indexTable = "base_from_smm_index" dataTable = "base_from_smm_data" case utils.DATA_SOURCE_BAIINFO: indexTable = "base_from_baiinfo_index" dataTable = "base_from_baiinfo_data" case utils.DATA_SOURCE_SCI: indexTable = "base_from_sci_index" dataTable = "base_from_sci_data" case utils.DATA_SOURCE_EIA_STEO: indexTable = "base_from_eia_steo_index" dataTable = "base_from_eia_steo_data" case utils.DATA_SOURCE_ICPI: indexTable = "base_from_icpi_index" dataTable = "base_from_icpi_data" case utils.DATA_SOURCE_YONYI: indexTable = "base_from_yongyi_index" dataTable = "base_from_yongyi_data" case utils.DATA_SOURCE_FENWEI: indexTable = "base_from_fenwei_index" dataTable = "base_from_fenwei_data" case utils.DATA_SOURCE_SCI99: indexTable = "base_from_icpi_index" dataTable = "base_from_icpi_data" case utils.DATA_SOURCE_BUSINESS: indexTable = "base_from_business_index" dataTable = "base_from_business_data" case utils.DATA_SOURCE_BLOOMBERG: indexTable = "base_from_bloomberg_index" dataTable = "base_from_bloomberg_data" default: utils.FileLog.Info(fmt.Sprintf("数据源无对应表名, source: %d, sub: %d", source, subSource)) } return } // getCoalmineDataTableName 获取中国煤炭市场网数据表名 func getCoalmineDataTableName(indexCode string) string { if strings.Contains(indexCode, "jsm") { return "base_from_coalmine_jsm_index" } if strings.Contains(indexCode, "company") { return "base_from_coalmine_company_index" } if strings.Contains(indexCode, "firm") { return "base_from_coalmine_firm_index" } if strings.Contains(indexCode, "coastal") { return "base_from_coalmine_coastal_index" } if strings.Contains(indexCode, "inland") { return "base_from_coalmine_inland_index" } return "" } // GetBaseIndexDataMinMax 获取数据源极值 func GetBaseIndexDataMinMax(source, subSource int, indexCode string) (item *BaseIndexDataMinMax, err error) { o := orm.NewOrmUsingDB("data") var sql string var latestVal float64 // 煤炭江湖 if source == utils.DATA_SOURCE_MTJH { sql = `SELECT MIN(data_time) AS min_date, MAX(data_time) AS max_date FROM base_from_mtjh_index WHERE index_code = ?` if e := o.Raw(sql, indexCode).QueryRow(&item); e != nil { err = fmt.Errorf("获取数据源开始结束时间失败, %v", e) return } sql = `SELECT deal_value AS latest_value FROM base_from_mtjh_index WHERE index_code = ? ORDER BY data_time DESC LIMIT 1` if e := o.Raw(sql, indexCode).QueryRow(&latestVal); e != nil { err = fmt.Errorf("获取数据源最新值失败, %v", e) return } item.LatestValue = latestVal return } // 中国煤炭市场网 if source == utils.DATA_SOURCE_COAL { dataTable := getCoalmineDataTableName(indexCode) if dataTable == "" { err = fmt.Errorf("中国煤炭市场网-指标无对应表名: %s", indexCode) return } fieldDataTime := "data_time" if dataTable == "base_from_coalmine_firm_index" { fieldDataTime = "data_time_date" } sql = `SELECT MIN(%s) AS min_date, MAX(%s) AS max_date FROM %s WHERE index_code = ?` sql = fmt.Sprintf(sql, fieldDataTime, fieldDataTime, dataTable) if e := o.Raw(sql, indexCode).QueryRow(&item); e != nil { err = fmt.Errorf("获取数据源开始结束时间失败, %v", e) return } sql = `SELECT deal_value AS latest_value FROM %s WHERE index_code = ? ORDER BY %s DESC LIMIT 1` sql = fmt.Sprintf(sql, dataTable, fieldDataTime) if e := o.Raw(sql, indexCode).QueryRow(&latestVal); e != nil { err = fmt.Errorf("获取数据源最新值失败, %v", e) return } item.LatestValue = latestVal return } // 其他数据源 _, dataTable := GetBaseIndexDataTableName(source, subSource) if dataTable == "" { err = fmt.Errorf("数据源无对应数据表, source: %d, sub: %d, code: %s", source, subSource, indexCode) return } sql = `SELECT MIN(data_time) AS min_date, MAX(data_time) AS max_date FROM %s WHERE index_code = ?` sql = fmt.Sprintf(sql, dataTable) if e := o.Raw(sql, indexCode).QueryRow(&item); e != nil { err = fmt.Errorf("获取数据源开始结束时间失败, %v", e) return } sql = `SELECT value AS latest_value FROM %s WHERE index_code = ? ORDER BY data_time DESC LIMIT 1` sql = fmt.Sprintf(sql, dataTable) if e := o.Raw(sql, indexCode).QueryRow(&latestVal); e != nil { err = fmt.Errorf("获取数据源最新值失败, %v", e) return } item.LatestValue = latestVal return }