edb_terminal.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "time"
  6. )
  7. // EdbTerminal 指标终端
  8. type EdbTerminal struct {
  9. TerminalId int `orm:"column(terminal_id);pk" gorm:"primaryKey" `
  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" gorm:"primaryKey" `
  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 := global.DmSQL["data"]
  42. sql := ` SELECT * FROM edb_terminal WHERE source = ? and status=1 ORDER BY terminal_id ASC `
  43. err = o.Raw(sql, source).Find(&items).Error
  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 := global.DmSQL["data"]
  74. sql := fmt.Sprintf(`select terminal_code, index_name from %s where index_code = ? `, tableName)
  75. err = o.Raw(sql, edbCode).Scan(&item).Error
  76. return
  77. }
  78. // GetEdbTerminalById 主键获取终端
  79. func GetEdbTerminalById(id int) (item *EdbTerminal, err error) {
  80. sql := `SELECT * FROM edb_terminal WHERE terminal_id = ? LIMIT 1`
  81. err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
  82. return
  83. }
  84. func GetEdbTerminalByTerminalCode(terminalCode string) (item *EdbTerminal, err error) {
  85. sql := `SELECT * FROM edb_terminal WHERE terminal_code = ? LIMIT 1`
  86. err = global.DmSQL["data"].Raw(sql, terminalCode).First(&item).Error
  87. return
  88. }
  89. func GetEdbTerminalList() (item []*EdbTerminalItem, err error) {
  90. o := global.DmSQL["data"]
  91. sql := ` SELECT * FROM edb_terminal ORDER BY terminal_id ASC`
  92. err = o.Raw(sql).Scan(&item).Error
  93. return
  94. }
  95. func GetEdbTerminalBySource(source int) (item []*EdbTerminalItem, err error) {
  96. o := global.DmSQL["data"]
  97. sql := ` SELECT * FROM edb_terminal where source=? ORDER BY terminal_id ASC`
  98. err = o.Raw(sql, source).Scan(&item).Error
  99. return
  100. }
  101. func (item *EdbTerminal) Add() (err error) {
  102. err = global.DmSQL["data"].Create(item).Error
  103. return
  104. }
  105. func (item *EdbTerminal) Update(cols []string) (err error) {
  106. o := global.DmSQL["data"]
  107. err = o.Select(cols).Updates(item).Error
  108. return
  109. }
  110. // GetEdbTerminalByCode 根据终端编码获取终端信息
  111. func GetEdbTerminalByCode(terminalCode string) (item *EdbTerminal, err error) {
  112. sql := ` SELECT * FROM edb_terminal WHERE terminal_code = ? `
  113. err = global.DmSQL["data"].Raw(sql, terminalCode).First(&item).Error
  114. return
  115. }
  116. type TerminalCodeCountGroup struct {
  117. TerminalCode string
  118. Total int
  119. }
  120. // GetEdbCountGroupByTerminal 获取终端code分组总数
  121. func GetEdbCountGroupByTerminal(source int) (list []TerminalCodeCountGroup, err error) {
  122. o := global.DmSQL["data"]
  123. sql := `select terminal_code,count(1) total from edb_info where source = ? AND no_update=0 AND terminal_code != "" group by terminal_code; `
  124. err = o.Raw(sql, source).Scan(&list).Error
  125. return
  126. }