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) }