package data_manage import ( "eta/eta_api/global" "eta/eta_api/utils" "gorm.io/gorm" "time" "github.com/rdlucklib/rdluck_tools/paging" ) type BaseFromYongyiIndex struct { YongyiIndexId int `orm:"column(yongyi_index_id);pk"` ClassifyId int IndexCode string IndexName string Frequency string Unit string Sort int CreateTime time.Time ModifyTime time.Time } type BaseFromYongyiIndexList struct { YongyiIndexId int `orm:"column(yongyi_index_id);pk"` ClassifyId int Interface string EdbInfoId int EdbUniqueCode string `description:"指标库唯一编码"` EdbClassifyId int `description:"指标库分类ID"` IndexCode string IndexName string Frequency string Unit string Sort int CreateTime string ModifyTime string EdbExist int `description:"指标库是否已添加:0-否;1-是"` DataList []*BaseFromYongyiData `gorm:"-"` Paging *paging.PagingItem `description:"分页数据" gorm:"-"` } func (m *BaseFromYongyiIndexList) AfterFind(tx *gorm.DB) (err error) { if utils.NeedDateOrTimeFormat(utils.DbDriverName) { if m.CreateTime != "" { m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime) } if m.ModifyTime != "" { m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime) } } return } type YongyiSingleDataResp struct { YongyiIndexId int ClassifyId int EdbInfoId int IndexCode string IndexName string Frequency string Unit string StartTime string CreateTime string ModifyTime string EdbExist int `description:"指标库是否已添加:0-否;1-是"` Data []*YongyiSingleData } type YongyiSingleData struct { Value string `orm:"column(value)" description:"日期"` DataTime string `orm:"column(data_time)" description:"值"` } func GetYongyiIndexByClassifyId(classifyId int) (items []*BaseFromYongyiIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT yongyi_index_id, classify_id, index_code, index_name FROM base_from_yongyi_index WHERE classify_id=? ORDER BY sort ASC, yongyi_index_id ASC ` err = o.Raw(sql, classifyId).Find(&items).Error return } func GetYongyiIndex(condition string, pars []interface{}) (items []*BaseFromYongyiIndexList, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY sort ASC, yongyi_index_id asc` err = o.Raw(sql, pars...).Find(&items).Error return } func GetYongyiIndexDataCount(indexCode string) (count int, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT COUNT(1) AS count FROM base_from_yongyi_data WHERE index_code=? ` err = o.Raw(sql, indexCode).Scan(&count).Error return } func GetYongyiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromYongyiData, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? ` err = o.Raw(sql, indexCode, startSize, pageSize).Find(&items).Error return } func GetYongyiIndexDataByCodes(indexCode []string) (items []*BaseFromYongyiData, err error) { if len(indexCode) == 0 { return } o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_yongyi_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC ` err = o.Raw(sql, indexCode).Find(&items).Error return } // GetYongyiByConditionAndFrequency 根据条件获取涌益咨询指标列表 func GetYongyiByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromYongyiIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_yongyi_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` AND frequency=?` sql += ` ORDER BY sort ASC, yongyi_index_id ASC` err = o.Raw(sql, pars, frequency).Find(&items).Error return } func GetYongyiFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) { sql := `SELECT DISTINCT frequency FROM base_from_yongyi_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') ` o := global.DbMap[utils.DbNameIndex] err = o.Raw(sql, pars...).Find(&items).Error return } // GetYongyiDataDataTimeByIndexId 根据指标id获取指标数据的日期列表 func GetYongyiDataDataTimeByIndexId(indexIdList []int) (items []string, err error) { if len(indexIdList) == 0 { return } o := global.DbMap[utils.DbNameIndex] sql := ` SELECT DISTINCT data_time FROM base_from_yongyi_data WHERE yongyi_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC` err = o.Raw(sql, indexIdList).Find(&items).Error return } type BaseFromYongyiData struct { YongyiDataId int `orm:"column(yongyi_data_id);pk" gorm:"primaryKey"` YongyiIndexId int IndexCode string DataTime string Value string CreateTime string ModifyTime string DataTimestamp int64 `gorm:"column:data_timestamp"` } func (m *BaseFromYongyiData) AfterFind(tx *gorm.DB) (err error) { if utils.NeedDateOrTimeFormat(utils.DbDriverName) { if m.CreateTime != "" { m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime) } if m.ModifyTime != "" { m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime) } if m.DataTime != "" { m.DataTime = utils.GormDateStrToDateStr(m.DataTime) } } return } type BaseFromYongyiIndexSearchItem struct { YongyiIndexId int `orm:"column(yongyi_index_id);pk" gorm:"primaryKey"` ClassifyId int ParentClassifyId int IndexCode string IndexName string } // GetYongyiItemList 模糊查询Yongyi数据库指标列表 func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) { o := global.DbMap[utils.DbNameIndex] sql := "SELECT * FROM base_from_yongyi_index WHERE 1=1" if condition != "" { sql += condition } err = o.Raw(sql).Find(&items).Error return } func GetYongyiIndexDataByCode(indexCode string) (list []*BaseFromYongyiData, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_yongyi_data WHERE index_code=? ` err = o.Raw(sql, indexCode).Find(&list).Error return } func GetBaseFromYongyiIndexByIndexCode(indexCode string) (list *BaseFromYongyiIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_yongyi_index WHERE index_code=? ` err = o.Raw(sql, indexCode).First(&list).Error return } type BaseFromYongyiIndexType struct { Type2 string `gorm:"column:type_2"` Type3 string `gorm:"column:type_3"` } // Update 更新Yongyi指标基础信息 func (item *BaseFromYongyiIndex) Update(cols []string) (err error) { o := global.DbMap[utils.DbNameIndex] err = o.Select(cols).Updates(item).Error return } // EditYongyiIndexInfoResp 新增指标的返回 type EditYongyiIndexInfoResp struct { YongyiIndexId int `description:"指标ID"` IndexCode string `description:"指标code"` }