123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- package data_manage
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type BaseFromMtjhMapping struct {
- BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"`
- 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"`
- 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"`
- 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 GetBaseFromMtjhMapping() (items []*BaseFromMtjhMapping, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM base_from_mtjh_mapping`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 查询指标
- func GetBaseFromMtjhIndex() (items []*BaseFromMtjhIndex, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM base_from_mtjh_index`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 添加数据
- func AddBaseFromMtjhIndex(item *BaseFromMtjhIndex) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- func AddBaseFromMtjhIndexMuti(items []*BaseFromMtjhIndex) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.InsertMulti(500, items)
- return
- }
- // 添加指标
- func AddBaseFromMtjhMapping(item *BaseFromMtjhMapping) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- func AddBaseFromMtjhMappingMuti(items []*BaseFromMtjhMapping) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.InsertMulti(500, items)
- return
- }
- func UpdateBaseFromMtjhIndex(item *BaseFromMtjhIndex) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE base_from_mtjh_index SET deal_value=? WHERE index_name=? AND data_time = ?`
- _, err = o.Raw(sql, item.DealValue, item.IndexName, item.DataTime).Exec()
- return
- }
- func GetMtjhClassifyList() (list []*BaseFromMtjhMapping, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT * FROM base_from_mtjh_mapping group by area"
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- type BaseFromMtjhMappingItem struct {
- BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"`
- 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) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_mtjh_mapping WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY base_from_mtjh_mapping_id asc`
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type BaseFromMtjhIndexList struct {
- BaseFromMtjhMappingId int `orm:"column(base_from_mtjh_mapping_id);pk"`
- 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) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM base_from_mtjh_index WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&count)
- return
- }
- func GetMtjhIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromMtjhIndexItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
- return
- }
- // GetMtjhItemList 模糊查询煤炭江湖数据库指标列表
- func GetMtjhItemList(keyword string) (items []*BaseFromMtjhMappingItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT * FROM base_from_mtjh_mapping WHERE CONCAT(index_name,index_code) LIKE ? "
- _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
- return
- }
- // 查询数据
- func GetBaseFromMtjhIndexByCode(indexCode string) (items []*BaseFromMtjhIndexItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_mtjh_index WHERE index_code=? ORDER BY data_time DESC `
- _, err = o.Raw(sql, indexCode).QueryRows(&items)
- return
- }
- // GetMtjhMappingItemByCode
- func GetMtjhMappingItemByCode(indexCode string) (item *BaseFromMtjhMappingItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT * FROM base_from_mtjh_mapping WHERE index_code=? "
- err = o.Raw(sql, indexCode).QueryRow(&item)
- return
- }
- // GetMtjhFrequencyByArea
- func GetMtjhFrequencyByArea(area string) (items []*string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT frequency FROM base_from_mtjh_index WHERE area=? group by area "
- _,err = o.Raw(sql, area).QueryRows(&items)
- return
- }
- func GetClassifyMtjhByArea(area string) (items []*string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT DISTINCT index_code FROM base_from_mtjh_index WHERE area=? `
- _, err = o.Raw(sql, area).QueryRows(&items)
- return
- }
- func GetCoalMtjhMaxCount(area string) (count int, err error) {
- o := orm.NewOrmUsingDB("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).QueryRow(&count)
- return
- }
- func GetMtjhCount(indexCode string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT
- COUNT( 1 ) AS num
- FROM
- base_from_mtjh_index
- WHERE
- index_code =? `
- err = o.Raw(sql, indexCode).QueryRow(&count)
- return
- }
- func GetMtjhIndexLatestDate(indexCode string) (ModifyTime string, err error) {
- o := orm.NewOrmUsingDB("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).QueryRow(&ModifyTime)
- return
- }
|