edb_terminal.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // GetEdbTerminalListBySource 根据指标来源类型获取所有的终端列表
  35. func GetEdbTerminalListBySource(source int) (items []*EdbTerminal, err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. sql := ` SELECT * FROM edb_terminal WHERE source = ? and status=1 ORDER BY terminal_id ASC `
  38. _, err = o.Raw(sql, source).QueryRows(&items)
  39. return
  40. }
  41. type BaseIndexTerminalCode struct {
  42. TerminalCode string `description:"终端编码,用于配置在机器上"`
  43. }
  44. type EdbTerminalLisResp struct {
  45. List []*EdbTerminalItem `description:"列表数据"`
  46. }
  47. type AddEdbTerminalListReq struct {
  48. TerminalId int `description:"终端id"`
  49. Source int `description:"指标来源类型"`
  50. Name string `description:"终端别名"`
  51. //TerminalCode string `description:"终端编码,用于配置在机器上"`
  52. ServerUrl string `description:"终端地址"`
  53. DirPath string `description:"终端存放的文件夹路径"`
  54. Num int `description:"终端最大指标数"`
  55. Status int `description:"状态,1启用,2禁用"`
  56. Value string `description:"终端相关的token"`
  57. }
  58. type SetEdbTerminalStatusReq struct {
  59. TerminalId int `description:"终端id"`
  60. Status int `description:"状态,1启用,2禁用"`
  61. }
  62. // GetBaseIndexTerminalCode 获取数据源的终端code
  63. func GetBaseIndexTerminalCode(edbCode, tableName string) (item BaseIndexTerminalCode, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. sql := fmt.Sprintf(`select terminal_code from %s where index_code = ? `, tableName)
  66. err = o.Raw(sql, edbCode).QueryRow(&item)
  67. return
  68. }
  69. // GetEdbTerminalById 主键获取终端
  70. func GetEdbTerminalById(id int) (item *EdbTerminal, err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. sql := `SELECT * FROM edb_terminal WHERE terminal_id = ? LIMIT 1`
  73. err = o.Raw(sql, id).QueryRow(&item)
  74. return
  75. }
  76. func GetEdbTerminalList() (item []*EdbTerminalItem, err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. sql := ` SELECT * FROM edb_terminal ORDER BY terminal_id ASC`
  79. _, err = o.Raw(sql).QueryRows(&item)
  80. return
  81. }
  82. func (item *EdbTerminal) Add() (err error) {
  83. o := orm.NewOrmUsingDB("data")
  84. _, err = o.Insert(item)
  85. return
  86. }
  87. func (item *EdbTerminal) Update(cols []string) (err error) {
  88. o := orm.NewOrmUsingDB("data")
  89. _, err = o.Update(item, cols...)
  90. return
  91. }