| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package item
- import (
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "server/global"
- "server/model"
- "server/model/common/response"
- "server/model/item/request"
- "strconv"
- )
- type BluetoothApi struct{}
- func (ba *BluetoothApi) QueryAllTempScanDevices(c *gin.Context) {
- devices, err := bluetoothService.QueryAllTempScanDevices()
- if err != nil {
- global.GVA_LOG.Error("获取失败", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- return
- }
- response.OkWithData(devices, c)
- }
- func (ba *BluetoothApi) GetDeviceData(c *gin.Context) {
- var info request.GetDeviceOrderData
- err := c.ShouldBindJSON(&info)
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Error(err))
- response.FailWithMessage("参数错误", c)
- return
- }
- err = bluetoothService.GetDeviceData(info)
- if err != nil {
- global.GVA_LOG.Error("发送 获取设备参数命令 错误", zap.Any("err", err))
- response.FailWithMessage("发送 获取设备参数命令 错误", c)
- return
- }
- response.Ok(c)
- }
- func (ba *BluetoothApi) DeviceSendCmd(c *gin.Context) {
- var info request.DeviceSendCmdData
- err := c.ShouldBindJSON(&info)
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Error(err))
- response.FailWithMessage("参数错误", c)
- return
- }
- err = bluetoothService.DeviceSendCmd(info)
- if err != nil {
- global.GVA_LOG.Error("发送 设置参数命令 错误", zap.Any("err", err))
- response.FailWithMessage("发送 设置参数命令 错误", c)
- return
- }
- response.Ok(c)
- }
- func (ba *BluetoothApi) ScanAllDevice(c *gin.Context) {
- var info request.GetDeviceOrderData
- err := c.ShouldBindJSON(&info)
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Error(err))
- response.FailWithMessage("参数错误", c)
- return
- }
- err = bluetoothService.ScanAllDevice(info)
- if err != nil {
- global.GVA_LOG.Error("发送 扫描灯具命令 错误", zap.Any("err", err))
- response.FailWithMessage("发送 扫描灯具命令 错误", c)
- return
- }
- response.Ok(c)
- }
- func (ba *BluetoothApi) CreateBluetooth(c *gin.Context) {
- var info request.CreateBluetoothData
- err := c.ShouldBindJSON(&info)
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Error(err))
- response.FailWithMessage("参数错误", c)
- return
- }
- err = bluetoothService.CreateBluetooth(info)
- if err != nil {
- global.GVA_LOG.Error("新增失败", zap.Any("err", err))
- response.FailWithMessage("新增失败", c)
- return
- }
- response.OkWithMessage("新增成功", c)
- }
- func (ba *BluetoothApi) QueryBluetoothsByGatewayID(c *gin.Context) {
- gatewayID, err := strconv.Atoi(c.Query("gateway_id"))
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Any("err", err))
- response.FailWithMessage("参数错误", c)
- return
- }
- result, err := bluetoothService.QueryBluetoothsByGatewayID(gatewayID)
- if err != nil {
- global.GVA_LOG.Error("获取失败", zap.Any("err", err))
- response.FailWithMessage("获取失败", c)
- return
- }
- response.OkWithData(result, c)
- }
- func (ba *BluetoothApi) QueryDataDashboardParameter(c *gin.Context) {
- var req model.DashboardRequest
- err := c.ShouldBindJSON(&req)
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Any("err", err))
- response.FailWithMessage("参数错误", c)
- return
- }
- parameter := bluetoothService.QueryDataDashboardParameter(req)
- response.OkWithData(parameter, c)
- }
- func (ba *BluetoothApi) QueryBluetoothList(c *gin.Context) {
- var info request.SearchBluetoothList
- err := c.ShouldBindJSON(&info)
- if err != nil {
- global.GVA_LOG.Error("参数错误", zap.Any("err", err))
- response.FailWithMessage("参数错误", c)
- return
- }
- list, total, err := bluetoothService.QueryBluetoothList(info)
- if err != nil {
- global.GVA_LOG.Error("获取失败", zap.Any("err", err))
- response.FailWithMessage("获取失败", c)
- return
- }
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: info.Page,
- PageSize: info.PageSize,
- }, "获取成功", c)
- }
|