From 4e046021e371d626b6233f6d69e3cc8a781ed650 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sun, 19 Oct 2025 20:24:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8Capi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs.go | 2402 +++++++++++++++++ docs/swagger.json | 2402 +++++++++++++++++ docs/swagger.yaml | 1490 ++++++++++ internal/app/api/api.go | 158 +- internal/app/api/router.go | 181 ++ .../controller/monitor/monitor_controller.go | 4 +- internal/app/middleware/auth.go | 2 +- internal/app/service/monitor_service.go | 63 +- internal/core/application.go | 16 + 9 files changed, 6541 insertions(+), 177 deletions(-) create mode 100644 internal/app/api/router.go diff --git a/docs/docs.go b/docs/docs.go index 4b91cff..72fe31b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -738,6 +738,1344 @@ const docTemplate = `{ } } }, + "/api/v1/monitor/device-command-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取设备命令日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取设备命令日志列表", + "parameters": [ + { + "type": "integer", + "name": "device_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "boolean", + "name": "received_success", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListDeviceCommandLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/feed-usage-records": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取饲料使用记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取饲料使用记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "feed_formula_id", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListFeedUsageRecordResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/medication-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取用药记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取用药记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "medication_id", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "reason", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListMedicationLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pending-collections": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取待采集请求", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取待采集请求列表", + "parameters": [ + { + "type": "integer", + "name": "device_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPendingCollectionResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-batch-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪批次日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪批次日志列表", + "parameters": [ + { + "type": "string", + "name": "change_type", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigBatchLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-purchases": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪只采购记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪只采购记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "supplier", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigPurchaseResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-sales": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪只售卖记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪只售卖记录列表", + "parameters": [ + { + "type": "string", + "name": "buyer", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigSaleResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-sick-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取病猪日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取病猪日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "reason", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "treatment_location", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigSickLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-transfer-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪只迁移日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪只迁移日志列表", + "parameters": [ + { + "type": "string", + "name": "correlation_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "transfer_type", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigTransferLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/plan-execution-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取计划执行日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取计划执行日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "plan_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPlanExecutionLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/raw-material-purchases": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取原料采购记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取原料采购记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "raw_material_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "supplier", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListRawMaterialPurchaseResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/raw-material-stock-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取原料库存日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取原料库存日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "raw_material_id", + "in": "query" + }, + { + "type": "integer", + "name": "source_id", + "in": "query" + }, + { + "type": "string", + "name": "source_type", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListRawMaterialStockLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/sensor-data": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取传感器数据", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取传感器数据列表", + "parameters": [ + { + "type": "integer", + "name": "device_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "sensor_type", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListSensorDataResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/task-execution-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取任务执行日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取任务执行日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "plan_execution_log_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "name": "task_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListTaskExecutionLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/user-action-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取用户操作日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取用户操作日志列表", + "parameters": [ + { + "type": "string", + "name": "action_type", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "name": "user_id", + "in": "query" + }, + { + "type": "string", + "name": "username", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListUserActionLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/weighing-batches": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取批次称重记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取批次称重记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListWeighingBatchResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/weighing-records": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取单次称重记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取单次称重记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "integer", + "name": "weighing_batch_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListWeighingRecordResponse" + } + } + } + ] + } + } + } + } + }, "/api/v1/pens": { "get": { "security": [ @@ -2891,6 +4229,26 @@ const docTemplate = `{ } } }, + "dto.DeviceCommandLogDTO": { + "type": "object", + "properties": { + "acknowledged_at": { + "type": "string" + }, + "device_id": { + "type": "integer" + }, + "message_id": { + "type": "string" + }, + "received_success": { + "type": "boolean" + }, + "sent_at": { + "type": "string" + } + } + }, "dto.DeviceResponse": { "type": "object", "properties": { @@ -2963,6 +4321,49 @@ const docTemplate = `{ } } }, + "dto.FeedFormulaDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.FeedUsageRecordDTO": { + "type": "object", + "properties": { + "amount": { + "type": "number" + }, + "feed_formula": { + "$ref": "#/definitions/dto.FeedFormulaDTO" + }, + "feed_formula_id": { + "type": "integer" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen": { + "$ref": "#/definitions/dto.PenDTO" + }, + "pen_id": { + "type": "integer" + }, + "recorded_at": { + "type": "string" + }, + "remarks": { + "type": "string" + } + } + }, "dto.HistoryResponse": { "type": "object", "properties": { @@ -2988,6 +4389,34 @@ const docTemplate = `{ } } }, + "dto.ListDeviceCommandLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.DeviceCommandLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListFeedUsageRecordResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.FeedUsageRecordDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, "dto.ListHistoryResponse": { "type": "object", "properties": { @@ -3003,6 +4432,216 @@ const docTemplate = `{ } } }, + "dto.ListMedicationLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.MedicationLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPendingCollectionResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PendingCollectionDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigBatchLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigBatchLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigPurchaseResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigPurchaseDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigSaleResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigSaleDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigSickLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigSickLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigTransferLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigTransferLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPlanExecutionLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PlanExecutionLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListRawMaterialPurchaseResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.RawMaterialPurchaseDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListRawMaterialStockLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.RawMaterialStockLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListSensorDataResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.SensorDataDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListTaskExecutionLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.TaskExecutionLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListUserActionLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.UserActionLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListWeighingBatchResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.WeighingBatchDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListWeighingRecordResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.WeighingRecordDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, "dto.LoginRequest": { "type": "object", "required": [ @@ -3047,6 +4686,52 @@ const docTemplate = `{ } } }, + "dto.MedicationDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.MedicationLogDTO": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "dosage_used": { + "type": "number" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "medication": { + "$ref": "#/definitions/dto.MedicationDTO" + }, + "medication_id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "reason": { + "$ref": "#/definitions/models.MedicationReasonType" + }, + "target_count": { + "type": "integer" + } + } + }, "dto.MovePigsIntoPenRequest": { "type": "object", "required": [ @@ -3069,6 +4754,31 @@ const docTemplate = `{ } } }, + "dto.PaginationDTO": { + "type": "object", + "properties": { + "page": { + "type": "integer" + }, + "pageSize": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, + "dto.PenDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "dto.PenResponse": { "type": "object", "properties": { @@ -3092,6 +4802,32 @@ const docTemplate = `{ } } }, + "dto.PendingCollectionDTO": { + "type": "object", + "properties": { + "command_metadata": { + "type": "array", + "items": { + "type": "integer" + } + }, + "correlation_id": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "device_id": { + "type": "integer" + }, + "fulfilled_at": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.PendingCollectionStatus" + } + } + }, "dto.PigBatchCreateDTO": { "type": "object", "required": [ @@ -3133,6 +4869,44 @@ const docTemplate = `{ } } }, + "dto.PigBatchLogDTO": { + "type": "object", + "properties": { + "after_count": { + "type": "integer" + }, + "before_count": { + "type": "integer" + }, + "change_count": { + "type": "integer" + }, + "change_type": { + "$ref": "#/definitions/models.LogChangeType" + }, + "created_at": { + "type": "string" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "reason": { + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "dto.PigBatchResponseDTO": { "type": "object", "properties": { @@ -3237,6 +5011,193 @@ const docTemplate = `{ } } }, + "dto.PigPurchaseDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "purchase_date": { + "type": "string" + }, + "quantity": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "supplier": { + "type": "string" + }, + "total_price": { + "type": "number" + }, + "unit_price": { + "type": "number" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PigSaleDTO": { + "type": "object", + "properties": { + "buyer": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "quantity": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "sale_date": { + "type": "string" + }, + "total_price": { + "type": "number" + }, + "unit_price": { + "type": "number" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PigSickLogDTO": { + "type": "object", + "properties": { + "after_count": { + "type": "integer" + }, + "before_count": { + "type": "integer" + }, + "change_count": { + "type": "integer" + }, + "created_at": { + "type": "string" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "reason": { + "$ref": "#/definitions/models.PigBatchSickPigReasonType" + }, + "remarks": { + "type": "string" + }, + "treatment_location": { + "$ref": "#/definitions/models.PigBatchSickPigTreatmentLocation" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PigTransferLogDTO": { + "type": "object", + "properties": { + "correlation_id": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "quantity": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "transfer_time": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/models.PigTransferType" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PlanExecutionLogDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "ended_at": { + "type": "string" + }, + "error": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "plan_id": { + "type": "integer" + }, + "started_at": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.ExecutionStatus" + }, + "updated_at": { + "type": "string" + } + } + }, "dto.PlanResponse": { "type": "object", "properties": { @@ -3302,6 +5263,75 @@ const docTemplate = `{ } } }, + "dto.RawMaterialDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.RawMaterialPurchaseDTO": { + "type": "object", + "properties": { + "amount": { + "type": "number" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "purchase_date": { + "type": "string" + }, + "raw_material": { + "$ref": "#/definitions/dto.RawMaterialDTO" + }, + "raw_material_id": { + "type": "integer" + }, + "supplier": { + "type": "string" + }, + "total_price": { + "type": "number" + }, + "unit_price": { + "type": "number" + } + } + }, + "dto.RawMaterialStockLogDTO": { + "type": "object", + "properties": { + "change_amount": { + "type": "number" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "raw_material_id": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "source_id": { + "type": "integer" + }, + "source_type": { + "$ref": "#/definitions/models.StockLogSourceType" + } + } + }, "dto.ReclassifyPenToNewBatchRequest": { "type": "object", "required": [ @@ -3565,6 +5595,29 @@ const docTemplate = `{ } } }, + "dto.SensorDataDTO": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "integer" + } + }, + "device_id": { + "type": "integer" + }, + "regional_controller_id": { + "type": "integer" + }, + "sensor_type": { + "$ref": "#/definitions/models.SensorType" + }, + "time": { + "type": "string" + } + } + }, "dto.SubPlanResponse": { "type": "object", "properties": { @@ -3589,6 +5642,60 @@ const docTemplate = `{ } } }, + "dto.TaskDTO": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.TaskExecutionLogDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "ended_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "output": { + "type": "string" + }, + "plan_execution_log_id": { + "type": "integer" + }, + "started_at": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.ExecutionStatus" + }, + "task": { + "description": "嵌套的任务信息", + "allOf": [ + { + "$ref": "#/definitions/dto.TaskDTO" + } + ] + }, + "task_id": { + "type": "integer" + }, + "updated_at": { + "type": "string" + } + } + }, "dto.TaskRequest": { "type": "object", "properties": { @@ -3912,6 +6019,116 @@ const docTemplate = `{ } } }, + "dto.UserActionLogDTO": { + "type": "object", + "properties": { + "action_type": { + "type": "string" + }, + "description": { + "type": "string" + }, + "http_method": { + "type": "string" + }, + "http_path": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "result_details": { + "type": "string" + }, + "source_ip": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.AuditStatus" + }, + "target_resource": { + "type": "array", + "items": { + "type": "integer" + } + }, + "time": { + "type": "string" + }, + "user_id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }, + "dto.WeighingBatchDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "updated_at": { + "type": "string" + }, + "weighing_time": { + "type": "string" + } + } + }, + "dto.WeighingRecordDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen_id": { + "type": "integer" + }, + "remark": { + "type": "string" + }, + "updated_at": { + "type": "string" + }, + "weighing_batch_id": { + "type": "integer" + }, + "weighing_time": { + "type": "string" + }, + "weight": { + "type": "number" + } + } + }, + "models.AuditStatus": { + "type": "string", + "enum": [ + "成功", + "失败" + ], + "x-enum-varnames": [ + "AuditStatusSuccess", + "AuditStatusFailed" + ] + }, "models.DeviceCategory": { "type": "string", "enum": [ @@ -3923,6 +6140,71 @@ const docTemplate = `{ "CategorySensor" ] }, + "models.ExecutionStatus": { + "type": "string", + "enum": [ + "已开始", + "已完成", + "失败", + "已取消", + "等待中" + ], + "x-enum-comments": { + "ExecutionStatusCancelled": "执行取消", + "ExecutionStatusCompleted": "执行完成", + "ExecutionStatusFailed": "执行失败", + "ExecutionStatusStarted": "开始执行", + "ExecutionStatusWaiting": "等待执行 (用于预写日志)" + }, + "x-enum-descriptions": [ + "开始执行", + "执行完成", + "执行失败", + "执行取消", + "等待执行 (用于预写日志)" + ], + "x-enum-varnames": [ + "ExecutionStatusStarted", + "ExecutionStatusCompleted", + "ExecutionStatusFailed", + "ExecutionStatusCancelled", + "ExecutionStatusWaiting" + ] + }, + "models.LogChangeType": { + "type": "string", + "enum": [ + "死亡", + "淘汰", + "销售", + "购买", + "转入", + "转出", + "盘点校正" + ], + "x-enum-varnames": [ + "ChangeTypeDeath", + "ChangeTypeCull", + "ChangeTypeSale", + "ChangeTypeBuy", + "ChangeTypeTransferIn", + "ChangeTypeTransferOut", + "ChangeTypeCorrection" + ] + }, + "models.MedicationReasonType": { + "type": "string", + "enum": [ + "预防", + "治疗", + "保健" + ], + "x-enum-varnames": [ + "ReasonTypePreventive", + "ReasonTypeTreatment", + "ReasonTypeHealthCare" + ] + }, "models.PenStatus": { "type": "string", "enum": [ @@ -3942,6 +6224,29 @@ const docTemplate = `{ "PenStatusUnderMaint" ] }, + "models.PendingCollectionStatus": { + "type": "string", + "enum": [ + "等待中", + "已完成", + "已超时" + ], + "x-enum-comments": { + "PendingStatusFulfilled": "已收到设备响应并成功处理", + "PendingStatusPending": "请求已发送,等待设备响应", + "PendingStatusTimedOut": "请求超时,未收到设备响应" + }, + "x-enum-descriptions": [ + "请求已发送,等待设备响应", + "已收到设备响应并成功处理", + "请求超时,未收到设备响应" + ], + "x-enum-varnames": [ + "PendingStatusPending", + "PendingStatusFulfilled", + "PendingStatusTimedOut" + ] + }, "models.PigBatchOriginType": { "type": "string", "enum": [ @@ -3953,6 +6258,45 @@ const docTemplate = `{ "OriginTypePurchased" ] }, + "models.PigBatchSickPigReasonType": { + "type": "string", + "enum": [ + "患病", + "康复", + "死亡", + "淘汰", + "转入", + "转出", + "其他" + ], + "x-enum-comments": { + "SickPigReasonTypeDeath": "猪只死亡", + "SickPigReasonTypeEliminate": "猪只淘汰", + "SickPigReasonTypeIllness": "猪只患病", + "SickPigReasonTypeOther": "其他原因", + "SickPigReasonTypeRecovery": "猪只康复", + "SickPigReasonTypeTransferIn": "病猪转入当前批次", + "SickPigReasonTypeTransferOut": "病猪转出当前批次 (例如转到其他批次或出售)" + }, + "x-enum-descriptions": [ + "猪只患病", + "猪只康复", + "猪只死亡", + "猪只淘汰", + "病猪转入当前批次", + "病猪转出当前批次 (例如转到其他批次或出售)", + "其他原因" + ], + "x-enum-varnames": [ + "SickPigReasonTypeIllness", + "SickPigReasonTypeRecovery", + "SickPigReasonTypeDeath", + "SickPigReasonTypeEliminate", + "SickPigReasonTypeTransferIn", + "SickPigReasonTypeTransferOut", + "SickPigReasonTypeOther" + ] + }, "models.PigBatchSickPigTreatmentLocation": { "type": "string", "enum": [ @@ -3998,6 +6342,45 @@ const docTemplate = `{ "BatchStatusArchived" ] }, + "models.PigTransferType": { + "type": "string", + "enum": [ + "群内调栏", + "跨群调栏", + "销售", + "死亡", + "淘汰", + "新购入", + "产房转入" + ], + "x-enum-comments": { + "PigTransferTypeCrossBatch": "不同猪群间的调动", + "PigTransferTypeCull": "猪只淘汰", + "PigTransferTypeDeath": "猪只死亡", + "PigTransferTypeDeliveryRoomTransfor": "产房转入", + "PigTransferTypeInternal": "同一猪群内猪栏间的调动", + "PigTransferTypePurchase": "新购入猪只", + "PigTransferTypeSale": "猪只售出" + }, + "x-enum-descriptions": [ + "同一猪群内猪栏间的调动", + "不同猪群间的调动", + "猪只售出", + "猪只死亡", + "猪只淘汰", + "新购入猪只", + "产房转入" + ], + "x-enum-varnames": [ + "PigTransferTypeInternal", + "PigTransferTypeCrossBatch", + "PigTransferTypeSale", + "PigTransferTypeDeath", + "PigTransferTypeCull", + "PigTransferTypePurchase", + "PigTransferTypeDeliveryRoomTransfor" + ] + }, "models.PlanContentType": { "type": "string", "enum": [ @@ -4094,6 +6477,25 @@ const docTemplate = `{ "SensorTypeWeight" ] }, + "models.StockLogSourceType": { + "type": "string", + "enum": [ + "采购入库", + "饲喂出库", + "变质出库", + "售卖出库", + "杂用领取", + "手动盘点" + ], + "x-enum-varnames": [ + "StockLogSourcePurchase", + "StockLogSourceFeeding", + "StockLogSourceDeteriorate", + "StockLogSourceSale", + "StockLogSourceMiscellaneous", + "StockLogSourceManual" + ] + }, "models.TaskType": { "type": "string", "enum": [ diff --git a/docs/swagger.json b/docs/swagger.json index 68ed315..f6cca86 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -730,6 +730,1344 @@ } } }, + "/api/v1/monitor/device-command-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取设备命令日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取设备命令日志列表", + "parameters": [ + { + "type": "integer", + "name": "device_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "boolean", + "name": "received_success", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListDeviceCommandLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/feed-usage-records": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取饲料使用记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取饲料使用记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "feed_formula_id", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListFeedUsageRecordResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/medication-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取用药记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取用药记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "medication_id", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "reason", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListMedicationLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pending-collections": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取待采集请求", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取待采集请求列表", + "parameters": [ + { + "type": "integer", + "name": "device_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPendingCollectionResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-batch-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪批次日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪批次日志列表", + "parameters": [ + { + "type": "string", + "name": "change_type", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigBatchLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-purchases": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪只采购记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪只采购记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "supplier", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigPurchaseResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-sales": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪只售卖记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪只售卖记录列表", + "parameters": [ + { + "type": "string", + "name": "buyer", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigSaleResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-sick-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取病猪日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取病猪日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "reason", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "treatment_location", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigSickLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/pig-transfer-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取猪只迁移日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取猪只迁移日志列表", + "parameters": [ + { + "type": "string", + "name": "correlation_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "transfer_type", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPigTransferLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/plan-execution-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取计划执行日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取计划执行日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "plan_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListPlanExecutionLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/raw-material-purchases": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取原料采购记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取原料采购记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "raw_material_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "supplier", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListRawMaterialPurchaseResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/raw-material-stock-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取原料库存日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取原料库存日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "raw_material_id", + "in": "query" + }, + { + "type": "integer", + "name": "source_id", + "in": "query" + }, + { + "type": "string", + "name": "source_type", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListRawMaterialStockLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/sensor-data": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取传感器数据", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取传感器数据列表", + "parameters": [ + { + "type": "integer", + "name": "device_id", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "sensor_type", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListSensorDataResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/task-execution-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取任务执行日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取任务执行日志列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "plan_execution_log_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "name": "task_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListTaskExecutionLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/user-action-logs": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取用户操作日志", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取用户操作日志列表", + "parameters": [ + { + "type": "string", + "name": "action_type", + "in": "query" + }, + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "string", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "name": "user_id", + "in": "query" + }, + { + "type": "string", + "name": "username", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListUserActionLogResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/weighing-batches": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取批次称重记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取批次称重记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pig_batch_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListWeighingBatchResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/monitor/weighing-records": { + "get": { + "security": [ + { + "BearerAuth": [] + } + ], + "description": "根据提供的过滤条件,分页获取单次称重记录", + "produces": [ + "application/json" + ], + "tags": [ + "数据监控" + ], + "summary": "获取单次称重记录列表", + "parameters": [ + { + "type": "string", + "name": "end_time", + "in": "query" + }, + { + "type": "integer", + "name": "operator_id", + "in": "query" + }, + { + "type": "string", + "name": "order_by", + "in": "query" + }, + { + "type": "integer", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "name": "pen_id", + "in": "query" + }, + { + "type": "string", + "name": "start_time", + "in": "query" + }, + { + "type": "integer", + "name": "weighing_batch_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/dto.ListWeighingRecordResponse" + } + } + } + ] + } + } + } + } + }, "/api/v1/pens": { "get": { "security": [ @@ -2883,6 +4221,26 @@ } } }, + "dto.DeviceCommandLogDTO": { + "type": "object", + "properties": { + "acknowledged_at": { + "type": "string" + }, + "device_id": { + "type": "integer" + }, + "message_id": { + "type": "string" + }, + "received_success": { + "type": "boolean" + }, + "sent_at": { + "type": "string" + } + } + }, "dto.DeviceResponse": { "type": "object", "properties": { @@ -2955,6 +4313,49 @@ } } }, + "dto.FeedFormulaDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.FeedUsageRecordDTO": { + "type": "object", + "properties": { + "amount": { + "type": "number" + }, + "feed_formula": { + "$ref": "#/definitions/dto.FeedFormulaDTO" + }, + "feed_formula_id": { + "type": "integer" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen": { + "$ref": "#/definitions/dto.PenDTO" + }, + "pen_id": { + "type": "integer" + }, + "recorded_at": { + "type": "string" + }, + "remarks": { + "type": "string" + } + } + }, "dto.HistoryResponse": { "type": "object", "properties": { @@ -2980,6 +4381,34 @@ } } }, + "dto.ListDeviceCommandLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.DeviceCommandLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListFeedUsageRecordResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.FeedUsageRecordDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, "dto.ListHistoryResponse": { "type": "object", "properties": { @@ -2995,6 +4424,216 @@ } } }, + "dto.ListMedicationLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.MedicationLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPendingCollectionResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PendingCollectionDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigBatchLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigBatchLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigPurchaseResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigPurchaseDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigSaleResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigSaleDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigSickLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigSickLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPigTransferLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PigTransferLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListPlanExecutionLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.PlanExecutionLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListRawMaterialPurchaseResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.RawMaterialPurchaseDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListRawMaterialStockLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.RawMaterialStockLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListSensorDataResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.SensorDataDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListTaskExecutionLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.TaskExecutionLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListUserActionLogResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.UserActionLogDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListWeighingBatchResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.WeighingBatchDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, + "dto.ListWeighingRecordResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/dto.WeighingRecordDTO" + } + }, + "pagination": { + "$ref": "#/definitions/dto.PaginationDTO" + } + } + }, "dto.LoginRequest": { "type": "object", "required": [ @@ -3039,6 +4678,52 @@ } } }, + "dto.MedicationDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.MedicationLogDTO": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "dosage_used": { + "type": "number" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "medication": { + "$ref": "#/definitions/dto.MedicationDTO" + }, + "medication_id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "reason": { + "$ref": "#/definitions/models.MedicationReasonType" + }, + "target_count": { + "type": "integer" + } + } + }, "dto.MovePigsIntoPenRequest": { "type": "object", "required": [ @@ -3061,6 +4746,31 @@ } } }, + "dto.PaginationDTO": { + "type": "object", + "properties": { + "page": { + "type": "integer" + }, + "pageSize": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, + "dto.PenDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "dto.PenResponse": { "type": "object", "properties": { @@ -3084,6 +4794,32 @@ } } }, + "dto.PendingCollectionDTO": { + "type": "object", + "properties": { + "command_metadata": { + "type": "array", + "items": { + "type": "integer" + } + }, + "correlation_id": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "device_id": { + "type": "integer" + }, + "fulfilled_at": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.PendingCollectionStatus" + } + } + }, "dto.PigBatchCreateDTO": { "type": "object", "required": [ @@ -3125,6 +4861,44 @@ } } }, + "dto.PigBatchLogDTO": { + "type": "object", + "properties": { + "after_count": { + "type": "integer" + }, + "before_count": { + "type": "integer" + }, + "change_count": { + "type": "integer" + }, + "change_type": { + "$ref": "#/definitions/models.LogChangeType" + }, + "created_at": { + "type": "string" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "reason": { + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "dto.PigBatchResponseDTO": { "type": "object", "properties": { @@ -3229,6 +5003,193 @@ } } }, + "dto.PigPurchaseDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "purchase_date": { + "type": "string" + }, + "quantity": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "supplier": { + "type": "string" + }, + "total_price": { + "type": "number" + }, + "unit_price": { + "type": "number" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PigSaleDTO": { + "type": "object", + "properties": { + "buyer": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "quantity": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "sale_date": { + "type": "string" + }, + "total_price": { + "type": "number" + }, + "unit_price": { + "type": "number" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PigSickLogDTO": { + "type": "object", + "properties": { + "after_count": { + "type": "integer" + }, + "before_count": { + "type": "integer" + }, + "change_count": { + "type": "integer" + }, + "created_at": { + "type": "string" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "reason": { + "$ref": "#/definitions/models.PigBatchSickPigReasonType" + }, + "remarks": { + "type": "string" + }, + "treatment_location": { + "$ref": "#/definitions/models.PigBatchSickPigTreatmentLocation" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PigTransferLogDTO": { + "type": "object", + "properties": { + "correlation_id": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen_id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "quantity": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "transfer_time": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/models.PigTransferType" + }, + "updated_at": { + "type": "string" + } + } + }, + "dto.PlanExecutionLogDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "ended_at": { + "type": "string" + }, + "error": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "plan_id": { + "type": "integer" + }, + "started_at": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.ExecutionStatus" + }, + "updated_at": { + "type": "string" + } + } + }, "dto.PlanResponse": { "type": "object", "properties": { @@ -3294,6 +5255,75 @@ } } }, + "dto.RawMaterialDTO": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.RawMaterialPurchaseDTO": { + "type": "object", + "properties": { + "amount": { + "type": "number" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "purchase_date": { + "type": "string" + }, + "raw_material": { + "$ref": "#/definitions/dto.RawMaterialDTO" + }, + "raw_material_id": { + "type": "integer" + }, + "supplier": { + "type": "string" + }, + "total_price": { + "type": "number" + }, + "unit_price": { + "type": "number" + } + } + }, + "dto.RawMaterialStockLogDTO": { + "type": "object", + "properties": { + "change_amount": { + "type": "number" + }, + "happened_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "raw_material_id": { + "type": "integer" + }, + "remarks": { + "type": "string" + }, + "source_id": { + "type": "integer" + }, + "source_type": { + "$ref": "#/definitions/models.StockLogSourceType" + } + } + }, "dto.ReclassifyPenToNewBatchRequest": { "type": "object", "required": [ @@ -3557,6 +5587,29 @@ } } }, + "dto.SensorDataDTO": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "integer" + } + }, + "device_id": { + "type": "integer" + }, + "regional_controller_id": { + "type": "integer" + }, + "sensor_type": { + "$ref": "#/definitions/models.SensorType" + }, + "time": { + "type": "string" + } + } + }, "dto.SubPlanResponse": { "type": "object", "properties": { @@ -3581,6 +5634,60 @@ } } }, + "dto.TaskDTO": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "dto.TaskExecutionLogDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "ended_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "output": { + "type": "string" + }, + "plan_execution_log_id": { + "type": "integer" + }, + "started_at": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.ExecutionStatus" + }, + "task": { + "description": "嵌套的任务信息", + "allOf": [ + { + "$ref": "#/definitions/dto.TaskDTO" + } + ] + }, + "task_id": { + "type": "integer" + }, + "updated_at": { + "type": "string" + } + } + }, "dto.TaskRequest": { "type": "object", "properties": { @@ -3904,6 +6011,116 @@ } } }, + "dto.UserActionLogDTO": { + "type": "object", + "properties": { + "action_type": { + "type": "string" + }, + "description": { + "type": "string" + }, + "http_method": { + "type": "string" + }, + "http_path": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "result_details": { + "type": "string" + }, + "source_ip": { + "type": "string" + }, + "status": { + "$ref": "#/definitions/models.AuditStatus" + }, + "target_resource": { + "type": "array", + "items": { + "type": "integer" + } + }, + "time": { + "type": "string" + }, + "user_id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }, + "dto.WeighingBatchDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "pig_batch_id": { + "type": "integer" + }, + "updated_at": { + "type": "string" + }, + "weighing_time": { + "type": "string" + } + } + }, + "dto.WeighingRecordDTO": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "operator_id": { + "type": "integer" + }, + "pen_id": { + "type": "integer" + }, + "remark": { + "type": "string" + }, + "updated_at": { + "type": "string" + }, + "weighing_batch_id": { + "type": "integer" + }, + "weighing_time": { + "type": "string" + }, + "weight": { + "type": "number" + } + } + }, + "models.AuditStatus": { + "type": "string", + "enum": [ + "成功", + "失败" + ], + "x-enum-varnames": [ + "AuditStatusSuccess", + "AuditStatusFailed" + ] + }, "models.DeviceCategory": { "type": "string", "enum": [ @@ -3915,6 +6132,71 @@ "CategorySensor" ] }, + "models.ExecutionStatus": { + "type": "string", + "enum": [ + "已开始", + "已完成", + "失败", + "已取消", + "等待中" + ], + "x-enum-comments": { + "ExecutionStatusCancelled": "执行取消", + "ExecutionStatusCompleted": "执行完成", + "ExecutionStatusFailed": "执行失败", + "ExecutionStatusStarted": "开始执行", + "ExecutionStatusWaiting": "等待执行 (用于预写日志)" + }, + "x-enum-descriptions": [ + "开始执行", + "执行完成", + "执行失败", + "执行取消", + "等待执行 (用于预写日志)" + ], + "x-enum-varnames": [ + "ExecutionStatusStarted", + "ExecutionStatusCompleted", + "ExecutionStatusFailed", + "ExecutionStatusCancelled", + "ExecutionStatusWaiting" + ] + }, + "models.LogChangeType": { + "type": "string", + "enum": [ + "死亡", + "淘汰", + "销售", + "购买", + "转入", + "转出", + "盘点校正" + ], + "x-enum-varnames": [ + "ChangeTypeDeath", + "ChangeTypeCull", + "ChangeTypeSale", + "ChangeTypeBuy", + "ChangeTypeTransferIn", + "ChangeTypeTransferOut", + "ChangeTypeCorrection" + ] + }, + "models.MedicationReasonType": { + "type": "string", + "enum": [ + "预防", + "治疗", + "保健" + ], + "x-enum-varnames": [ + "ReasonTypePreventive", + "ReasonTypeTreatment", + "ReasonTypeHealthCare" + ] + }, "models.PenStatus": { "type": "string", "enum": [ @@ -3934,6 +6216,29 @@ "PenStatusUnderMaint" ] }, + "models.PendingCollectionStatus": { + "type": "string", + "enum": [ + "等待中", + "已完成", + "已超时" + ], + "x-enum-comments": { + "PendingStatusFulfilled": "已收到设备响应并成功处理", + "PendingStatusPending": "请求已发送,等待设备响应", + "PendingStatusTimedOut": "请求超时,未收到设备响应" + }, + "x-enum-descriptions": [ + "请求已发送,等待设备响应", + "已收到设备响应并成功处理", + "请求超时,未收到设备响应" + ], + "x-enum-varnames": [ + "PendingStatusPending", + "PendingStatusFulfilled", + "PendingStatusTimedOut" + ] + }, "models.PigBatchOriginType": { "type": "string", "enum": [ @@ -3945,6 +6250,45 @@ "OriginTypePurchased" ] }, + "models.PigBatchSickPigReasonType": { + "type": "string", + "enum": [ + "患病", + "康复", + "死亡", + "淘汰", + "转入", + "转出", + "其他" + ], + "x-enum-comments": { + "SickPigReasonTypeDeath": "猪只死亡", + "SickPigReasonTypeEliminate": "猪只淘汰", + "SickPigReasonTypeIllness": "猪只患病", + "SickPigReasonTypeOther": "其他原因", + "SickPigReasonTypeRecovery": "猪只康复", + "SickPigReasonTypeTransferIn": "病猪转入当前批次", + "SickPigReasonTypeTransferOut": "病猪转出当前批次 (例如转到其他批次或出售)" + }, + "x-enum-descriptions": [ + "猪只患病", + "猪只康复", + "猪只死亡", + "猪只淘汰", + "病猪转入当前批次", + "病猪转出当前批次 (例如转到其他批次或出售)", + "其他原因" + ], + "x-enum-varnames": [ + "SickPigReasonTypeIllness", + "SickPigReasonTypeRecovery", + "SickPigReasonTypeDeath", + "SickPigReasonTypeEliminate", + "SickPigReasonTypeTransferIn", + "SickPigReasonTypeTransferOut", + "SickPigReasonTypeOther" + ] + }, "models.PigBatchSickPigTreatmentLocation": { "type": "string", "enum": [ @@ -3990,6 +6334,45 @@ "BatchStatusArchived" ] }, + "models.PigTransferType": { + "type": "string", + "enum": [ + "群内调栏", + "跨群调栏", + "销售", + "死亡", + "淘汰", + "新购入", + "产房转入" + ], + "x-enum-comments": { + "PigTransferTypeCrossBatch": "不同猪群间的调动", + "PigTransferTypeCull": "猪只淘汰", + "PigTransferTypeDeath": "猪只死亡", + "PigTransferTypeDeliveryRoomTransfor": "产房转入", + "PigTransferTypeInternal": "同一猪群内猪栏间的调动", + "PigTransferTypePurchase": "新购入猪只", + "PigTransferTypeSale": "猪只售出" + }, + "x-enum-descriptions": [ + "同一猪群内猪栏间的调动", + "不同猪群间的调动", + "猪只售出", + "猪只死亡", + "猪只淘汰", + "新购入猪只", + "产房转入" + ], + "x-enum-varnames": [ + "PigTransferTypeInternal", + "PigTransferTypeCrossBatch", + "PigTransferTypeSale", + "PigTransferTypeDeath", + "PigTransferTypeCull", + "PigTransferTypePurchase", + "PigTransferTypeDeliveryRoomTransfor" + ] + }, "models.PlanContentType": { "type": "string", "enum": [ @@ -4086,6 +6469,25 @@ "SensorTypeWeight" ] }, + "models.StockLogSourceType": { + "type": "string", + "enum": [ + "采购入库", + "饲喂出库", + "变质出库", + "售卖出库", + "杂用领取", + "手动盘点" + ], + "x-enum-varnames": [ + "StockLogSourcePurchase", + "StockLogSourceFeeding", + "StockLogSourceDeteriorate", + "StockLogSourceSale", + "StockLogSourceMiscellaneous", + "StockLogSourceManual" + ] + }, "models.TaskType": { "type": "string", "enum": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6a7280e..8f68862 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -233,6 +233,19 @@ definitions: example: newuser type: string type: object + dto.DeviceCommandLogDTO: + properties: + acknowledged_at: + type: string + device_id: + type: integer + message_id: + type: string + received_success: + type: boolean + sent_at: + type: string + type: object dto.DeviceResponse: properties: area_controller_id: @@ -281,6 +294,34 @@ definitions: $ref: '#/definitions/models.ValueDescriptor' type: array type: object + dto.FeedFormulaDTO: + properties: + id: + type: integer + name: + type: string + type: object + dto.FeedUsageRecordDTO: + properties: + amount: + type: number + feed_formula: + $ref: '#/definitions/dto.FeedFormulaDTO' + feed_formula_id: + type: integer + id: + type: integer + operator_id: + type: integer + pen: + $ref: '#/definitions/dto.PenDTO' + pen_id: + type: integer + recorded_at: + type: string + remarks: + type: string + type: object dto.HistoryResponse: properties: action_type: @@ -299,6 +340,24 @@ definitions: example: testuser type: string type: object + dto.ListDeviceCommandLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.DeviceCommandLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListFeedUsageRecordResponse: + properties: + list: + items: + $ref: '#/definitions/dto.FeedUsageRecordDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object dto.ListHistoryResponse: properties: history: @@ -309,6 +368,141 @@ definitions: example: 100 type: integer type: object + dto.ListMedicationLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.MedicationLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPendingCollectionResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PendingCollectionDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPigBatchLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PigBatchLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPigPurchaseResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PigPurchaseDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPigSaleResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PigSaleDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPigSickLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PigSickLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPigTransferLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PigTransferLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListPlanExecutionLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.PlanExecutionLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListRawMaterialPurchaseResponse: + properties: + list: + items: + $ref: '#/definitions/dto.RawMaterialPurchaseDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListRawMaterialStockLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.RawMaterialStockLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListSensorDataResponse: + properties: + list: + items: + $ref: '#/definitions/dto.SensorDataDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListTaskExecutionLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.TaskExecutionLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListUserActionLogResponse: + properties: + list: + items: + $ref: '#/definitions/dto.UserActionLogDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListWeighingBatchResponse: + properties: + list: + items: + $ref: '#/definitions/dto.WeighingBatchDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object + dto.ListWeighingRecordResponse: + properties: + list: + items: + $ref: '#/definitions/dto.WeighingRecordDTO' + type: array + pagination: + $ref: '#/definitions/dto.PaginationDTO' + type: object dto.LoginRequest: properties: identifier: @@ -340,6 +534,36 @@ definitions: description: Action 不传表示这是一个传感器, 会触发一次采集 type: string type: object + dto.MedicationDTO: + properties: + id: + type: integer + name: + type: string + type: object + dto.MedicationLogDTO: + properties: + description: + type: string + dosage_used: + type: number + happened_at: + type: string + id: + type: integer + medication: + $ref: '#/definitions/dto.MedicationDTO' + medication_id: + type: integer + operator_id: + type: integer + pig_batch_id: + type: integer + reason: + $ref: '#/definitions/models.MedicationReasonType' + target_count: + type: integer + type: object dto.MovePigsIntoPenRequest: properties: quantity: @@ -356,6 +580,22 @@ definitions: - quantity - toPenID type: object + dto.PaginationDTO: + properties: + page: + type: integer + pageSize: + type: integer + total: + type: integer + type: object + dto.PenDTO: + properties: + id: + type: integer + name: + type: string + type: object dto.PenResponse: properties: capacity: @@ -371,6 +611,23 @@ definitions: status: $ref: '#/definitions/models.PenStatus' type: object + dto.PendingCollectionDTO: + properties: + command_metadata: + items: + type: integer + type: array + correlation_id: + type: string + created_at: + type: string + device_id: + type: integer + fulfilled_at: + type: string + status: + $ref: '#/definitions/models.PendingCollectionStatus' + type: object dto.PigBatchCreateDTO: properties: batch_number: @@ -398,6 +655,31 @@ definitions: - start_date - status type: object + dto.PigBatchLogDTO: + properties: + after_count: + type: integer + before_count: + type: integer + change_count: + type: integer + change_type: + $ref: '#/definitions/models.LogChangeType' + created_at: + type: string + happened_at: + type: string + id: + type: integer + operator_id: + type: integer + pig_batch_id: + type: integer + reason: + type: string + updated_at: + type: string + type: object dto.PigBatchResponseDTO: properties: batch_number: @@ -465,6 +747,129 @@ definitions: name: type: string type: object + dto.PigPurchaseDTO: + properties: + created_at: + type: string + id: + type: integer + operator_id: + type: integer + pig_batch_id: + type: integer + purchase_date: + type: string + quantity: + type: integer + remarks: + type: string + supplier: + type: string + total_price: + type: number + unit_price: + type: number + updated_at: + type: string + type: object + dto.PigSaleDTO: + properties: + buyer: + type: string + created_at: + type: string + id: + type: integer + operator_id: + type: integer + pig_batch_id: + type: integer + quantity: + type: integer + remarks: + type: string + sale_date: + type: string + total_price: + type: number + unit_price: + type: number + updated_at: + type: string + type: object + dto.PigSickLogDTO: + properties: + after_count: + type: integer + before_count: + type: integer + change_count: + type: integer + created_at: + type: string + happened_at: + type: string + id: + type: integer + operator_id: + type: integer + pen_id: + type: integer + pig_batch_id: + type: integer + reason: + $ref: '#/definitions/models.PigBatchSickPigReasonType' + remarks: + type: string + treatment_location: + $ref: '#/definitions/models.PigBatchSickPigTreatmentLocation' + updated_at: + type: string + type: object + dto.PigTransferLogDTO: + properties: + correlation_id: + type: string + created_at: + type: string + id: + type: integer + operator_id: + type: integer + pen_id: + type: integer + pig_batch_id: + type: integer + quantity: + type: integer + remarks: + type: string + transfer_time: + type: string + type: + $ref: '#/definitions/models.PigTransferType' + updated_at: + type: string + type: object + dto.PlanExecutionLogDTO: + properties: + created_at: + type: string + ended_at: + type: string + error: + type: string + id: + type: integer + plan_id: + type: integer + started_at: + type: string + status: + $ref: '#/definitions/models.ExecutionStatus' + updated_at: + type: string + type: object dto.PlanResponse: properties: content_type: @@ -506,6 +911,51 @@ definitions: $ref: '#/definitions/dto.TaskResponse' type: array type: object + dto.RawMaterialDTO: + properties: + id: + type: integer + name: + type: string + type: object + dto.RawMaterialPurchaseDTO: + properties: + amount: + type: number + created_at: + type: string + id: + type: integer + purchase_date: + type: string + raw_material: + $ref: '#/definitions/dto.RawMaterialDTO' + raw_material_id: + type: integer + supplier: + type: string + total_price: + type: number + unit_price: + type: number + type: object + dto.RawMaterialStockLogDTO: + properties: + change_amount: + type: number + happened_at: + type: string + id: + type: integer + raw_material_id: + type: integer + remarks: + type: string + source_id: + type: integer + source_type: + $ref: '#/definitions/models.StockLogSourceType' + type: object dto.ReclassifyPenToNewBatchRequest: properties: penID: @@ -695,6 +1145,21 @@ definitions: - traderName - unitPrice type: object + dto.SensorDataDTO: + properties: + data: + items: + type: integer + type: array + device_id: + type: integer + regional_controller_id: + type: integer + sensor_type: + $ref: '#/definitions/models.SensorType' + time: + type: string + type: object dto.SubPlanResponse: properties: child_plan: @@ -712,6 +1177,40 @@ definitions: example: 1 type: integer type: object + dto.TaskDTO: + properties: + description: + type: string + id: + type: integer + name: + type: string + type: object + dto.TaskExecutionLogDTO: + properties: + created_at: + type: string + ended_at: + type: string + id: + type: integer + output: + type: string + plan_execution_log_id: + type: integer + started_at: + type: string + status: + $ref: '#/definitions/models.ExecutionStatus' + task: + allOf: + - $ref: '#/definitions/dto.TaskDTO' + description: 嵌套的任务信息 + task_id: + type: integer + updated_at: + type: string + type: object dto.TaskRequest: properties: description: @@ -934,6 +1433,79 @@ definitions: required: - execution_type type: object + dto.UserActionLogDTO: + properties: + action_type: + type: string + description: + type: string + http_method: + type: string + http_path: + type: string + id: + type: integer + result_details: + type: string + source_ip: + type: string + status: + $ref: '#/definitions/models.AuditStatus' + target_resource: + items: + type: integer + type: array + time: + type: string + user_id: + type: integer + username: + type: string + type: object + dto.WeighingBatchDTO: + properties: + created_at: + type: string + description: + type: string + id: + type: integer + pig_batch_id: + type: integer + updated_at: + type: string + weighing_time: + type: string + type: object + dto.WeighingRecordDTO: + properties: + created_at: + type: string + id: + type: integer + operator_id: + type: integer + pen_id: + type: integer + remark: + type: string + updated_at: + type: string + weighing_batch_id: + type: integer + weighing_time: + type: string + weight: + type: number + type: object + models.AuditStatus: + enum: + - 成功 + - 失败 + type: string + x-enum-varnames: + - AuditStatusSuccess + - AuditStatusFailed models.DeviceCategory: enum: - 执行器 @@ -942,6 +1514,60 @@ definitions: x-enum-varnames: - CategoryActuator - CategorySensor + models.ExecutionStatus: + enum: + - 已开始 + - 已完成 + - 失败 + - 已取消 + - 等待中 + type: string + x-enum-comments: + ExecutionStatusCancelled: 执行取消 + ExecutionStatusCompleted: 执行完成 + ExecutionStatusFailed: 执行失败 + ExecutionStatusStarted: 开始执行 + ExecutionStatusWaiting: 等待执行 (用于预写日志) + x-enum-descriptions: + - 开始执行 + - 执行完成 + - 执行失败 + - 执行取消 + - 等待执行 (用于预写日志) + x-enum-varnames: + - ExecutionStatusStarted + - ExecutionStatusCompleted + - ExecutionStatusFailed + - ExecutionStatusCancelled + - ExecutionStatusWaiting + models.LogChangeType: + enum: + - 死亡 + - 淘汰 + - 销售 + - 购买 + - 转入 + - 转出 + - 盘点校正 + type: string + x-enum-varnames: + - ChangeTypeDeath + - ChangeTypeCull + - ChangeTypeSale + - ChangeTypeBuy + - ChangeTypeTransferIn + - ChangeTypeTransferOut + - ChangeTypeCorrection + models.MedicationReasonType: + enum: + - 预防 + - 治疗 + - 保健 + type: string + x-enum-varnames: + - ReasonTypePreventive + - ReasonTypeTreatment + - ReasonTypeHealthCare models.PenStatus: enum: - 空闲 @@ -958,6 +1584,24 @@ definitions: - PenStatusRecovering - PenStatusCleaning - PenStatusUnderMaint + models.PendingCollectionStatus: + enum: + - 等待中 + - 已完成 + - 已超时 + type: string + x-enum-comments: + PendingStatusFulfilled: 已收到设备响应并成功处理 + PendingStatusPending: 请求已发送,等待设备响应 + PendingStatusTimedOut: 请求超时,未收到设备响应 + x-enum-descriptions: + - 请求已发送,等待设备响应 + - 已收到设备响应并成功处理 + - 请求超时,未收到设备响应 + x-enum-varnames: + - PendingStatusPending + - PendingStatusFulfilled + - PendingStatusTimedOut models.PigBatchOriginType: enum: - 自繁 @@ -966,6 +1610,40 @@ definitions: x-enum-varnames: - OriginTypeSelfFarrowed - OriginTypePurchased + models.PigBatchSickPigReasonType: + enum: + - 患病 + - 康复 + - 死亡 + - 淘汰 + - 转入 + - 转出 + - 其他 + type: string + x-enum-comments: + SickPigReasonTypeDeath: 猪只死亡 + SickPigReasonTypeEliminate: 猪只淘汰 + SickPigReasonTypeIllness: 猪只患病 + SickPigReasonTypeOther: 其他原因 + SickPigReasonTypeRecovery: 猪只康复 + SickPigReasonTypeTransferIn: 病猪转入当前批次 + SickPigReasonTypeTransferOut: 病猪转出当前批次 (例如转到其他批次或出售) + x-enum-descriptions: + - 猪只患病 + - 猪只康复 + - 猪只死亡 + - 猪只淘汰 + - 病猪转入当前批次 + - 病猪转出当前批次 (例如转到其他批次或出售) + - 其他原因 + x-enum-varnames: + - SickPigReasonTypeIllness + - SickPigReasonTypeRecovery + - SickPigReasonTypeDeath + - SickPigReasonTypeEliminate + - SickPigReasonTypeTransferIn + - SickPigReasonTypeTransferOut + - SickPigReasonTypeOther models.PigBatchSickPigTreatmentLocation: enum: - 原地治疗 @@ -1003,6 +1681,40 @@ definitions: - BatchStatusForSale - BatchStatusSold - BatchStatusArchived + models.PigTransferType: + enum: + - 群内调栏 + - 跨群调栏 + - 销售 + - 死亡 + - 淘汰 + - 新购入 + - 产房转入 + type: string + x-enum-comments: + PigTransferTypeCrossBatch: 不同猪群间的调动 + PigTransferTypeCull: 猪只淘汰 + PigTransferTypeDeath: 猪只死亡 + PigTransferTypeDeliveryRoomTransfor: 产房转入 + PigTransferTypeInternal: 同一猪群内猪栏间的调动 + PigTransferTypePurchase: 新购入猪只 + PigTransferTypeSale: 猪只售出 + x-enum-descriptions: + - 同一猪群内猪栏间的调动 + - 不同猪群间的调动 + - 猪只售出 + - 猪只死亡 + - 猪只淘汰 + - 新购入猪只 + - 产房转入 + x-enum-varnames: + - PigTransferTypeInternal + - PigTransferTypeCrossBatch + - PigTransferTypeSale + - PigTransferTypeDeath + - PigTransferTypeCull + - PigTransferTypePurchase + - PigTransferTypeDeliveryRoomTransfor models.PlanContentType: enum: - 子计划 @@ -1079,6 +1791,22 @@ definitions: - SensorTypeTemperature - SensorTypeHumidity - SensorTypeWeight + models.StockLogSourceType: + enum: + - 采购入库 + - 饲喂出库 + - 变质出库 + - 售卖出库 + - 杂用领取 + - 手动盘点 + type: string + x-enum-varnames: + - StockLogSourcePurchase + - StockLogSourceFeeding + - StockLogSourceDeteriorate + - StockLogSourceSale + - StockLogSourceMiscellaneous + - StockLogSourceManual models.TaskType: enum: - 计划分析 @@ -1536,6 +2264,768 @@ paths: summary: 手动控制设备 tags: - 设备管理 + /api/v1/monitor/device-command-logs: + get: + description: 根据提供的过滤条件,分页获取设备命令日志 + parameters: + - in: query + name: device_id + type: integer + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: received_success + type: boolean + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListDeviceCommandLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取设备命令日志列表 + tags: + - 数据监控 + /api/v1/monitor/feed-usage-records: + get: + description: 根据提供的过滤条件,分页获取饲料使用记录 + parameters: + - in: query + name: end_time + type: string + - in: query + name: feed_formula_id + type: integer + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pen_id + type: integer + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListFeedUsageRecordResponse' + type: object + security: + - BearerAuth: [] + summary: 获取饲料使用记录列表 + tags: + - 数据监控 + /api/v1/monitor/medication-logs: + get: + description: 根据提供的过滤条件,分页获取用药记录 + parameters: + - in: query + name: end_time + type: string + - in: query + name: medication_id + type: integer + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: reason + type: string + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListMedicationLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取用药记录列表 + tags: + - 数据监控 + /api/v1/monitor/pending-collections: + get: + description: 根据提供的过滤条件,分页获取待采集请求 + parameters: + - in: query + name: device_id + type: integer + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: start_time + type: string + - in: query + name: status + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPendingCollectionResponse' + type: object + security: + - BearerAuth: [] + summary: 获取待采集请求列表 + tags: + - 数据监控 + /api/v1/monitor/pig-batch-logs: + get: + description: 根据提供的过滤条件,分页获取猪批次日志 + parameters: + - in: query + name: change_type + type: string + - in: query + name: end_time + type: string + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPigBatchLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取猪批次日志列表 + tags: + - 数据监控 + /api/v1/monitor/pig-purchases: + get: + description: 根据提供的过滤条件,分页获取猪只采购记录 + parameters: + - in: query + name: end_time + type: string + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: start_time + type: string + - in: query + name: supplier + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPigPurchaseResponse' + type: object + security: + - BearerAuth: [] + summary: 获取猪只采购记录列表 + tags: + - 数据监控 + /api/v1/monitor/pig-sales: + get: + description: 根据提供的过滤条件,分页获取猪只售卖记录 + parameters: + - in: query + name: buyer + type: string + - in: query + name: end_time + type: string + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPigSaleResponse' + type: object + security: + - BearerAuth: [] + summary: 获取猪只售卖记录列表 + tags: + - 数据监控 + /api/v1/monitor/pig-sick-logs: + get: + description: 根据提供的过滤条件,分页获取病猪日志 + parameters: + - in: query + name: end_time + type: string + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pen_id + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: reason + type: string + - in: query + name: start_time + type: string + - in: query + name: treatment_location + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPigSickLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取病猪日志列表 + tags: + - 数据监控 + /api/v1/monitor/pig-transfer-logs: + get: + description: 根据提供的过滤条件,分页获取猪只迁移日志 + parameters: + - in: query + name: correlation_id + type: string + - in: query + name: end_time + type: string + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pen_id + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: start_time + type: string + - in: query + name: transfer_type + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPigTransferLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取猪只迁移日志列表 + tags: + - 数据监控 + /api/v1/monitor/plan-execution-logs: + get: + description: 根据提供的过滤条件,分页获取计划执行日志 + parameters: + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: plan_id + type: integer + - in: query + name: start_time + type: string + - in: query + name: status + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListPlanExecutionLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取计划执行日志列表 + tags: + - 数据监控 + /api/v1/monitor/raw-material-purchases: + get: + description: 根据提供的过滤条件,分页获取原料采购记录 + parameters: + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: raw_material_id + type: integer + - in: query + name: start_time + type: string + - in: query + name: supplier + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListRawMaterialPurchaseResponse' + type: object + security: + - BearerAuth: [] + summary: 获取原料采购记录列表 + tags: + - 数据监控 + /api/v1/monitor/raw-material-stock-logs: + get: + description: 根据提供的过滤条件,分页获取原料库存日志 + parameters: + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: raw_material_id + type: integer + - in: query + name: source_id + type: integer + - in: query + name: source_type + type: string + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListRawMaterialStockLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取原料库存日志列表 + tags: + - 数据监控 + /api/v1/monitor/sensor-data: + get: + description: 根据提供的过滤条件,分页获取传感器数据 + parameters: + - in: query + name: device_id + type: integer + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: sensor_type + type: string + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListSensorDataResponse' + type: object + security: + - BearerAuth: [] + summary: 获取传感器数据列表 + tags: + - 数据监控 + /api/v1/monitor/task-execution-logs: + get: + description: 根据提供的过滤条件,分页获取任务执行日志 + parameters: + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: plan_execution_log_id + type: integer + - in: query + name: start_time + type: string + - in: query + name: status + type: string + - in: query + name: task_id + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListTaskExecutionLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取任务执行日志列表 + tags: + - 数据监控 + /api/v1/monitor/user-action-logs: + get: + description: 根据提供的过滤条件,分页获取用户操作日志 + parameters: + - in: query + name: action_type + type: string + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: start_time + type: string + - in: query + name: status + type: string + - in: query + name: user_id + type: integer + - in: query + name: username + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListUserActionLogResponse' + type: object + security: + - BearerAuth: [] + summary: 获取用户操作日志列表 + tags: + - 数据监控 + /api/v1/monitor/weighing-batches: + get: + description: 根据提供的过滤条件,分页获取批次称重记录 + parameters: + - in: query + name: end_time + type: string + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pig_batch_id + type: integer + - in: query + name: start_time + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListWeighingBatchResponse' + type: object + security: + - BearerAuth: [] + summary: 获取批次称重记录列表 + tags: + - 数据监控 + /api/v1/monitor/weighing-records: + get: + description: 根据提供的过滤条件,分页获取单次称重记录 + parameters: + - in: query + name: end_time + type: string + - in: query + name: operator_id + type: integer + - in: query + name: order_by + type: string + - in: query + name: page + type: integer + - in: query + name: pageSize + type: integer + - in: query + name: pen_id + type: integer + - in: query + name: start_time + type: string + - in: query + name: weighing_batch_id + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/controller.Response' + - properties: + data: + $ref: '#/definitions/dto.ListWeighingRecordResponse' + type: object + security: + - BearerAuth: [] + summary: 获取单次称重记录列表 + tags: + - 数据监控 /api/v1/pens: get: description: 获取所有猪栏的列表 diff --git a/internal/app/api/api.go b/internal/app/api/api.go index 3dc698f..c95f47a 100644 --- a/internal/app/api/api.go +++ b/internal/app/api/api.go @@ -16,15 +16,14 @@ import ( "context" "fmt" "net/http" - "net/http/pprof" "time" _ "git.huangwc.com/pig/pig-farm-controller/docs" // 引入 swag 生成的 docs "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/device" "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/management" + "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/monitor" "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/plan" "git.huangwc.com/pig/pig-farm-controller/internal/app/controller/user" - "git.huangwc.com/pig/pig-farm-controller/internal/app/middleware" "git.huangwc.com/pig/pig-farm-controller/internal/app/service" "git.huangwc.com/pig/pig-farm-controller/internal/app/webhook" "git.huangwc.com/pig/pig-farm-controller/internal/domain/audit" @@ -36,8 +35,6 @@ import ( "git.huangwc.com/pig/pig-farm-controller/internal/infra/repository" "github.com/gin-gonic/gin" - swaggerFiles "github.com/swaggo/files" - ginSwagger "github.com/swaggo/gin-swagger" ) // API 结构体定义了 HTTP 服务器及其依赖 @@ -54,6 +51,7 @@ type API struct { planController *plan.Controller // 计划控制器实例 pigFarmController *management.PigFarmController // 猪场管理控制器实例 pigBatchController *management.PigBatchController // 猪群控制器实例 + monitorController *monitor.Controller // 数据监控控制器实例 listenHandler webhook.ListenHandler // 设备上行事件监听器 analysisTaskManager *task.AnalysisPlanTaskManager // 计划触发器管理器实例 } @@ -69,6 +67,7 @@ func NewAPI(cfg config.ServerConfig, planRepository repository.PlanRepository, pigFarmService service.PigFarmService, pigBatchService service.PigBatchService, + monitorService service.MonitorService, userActionLogRepository repository.UserActionLogRepository, tokenService token.TokenService, auditService audit.Service, @@ -106,161 +105,14 @@ func NewAPI(cfg config.ServerConfig, pigFarmController: management.NewPigFarmController(logger, pigFarmService), // 在 NewAPI 中初始化猪群控制器 pigBatchController: management.NewPigBatchController(logger, pigBatchService), + // 在 NewAPI 中初始化数据监控控制器 + monitorController: monitor.NewController(monitorService, logger), } api.setupRoutes() // 设置所有路由 return api } -// setupRoutes 设置所有 API 路由 -// 在此方法中,使用已初始化的控制器实例将其路由注册到 Gin 引擎中。 -func (a *API) setupRoutes() { - - // --- Public Routes --- - // 这些路由不需要身份验证 - - // 用户注册和登录 - a.engine.POST("/api/v1/users", a.userController.CreateUser) // 注册新用户 - a.engine.POST("/api/v1/users/login", a.userController.Login) // 用户登录 - a.logger.Info("公开接口注册成功:用户注册、登录") - - // 注册 pprof 路由 - pprofGroup := a.engine.Group("/debug/pprof") - { - pprofGroup.GET("/", gin.WrapF(pprof.Index)) // pprof 索引页 - pprofGroup.GET("/cmdline", gin.WrapF(pprof.Cmdline)) // pprof 命令行参数 - pprofGroup.GET("/profile", gin.WrapF(pprof.Profile)) // pprof CPU profile - pprofGroup.POST("/symbol", gin.WrapF(pprof.Symbol)) // pprof 符号查找 (POST) - pprofGroup.GET("/symbol", gin.WrapF(pprof.Symbol)) // pprof 符号查找 (GET) - pprofGroup.GET("/trace", gin.WrapF(pprof.Trace)) // pprof 跟踪 - pprofGroup.GET("/allocs", gin.WrapH(pprof.Handler("allocs"))) // pprof 内存分配 - pprofGroup.GET("/block", gin.WrapH(pprof.Handler("block"))) // pprof 阻塞 - pprofGroup.GET("/goroutine", gin.WrapH(pprof.Handler("goroutine"))) - pprofGroup.GET("/heap", gin.WrapH(pprof.Handler("heap"))) // pprof 堆内存 - pprofGroup.GET("/mutex", gin.WrapH(pprof.Handler("mutex"))) // pprof 互斥锁 - pprofGroup.GET("/threadcreate", gin.WrapH(pprof.Handler("threadcreate"))) - } - a.logger.Info("pprof 接口注册成功") - - // 上行事件监听路由 - a.engine.POST("/upstream", gin.WrapH(a.listenHandler.Handler())) // 处理设备上行事件 - a.logger.Info("上行事件监听接口注册成功") - - // 添加 Swagger UI 路由, Swagger UI可在 /swagger/index.html 上找到 - a.engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // Swagger UI 接口 - a.logger.Info("Swagger UI 接口注册成功") - - // --- Authenticated Routes --- - // 所有在此注册的路由都需要通过 JWT 身份验证 - authGroup := a.engine.Group("/api/v1") - authGroup.Use(middleware.AuthMiddleware(a.tokenService, a.userRepo)) // 1. 身份认证中间件 - authGroup.Use(middleware.AuditLogMiddleware(a.auditService)) // 2. 审计日志中间件 - { - // 用户相关路由组 - userGroup := authGroup.Group("/users") - { - userGroup.GET("/:id/history", a.userController.ListUserHistory) // 获取用户操作历史 - } - a.logger.Info("用户相关接口注册成功 (需要认证和审计)") - - // 设备相关路由组 - deviceGroup := authGroup.Group("/devices") - { - deviceGroup.POST("", a.deviceController.CreateDevice) // 创建设备 - deviceGroup.GET("", a.deviceController.ListDevices) // 获取设备列表 - deviceGroup.GET("/:id", a.deviceController.GetDevice) // 获取单个设备 - deviceGroup.PUT("/:id", a.deviceController.UpdateDevice) // 更新设备 - deviceGroup.DELETE("/:id", a.deviceController.DeleteDevice) // 删除设备 - deviceGroup.POST("/manual-control/:id", a.deviceController.ManualControl) // 手动控制设备 - } - a.logger.Info("设备相关接口注册成功 (需要认证和审计)") - - // 区域主控相关路由组 - areaControllerGroup := authGroup.Group("/area-controllers") - { - areaControllerGroup.POST("", a.deviceController.CreateAreaController) // 创建区域主控 - areaControllerGroup.GET("", a.deviceController.ListAreaControllers) // 获取区域主控列表 - areaControllerGroup.GET("/:id", a.deviceController.GetAreaController) // 获取单个区域主控 - areaControllerGroup.PUT("/:id", a.deviceController.UpdateAreaController) // 更新区域主控 - areaControllerGroup.DELETE("/:id", a.deviceController.DeleteAreaController) // 删除区域主控 - } - a.logger.Info("区域主控相关接口注册成功 (需要认证和审计)") - - // 设备模板相关路由组 - deviceTemplateGroup := authGroup.Group("/device-templates") - { - deviceTemplateGroup.POST("", a.deviceController.CreateDeviceTemplate) // 创建设备模板 - deviceTemplateGroup.GET("", a.deviceController.ListDeviceTemplates) // 获取设备模板列表 - deviceTemplateGroup.GET("/:id", a.deviceController.GetDeviceTemplate) // 获取单个设备模板 - deviceTemplateGroup.PUT("/:id", a.deviceController.UpdateDeviceTemplate) // 更新设备模板 - deviceTemplateGroup.DELETE("/:id", a.deviceController.DeleteDeviceTemplate) // 删除设备模板 - } - a.logger.Info("设备模板相关接口注册成功 (需要认证和审计)") - - // 计划相关路由组 - planGroup := authGroup.Group("/plans") - { - planGroup.POST("", a.planController.CreatePlan) // 创建计划 - planGroup.GET("", a.planController.ListPlans) // 获取计划列表 - planGroup.GET("/:id", a.planController.GetPlan) // 获取单个计划 - planGroup.PUT("/:id", a.planController.UpdatePlan) // 更新计划 - planGroup.DELETE("/:id", a.planController.DeletePlan) // 删除计划 - planGroup.POST("/:id/start", a.planController.StartPlan) // 启动计划 - planGroup.POST("/:id/stop", a.planController.StopPlan) // 停止计划 - } - a.logger.Info("计划相关接口注册成功 (需要认证和审计)") - - // 猪舍相关路由组 - pigHouseGroup := authGroup.Group("/pig-houses") - { - pigHouseGroup.POST("", a.pigFarmController.CreatePigHouse) // 创建猪舍 - pigHouseGroup.GET("", a.pigFarmController.ListPigHouses) // 获取猪舍列表 - pigHouseGroup.GET("/:id", a.pigFarmController.GetPigHouse) // 获取单个猪舍 - pigHouseGroup.PUT("/:id", a.pigFarmController.UpdatePigHouse) // 更新猪舍 - pigHouseGroup.DELETE("/:id", a.pigFarmController.DeletePigHouse) // 删除猪舍 - } - a.logger.Info("猪舍相关接口注册成功 (需要认证和审计)") - - // 猪圈相关路由组 - penGroup := authGroup.Group("/pens") - { - penGroup.POST("", a.pigFarmController.CreatePen) // 创建猪圈 - penGroup.GET("", a.pigFarmController.ListPens) // 获取猪圈列表 - penGroup.GET("/:id", a.pigFarmController.GetPen) // 获取单个猪圈 - penGroup.PUT("/:id", a.pigFarmController.UpdatePen) // 更新猪圈 - penGroup.DELETE("/:id", a.pigFarmController.DeletePen) // 删除猪圈 - penGroup.PUT("/:id/status", a.pigFarmController.UpdatePenStatus) // 更新猪圈状态 - } - a.logger.Info("猪圈相关接口注册成功 (需要认证和审计)") - - // 猪群相关路由组 - pigBatchGroup := authGroup.Group("/pig-batches") - { - pigBatchGroup.POST("", a.pigBatchController.CreatePigBatch) // 创建猪群 - pigBatchGroup.GET("", a.pigBatchController.ListPigBatches) // 获取猪群列表 - pigBatchGroup.GET("/:id", a.pigBatchController.GetPigBatch) // 获取单个猪群 - pigBatchGroup.PUT("/:id", a.pigBatchController.UpdatePigBatch) // 更新猪群 - pigBatchGroup.DELETE("/:id", a.pigBatchController.DeletePigBatch) // 删除猪群 - pigBatchGroup.POST("/assign-pens/:id", a.pigBatchController.AssignEmptyPensToBatch) // 为猪群分配空栏 - pigBatchGroup.POST("/reclassify-pen/:fromBatchID", a.pigBatchController.ReclassifyPenToNewBatch) // 将猪栏划拨到新群 - penGroup.DELETE("/remove-pen/:penID/:batchID", a.pigBatchController.RemoveEmptyPenFromBatch) // 从猪群移除空栏 - pigBatchGroup.POST("/move-pigs-into-pen/:id", a.pigBatchController.MovePigsIntoPen) // 将猪只从“虚拟库存”移入指定猪栏 - pigBatchGroup.POST("/sell-pigs/:id", a.pigBatchController.SellPigs) // 处理卖猪业务 - pigBatchGroup.POST("/buy-pigs/:id", a.pigBatchController.BuyPigs) // 处理买猪业务 - pigBatchGroup.POST("/transfer-across-batches/:sourceBatchID", a.pigBatchController.TransferPigsAcrossBatches) // 跨猪群调栏 - pigBatchGroup.POST("/transfer-within-batch/:id", a.pigBatchController.TransferPigsWithinBatch) // 群内调栏 - pigBatchGroup.POST("/record-sick-pigs/:id", a.pigBatchController.RecordSickPigs) // 记录新增病猪事件 - pigBatchGroup.POST("/record-sick-pig-recovery/:id", a.pigBatchController.RecordSickPigRecovery) // 记录病猪康复事件 - pigBatchGroup.POST("/record-sick-pig-death/:id", a.pigBatchController.RecordSickPigDeath) // 记录病猪死亡事件 - pigBatchGroup.POST("/record-sick-pig-cull/:id", a.pigBatchController.RecordSickPigCull) // 记录病猪淘汰事件 - pigBatchGroup.POST("/record-death/:id", a.pigBatchController.RecordDeath) // 记录正常猪只死亡事件 - pigBatchGroup.POST("/record-cull/:id", a.pigBatchController.RecordCull) // 记录正常猪只淘汰事件 - } - a.logger.Info("猪群相关接口注册成功 (需要认证和审计)") - - } -} - // Start 启动 HTTP 服务器 // 接收一个地址字符串 (例如 ":8080"),并在一个新的 goroutine 中启动服务器, // 以便主线程可以继续执行其他任务(例如监听操作系统信号)。 diff --git a/internal/app/api/router.go b/internal/app/api/router.go new file mode 100644 index 0000000..99fdbf6 --- /dev/null +++ b/internal/app/api/router.go @@ -0,0 +1,181 @@ +package api + +import ( + "net/http/pprof" + + "git.huangwc.com/pig/pig-farm-controller/internal/app/middleware" + "github.com/gin-gonic/gin" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" +) + +// setupRoutes 设置所有 API 路由 +// 在此方法中,使用已初始化的控制器实例将其路由注册到 Gin 引擎中。 +func (a *API) setupRoutes() { + + // --- Public Routes --- + // 这些路由不需要身份验证 + + // 用户注册和登录 + a.engine.POST("/api/v1/users", a.userController.CreateUser) // 注册新用户 + a.engine.POST("/api/v1/users/login", a.userController.Login) // 用户登录 + a.logger.Info("公开接口注册成功:用户注册、登录") + + // 注册 pprof 路由 + pprofGroup := a.engine.Group("/debug/pprof") + { + pprofGroup.GET("/", gin.WrapF(pprof.Index)) // pprof 索引页 + pprofGroup.GET("/cmdline", gin.WrapF(pprof.Cmdline)) // pprof 命令行参数 + pprofGroup.GET("/profile", gin.WrapF(pprof.Profile)) // pprof CPU profile + pprofGroup.POST("/symbol", gin.WrapF(pprof.Symbol)) // pprof 符号查找 (POST) + pprofGroup.GET("/symbol", gin.WrapF(pprof.Symbol)) // pprof 符号查找 (GET) + pprofGroup.GET("/trace", gin.WrapF(pprof.Trace)) // pprof 跟踪 + pprofGroup.GET("/allocs", gin.WrapH(pprof.Handler("allocs"))) // pprof 内存分配 + pprofGroup.GET("/block", gin.WrapH(pprof.Handler("block"))) // pprof 阻塞 + pprofGroup.GET("/goroutine", gin.WrapH(pprof.Handler("goroutine"))) + pprofGroup.GET("/heap", gin.WrapH(pprof.Handler("heap"))) // pprof 堆内存 + pprofGroup.GET("/mutex", gin.WrapH(pprof.Handler("mutex"))) // pprof 互斥锁 + pprofGroup.GET("/threadcreate", gin.WrapH(pprof.Handler("threadcreate"))) + } + a.logger.Info("pprof 接口注册成功") + + // 上行事件监听路由 + a.engine.POST("/upstream", gin.WrapH(a.listenHandler.Handler())) // 处理设备上行事件 + a.logger.Info("上行事件监听接口注册成功") + + // 添加 Swagger UI 路由, Swagger UI可在 /swagger/index.html 上找到 + a.engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // Swagger UI 接口 + a.logger.Info("Swagger UI 接口注册成功") + + // --- Authenticated Routes --- + // 所有在此注册的路由都需要通过 JWT 身份验证 + authGroup := a.engine.Group("/api/v1") + authGroup.Use(middleware.AuthMiddleware(a.tokenService, a.userRepo)) // 1. 身份认证中间件 + authGroup.Use(middleware.AuditLogMiddleware(a.auditService)) // 2. 审计日志中间件 + { + // 用户相关路由组 + userGroup := authGroup.Group("/users") + { + userGroup.GET("/:id/history", a.userController.ListUserHistory) // 获取用户操作历史 + } + a.logger.Info("用户相关接口注册成功 (需要认证和审计)") + + // 设备相关路由组 + deviceGroup := authGroup.Group("/devices") + { + deviceGroup.POST("", a.deviceController.CreateDevice) // 创建设备 + deviceGroup.GET("", a.deviceController.ListDevices) // 获取设备列表 + deviceGroup.GET("/:id", a.deviceController.GetDevice) // 获取单个设备 + deviceGroup.PUT("/:id", a.deviceController.UpdateDevice) // 更新设备 + deviceGroup.DELETE("/:id", a.deviceController.DeleteDevice) // 删除设备 + deviceGroup.POST("/manual-control/:id", a.deviceController.ManualControl) // 手动控制设备 + } + a.logger.Info("设备相关接口注册成功 (需要认证和审计)") + + // 区域主控相关路由组 + areaControllerGroup := authGroup.Group("/area-controllers") + { + areaControllerGroup.POST("", a.deviceController.CreateAreaController) // 创建区域主控 + areaControllerGroup.GET("", a.deviceController.ListAreaControllers) // 获取区域主控列表 + areaControllerGroup.GET("/:id", a.deviceController.GetAreaController) // 获取单个区域主控 + areaControllerGroup.PUT("/:id", a.deviceController.UpdateAreaController) // 更新区域主控 + areaControllerGroup.DELETE("/:id", a.deviceController.DeleteAreaController) // 删除区域主控 + } + a.logger.Info("区域主控相关接口注册成功 (需要认证和审计)") + + // 设备模板相关路由组 + deviceTemplateGroup := authGroup.Group("/device-templates") + { + deviceTemplateGroup.POST("", a.deviceController.CreateDeviceTemplate) // 创建设备模板 + deviceTemplateGroup.GET("", a.deviceController.ListDeviceTemplates) // 获取设备模板列表 + deviceTemplateGroup.GET("/:id", a.deviceController.GetDeviceTemplate) // 获取单个设备模板 + deviceTemplateGroup.PUT("/:id", a.deviceController.UpdateDeviceTemplate) // 更新设备模板 + deviceTemplateGroup.DELETE("/:id", a.deviceController.DeleteDeviceTemplate) // 删除设备模板 + } + a.logger.Info("设备模板相关接口注册成功 (需要认证和审计)") + + // 计划相关路由组 + planGroup := authGroup.Group("/plans") + { + planGroup.POST("", a.planController.CreatePlan) // 创建计划 + planGroup.GET("", a.planController.ListPlans) // 获取计划列表 + planGroup.GET("/:id", a.planController.GetPlan) // 获取单个计划 + planGroup.PUT("/:id", a.planController.UpdatePlan) // 更新计划 + planGroup.DELETE("/:id", a.planController.DeletePlan) // 删除计划 + planGroup.POST("/:id/start", a.planController.StartPlan) // 启动计划 + planGroup.POST("/:id/stop", a.planController.StopPlan) // 停止计划 + } + a.logger.Info("计划相关接口注册成功 (需要认证和审计)") + + // 猪舍相关路由组 + pigHouseGroup := authGroup.Group("/pig-houses") + { + pigHouseGroup.POST("", a.pigFarmController.CreatePigHouse) // 创建猪舍 + pigHouseGroup.GET("", a.pigFarmController.ListPigHouses) // 获取猪舍列表 + pigHouseGroup.GET("/:id", a.pigFarmController.GetPigHouse) // 获取单个猪舍 + pigHouseGroup.PUT("/:id", a.pigFarmController.UpdatePigHouse) // 更新猪舍 + pigHouseGroup.DELETE("/:id", a.pigFarmController.DeletePigHouse) // 删除猪舍 + } + a.logger.Info("猪舍相关接口注册成功 (需要认证和审计)") + + // 猪圈相关路由组 + penGroup := authGroup.Group("/pens") + { + penGroup.POST("", a.pigFarmController.CreatePen) // 创建猪圈 + penGroup.GET("", a.pigFarmController.ListPens) // 获取猪圈列表 + penGroup.GET("/:id", a.pigFarmController.GetPen) // 获取单个猪圈 + penGroup.PUT("/:id", a.pigFarmController.UpdatePen) // 更新猪圈 + penGroup.DELETE("/:id", a.pigFarmController.DeletePen) // 删除猪圈 + penGroup.PUT("/:id/status", a.pigFarmController.UpdatePenStatus) // 更新猪圈状态 + } + a.logger.Info("猪圈相关接口注册成功 (需要认证和审计)") + + // 猪群相关路由组 + pigBatchGroup := authGroup.Group("/pig-batches") + { + pigBatchGroup.POST("", a.pigBatchController.CreatePigBatch) // 创建猪群 + pigBatchGroup.GET("", a.pigBatchController.ListPigBatches) // 获取猪群列表 + pigBatchGroup.GET("/:id", a.pigBatchController.GetPigBatch) // 获取单个猪群 + pigBatchGroup.PUT("/:id", a.pigBatchController.UpdatePigBatch) // 更新猪群 + pigBatchGroup.DELETE("/:id", a.pigBatchController.DeletePigBatch) // 删除猪群 + pigBatchGroup.POST("/assign-pens/:id", a.pigBatchController.AssignEmptyPensToBatch) // 为猪群分配空栏 + pigBatchGroup.POST("/reclassify-pen/:fromBatchID", a.pigBatchController.ReclassifyPenToNewBatch) // 将猪栏划拨到新群 + penGroup.DELETE("/remove-pen/:penID/:batchID", a.pigBatchController.RemoveEmptyPenFromBatch) // 从猪群移除空栏 + pigBatchGroup.POST("/move-pigs-into-pen/:id", a.pigBatchController.MovePigsIntoPen) // 将猪只从“虚拟库存”移入指定猪栏 + pigBatchGroup.POST("/sell-pigs/:id", a.pigBatchController.SellPigs) // 处理卖猪业务 + pigBatchGroup.POST("/buy-pigs/:id", a.pigBatchController.BuyPigs) // 处理买猪业务 + pigBatchGroup.POST("/transfer-across-batches/:sourceBatchID", a.pigBatchController.TransferPigsAcrossBatches) // 跨猪群调栏 + pigBatchGroup.POST("/transfer-within-batch/:id", a.pigBatchController.TransferPigsWithinBatch) // 群内调栏 + pigBatchGroup.POST("/record-sick-pigs/:id", a.pigBatchController.RecordSickPigs) // 记录新增病猪事件 + pigBatchGroup.POST("/record-sick-pig-recovery/:id", a.pigBatchController.RecordSickPigRecovery) // 记录病猪康复事件 + pigBatchGroup.POST("/record-sick-pig-death/:id", a.pigBatchController.RecordSickPigDeath) // 记录病猪死亡事件 + pigBatchGroup.POST("/record-sick-pig-cull/:id", a.pigBatchController.RecordSickPigCull) // 记录病猪淘汰事件 + pigBatchGroup.POST("/record-death/:id", a.pigBatchController.RecordDeath) // 记录正常猪只死亡事件 + pigBatchGroup.POST("/record-cull/:id", a.pigBatchController.RecordCull) // 记录正常猪只淘汰事件 + } + a.logger.Info("猪群相关接口注册成功 (需要认证和审计)") + + // 数据监控相关路由组 + monitorGroup := authGroup.Group("/monitor") + { + monitorGroup.GET("/sensor-data", a.monitorController.ListSensorData) + monitorGroup.GET("/device-command-logs", a.monitorController.ListDeviceCommandLogs) + monitorGroup.GET("/plan-execution-logs", a.monitorController.ListPlanExecutionLogs) + monitorGroup.GET("/task-execution-logs", a.monitorController.ListTaskExecutionLogs) + monitorGroup.GET("/pending-collections", a.monitorController.ListPendingCollections) + monitorGroup.GET("/user-action-logs", a.monitorController.ListUserActionLogs) + monitorGroup.GET("/raw-material-purchases", a.monitorController.ListRawMaterialPurchases) + monitorGroup.GET("/raw-material-stock-logs", a.monitorController.ListRawMaterialStockLogs) + monitorGroup.GET("/feed-usage-records", a.monitorController.ListFeedUsageRecords) + monitorGroup.GET("/medication-logs", a.monitorController.ListMedicationLogs) + monitorGroup.GET("/pig-batch-logs", a.monitorController.ListPigBatchLogs) + monitorGroup.GET("/weighing-batches", a.monitorController.ListWeighingBatches) + monitorGroup.GET("/weighing-records", a.monitorController.ListWeighingRecords) + monitorGroup.GET("/pig-transfer-logs", a.monitorController.ListPigTransferLogs) + monitorGroup.GET("/pig-sick-logs", a.monitorController.ListPigSickLogs) + monitorGroup.GET("/pig-purchases", a.monitorController.ListPigPurchases) + monitorGroup.GET("/pig-sales", a.monitorController.ListPigSales) + } + a.logger.Info("数据监控相关接口注册成功 (需要认证和审计)") + } +} diff --git a/internal/app/controller/monitor/monitor_controller.go b/internal/app/controller/monitor/monitor_controller.go index 1bb4a03..9b409fe 100644 --- a/internal/app/controller/monitor/monitor_controller.go +++ b/internal/app/controller/monitor/monitor_controller.go @@ -14,12 +14,12 @@ import ( // Controller 监控控制器,封装了所有与数据监控相关的业务逻辑 type Controller struct { - monitorService *service.MonitorService + monitorService service.MonitorService logger *logs.Logger } // NewController 创建一个新的监控控制器实例 -func NewController(monitorService *service.MonitorService, logger *logs.Logger) *Controller { +func NewController(monitorService service.MonitorService, logger *logs.Logger) *Controller { return &Controller{ monitorService: monitorService, logger: logger, diff --git a/internal/app/middleware/auth.go b/internal/app/middleware/auth.go index 2755313..e370954 100644 --- a/internal/app/middleware/auth.go +++ b/internal/app/middleware/auth.go @@ -25,7 +25,7 @@ func AuthMiddleware(tokenService token.TokenService, userRepo repository.UserRep // 授权标头的格式应为 "Bearer " parts := strings.Split(authHeader, " ") - if len(parts) != 2 || parts[0] != "Bearer" { + if len(parts) != 2 || strings.ToLower(parts[0]) != "bearer" { c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "授权标头格式不正确"}) return } diff --git a/internal/app/service/monitor_service.go b/internal/app/service/monitor_service.go index cd9e5a2..eed0f4d 100644 --- a/internal/app/service/monitor_service.go +++ b/internal/app/service/monitor_service.go @@ -5,8 +5,29 @@ import ( "git.huangwc.com/pig/pig-farm-controller/internal/infra/repository" ) -// MonitorService 定义了监控相关的业务逻辑服务 -type MonitorService struct { +// MonitorService 定义了监控相关的业务逻辑服务接口 +type MonitorService interface { + ListSensorData(opts repository.SensorDataListOptions, page, pageSize int) ([]models.SensorData, int64, error) + ListDeviceCommandLogs(opts repository.DeviceCommandLogListOptions, page, pageSize int) ([]models.DeviceCommandLog, int64, error) + ListPlanExecutionLogs(opts repository.PlanExecutionLogListOptions, page, pageSize int) ([]models.PlanExecutionLog, int64, error) + ListTaskExecutionLogs(opts repository.TaskExecutionLogListOptions, page, pageSize int) ([]models.TaskExecutionLog, int64, error) + ListPendingCollections(opts repository.PendingCollectionListOptions, page, pageSize int) ([]models.PendingCollection, int64, error) + ListUserActionLogs(opts repository.UserActionLogListOptions, page, pageSize int) ([]models.UserActionLog, int64, error) + ListRawMaterialPurchases(opts repository.RawMaterialPurchaseListOptions, page, pageSize int) ([]models.RawMaterialPurchase, int64, error) + ListRawMaterialStockLogs(opts repository.RawMaterialStockLogListOptions, page, pageSize int) ([]models.RawMaterialStockLog, int64, error) + ListFeedUsageRecords(opts repository.FeedUsageRecordListOptions, page, pageSize int) ([]models.FeedUsageRecord, int64, error) + ListMedicationLogs(opts repository.MedicationLogListOptions, page, pageSize int) ([]models.MedicationLog, int64, error) + ListPigBatchLogs(opts repository.PigBatchLogListOptions, page, pageSize int) ([]models.PigBatchLog, int64, error) + ListWeighingBatches(opts repository.WeighingBatchListOptions, page, pageSize int) ([]models.WeighingBatch, int64, error) + ListWeighingRecords(opts repository.WeighingRecordListOptions, page, pageSize int) ([]models.WeighingRecord, int64, error) + ListPigTransferLogs(opts repository.PigTransferLogListOptions, page, pageSize int) ([]models.PigTransferLog, int64, error) + ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error) + ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error) + ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error) +} + +// monitorService 是 MonitorService 接口的具体实现 +type monitorService struct { sensorDataRepo repository.SensorDataRepository deviceCommandLogRepo repository.DeviceCommandLogRepository executionLogRepo repository.ExecutionLogRepository @@ -35,8 +56,8 @@ func NewMonitorService( pigTransferLogRepo repository.PigTransferLogRepository, pigSickLogRepo repository.PigSickLogRepository, pigTradeRepo repository.PigTradeRepository, -) *MonitorService { - return &MonitorService{ +) MonitorService { + return &monitorService{ sensorDataRepo: sensorDataRepo, deviceCommandLogRepo: deviceCommandLogRepo, executionLogRepo: executionLogRepo, @@ -53,86 +74,86 @@ func NewMonitorService( } // ListSensorData 负责处理查询传感器数据列表的业务逻辑 -func (s *MonitorService) ListSensorData(opts repository.SensorDataListOptions, page, pageSize int) ([]models.SensorData, int64, error) { +func (s *monitorService) ListSensorData(opts repository.SensorDataListOptions, page, pageSize int) ([]models.SensorData, int64, error) { return s.sensorDataRepo.List(opts, page, pageSize) } // ListDeviceCommandLogs 负责处理查询设备命令日志列表的业务逻辑 -func (s *MonitorService) ListDeviceCommandLogs(opts repository.DeviceCommandLogListOptions, page, pageSize int) ([]models.DeviceCommandLog, int64, error) { +func (s *monitorService) ListDeviceCommandLogs(opts repository.DeviceCommandLogListOptions, page, pageSize int) ([]models.DeviceCommandLog, int64, error) { return s.deviceCommandLogRepo.List(opts, page, pageSize) } // ListPlanExecutionLogs 负责处理查询计划执行日志列表的业务逻辑 -func (s *MonitorService) ListPlanExecutionLogs(opts repository.PlanExecutionLogListOptions, page, pageSize int) ([]models.PlanExecutionLog, int64, error) { +func (s *monitorService) ListPlanExecutionLogs(opts repository.PlanExecutionLogListOptions, page, pageSize int) ([]models.PlanExecutionLog, int64, error) { return s.executionLogRepo.ListPlanExecutionLogs(opts, page, pageSize) } // ListTaskExecutionLogs 负责处理查询任务执行日志列表的业务逻辑 -func (s *MonitorService) ListTaskExecutionLogs(opts repository.TaskExecutionLogListOptions, page, pageSize int) ([]models.TaskExecutionLog, int64, error) { +func (s *monitorService) ListTaskExecutionLogs(opts repository.TaskExecutionLogListOptions, page, pageSize int) ([]models.TaskExecutionLog, int64, error) { return s.executionLogRepo.ListTaskExecutionLogs(opts, page, pageSize) } // ListPendingCollections 负责处理查询待采集请求列表的业务逻辑 -func (s *MonitorService) ListPendingCollections(opts repository.PendingCollectionListOptions, page, pageSize int) ([]models.PendingCollection, int64, error) { +func (s *monitorService) ListPendingCollections(opts repository.PendingCollectionListOptions, page, pageSize int) ([]models.PendingCollection, int64, error) { return s.pendingCollectionRepo.List(opts, page, pageSize) } // ListUserActionLogs 负责处理查询用户操作日志列表的业务逻辑 -func (s *MonitorService) ListUserActionLogs(opts repository.UserActionLogListOptions, page, pageSize int) ([]models.UserActionLog, int64, error) { +func (s *monitorService) ListUserActionLogs(opts repository.UserActionLogListOptions, page, pageSize int) ([]models.UserActionLog, int64, error) { return s.userActionLogRepo.List(opts, page, pageSize) } // ListRawMaterialPurchases 负责处理查询原料采购记录列表的业务逻辑 -func (s *MonitorService) ListRawMaterialPurchases(opts repository.RawMaterialPurchaseListOptions, page, pageSize int) ([]models.RawMaterialPurchase, int64, error) { +func (s *monitorService) ListRawMaterialPurchases(opts repository.RawMaterialPurchaseListOptions, page, pageSize int) ([]models.RawMaterialPurchase, int64, error) { return s.rawMaterialRepo.ListRawMaterialPurchases(opts, page, pageSize) } // ListRawMaterialStockLogs 负责处理查询原料库存日志列表的业务逻辑 -func (s *MonitorService) ListRawMaterialStockLogs(opts repository.RawMaterialStockLogListOptions, page, pageSize int) ([]models.RawMaterialStockLog, int64, error) { +func (s *monitorService) ListRawMaterialStockLogs(opts repository.RawMaterialStockLogListOptions, page, pageSize int) ([]models.RawMaterialStockLog, int64, error) { return s.rawMaterialRepo.ListRawMaterialStockLogs(opts, page, pageSize) } // ListFeedUsageRecords 负责处理查询饲料使用记录列表的业务逻辑 -func (s *MonitorService) ListFeedUsageRecords(opts repository.FeedUsageRecordListOptions, page, pageSize int) ([]models.FeedUsageRecord, int64, error) { +func (s *monitorService) ListFeedUsageRecords(opts repository.FeedUsageRecordListOptions, page, pageSize int) ([]models.FeedUsageRecord, int64, error) { return s.rawMaterialRepo.ListFeedUsageRecords(opts, page, pageSize) } // ListMedicationLogs 负责处理查询用药记录列表的业务逻辑 -func (s *MonitorService) ListMedicationLogs(opts repository.MedicationLogListOptions, page, pageSize int) ([]models.MedicationLog, int64, error) { +func (s *monitorService) ListMedicationLogs(opts repository.MedicationLogListOptions, page, pageSize int) ([]models.MedicationLog, int64, error) { return s.medicationRepo.ListMedicationLogs(opts, page, pageSize) } // ListPigBatchLogs 负责处理查询猪批次日志列表的业务逻辑 -func (s *MonitorService) ListPigBatchLogs(opts repository.PigBatchLogListOptions, page, pageSize int) ([]models.PigBatchLog, int64, error) { +func (s *monitorService) ListPigBatchLogs(opts repository.PigBatchLogListOptions, page, pageSize int) ([]models.PigBatchLog, int64, error) { return s.pigBatchLogRepo.List(opts, page, pageSize) } // ListWeighingBatches 负责处理查询批次称重记录列表的业务逻辑 -func (s *MonitorService) ListWeighingBatches(opts repository.WeighingBatchListOptions, page, pageSize int) ([]models.WeighingBatch, int64, error) { +func (s *monitorService) ListWeighingBatches(opts repository.WeighingBatchListOptions, page, pageSize int) ([]models.WeighingBatch, int64, error) { return s.pigBatchRepo.ListWeighingBatches(opts, page, pageSize) } // ListWeighingRecords 负责处理查询单次称重记录列表的业务逻辑 -func (s *MonitorService) ListWeighingRecords(opts repository.WeighingRecordListOptions, page, pageSize int) ([]models.WeighingRecord, int64, error) { +func (s *monitorService) ListWeighingRecords(opts repository.WeighingRecordListOptions, page, pageSize int) ([]models.WeighingRecord, int64, error) { return s.pigBatchRepo.ListWeighingRecords(opts, page, pageSize) } // ListPigTransferLogs 负责处理查询猪只迁移日志列表的业务逻辑 -func (s *MonitorService) ListPigTransferLogs(opts repository.PigTransferLogListOptions, page, pageSize int) ([]models.PigTransferLog, int64, error) { +func (s *monitorService) ListPigTransferLogs(opts repository.PigTransferLogListOptions, page, pageSize int) ([]models.PigTransferLog, int64, error) { return s.pigTransferLogRepo.ListPigTransferLogs(opts, page, pageSize) } // ListPigSickLogs 负责处理查询病猪日志列表的业务逻辑 -func (s *MonitorService) ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error) { +func (s *monitorService) ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error) { return s.pigSickLogRepo.ListPigSickLogs(opts, page, pageSize) } // ListPigPurchases 负责处理查询猪只采购记录列表的业务逻辑 -func (s *MonitorService) ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error) { +func (s *monitorService) ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error) { return s.pigTradeRepo.ListPigPurchases(opts, page, pageSize) } // ListPigSales 负责处理查询猪只销售记录列表的业务逻辑 -func (s *MonitorService) ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error) { +func (s *monitorService) ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error) { return s.pigTradeRepo.ListPigSales(opts, page, pageSize) } diff --git a/internal/core/application.go b/internal/core/application.go index f123a78..df0e6c7 100644 --- a/internal/core/application.go +++ b/internal/core/application.go @@ -84,6 +84,7 @@ func NewApplication(configPath string) (*Application, error) { pigTradeRepo := repository.NewGormPigTradeRepository(storage.GetDB()) pigSickPigLogRepo := repository.NewGormPigSickLogRepository(storage.GetDB()) medicationLogRepo := repository.NewGormMedicationLogRepository(storage.GetDB()) + rawMaterialRepo := repository.NewGormRawMaterialRepository(storage.GetDB()) // 初始化事务管理器 unitOfWork := repository.NewGormUnitOfWork(storage.GetDB(), logger) @@ -98,6 +99,20 @@ func NewApplication(configPath string) (*Application, error) { // --- 业务逻辑处理器初始化 --- pigFarmService := service.NewPigFarmService(pigFarmRepo, pigPenRepo, pigBatchRepo, unitOfWork, logger) pigBatchService := service.NewPigBatchService(pigBatchDomain, logger) + monitorService := service.NewMonitorService( + sensorDataRepo, + deviceCommandLogRepo, + executionLogRepo, + pendingCollectionRepo, + userActionLogRepo, + rawMaterialRepo, + medicationLogRepo, + pigBatchRepo, + pigBatchLogRepo, + pigTransferLogRepo, + pigSickPigLogRepo, + pigTradeRepo, + ) // 初始化审计服务 auditService := audit.NewService(userActionLogRepo, logger) @@ -160,6 +175,7 @@ func NewApplication(configPath string) (*Application, error) { planRepo, pigFarmService, pigBatchService, + monitorService, userActionLogRepo, tokenService, auditService,