edb_info.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type EdbInfo struct {
  8. EdbInfoId int `orm:"column(edb_info_id);pk"`
  9. SourceName string `description:"来源名称"`
  10. Source int `description:"来源id"`
  11. EdbCode string `description:"指标编码"`
  12. EdbName string `description:"指标名称"`
  13. EdbNameSource string `description:"指标名称来源"`
  14. Frequency string `description:"频率"`
  15. Unit string `description:"单位"`
  16. StartDate string `description:"起始日期"`
  17. EndDate string `description:"终止日期"`
  18. ClassifyId int `description:"分类id"`
  19. SysUserId int
  20. SysUserRealName string
  21. UniqueCode string `description:"指标唯一编码"`
  22. CreateTime time.Time
  23. ModifyTime time.Time
  24. MinValue float64 `description:"指标最小值"`
  25. MaxValue float64 `description:"指标最大值"`
  26. CalculateFormula string `description:"计算公式"`
  27. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  28. Sort int `description:"排序字段"`
  29. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  30. MoveFrequency string `description:"移动频度"`
  31. }
  32. type EdbInfoMaxAndMinInfo struct {
  33. MinDate string `description:"最小日期"`
  34. MaxDate string `description:"最大日期"`
  35. MinValue float64 `description:"最小值"`
  36. MaxValue float64 `description:"最大值"`
  37. LatestValue float64 `description:"最新值"`
  38. }
  39. func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  40. o := orm.NewOrmUsingDB("data")
  41. sql := ``
  42. tableName := GetEdbDataTableName(source)
  43. sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
  44. sql = fmt.Sprintf(sql, tableName)
  45. err = o.Raw(sql, edbCode).QueryRow(&item)
  46. var latest_value float64
  47. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  48. sql = fmt.Sprintf(sql, tableName)
  49. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  50. item.LatestValue = latest_value
  51. return
  52. }
  53. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  54. o := orm.NewOrmUsingDB("data")
  55. sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id=? `
  56. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
  57. return
  58. }