package data_manage import ( sql2 "database/sql" "eta/eta_task/global" "eta/eta_task/utils" "time" ) // BaseFromEiaSteoIndex EiaSteo指标 type BaseFromEiaSteoIndex struct { BaseFromEiaSteoIndexId int `gorm:"column:base_from_eia_steo_index_id;primaryKey;autoIncrement"` BaseFromEiaSteoClassifyId int `description:"指标分类id"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称(中文名称)"` IndexNameOriginal string `description:"指标名称(原始名称)"` Frequency string `description:"频度"` Level int `description:"指标层级(原始层级)"` Unit string `description:"单位"` Super string `description:"我也不知道是个啥,反正先存起来,万一用到了呢"` Precision int `description:"精度,我也不知道会不会用到,反正先存起来,万一用到了呢"` LastHistorical string `description:"最近的历史记录,我也不知道会不会用到,反正先存起来,万一用到了呢"` Description string `description:"备注信息,我也不知道会不会用到,反正先存起来,万一用到了呢"` IsMappable int `description:"是否可映射,我也不知道会不会用到,反正先存起来,万一用到了呢"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` ModifyTime string `description:"最新更新时间"` CreateTime string `description:"创建时间"` LatestValue float64 `description:"最新值"` } func AddBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error if err != nil { return } lastId = int64(item.BaseFromEiaSteoIndexId) return } func InsertOrUpdateBaseFromEiaSteoIndex(item *BaseFromEiaSteoIndex) (lastId int64, err error) { saveItem := *item o := global.DbMap[utils.DbNameIndex] result := o.FirstOrCreate(item, "base_from_eia_steo_index_id = ?", item.BaseFromEiaSteoIndexId) if result.Error != nil { err = result.Error return } if result.RowsAffected == 0 { saveItem.BaseFromEiaSteoIndexId = 0 result = o.Model(item).Where("base_from_eia_steo_index_id = ?", item.BaseFromEiaSteoIndexId).Updates(saveItem) if result.Error != nil { err = result.Error return } } return int64(item.BaseFromEiaSteoIndexId), nil } // Add 新增指标 func (item *BaseFromEiaSteoIndex) Add() (err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } func GetBaseFromEiaSteoIndexAll(dateStr string) (list []*BaseFromEiaSteoIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_eia_steo_index WHERE create_time>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } func GetBaseFromEiaSteoIndexCodeListByDate(dateStr string) (list []string, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT index_code FROM base_from_eia_steo_index WHERE modify_time>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } // Update 更新作者基础信息 func (item *BaseFromEiaSteoIndex) Update(cols []string) (err error) { err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(item).Error return } // BaseFromEiaSteoClassify EiaSteo分类 type BaseFromEiaSteoClassify struct { BaseFromEiaSteoClassifyId int `gorm:"column:base_from_eia_steo_classify_id;primaryKey;autoIncrement"` ClassifyName string `description:"分类名称(中文名称)"` ClassifyNameOriginal string `description:"分类名称(原始名称)"` ParentId int `description:"父级id"` Level int `description:"层级"` ModifyTime time.Time `description:"最新更新时间"` CreateTime time.Time `description:"创建时间"` } func (item *BaseFromEiaSteoClassify) AddBaseFromEiaSteoClassify() (err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } // BaseFromEiaSteoData EiaSteo数据表 type BaseFromEiaSteoData struct { BaseFromEiaSteoDataId int `gorm:"column:base_from_eia_steo_data_id;primaryKey;autoIncrement"` BaseFromEiaSteoIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime time.Time `description:"数据日期"` Value float64 `description:"数据值"` ModifyTime time.Time `description:"最新更新时间"` CreateTime time.Time `description:"创建时间"` } func (b *BaseFromEiaSteoData) Update(cols []string) (err error) { err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(b).Error return } func AddBaseFromEiaSteoData(item *BaseFromEiaSteoData) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error if err != nil { return } lastId = int64(item.BaseFromEiaSteoDataId) return } // GetBaseFromEiaSteoClassifyAll 获取所有的分类 func GetBaseFromEiaSteoClassifyAll() (list []*BaseFromEiaSteoClassify, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_eia_steo_classify` err = o.Raw(sql).Find(&list).Error return } func AddBaseEiaSteoClassify(item *BaseFromEiaSteoClassify) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error if err != nil { return } lastId = int64(item.BaseFromEiaSteoClassifyId) return } func (item *BaseFromEiaSteoClassify) Update(cols []string) (err error) { err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(item).Error return } func BatchDeleteBaseFromEiaSteoClassify(id []int) (err error) { if len(id) == 0 { return } o := global.DbMap[utils.DbNameIndex] sql := `DELETE FROM base_from_eia_steo_classify WHERE base_from_eia_steo_classify_id IN (` + utils.GetOrmInReplace(len(id)) + `)` err = o.Exec(sql, id).Error return } type EiaSteoIndexResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromEiaSteoIndex } type EiaSteoIndexDataResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromEiaSteoData } type EiaSteoClassifyDataResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromEiaSteoClassify } func GetBaseFromEiaSteoIndexDataAll(dateStr string) (list []*BaseFromEiaSteoData, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_eia_steo_data WHERE create_time>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } func GetBaseFromEiaSteoIndexDataByIndexCode(indexCode, dateStr string) (list []*BaseFromEiaSteoData, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_eia_steo_data WHERE index_code=? AND modify_time>=?` err = o.Raw(sql, indexCode, dateStr).Find(&list).Error return } func GetBaseFromEiaSteoIndexDataByDate(dateStr string) (list []*BaseFromEiaSteoData, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_eia_steo_data WHERE modify_time>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } func GetBaseFromEiaSteoIndexMaxDate() (maxDate time.Time, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT MAX(a.data_time) AS max_date FROM base_from_eia_steo_data AS a ` var timeNull sql2.NullTime err = o.Raw(sql).Scan(&timeNull).Error if err != nil { return } if timeNull.Valid { maxDate = timeNull.Time } return } func GetBaseFromEiaSteoIndexMaxCreateDate() (maxDate time.Time, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT MAX(a.create_time) AS max_date FROM base_from_eia_steo_index AS a ` var timeNull sql2.NullTime err = o.Raw(sql).Scan(&timeNull).Error if err != nil { return } if timeNull.Valid { maxDate = timeNull.Time } return }