diff --git a/docs/swagger.json b/docs/swagger.json index e987a0a2..c314693b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -10,6 +10,402 @@ "host": "", "basePath": "", "paths": { + "/api/v1/area-controllers": { + "get": { + "description": "获取系统中所有区域主控的列表", + "produces": [ + "application/json" + ], + "tags": [ + "区域主控管理" + ], + "summary": "获取所有区域主控列表", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/device.AreaControllerResponse" + } + } + } + } + ] + } + } + } + }, + "post": { + "description": "根据提供的信息创建一个新区域主控", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "区域主控管理" + ], + "summary": "创建新区域主控", + "parameters": [ + { + "description": "区域主控信息", + "name": "areaController", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/device.CreateAreaControllerRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/device.AreaControllerResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/area-controllers/{id}": { + "get": { + "description": "根据ID获取单个区域主控的详细信息", + "produces": [ + "application/json" + ], + "tags": [ + "区域主控管理" + ], + "summary": "获取区域主控信息", + "parameters": [ + { + "type": "string", + "description": "区域主控ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/device.AreaControllerResponse" + } + } + } + ] + } + } + } + }, + "put": { + "description": "根据ID更新一个已存在的区域主控信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "区域主控管理" + ], + "summary": "更新区域主控信息", + "parameters": [ + { + "type": "string", + "description": "区域主控ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "要更新的区域主控信息", + "name": "areaController", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/device.UpdateAreaControllerRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/device.AreaControllerResponse" + } + } + } + ] + } + } + } + }, + "delete": { + "description": "根据ID删除一个区域主控(软删除)", + "produces": [ + "application/json" + ], + "tags": [ + "区域主控管理" + ], + "summary": "删除区域主控", + "parameters": [ + { + "type": "string", + "description": "区域主控ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.Response" + } + } + } + } + }, + "/api/v1/device-templates": { + "get": { + "description": "获取系统中所有设备模板的列表", + "produces": [ + "application/json" + ], + "tags": [ + "设备模板管理" + ], + "summary": "获取设备模板列表", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/device.DeviceTemplateResponse" + } + } + } + } + ] + } + } + } + }, + "post": { + "description": "根据提供的信息创建一个新设备模板", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "设备模板管理" + ], + "summary": "创建新设备模板", + "parameters": [ + { + "description": "设备模板信息", + "name": "deviceTemplate", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/device.CreateDeviceTemplateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/device.DeviceTemplateResponse" + } + } + } + ] + } + } + } + } + }, + "/api/v1/device-templates/{id}": { + "get": { + "description": "根据设备模板ID获取单个设备模板的详细信息", + "produces": [ + "application/json" + ], + "tags": [ + "设备模板管理" + ], + "summary": "获取设备模板信息", + "parameters": [ + { + "type": "string", + "description": "设备模板ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/device.DeviceTemplateResponse" + } + } + } + ] + } + } + } + }, + "put": { + "description": "根据设备模板ID更新一个已存在的设备模板信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "设备模板管理" + ], + "summary": "更新设备模板信息", + "parameters": [ + { + "type": "string", + "description": "设备模板ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "要更新的设备模板信息", + "name": "deviceTemplate", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/device.UpdateDeviceTemplateRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/device.DeviceTemplateResponse" + } + } + } + ] + } + } + } + }, + "delete": { + "description": "根据设备模板ID删除一个设备模板(软删除)", + "produces": [ + "application/json" + ], + "tags": [ + "设备模板管理" + ], + "summary": "删除设备模板", + "parameters": [ + { + "type": "string", + "description": "设备模板ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.Response" + } + } + } + } + }, "/api/v1/devices": { "get": { "description": "获取系统中所有设备的列表", @@ -376,7 +772,7 @@ } }, "delete": { - "description": "根据计划ID删除计划。", + "description": "根据计划ID删除计划。(软删除)", "produces": [ "application/json" ], @@ -509,7 +905,7 @@ }, "/api/v1/users/login": { "post": { - "description": "用户使用用户名和密码登录,成功后返回 JWT 令牌。", + "description": "用户可以使用用户名、邮箱、手机号、微信号或飞书账号进行登录,成功后返回 JWT 令牌。", "consumes": [ "application/json" ], @@ -552,6 +948,67 @@ } } } + }, + "/api/v1/users/{id}/history": { + "get": { + "description": "根据用户ID,分页获取该用户的操作审计日志。", + "produces": [ + "application/json" + ], + "tags": [ + "用户管理" + ], + "summary": "获取指定用户的操作历史", + "parameters": [ + { + "type": "integer", + "description": "用户ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "default": 1, + "description": "页码", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "default": 10, + "description": "每页大小", + "name": "page_size", + "in": "query" + }, + { + "type": "string", + "description": "按操作类型过滤", + "name": "action_type", + "in": "query" + } + ], + "responses": { + "200": { + "description": "业务码为200代表成功获取", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/controller.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/user.ListHistoryResponse" + } + } + } + ] + } + } + } + } } }, "definitions": { @@ -560,7 +1017,11 @@ "properties": { "code": { "description": "业务状态码", - "type": "integer" + "allOf": [ + { + "$ref": "#/definitions/controller.ResponseCode" + } + ] }, "data": { "description": "业务数据" @@ -571,63 +1032,50 @@ } } }, - "device.CreateDeviceRequest": { - "type": "object", - "required": [ - "name", - "type" + "controller.ResponseCode": { + "type": "integer", + "enum": [ + 2000, + 2001, + 4000, + 4001, + 4004, + 4009, + 5000, + 5003 ], - "properties": { - "location": { - "type": "string" - }, - "name": { - "type": "string" - }, - "parent_id": { - "type": "integer" - }, - "properties": { - "type": "object", - "additionalProperties": true - }, - "sub_type": { - "$ref": "#/definitions/models.DeviceSubType" - }, - "type": { - "$ref": "#/definitions/models.DeviceType" - } - } - }, - "device.UpdateDeviceRequest": { - "type": "object", - "required": [ - "name", - "type" + "x-enum-comments": { + "CodeBadRequest": "请求参数错误", + "CodeConflict": "资源冲突", + "CodeCreated": "创建成功", + "CodeInternalError": "服务器内部错误", + "CodeNotFound": "资源未找到", + "CodeServiceUnavailable": "服务不可用", + "CodeSuccess": "操作成功", + "CodeUnauthorized": "未授权" + }, + "x-enum-descriptions": [ + "操作成功", + "创建成功", + "请求参数错误", + "未授权", + "资源未找到", + "资源冲突", + "服务器内部错误", + "服务不可用" ], - "properties": { - "location": { - "type": "string" - }, - "name": { - "type": "string" - }, - "parent_id": { - "type": "integer" - }, - "properties": { - "type": "object", - "additionalProperties": true - }, - "sub_type": { - "$ref": "#/definitions/models.DeviceSubType" - }, - "type": { - "$ref": "#/definitions/models.DeviceType" - } - } + "x-enum-varnames": [ + "CodeSuccess", + "CodeCreated", + "CodeBadRequest", + "CodeUnauthorized", + "CodeNotFound", + "CodeConflict", + "CodeInternalError", + "CodeServiceUnavailable" + ] }, - "git_huangwc_com_pig_pig-farm-controller_internal_app_controller_device.DeviceResponse": { + "device.AreaControllerResponse": { "type": "object", "properties": { "created_at": { @@ -642,54 +1090,262 @@ "name": { "type": "string" }, - "parent_id": { - "type": "integer" + "network_id": { + "type": "string" }, "properties": { "type": "object", "additionalProperties": true }, - "sub_type": { - "$ref": "#/definitions/models.DeviceSubType" - }, - "type": { - "$ref": "#/definitions/models.DeviceType" + "status": { + "type": "string" }, "updated_at": { "type": "string" } } }, - "models.DeviceSubType": { - "type": "string", - "enum": [ - "", - "temperature", - "humidity", - "ammonia", - "feed_valve", - "fan", - "water_curtain" + "device.CreateAreaControllerRequest": { + "type": "object", + "required": [ + "name", + "network_id" ], - "x-enum-varnames": [ - "SubTypeNone", - "SubTypeSensorTemp", - "SubTypeSensorHumidity", - "SubTypeSensorAmmonia", - "SubTypeValveFeed", - "SubTypeFan", - "SubTypeWaterCurtain" - ] + "properties": { + "location": { + "type": "string" + }, + "name": { + "type": "string" + }, + "network_id": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + } + } }, - "models.DeviceType": { + "device.CreateDeviceRequest": { + "type": "object", + "required": [ + "area_controller_id", + "device_template_id", + "name" + ], + "properties": { + "area_controller_id": { + "type": "integer" + }, + "device_template_id": { + "type": "integer" + }, + "location": { + "type": "string" + }, + "name": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + } + } + }, + "device.CreateDeviceTemplateRequest": { + "type": "object", + "required": [ + "category", + "commands", + "name" + ], + "properties": { + "category": { + "$ref": "#/definitions/models.DeviceCategory" + }, + "commands": { + "type": "object", + "additionalProperties": true + }, + "description": { + "type": "string" + }, + "manufacturer": { + "type": "string" + }, + "name": { + "type": "string" + }, + "values": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ValueDescriptor" + } + } + } + }, + "device.DeviceTemplateResponse": { + "type": "object", + "properties": { + "category": { + "$ref": "#/definitions/models.DeviceCategory" + }, + "commands": { + "type": "object", + "additionalProperties": true + }, + "created_at": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "manufacturer": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updated_at": { + "type": "string" + }, + "values": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ValueDescriptor" + } + } + } + }, + "device.UpdateAreaControllerRequest": { + "type": "object", + "required": [ + "name", + "network_id" + ], + "properties": { + "location": { + "type": "string" + }, + "name": { + "type": "string" + }, + "network_id": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + } + } + }, + "device.UpdateDeviceRequest": { + "type": "object", + "required": [ + "area_controller_id", + "device_template_id", + "name" + ], + "properties": { + "area_controller_id": { + "type": "integer" + }, + "device_template_id": { + "type": "integer" + }, + "location": { + "type": "string" + }, + "name": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + } + } + }, + "device.UpdateDeviceTemplateRequest": { + "type": "object", + "required": [ + "category", + "commands", + "name" + ], + "properties": { + "category": { + "$ref": "#/definitions/models.DeviceCategory" + }, + "commands": { + "type": "object", + "additionalProperties": true + }, + "description": { + "type": "string" + }, + "manufacturer": { + "type": "string" + }, + "name": { + "type": "string" + }, + "values": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ValueDescriptor" + } + } + } + }, + "git_huangwc_com_pig_pig-farm-controller_internal_app_controller_device.DeviceResponse": { + "type": "object", + "properties": { + "area_controller_id": { + "type": "integer" + }, + "area_controller_name": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "device_template_id": { + "type": "integer" + }, + "device_template_name": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "location": { + "type": "string" + }, + "name": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "updated_at": { + "type": "string" + } + } + }, + "models.DeviceCategory": { "type": "string", "enum": [ - "area_controller", - "device" + "actuator", + "sensor" ], "x-enum-varnames": [ - "DeviceTypeAreaController", - "DeviceTypeDevice" + "CategoryActuator", + "CategorySensor" ] }, "models.PlanContentType": { @@ -736,59 +1392,105 @@ "enum": [ 0, 1, - 2 + 2, + 3 ], "x-enum-comments": { "PlanStatusDisabled": "禁用计划", "PlanStatusEnabled": "启用计划", + "PlanStatusFailed": "执行失败", "PlanStatusStopeed": "执行完毕" }, "x-enum-descriptions": [ - "启用计划", "禁用计划", - "执行完毕" + "启用计划", + "执行完毕", + "执行失败" ], "x-enum-varnames": [ - "PlanStatusEnabled", "PlanStatusDisabled", - "PlanStatusStopeed" + "PlanStatusEnabled", + "PlanStatusStopeed", + "PlanStatusFailed" + ] + }, + "models.SensorType": { + "type": "string", + "enum": [ + "signal_metrics", + "battery_level", + "temperature", + "humidity", + "weight" + ], + "x-enum-comments": { + "SensorTypeBatteryLevel": "电池电量", + "SensorTypeHumidity": "湿度", + "SensorTypeSignalMetrics": "信号强度", + "SensorTypeTemperature": "温度", + "SensorTypeWeight": "重量" + }, + "x-enum-descriptions": [ + "信号强度", + "电池电量", + "温度", + "湿度", + "重量" + ], + "x-enum-varnames": [ + "SensorTypeSignalMetrics", + "SensorTypeBatteryLevel", + "SensorTypeTemperature", + "SensorTypeHumidity", + "SensorTypeWeight" ] }, "models.TaskType": { "type": "string", "enum": [ "plan_analysis", - "waiting" + "waiting", + "release_feed_weight" ], "x-enum-comments": { "TaskPlanAnalysis": "解析Plan的Task列表并添加到待执行队列的特殊任务", + "TaskTypeReleaseFeedWeight": "下料口释放指定重量任务", "TaskTypeWaiting": "等待任务" }, "x-enum-descriptions": [ "解析Plan的Task列表并添加到待执行队列的特殊任务", - "等待任务" + "等待任务", + "下料口释放指定重量任务" ], "x-enum-varnames": [ "TaskPlanAnalysis", - "TaskTypeWaiting" + "TaskTypeWaiting", + "TaskTypeReleaseFeedWeight" ] }, + "models.ValueDescriptor": { + "type": "object", + "properties": { + "multiplier": { + "description": "乘数,用于原始数据转换", + "type": "number" + }, + "offset": { + "description": "偏移量,用于原始数据转换", + "type": "number" + }, + "type": { + "$ref": "#/definitions/models.SensorType" + } + } + }, "plan.CreatePlanRequest": { "type": "object", "required": [ - "content_type", "execution_type", "name" ], "properties": { - "content_type": { - "allOf": [ - { - "$ref": "#/definitions/models.PlanContentType" - } - ], - "example": "tasks" - }, "cron_expression": { "type": "string", "example": "0 0 6 * * *" @@ -1000,14 +1702,6 @@ "plan.UpdatePlanRequest": { "type": "object", "properties": { - "content_type": { - "allOf": [ - { - "$ref": "#/definitions/models.PlanContentType" - } - ], - "example": "tasks" - }, "cron_expression": { "type": "string", "example": "0 0 6 * * *" @@ -1077,16 +1771,24 @@ } } }, - "user.LoginRequest": { + "user.HistoryResponse": { "type": "object", - "required": [ - "password", - "username" - ], "properties": { - "password": { + "action_type": { "type": "string", - "example": "password123" + "example": "更新设备" + }, + "description": { + "type": "string", + "example": "设备更新成功" + }, + "target_resource": {}, + "time": { + "type": "string" + }, + "user_id": { + "type": "integer", + "example": 101 }, "username": { "type": "string", @@ -1094,6 +1796,39 @@ } } }, + "user.ListHistoryResponse": { + "type": "object", + "properties": { + "history": { + "type": "array", + "items": { + "$ref": "#/definitions/user.HistoryResponse" + } + }, + "total": { + "type": "integer", + "example": 100 + } + } + }, + "user.LoginRequest": { + "type": "object", + "required": [ + "identifier", + "password" + ], + "properties": { + "identifier": { + "description": "Identifier 可以是用户名、邮箱、手机号、微信号或飞书账号", + "type": "string", + "example": "testuser" + }, + "password": { + "type": "string", + "example": "password123" + } + } + }, "user.LoginResponse": { "type": "object", "properties": { diff --git a/src/api/device.js b/src/api/device.js index de076251..c5eb8b9c 100644 --- a/src/api/device.js +++ b/src/api/device.js @@ -1,7 +1,57 @@ import http from '../utils/http.js'; /** - * 设备管理API + * 区域主控管理API + */ +export class AreaControllerApi { + /** + * 获取区域主控列表 + * @returns {Promise} 区域主控列表 + */ + static list() { + return http.get('/api/v1/area-controllers'); + } + + /** + * 创建新区域主控 + * @param {Object} areaControllerData 区域主控数据 + * @returns {Promise} 创建结果 + */ + static create(areaControllerData) { + return http.post('/api/v1/area-controllers', areaControllerData); + } + + /** + * 获取区域主控详情 + * @param {string|number} id 区域主控ID + * @returns {Promise} 区域主控详情 + */ + static get(id) { + return http.get(`/api/v1/area-controllers/${id}`); + } + + /** + * 更新区域主控信息 + * @param {string|number} id 区域主控ID + * @param {Object} areaControllerData 区域主控数据 + * @returns {Promise} 更新结果 + */ + static update(id, areaControllerData) { + return http.put(`/api/v1/area-controllers/${id}`, areaControllerData); + } + + /** + * 删除区域主控 + * @param {string|number} id 区域主控ID + * @returns {Promise} 删除结果 + */ + static delete(id) { + return http.delete(`/api/v1/area-controllers/${id}`); + } +} + +/** + * 普通设备管理API */ export class DeviceApi { /** @@ -49,5 +99,3 @@ export class DeviceApi { return http.delete(`/api/v1/devices/${id}`); } } - -export default DeviceApi; \ No newline at end of file diff --git a/src/api/index.js b/src/api/index.js index f21ed065..1a529417 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -1,4 +1,4 @@ -import DeviceApi from './device.js'; +import { AreaControllerApi, DeviceApi } from './device.js'; import PlanApi from './plan.js'; import UserApi from './user.js'; @@ -7,6 +7,7 @@ import UserApi from './user.js'; */ export class ApiClient { constructor() { + this.areaControllers = AreaControllerApi; this.devices = DeviceApi; this.plans = PlanApi; this.users = UserApi; diff --git a/src/components/DeviceForm.vue b/src/components/DeviceForm.vue index 4554f3ef..99dc0f1d 100644 --- a/src/components/DeviceForm.vue +++ b/src/components/DeviceForm.vue @@ -14,32 +14,32 @@ @submit.prevent > - + - - + + - +
- - + +
- - + + - - - - - - - - + + + + + + + + + - + - + - +