edb_info.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
  10. SourceName string `description:"来源名称"`
  11. Source int `description:"来源id"`
  12. EdbCode string `description:"指标编码"`
  13. EdbName string `description:"指标名称"`
  14. EdbNameSource string `description:"指标名称来源"`
  15. Frequency string `description:"频率"`
  16. Unit string `description:"单位"`
  17. StartDate string `description:"起始日期"`
  18. EndDate string `description:"终止日期"`
  19. ClassifyId int `description:"分类id"`
  20. SysUserId int
  21. SysUserRealName string
  22. UniqueCode string `description:"指标唯一编码"`
  23. CreateTime time.Time
  24. ModifyTime time.Time
  25. MinValue float64 `description:"指标最小值"`
  26. MaxValue float64 `description:"指标最大值"`
  27. CalculateFormula string `description:"计算公式"`
  28. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  29. Sort int `description:"排序字段"`
  30. LatestDate string `description:"数据最新日期"`
  31. LatestValue float64 `description:"数据最新值"`
  32. MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
  33. MoveFrequency string `description:"移动频度"`
  34. }
  35. type EdbInfoMaxAndMinInfo struct {
  36. MinDate string `description:"最小日期"`
  37. MaxDate string `description:"最大日期"`
  38. MinValue float64 `description:"最小值"`
  39. MaxValue float64 `description:"最大值"`
  40. LatestValue float64 `description:"最新值"`
  41. }
  42. func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. sql := ``
  45. tableName := GetEdbDataTableName(source)
  46. 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=? `
  47. sql = fmt.Sprintf(sql, tableName)
  48. err = o.Raw(sql, edbCode).QueryRow(&item)
  49. var latest_value float64
  50. sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
  51. sql = fmt.Sprintf(sql, tableName)
  52. err = o.Raw(sql, edbCode).QueryRow(&latest_value)
  53. item.LatestValue = latest_value
  54. return
  55. }
  56. func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  57. o := orm.NewOrmUsingDB("data")
  58. 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=? `
  59. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
  60. return
  61. }
  62. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  63. o := orm.NewOrmUsingDB("data")
  64. sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
  65. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  66. return
  67. }