123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- package data_manage
- import (
- "eta_gn/eta_task/global"
- "time"
- )
- type BaseFromSmm struct {
- BaseFromSmmId int `orm:"column(base_from_smm_id);pk"`
- Aid int
- Name string
- Interface string
- ApiUpdate int
- ApiUpdateType string
- ApiType int
- ApiTypeAll string
- Type1 string `orm:"column(type_1)"`
- Type2 string `orm:"column(type_2)"`
- Type3 string `orm:"column(type_3)"`
- ApiStartTime string
- ApiUpdateTime string
- StartTime string
- FinishTime string
- AuthModule string
- AuthLang string
- ApiLabel string
- Enable string
- EditPerson string
- EditTime string
- AuthDur int
- AuthDurType string
- StartDate string
- EndDate string
- }
- func AddBaseFromSmm(item *BaseFromSmm) (lastId int64, err error) {
- //o := orm.NewOrm()
- //lastId, err = o.Insert(item)
- err = global.DEFAULT_DmSQL.Create(item).Error
- if err != nil {
- return
- }
- lastId = int64(item.BaseFromSmmId)
- return
- }
- func GetBaseFromSmmList() (list []*BaseFromSmm, err error) {
- //o := orm.NewOrm()
- //sql := `SELECT * FROM base_from_smm WHERE interface='cu_annual_copper_cathode_demand_supply_balance_in_china' `
- sql := `SELECT * FROM base_from_smm WHERE end_date IS NOT NULL `
- //_, err = o.Raw(sql).QueryRows(&list)
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&list).Error
- return
- }
- type BaseFromSmmIndex struct {
- BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
- Interface string
- Name string
- IndexCode string
- IndexName string
- Type1 string `orm:"column(type_1)"`
- Type2 string `orm:"column(type_2)"`
- Type3 string `orm:"column(type_3)"`
- Frequency string
- Unit string
- ApiStartTime string
- ApiUpdateTime string
- StartTime string
- FinishTime string
- CreateTime time.Time
- ModifyTime time.Time
- }
- func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
- //o := orm.NewOrm()
- //lastId, err = o.Insert(item)
- err = global.DEFAULT_DmSQL.Create(item).Error
- if err != nil {
- return
- }
- lastId = int64(item.BaseFromSmmIndexId)
- return
- }
- func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) {
- //o := orm.NewOrm()
- sql := `SELECT * FROM base_from_smm_index `
- //_, err = o.Raw(sql).QueryRows(&list)
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&list).Error
- return
- }
- type BaseFromSmmData struct {
- SmmDataId int `orm:"column(smm_data_id);pk"`
- BaseFromSmmIndexId int
- IndexCode string
- DataTime string
- Value string
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) {
- //o := orm.NewOrm()
- //lastId, err = o.Insert(item)
- err = global.DEFAULT_DmSQL.Create(item).Error
- if err != nil {
- return
- }
- lastId = int64(item.SmmDataId)
- return
- }
- func GetBaseFromSmmDataAll(indexCode string) (list []*BaseFromSmmData, err error) {
- //o := orm.NewOrm()
- sql := `SELECT * FROM base_from_smm_data WHERE index_code=?`
- //_, err = o.Raw(sql, indexCode).QueryRows(&list)
- err = global.DEFAULT_DmSQL.Raw(sql, indexCode).Find(&list).Error
- return
- }
- func ModifyBaseFromSmmData(smmDataId int, value string) (err error) {
- //o := orm.NewOrm()
- sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? `
- //_, err = o.Raw(sql, value, smmDataId).Exec()
- err = global.DEFAULT_DmSQL.Exec(sql, value, smmDataId).Error
- return
- }
- func GetBaseFromSmmIndexByCode(smmCode string) (list []*BaseFromSmmIndex, err error) {
- //o := orm.NewOrm()
- sql := ` SELECT * FROM base_from_smm_index WHERE interface=? `
- //_, err = o.Raw(sql, smmCode).QueryRows(&list)
- err = global.DEFAULT_DmSQL.Raw(sql, smmCode).Find(&list).Error
- return
- }
- func GetBaseFromSmmMaxOrMinDate(indexCode string) (min_date, max_date string, err error) {
- //o := orm.NewOrm()
- sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? `
- //err = o.Raw(sql, indexCode).QueryRow(&min_date, &max_date)
- err = global.DEFAULT_DmSQL.Raw(sql, indexCode).First(min_date, &max_date).Error
- return
- }
- func ModifyBaseFromSmmSmmType(baseFromSmmId int, smmType string) (err error) {
- //o := orm.NewOrm()
- sql := ` UPDATE base_from_smm SET smm_type=? WHERE base_from_smm_id=? `
- //_, err = o.Raw(sql, smmType, baseFromSmmId).Exec()
- err = global.DEFAULT_DmSQL.Exec(sql, smmType, baseFromSmmId).Error
- return
- }
- func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId, baseFromSmmId int, minDate, maxDate string) (err error) {
- to := global.DEFAULT_DmSQL.Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- //o := orm.NewOrm()
- sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? `
- //_, err = o.Raw(sql, minDate, maxDate, baseFromSmmIndexId).Exec()
- err = to.Exec(sql, minDate, maxDate, baseFromSmmIndexId).Error
- if err != nil {
- return
- }
- sql = ` UPDATE base_from_smm SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_id=? `
- //_, err = o.Raw(sql, minDate, maxDate, baseFromSmmId).Exec()
- err = to.Exec(sql, minDate, maxDate, baseFromSmmId).Error
- return
- }
- type BaseFromSmmDataSimple struct {
- SmmDataId int `orm:"column(smm_data_id);pk"`
- BaseFromSmmIndexId int
- IndexCode string
- DataTime string
- Value float64
- }
- func GetBaseFromSmmDataByCondition(condition string, pars []interface{}) (list []*BaseFromSmmDataSimple, err error) {
- //o := orm.NewOrm()
- sql := `SELECT * FROM base_from_smm_data WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- //_, err = o.Raw(sql, pars).QueryRows(&list)
- err = global.DEFAULT_DmSQL.Raw(sql, pars).Find(&list).Error
- return
- }
|