base_from_coal_inland.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import (
  3. "eta/eta_index_lib/global"
  4. "time"
  5. )
  6. // BaseFromCoalmineInlandIndex 沿海八省动力煤用户供耗存数据指标表
  7. type BaseFromCoalmineInlandIndex struct {
  8. BaseFromCoalmineInlandIndexID int `gorm:"column:base_from_coalmine_inland_index_id;primaryKey"`
  9. //BaseFromCoalmineInlandIndexID int `orm:"column(base_from_coalmine_inland_index_id);pk"`
  10. IndexName string // 省份/企业名称
  11. IndexCode string // 持买单量指标编码
  12. DataTime string // 指标时间
  13. DealValue string // 数据量
  14. GroupName string // 地区
  15. Source string // 来源
  16. Unit string // 来源
  17. Frequency string `description:"频率"`
  18. CreateTime time.Time `description:"插入时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. }
  21. // 查询指标
  22. func GetBaseFromCoalmineInlandIndex() (items []*BaseFromCoalmineInlandIndex, err error) {
  23. //o := orm.NewOrm()
  24. sql := `SELECT * FROM base_from_coalmine_inland_index`
  25. //_, err = o.Raw(sql).QueryRows(&items)
  26. err = global.DEFAULT_DB.Raw(sql).Find(&items).Error
  27. return
  28. }
  29. // 添加数据
  30. func AddBaseFromCoalInlandIndex(item *BaseFromCoalmineInlandIndex) (lastId int64, err error) {
  31. //o := orm.NewOrm()
  32. //lastId, err = o.Insert(item)
  33. err = global.DEFAULT_DB.Create(&item).Error
  34. if err != nil {
  35. return
  36. }
  37. lastId = int64(item.BaseFromCoalmineInlandIndexID)
  38. return
  39. }
  40. func UpdateBaseFromCoalInlandIndex(item *BaseFromCoalmineInlandIndex) (err error) {
  41. //o := orm.NewOrm()
  42. sql := `UPDATE base_from_coalmine_inland_index SET deal_value=? WHERE index_name=? AND data_time = ?`
  43. //_, err = o.Raw(sql, item.DealValue, item.IndexName, item.DataTime).Exec()
  44. err = global.DEFAULT_DB.Exec(sql, item.DealValue, item.IndexName, item.DataTime).Error
  45. return
  46. }