edb_terminal.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package models
  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. Num int `description:"终端最大指标数"`
  15. Status int `description:"状态,1启用,2禁用"`
  16. Value string `description:"终端相关的凭证"`
  17. ModifyTime time.Time `description:"修改时间"`
  18. CreateTime time.Time `description:"创建时间"`
  19. }
  20. // GetEdbTerminalListBySource 根据指标来源类型获取所有的终端列表
  21. func GetEdbTerminalListBySource(source int) (items []*EdbTerminal, err error) {
  22. o := orm.NewOrm()
  23. sql := ` SELECT * FROM edb_terminal WHERE source = ? and status=1 ORDER BY terminal_id ASC `
  24. _, err = o.Raw(sql, source).QueryRows(&items)
  25. return
  26. }
  27. // GetEdbTerminalFirstBySource 根据指标来源类型获取配置的首个终端信息
  28. func GetEdbTerminalFirstBySource(source int) (item *EdbTerminal, err error) {
  29. o := orm.NewOrm()
  30. sql := ` SELECT * FROM edb_terminal WHERE source = ? and status=1 ORDER BY terminal_id ASC Limit 1 `
  31. err = o.Raw(sql, source).QueryRow(&item)
  32. return
  33. }
  34. type TerminalCodeCountGroup struct {
  35. TerminalCode string
  36. Total int
  37. }
  38. // GetEdbTerminalByCode 根据终端编码获取终端信息
  39. func GetEdbTerminalByCode(terminalCode string) (item *EdbTerminal, err error) {
  40. o := orm.NewOrm()
  41. sql := ` SELECT * FROM edb_terminal WHERE terminal_code = ? `
  42. err = o.Raw(sql, terminalCode).QueryRow(&item)
  43. return
  44. }
  45. // GetEdbCountGroupByTerminal 获取终端code分组总数
  46. func GetEdbCountGroupByTerminal(source int) (list []TerminalCodeCountGroup, err error) {
  47. o := orm.NewOrm()
  48. sql := `select terminal_code,count(1) total from edb_info where source = ? AND no_update=0 AND terminal_code != "" group by terminal_code; `
  49. _, err = o.Raw(sql, source).QueryRows(&list)
  50. return
  51. }
  52. type BaseIndexTerminalCode struct {
  53. TerminalCode string `description:"终端编码,用于配置在机器上"`
  54. IndexName string
  55. }
  56. // GetBaseIndexTerminalCode 获取数据源的终端code
  57. func GetBaseIndexTerminalCode(edbCode, tableName string) (item BaseIndexTerminalCode, err error) {
  58. o := orm.NewOrm()
  59. sql := fmt.Sprintf(`select terminal_code, index_name from %s where index_code = ? `, tableName)
  60. err = o.Raw(sql, edbCode).QueryRow(&item)
  61. return
  62. }