bluetooth.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package item
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "server/global"
  6. "server/model"
  7. "server/model/common/response"
  8. "server/model/item/request"
  9. "strconv"
  10. )
  11. type BluetoothApi struct{}
  12. func (ba *BluetoothApi) QueryAllTempScanDevices(c *gin.Context) {
  13. devices, err := bluetoothService.QueryAllTempScanDevices()
  14. if err != nil {
  15. global.GVA_LOG.Error("获取失败", zap.Error(err))
  16. response.FailWithMessage("获取失败", c)
  17. return
  18. }
  19. response.OkWithData(devices, c)
  20. }
  21. func (ba *BluetoothApi) GetDeviceData(c *gin.Context) {
  22. var info request.GetDeviceOrderData
  23. err := c.ShouldBindJSON(&info)
  24. if err != nil {
  25. global.GVA_LOG.Error("参数错误", zap.Error(err))
  26. response.FailWithMessage("参数错误", c)
  27. return
  28. }
  29. err = bluetoothService.GetDeviceData(info)
  30. if err != nil {
  31. global.GVA_LOG.Error("发送 获取设备参数命令 错误", zap.Any("err", err))
  32. response.FailWithMessage("发送 获取设备参数命令 错误", c)
  33. return
  34. }
  35. response.Ok(c)
  36. }
  37. func (ba *BluetoothApi) DeviceSendCmd(c *gin.Context) {
  38. var info request.DeviceSendCmdData
  39. err := c.ShouldBindJSON(&info)
  40. if err != nil {
  41. global.GVA_LOG.Error("参数错误", zap.Error(err))
  42. response.FailWithMessage("参数错误", c)
  43. return
  44. }
  45. err = bluetoothService.DeviceSendCmd(info)
  46. if err != nil {
  47. global.GVA_LOG.Error("发送 设置参数命令 错误", zap.Any("err", err))
  48. response.FailWithMessage("发送 设置参数命令 错误", c)
  49. return
  50. }
  51. response.Ok(c)
  52. }
  53. func (ba *BluetoothApi) ScanAllDevice(c *gin.Context) {
  54. var info request.GetDeviceOrderData
  55. err := c.ShouldBindJSON(&info)
  56. if err != nil {
  57. global.GVA_LOG.Error("参数错误", zap.Error(err))
  58. response.FailWithMessage("参数错误", c)
  59. return
  60. }
  61. err = bluetoothService.ScanAllDevice(info)
  62. if err != nil {
  63. global.GVA_LOG.Error("发送 扫描灯具命令 错误", zap.Any("err", err))
  64. response.FailWithMessage("发送 扫描灯具命令 错误", c)
  65. return
  66. }
  67. response.Ok(c)
  68. }
  69. func (ba *BluetoothApi) CreateBluetooth(c *gin.Context) {
  70. var info request.CreateBluetoothData
  71. err := c.ShouldBindJSON(&info)
  72. if err != nil {
  73. global.GVA_LOG.Error("参数错误", zap.Error(err))
  74. response.FailWithMessage("参数错误", c)
  75. return
  76. }
  77. err = bluetoothService.CreateBluetooth(info)
  78. if err != nil {
  79. global.GVA_LOG.Error("新增失败", zap.Any("err", err))
  80. response.FailWithMessage("新增失败", c)
  81. return
  82. }
  83. response.OkWithMessage("新增成功", c)
  84. }
  85. func (ba *BluetoothApi) QueryBluetoothsByGatewayID(c *gin.Context) {
  86. gatewayID, err := strconv.Atoi(c.Query("gateway_id"))
  87. if err != nil {
  88. global.GVA_LOG.Error("参数错误", zap.Any("err", err))
  89. response.FailWithMessage("参数错误", c)
  90. return
  91. }
  92. result, err := bluetoothService.QueryBluetoothsByGatewayID(gatewayID)
  93. if err != nil {
  94. global.GVA_LOG.Error("获取失败", zap.Any("err", err))
  95. response.FailWithMessage("获取失败", c)
  96. return
  97. }
  98. response.OkWithData(result, c)
  99. }
  100. func (ba *BluetoothApi) QueryDataDashboardParameter(c *gin.Context) {
  101. var req model.DashboardRequest
  102. err := c.ShouldBindJSON(&req)
  103. if err != nil {
  104. global.GVA_LOG.Error("参数错误", zap.Any("err", err))
  105. response.FailWithMessage("参数错误", c)
  106. return
  107. }
  108. parameter := bluetoothService.QueryDataDashboardParameter(req)
  109. response.OkWithData(parameter, c)
  110. }
  111. func (ba *BluetoothApi) QueryBluetoothList(c *gin.Context) {
  112. var info request.SearchBluetoothList
  113. err := c.ShouldBindJSON(&info)
  114. if err != nil {
  115. global.GVA_LOG.Error("参数错误", zap.Any("err", err))
  116. response.FailWithMessage("参数错误", c)
  117. return
  118. }
  119. list, total, err := bluetoothService.QueryBluetoothList(info)
  120. if err != nil {
  121. global.GVA_LOG.Error("获取失败", zap.Any("err", err))
  122. response.FailWithMessage("获取失败", c)
  123. return
  124. }
  125. response.OkWithDetailed(response.PageResult{
  126. List: list,
  127. Total: total,
  128. Page: info.Page,
  129. PageSize: info.PageSize,
  130. }, "获取成功", c)
  131. }