edb_data_base.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_edb_lib/utils"
  5. "time"
  6. )
  7. //指标检索数据
  8. type EdbDataItem struct {
  9. EdbCode string `description:"指标编码"`
  10. StartDate string `description:"起始日期"`
  11. EndDate string `description:"终止日期"`
  12. EdbName string `description:"指标名称"`
  13. Unit string `description:"单位"`
  14. Frequency string `description:"频率"`
  15. DataList []*EdbData
  16. }
  17. type EdbData struct {
  18. EdbDataId int `orm:"column(edb_data_id);pk"`
  19. EdbInfoId int
  20. EdbCode string
  21. DataTime string
  22. Value string
  23. Status int
  24. CreateTime time.Time
  25. ModifyTime time.Time
  26. DataTimestamp int64
  27. }
  28. func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr string, value string) (addSql string) {
  29. nowStr := time.Now().Format(utils.FormatDateTime)
  30. addSql += "("
  31. addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
  32. "," + "'" + nowStr + "'" + "," + "1"
  33. addSql += "," + "'" + timestampStr + "'"
  34. addSql += "),"
  35. return
  36. }
  37. type AddEdbInfoReq struct {
  38. EdbCode string `description:"指标编码"`
  39. }
  40. // GetEdbInfoCountByCondition 获取指标数量
  41. func GetEdbInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  42. o := orm.NewOrm()
  43. sql := ` SELECT COUNT(1) AS count FROM edb_info WHERE 1=1 `
  44. if condition != "" {
  45. sql += condition
  46. }
  47. err = o.Raw(sql, pars).QueryRow(&count)
  48. return
  49. }