package data_manage import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type BaseFromMtjhMapping struct { BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk" gorm:"primaryKey" ` IndexName string `description:"持买单量指标名称"` IndexCode string `description:"持买单量指标编码"` CreateTime time.Time `description:"时间"` Area string `description:"区域"` Port string `description:"港口或码头"` Variety string `description:"品种"` Unit string `description:"单位"` Frequency string `description:"频率"` } type BaseFromMtjhIndex struct { BaseFromMtjhIndexId int `orm:"column(base_from_mtjh_index_id);pk" gorm:"primaryKey" ` IndexName string `description:"持买单量指标名称"` IndexCode string `description:"持买单量指标编码"` DealValue string `description:"成交量"` DataTime string `description:"数据日期"` Area string `description:"区域"` Port string `description:"港口或码头"` Unit string `description:"单位"` Frequency string `description:"频率"` Variety string `description:"品种"` CreateTime time.Time `description:"插入时间"` ModifyTime time.Time `description:"修改时间"` } type BaseFromMtjhIndexItem struct { BaseFromMtjhIndexId int `orm:"column(base_from_mtjh_index_id);pk" gorm:"primaryKey" ` IndexName string `description:"持买单量指标名称"` IndexCode string `description:"持买单量指标编码"` DealValue string `description:"成交量"` DataTime string `description:"数据日期"` Area string `description:"区域"` Port string `description:"港口或码头"` Unit string `description:"单位"` Frequency string `description:"频率"` Variety string `description:"品种"` CreateTime string `description:"插入时间"` ModifyTime string `description:"修改时间"` } func GetMtjhClassifyList() (list []*BaseFromMtjhMapping, err error) { sql := "SELECT * FROM base_from_mtjh_mapping group by area" err = global.DmSQL["data"].Raw(sql).Scan(&list).Error return } type BaseFromMtjhMappingItem struct { BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk" gorm:"primaryKey" ` IndexName string `description:"持买单量指标名称"` IndexCode string `description:"持买单量指标编码"` CreateTime string `description:"时间"` Area string `description:"区域"` Port string `description:"港口或码头"` Variety string `description:"品种"` Unit string `description:"单位"` Frequency string `description:"频率"` } func GetMtjhMapping(condition string, pars []interface{}) (items []*BaseFromMtjhMappingItem, err error) { sql := ` SELECT * FROM base_from_mtjh_mapping WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY base_from_mtjh_mapping_id asc` err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error return } type BaseFromMtjhIndexList struct { BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk" gorm:"primaryKey" ` IndexName string `description:"持买单量指标名称"` IndexCode string `description:"持买单量指标编码"` Area string `description:"区域"` Port string `description:"港口或码头"` Unit string `description:"单位"` Frequency string `description:"频率"` CreateTime string `description:"插入时间"` ModifyTime string `description:"修改时间"` Variety string `description:"品种"` DataList []*BaseFromMtjhIndexItem Paging *paging.PagingItem `description:"分页数据"` } func GetMtjhIndexDataCount(indexCode string) (count int, err error) { sql := ` SELECT COUNT(1) AS count FROM base_from_mtjh_index WHERE index_code=? ` err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error return } func GetMtjhIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromMtjhIndexItem, err error) { sql := ` SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? ` err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Scan(&items).Error return } // GetMtjhItemList 模糊查询煤炭江湖数据库指标列表 func GetMtjhItemList(keyword string) (items []*BaseFromMtjhMappingItem, err error) { sql := "SELECT * FROM base_from_mtjh_mapping WHERE CONCAT(index_name,index_code) LIKE ? " err = global.DmSQL["data"].Raw(sql, utils.GetLikeKeyword(keyword)).Scan(&items).Error return } // 查询数据 func GetBaseFromMtjhIndexByCode(indexCode string) (items []*BaseFromMtjhIndexItem, err error) { sql := `SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC ` err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&items).Error return } // GetMtjhMappingItemByCode func GetMtjhMappingItemByCode(indexCode string) (item *BaseFromMtjhMappingItem, err error) { o := global.DmSQL["data"] sql := "SELECT * FROM base_from_mtjh_mapping WHERE index_code=? " err = o.Raw(sql, indexCode).First(&item).Error return } // GetMtjhFrequencyByArea func GetMtjhFrequencyByArea(area string) (items []*string, err error) { sql := "SELECT frequency FROM base_from_mtjh_index WHERE area=? group by area " err = global.DmSQL["data"].Raw(sql, area).Scan(&items).Error return } func GetClassifyMtjhByArea(area string) (items []*string, err error) { sql := `SELECT DISTINCT index_code FROM base_from_mtjh_index WHERE area=? ` err = global.DmSQL["data"].Raw(sql, area).Scan(&items).Error return } func GetCoalMtjhMaxCount(area string) (count int, err error) { o := global.DmSQL["data"] sql := `SELECT MAX( t.num ) AS count FROM ( SELECT COUNT( 1 ) AS num FROM base_from_mtjh_index WHERE area =? GROUP BY index_name ) AS t ` err = o.Raw(sql, area).Scan(&count).Error return } func GetMtjhCount(indexCode string) (count int, err error) { o := global.DmSQL["data"] sql := `SELECT COUNT( 1 ) AS num FROM base_from_mtjh_index WHERE index_code =? ` err = o.Raw(sql, indexCode).Scan(&count).Error return } func GetMtjhIndexLatestDate(indexCode string) (ModifyTime string, err error) { o := global.DmSQL["data"] sql := ` SELECT modify_time FROM base_from_mtjh_index WHERE index_code=? ORDER BY modify_time DESC limit 1 ` err = o.Raw(sql, indexCode).Scan(&ModifyTime).Error return }