edb_monitor.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package edbmonitor
  2. import (
  3. "eta/eta_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type EdbMonitorInfo struct {
  8. EdbMonitorId int `orm:"column(edb_monitor_id);pk"`
  9. EdbMonitorClassifyId int `description:"预警分类id"`
  10. EdbMonitorName string `description:"预警名称"`
  11. EdbInfoId int `description:"指标id"`
  12. EdbInfoType int `description:"指标类型"`
  13. EdbUniqueCode string `description:"指标唯一标识"`
  14. EdbClassifyId int `description:"指标id"`
  15. EdbCode string `description:"指标编码"`
  16. Source int `description:"指标来源"`
  17. SubSource int `description:"指标子来源: 0-经济数据库;1-日期序列;2-高频数据"`
  18. EdbLatestDate string `description:"最新日期"`
  19. EdbLatestValue float64 `description:"指标最新值"`
  20. MonitorType int `description:"突破方式: 0-向上突破;1-向下突破"`
  21. MonitorData float64 `description:"预警值"`
  22. MonitorLevel string `description:"预警等级"`
  23. State int `description:"预警状态: 0-已关闭;1-未触发;2-已触发"`
  24. EdbTriggerDate time.Time `description:"触发日期"`
  25. MonitorTriggerTime time.Time `description:"预警触发时间"`
  26. CreateUserId int `description:"创建人id"`
  27. CreateTime time.Time `description:"创建时间"`
  28. ModifyTime time.Time `description:"修改时间"`
  29. }
  30. func (m *EdbMonitorInfo) Insert() (int64, error) {
  31. o := orm.NewOrmUsingDB("data")
  32. return o.Insert(m)
  33. }
  34. func (m *EdbMonitorInfo) Update(cols []string) (err error) {
  35. if len(cols) == 0 {
  36. return
  37. }
  38. o := orm.NewOrmUsingDB("data")
  39. _, err = o.Update(m, cols...)
  40. return
  41. }
  42. func GetEdbMonitorLevelList() (list []string, err error) {
  43. o := orm.NewOrmUsingDB("data")
  44. sql := `SELECT DISTINCT monitor_level FROM edb_monitor_info`
  45. _, err = o.Raw(sql).QueryRows(&list)
  46. return
  47. }
  48. func GetEdbMonitorEdbInfoList() (items []*EdbMonitorInfo, err error) {
  49. o := orm.NewOrmUsingDB("data")
  50. sql := `SELECT * FROM edb_monitor_info WHERE state <> 0`
  51. _, err = o.Raw(sql).QueryRows(&items)
  52. return
  53. }
  54. func DeleteEdbMonitorInfoById(id int) (err error) {
  55. o := orm.NewOrmUsingDB("data")
  56. sql := `DELETE FROM edb_monitor_info WHERE edb_monitor_id =?`
  57. _, err = o.Raw(sql, id).Exec()
  58. return
  59. }
  60. func DeleteEdbMonitorInfoByIdList(ids []int) (err error) {
  61. if len(ids) == 0 {
  62. return
  63. }
  64. o := orm.NewOrmUsingDB("data")
  65. sql := `DELETE FROM edb_monitor_info WHERE edb_monitor_id IN(` + utils.GetOrmInReplace(len(ids)) + `)`
  66. _, err = o.Raw(sql, ids).Exec()
  67. return
  68. }
  69. func GetEdbMonitorInfoById(id int) (item *EdbMonitorInfo, err error) {
  70. o := orm.NewOrmUsingDB("data")
  71. sql := `SELECT * FROM edb_monitor_info WHERE edb_monitor_id =?`
  72. err = o.Raw(sql, id).QueryRow(&item)
  73. return
  74. }
  75. func GetEdbMonitorInfoByEdbInfoId(edbInfoId int) (items []*EdbMonitorInfo, err error) {
  76. o := orm.NewOrmUsingDB("data")
  77. sql := `SELECT * FROM edb_monitor_info WHERE edb_info_id =?`
  78. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  79. return
  80. }
  81. func GetEdbMonitorInfoCountByClassifyId(classifyId []int) (count int, err error) {
  82. if len(classifyId) == 0 {
  83. return
  84. }
  85. o := orm.NewOrmUsingDB("data")
  86. sql := `SELECT COUNT(*) AS count FROM edb_monitor_info WHERE edb_monitor_classify_id IN(` + utils.GetOrmInReplace(len(classifyId)) + `)`
  87. err = o.Raw(sql, classifyId).QueryRow(&count)
  88. return
  89. }
  90. func GetEdbMonitorInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  91. o := orm.NewOrmUsingDB("data")
  92. sql := `SELECT COUNT(*) AS count FROM edb_monitor_info WHERE 1=1 `
  93. if condition != "" {
  94. sql += condition
  95. }
  96. err = o.Raw(sql, pars).QueryRow(&count)
  97. return
  98. }
  99. func GetEdbMonitorInfoPageByCondition(condition string, pars []interface{}, startSize int, pageSize int) (items []*EdbMonitorInfo, err error) {
  100. o := orm.NewOrmUsingDB("data")
  101. sql := `SELECT * FROM edb_monitor_info WHERE 1=1 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. sql += ` ORDER BY create_time DESC LIMIT?,?`
  106. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  107. return
  108. }
  109. func GetEdbMonitorCreateUserId() (userIds []int, err error) {
  110. o := orm.NewOrmUsingDB("data")
  111. sql := `SELECT DISTINCT create_user_id FROM edb_monitor_info`
  112. _, err = o.Raw(sql).QueryRows(&userIds)
  113. return
  114. }