From fa437b30aaf7e9a9d129f0b0695272b1daea2b28 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Mon, 13 Oct 2025 14:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4swag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs.go | 6 +----- docs/swagger.json | 6 +----- docs/swagger.yaml | 3 --- internal/app/controller/device/device_controller.go | 7 ++++++- internal/app/dto/device_dto.go | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 66f76ef..4b91cff 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3043,11 +3043,7 @@ const docTemplate = `{ "properties": { "action": { "description": "Action 不传表示这是一个传感器, 会触发一次采集", - "type": "string", - "enum": [ - "on", - "off" - ] + "type": "string" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index cab952d..68ed315 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3035,11 +3035,7 @@ "properties": { "action": { "description": "Action 不传表示这是一个传感器, 会触发一次采集", - "type": "string", - "enum": [ - "on", - "off" - ] + "type": "string" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e9fc675..6a7280e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -338,9 +338,6 @@ definitions: properties: action: description: Action 不传表示这是一个传感器, 会触发一次采集 - enum: - - "on" - - "off" type: string type: object dto.MovePigsIntoPenRequest: diff --git a/internal/app/controller/device/device_controller.go b/internal/app/controller/device/device_controller.go index e727c37..df5a8c5 100644 --- a/internal/app/controller/device/device_controller.go +++ b/internal/app/controller/device/device_controller.go @@ -355,8 +355,13 @@ func (c *Controller) ManualControl(ctx *gin.Context) { } } else { action := device.DeviceActionStart - if *req.Action == "off" { + switch *req.Action { + case "off": action = device.DeviceActionStop + case "on": + default: + c.logger.Errorf("%s: 无效的动作: %s, 设备ID: %s", actionType, *req.Action, deviceID) + controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的动作: "+*req.Action, actionType, "无效的动作", req.Action) } err = c.deviceService.Switch(dev, action) if err != nil { diff --git a/internal/app/dto/device_dto.go b/internal/app/dto/device_dto.go index 68a27ba..ed11729 100644 --- a/internal/app/dto/device_dto.go +++ b/internal/app/dto/device_dto.go @@ -23,7 +23,7 @@ type UpdateDeviceRequest struct { // ManualControlDeviceRequest 定义了手动控制设备时需要传入的参数 type ManualControlDeviceRequest struct { // Action 不传表示这是一个传感器, 会触发一次采集 - Action *string `json:"action" binding:"oneof=on off"` + Action *string `json:"action"` } // CreateAreaControllerRequest 定义了创建区域主控时需要传入的参数