diff --git a/Makefile b/Makefile index 35ef016..b53de4c 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ test: .PHONY: swag swag: if exist docs rmdir /s /q docs - swag init --parseInternal --parseDependency + swag init -g internal/app/api/api.go --parseInternal --parseDependency # 生成protobuf文件 diff --git a/docs/docs.go b/docs/docs.go index 32ca199..66f76ef 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -9,7 +9,15 @@ const docTemplate = `{ "info": { "description": "{{escape .Description}}", "title": "{{.Title}}", - "contact": {}, + "contact": { + "name": "Divano", + "url": "http://www.example.com", + "email": "divano@example.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, "version": "{{.Version}}" }, "host": "{{.Host}}", @@ -17,6 +25,11 @@ const docTemplate = `{ "paths": { "/api/v1/area-controllers": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取系统中所有区域主控的列表", "produces": [ "application/json" @@ -50,6 +63,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据提供的信息创建一个新区域主控", "consumes": [ "application/json" @@ -96,6 +114,11 @@ const docTemplate = `{ }, "/api/v1/area-controllers/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个区域主控的详细信息", "produces": [ "application/json" @@ -135,6 +158,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID更新一个已存在的区域主控信息", "consumes": [ "application/json" @@ -186,6 +214,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个区域主控(软删除)", "produces": [ "application/json" @@ -215,6 +248,11 @@ const docTemplate = `{ }, "/api/v1/device-templates": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取系统中所有设备模板的列表", "produces": [ "application/json" @@ -248,6 +286,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据提供的信息创建一个新设备模板", "consumes": [ "application/json" @@ -294,6 +337,11 @@ const docTemplate = `{ }, "/api/v1/device-templates/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备模板ID获取单个设备模板的详细信息", "produces": [ "application/json" @@ -333,6 +381,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备模板ID更新一个已存在的设备模板信息", "consumes": [ "application/json" @@ -384,6 +437,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备模板ID删除一个设备模板(软删除)", "produces": [ "application/json" @@ -413,6 +471,11 @@ const docTemplate = `{ }, "/api/v1/devices": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取系统中所有设备的列表", "produces": [ "application/json" @@ -446,6 +509,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据提供的信息创建一个新设备", "consumes": [ "application/json" @@ -492,6 +560,11 @@ const docTemplate = `{ }, "/api/v1/devices/manual-control/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID和指定的动作(开启或关闭)来手动控制设备", "consumes": [ "application/json" @@ -533,6 +606,11 @@ const docTemplate = `{ }, "/api/v1/devices/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID获取单个设备的详细信息", "produces": [ "application/json" @@ -572,6 +650,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID更新一个已存在的设备信息", "consumes": [ "application/json" @@ -623,6 +706,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID删除一个设备(软删除)", "produces": [ "application/json" @@ -652,6 +740,11 @@ const docTemplate = `{ }, "/api/v1/pens": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有猪栏的列表", "produces": [ "application/json" @@ -685,6 +778,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的猪栏", "consumes": [ "application/json" @@ -731,6 +829,11 @@ const docTemplate = `{ }, "/api/v1/pens/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个猪栏信息", "produces": [ "application/json" @@ -770,6 +873,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新一个已存在的猪栏信息", "consumes": [ "application/json" @@ -821,6 +929,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个猪栏", "produces": [ "application/json" @@ -850,6 +963,11 @@ const docTemplate = `{ }, "/api/v1/pens/{id}/status": { "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新指定猪栏的当前状态", "consumes": [ "application/json" @@ -903,6 +1021,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有猪批次的列表,支持按活跃状态筛选", "produces": [ "application/json" @@ -944,6 +1067,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的猪批次", "consumes": [ "application/json" @@ -990,6 +1118,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/assign-pens/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将一个或多个空闲猪栏分配给指定的猪批次", "consumes": [ "application/json" @@ -1031,6 +1164,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/buy-pigs/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中的猪只购买事件", "consumes": [ "application/json" @@ -1072,6 +1210,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/move-pigs-into-pen/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将指定数量的猪只从批次的“虚拟库存”移入一个已分配的猪栏", "consumes": [ "application/json" @@ -1113,6 +1256,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/reclassify-pen/{fromBatchID}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将一个猪栏(连同其中的猪只)从一个批次整体划拨到另一个批次", "consumes": [ "application/json" @@ -1154,6 +1302,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/record-cull/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中正常猪只淘汰的数量和发生时间", "consumes": [ "application/json" @@ -1195,6 +1348,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/record-death/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中正常猪只死亡的数量和发生时间", "consumes": [ "application/json" @@ -1236,6 +1394,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/record-sick-pig-cull/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中病猪淘汰的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1277,6 +1440,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/record-sick-pig-death/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中病猪死亡的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1318,6 +1486,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/record-sick-pig-recovery/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中病猪康复的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1359,6 +1532,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/record-sick-pigs/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中新增病猪的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1400,6 +1578,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/remove-pen/{penID}/{batchID}": { "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将一个空闲猪栏从指定的猪批次中移除", "produces": [ "application/json" @@ -1436,6 +1619,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/sell-pigs/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中的猪只出售事件", "consumes": [ "application/json" @@ -1477,6 +1665,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/transfer-across-batches/{sourceBatchID}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将指定数量的猪只从一个猪群的猪栏调动到另一个猪群的猪栏", "consumes": [ "application/json" @@ -1518,6 +1711,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/transfer-within-batch/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将指定数量的猪只在同一个猪群的不同猪栏间调动", "consumes": [ "application/json" @@ -1559,6 +1757,11 @@ const docTemplate = `{ }, "/api/v1/pig-batches/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个猪批次信息", "produces": [ "application/json" @@ -1598,6 +1801,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新一个已存在的猪批次信息", "consumes": [ "application/json" @@ -1649,6 +1857,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个猪批次", "produces": [ "application/json" @@ -1678,6 +1891,11 @@ const docTemplate = `{ }, "/api/v1/pig-houses": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有猪舍的列表", "produces": [ "application/json" @@ -1711,6 +1929,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的猪舍", "consumes": [ "application/json" @@ -1757,6 +1980,11 @@ const docTemplate = `{ }, "/api/v1/pig-houses/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个猪舍信息", "produces": [ "application/json" @@ -1796,6 +2024,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新一个已存在的猪舍信息", "consumes": [ "application/json" @@ -1847,6 +2080,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个猪舍", "produces": [ "application/json" @@ -1876,6 +2114,11 @@ const docTemplate = `{ }, "/api/v1/plans": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有计划的列表", "produces": [ "application/json" @@ -1909,6 +2152,11 @@ const docTemplate = `{ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的计划,包括其基本信息和所有关联的子计划/任务。", "consumes": [ "application/json" @@ -1955,6 +2203,11 @@ const docTemplate = `{ }, "/api/v1/plans/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID获取单个计划的详细信息。", "produces": [ "application/json" @@ -1994,6 +2247,11 @@ const docTemplate = `{ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID更新计划的详细信息。", "consumes": [ "application/json" @@ -2045,6 +2303,11 @@ const docTemplate = `{ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID删除计划。(软删除)", "produces": [ "application/json" @@ -2074,6 +2337,11 @@ const docTemplate = `{ }, "/api/v1/plans/{id}/start": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID启动一个计划的执行。", "produces": [ "application/json" @@ -2103,6 +2371,11 @@ const docTemplate = `{ }, "/api/v1/plans/{id}/stop": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID停止一个正在执行的计划。", "produces": [ "application/json" @@ -2224,6 +2497,11 @@ const docTemplate = `{ }, "/api/v1/users/{id}/history": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据用户ID,分页获取该用户的操作审计日志。", "produces": [ "application/json" @@ -3859,17 +4137,24 @@ const docTemplate = `{ } } } + }, + "securityDefinitions": { + "BearerAuth": { + "type": "apiKey", + "name": "Authorization", + "in": "header" + } } }` // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "", + Version: "1.0", Host: "", BasePath: "", Schemes: []string{}, - Title: "", - Description: "", + Title: "猪场管理系统 API", + Description: "这是一个用于管理猪场设备的后端服务。", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/docs/swagger.json b/docs/swagger.json index 2c0a284..cab952d 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,11 +1,27 @@ { "swagger": "2.0", "info": { - "contact": {} + "description": "这是一个用于管理猪场设备的后端服务。", + "title": "猪场管理系统 API", + "contact": { + "name": "Divano", + "url": "http://www.example.com", + "email": "divano@example.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0" }, "paths": { "/api/v1/area-controllers": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取系统中所有区域主控的列表", "produces": [ "application/json" @@ -39,6 +55,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据提供的信息创建一个新区域主控", "consumes": [ "application/json" @@ -85,6 +106,11 @@ }, "/api/v1/area-controllers/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个区域主控的详细信息", "produces": [ "application/json" @@ -124,6 +150,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID更新一个已存在的区域主控信息", "consumes": [ "application/json" @@ -175,6 +206,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个区域主控(软删除)", "produces": [ "application/json" @@ -204,6 +240,11 @@ }, "/api/v1/device-templates": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取系统中所有设备模板的列表", "produces": [ "application/json" @@ -237,6 +278,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据提供的信息创建一个新设备模板", "consumes": [ "application/json" @@ -283,6 +329,11 @@ }, "/api/v1/device-templates/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备模板ID获取单个设备模板的详细信息", "produces": [ "application/json" @@ -322,6 +373,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备模板ID更新一个已存在的设备模板信息", "consumes": [ "application/json" @@ -373,6 +429,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备模板ID删除一个设备模板(软删除)", "produces": [ "application/json" @@ -402,6 +463,11 @@ }, "/api/v1/devices": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取系统中所有设备的列表", "produces": [ "application/json" @@ -435,6 +501,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据提供的信息创建一个新设备", "consumes": [ "application/json" @@ -481,6 +552,11 @@ }, "/api/v1/devices/manual-control/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID和指定的动作(开启或关闭)来手动控制设备", "consumes": [ "application/json" @@ -522,6 +598,11 @@ }, "/api/v1/devices/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID获取单个设备的详细信息", "produces": [ "application/json" @@ -561,6 +642,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID更新一个已存在的设备信息", "consumes": [ "application/json" @@ -612,6 +698,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据设备ID删除一个设备(软删除)", "produces": [ "application/json" @@ -641,6 +732,11 @@ }, "/api/v1/pens": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有猪栏的列表", "produces": [ "application/json" @@ -674,6 +770,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的猪栏", "consumes": [ "application/json" @@ -720,6 +821,11 @@ }, "/api/v1/pens/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个猪栏信息", "produces": [ "application/json" @@ -759,6 +865,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新一个已存在的猪栏信息", "consumes": [ "application/json" @@ -810,6 +921,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个猪栏", "produces": [ "application/json" @@ -839,6 +955,11 @@ }, "/api/v1/pens/{id}/status": { "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新指定猪栏的当前状态", "consumes": [ "application/json" @@ -892,6 +1013,11 @@ }, "/api/v1/pig-batches": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有猪批次的列表,支持按活跃状态筛选", "produces": [ "application/json" @@ -933,6 +1059,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的猪批次", "consumes": [ "application/json" @@ -979,6 +1110,11 @@ }, "/api/v1/pig-batches/assign-pens/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将一个或多个空闲猪栏分配给指定的猪批次", "consumes": [ "application/json" @@ -1020,6 +1156,11 @@ }, "/api/v1/pig-batches/buy-pigs/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中的猪只购买事件", "consumes": [ "application/json" @@ -1061,6 +1202,11 @@ }, "/api/v1/pig-batches/move-pigs-into-pen/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将指定数量的猪只从批次的“虚拟库存”移入一个已分配的猪栏", "consumes": [ "application/json" @@ -1102,6 +1248,11 @@ }, "/api/v1/pig-batches/reclassify-pen/{fromBatchID}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将一个猪栏(连同其中的猪只)从一个批次整体划拨到另一个批次", "consumes": [ "application/json" @@ -1143,6 +1294,11 @@ }, "/api/v1/pig-batches/record-cull/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中正常猪只淘汰的数量和发生时间", "consumes": [ "application/json" @@ -1184,6 +1340,11 @@ }, "/api/v1/pig-batches/record-death/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中正常猪只死亡的数量和发生时间", "consumes": [ "application/json" @@ -1225,6 +1386,11 @@ }, "/api/v1/pig-batches/record-sick-pig-cull/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中病猪淘汰的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1266,6 +1432,11 @@ }, "/api/v1/pig-batches/record-sick-pig-death/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中病猪死亡的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1307,6 +1478,11 @@ }, "/api/v1/pig-batches/record-sick-pig-recovery/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中病猪康复的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1348,6 +1524,11 @@ }, "/api/v1/pig-batches/record-sick-pigs/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中新增病猪的数量、治疗地点和发生时间", "consumes": [ "application/json" @@ -1389,6 +1570,11 @@ }, "/api/v1/pig-batches/remove-pen/{penID}/{batchID}": { "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将一个空闲猪栏从指定的猪批次中移除", "produces": [ "application/json" @@ -1425,6 +1611,11 @@ }, "/api/v1/pig-batches/sell-pigs/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "记录猪批次中的猪只出售事件", "consumes": [ "application/json" @@ -1466,6 +1657,11 @@ }, "/api/v1/pig-batches/transfer-across-batches/{sourceBatchID}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将指定数量的猪只从一个猪群的猪栏调动到另一个猪群的猪栏", "consumes": [ "application/json" @@ -1507,6 +1703,11 @@ }, "/api/v1/pig-batches/transfer-within-batch/{id}": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "将指定数量的猪只在同一个猪群的不同猪栏间调动", "consumes": [ "application/json" @@ -1548,6 +1749,11 @@ }, "/api/v1/pig-batches/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个猪批次信息", "produces": [ "application/json" @@ -1587,6 +1793,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新一个已存在的猪批次信息", "consumes": [ "application/json" @@ -1638,6 +1849,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个猪批次", "produces": [ "application/json" @@ -1667,6 +1883,11 @@ }, "/api/v1/pig-houses": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有猪舍的列表", "produces": [ "application/json" @@ -1700,6 +1921,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的猪舍", "consumes": [ "application/json" @@ -1746,6 +1972,11 @@ }, "/api/v1/pig-houses/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID获取单个猪舍信息", "produces": [ "application/json" @@ -1785,6 +2016,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "更新一个已存在的猪舍信息", "consumes": [ "application/json" @@ -1836,6 +2072,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据ID删除一个猪舍", "produces": [ "application/json" @@ -1865,6 +2106,11 @@ }, "/api/v1/plans": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "获取所有计划的列表", "produces": [ "application/json" @@ -1898,6 +2144,11 @@ } }, "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "创建一个新的计划,包括其基本信息和所有关联的子计划/任务。", "consumes": [ "application/json" @@ -1944,6 +2195,11 @@ }, "/api/v1/plans/{id}": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID获取单个计划的详细信息。", "produces": [ "application/json" @@ -1983,6 +2239,11 @@ } }, "put": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID更新计划的详细信息。", "consumes": [ "application/json" @@ -2034,6 +2295,11 @@ } }, "delete": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID删除计划。(软删除)", "produces": [ "application/json" @@ -2063,6 +2329,11 @@ }, "/api/v1/plans/{id}/start": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID启动一个计划的执行。", "produces": [ "application/json" @@ -2092,6 +2363,11 @@ }, "/api/v1/plans/{id}/stop": { "post": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据计划ID停止一个正在执行的计划。", "produces": [ "application/json" @@ -2213,6 +2489,11 @@ }, "/api/v1/users/{id}/history": { "get": { + "security": [ + { + "BearerAuth": [] + } + ], "description": "根据用户ID,分页获取该用户的操作审计日志。", "produces": [ "application/json" @@ -3848,5 +4129,12 @@ } } } + }, + "securityDefinitions": { + "BearerAuth": { + "type": "apiKey", + "name": "Authorization", + "in": "header" + } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 71b1241..e9fc675 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1112,7 +1112,16 @@ definitions: $ref: '#/definitions/models.SensorType' type: object info: - contact: {} + contact: + email: divano@example.com + name: Divano + url: http://www.example.com + description: 这是一个用于管理猪场设备的后端服务。 + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + title: 猪场管理系统 API + version: "1.0" paths: /api/v1/area-controllers: get: @@ -1131,6 +1140,8 @@ paths: $ref: '#/definitions/dto.AreaControllerResponse' type: array type: object + security: + - BearerAuth: [] summary: 获取所有区域主控列表 tags: - 区域主控管理 @@ -1157,6 +1168,8 @@ paths: data: $ref: '#/definitions/dto.AreaControllerResponse' type: object + security: + - BearerAuth: [] summary: 创建新区域主控 tags: - 区域主控管理 @@ -1176,6 +1189,8 @@ paths: description: OK schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除区域主控 tags: - 区域主控管理 @@ -1199,6 +1214,8 @@ paths: data: $ref: '#/definitions/dto.AreaControllerResponse' type: object + security: + - BearerAuth: [] summary: 获取区域主控信息 tags: - 区域主控管理 @@ -1230,6 +1247,8 @@ paths: data: $ref: '#/definitions/dto.AreaControllerResponse' type: object + security: + - BearerAuth: [] summary: 更新区域主控信息 tags: - 区域主控管理 @@ -1250,6 +1269,8 @@ paths: $ref: '#/definitions/dto.DeviceTemplateResponse' type: array type: object + security: + - BearerAuth: [] summary: 获取设备模板列表 tags: - 设备模板管理 @@ -1276,6 +1297,8 @@ paths: data: $ref: '#/definitions/dto.DeviceTemplateResponse' type: object + security: + - BearerAuth: [] summary: 创建新设备模板 tags: - 设备模板管理 @@ -1295,6 +1318,8 @@ paths: description: OK schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除设备模板 tags: - 设备模板管理 @@ -1318,6 +1343,8 @@ paths: data: $ref: '#/definitions/dto.DeviceTemplateResponse' type: object + security: + - BearerAuth: [] summary: 获取设备模板信息 tags: - 设备模板管理 @@ -1349,6 +1376,8 @@ paths: data: $ref: '#/definitions/dto.DeviceTemplateResponse' type: object + security: + - BearerAuth: [] summary: 更新设备模板信息 tags: - 设备模板管理 @@ -1369,6 +1398,8 @@ paths: $ref: '#/definitions/dto.DeviceResponse' type: array type: object + security: + - BearerAuth: [] summary: 获取设备列表 tags: - 设备管理 @@ -1395,6 +1426,8 @@ paths: data: $ref: '#/definitions/dto.DeviceResponse' type: object + security: + - BearerAuth: [] summary: 创建新设备 tags: - 设备管理 @@ -1414,6 +1447,8 @@ paths: description: OK schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除设备 tags: - 设备管理 @@ -1437,6 +1472,8 @@ paths: data: $ref: '#/definitions/dto.DeviceResponse' type: object + security: + - BearerAuth: [] summary: 获取设备信息 tags: - 设备管理 @@ -1468,6 +1505,8 @@ paths: data: $ref: '#/definitions/dto.DeviceResponse' type: object + security: + - BearerAuth: [] summary: 更新设备信息 tags: - 设备管理 @@ -1495,6 +1534,8 @@ paths: description: OK schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 手动控制设备 tags: - 设备管理 @@ -1515,6 +1556,8 @@ paths: $ref: '#/definitions/dto.PenResponse' type: array type: object + security: + - BearerAuth: [] summary: 获取猪栏列表 tags: - 猪场管理 @@ -1541,6 +1584,8 @@ paths: data: $ref: '#/definitions/dto.PenResponse' type: object + security: + - BearerAuth: [] summary: 创建猪栏 tags: - 猪场管理 @@ -1560,6 +1605,8 @@ paths: description: 删除成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除猪栏 tags: - 猪场管理 @@ -1583,6 +1630,8 @@ paths: data: $ref: '#/definitions/dto.PenResponse' type: object + security: + - BearerAuth: [] summary: 获取单个猪栏 tags: - 猪场管理 @@ -1614,6 +1663,8 @@ paths: data: $ref: '#/definitions/dto.PenResponse' type: object + security: + - BearerAuth: [] summary: 更新猪栏 tags: - 猪场管理 @@ -1646,6 +1697,8 @@ paths: data: $ref: '#/definitions/dto.PenResponse' type: object + security: + - BearerAuth: [] summary: 更新猪栏状态 tags: - 猪场管理 @@ -1671,6 +1724,8 @@ paths: $ref: '#/definitions/dto.PigBatchResponseDTO' type: array type: object + security: + - BearerAuth: [] summary: 获取猪批次列表 tags: - 猪群管理 @@ -1697,6 +1752,8 @@ paths: data: $ref: '#/definitions/dto.PigBatchResponseDTO' type: object + security: + - BearerAuth: [] summary: 创建猪批次 tags: - 猪群管理 @@ -1716,6 +1773,8 @@ paths: description: 删除成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除猪批次 tags: - 猪群管理 @@ -1739,6 +1798,8 @@ paths: data: $ref: '#/definitions/dto.PigBatchResponseDTO' type: object + security: + - BearerAuth: [] summary: 获取单个猪批次 tags: - 猪群管理 @@ -1770,6 +1831,8 @@ paths: data: $ref: '#/definitions/dto.PigBatchResponseDTO' type: object + security: + - BearerAuth: [] summary: 更新猪批次 tags: - 猪群管理 @@ -1797,6 +1860,8 @@ paths: description: 分配成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 为猪批次分配空栏 tags: - 猪群管理 @@ -1824,6 +1889,8 @@ paths: description: 买猪成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 处理买猪的业务逻辑 tags: - 猪群管理 @@ -1851,6 +1918,8 @@ paths: description: 移入成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 将猪只从“虚拟库存”移入指定猪栏 tags: - 猪群管理 @@ -1878,6 +1947,8 @@ paths: description: 划拨成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 将猪栏划拨到新批次 tags: - 猪群管理 @@ -1905,6 +1976,8 @@ paths: description: 记录成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 记录正常猪只淘汰事件 tags: - 猪群管理 @@ -1932,6 +2005,8 @@ paths: description: 记录成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 记录正常猪只死亡事件 tags: - 猪群管理 @@ -1959,6 +2034,8 @@ paths: description: 记录成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 记录病猪淘汰事件 tags: - 猪群管理 @@ -1986,6 +2063,8 @@ paths: description: 记录成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 记录病猪死亡事件 tags: - 猪群管理 @@ -2013,6 +2092,8 @@ paths: description: 记录成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 记录病猪康复事件 tags: - 猪群管理 @@ -2040,6 +2121,8 @@ paths: description: 记录成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 记录新增病猪事件 tags: - 猪群管理 @@ -2064,6 +2147,8 @@ paths: description: 移除成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 从猪批次移除空栏 tags: - 猪群管理 @@ -2091,6 +2176,8 @@ paths: description: 卖猪成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 处理卖猪的业务逻辑 tags: - 猪群管理 @@ -2118,6 +2205,8 @@ paths: description: 调栏成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 跨猪群调栏 tags: - 猪群管理 @@ -2145,6 +2234,8 @@ paths: description: 调栏成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 群内调栏 tags: - 猪群管理 @@ -2165,6 +2256,8 @@ paths: $ref: '#/definitions/dto.PigHouseResponse' type: array type: object + security: + - BearerAuth: [] summary: 获取猪舍列表 tags: - 猪场管理 @@ -2191,6 +2284,8 @@ paths: data: $ref: '#/definitions/dto.PigHouseResponse' type: object + security: + - BearerAuth: [] summary: 创建猪舍 tags: - 猪场管理 @@ -2210,6 +2305,8 @@ paths: description: 删除成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除猪舍 tags: - 猪场管理 @@ -2233,6 +2330,8 @@ paths: data: $ref: '#/definitions/dto.PigHouseResponse' type: object + security: + - BearerAuth: [] summary: 获取单个猪舍 tags: - 猪场管理 @@ -2264,6 +2363,8 @@ paths: data: $ref: '#/definitions/dto.PigHouseResponse' type: object + security: + - BearerAuth: [] summary: 更新猪舍 tags: - 猪场管理 @@ -2284,6 +2385,8 @@ paths: $ref: '#/definitions/dto.PlanResponse' type: array type: object + security: + - BearerAuth: [] summary: 获取计划列表 tags: - 计划管理 @@ -2310,6 +2413,8 @@ paths: data: $ref: '#/definitions/dto.PlanResponse' type: object + security: + - BearerAuth: [] summary: 创建计划 tags: - 计划管理 @@ -2329,6 +2434,8 @@ paths: description: 业务码为200代表删除成功 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 删除计划 tags: - 计划管理 @@ -2352,6 +2459,8 @@ paths: data: $ref: '#/definitions/dto.PlanResponse' type: object + security: + - BearerAuth: [] summary: 获取计划详情 tags: - 计划管理 @@ -2383,6 +2492,8 @@ paths: data: $ref: '#/definitions/dto.PlanResponse' type: object + security: + - BearerAuth: [] summary: 更新计划 tags: - 计划管理 @@ -2402,6 +2513,8 @@ paths: description: 业务码为200代表成功启动计划 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 启动计划 tags: - 计划管理 @@ -2421,6 +2534,8 @@ paths: description: 业务码为200代表成功停止计划 schema: $ref: '#/definitions/controller.Response' + security: + - BearerAuth: [] summary: 停止计划 tags: - 计划管理 @@ -2486,6 +2601,8 @@ paths: data: $ref: '#/definitions/dto.ListHistoryResponse' type: object + security: + - BearerAuth: [] summary: 获取指定用户的操作历史 tags: - 用户管理 @@ -2516,4 +2633,9 @@ paths: summary: 用户登录 tags: - 用户管理 +securityDefinitions: + BearerAuth: + in: header + name: Authorization + type: apiKey swagger: "2.0" diff --git a/internal/app/api/api.go b/internal/app/api/api.go index ac46297..3dc698f 100644 --- a/internal/app/api/api.go +++ b/internal/app/api/api.go @@ -8,6 +8,10 @@ package api // @contact.email divano@example.com // @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html +// @securityDefinitions.apikey BearerAuth +// @in header +// @name Authorization + import ( "context" "fmt" diff --git a/internal/app/controller/device/device_controller.go b/internal/app/controller/device/device_controller.go index 0bed6fc..e727c37 100644 --- a/internal/app/controller/device/device_controller.go +++ b/internal/app/controller/device/device_controller.go @@ -48,6 +48,7 @@ func NewController( // @Summary 创建新设备 // @Description 根据提供的信息创建一个新设备 // @Tags 设备管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param device body dto.CreateDeviceRequest true "设备信息" @@ -111,6 +112,7 @@ func (c *Controller) CreateDevice(ctx *gin.Context) { // @Summary 获取设备信息 // @Description 根据设备ID获取单个设备的详细信息 // @Tags 设备管理 +// @Security BearerAuth // @Produce json // @Param id path string true "设备ID" // @Success 200 {object} controller.Response{data=dto.DeviceResponse} @@ -157,6 +159,7 @@ func (c *Controller) GetDevice(ctx *gin.Context) { // @Summary 获取设备列表 // @Description 获取系统中所有设备的列表 // @Tags 设备管理 +// @Security BearerAuth // @Produce json // @Success 200 {object} controller.Response{data=[]dto.DeviceResponse} // @Router /api/v1/devices [get] @@ -184,6 +187,7 @@ func (c *Controller) ListDevices(ctx *gin.Context) { // @Summary 更新设备信息 // @Description 根据设备ID更新一个已存在的设备信息 // @Tags 设备管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path string true "设备ID" @@ -265,6 +269,7 @@ func (c *Controller) UpdateDevice(ctx *gin.Context) { // @Summary 删除设备 // @Description 根据设备ID删除一个设备(软删除) // @Tags 设备管理 +// @Security BearerAuth // @Produce json // @Param id path string true "设备ID" // @Success 200 {object} controller.Response @@ -306,6 +311,7 @@ func (c *Controller) DeleteDevice(ctx *gin.Context) { // @Summary 手动控制设备 // @Description 根据设备ID和指定的动作(开启或关闭)来手动控制设备 // @Tags 设备管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path string true "设备ID" @@ -369,6 +375,7 @@ func (c *Controller) ManualControl(ctx *gin.Context) { // @Summary 创建新区域主控 // @Description 根据提供的信息创建一个新区域主控 // @Tags 区域主控管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param areaController body dto.CreateAreaControllerRequest true "区域主控信息" @@ -424,6 +431,7 @@ func (c *Controller) CreateAreaController(ctx *gin.Context) { // @Summary 获取区域主控信息 // @Description 根据ID获取单个区域主控的详细信息 // @Tags 区域主控管理 +// @Security BearerAuth // @Produce json // @Param id path string true "区域主控ID" // @Success 200 {object} controller.Response{data=dto.AreaControllerResponse} @@ -466,6 +474,7 @@ func (c *Controller) GetAreaController(ctx *gin.Context) { // @Summary 获取所有区域主控列表 // @Description 获取系统中所有区域主控的列表 // @Tags 区域主控管理 +// @Security BearerAuth // @Produce json // @Success 200 {object} controller.Response{data=[]dto.AreaControllerResponse} // @Router /api/v1/area-controllers [get] @@ -493,6 +502,7 @@ func (c *Controller) ListAreaControllers(ctx *gin.Context) { // @Summary 更新区域主控信息 // @Description 根据ID更新一个已存在的区域主控信息 // @Tags 区域主控管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path string true "区域主控ID" @@ -568,6 +578,7 @@ func (c *Controller) UpdateAreaController(ctx *gin.Context) { // @Summary 删除区域主控 // @Description 根据ID删除一个区域主控(软删除) // @Tags 区域主控管理 +// @Security BearerAuth // @Produce json // @Param id path string true "区域主控ID" // @Success 200 {object} controller.Response @@ -611,6 +622,7 @@ func (c *Controller) DeleteAreaController(ctx *gin.Context) { // @Summary 创建新设备模板 // @Description 根据提供的信息创建一个新设备模板 // @Tags 设备模板管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param deviceTemplate body dto.CreateDeviceTemplateRequest true "设备模板信息" @@ -675,6 +687,7 @@ func (c *Controller) CreateDeviceTemplate(ctx *gin.Context) { // @Summary 获取设备模板信息 // @Description 根据设备模板ID获取单个设备模板的详细信息 // @Tags 设备模板管理 +// @Security BearerAuth // @Produce json // @Param id path string true "设备模板ID" // @Success 200 {object} controller.Response{data=dto.DeviceTemplateResponse} @@ -717,6 +730,7 @@ func (c *Controller) GetDeviceTemplate(ctx *gin.Context) { // @Summary 获取设备模板列表 // @Description 获取系统中所有设备模板的列表 // @Tags 设备模板管理 +// @Security BearerAuth // @Produce json // @Success 200 {object} controller.Response{data=[]dto.DeviceTemplateResponse} // @Router /api/v1/device-templates [get] @@ -744,6 +758,7 @@ func (c *Controller) ListDeviceTemplates(ctx *gin.Context) { // @Summary 更新设备模板信息 // @Description 根据设备模板ID更新一个已存在的设备模板信息 // @Tags 设备模板管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path string true "设备模板ID" @@ -828,6 +843,7 @@ func (c *Controller) UpdateDeviceTemplate(ctx *gin.Context) { // @Summary 删除设备模板 // @Description 根据设备模板ID删除一个设备模板(软删除) // @Tags 设备模板管理 +// @Security BearerAuth // @Produce json // @Param id path string true "设备模板ID" // @Success 200 {object} controller.Response diff --git a/internal/app/controller/management/pig_batch_controller.go b/internal/app/controller/management/pig_batch_controller.go index 6b1bf8e..7f24b13 100644 --- a/internal/app/controller/management/pig_batch_controller.go +++ b/internal/app/controller/management/pig_batch_controller.go @@ -28,6 +28,7 @@ func NewPigBatchController(logger *logs.Logger, service service.PigBatchService) // @Summary 创建猪批次 // @Description 创建一个新的猪批次 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param body body dto.PigBatchCreateDTO true "猪批次信息" @@ -52,6 +53,7 @@ func (c *PigBatchController) CreatePigBatch(ctx *gin.Context) { // @Summary 获取单个猪批次 // @Description 根据ID获取单个猪批次信息 // @Tags 猪群管理 +// @Security BearerAuth // @Produce json // @Param id path int true "猪批次ID" // @Success 200 {object} controller.Response{data=dto.PigBatchResponseDTO} "获取成功" @@ -73,6 +75,7 @@ func (c *PigBatchController) GetPigBatch(ctx *gin.Context) { // @Summary 更新猪批次 // @Description 更新一个已存在的猪批次信息 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -97,6 +100,7 @@ func (c *PigBatchController) UpdatePigBatch(ctx *gin.Context) { // @Summary 删除猪批次 // @Description 根据ID删除一个猪批次 // @Tags 猪群管理 +// @Security BearerAuth // @Produce json // @Param id path int true "猪批次ID" // @Success 200 {object} controller.Response "删除成功" @@ -118,6 +122,7 @@ func (c *PigBatchController) DeletePigBatch(ctx *gin.Context) { // @Summary 获取猪批次列表 // @Description 获取所有猪批次的列表,支持按活跃状态筛选 // @Tags 猪群管理 +// @Security BearerAuth // @Produce json // @Param is_active query bool false "是否活跃 (true/false)" // @Success 200 {object} controller.Response{data=[]dto.PigBatchResponseDTO} "获取成功" @@ -139,6 +144,7 @@ func (c *PigBatchController) ListPigBatches(ctx *gin.Context) { // @Summary 为猪批次分配空栏 // @Description 将一个或多个空闲猪栏分配给指定的猪批次 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -163,6 +169,7 @@ func (c *PigBatchController) AssignEmptyPensToBatch(ctx *gin.Context) { // @Summary 将猪栏划拨到新批次 // @Description 将一个猪栏(连同其中的猪只)从一个批次整体划拨到另一个批次 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param fromBatchID path int true "源猪批次ID" @@ -195,6 +202,7 @@ func (c *PigBatchController) ReclassifyPenToNewBatch(ctx *gin.Context) { // @Summary 从猪批次移除空栏 // @Description 将一个空闲猪栏从指定的猪批次中移除 // @Tags 猪群管理 +// @Security BearerAuth // @Produce json // @Param batchID path int true "猪批次ID" // @Param penID path int true "待移除的猪栏ID" @@ -230,6 +238,7 @@ func (c *PigBatchController) RemoveEmptyPenFromBatch(ctx *gin.Context) { // @Summary 将猪只从“虚拟库存”移入指定猪栏 // @Description 将指定数量的猪只从批次的“虚拟库存”移入一个已分配的猪栏 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" diff --git a/internal/app/controller/management/pig_batch_health_controller.go b/internal/app/controller/management/pig_batch_health_controller.go index dd8c235..828c5a3 100644 --- a/internal/app/controller/management/pig_batch_health_controller.go +++ b/internal/app/controller/management/pig_batch_health_controller.go @@ -9,6 +9,7 @@ import ( // @Summary 记录新增病猪事件 // @Description 记录猪批次中新增病猪的数量、治疗地点和发生时间 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -33,6 +34,7 @@ func (c *PigBatchController) RecordSickPigs(ctx *gin.Context) { // @Summary 记录病猪康复事件 // @Description 记录猪批次中病猪康复的数量、治疗地点和发生时间 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -57,6 +59,7 @@ func (c *PigBatchController) RecordSickPigRecovery(ctx *gin.Context) { // @Summary 记录病猪死亡事件 // @Description 记录猪批次中病猪死亡的数量、治疗地点和发生时间 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -81,6 +84,7 @@ func (c *PigBatchController) RecordSickPigDeath(ctx *gin.Context) { // @Summary 记录病猪淘汰事件 // @Description 记录猪批次中病猪淘汰的数量、治疗地点和发生时间 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -105,6 +109,7 @@ func (c *PigBatchController) RecordSickPigCull(ctx *gin.Context) { // @Summary 记录正常猪只死亡事件 // @Description 记录猪批次中正常猪只死亡的数量和发生时间 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -129,6 +134,7 @@ func (c *PigBatchController) RecordDeath(ctx *gin.Context) { // @Summary 记录正常猪只淘汰事件 // @Description 记录猪批次中正常猪只淘汰的数量和发生时间 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" diff --git a/internal/app/controller/management/pig_batch_trade_controller.go b/internal/app/controller/management/pig_batch_trade_controller.go index 2db82af..de79498 100644 --- a/internal/app/controller/management/pig_batch_trade_controller.go +++ b/internal/app/controller/management/pig_batch_trade_controller.go @@ -9,6 +9,7 @@ import ( // @Summary 处理卖猪的业务逻辑 // @Description 记录猪批次中的猪只出售事件 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" @@ -33,6 +34,7 @@ func (c *PigBatchController) SellPigs(ctx *gin.Context) { // @Summary 处理买猪的业务逻辑 // @Description 记录猪批次中的猪只购买事件 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" diff --git a/internal/app/controller/management/pig_batch_transfer_controller.go b/internal/app/controller/management/pig_batch_transfer_controller.go index 4d5cc3e..715cb61 100644 --- a/internal/app/controller/management/pig_batch_transfer_controller.go +++ b/internal/app/controller/management/pig_batch_transfer_controller.go @@ -11,6 +11,7 @@ import ( // @Summary 跨猪群调栏 // @Description 将指定数量的猪只从一个猪群的猪栏调动到另一个猪群的猪栏 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param sourceBatchID path int true "源猪批次ID" @@ -43,6 +44,7 @@ func (c *PigBatchController) TransferPigsAcrossBatches(ctx *gin.Context) { // @Summary 群内调栏 // @Description 将指定数量的猪只在同一个猪群的不同猪栏间调动 // @Tags 猪群管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪批次ID" diff --git a/internal/app/controller/management/pig_farm_controller.go b/internal/app/controller/management/pig_farm_controller.go index 84a6a05..d31ef31 100644 --- a/internal/app/controller/management/pig_farm_controller.go +++ b/internal/app/controller/management/pig_farm_controller.go @@ -33,6 +33,7 @@ func NewPigFarmController(logger *logs.Logger, service service.PigFarmService) * // @Summary 创建猪舍 // @Description 创建一个新的猪舍 // @Tags 猪场管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param body body dto.CreatePigHouseRequest true "猪舍信息" @@ -65,6 +66,7 @@ func (c *PigFarmController) CreatePigHouse(ctx *gin.Context) { // @Summary 获取单个猪舍 // @Description 根据ID获取单个猪舍信息 // @Tags 猪场管理 +// @Security BearerAuth // @Produce json // @Param id path int true "猪舍ID" // @Success 200 {object} controller.Response{data=dto.PigHouseResponse} "获取成功" @@ -100,6 +102,7 @@ func (c *PigFarmController) GetPigHouse(ctx *gin.Context) { // @Summary 获取猪舍列表 // @Description 获取所有猪舍的列表 // @Tags 猪场管理 +// @Security BearerAuth // @Produce json // @Success 200 {object} controller.Response{data=[]dto.PigHouseResponse} "获取成功" // @Router /api/v1/pig-houses [get] @@ -128,6 +131,7 @@ func (c *PigFarmController) ListPigHouses(ctx *gin.Context) { // @Summary 更新猪舍 // @Description 更新一个已存在的猪舍信息 // @Tags 猪场管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪舍ID" @@ -171,6 +175,7 @@ func (c *PigFarmController) UpdatePigHouse(ctx *gin.Context) { // @Summary 删除猪舍 // @Description 根据ID删除一个猪舍 // @Tags 猪场管理 +// @Security BearerAuth // @Produce json // @Param id path int true "猪舍ID" // @Success 200 {object} controller.Response "删除成功" @@ -207,6 +212,7 @@ func (c *PigFarmController) DeletePigHouse(ctx *gin.Context) { // @Summary 创建猪栏 // @Description 创建一个新的猪栏 // @Tags 猪场管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param body body dto.CreatePenRequest true "猪栏信息" @@ -247,6 +253,7 @@ func (c *PigFarmController) CreatePen(ctx *gin.Context) { // @Summary 获取单个猪栏 // @Description 根据ID获取单个猪栏信息 // @Tags 猪场管理 +// @Security BearerAuth // @Produce json // @Param id path int true "猪栏ID" // @Success 200 {object} controller.Response{data=dto.PenResponse} "获取成功" @@ -285,6 +292,7 @@ func (c *PigFarmController) GetPen(ctx *gin.Context) { // @Summary 获取猪栏列表 // @Description 获取所有猪栏的列表 // @Tags 猪场管理 +// @Security BearerAuth // @Produce json // @Success 200 {object} controller.Response{data=[]dto.PenResponse} "获取成功" // @Router /api/v1/pens [get] @@ -316,6 +324,7 @@ func (c *PigFarmController) ListPens(ctx *gin.Context) { // @Summary 更新猪栏 // @Description 更新一个已存在的猪栏信息 // @Tags 猪场管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪栏ID" @@ -363,6 +372,7 @@ func (c *PigFarmController) UpdatePen(ctx *gin.Context) { // @Summary 删除猪栏 // @Description 根据ID删除一个猪栏 // @Tags 猪场管理 +// @Security BearerAuth // @Produce json // @Param id path int true "猪栏ID" // @Success 200 {object} controller.Response "删除成功" @@ -397,6 +407,7 @@ func (c *PigFarmController) DeletePen(ctx *gin.Context) { // @Summary 更新猪栏状态 // @Description 更新指定猪栏的当前状态 // @Tags 猪场管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "猪栏ID" diff --git a/internal/app/controller/plan/plan_controller.go b/internal/app/controller/plan/plan_controller.go index e7a8862..cad8afe 100644 --- a/internal/app/controller/plan/plan_controller.go +++ b/internal/app/controller/plan/plan_controller.go @@ -38,6 +38,7 @@ func NewController(logger *logs.Logger, planRepo repository.PlanRepository, anal // @Summary 创建计划 // @Description 创建一个新的计划,包括其基本信息和所有关联的子计划/任务。 // @Tags 计划管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param plan body dto.CreatePlanRequest true "计划信息" @@ -98,6 +99,7 @@ func (c *Controller) CreatePlan(ctx *gin.Context) { // @Summary 获取计划详情 // @Description 根据计划ID获取单个计划的详细信息。 // @Tags 计划管理 +// @Security BearerAuth // @Produce json // @Param id path int true "计划ID" // @Success 200 {object} controller.Response{data=dto.PlanResponse} "业务码为200代表成功获取" @@ -145,6 +147,7 @@ func (c *Controller) GetPlan(ctx *gin.Context) { // @Summary 获取计划列表 // @Description 获取所有计划的列表 // @Tags 计划管理 +// @Security BearerAuth // @Produce json // @Success 200 {object} controller.Response{data=[]dto.PlanResponse} "业务码为200代表成功获取列表" // @Router /api/v1/plans [get] @@ -183,6 +186,7 @@ func (c *Controller) ListPlans(ctx *gin.Context) { // @Summary 更新计划 // @Description 根据计划ID更新计划的详细信息。 // @Tags 计划管理 +// @Security BearerAuth // @Accept json // @Produce json // @Param id path int true "计划ID" @@ -280,6 +284,7 @@ func (c *Controller) UpdatePlan(ctx *gin.Context) { // @Summary 删除计划 // @Description 根据计划ID删除计划。(软删除) // @Tags 计划管理 +// @Security BearerAuth // @Produce json // @Param id path int true "计划ID" // @Success 200 {object} controller.Response "业务码为200代表删除成功" @@ -333,6 +338,7 @@ func (c *Controller) DeletePlan(ctx *gin.Context) { // @Summary 启动计划 // @Description 根据计划ID启动一个计划的执行。 // @Tags 计划管理 +// @Security BearerAuth // @Produce json // @Param id path int true "计划ID" // @Success 200 {object} controller.Response "业务码为200代表成功启动计划" @@ -412,6 +418,7 @@ func (c *Controller) StartPlan(ctx *gin.Context) { // @Summary 停止计划 // @Description 根据计划ID停止一个正在执行的计划。 // @Tags 计划管理 +// @Security BearerAuth // @Produce json // @Param id path int true "计划ID" // @Success 200 {object} controller.Response "业务码为200代表成功停止计划" diff --git a/internal/app/controller/user/user_controller.go b/internal/app/controller/user/user_controller.go index 27689d4..14462be 100644 --- a/internal/app/controller/user/user_controller.go +++ b/internal/app/controller/user/user_controller.go @@ -130,6 +130,7 @@ func (c *Controller) Login(ctx *gin.Context) { // @Summary 获取指定用户的操作历史 // @Description 根据用户ID,分页获取该用户的操作审计日志。 // @Tags 用户管理 +// @Security BearerAuth // @Produce json // @Param id path int true "用户ID" // @Param page query int false "页码" default(1)