package data_manage import ( "eta/eta_api/global" "eta/eta_api/utils" "time" "gorm.io/gorm" "github.com/rdlucklib/rdluck_tools/paging" ) type BaseFromKplerIndex struct { BaseFromKplerIndexId int `orm:"column(base_from_kpler_index_id);pk" gorm:"primaryKey"` ClassifyId int IndexCode string IndexName string Frequency string Unit string Sort int StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` EndValue float64 CreateTime time.Time ModifyTime time.Time BaseFileName string `description:"文件目录"` TerminalCode string `description:"所属终端编码"` ApiQueryUrl string `description:"API查询URL"` ProductNames string `description:"产品名称"` FromZoneId int `description:"区域ID"` FromZoneName string `description:"区域名称"` ToZoneId int `description:"区域ID"` ToZoneName string `description:"区域名称"` FlowDirection string `description:"流向"` Granularity string `description:"粒度"` Split string `description:"拆分类型"` } type BaseFromKplerIndexList struct { BaseFromKplerIndexId int `orm:"column(base_from_kpler_index_id);pk" gorm:"primaryKey"` ClassifyId int Interface string EdbInfoId int EdbUniqueCode string `description:"指标库唯一编码"` EdbClassifyId int `description:"指标库分类ID"` StartDate string EndDate string EndValue float64 IndexCode string IndexName string Frequency string Unit string Sort int CreateTime string ModifyTime string BaseFileName string `description:"文件目录"` TerminalCode string `description:"所属终端编码"` ApiQueryUrl string `description:"API查询URL"` ProductNames string `description:"产品名称"` FromZoneId int `description:"区域ID"` FromZoneName string `description:"区域名称"` ToZoneId int `description:"区域ID"` ToZoneName string `description:"区域名称"` FlowDirection string `description:"流向"` Granularity string `description:"粒度"` Split string `description:"拆分类型"` EdbExist int `description:"指标库是否已添加:0-否;1-是"` DataList []*BaseFromKplerData `gorm:"-"` Paging *paging.PagingItem `description:"分页数据" gorm:"-"` } func (obj *BaseFromKplerIndexList) AfterFind(db *gorm.DB) (err error) { obj.CreateTime = utils.GormDateStrToDateTimeStr(obj.CreateTime) obj.ModifyTime = utils.GormDateStrToDateTimeStr(obj.ModifyTime) obj.StartDate = utils.GormDateStrToDateStr(obj.StartDate) obj.EndDate = utils.GormDateStrToDateStr(obj.EndDate) return } type BaseFromKplerIndexSearchList struct { List []*BaseFromKplerIndexList Paging *paging.PagingItem `description:"分页数据"` } type KplerSingleDataResp struct { BaseFromKplerIndexId 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 []*KplerSingleData } type KplerSingleData struct { Value string `orm:"column(value)" description:"日期"` DataTime string `orm:"column(data_time)" description:"值"` } func GetKplerIndexByClassifyId(classifyId int) (items []*BaseFromKplerIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT base_from_kpler_index_id, classify_id, index_code, index_name FROM base_from_kpler_index WHERE classify_id=? ORDER BY sort ASC, base_from_kpler_index_id ASC ` err = o.Raw(sql, classifyId).Find(&items).Error return } func GetKplerIndex(condition string, pars []interface{}) (items []*BaseFromKplerIndexList, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_kpler_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY sort ASC, base_from_kpler_index_id asc` err = o.Raw(sql, pars...).Find(&items).Error return } func GetKplerIndexPage(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromKplerIndexList, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_kpler_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY sort ASC, base_from_kpler_index_id asc LIMIT ?,?` pars = append(pars, startSize, pageSize) err = o.Raw(sql, pars...).Find(&items).Error return } func GetKplerIndexPageCount(condition string, pars []interface{}) (count int, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT COUNT(1) AS count FROM base_from_kpler_index WHERE 1=1 ` if condition != "" { sql += condition } err = o.Raw(sql, pars...).Scan(&count).Error return } func GetKplerIndexDataCount(indexCode string) (count int, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT COUNT(1) AS count FROM base_from_kpler_data WHERE index_code=? ` err = o.Raw(sql, indexCode).Scan(&count).Error return } func GetKplerIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromKplerData, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT * FROM base_from_kpler_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) and data_time >=? and data_time