123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package data_manage
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_ETA_mobile_api/utils"
- "time"
- )
- // 指标数据->存储表
- func GetEdbDataTableName(source int) (tableName string) {
- switch source {
- case utils.DATA_SOURCE_THS:
- tableName = "edb_data_ths"
- case utils.DATA_SOURCE_WIND:
- tableName = "edb_data_wind"
- case utils.DATA_SOURCE_PB, utils.DATA_SOURCE_PB_FINANCE: //彭博经济数据、彭博财务数据
- tableName = "edb_data_pb"
- case utils.DATA_SOURCE_CALCULATE:
- tableName = "edb_data_calculate"
- case utils.DATA_SOURCE_CALCULATE_LJZZY:
- tableName = "edb_data_calculate_ljzzy"
- case utils.DATA_SOURCE_CALCULATE_TBZ:
- tableName = "edb_data_calculate_tbz"
- case utils.DATA_SOURCE_CALCULATE_TCZ:
- tableName = "edb_data_calculate_tcz"
- case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
- tableName = "edb_data_calculate_nszydpjjs"
- case utils.DATA_SOURCE_MANUAL:
- tableName = "edb_data_manual"
- case utils.DATA_SOURCE_LZ:
- tableName = "edb_data_lz"
- case utils.DATA_SOURCE_YS:
- tableName = "edb_data_ys"
- case utils.DATA_SOURCE_CALCULATE_HBZ:
- tableName = "edb_data_calculate_hbz"
- case utils.DATA_SOURCE_CALCULATE_HCZ:
- tableName = "edb_data_calculate_hcz"
- case utils.DATA_SOURCE_CALCULATE_BP:
- tableName = "edb_data_calculate_bp"
- case utils.DATA_SOURCE_GL:
- tableName = "edb_data_gl"
- case utils.DATA_SOURCE_ZZ:
- tableName = "edb_data_zz"
- case utils.DATA_SOURCE_DL:
- tableName = "edb_data_dl"
- case utils.DATA_SOURCE_SH:
- tableName = "edb_data_sh"
- case utils.DATA_SOURCE_CFFEX:
- tableName = "edb_data_cffex"
- case utils.DATA_SOURCE_SHFE:
- tableName = "edb_data_ine"
- case utils.DATA_SOURCE_GIE:
- tableName = "edb_data_gie"
- case utils.DATA_SOURCE_CALCULATE_ZJPJ:
- tableName = "edb_data_calculate_zjpj"
- case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT:
- tableName = "edb_data_calculate_time_shift"
- case utils.DATA_SOURCE_CALCULATE_LJZTBPJ:
- tableName = "edb_data_calculate_ljztbpj"
- case utils.DATA_SOURCE_LT:
- tableName = "edb_data_lt"
- case utils.DATA_SOURCE_COAL:
- tableName = "edb_data_coal"
- case utils.DATA_SOURCE_PYTHON:
- tableName = "edb_data_python"
- case utils.DATA_SOURCE_GOOGLE_TRAVEL:
- tableName = "edb_data_google_travel"
- case utils.DATA_SOURCE_PREDICT_CALCULATE:
- tableName = "edb_data_predict_calculate"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
- tableName = "edb_data_predict_calculate_tbz"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
- tableName = "edb_data_predict_calculate_tcz"
- case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
- tableName = "edb_data_mysteel_chemical"
- case utils.DATA_SOURCE_CALCULATE_CJJX:
- tableName = "edb_data_calculate_cjjx"
- case utils.DATA_SOURCE_EIA_STEO:
- tableName = "edb_data_eia_steo"
- case utils.DATA_SOURCE_CALCULATE_NHCC:
- tableName = "edb_data_calculate_nhcc"
- case utils.DATA_SOURCE_COM_TRADE:
- tableName = "edb_data_com_trade"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
- tableName = "edb_data_predict_calculate_nszydpjjs"
- case utils.DATA_SOURCE_CALCULATE_ADJUST:
- tableName = "edb_data_calculate_adjust"
- case utils.DATA_SOURCE_SCI:
- tableName = "edb_data_sci"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
- tableName = "edb_data_predict_calculate_ljzzy"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
- tableName = "edb_data_predict_calculate_time_shift"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ:
- tableName = "edb_data_predict_calculate_zjpj"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ:
- tableName = "edb_data_predict_calculate_ljztbpj"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC:
- tableName = "edb_data_predict_calculate_nhcc"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
- tableName = "edb_data_predict_calculate_cjjx"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
- tableName = "edb_data_predict_calculate_hbz"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
- tableName = "edb_data_predict_calculate_hcz"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_BP:
- tableName = "edb_data_predict_calculate_bp"
- case utils.DATA_SOURCE_CALCULATE_JP:
- tableName = "edb_data_calculate_jp"
- case utils.DATA_SOURCE_CALCULATE_NH:
- tableName = "edb_data_calculate_nh"
- case utils.DATA_SOURCE_CALCULATE_KSZS:
- tableName = "edb_data_calculate_kszs"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
- tableName = "edb_data_predict_calculate_jp"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
- tableName = "edb_data_predict_calculate_nh"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS:
- tableName = "edb_data_predict_calculate_kszs"
- case utils.DATA_SOURCE_BAIINFO:
- tableName = "edb_data_baiinfo"
- case utils.DATA_SOURCE_STOCK_PLANT:
- tableName = "edb_data_stock_plant"
- case utils.DATA_SOURCE_CALCULATE_CORRELATION:
- tableName = "edb_data_calculate_correlation"
- case utils.DATA_SOURCE_NATIONAL_STATISTICS:
- tableName = "edb_data_national_statistics"
- case utils.DATA_SOURCE_CALCULATE_LJZZJ: //累计值转季 -> 61
- tableName = "edb_data_calculate_ljzzj"
- case utils.DATA_SOURCE_CALCULATE_LJZ: //累计值 -> 62
- tableName = "edb_data_calculate_ljz"
- case utils.DATA_SOURCE_CALCULATE_LJZNCZJ: //累计值(年初至今) -> 63
- tableName = "edb_data_calculate_ljznczj"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZJ: // 预测指标 - 累计值 -> 65
- tableName = "edb_data_predict_calculate_ljzzj"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZ: //预测指标 - 累计值转季->64
- tableName = "edb_data_predict_calculate_ljz"
- case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ: //预测指标 - 累计值(年初至今) -> 66
- tableName = "edb_data_predict_calculate_ljznczj"
- case utils.DATA_SOURCE_FUBAO: //富宝数据 -> 71
- tableName = "edb_data_fubao"
- default:
- tableName = ""
- }
- return
- }
- //计算指标->关联的基础指标表
- //func GetEdbInfoCalculateTableName(source int) (tableName string) {
- // switch source {
- // case utils.DATA_SOURCE_CALCULATE:
- // tableName = "edb_info_calculate"
- // case utils.DATA_SOURCE_CALCULATE_LJZZY:
- // tableName = "edb_info_calculate_ljzzy"
- // case utils.DATA_SOURCE_CALCULATE_TBZ:
- // tableName = "edb_info_calculate_tbz"
- // case utils.DATA_SOURCE_CALCULATE_TCZ:
- // tableName = "edb_info_calculate_tcz"
- // case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
- // tableName = "edb_info_calculate_nszydpjjs"
- // case utils.DATA_SOURCE_CALCULATE_HBZ:
- // tableName = "edb_info_calculate_hbz"
- // case utils.DATA_SOURCE_CALCULATE_HCZ:
- // tableName = "edb_info_calculate_hcz"
- // case utils.DATA_SOURCE_CALCULATE_BP:
- // tableName = "edb_info_calculate_bp"
- // default:
- // tableName = ""
- // }
- // return
- //}
- type EdbDataBase struct {
- EdbDataId int `orm:"column(edb_data_id);pk"`
- EdbInfoId int
- EdbCode string
- DataTime string
- Value string
- Status int
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbInfoSearchData, err error) {
- var pars []interface{}
- pars = append(pars, edbCode)
- o := orm.NewOrmUsingDB("data")
- tableName := GetEdbDataTableName(source)
- sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
- if limit > 0 {
- sql += ` LIMIT ? `
- pars = append(pars, limit)
- }
- sql = fmt.Sprintf(sql, tableName)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- tableName := GetEdbDataTableName(source)
- sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
- sql = fmt.Sprintf(sql, tableName)
- err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
- return
- }
|