edb_terminal.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // EdbTerminal 指标终端
  8. type EdbTerminal struct {
  9. TerminalId int `orm:"column(terminal_id);pk"`
  10. Source int `orm:"column(source)" description:"指标来源类型"`
  11. Name string `description:"终端名称"`
  12. TerminalCode string `description:"终端编码,用于配置在机器上"`
  13. ServerUrl string `description:"终端地址"`
  14. DirPath string `description:"终端存放的文件夹路径"`
  15. Num int `description:"终端最大指标数"`
  16. Status int `description:"状态,1启用,2禁用"`
  17. Value string `description:"终端相关的token"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. CreateTime time.Time `description:"创建时间"`
  20. }
  21. type EdbTerminalItem struct {
  22. TerminalId int `orm:"column(terminal_id);pk"`
  23. Source int `description:"指标来源类型"`
  24. Name string `description:"终端别名"`
  25. TerminalCode string `description:"终端编码,用于配置在机器上"`
  26. ServerUrl string `description:"终端地址"`
  27. DirPath string `description:"终端存放的文件夹路径"`
  28. Num int `description:"终端最大指标数"`
  29. Status int `description:"状态,1启用,2禁用"`
  30. Value string `description:"终端相关的token"`
  31. ModifyTime string `description:"修改时间"`
  32. CreateTime string `description:"创建时间"`
  33. }
  34. type EdbTerminalCode struct {
  35. TerminalCode string `description:"终端编码,用于配置在机器上"`
  36. Source int `description:"指标来源类型"`
  37. Name string `description:"终端别名"`
  38. }
  39. // GetEdbTerminalListBySource 根据指标来源类型获取所有的终端列表
  40. func GetEdbTerminalListBySource(source int) (items []*EdbTerminal, err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. sql := ` SELECT * FROM edb_terminal WHERE source = ? and status=1 ORDER BY terminal_id ASC `
  43. _, err = o.Raw(sql, source).QueryRows(&items)
  44. return
  45. }
  46. type BaseIndexTerminalCode struct {
  47. TerminalCode string `description:"终端编码,用于配置在机器上"`
  48. IndexName string
  49. }
  50. type EdbTerminalListResp struct {
  51. List []*EdbTerminalItem `description:"列表数据"`
  52. }
  53. type EdbTerminalCodeResp struct {
  54. List []*EdbTerminalCode `description:"终端编码列表"`
  55. }
  56. type AddEdbTerminalListReq struct {
  57. TerminalId int `description:"终端id"`
  58. Source int `description:"指标来源类型"`
  59. Name string `description:"终端别名"`
  60. //TerminalCode string `description:"终端编码,用于配置在机器上"`
  61. ServerUrl string `description:"终端地址"`
  62. DirPath string `description:"终端存放的文件夹路径"`
  63. Num int `description:"终端最大指标数"`
  64. //Status int `description:"状态,1启用,2禁用"`
  65. Value string `description:"终端相关的token"`
  66. }
  67. type SetEdbTerminalStatusReq struct {
  68. TerminalId int `description:"终端id"`
  69. Status int `description:"状态,1启用,2禁用"`
  70. }
  71. // GetBaseIndexTerminalCode 获取数据源的终端code
  72. func GetBaseIndexTerminalCode(edbCode, tableName string) (item BaseIndexTerminalCode, err error) {
  73. o := orm.NewOrmUsingDB("data")
  74. sql := fmt.Sprintf(`select terminal_code, index_name from %s where index_code = ? `, tableName)
  75. err = o.Raw(sql, edbCode).QueryRow(&item)
  76. return
  77. }
  78. // GetEdbTerminalById 主键获取终端
  79. func GetEdbTerminalById(id int) (item *EdbTerminal, err error) {
  80. o := orm.NewOrmUsingDB("data")
  81. sql := `SELECT * FROM edb_terminal WHERE terminal_id = ? LIMIT 1`
  82. err = o.Raw(sql, id).QueryRow(&item)
  83. return
  84. }
  85. func GetEdbTerminalByTerminalCode(terminalCode string) (item *EdbTerminal, err error) {
  86. o := orm.NewOrmUsingDB("data")
  87. sql := `SELECT * FROM edb_terminal WHERE terminal_code = ? LIMIT 1`
  88. err = o.Raw(sql, terminalCode).QueryRow(&item)
  89. return
  90. }
  91. func GetEdbTerminalList() (item []*EdbTerminalItem, err error) {
  92. o := orm.NewOrmUsingDB("data")
  93. sql := ` SELECT * FROM edb_terminal ORDER BY terminal_id ASC`
  94. _, err = o.Raw(sql).QueryRows(&item)
  95. return
  96. }
  97. func GetEdbTerminalBySource(source int) (item []*EdbTerminalItem, err error) {
  98. o := orm.NewOrmUsingDB("data")
  99. sql := ` SELECT * FROM edb_terminal where source=? ORDER BY terminal_id ASC`
  100. _, err = o.Raw(sql, source).QueryRows(&item)
  101. return
  102. }
  103. func (item *EdbTerminal) Add() (err error) {
  104. o := orm.NewOrmUsingDB("data")
  105. _, err = o.Insert(item)
  106. return
  107. }
  108. func (item *EdbTerminal) Update(cols []string) (err error) {
  109. o := orm.NewOrmUsingDB("data")
  110. _, err = o.Update(item, cols...)
  111. return
  112. }
  113. // GetEdbTerminalByCode 根据终端编码获取终端信息
  114. func GetEdbTerminalByCode(terminalCode string) (item *EdbTerminal, err error) {
  115. o := orm.NewOrmUsingDB("data")
  116. sql := ` SELECT * FROM edb_terminal WHERE terminal_code = ? `
  117. err = o.Raw(sql, terminalCode).QueryRow(&item)
  118. return
  119. }
  120. type TerminalCodeCountGroup struct {
  121. TerminalCode string
  122. Total int
  123. }
  124. // GetEdbCountGroupByTerminal 获取终端code分组总数
  125. func GetEdbCountGroupByTerminal(source int) (list []TerminalCodeCountGroup, err error) {
  126. o := orm.NewOrmUsingDB("data")
  127. sql := `select terminal_code,count(1) total from edb_info where source = ? AND no_update=0 AND terminal_code != "" group by terminal_code; `
  128. _, err = o.Raw(sql, source).QueryRows(&list)
  129. return
  130. }