edb_terminal.go 4.2 KB

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