Compare commits
26 Commits
accbb1a9f6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| fff309f56b | |||
| d3700c8835 | |||
| ea44c9caea | |||
| ab8ea6977f | |||
| d5f91b9b12 | |||
| a8d9b033f3 | |||
| e1fb3055bb | |||
| 6d452394aa | |||
| 62801326cb | |||
| ee2f3e12d2 | |||
| e341e53fe2 | |||
| 03eed8202b | |||
| 624592a63d | |||
| 2191bf2bdf | |||
| d7d68684e4 | |||
| d85cfb303b | |||
| 2e5c04d2d4 | |||
| 2fe6f0c576 | |||
| c176fadafe | |||
| ced688a7a3 | |||
| 263af9fa3a | |||
| 1a55330734 | |||
| 0026f24002 | |||
| 2d6bb69387 | |||
| 70e3a4f2b0 | |||
| 98cd24ee29 |
@@ -970,6 +970,149 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/monitor/notifications": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "根据提供的过滤条件,分页获取通知列表",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"数据监控"
|
||||||
|
],
|
||||||
|
"summary": "批量查询通知",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"name": "end_time",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enum": [
|
||||||
|
7,
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
-1,
|
||||||
|
5,
|
||||||
|
6
|
||||||
|
],
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"_numLevels",
|
||||||
|
"DebugLevel",
|
||||||
|
"InfoLevel",
|
||||||
|
"WarnLevel",
|
||||||
|
"ErrorLevel",
|
||||||
|
"DPanicLevel",
|
||||||
|
"PanicLevel",
|
||||||
|
"FatalLevel",
|
||||||
|
"_minLevel",
|
||||||
|
"_maxLevel",
|
||||||
|
"InvalidLevel"
|
||||||
|
],
|
||||||
|
"name": "level",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enum": [
|
||||||
|
"邮件",
|
||||||
|
"企业微信",
|
||||||
|
"飞书",
|
||||||
|
"日志"
|
||||||
|
],
|
||||||
|
"type": "string",
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"NotifierTypeSMTP",
|
||||||
|
"NotifierTypeWeChat",
|
||||||
|
"NotifierTypeLark",
|
||||||
|
"NotifierTypeLog"
|
||||||
|
],
|
||||||
|
"name": "notifier_type",
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enum": [
|
||||||
|
"发送成功",
|
||||||
|
"发送失败",
|
||||||
|
"已跳过"
|
||||||
|
],
|
||||||
|
"type": "string",
|
||||||
|
"x-enum-comments": {
|
||||||
|
"NotificationStatusFailed": "通知发送失败",
|
||||||
|
"NotificationStatusSkipped": "通知因某些原因被跳过(例如:用户未配置联系方式)",
|
||||||
|
"NotificationStatusSuccess": "通知已成功发送"
|
||||||
|
},
|
||||||
|
"x-enum-descriptions": [
|
||||||
|
"通知已成功发送",
|
||||||
|
"通知发送失败",
|
||||||
|
"通知因某些原因被跳过(例如:用户未配置联系方式)"
|
||||||
|
],
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"NotificationStatusSuccess",
|
||||||
|
"NotificationStatusFailed",
|
||||||
|
"NotificationStatusSkipped"
|
||||||
|
],
|
||||||
|
"name": "status",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"name": "user_id",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/controller.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/definitions/dto.ListNotificationResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/monitor/pending-collections": {
|
"/api/v1/monitor/pending-collections": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -3918,6 +4061,64 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/users/{id}/notifications/test": {
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "为指定用户发送一条特定渠道的测试消息,以验证其配置是否正确。",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"用户管理"
|
||||||
|
],
|
||||||
|
"summary": "发送测试通知",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "用户ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "请求体",
|
||||||
|
"name": "body",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/dto.SendTestNotificationRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "成功响应",
|
||||||
|
"schema": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/controller.Response"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
@@ -4426,6 +4627,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dto.ListNotificationResponse": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"list": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/dto.NotificationDTO"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pagination": {
|
||||||
|
"$ref": "#/definitions/dto.PaginationDTO"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dto.ListPendingCollectionResponse": {
|
"dto.ListPendingCollectionResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -4734,6 +4949,47 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dto.NotificationDTO": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"alarm_timestamp": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"error_message": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"level": {
|
||||||
|
"$ref": "#/definitions/zapcore.Level"
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"notifier_type": {
|
||||||
|
"$ref": "#/definitions/notify.NotifierType"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"$ref": "#/definitions/models.NotificationStatus"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"to_address": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dto.PaginationDTO": {
|
"dto.PaginationDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -5586,6 +5842,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dto.SendTestNotificationRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"type"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"description": "Type 指定要测试的通知渠道",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/notify.NotifierType"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dto.SensorDataDTO": {
|
"dto.SensorDataDTO": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -6196,6 +6468,29 @@
|
|||||||
"ReasonTypeHealthCare"
|
"ReasonTypeHealthCare"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"models.NotificationStatus": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"发送成功",
|
||||||
|
"发送失败",
|
||||||
|
"已跳过"
|
||||||
|
],
|
||||||
|
"x-enum-comments": {
|
||||||
|
"NotificationStatusFailed": "通知发送失败",
|
||||||
|
"NotificationStatusSkipped": "通知因某些原因被跳过(例如:用户未配置联系方式)",
|
||||||
|
"NotificationStatusSuccess": "通知已成功发送"
|
||||||
|
},
|
||||||
|
"x-enum-descriptions": [
|
||||||
|
"通知已成功发送",
|
||||||
|
"通知发送失败",
|
||||||
|
"通知因某些原因被跳过(例如:用户未配置联系方式)"
|
||||||
|
],
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"NotificationStatusSuccess",
|
||||||
|
"NotificationStatusFailed",
|
||||||
|
"NotificationStatusSkipped"
|
||||||
|
]
|
||||||
|
},
|
||||||
"models.PenStatus": {
|
"models.PenStatus": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -6525,6 +6820,51 @@
|
|||||||
"$ref": "#/definitions/models.SensorType"
|
"$ref": "#/definitions/models.SensorType"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"notify.NotifierType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"邮件",
|
||||||
|
"企业微信",
|
||||||
|
"飞书",
|
||||||
|
"日志"
|
||||||
|
],
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"NotifierTypeSMTP",
|
||||||
|
"NotifierTypeWeChat",
|
||||||
|
"NotifierTypeLark",
|
||||||
|
"NotifierTypeLog"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"zapcore.Level": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"enum": [
|
||||||
|
7,
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
-1,
|
||||||
|
5,
|
||||||
|
6
|
||||||
|
],
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"_numLevels",
|
||||||
|
"DebugLevel",
|
||||||
|
"InfoLevel",
|
||||||
|
"WarnLevel",
|
||||||
|
"ErrorLevel",
|
||||||
|
"DPanicLevel",
|
||||||
|
"PanicLevel",
|
||||||
|
"FatalLevel",
|
||||||
|
"_minLevel",
|
||||||
|
"_maxLevel",
|
||||||
|
"InvalidLevel"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
|
|||||||
@@ -1,8 +1,36 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} AreaControllerResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} network_id
|
||||||
|
* @property {string} location
|
||||||
|
* @property {string} status
|
||||||
|
* @property {object} properties
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreateAreaControllerRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} network_id
|
||||||
|
* @property {string} [location]
|
||||||
|
* @property {object} [properties]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdateAreaControllerRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} network_id
|
||||||
|
* @property {string} [location]
|
||||||
|
* @property {object} [properties]
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统中所有区域主控的列表
|
* 获取系统中所有区域主控的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<AreaControllerResponse>>}
|
||||||
*/
|
*/
|
||||||
export const getAreaControllers = () => {
|
export const getAreaControllers = () => {
|
||||||
return http.get('/api/v1/area-controllers');
|
return http.get('/api/v1/area-controllers');
|
||||||
@@ -10,8 +38,8 @@ export const getAreaControllers = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据提供的信息创建一个新区域主控
|
* 根据提供的信息创建一个新区域主控
|
||||||
* @param {object} areaControllerData - 区域主控信息,对应 dto.CreateAreaControllerRequest
|
* @param {CreateAreaControllerRequest} areaControllerData - 区域主控信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<AreaControllerResponse>}
|
||||||
*/
|
*/
|
||||||
export const createAreaController = (areaControllerData) => {
|
export const createAreaController = (areaControllerData) => {
|
||||||
return http.post('/api/v1/area-controllers', areaControllerData);
|
return http.post('/api/v1/area-controllers', areaControllerData);
|
||||||
@@ -20,7 +48,7 @@ export const createAreaController = (areaControllerData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID获取单个区域主控的详细信息
|
* 根据ID获取单个区域主控的详细信息
|
||||||
* @param {string} id - 区域主控ID
|
* @param {string} id - 区域主控ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<AreaControllerResponse>}
|
||||||
*/
|
*/
|
||||||
export const getAreaControllerById = (id) => {
|
export const getAreaControllerById = (id) => {
|
||||||
return http.get(`/api/v1/area-controllers/${id}`);
|
return http.get(`/api/v1/area-controllers/${id}`);
|
||||||
@@ -29,8 +57,8 @@ export const getAreaControllerById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID更新一个已存在的区域主控信息
|
* 根据ID更新一个已存在的区域主控信息
|
||||||
* @param {string} id - 区域主控ID
|
* @param {string} id - 区域主控ID
|
||||||
* @param {object} areaControllerData - 要更新的区域主控信息,对应 dto.UpdateAreaControllerRequest
|
* @param {UpdateAreaControllerRequest} areaControllerData - 要更新的区域主控信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<AreaControllerResponse>}
|
||||||
*/
|
*/
|
||||||
export const updateAreaController = (id, areaControllerData) => {
|
export const updateAreaController = (id, areaControllerData) => {
|
||||||
return http.put(`/api/v1/area-controllers/${id}`, areaControllerData);
|
return http.put(`/api/v1/area-controllers/${id}`, areaControllerData);
|
||||||
|
|||||||
@@ -1,10 +1,78 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
// --- Typedefs ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} DeviceResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} location
|
||||||
|
* @property {number} area_controller_id
|
||||||
|
* @property {string} area_controller_name
|
||||||
|
* @property {number} device_template_id
|
||||||
|
* @property {string} device_template_name
|
||||||
|
* @property {object} properties
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreateDeviceRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [location]
|
||||||
|
* @property {number} area_controller_id
|
||||||
|
* @property {number} device_template_id
|
||||||
|
* @property {object} [properties]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdateDeviceRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [location]
|
||||||
|
* @property {number} area_controller_id
|
||||||
|
* @property {number} device_template_id
|
||||||
|
* @property {object} [properties]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ManualControlDeviceRequest
|
||||||
|
* @property {string} [action] - Action 不传表示这是一个传感器, 会触发一次采集
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} AreaControllerResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} network_id
|
||||||
|
* @property {string} location
|
||||||
|
* @property {string} status
|
||||||
|
* @property {object} properties
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreateAreaControllerRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} network_id
|
||||||
|
* @property {string} [location]
|
||||||
|
* @property {object} [properties]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdateAreaControllerRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} network_id
|
||||||
|
* @property {string} [location]
|
||||||
|
* @property {object} [properties]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// --- Device API Functions ---
|
// --- Device API Functions ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统中所有设备的列表
|
* 获取系统中所有设备的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<DeviceResponse>>}
|
||||||
*/
|
*/
|
||||||
export const getDevices = () => {
|
export const getDevices = () => {
|
||||||
return http.get('/api/v1/devices');
|
return http.get('/api/v1/devices');
|
||||||
@@ -12,8 +80,8 @@ export const getDevices = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据提供的信息创建一个新设备
|
* 根据提供的信息创建一个新设备
|
||||||
* @param {object} deviceData - 设备信息,对应 dto.CreateDeviceRequest
|
* @param {CreateDeviceRequest} deviceData - 设备信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<DeviceResponse>}
|
||||||
*/
|
*/
|
||||||
export const createDevice = (deviceData) => {
|
export const createDevice = (deviceData) => {
|
||||||
return http.post('/api/v1/devices', deviceData);
|
return http.post('/api/v1/devices', deviceData);
|
||||||
@@ -22,7 +90,7 @@ export const createDevice = (deviceData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据设备ID获取单个设备的详细信息
|
* 根据设备ID获取单个设备的详细信息
|
||||||
* @param {string} id - 设备ID
|
* @param {string} id - 设备ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<DeviceResponse>}
|
||||||
*/
|
*/
|
||||||
export const getDeviceById = (id) => {
|
export const getDeviceById = (id) => {
|
||||||
return http.get(`/api/v1/devices/${id}`);
|
return http.get(`/api/v1/devices/${id}`);
|
||||||
@@ -31,8 +99,8 @@ export const getDeviceById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 根据设备ID更新一个已存在的设备信息
|
* 根据设备ID更新一个已存在的设备信息
|
||||||
* @param {string} id - 设备ID
|
* @param {string} id - 设备ID
|
||||||
* @param {object} deviceData - 要更新的设备信息,对应 dto.UpdateDeviceRequest
|
* @param {UpdateDeviceRequest} deviceData - 要更新的设备信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<DeviceResponse>}
|
||||||
*/
|
*/
|
||||||
export const updateDevice = (id, deviceData) => {
|
export const updateDevice = (id, deviceData) => {
|
||||||
return http.put(`/api/v1/devices/${id}`, deviceData);
|
return http.put(`/api/v1/devices/${id}`, deviceData);
|
||||||
@@ -50,7 +118,7 @@ export const deleteDevice = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 根据设备ID和指定的动作(开启或关闭)来手动控制设备
|
* 根据设备ID和指定的动作(开启或关闭)来手动控制设备
|
||||||
* @param {string} id - 设备ID
|
* @param {string} id - 设备ID
|
||||||
* @param {object} manualControlData - 手动控制指令,对应 dto.ManualControlDeviceRequest
|
* @param {ManualControlDeviceRequest} manualControlData - 手动控制指令
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const manualControlDevice = (id, manualControlData) => {
|
export const manualControlDevice = (id, manualControlData) => {
|
||||||
@@ -62,7 +130,7 @@ export const manualControlDevice = (id, manualControlData) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统中所有区域主控的列表
|
* 获取系统中所有区域主控的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<AreaControllerResponse>>}
|
||||||
*/
|
*/
|
||||||
export const getAreaControllers = () => {
|
export const getAreaControllers = () => {
|
||||||
return http.get('/api/v1/area-controllers');
|
return http.get('/api/v1/area-controllers');
|
||||||
@@ -70,8 +138,8 @@ export const getAreaControllers = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新区域主控
|
* 创建一个新区域主控
|
||||||
* @param {object} areaControllerData - 区域主控信息
|
* @param {CreateAreaControllerRequest} areaControllerData - 区域主控信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<AreaControllerResponse>}
|
||||||
*/
|
*/
|
||||||
export const createAreaController = (areaControllerData) => {
|
export const createAreaController = (areaControllerData) => {
|
||||||
return http.post('/api/v1/area-controllers', areaControllerData);
|
return http.post('/api/v1/area-controllers', areaControllerData);
|
||||||
@@ -80,7 +148,7 @@ export const createAreaController = (areaControllerData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID获取单个区域主控的详细信息
|
* 根据ID获取单个区域主控的详细信息
|
||||||
* @param {string} id - 区域主控ID
|
* @param {string} id - 区域主控ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<AreaControllerResponse>}
|
||||||
*/
|
*/
|
||||||
export const getAreaControllerById = (id) => {
|
export const getAreaControllerById = (id) => {
|
||||||
return http.get(`/api/v1/area-controllers/${id}`);
|
return http.get(`/api/v1/area-controllers/${id}`);
|
||||||
@@ -89,8 +157,8 @@ export const getAreaControllerById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID更新一个已存在的区域主控信息
|
* 根据ID更新一个已存在的区域主控信息
|
||||||
* @param {string} id - 区域主控ID
|
* @param {string} id - 区域主控ID
|
||||||
* @param {object} areaControllerData - 要更新的区域主控信息
|
* @param {UpdateAreaControllerRequest} areaControllerData - 要更新的区域主控信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<AreaControllerResponse>}
|
||||||
*/
|
*/
|
||||||
export const updateAreaController = (id, areaControllerData) => {
|
export const updateAreaController = (id, areaControllerData) => {
|
||||||
return http.put(`/api/v1/area-controllers/${id}`, areaControllerData);
|
return http.put(`/api/v1/area-controllers/${id}`, areaControllerData);
|
||||||
@@ -123,5 +191,6 @@ export const DeviceApi = {
|
|||||||
create: createDevice,
|
create: createDevice,
|
||||||
getById: getDeviceById,
|
getById: getDeviceById,
|
||||||
update: updateDevice,
|
update: updateDevice,
|
||||||
delete: deleteDevice
|
delete: deleteDevice,
|
||||||
|
manualControl: manualControlDevice
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,57 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('执行器'|'传感器')} DeviceCategory
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('信号强度'|'电池电量'|'温度'|'湿度'|'重量')} SensorType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ValueDescriptor
|
||||||
|
* @property {SensorType} type
|
||||||
|
* @property {number} [multiplier] - 乘数,用于原始数据转换
|
||||||
|
* @property {number} [offset] - 偏移量,用于原始数据转换
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} DeviceTemplateResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [description]
|
||||||
|
* @property {string} [manufacturer]
|
||||||
|
* @property {DeviceCategory} category
|
||||||
|
* @property {object} commands
|
||||||
|
* @property {Array<ValueDescriptor>} values
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreateDeviceTemplateRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [description]
|
||||||
|
* @property {string} [manufacturer]
|
||||||
|
* @property {DeviceCategory} category
|
||||||
|
* @property {object} commands
|
||||||
|
* @property {Array<ValueDescriptor>} [values]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdateDeviceTemplateRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [description]
|
||||||
|
* @property {string} [manufacturer]
|
||||||
|
* @property {DeviceCategory} category
|
||||||
|
* @property {object} commands
|
||||||
|
* @property {Array<ValueDescriptor>} [values]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统中所有设备模板的列表
|
* 获取系统中所有设备模板的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<DeviceTemplateResponse>>}
|
||||||
*/
|
*/
|
||||||
const getDeviceTemplates = () => {
|
const getDeviceTemplates = () => {
|
||||||
return http.get('/api/v1/device-templates');
|
return http.get('/api/v1/device-templates');
|
||||||
@@ -10,8 +59,8 @@ const getDeviceTemplates = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据提供的信息创建一个新设备模板
|
* 根据提供的信息创建一个新设备模板
|
||||||
* @param {object} deviceTemplateData - 设备模板信息,对应 dto.CreateDeviceTemplateRequest
|
* @param {CreateDeviceTemplateRequest} deviceTemplateData - 设备模板信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<DeviceTemplateResponse>}
|
||||||
*/
|
*/
|
||||||
const createDeviceTemplate = (deviceTemplateData) => {
|
const createDeviceTemplate = (deviceTemplateData) => {
|
||||||
return http.post('/api/v1/device-templates', deviceTemplateData);
|
return http.post('/api/v1/device-templates', deviceTemplateData);
|
||||||
@@ -20,7 +69,7 @@ const createDeviceTemplate = (deviceTemplateData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据设备模板ID获取单个设备模板的详细信息
|
* 根据设备模板ID获取单个设备模板的详细信息
|
||||||
* @param {string} id - 设备模板ID
|
* @param {string} id - 设备模板ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<DeviceTemplateResponse>}
|
||||||
*/
|
*/
|
||||||
const getDeviceTemplateById = (id) => {
|
const getDeviceTemplateById = (id) => {
|
||||||
return http.get(`/api/v1/device-templates/${id}`);
|
return http.get(`/api/v1/device-templates/${id}`);
|
||||||
@@ -29,8 +78,8 @@ const getDeviceTemplateById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 根据设备模板ID更新一个已存在的设备模板信息
|
* 根据设备模板ID更新一个已存在的设备模板信息
|
||||||
* @param {string} id - 设备模板ID
|
* @param {string} id - 设备模板ID
|
||||||
* @param {object} deviceTemplateData - 要更新的设备模板信息,对应 dto.UpdateDeviceTemplateRequest
|
* @param {UpdateDeviceTemplateRequest} deviceTemplateData - 要更新的设备模板信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<DeviceTemplateResponse>}
|
||||||
*/
|
*/
|
||||||
const updateDeviceTemplate = (id, deviceTemplateData) => {
|
const updateDeviceTemplate = (id, deviceTemplateData) => {
|
||||||
return http.put(`/api/v1/device-templates/${id}`, deviceTemplateData);
|
return http.put(`/api/v1/device-templates/${id}`, deviceTemplateData);
|
||||||
|
|||||||
@@ -1,30 +1,695 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
// 这个辅助函数现在接收后端返回的JSON数据本身,而不是整个axios响应
|
// --- Typedefs ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PaginationDTO
|
||||||
|
* @property {number} page
|
||||||
|
* @property {number} pageSize
|
||||||
|
* @property {number} total
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} DeviceCommandLogDTO
|
||||||
|
* @property {string} message_id
|
||||||
|
* @property {number} device_id
|
||||||
|
* @property {string} sent_at
|
||||||
|
* @property {string} acknowledged_at
|
||||||
|
* @property {boolean} received_success
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListDeviceCommandLogResponse
|
||||||
|
* @property {Array<DeviceCommandLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} DeviceCommandLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [device_id]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {boolean} [received_success]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} FeedFormulaDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PenDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} FeedUsageRecordDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pen_id
|
||||||
|
* @property {PenDTO} pen
|
||||||
|
* @property {number} feed_formula_id
|
||||||
|
* @property {FeedFormulaDTO} feed_formula
|
||||||
|
* @property {number} amount
|
||||||
|
* @property {string} recorded_at
|
||||||
|
* @property {string} remarks
|
||||||
|
* @property {number} operator_id
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListFeedUsageRecordResponse
|
||||||
|
* @property {Array<FeedUsageRecordDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} FeedUsageRecordsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pen_id]
|
||||||
|
* @property {number} [feed_formula_id]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('预防'|'治疗'|'保健')} MedicationReasonType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} MedicationDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} MedicationLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {number} medication_id
|
||||||
|
* @property {MedicationDTO} medication
|
||||||
|
* @property {number} dosage_used
|
||||||
|
* @property {number} target_count
|
||||||
|
* @property {MedicationReasonType} reason
|
||||||
|
* @property {string} description
|
||||||
|
* @property {string} happened_at
|
||||||
|
* @property {number} operator_id
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListMedicationLogResponse
|
||||||
|
* @property {Array<MedicationLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} MedicationLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {number} [medication_id]
|
||||||
|
* @property {string} [reason]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('发送成功'|'发送失败'|'已跳过')} NotificationStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} NotificationDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} user_id
|
||||||
|
* @property {NotifierType} notifier_type
|
||||||
|
* @property {string} to_address
|
||||||
|
* @property {string} title
|
||||||
|
* @property {string} message
|
||||||
|
* @property {number} level - 日志级别, 见 ZapcoreLevel 枚举
|
||||||
|
* @property {string} alarm_timestamp
|
||||||
|
* @property {NotificationStatus} status
|
||||||
|
* @property {string} error_message
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListNotificationResponse
|
||||||
|
* @property {Array<NotificationDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} NotificationsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [level] - 日志级别, 见 ZapcoreLevel 枚举
|
||||||
|
* @property {NotifierType} [notifier_type]
|
||||||
|
* @property {NotificationStatus} [status]
|
||||||
|
* @property {number} [user_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('等待中'|'已完成'|'已超时')} PendingCollectionStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PendingCollectionDTO
|
||||||
|
* @property {string} correlation_id
|
||||||
|
* @property {number} device_id
|
||||||
|
* @property {Array<number>} command_metadata
|
||||||
|
* @property {PendingCollectionStatus} status
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} fulfilled_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPendingCollectionResponse
|
||||||
|
* @property {Array<PendingCollectionDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PendingCollectionsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [device_id]
|
||||||
|
* @property {string} [status]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('死亡'|'淘汰'|'销售'|'购买'|'转入'|'转出'|'盘点校正')} LogChangeType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigBatchLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {LogChangeType} change_type
|
||||||
|
* @property {number} before_count
|
||||||
|
* @property {number} after_count
|
||||||
|
* @property {number} change_count
|
||||||
|
* @property {string} reason
|
||||||
|
* @property {number} operator_id
|
||||||
|
* @property {string} happened_at
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPigBatchLogResponse
|
||||||
|
* @property {Array<PigBatchLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigBatchLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {string} [change_type]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigPurchaseDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {number} quantity
|
||||||
|
* @property {number} unit_price
|
||||||
|
* @property {number} total_price
|
||||||
|
* @property {string} supplier
|
||||||
|
* @property {string} purchase_date
|
||||||
|
* @property {string} remarks
|
||||||
|
* @property {number} operator_id
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPigPurchaseResponse
|
||||||
|
* @property {Array<PigPurchaseDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigPurchasesParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {string} [supplier]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigSaleDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {number} quantity
|
||||||
|
* @property {number} unit_price
|
||||||
|
* @property {number} total_price
|
||||||
|
* @property {string} buyer
|
||||||
|
* @property {string} sale_date
|
||||||
|
* @property {string} remarks
|
||||||
|
* @property {number} operator_id
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPigSaleResponse
|
||||||
|
* @property {Array<PigSaleDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigSalesParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {string} [buyer]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('患病'|'康复'|'死亡'|'淘汰'|'转入'|'转出'|'其他')} PigBatchSickPigReasonType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('原地治疗'|'病猪栏治疗')} PigBatchSickPigTreatmentLocation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigSickLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {number} pen_id
|
||||||
|
* @property {PigBatchSickPigReasonType} reason
|
||||||
|
* @property {PigBatchSickPigTreatmentLocation} treatment_location
|
||||||
|
* @property {number} before_count
|
||||||
|
* @property {number} after_count
|
||||||
|
* @property {number} change_count
|
||||||
|
* @property {string} remarks
|
||||||
|
* @property {number} operator_id
|
||||||
|
* @property {string} happened_at
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPigSickLogResponse
|
||||||
|
* @property {Array<PigSickLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigSickLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {number} [pen_id]
|
||||||
|
* @property {string} [reason]
|
||||||
|
* @property {string} [treatment_location]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('群内调栏'|'跨群调栏'|'销售'|'死亡'|'淘汰'|'新购入'|'产房转入')} PigTransferType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigTransferLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {number} pen_id
|
||||||
|
* @property {PigTransferType} type
|
||||||
|
* @property {number} quantity
|
||||||
|
* @property {string} remarks
|
||||||
|
* @property {string} correlation_id
|
||||||
|
* @property {number} operator_id
|
||||||
|
* @property {string} transfer_time
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPigTransferLogResponse
|
||||||
|
* @property {Array<PigTransferLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigTransferLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {number} [pen_id]
|
||||||
|
* @property {string} [transfer_type]
|
||||||
|
* @property {string} [correlation_id]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('已开始'|'已完成'|'失败'|'已取消'|'等待中')} ExecutionStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PlanExecutionLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} plan_id
|
||||||
|
* @property {ExecutionStatus} status
|
||||||
|
* @property {string} started_at
|
||||||
|
* @property {string} ended_at
|
||||||
|
* @property {string} error
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListPlanExecutionLogResponse
|
||||||
|
* @property {Array<PlanExecutionLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PlanExecutionLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [plan_id]
|
||||||
|
* @property {string} [status]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RawMaterialDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RawMaterialPurchaseDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} raw_material_id
|
||||||
|
* @property {RawMaterialDTO} raw_material
|
||||||
|
* @property {number} amount
|
||||||
|
* @property {number} unit_price
|
||||||
|
* @property {number} total_price
|
||||||
|
* @property {string} supplier
|
||||||
|
* @property {string} purchase_date
|
||||||
|
* @property {string} created_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListRawMaterialPurchaseResponse
|
||||||
|
* @property {Array<RawMaterialPurchaseDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RawMaterialPurchasesParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [raw_material_id]
|
||||||
|
* @property {string} [supplier]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('采购入库'|'饲喂出库'|'变质出库'|'售卖出库'|'杂用领取'|'手动盘点')} StockLogSourceType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RawMaterialStockLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} raw_material_id
|
||||||
|
* @property {number} change_amount
|
||||||
|
* @property {StockLogSourceType} source_type
|
||||||
|
* @property {number} source_id
|
||||||
|
* @property {string} remarks
|
||||||
|
* @property {string} happened_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListRawMaterialStockLogResponse
|
||||||
|
* @property {Array<RawMaterialStockLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RawMaterialStockLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [raw_material_id]
|
||||||
|
* @property {string} [source_type]
|
||||||
|
* @property {number} [source_id]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('信号强度'|'电池电量'|'温度'|'湿度'|'重量')} SensorType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} SensorDataDTO
|
||||||
|
* @property {number} regional_controller_id
|
||||||
|
* @property {number} device_id
|
||||||
|
* @property {SensorType} sensor_type
|
||||||
|
* @property {Array<number>} data
|
||||||
|
* @property {string} time
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListSensorDataResponse
|
||||||
|
* @property {Array<SensorDataDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} SensorDataParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [device_id]
|
||||||
|
* @property {string} [sensor_type]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TaskDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} description
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TaskExecutionLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} plan_execution_log_id
|
||||||
|
* @property {number} task_id
|
||||||
|
* @property {TaskDTO} task
|
||||||
|
* @property {ExecutionStatus} status
|
||||||
|
* @property {string} output
|
||||||
|
* @property {string} started_at
|
||||||
|
* @property {string} ended_at
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListTaskExecutionLogResponse
|
||||||
|
* @property {Array<TaskExecutionLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TaskExecutionLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [plan_execution_log_id]
|
||||||
|
* @property {number} [task_id]
|
||||||
|
* @property {string} [status]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('成功'|'失败')} AuditStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UserActionLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} user_id
|
||||||
|
* @property {string} username
|
||||||
|
* @property {string} action_type
|
||||||
|
* @property {string} description
|
||||||
|
* @property {string} http_method
|
||||||
|
* @property {string} http_path
|
||||||
|
* @property {string} source_ip
|
||||||
|
* @property {Array<number>} target_resource
|
||||||
|
* @property {AuditStatus} status
|
||||||
|
* @property {string} result_details
|
||||||
|
* @property {string} time
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListUserActionLogResponse
|
||||||
|
* @property {Array<UserActionLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UserActionLogsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [user_id]
|
||||||
|
* @property {string} [username]
|
||||||
|
* @property {string} [action_type]
|
||||||
|
* @property {string} [status]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} WeighingBatchDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {string} description
|
||||||
|
* @property {string} weighing_time
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListWeighingBatchResponse
|
||||||
|
* @property {Array<WeighingBatchDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} WeighingBatchesParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [pig_batch_id]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} WeighingRecordDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} weighing_batch_id
|
||||||
|
* @property {number} pen_id
|
||||||
|
* @property {number} weight
|
||||||
|
* @property {string} remark
|
||||||
|
* @property {number} operator_id
|
||||||
|
* @property {string} weighing_time
|
||||||
|
* @property {string} created_at
|
||||||
|
* @property {string} updated_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListWeighingRecordResponse
|
||||||
|
* @property {Array<WeighingRecordDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} WeighingRecordsParams
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [weighing_batch_id]
|
||||||
|
* @property {number} [pen_id]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {number} [operator_id]
|
||||||
|
*/
|
||||||
|
|
||||||
|
// --- Enums ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志级别, 对应后端的 zapcore.Level
|
||||||
|
* @enum {number}
|
||||||
|
*/
|
||||||
|
export const ZapcoreLevel = {
|
||||||
|
Debug: -1,
|
||||||
|
Info: 0,
|
||||||
|
Warn: 1,
|
||||||
|
Error: 2,
|
||||||
|
DPanic: 3,
|
||||||
|
Panic: 4,
|
||||||
|
Fatal: 5,
|
||||||
|
Invalid: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Functions ---
|
||||||
|
|
||||||
const processResponse = (responseData) => {
|
const processResponse = (responseData) => {
|
||||||
// 后端数据在responseData.data中
|
|
||||||
const data = responseData.data;
|
const data = responseData.data;
|
||||||
return {
|
return {
|
||||||
list: data.list || [],
|
list: data.list || [],
|
||||||
total: data.pagination.total || 0,
|
total: data.pagination ? data.pagination.total : 0,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备命令日志列表
|
* 获取设备命令日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {DeviceCommandLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<DeviceCommandLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getDeviceCommandLogs = async (params) => {
|
export const getDeviceCommandLogs = async (params) => {
|
||||||
// http.get 通常被封装为返回 response.data
|
|
||||||
const responseData = await http.get('/api/v1/monitor/device-command-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/device-command-logs', { params });
|
||||||
return processResponse(responseData);
|
return processResponse(responseData);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取饲料使用记录列表
|
* 获取饲料使用记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {FeedUsageRecordsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<FeedUsageRecordDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getFeedUsageRecords = async (params) => {
|
export const getFeedUsageRecords = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/feed-usage-records', { params });
|
const responseData = await http.get('/api/v1/monitor/feed-usage-records', { params });
|
||||||
@@ -33,18 +698,28 @@ export const getFeedUsageRecords = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用药记录列表
|
* 获取用药记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {MedicationLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<MedicationLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getMedicationLogs = async (params) => {
|
export const getMedicationLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/medication-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/medication-logs', { params });
|
||||||
return processResponse(responseData);
|
return processResponse(responseData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量查询通知
|
||||||
|
* @param {NotificationsParams} params - 查询参数
|
||||||
|
* @returns {Promise<{list: Array<NotificationDTO>, total: number}>}
|
||||||
|
*/
|
||||||
|
export const getNotifications = async (params) => {
|
||||||
|
const responseData = await http.get('/api/v1/monitor/notifications', { params });
|
||||||
|
return processResponse(responseData);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取待采集请求列表
|
* 获取待采集请求列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PendingCollectionsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PendingCollectionDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPendingCollections = async (params) => {
|
export const getPendingCollections = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/pending-collections', { params });
|
const responseData = await http.get('/api/v1/monitor/pending-collections', { params });
|
||||||
@@ -53,8 +728,8 @@ export const getPendingCollections = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取猪批次日志列表
|
* 获取猪批次日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PigBatchLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PigBatchLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPigBatchLogs = async (params) => {
|
export const getPigBatchLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/pig-batch-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/pig-batch-logs', { params });
|
||||||
@@ -63,8 +738,8 @@ export const getPigBatchLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取猪只采购记录列表
|
* 获取猪只采购记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PigPurchasesParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PigPurchaseDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPigPurchases = async (params) => {
|
export const getPigPurchases = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/pig-purchases', { params });
|
const responseData = await http.get('/api/v1/monitor/pig-purchases', { params });
|
||||||
@@ -73,8 +748,8 @@ export const getPigPurchases = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取猪只售卖记录列表
|
* 获取猪只售卖记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PigSalesParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PigSaleDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPigSales = async (params) => {
|
export const getPigSales = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/pig-sales', { params });
|
const responseData = await http.get('/api/v1/monitor/pig-sales', { params });
|
||||||
@@ -83,8 +758,8 @@ export const getPigSales = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取病猪日志列表
|
* 获取病猪日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PigSickLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PigSickLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPigSickLogs = async (params) => {
|
export const getPigSickLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/pig-sick-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/pig-sick-logs', { params });
|
||||||
@@ -93,8 +768,8 @@ export const getPigSickLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取猪只迁移日志列表
|
* 获取猪只迁移日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PigTransferLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PigTransferLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPigTransferLogs = async (params) => {
|
export const getPigTransferLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/pig-transfer-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/pig-transfer-logs', { params });
|
||||||
@@ -103,8 +778,8 @@ export const getPigTransferLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取计划执行日志列表
|
* 获取计划执行日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {PlanExecutionLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<PlanExecutionLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getPlanExecutionLogs = async (params) => {
|
export const getPlanExecutionLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/plan-execution-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/plan-execution-logs', { params });
|
||||||
@@ -113,8 +788,8 @@ export const getPlanExecutionLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取原料采购记录列表
|
* 获取原料采购记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {RawMaterialPurchasesParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<RawMaterialPurchaseDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getRawMaterialPurchases = async (params) => {
|
export const getRawMaterialPurchases = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/raw-material-purchases', { params });
|
const responseData = await http.get('/api/v1/monitor/raw-material-purchases', { params });
|
||||||
@@ -123,8 +798,8 @@ export const getRawMaterialPurchases = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取原料库存日志列表
|
* 获取原料库存日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {RawMaterialStockLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<RawMaterialStockLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getRawMaterialStockLogs = async (params) => {
|
export const getRawMaterialStockLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/raw-material-stock-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/raw-material-stock-logs', { params });
|
||||||
@@ -133,8 +808,8 @@ export const getRawMaterialStockLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取传感器数据列表
|
* 获取传感器数据列表
|
||||||
* @param {object} params - 查询参数
|
* @param {SensorDataParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<SensorDataDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getSensorData = async (params) => {
|
export const getSensorData = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/sensor-data', { params });
|
const responseData = await http.get('/api/v1/monitor/sensor-data', { params });
|
||||||
@@ -143,8 +818,8 @@ export const getSensorData = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取任务执行日志列表
|
* 获取任务执行日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {TaskExecutionLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<TaskExecutionLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getTaskExecutionLogs = async (params) => {
|
export const getTaskExecutionLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/task-execution-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/task-execution-logs', { params });
|
||||||
@@ -153,8 +828,8 @@ export const getTaskExecutionLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户操作日志列表
|
* 获取用户操作日志列表
|
||||||
* @param {object} params - 查询参数
|
* @param {UserActionLogsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<UserActionLogDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getUserActionLogs = async (params) => {
|
export const getUserActionLogs = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/user-action-logs', { params });
|
const responseData = await http.get('/api/v1/monitor/user-action-logs', { params });
|
||||||
@@ -163,8 +838,8 @@ export const getUserActionLogs = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取批次称重记录列表
|
* 获取批次称重记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {WeighingBatchesParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<WeighingBatchDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getWeighingBatches = async (params) => {
|
export const getWeighingBatches = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/weighing-batches', { params });
|
const responseData = await http.get('/api/v1/monitor/weighing-batches', { params });
|
||||||
@@ -173,8 +848,8 @@ export const getWeighingBatches = async (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单次称重记录列表
|
* 获取单次称重记录列表
|
||||||
* @param {object} params - 查询参数
|
* @param {WeighingRecordsParams} params - 查询参数
|
||||||
* @returns {Promise<{list: Array, total: number}>}
|
* @returns {Promise<{list: Array<WeighingRecordDTO>, total: number}>}
|
||||||
*/
|
*/
|
||||||
export const getWeighingRecords = async (params) => {
|
export const getWeighingRecords = async (params) => {
|
||||||
const responseData = await http.get('/api/v1/monitor/weighing-records', { params });
|
const responseData = await http.get('/api/v1/monitor/weighing-records', { params });
|
||||||
|
|||||||
@@ -1,8 +1,39 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PenResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} house_id
|
||||||
|
* @property {string} pen_number
|
||||||
|
* @property {number} capacity
|
||||||
|
* @property {number} current_pig_count
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreatePenRequest
|
||||||
|
* @property {number} house_id
|
||||||
|
* @property {string} pen_number
|
||||||
|
* @property {number} capacity
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdatePenRequest
|
||||||
|
* @property {number} house_id
|
||||||
|
* @property {string} pen_number
|
||||||
|
* @property {number} capacity
|
||||||
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdatePenStatusRequest
|
||||||
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有猪栏的列表
|
* 获取所有猪栏的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<PenResponse>>}
|
||||||
*/
|
*/
|
||||||
export const getPens = () => {
|
export const getPens = () => {
|
||||||
return http.get('/api/v1/pens');
|
return http.get('/api/v1/pens');
|
||||||
@@ -10,8 +41,8 @@ export const getPens = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的猪栏
|
* 创建一个新的猪栏
|
||||||
* @param {object} penData - 猪栏信息,对应 dto.CreatePenRequest
|
* @param {CreatePenRequest} penData - 猪栏信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PenResponse>}
|
||||||
*/
|
*/
|
||||||
export const createPen = (penData) => {
|
export const createPen = (penData) => {
|
||||||
return http.post('/api/v1/pens', penData);
|
return http.post('/api/v1/pens', penData);
|
||||||
@@ -20,7 +51,7 @@ export const createPen = (penData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID获取单个猪栏信息
|
* 根据ID获取单个猪栏信息
|
||||||
* @param {number} id - 猪栏ID
|
* @param {number} id - 猪栏ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PenResponse>}
|
||||||
*/
|
*/
|
||||||
export const getPenById = (id) => {
|
export const getPenById = (id) => {
|
||||||
return http.get(`/api/v1/pens/${id}`);
|
return http.get(`/api/v1/pens/${id}`);
|
||||||
@@ -29,8 +60,8 @@ export const getPenById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 更新一个已存在的猪栏信息
|
* 更新一个已存在的猪栏信息
|
||||||
* @param {number} id - 猪栏ID
|
* @param {number} id - 猪栏ID
|
||||||
* @param {object} penData - 猪栏信息,对应 dto.UpdatePenRequest
|
* @param {UpdatePenRequest} penData - 猪栏信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PenResponse>}
|
||||||
*/
|
*/
|
||||||
export const updatePen = (id, penData) => {
|
export const updatePen = (id, penData) => {
|
||||||
return http.put(`/api/v1/pens/${id}`, penData);
|
return http.put(`/api/v1/pens/${id}`, penData);
|
||||||
@@ -48,8 +79,8 @@ export const deletePen = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 更新指定猪栏的当前状态
|
* 更新指定猪栏的当前状态
|
||||||
* @param {number} id - 猪栏ID
|
* @param {number} id - 猪栏ID
|
||||||
* @param {object} statusData - 新的猪栏状态,对应 dto.UpdatePenStatusRequest
|
* @param {UpdatePenStatusRequest} statusData - 新的猪栏状态
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PenResponse>}
|
||||||
*/
|
*/
|
||||||
export const updatePenStatus = (id, statusData) => {
|
export const updatePenStatus = (id, statusData) => {
|
||||||
return http.put(`/api/v1/pens/${id}/status`, statusData);
|
return http.put(`/api/v1/pens/${id}/status`, statusData);
|
||||||
|
|||||||
@@ -1,11 +1,193 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
// --- Typedefs ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('自繁'|'外购')} PigBatchOriginType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('保育'|'生长'|'育肥'|'待售'|'已出售'|'已归档')} PigBatchStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigBatchResponseDTO
|
||||||
|
* @property {number} id - 批次ID
|
||||||
|
* @property {string} batch_number - 批次编号
|
||||||
|
* @property {PigBatchOriginType} origin_type - 批次来源
|
||||||
|
* @property {string} start_date - 批次开始日期
|
||||||
|
* @property {string} [end_date] - 批次结束日期
|
||||||
|
* @property {number} initial_count - 初始数量
|
||||||
|
* @property {PigBatchStatus} status - 批次状态
|
||||||
|
* @property {boolean} is_active - 是否活跃
|
||||||
|
* @property {string} create_time - 创建时间
|
||||||
|
* @property {string} update_time - 更新时间
|
||||||
|
* @property {number} currentTotalQuantity - 当前总数
|
||||||
|
* @property {number} currentTotalPigsInPens - 当前存栏总数
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigBatchesParams
|
||||||
|
* @property {boolean} [is_active] - 是否活跃 (true/false)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigBatchCreateDTO
|
||||||
|
* @property {string} batch_number - 批次编号,必填
|
||||||
|
* @property {PigBatchOriginType} origin_type - 批次来源,必填
|
||||||
|
* @property {string} start_date - 批次开始日期,必填
|
||||||
|
* @property {number} initial_count - 初始数量,必填,最小为1
|
||||||
|
* @property {PigBatchStatus} status - 批次状态,必填
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigBatchUpdateDTO
|
||||||
|
* @property {string} [batch_number] - 批次编号,可选
|
||||||
|
* @property {PigBatchOriginType} [origin_type] - 批次来源,可选
|
||||||
|
* @property {string} [start_date] - 批次开始日期,可选
|
||||||
|
* @property {string} [end_date] - 批次结束日期,可选
|
||||||
|
* @property {number} [initial_count] - 初始数量,可选
|
||||||
|
* @property {PigBatchStatus} [status] - 批次状态,可选
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} AssignEmptyPensToBatchRequest
|
||||||
|
* @property {Array<number>} pen_ids - 待分配的猪栏ID列表
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} BuyPigsRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 买入猪只数量
|
||||||
|
* @property {number} unitPrice - 单价
|
||||||
|
* @property {number} totalPrice - 总价
|
||||||
|
* @property {string} traderName - 交易方名称
|
||||||
|
* @property {string} tradeDate - 交易日期
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} SellPigsRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 卖出猪只数量
|
||||||
|
* @property {number} unitPrice - 单价
|
||||||
|
* @property {number} totalPrice - 总价
|
||||||
|
* @property {string} traderName - 交易方名称
|
||||||
|
* @property {string} tradeDate - 交易日期
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} MovePigsIntoPenRequest
|
||||||
|
* @property {number} toPenID - 目标猪栏ID
|
||||||
|
* @property {number} quantity - 移入猪只数量
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TransferPigsWithinBatchRequest
|
||||||
|
* @property {number} fromPenID - 源猪栏ID
|
||||||
|
* @property {number} toPenID - 目标猪栏ID
|
||||||
|
* @property {number} quantity - 调栏猪只数量
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TransferPigsAcrossBatchesRequest
|
||||||
|
* @property {number} fromPenID - 源猪栏ID
|
||||||
|
* @property {number} destBatchID - 目标猪批次ID
|
||||||
|
* @property {number} toPenID - 目标猪栏ID
|
||||||
|
* @property {number} quantity - 调栏猪只数量
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ReclassifyPenToNewBatchRequest
|
||||||
|
* @property {number} penID - 待划拨的猪栏ID
|
||||||
|
* @property {number} toBatchID - 目标猪批次ID
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('原地治疗'|'病猪栏治疗')} PigBatchSickPigTreatmentLocation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RecordSickPigsRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 病猪数量
|
||||||
|
* @property {PigBatchSickPigTreatmentLocation} treatmentLocation - 治疗地点
|
||||||
|
* @property {string} happenedAt - 发生时间
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RecordSickPigRecoveryRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 康复猪数量
|
||||||
|
* @property {PigBatchSickPigTreatmentLocation} treatmentLocation - 治疗地点
|
||||||
|
* @property {string} happenedAt - 发生时间
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RecordSickPigDeathRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 死亡猪数量
|
||||||
|
* @property {PigBatchSickPigTreatmentLocation} treatmentLocation - 治疗地点
|
||||||
|
* @property {string} happenedAt - 发生时间
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RecordSickPigCullRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 淘汰猪数量
|
||||||
|
* @property {PigBatchSickPigTreatmentLocation} treatmentLocation - 治疗地点
|
||||||
|
* @property {string} happenedAt - 发生时间
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RecordDeathRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 死亡猪数量
|
||||||
|
* @property {string} happenedAt - 发生时间
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} RecordCullRequest
|
||||||
|
* @property {number} penID - 猪栏ID
|
||||||
|
* @property {number} quantity - 淘汰猪数量
|
||||||
|
* @property {string} happenedAt - 发生时间
|
||||||
|
* @property {string} [remarks] - 备注
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PenResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} house_id
|
||||||
|
* @property {string} pen_number
|
||||||
|
* @property {number} capacity
|
||||||
|
* @property {number} current_pig_count
|
||||||
|
* @property {number} pig_batch_id
|
||||||
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigHouseResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} description
|
||||||
|
*/
|
||||||
|
|
||||||
// --- 猪批次基础操作 ---
|
// --- 猪批次基础操作 ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有猪批次的列表
|
* 获取所有猪批次的列表
|
||||||
* @param {object} params - 查询参数,例如 { is_active: true }
|
* @param {PigBatchesParams} params - 查询参数
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<PigBatchResponseDTO>>}
|
||||||
*/
|
*/
|
||||||
export const getPigBatches = (params) => {
|
export const getPigBatches = (params) => {
|
||||||
return http.get('/api/v1/pig-batches', { params });
|
return http.get('/api/v1/pig-batches', { params });
|
||||||
@@ -13,8 +195,8 @@ export const getPigBatches = (params) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的猪批次
|
* 创建一个新的猪批次
|
||||||
* @param {object} batchData - 猪批次信息,对应 dto.PigBatchCreateDTO
|
* @param {PigBatchCreateDTO} batchData - 猪批次信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PigBatchResponseDTO>}
|
||||||
*/
|
*/
|
||||||
export const createPigBatch = (batchData) => {
|
export const createPigBatch = (batchData) => {
|
||||||
return http.post('/api/v1/pig-batches', batchData);
|
return http.post('/api/v1/pig-batches', batchData);
|
||||||
@@ -23,7 +205,7 @@ export const createPigBatch = (batchData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID获取单个猪批次信息
|
* 根据ID获取单个猪批次信息
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PigBatchResponseDTO>}
|
||||||
*/
|
*/
|
||||||
export const getPigBatchById = (id) => {
|
export const getPigBatchById = (id) => {
|
||||||
return http.get(`/api/v1/pig-batches/${id}`);
|
return http.get(`/api/v1/pig-batches/${id}`);
|
||||||
@@ -32,8 +214,8 @@ export const getPigBatchById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 更新一个已存在的猪批次信息
|
* 更新一个已存在的猪批次信息
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} batchData - 猪批次信息,对应 dto.PigBatchUpdateDTO
|
* @param {PigBatchUpdateDTO} batchData - 猪批次信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PigBatchResponseDTO>}
|
||||||
*/
|
*/
|
||||||
export const updatePigBatch = (id, batchData) => {
|
export const updatePigBatch = (id, batchData) => {
|
||||||
return http.put(`/api/v1/pig-batches/${id}`, batchData);
|
return http.put(`/api/v1/pig-batches/${id}`, batchData);
|
||||||
@@ -53,7 +235,7 @@ export const deletePigBatch = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 为猪批次分配空栏
|
* 为猪批次分配空栏
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} pensData - 待分配的猪栏ID列表,对应 dto.AssignEmptyPensToBatchRequest
|
* @param {AssignEmptyPensToBatchRequest} pensData - 待分配的猪栏ID列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const assignPensToBatch = (id, pensData) => {
|
export const assignPensToBatch = (id, pensData) => {
|
||||||
@@ -62,18 +244,18 @@ export const assignPensToBatch = (id, pensData) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从猪批次移除空栏
|
* 从猪批次移除空栏
|
||||||
* @param {number} batchID - 猪批次ID
|
|
||||||
* @param {number} penID - 待移除的猪栏ID
|
* @param {number} penID - 待移除的猪栏ID
|
||||||
|
* @param {number} batchID - 猪批次ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const removePenFromBatch = (batchID, penID) => {
|
export const removePenFromBatch = (penID, batchID) => {
|
||||||
return http.delete(`/api/v1/pig-batches/remove-pen/${penID}/${batchID}`);
|
return http.delete(`/api/v1/pig-batches/remove-pen/${penID}/${batchID}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理买猪的业务逻辑
|
* 处理买猪的业务逻辑
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} buyData - 买猪请求信息,对应 dto.BuyPigsRequest
|
* @param {BuyPigsRequest} buyData - 买猪请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const buyPigsForBatch = (id, buyData) => {
|
export const buyPigsForBatch = (id, buyData) => {
|
||||||
@@ -83,7 +265,7 @@ export const buyPigsForBatch = (id, buyData) => {
|
|||||||
/**
|
/**
|
||||||
* 处理卖猪的业务逻辑
|
* 处理卖猪的业务逻辑
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} sellData - 卖猪请求信息,对应 dto.SellPigsRequest
|
* @param {SellPigsRequest} sellData - 卖猪请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const sellPigsFromBatch = (id, sellData) => {
|
export const sellPigsFromBatch = (id, sellData) => {
|
||||||
@@ -93,7 +275,7 @@ export const sellPigsFromBatch = (id, sellData) => {
|
|||||||
/**
|
/**
|
||||||
* 将猪只从“虚拟库存”移入指定猪栏
|
* 将猪只从“虚拟库存”移入指定猪栏
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} moveData - 移入猪只请求信息,对应 dto.MovePigsIntoPenRequest
|
* @param {MovePigsIntoPenRequest} moveData - 移入猪只请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const movePigsIntoPen = (id, moveData) => {
|
export const movePigsIntoPen = (id, moveData) => {
|
||||||
@@ -103,7 +285,7 @@ export const movePigsIntoPen = (id, moveData) => {
|
|||||||
/**
|
/**
|
||||||
* 群内调栏
|
* 群内调栏
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} transferData - 群内调栏请求信息,对应 dto.TransferPigsWithinBatchRequest
|
* @param {TransferPigsWithinBatchRequest} transferData - 群内调栏请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const transferPigsWithinBatch = (id, transferData) => {
|
export const transferPigsWithinBatch = (id, transferData) => {
|
||||||
@@ -113,7 +295,7 @@ export const transferPigsWithinBatch = (id, transferData) => {
|
|||||||
/**
|
/**
|
||||||
* 跨猪群调栏
|
* 跨猪群调栏
|
||||||
* @param {number} sourceBatchID - 源猪批次ID
|
* @param {number} sourceBatchID - 源猪批次ID
|
||||||
* @param {object} transferData - 跨群调栏请求信息,对应 dto.TransferPigsAcrossBatchesRequest
|
* @param {TransferPigsAcrossBatchesRequest} transferData - 跨群调栏请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const transferPigsAcrossBatches = (sourceBatchID, transferData) => {
|
export const transferPigsAcrossBatches = (sourceBatchID, transferData) => {
|
||||||
@@ -123,7 +305,7 @@ export const transferPigsAcrossBatches = (sourceBatchID, transferData) => {
|
|||||||
/**
|
/**
|
||||||
* 将猪栏划拨到新批次
|
* 将猪栏划拨到新批次
|
||||||
* @param {number} fromBatchID - 源猪批次ID
|
* @param {number} fromBatchID - 源猪批次ID
|
||||||
* @param {object} reclassifyData - 划拨请求信息,对应 dto.ReclassifyPenToNewBatchRequest
|
* @param {ReclassifyPenToNewBatchRequest} reclassifyData - 划拨请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const reclassifyPenToNewBatch = (fromBatchID, reclassifyData) => {
|
export const reclassifyPenToNewBatch = (fromBatchID, reclassifyData) => {
|
||||||
@@ -135,7 +317,7 @@ export const reclassifyPenToNewBatch = (fromBatchID, reclassifyData) => {
|
|||||||
/**
|
/**
|
||||||
* 记录新增病猪事件
|
* 记录新增病猪事件
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} sickData - 记录病猪请求信息,对应 dto.RecordSickPigsRequest
|
* @param {RecordSickPigsRequest} sickData - 记录病猪请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const recordSickPigsInBatch = (id, sickData) => {
|
export const recordSickPigsInBatch = (id, sickData) => {
|
||||||
@@ -145,7 +327,7 @@ export const recordSickPigsInBatch = (id, sickData) => {
|
|||||||
/**
|
/**
|
||||||
* 记录病猪康复事件
|
* 记录病猪康复事件
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} recoveryData - 记录病猪康复请求信息,对应 dto.RecordSickPigRecoveryRequest
|
* @param {RecordSickPigRecoveryRequest} recoveryData - 记录病猪康复请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const recordSickPigRecoveryInBatch = (id, recoveryData) => {
|
export const recordSickPigRecoveryInBatch = (id, recoveryData) => {
|
||||||
@@ -155,7 +337,7 @@ export const recordSickPigRecoveryInBatch = (id, recoveryData) => {
|
|||||||
/**
|
/**
|
||||||
* 记录病猪死亡事件
|
* 记录病猪死亡事件
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} deathData - 记录病猪死亡请求信息,对应 dto.RecordSickPigDeathRequest
|
* @param {RecordSickPigDeathRequest} deathData - 记录病猪死亡请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const recordSickPigDeathInBatch = (id, deathData) => {
|
export const recordSickPigDeathInBatch = (id, deathData) => {
|
||||||
@@ -165,7 +347,7 @@ export const recordSickPigDeathInBatch = (id, deathData) => {
|
|||||||
/**
|
/**
|
||||||
* 记录病猪淘汰事件
|
* 记录病猪淘汰事件
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} cullData - 记录病猪淘汰请求信息,对应 dto.RecordSickPigCullRequest
|
* @param {RecordSickPigCullRequest} cullData - 记录病猪淘汰请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const recordSickPigCullInBatch = (id, cullData) => {
|
export const recordSickPigCullInBatch = (id, cullData) => {
|
||||||
@@ -175,7 +357,7 @@ export const recordSickPigCullInBatch = (id, cullData) => {
|
|||||||
/**
|
/**
|
||||||
* 记录正常猪只死亡事件
|
* 记录正常猪只死亡事件
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} deathData - 记录正常猪只死亡请求信息,对应 dto.RecordDeathRequest
|
* @param {RecordDeathRequest} deathData - 记录正常猪只死亡请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const recordDeathInBatch = (id, deathData) => {
|
export const recordDeathInBatch = (id, deathData) => {
|
||||||
@@ -185,9 +367,27 @@ export const recordDeathInBatch = (id, deathData) => {
|
|||||||
/**
|
/**
|
||||||
* 记录正常猪只淘汰事件
|
* 记录正常猪只淘汰事件
|
||||||
* @param {number} id - 猪批次ID
|
* @param {number} id - 猪批次ID
|
||||||
* @param {object} cullData - 记录正常猪只淘汰请求信息,对应 dto.RecordCullRequest
|
* @param {RecordCullRequest} cullData - 记录正常猪只淘汰请求信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const recordCullInBatch = (id, cullData) => {
|
export const recordCullInBatch = (id, cullData) => {
|
||||||
return http.post(`/api/v1/pig-batches/record-cull/${id}`, cullData);
|
return http.post(`/api/v1/pig-batches/record-cull/${id}`, cullData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --- 新增的猪栏和猪舍API ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有猪栏的列表
|
||||||
|
* @returns {Promise<Array<PenResponse>>}
|
||||||
|
*/
|
||||||
|
export const getAllPens = () => {
|
||||||
|
return http.get('/api/v1/pens');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有猪舍的列表
|
||||||
|
* @returns {Promise<Array<PigHouseResponse>>}
|
||||||
|
*/
|
||||||
|
export const getAllPigHouses = () => {
|
||||||
|
return http.get('/api/v1/pig-houses');
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,8 +1,27 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PigHouseResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} description
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreatePigHouseRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [description]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdatePigHouseRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [description]
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有猪舍的列表
|
* 获取所有猪舍的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<PigHouseResponse>>}
|
||||||
*/
|
*/
|
||||||
export const getPigHouses = () => {
|
export const getPigHouses = () => {
|
||||||
return http.get('/api/v1/pig-houses');
|
return http.get('/api/v1/pig-houses');
|
||||||
@@ -10,8 +29,8 @@ export const getPigHouses = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的猪舍
|
* 创建一个新的猪舍
|
||||||
* @param {object} pigHouseData - 猪舍信息,对应 dto.CreatePigHouseRequest
|
* @param {CreatePigHouseRequest} pigHouseData - 猪舍信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PigHouseResponse>}
|
||||||
*/
|
*/
|
||||||
export const createPigHouse = (pigHouseData) => {
|
export const createPigHouse = (pigHouseData) => {
|
||||||
return http.post('/api/v1/pig-houses', pigHouseData);
|
return http.post('/api/v1/pig-houses', pigHouseData);
|
||||||
@@ -20,7 +39,7 @@ export const createPigHouse = (pigHouseData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据ID获取单个猪舍信息
|
* 根据ID获取单个猪舍信息
|
||||||
* @param {number} id - 猪舍ID
|
* @param {number} id - 猪舍ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PigHouseResponse>}
|
||||||
*/
|
*/
|
||||||
export const getPigHouseById = (id) => {
|
export const getPigHouseById = (id) => {
|
||||||
return http.get(`/api/v1/pig-houses/${id}`);
|
return http.get(`/api/v1/pig-houses/${id}`);
|
||||||
@@ -29,8 +48,8 @@ export const getPigHouseById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 更新一个已存在的猪舍信息
|
* 更新一个已存在的猪舍信息
|
||||||
* @param {number} id - 猪舍ID
|
* @param {number} id - 猪舍ID
|
||||||
* @param {object} pigHouseData - 猪舍信息,对应 dto.UpdatePigHouseRequest
|
* @param {UpdatePigHouseRequest} pigHouseData - 猪舍信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PigHouseResponse>}
|
||||||
*/
|
*/
|
||||||
export const updatePigHouse = (id, pigHouseData) => {
|
export const updatePigHouse = (id, pigHouseData) => {
|
||||||
return http.put(`/api/v1/pig-houses/${id}`, pigHouseData);
|
return http.put(`/api/v1/pig-houses/${id}`, pigHouseData);
|
||||||
|
|||||||
@@ -1,8 +1,91 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('计划分析'|'等待'|'下料')} TaskType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TaskRequest
|
||||||
|
* @property {string} [name]
|
||||||
|
* @property {string} [description]
|
||||||
|
* @property {TaskType} [type]
|
||||||
|
* @property {object} [parameters]
|
||||||
|
* @property {number} [execution_order]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('自动'|'手动')} PlanExecutionType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreatePlanRequest
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} [description]
|
||||||
|
* @property {PlanExecutionType} execution_type
|
||||||
|
* @property {string} [cron_expression]
|
||||||
|
* @property {number} [execute_num]
|
||||||
|
* @property {Array<TaskRequest>} [tasks]
|
||||||
|
* @property {Array<number>} [sub_plan_ids]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UpdatePlanRequest
|
||||||
|
* @property {string} [name]
|
||||||
|
* @property {string} [description]
|
||||||
|
* @property {PlanExecutionType} execution_type
|
||||||
|
* @property {string} [cron_expression]
|
||||||
|
* @property {number} [execute_num]
|
||||||
|
* @property {Array<TaskRequest>} [tasks]
|
||||||
|
* @property {Array<number>} [sub_plan_ids]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} TaskResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} plan_id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} description
|
||||||
|
* @property {TaskType} type
|
||||||
|
* @property {object} parameters
|
||||||
|
* @property {number} execution_order
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} SubPlanResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} parent_plan_id
|
||||||
|
* @property {number} child_plan_id
|
||||||
|
* @property {number} execution_order
|
||||||
|
* @property {PlanResponse} child_plan
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('已禁用'|'已启用'|'执行完毕'|'执行失败')} PlanStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('子计划'|'任务')} PlanContentType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PlanResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} name
|
||||||
|
* @property {string} description
|
||||||
|
* @property {PlanExecutionType} execution_type
|
||||||
|
* @property {string} cron_expression
|
||||||
|
* @property {number} execute_num
|
||||||
|
* @property {number} execute_count
|
||||||
|
* @property {PlanStatus} status
|
||||||
|
* @property {PlanContentType} content_type
|
||||||
|
* @property {Array<TaskResponse>} tasks
|
||||||
|
* @property {Array<SubPlanResponse>} sub_plans
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有计划的列表
|
* 获取所有计划的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<Array<PlanResponse>>}
|
||||||
*/
|
*/
|
||||||
const getPlans = () => {
|
const getPlans = () => {
|
||||||
return http.get('/api/v1/plans');
|
return http.get('/api/v1/plans');
|
||||||
@@ -10,8 +93,8 @@ const getPlans = () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的计划
|
* 创建一个新的计划
|
||||||
* @param {object} planData - 计划信息,对应 dto.CreatePlanRequest
|
* @param {CreatePlanRequest} planData - 计划信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PlanResponse>}
|
||||||
*/
|
*/
|
||||||
const createPlan = (planData) => {
|
const createPlan = (planData) => {
|
||||||
return http.post('/api/v1/plans', planData);
|
return http.post('/api/v1/plans', planData);
|
||||||
@@ -20,7 +103,7 @@ const createPlan = (planData) => {
|
|||||||
/**
|
/**
|
||||||
* 根据计划ID获取单个计划的详细信息
|
* 根据计划ID获取单个计划的详细信息
|
||||||
* @param {number} id - 计划ID
|
* @param {number} id - 计划ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PlanResponse>}
|
||||||
*/
|
*/
|
||||||
const getPlanById = (id) => {
|
const getPlanById = (id) => {
|
||||||
return http.get(`/api/v1/plans/${id}`);
|
return http.get(`/api/v1/plans/${id}`);
|
||||||
@@ -29,8 +112,8 @@ const getPlanById = (id) => {
|
|||||||
/**
|
/**
|
||||||
* 根据计划ID更新计划的详细信息
|
* 根据计划ID更新计划的详细信息
|
||||||
* @param {number} id - 计划ID
|
* @param {number} id - 计划ID
|
||||||
* @param {object} planData - 更新后的计划信息,对应 dto.UpdatePlanRequest
|
* @param {UpdatePlanRequest} planData - 更新后的计划信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<PlanResponse>}
|
||||||
*/
|
*/
|
||||||
const updatePlan = (id, planData) => {
|
const updatePlan = (id, planData) => {
|
||||||
return http.put(`/api/v1/plans/${id}`, planData);
|
return http.put(`/api/v1/plans/${id}`, planData);
|
||||||
|
|||||||
103
src/api/user.js
103
src/api/user.js
@@ -1,9 +1,89 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreateUserRequest
|
||||||
|
* @property {string} username
|
||||||
|
* @property {string} password
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} CreateUserResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} username
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} LoginRequest
|
||||||
|
* @property {string} identifier - Identifier 可以是用户名、邮箱、手机号、微信号或飞书账号
|
||||||
|
* @property {string} password
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} LoginResponse
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} username
|
||||||
|
* @property {string} token
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('成功'|'失败')} AuditStatus
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UserActionLogDTO
|
||||||
|
* @property {number} id
|
||||||
|
* @property {number} user_id
|
||||||
|
* @property {string} username
|
||||||
|
* @property {string} action_type
|
||||||
|
* @property {string} description
|
||||||
|
* @property {string} http_method
|
||||||
|
* @property {string} http_path
|
||||||
|
* @property {string} source_ip
|
||||||
|
* @property {Array<number>} target_resource
|
||||||
|
* @property {AuditStatus} status
|
||||||
|
* @property {string} result_details
|
||||||
|
* @property {string} time
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} PaginationDTO
|
||||||
|
* @property {number} page
|
||||||
|
* @property {number} pageSize
|
||||||
|
* @property {number} total
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListUserActionLogResponse
|
||||||
|
* @property {Array<UserActionLogDTO>} list
|
||||||
|
* @property {PaginationDTO} pagination
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} UserHistoryParams
|
||||||
|
* @property {string} [action_type]
|
||||||
|
* @property {string} [end_time]
|
||||||
|
* @property {string} [order_by]
|
||||||
|
* @property {number} [page]
|
||||||
|
* @property {number} [pageSize]
|
||||||
|
* @property {string} [start_time]
|
||||||
|
* @property {string} [status]
|
||||||
|
* @property {number} [user_id]
|
||||||
|
* @property {string} [username]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} SendTestNotificationRequest
|
||||||
|
* @property {NotifierType} type - Type 指定要测试的通知渠道
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新用户
|
* 创建一个新用户
|
||||||
* @param {object} userData - 用户信息,对应 dto.CreateUserRequest
|
* @param {CreateUserRequest} userData - 用户信息
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<CreateUserResponse>}
|
||||||
*/
|
*/
|
||||||
const createUser = (userData) => {
|
const createUser = (userData) => {
|
||||||
return http.post('/api/v1/users', userData);
|
return http.post('/api/v1/users', userData);
|
||||||
@@ -11,8 +91,8 @@ const createUser = (userData) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
* @param {object} credentials - 登录凭证,对应 dto.LoginRequest
|
* @param {LoginRequest} credentials - 登录凭证
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<LoginResponse>}
|
||||||
*/
|
*/
|
||||||
const login = (credentials) => {
|
const login = (credentials) => {
|
||||||
return http.post('/api/v1/users/login', credentials);
|
return http.post('/api/v1/users/login', credentials);
|
||||||
@@ -21,15 +101,26 @@ const login = (credentials) => {
|
|||||||
/**
|
/**
|
||||||
* 获取指定用户的操作历史
|
* 获取指定用户的操作历史
|
||||||
* @param {number} id - 用户ID
|
* @param {number} id - 用户ID
|
||||||
* @param {object} params - 查询参数
|
* @param {UserHistoryParams} params - 查询参数
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<ListUserActionLogResponse>}
|
||||||
*/
|
*/
|
||||||
const getUserHistory = (id, params) => {
|
const getUserHistory = (id, params) => {
|
||||||
return http.get(`/api/v1/users/${id}/history`, { params });
|
return http.get(`/api/v1/users/${id}/history`, { params });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送测试通知
|
||||||
|
* @param {number} id - 用户ID
|
||||||
|
* @param {SendTestNotificationRequest} data - 请求体
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
const sendTestNotification = (id, data) => {
|
||||||
|
return http.post(`/api/v1/users/${id}/notifications/test`, data);
|
||||||
|
};
|
||||||
|
|
||||||
export const UserApi = {
|
export const UserApi = {
|
||||||
createUser,
|
createUser,
|
||||||
login,
|
login,
|
||||||
getUserHistory,
|
getUserHistory,
|
||||||
|
sendTestNotification,
|
||||||
};
|
};
|
||||||
|
|||||||
80
src/components/AllocatePigsDialog.vue
Normal file
80
src/components/AllocatePigsDialog.vue
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
title="分配猪只"
|
||||||
|
:model-value="visible"
|
||||||
|
@update:model-value="$emit('update:visible', $event)"
|
||||||
|
width="30%"
|
||||||
|
@close="resetForm"
|
||||||
|
>
|
||||||
|
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||||
|
<el-form-item label="未分配数量">
|
||||||
|
<span>{{ unassignedPigCount }}</span>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="分配数量" prop="quantity">
|
||||||
|
<el-input-number v-model="form.quantity" :min="1" :max="unassignedPigCount" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="$emit('update:visible', false)">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="handleConfirm">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'AllocatePigsDialog',
|
||||||
|
props: {
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
unassignedPigCount: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
penId: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:visible', 'confirm'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
form: {
|
||||||
|
quantity: 1
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
quantity: [
|
||||||
|
{ required: true, message: '请输入分配数量', trigger: 'blur' },
|
||||||
|
{ type: 'integer', message: '请输入整数', trigger: 'blur' },
|
||||||
|
{ validator: this.validateQuantity, trigger: 'blur' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
validateQuantity(rule, value, callback) {
|
||||||
|
if (value > this.unassignedPigCount) {
|
||||||
|
callback(new Error('分配数量不能超过未分配数量'));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleConfirm() {
|
||||||
|
this.$refs.form.validate(valid => {
|
||||||
|
if (valid) {
|
||||||
|
this.$emit('confirm', { penId: this.penId, quantity: this.form.quantity });
|
||||||
|
this.$emit('update:visible', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
this.$refs.form.resetFields();
|
||||||
|
this.form.quantity = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -3,24 +3,73 @@
|
|||||||
<div v-for="batch in pigBatches" :key="batch.id" class="pig-batch-item">
|
<div v-for="batch in pigBatches" :key="batch.id" class="pig-batch-item">
|
||||||
<div class="batch-header" @click="toggleExpand(batch)">
|
<div class="batch-header" @click="toggleExpand(batch)">
|
||||||
<div class="batch-info">
|
<div class="batch-info">
|
||||||
<span>批次编号: {{ batch.batch_number }}</span>
|
<div class="batch-info-line">
|
||||||
<span>状态: {{ batch.status }}</span>
|
<span>批次编号: {{ batch.batch_number }}</span>
|
||||||
<span>初始数量: {{ batch.initial_count }}</span>
|
<span>状态: {{ batch.status }}</span>
|
||||||
|
<span>初始数量: {{ batch.initial_count }}</span>
|
||||||
|
<span v-if="batch.currentTotalQuantity !== undefined && batch.currentTotalQuantity !== null">当前总数: {{
|
||||||
|
batch.currentTotalQuantity
|
||||||
|
}}</span>
|
||||||
|
<span v-if="batch.origin_type">批次来源: {{ batch.origin_type }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="batch-info-line">
|
||||||
|
<span v-if="batch.start_date">批次开始日期: {{ formatRFC3339(batch.start_date) }}</span>
|
||||||
|
<span v-if="batch.end_date">
|
||||||
|
批次结束日期:
|
||||||
|
<template v-if="formatRFC3339(batch.end_date) === '0001-01-01 08:00:00'">
|
||||||
|
正在饲养中
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
{{ formatRFC3339(batch.end_date) }}
|
||||||
|
</template>
|
||||||
|
</span>
|
||||||
|
<span v-if="batch.unassigned_pig_count !== undefined && batch.unassigned_pig_count > 0" class="red-text">
|
||||||
|
未分配数量: {{ batch.unassigned_pig_count }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="batch-actions">
|
<div class="batch-actions">
|
||||||
<el-button size="small" type="primary" @click.stop="emitAddPen(batch)">增加猪栏</el-button>
|
<el-dropdown trigger="click" class="batch-dropdown">
|
||||||
<el-button size="small" @click.stop="emitEditBatch(batch)">编辑</el-button>
|
<el-button type="primary" size="small">
|
||||||
<el-button size="small" type="danger" @click.stop="emitDeleteBatch(batch)">删除</el-button>
|
管理猪群<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item @click="showAddPenDialog(batch)" :disabled="!batch.is_active">增加猪栏</el-dropdown-item>
|
||||||
|
<el-dropdown-item @click="emitEditBatch(batch)">编辑</el-dropdown-item>
|
||||||
|
<el-dropdown-item @click="emitDeleteBatch(batch)" divided>删除</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
|
<el-dropdown trigger="click" class="batch-dropdown">
|
||||||
|
<el-button type="success" size="small">
|
||||||
|
调栏<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||||
|
</el-button>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item
|
||||||
|
@click="emitTransferPigs(batch)"
|
||||||
|
:disabled="!batch.is_active || !batch.pens || batch.pens.length < 2"
|
||||||
|
>群内调栏</el-dropdown-item>
|
||||||
|
<el-dropdown-item
|
||||||
|
@click="emitTransferPigsAcrossBatches(batch)"
|
||||||
|
:disabled="!batch.is_active || !batch.pens || batch.pens.length === 0"
|
||||||
|
>跨群调栏</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="batch.isExpanded" class="batch-content">
|
<div v-if="batch.isExpanded" class="batch-content">
|
||||||
<div v-if="batch.pens && batch.pens.length > 0" class="pig-pen-list">
|
<div v-if="batch.pens && batch.pens.length > 0" class="pig-pen-list">
|
||||||
<PigPenInfoCard
|
<PigBatchPenCard
|
||||||
v-for="pen in batch.pens"
|
v-for="pen in batch.pens"
|
||||||
:key="pen.id"
|
:key="pen.id"
|
||||||
:pen="pen"
|
:pen="pen"
|
||||||
@edit="emitEditPen"
|
:isBatchActive="batch.is_active"
|
||||||
@delete="emitDeletePen"
|
:batchUnassignedPigCount="batch.unassigned_pig_count"
|
||||||
|
@allocate-pigs="showAllocatePigsDialog($event, batch)"
|
||||||
|
@remove="emitRemovePen"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="no-pens-message">
|
<div v-else class="no-pens-message">
|
||||||
@@ -28,16 +77,48 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 增加猪栏对话框 -->
|
||||||
|
<el-dialog title="选择猪栏" v-model="addPenDialogVisible" width="30%">
|
||||||
|
<el-select v-model="selectedPenId" placeholder="请选择猪栏" style="width: 100%;">
|
||||||
|
<el-option
|
||||||
|
v-for="pen in availablePens"
|
||||||
|
:key="pen.id"
|
||||||
|
:label="pen.label"
|
||||||
|
:value="pen.id">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="addPenDialogVisible = false">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="assignPen">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<!-- 分配猪只对话框 -->
|
||||||
|
<AllocatePigsDialog
|
||||||
|
v-model:visible="allocatePigsDialogVisible"
|
||||||
|
:unassigned-pig-count="currentBatch ? currentBatch.unassigned_pig_count : 0"
|
||||||
|
:pen-id="selectedPenForAllocation ? selectedPenForAllocation.id : 0"
|
||||||
|
@confirm="handleAllocatePigs"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import PigPenInfoCard from './PigPenInfoCard.vue';
|
import PigBatchPenCard from './PigBatchPenCard.vue';
|
||||||
|
import AllocatePigsDialog from './AllocatePigsDialog.vue';
|
||||||
|
import {getAllPens, getAllPigHouses, movePigsIntoPen} from '../api/pigBatch';
|
||||||
|
import {formatRFC3339} from '../utils/format'; // 导入格式化函数
|
||||||
|
import { ArrowDown } from '@element-plus/icons-vue'; // 导入 ArrowDown 图标
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PigBatchList',
|
name: 'PigBatchList',
|
||||||
components: {
|
components: {
|
||||||
PigPenInfoCard
|
PigBatchPenCard,
|
||||||
|
AllocatePigsDialog,
|
||||||
|
ArrowDown // 注册 ArrowDown 图标
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
pigBatches: {
|
pigBatches: {
|
||||||
@@ -45,27 +126,96 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['edit-batch', 'delete-batch', 'add-pen', 'edit-pen', 'delete-pen'],
|
emits: ['edit-batch', 'delete-batch', 'add-pen', 'remove-pen', 'assign-pen-to-batch', 'reload-data', 'transfer-pigs', 'transfer-pigs-across-batches'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
addPenDialogVisible: false,
|
||||||
|
availablePens: [],
|
||||||
|
selectedPenId: null,
|
||||||
|
currentBatch: null, // To store the batch for which we are adding a pen
|
||||||
|
allocatePigsDialogVisible: false,
|
||||||
|
selectedPenForAllocation: null
|
||||||
|
};
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
formatRFC3339,
|
||||||
toggleExpand(batch) {
|
toggleExpand(batch) {
|
||||||
batch.isExpanded = !batch.isExpanded;
|
batch.isExpanded = !batch.isExpanded;
|
||||||
},
|
},
|
||||||
// 猪群操作
|
async fetchAvailablePens() {
|
||||||
emitAddPen(batch) {
|
try {
|
||||||
this.$emit('add-pen', batch);
|
const [pensResponse, housesResponse] = await Promise.all([
|
||||||
|
getAllPens(),
|
||||||
|
getAllPigHouses()
|
||||||
|
]);
|
||||||
|
|
||||||
|
const pens = pensResponse.data;
|
||||||
|
const houses = housesResponse.data;
|
||||||
|
|
||||||
|
// Create a map for quick lookup of house names by ID
|
||||||
|
const houseMap = new Map(houses.map(house => [house.id, house.name]));
|
||||||
|
|
||||||
|
// Filter for pens that are not assigned to any batch
|
||||||
|
const unassignedPens = pens.filter(pen => !pen.pig_batch_id);
|
||||||
|
|
||||||
|
this.availablePens = unassignedPens.map(pen => ({
|
||||||
|
id: pen.id,
|
||||||
|
label: `${pen.pen_number} (${houseMap.get(pen.house_id) || '未知猪舍'})`
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching pens or houses:", error);
|
||||||
|
this.$message.error("获取猪栏或猪舍信息失败");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
showAddPenDialog(batch) {
|
||||||
|
this.currentBatch = batch;
|
||||||
|
this.selectedPenId = null; // Reset selection
|
||||||
|
this.fetchAvailablePens();
|
||||||
|
this.addPenDialogVisible = true;
|
||||||
|
},
|
||||||
|
assignPen() {
|
||||||
|
if (this.selectedPenId && this.currentBatch) {
|
||||||
|
this.$emit('assign-pen-to-batch', {
|
||||||
|
batchId: this.currentBatch.id,
|
||||||
|
penId: this.selectedPenId
|
||||||
|
});
|
||||||
|
this.addPenDialogVisible = false;
|
||||||
|
} else {
|
||||||
|
this.$message.warning("请选择一个猪栏");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
showAllocatePigsDialog(pen, batch) {
|
||||||
|
this.currentBatch = batch;
|
||||||
|
this.selectedPenForAllocation = pen;
|
||||||
|
this.allocatePigsDialogVisible = true;
|
||||||
|
},
|
||||||
|
async handleAllocatePigs({penId, quantity}) {
|
||||||
|
try {
|
||||||
|
await movePigsIntoPen(this.currentBatch.id, {toPenID: penId, quantity});
|
||||||
|
this.$message.success('猪只分配成功');
|
||||||
|
this.allocatePigsDialogVisible = false;
|
||||||
|
this.$emit('reload-data'); // 通知父组件重新加载数据
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error allocating pigs:', error);
|
||||||
|
this.$message.error('分配猪只失败');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 猪群操作
|
||||||
emitEditBatch(batch) {
|
emitEditBatch(batch) {
|
||||||
this.$emit('edit-batch', batch);
|
this.$emit('edit-batch', batch);
|
||||||
},
|
},
|
||||||
emitDeleteBatch(batch) {
|
emitDeleteBatch(batch) {
|
||||||
this.$emit('delete-batch', batch);
|
this.$emit('delete-batch', batch);
|
||||||
},
|
},
|
||||||
// 猪栏操作
|
emitTransferPigs(batch) {
|
||||||
emitEditPen(pen) {
|
this.$emit('transfer-pigs', batch);
|
||||||
this.$emit('edit-pen', pen);
|
|
||||||
},
|
},
|
||||||
emitDeletePen(pen) {
|
emitTransferPigsAcrossBatches(batch) {
|
||||||
this.$emit('delete-pen', pen);
|
this.$emit('transfer-pigs-across-batches', batch);
|
||||||
|
},
|
||||||
|
// 猪栏操作
|
||||||
|
emitRemovePen(pen) {
|
||||||
|
this.$emit('remove-pen', pen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,16 +249,21 @@ export default {
|
|||||||
|
|
||||||
.batch-info {
|
.batch-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column; /* 垂直堆叠子元素 */
|
||||||
gap: 8px;
|
gap: 8px; /* 行间距 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.batch-info span:first-child {
|
.batch-info-line {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0 20px; /* 列间距 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.batch-info-line:first-child span:first-child {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.batch-info span {
|
.batch-info span {
|
||||||
margin-right: 20px;
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #606266;
|
color: #606266;
|
||||||
}
|
}
|
||||||
@@ -118,6 +273,10 @@ export default {
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.batch-dropdown {
|
||||||
|
margin-left: 10px; /* 为下拉菜单添加左边距 */
|
||||||
|
}
|
||||||
|
|
||||||
.batch-content {
|
.batch-content {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
border-top: 1px solid #eee;
|
border-top: 1px solid #eee;
|
||||||
@@ -134,4 +293,8 @@ export default {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 20px 0;
|
padding: 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.batch-info-line .red-text {
|
||||||
|
color: red !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
135
src/components/PigBatchPenCard.vue
Normal file
135
src/components/PigBatchPenCard.vue
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<template>
|
||||||
|
<div class="pig-pen-info-card">
|
||||||
|
<div class="info-section">
|
||||||
|
<div class="title">
|
||||||
|
猪栏: {{ pen.pen_number }} <el-tag size="small" :type="statusType">{{ pen.status || '未知' }}</el-tag>
|
||||||
|
</div>
|
||||||
|
<div class="info-item">猪舍: {{ pen.house_name || '未知' }}</div>
|
||||||
|
<div class="info-item border-left">容量: {{ pen.capacity }}</div>
|
||||||
|
<div class="info-item">批次: {{ pen.batch_number || '未分配' }}</div>
|
||||||
|
<div class="info-item border-left">存栏: <span :class="{'over-capacity': pen.current_pig_count > pen.capacity}">{{ pen.current_pig_count || 0 }}</span></div>
|
||||||
|
</div>
|
||||||
|
<div class="actions-section">
|
||||||
|
<el-button size="small" @click="emitAllocatePigs" :disabled="!isBatchActive || batchUnassignedPigCount <= 0">分配猪只</el-button>
|
||||||
|
<el-button size="small" type="danger" @click="emitRemove" :disabled="!isBatchActive || pen.current_pig_count > 0">移除</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PigBatchPenCard',
|
||||||
|
props: {
|
||||||
|
pen: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
isBatchActive: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true // 默认活跃,以防万一没有传递
|
||||||
|
},
|
||||||
|
batchUnassignedPigCount: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['remove', 'allocate-pigs'],
|
||||||
|
setup(props, { emit }) {
|
||||||
|
const statusType = computed(() => {
|
||||||
|
switch (props.pen.status) {
|
||||||
|
case '使用中':
|
||||||
|
return 'success';
|
||||||
|
case '病猪栏':
|
||||||
|
case '维修中':
|
||||||
|
return 'danger';
|
||||||
|
case '清洗消毒':
|
||||||
|
return 'warning';
|
||||||
|
case '空闲':
|
||||||
|
default:
|
||||||
|
return 'info';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const emitAllocatePigs = () => {
|
||||||
|
emit('allocate-pigs', props.pen);
|
||||||
|
};
|
||||||
|
|
||||||
|
const emitRemove = () => {
|
||||||
|
emit('remove', props.pen);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusType,
|
||||||
|
emitAllocatePigs,
|
||||||
|
emitRemove
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.pig-pen-info-card {
|
||||||
|
border: 2px solid #ccc;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 220px; /* 适当加宽以容纳更多信息 */
|
||||||
|
height: auto; /* 让高度自适应内容 */
|
||||||
|
min-height: 240px; /* 设置最小高度 */
|
||||||
|
background-color: #fff;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||||
|
transition: box-shadow 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pig-pen-info-card:hover {
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-section {
|
||||||
|
display: grid; /* 使用grid布局创建两列 */
|
||||||
|
grid-template-columns: 1fr 1fr; /* 两列等宽 */
|
||||||
|
gap: 8px 10px; /* 行间距 8px, 列间距 10px */
|
||||||
|
margin-bottom: 10px;
|
||||||
|
flex-grow: 1; /* 允许信息部分填充可用空间 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-section .title {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1.1em;
|
||||||
|
color: #303133;
|
||||||
|
grid-column: 1 / -1; /* 标题横跨两列 */
|
||||||
|
margin-bottom: 5px; /* 标题下方增加一点间距 */
|
||||||
|
display: flex; /* Add flexbox for alignment */
|
||||||
|
align-items: center; /* Vertically align items */
|
||||||
|
gap: 8px; /* Space between title text and tag */
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-section .info-item {
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-item.border-left {
|
||||||
|
border-left: 1px solid #eee; /* 添加左边框作为分隔线 */
|
||||||
|
padding-left: 10px; /* 增加左内边距,使内容不紧贴边框 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions-section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions-section .el-button {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.over-capacity {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="pig-house-list">
|
<div class="pig-house-list">
|
||||||
<div v-for="house in pigHouses" :key="house.id" class="pig-house-item">
|
<div v-for="house in enrichedPigHouses" :key="house.id" class="pig-house-item">
|
||||||
<div class="house-header" @click="toggleExpand(house)">
|
<div class="house-header" @click="emitToggleExpand(house.id)">
|
||||||
<div class="house-info">
|
<div class="house-info">
|
||||||
<span>猪舍: {{ house.name }}</span>
|
<span>猪舍: {{ house.name }}</span>
|
||||||
<span v-if="house.description">描述: {{ house.description }}</span>
|
<span v-if="house.description">描述: {{ house.description }}</span>
|
||||||
@@ -44,10 +44,25 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['edit-house', 'delete-house', 'add-pen', 'edit-pen', 'delete-pen'],
|
emits: ['edit-house', 'delete-house', 'add-pen', 'edit-pen', 'delete-pen', 'toggle-house-expand'],
|
||||||
|
computed: {
|
||||||
|
enrichedPigHouses() {
|
||||||
|
return this.pigHouses.map(house => {
|
||||||
|
const pensWithHouseInfo = house.pens ? house.pens.map(pen => ({
|
||||||
|
...pen,
|
||||||
|
house_name: house.name,
|
||||||
|
house_id: house.id
|
||||||
|
})) : [];
|
||||||
|
return {
|
||||||
|
...house,
|
||||||
|
pens: pensWithHouseInfo
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleExpand(house) {
|
emitToggleExpand(houseId) {
|
||||||
house.isExpanded = !house.isExpanded;
|
this.$emit('toggle-house-expand', houseId);
|
||||||
},
|
},
|
||||||
// 猪舍操作
|
// 猪舍操作
|
||||||
emitAddPen(house) {
|
emitAddPen(house) {
|
||||||
@@ -79,7 +94,7 @@ export default {
|
|||||||
border: 1px solid #eee;
|
border: 1px solid #eee;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
overflow: hidden; /* 防止子元素溢出圆角 */
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.house-header {
|
.house-header {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="pig-pen-info-card">
|
<div class="pig-pen-info-card">
|
||||||
<div class="info-section">
|
<div class="info-section">
|
||||||
<div class="title">猪栏: {{ pen.pen_number }}</div>
|
<div class="title">
|
||||||
<div class="info-item">状态: <el-tag size="small" :type="statusType">{{ pen.status || '未知' }}</el-tag></div>
|
猪栏: {{ pen.pen_number }} <el-tag size="small" :type="statusType">{{ pen.status || '未知' }}</el-tag>
|
||||||
<div class="info-item">容量: {{ pen.capacity }}</div>
|
</div>
|
||||||
<div class="info-item">存栏: {{ pen.current_pig_count || 0 }}</div>
|
|
||||||
<div class="info-item">批次: {{ pen.batch_number || '未分配' }}</div>
|
|
||||||
<div class="info-item">猪舍: {{ pen.house_name || '未知' }}</div>
|
<div class="info-item">猪舍: {{ pen.house_name || '未知' }}</div>
|
||||||
|
<div class="info-item border-left">容量: {{ pen.capacity }}</div>
|
||||||
|
<div class="info-item">批次: {{ pen.batch_number || '未分配' }}</div>
|
||||||
|
<div class="info-item border-left">存栏: <span :class="{'over-capacity': pen.current_pig_count > pen.capacity}">{{ pen.current_pig_count || 0 }}</span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions-section">
|
<div class="actions-section">
|
||||||
<el-button size="small" @click="emitEdit">编辑</el-button>
|
<el-button size="small" @click="emitEdit">编辑</el-button>
|
||||||
@@ -62,14 +63,15 @@ export default {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.pig-pen-info-card {
|
.pig-pen-info-card {
|
||||||
border: 1px solid #eee;
|
border: 2px solid #ccc;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
width: 200px; /* 适当加宽以容纳更多信息 */
|
width: 220px; /* 适当加宽以容纳更多信息 */
|
||||||
height: 260px; /* 调整高度以适应更多信息 */
|
height: auto; /* 让高度自适应内容 */
|
||||||
|
min-height: 240px; /* 设置最小高度 */
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||||
transition: box-shadow 0.3s;
|
transition: box-shadow 0.3s;
|
||||||
@@ -80,16 +82,22 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.info-section {
|
.info-section {
|
||||||
display: flex;
|
display: grid; /* 使用grid布局创建两列 */
|
||||||
flex-direction: column;
|
grid-template-columns: 1fr 1fr; /* 两列等宽 */
|
||||||
gap: 10px; /* 调整信息项间距 */
|
gap: 8px 10px; /* 行间距 8px, 列间距 10px */
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
flex-grow: 1; /* 允许信息部分填充可用空间 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-section .title {
|
.info-section .title {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
color: #303133;
|
color: #303133;
|
||||||
|
grid-column: 1 / -1; /* 标题横跨两列 */
|
||||||
|
margin-bottom: 5px; /* 标题下方增加一点间距 */
|
||||||
|
display: flex; /* Add flexbox for alignment */
|
||||||
|
align-items: center; /* Vertically align items */
|
||||||
|
gap: 8px; /* Space between title text and tag */
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-section .info-item {
|
.info-section .info-item {
|
||||||
@@ -97,6 +105,11 @@ export default {
|
|||||||
color: #606266;
|
color: #606266;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info-item.border-left {
|
||||||
|
border-left: 1px solid #eee; /* 添加左边框作为分隔线 */
|
||||||
|
padding-left: 10px; /* 增加左内边距,使内容不紧贴边框 */
|
||||||
|
}
|
||||||
|
|
||||||
.actions-section {
|
.actions-section {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -107,4 +120,8 @@ export default {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.over-capacity {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
204
src/components/TransferPigsAcrossBatchesModal.vue
Normal file
204
src/components/TransferPigsAcrossBatchesModal.vue
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
title="跨群调栏"
|
||||||
|
:model-value="visible"
|
||||||
|
@update:model-value="$emit('update:visible', $event)"
|
||||||
|
width="40%"
|
||||||
|
@close="resetForm"
|
||||||
|
>
|
||||||
|
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
||||||
|
<el-form-item label="源猪群批次">
|
||||||
|
<span>{{ batch.batch_number }}</span>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="源猪栏" prop="fromPenID">
|
||||||
|
<el-select v-model="form.fromPenID" placeholder="请选择源猪栏" style="width: 100%;">
|
||||||
|
<el-option
|
||||||
|
v-for="pen in sourcePens"
|
||||||
|
:key="pen.id"
|
||||||
|
:label="`${pen.pen_number} (存栏: ${pen.current_pig_count})`"
|
||||||
|
:value="pen.id"
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="目标猪群批次" prop="destBatchID">
|
||||||
|
<el-select v-model="form.destBatchID" placeholder="请选择目标猪群" style="width: 100%;" @change="onDestBatchChange">
|
||||||
|
<el-option
|
||||||
|
v-for="b in availableBatches"
|
||||||
|
:key="b.id"
|
||||||
|
:label="b.batch_number"
|
||||||
|
:value="b.id"
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="目标猪栏" prop="toPenID">
|
||||||
|
<el-select v-model="form.toPenID" placeholder="请选择目标猪栏" style="width: 100%;">
|
||||||
|
<el-option
|
||||||
|
v-for="pen in destinationPens"
|
||||||
|
:key="pen.id"
|
||||||
|
:label="`${pen.pen_number} (容量: ${pen.capacity})`"
|
||||||
|
:value="pen.id"
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="调栏数量" prop="quantity">
|
||||||
|
<el-input-number v-model="form.quantity" :min="1" :max="maxTransferQuantity" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remarks">
|
||||||
|
<el-input v-model="form.remarks" type="textarea" :rows="2" placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="$emit('update:visible', false)">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="handleConfirm">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getPigBatches, transferPigsAcrossBatches } from '@/api/pigBatch';
|
||||||
|
import { getPens } from '@/api/pen';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'TransferPigsAcrossBatchesModal',
|
||||||
|
props: {
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
batch: {
|
||||||
|
type: Object,
|
||||||
|
required: true // 源猪群批次信息
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:visible', 'success'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
form: {
|
||||||
|
fromPenID: null,
|
||||||
|
destBatchID: null,
|
||||||
|
toPenID: null,
|
||||||
|
quantity: 1,
|
||||||
|
remarks: ''
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
fromPenID: [{ required: true, message: '请选择源猪栏', trigger: 'change' }],
|
||||||
|
destBatchID: [{ required: true, message: '请选择目标猪群批次', trigger: 'change' }],
|
||||||
|
toPenID: [{ required: true, message: '请选择目标猪栏', trigger: 'change' }],
|
||||||
|
quantity: [
|
||||||
|
{ required: true, message: '请输入调栏数量', trigger: 'blur' },
|
||||||
|
{ type: 'integer', message: '请输入整数', trigger: 'blur' },
|
||||||
|
{ validator: this.validateQuantity, trigger: 'blur' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
sourcePens: [], // 源猪群的猪栏列表
|
||||||
|
availableBatches: [], // 可用的目标猪群列表
|
||||||
|
destinationPens: [], // 目标猪群的猪栏列表
|
||||||
|
maxTransferQuantity: 1 // 最大可调栏数量
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
visible(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
this.initData();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'form.fromPenID': function(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
const selectedPen = this.sourcePens.find(pen => pen.id === newVal);
|
||||||
|
this.maxTransferQuantity = selectedPen ? selectedPen.current_pig_count : 1;
|
||||||
|
// 如果当前数量大于最大值,重置数量
|
||||||
|
if (this.form.quantity > this.maxTransferQuantity) {
|
||||||
|
this.form.quantity = this.maxTransferQuantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async initData() {
|
||||||
|
this.resetForm();
|
||||||
|
this.sourcePens = this.batch.pens.filter(pen => pen.current_pig_count > 0); // 过滤掉没有猪的猪栏
|
||||||
|
await this.fetchAvailableBatchesAndPens();
|
||||||
|
},
|
||||||
|
async fetchAvailableBatchesAndPens() {
|
||||||
|
try {
|
||||||
|
const [batchesResponse, pensResponse] = await Promise.all([
|
||||||
|
getPigBatches({ is_active: true }), // 获取所有活跃猪群
|
||||||
|
getPens() // 获取所有猪栏
|
||||||
|
]);
|
||||||
|
|
||||||
|
const allBatches = batchesResponse.data || [];
|
||||||
|
const allPens = pensResponse.data || [];
|
||||||
|
|
||||||
|
// 过滤掉源猪群自身,以及非活跃的猪群
|
||||||
|
this.availableBatches = allBatches.filter(b => b.id !== this.batch.id && b.is_active);
|
||||||
|
|
||||||
|
// 将所有猪栏按批次ID分组,方便后续查找
|
||||||
|
const pensByBatch = allPens.reduce((acc, pen) => {
|
||||||
|
if (pen.pig_batch_id) {
|
||||||
|
if (!acc[pen.pig_batch_id]) {
|
||||||
|
acc[pen.pig_batch_id] = [];
|
||||||
|
}
|
||||||
|
acc[pen.pig_batch_id].push(pen);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
this.pensByBatch = pensByBatch; // 存储起来,以便 onDestBatchChange 使用
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching batches or pens:", error);
|
||||||
|
this.$message.error("获取猪群或猪栏信息失败");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDestBatchChange(batchId) {
|
||||||
|
this.form.toPenID = null; // 重置目标猪栏选择
|
||||||
|
// 允许选择目标批次下的所有猪栏,包括已满的
|
||||||
|
this.destinationPens = (this.pensByBatch[batchId] || []);
|
||||||
|
},
|
||||||
|
validateQuantity(rule, value, callback) {
|
||||||
|
if (value > this.maxTransferQuantity) {
|
||||||
|
callback(new Error(`调栏数量不能超过源猪栏存栏数量 (${this.maxTransferQuantity})`));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleConfirm() {
|
||||||
|
this.$refs.form.validate(async valid => {
|
||||||
|
if (valid) {
|
||||||
|
try {
|
||||||
|
await transferPigsAcrossBatches(this.batch.id, {
|
||||||
|
fromPenID: this.form.fromPenID,
|
||||||
|
destBatchID: this.form.destBatchID,
|
||||||
|
toPenID: this.form.toPenID,
|
||||||
|
quantity: this.form.quantity,
|
||||||
|
remarks: this.form.remarks
|
||||||
|
});
|
||||||
|
this.$message.success('跨群调栏成功');
|
||||||
|
this.$emit('success');
|
||||||
|
this.$emit('update:visible', false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error transferring pigs across batches:', error);
|
||||||
|
this.$message.error('跨群调栏失败: ' + (error.response?.data?.message || error.message || '未知错误'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
this.$refs.form?.resetFields();
|
||||||
|
this.form.fromPenID = null;
|
||||||
|
this.form.destBatchID = null;
|
||||||
|
this.form.toPenID = null;
|
||||||
|
this.form.quantity = 1;
|
||||||
|
this.form.remarks = '';
|
||||||
|
this.sourcePens = [];
|
||||||
|
this.availableBatches = [];
|
||||||
|
this.destinationPens = [];
|
||||||
|
this.maxTransferQuantity = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
</style>
|
||||||
161
src/components/TransferPigsModal.vue
Normal file
161
src/components/TransferPigsModal.vue
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
title="群内调栏"
|
||||||
|
:model-value="visible"
|
||||||
|
@update:model-value="$emit('update:visible', $event)"
|
||||||
|
width="500px"
|
||||||
|
:before-close="handleClose"
|
||||||
|
>
|
||||||
|
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||||
|
<el-form-item label="调出猪栏" prop="fromPenID">
|
||||||
|
<el-select v-model="form.fromPenID" placeholder="请选择调出猪栏" style="width: 100%;" @change="handleFromPenChange">
|
||||||
|
<el-option
|
||||||
|
v-for="pen in sourcePens"
|
||||||
|
:key="pen.id"
|
||||||
|
:label="`${pen.pen_number} (存栏: ${pen.current_pig_count})`"
|
||||||
|
:value="pen.id"
|
||||||
|
:disabled="pen.current_pig_count === 0"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="调入猪栏" prop="toPenID">
|
||||||
|
<el-select v-model="form.toPenID" placeholder="请选择调入猪栏" style="width: 100%;" :disabled="!form.fromPenID">
|
||||||
|
<el-option
|
||||||
|
v-for="pen in destinationPens"
|
||||||
|
:key="pen.id"
|
||||||
|
:label="`${pen.pen_number} (存栏: ${pen.current_pig_count})`"
|
||||||
|
:value="pen.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="调栏数量" prop="quantity">
|
||||||
|
<el-input-number
|
||||||
|
v-model="form.quantity"
|
||||||
|
:min="1"
|
||||||
|
:max="maxQuantity"
|
||||||
|
:disabled="!form.fromPenID"
|
||||||
|
placeholder="请输入数量"
|
||||||
|
style="width: 100%;"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remarks">
|
||||||
|
<el-input v-model="form.remarks" type="textarea" placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="handleClose">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="handleSubmit" :loading="loading">确 定</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { transferPigsWithinBatch } from '@/api/pigBatch.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'TransferPigsModal',
|
||||||
|
props: {
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
batch: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['update:visible', 'success'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
form: {
|
||||||
|
fromPenID: null,
|
||||||
|
toPenID: null,
|
||||||
|
quantity: 1,
|
||||||
|
remarks: '',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
fromPenID: [{ required: true, message: '请选择调出猪栏', trigger: 'change' }],
|
||||||
|
toPenID: [{ required: true, message: '请选择调入猪栏', trigger: 'change' }],
|
||||||
|
quantity: [{ required: true, message: '请输入调栏数量', trigger: 'blur' }],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
sourcePens() {
|
||||||
|
return this.batch.pens || [];
|
||||||
|
},
|
||||||
|
destinationPens() {
|
||||||
|
if (!this.form.fromPenID) return [];
|
||||||
|
return this.batch.pens.filter(pen => pen.id !== this.form.fromPenID);
|
||||||
|
},
|
||||||
|
maxQuantity() {
|
||||||
|
if (!this.form.fromPenID) return 1;
|
||||||
|
const selectedPen = this.sourcePens.find(p => p.id === this.form.fromPenID);
|
||||||
|
return selectedPen ? selectedPen.current_pig_count : 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
visible(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
this.resetForm();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleFromPenChange(penId) {
|
||||||
|
this.form.toPenID = null;
|
||||||
|
this.form.quantity = 1;
|
||||||
|
const selectedPen = this.sourcePens.find(p => p.id === penId);
|
||||||
|
if (selectedPen && selectedPen.current_pig_count === 0) {
|
||||||
|
this.$message.warning('该猪栏没有猪,无法调出。');
|
||||||
|
this.form.fromPenID = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleSubmit() {
|
||||||
|
this.$refs.formRef.validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
if (this.form.quantity > this.maxQuantity) {
|
||||||
|
this.$message.error('调栏数量不能超过当前存栏量');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
await transferPigsWithinBatch(this.batch.id, this.form);
|
||||||
|
this.$message.success('调栏成功');
|
||||||
|
this.$emit('success');
|
||||||
|
this.handleClose();
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error('调栏失败: ' + (error.response?.data?.message || error.message));
|
||||||
|
console.error('Failed to transfer pigs:', error);
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleClose() {
|
||||||
|
this.$emit('update:visible', false);
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
if (this.$refs.formRef) {
|
||||||
|
this.$refs.formRef.resetFields();
|
||||||
|
}
|
||||||
|
this.form = {
|
||||||
|
fromPenID: null,
|
||||||
|
toPenID: null,
|
||||||
|
quantity: 1,
|
||||||
|
remarks: '',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dialog-footer {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -77,6 +77,10 @@
|
|||||||
<el-icon><FirstAidKit /></el-icon>
|
<el-icon><FirstAidKit /></el-icon>
|
||||||
<template #title>用药记录</template>
|
<template #title>用药记录</template>
|
||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
|
<el-menu-item index="/monitor/notifications">
|
||||||
|
<el-icon><Bell /></el-icon>
|
||||||
|
<template #title>通知记录</template>
|
||||||
|
</el-menu-item>
|
||||||
<el-menu-item index="/monitor/pending-collections">
|
<el-menu-item index="/monitor/pending-collections">
|
||||||
<el-icon><Clock /></el-icon>
|
<el-icon><Clock /></el-icon>
|
||||||
<template #title>待采集请求</template>
|
<template #title>待采集请求</template>
|
||||||
@@ -183,14 +187,14 @@ import { ref, computed, onMounted, onUnmounted } from 'vue';
|
|||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import {
|
import {
|
||||||
House, Monitor, Calendar, ArrowDown, Menu, Fold, Expand, Setting, Tickets, DataAnalysis, Document, Food,
|
House, Monitor, Calendar, ArrowDown, Menu, Fold, Expand, Setting, Tickets, DataAnalysis, Document, Food,
|
||||||
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management
|
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management, Bell
|
||||||
} from '@element-plus/icons-vue';
|
} from '@element-plus/icons-vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MainLayout',
|
name: 'MainLayout',
|
||||||
components: {
|
components: {
|
||||||
House, Monitor, Calendar, ArrowDown, Menu, Fold, Expand, Setting, Tickets, DataAnalysis, Document, Food,
|
House, Monitor, Calendar, ArrowDown, Menu, Fold, Expand, Setting, Tickets, DataAnalysis, Document, Food,
|
||||||
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management
|
FirstAidKit, Clock, Files, ShoppingCart, SoldOut, Warning, Switch, List, Shop, Coin, DataLine, Finished, User, ScaleToOriginal, OfficeBuilding, Management, Bell
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -233,6 +237,7 @@ export default {
|
|||||||
'/monitor/device-command-logs': '设备命令日志',
|
'/monitor/device-command-logs': '设备命令日志',
|
||||||
'/monitor/feed-usage-records': '饲料使用记录',
|
'/monitor/feed-usage-records': '饲料使用记录',
|
||||||
'/monitor/medication-logs': '用药记录',
|
'/monitor/medication-logs': '用药记录',
|
||||||
|
'/monitor/notifications': '通知记录',
|
||||||
'/monitor/pending-collections': '待采集请求',
|
'/monitor/pending-collections': '待采集请求',
|
||||||
'/monitor/pig-batch-logs': '猪批次日志',
|
'/monitor/pig-batch-logs': '猪批次日志',
|
||||||
'/monitor/pig-purchases': '猪只采购记录',
|
'/monitor/pig-purchases': '猪只采购记录',
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import PigBatchManagementView from './views/pms/PigBatchManagementView.vue'; //
|
|||||||
import DeviceCommandLogView from './views/monitor/DeviceCommandLogView.vue';
|
import DeviceCommandLogView from './views/monitor/DeviceCommandLogView.vue';
|
||||||
import FeedUsageRecordsView from './views/monitor/FeedUsageRecordsView.vue';
|
import FeedUsageRecordsView from './views/monitor/FeedUsageRecordsView.vue';
|
||||||
import MedicationLogsView from './views/monitor/MedicationLogsView.vue';
|
import MedicationLogsView from './views/monitor/MedicationLogsView.vue';
|
||||||
|
import NotificationLogView from './views/monitor/NotificationLogView.vue';
|
||||||
import PendingCollectionsView from './views/monitor/PendingCollectionsView.vue';
|
import PendingCollectionsView from './views/monitor/PendingCollectionsView.vue';
|
||||||
import PigBatchLogsView from './views/monitor/PigBatchLogsView.vue';
|
import PigBatchLogsView from './views/monitor/PigBatchLogsView.vue';
|
||||||
import PigPurchasesView from './views/monitor/PigPurchasesView.vue';
|
import PigPurchasesView from './views/monitor/PigPurchasesView.vue';
|
||||||
@@ -50,6 +51,7 @@ const routes = [
|
|||||||
{path: '/monitor/device-command-logs', component: DeviceCommandLogView, meta: {requiresAuth: true}},
|
{path: '/monitor/device-command-logs', component: DeviceCommandLogView, meta: {requiresAuth: true}},
|
||||||
{path: '/monitor/feed-usage-records', component: FeedUsageRecordsView, meta: {requiresAuth: true}},
|
{path: '/monitor/feed-usage-records', component: FeedUsageRecordsView, meta: {requiresAuth: true}},
|
||||||
{path: '/monitor/medication-logs', component: MedicationLogsView, meta: {requiresAuth: true}},
|
{path: '/monitor/medication-logs', component: MedicationLogsView, meta: {requiresAuth: true}},
|
||||||
|
{path: '/monitor/notifications', component: NotificationLogView, meta: {requiresAuth: true}},
|
||||||
{path: '/monitor/pending-collections', component: PendingCollectionsView, meta: {requiresAuth: true}},
|
{path: '/monitor/pending-collections', component: PendingCollectionsView, meta: {requiresAuth: true}},
|
||||||
{path: '/monitor/pig-batch-logs', component: PigBatchLogsView, meta: {requiresAuth: true}},
|
{path: '/monitor/pig-batch-logs', component: PigBatchLogsView, meta: {requiresAuth: true}},
|
||||||
{path: '/monitor/pig-purchases', component: PigPurchasesView, meta: {requiresAuth: true}},
|
{path: '/monitor/pig-purchases', component: PigPurchasesView, meta: {requiresAuth: true}},
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ http.interceptors.response.use(
|
|||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
// 清除token并重定向到登录页
|
// 清除token并重定向到登录页
|
||||||
localStorage.removeItem('jwt_token');
|
localStorage.removeItem('jwt_token');
|
||||||
// 这里需要访问router,但http.js是纯工具文件,不应直接依赖Vue Router实例
|
window.location.href = '/login';
|
||||||
// 可以在main.js的全局错误处理或组件中处理401错误
|
|
||||||
// 例如:window.location.href = '/login';
|
|
||||||
}
|
}
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
// 请求发出但没有收到响应
|
// 请求发出但没有收到响应
|
||||||
|
|||||||
111
src/views/monitor/NotificationLogView.vue
Normal file
111
src/views/monitor/NotificationLogView.vue
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
<template>
|
||||||
|
<div class="notification-log-view">
|
||||||
|
<GenericMonitorList
|
||||||
|
:fetchData="fetchNotifications"
|
||||||
|
:columnsConfig="notificationLogColumns"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import GenericMonitorList from '../../components/GenericMonitorList.vue';
|
||||||
|
import { getNotifications, ZapcoreLevel } from '../../api/monitor.js';
|
||||||
|
import { formatRFC3339 } from '../../utils/format.js';
|
||||||
|
|
||||||
|
// 适配通用组件的 fetchData prop
|
||||||
|
const fetchNotifications = async (params) => {
|
||||||
|
return await getNotifications(params);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 定义表格的列
|
||||||
|
const notificationLogColumns = [
|
||||||
|
{
|
||||||
|
title: '用户ID',
|
||||||
|
dataIndex: 'user_id',
|
||||||
|
key: 'user_id',
|
||||||
|
sorter: true,
|
||||||
|
filterType: 'number',
|
||||||
|
minWidth: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '通知渠道',
|
||||||
|
dataIndex: 'notifier_type',
|
||||||
|
key: 'notifier_type',
|
||||||
|
filterType: 'select',
|
||||||
|
filterOptions: [
|
||||||
|
{ value: '邮件', text: '邮件' },
|
||||||
|
{ value: '企业微信', text: '企业微信' },
|
||||||
|
{ value: '飞书', text: '飞书' },
|
||||||
|
{ value: '日志', text: '日志' },
|
||||||
|
],
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '目标地址',
|
||||||
|
dataIndex: 'to_address',
|
||||||
|
key: 'to_address',
|
||||||
|
minWidth: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '标题',
|
||||||
|
dataIndex: 'title',
|
||||||
|
key: 'title',
|
||||||
|
minWidth: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '消息',
|
||||||
|
dataIndex: 'message',
|
||||||
|
key: 'message',
|
||||||
|
minWidth: 300,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '日志级别',
|
||||||
|
dataIndex: 'level',
|
||||||
|
key: 'level',
|
||||||
|
sorter: true,
|
||||||
|
filterType: 'select',
|
||||||
|
filterOptions: Object.entries(ZapcoreLevel).map(([text, value]) => ({ value, text })),
|
||||||
|
minWidth: 110,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '告警时间',
|
||||||
|
dataIndex: 'alarm_timestamp',
|
||||||
|
key: 'alarm_timestamp',
|
||||||
|
sorter: true,
|
||||||
|
formatter: (row, column, cellValue) => formatRFC3339(cellValue),
|
||||||
|
minWidth: 180,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
key: 'status',
|
||||||
|
filterType: 'select',
|
||||||
|
filterOptions: [
|
||||||
|
{ value: '发送成功', text: '发送成功' },
|
||||||
|
{ value: '发送失败', text: '发送失败' },
|
||||||
|
{ value: '已跳过', text: '已跳过' },
|
||||||
|
],
|
||||||
|
minWidth: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '错误信息',
|
||||||
|
dataIndex: 'error_message',
|
||||||
|
key: 'error_message',
|
||||||
|
minWidth: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'created_at',
|
||||||
|
key: 'created_at',
|
||||||
|
sorter: true,
|
||||||
|
formatter: (row, column, cellValue) => formatRFC3339(cellValue),
|
||||||
|
minWidth: 180,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.notification-log-view {
|
||||||
|
/* 视图容器样式 */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -39,8 +39,12 @@
|
|||||||
@edit-batch="handleEditBatch"
|
@edit-batch="handleEditBatch"
|
||||||
@delete-batch="handleDeleteBatch"
|
@delete-batch="handleDeleteBatch"
|
||||||
@add-pen="handleAddPen"
|
@add-pen="handleAddPen"
|
||||||
@edit-pen="handleEditPen"
|
@modify-pig-count-pen="handleModifyPigCountPen"
|
||||||
@delete-pen="handleDeletePen"
|
@remove-pen="handleRemovePen"
|
||||||
|
@assign-pen-to-batch="handleAssignPenToBatch"
|
||||||
|
@transfer-pigs="handleTransferPigs"
|
||||||
|
@transfer-pigs-across-batches="handleTransferPigsAcrossBatches"
|
||||||
|
@reload-data="loadData"
|
||||||
/>
|
/>
|
||||||
<el-empty v-else description="暂无数据" />
|
<el-empty v-else description="暂无数据" />
|
||||||
</div>
|
</div>
|
||||||
@@ -64,16 +68,33 @@
|
|||||||
@success="handlePenSuccess"
|
@success="handlePenSuccess"
|
||||||
@cancel="penDialogVisible = false"
|
@cancel="penDialogVisible = false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- 群内调栏对话框 -->
|
||||||
|
<TransferPigsModal
|
||||||
|
v-if="transferDialogVisible"
|
||||||
|
v-model:visible="transferDialogVisible"
|
||||||
|
:batch="currentBatchForTransfer"
|
||||||
|
@success="handleTransferSuccess"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 跨群调栏对话框 -->
|
||||||
|
<TransferPigsAcrossBatchesModal
|
||||||
|
v-model:visible="transferAcrossBatchesDialogVisible"
|
||||||
|
:batch="currentBatchForTransferAcrossBatches"
|
||||||
|
@success="handleTransferAcrossBatchesSuccess"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getPigBatches, deletePigBatch } from '@/api/pigBatch.js';
|
import { getPigBatches, deletePigBatch, assignPensToBatch, removePenFromBatch } from '@/api/pigBatch.js';
|
||||||
import { getPens, deletePen } from '@/api/pen.js';
|
import { getPens } from '@/api/pen.js';
|
||||||
import { getPigHouses } from '@/api/pigHouse.js';
|
import { getPigHouses } from '@/api/pigHouse.js';
|
||||||
import PigBatchList from '@/components/PigBatchList.vue';
|
import PigBatchList from '@/components/PigBatchList.vue';
|
||||||
import PigBatchForm from '@/components/PigBatchForm.vue';
|
import PigBatchForm from '@/components/PigBatchForm.vue';
|
||||||
import PenForm from '@/components/PenForm.vue'; // 引入 PenForm
|
import PenForm from '@/components/PenForm.vue';
|
||||||
|
import TransferPigsModal from '@/components/TransferPigsModal.vue';
|
||||||
|
import TransferPigsAcrossBatchesModal from '@/components/TransferPigsAcrossBatchesModal.vue';
|
||||||
import { Refresh } from '@element-plus/icons-vue';
|
import { Refresh } from '@element-plus/icons-vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -82,6 +103,8 @@ export default {
|
|||||||
PigBatchList,
|
PigBatchList,
|
||||||
PigBatchForm,
|
PigBatchForm,
|
||||||
PenForm,
|
PenForm,
|
||||||
|
TransferPigsModal,
|
||||||
|
TransferPigsAcrossBatchesModal,
|
||||||
Refresh
|
Refresh
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -97,6 +120,12 @@ export default {
|
|||||||
penDialogVisible: false,
|
penDialogVisible: false,
|
||||||
isEditPen: false,
|
isEditPen: false,
|
||||||
currentPen: {},
|
currentPen: {},
|
||||||
|
// 调栏模态框状态
|
||||||
|
transferDialogVisible: false,
|
||||||
|
currentBatchForTransfer: {},
|
||||||
|
// 跨群调栏模态框状态
|
||||||
|
transferAcrossBatchesDialogVisible: false,
|
||||||
|
currentBatchForTransferAcrossBatches: {},
|
||||||
// 辅助映射
|
// 辅助映射
|
||||||
houseMap: new Map(), // 用于猪栏显示猪舍名称
|
houseMap: new Map(), // 用于猪栏显示猪舍名称
|
||||||
};
|
};
|
||||||
@@ -119,8 +148,9 @@ export default {
|
|||||||
const pens = Array.isArray(pensResponse.data) ? pensResponse.data : [];
|
const pens = Array.isArray(pensResponse.data) ? pensResponse.data : [];
|
||||||
const houses = Array.isArray(housesResponse.data) ? housesResponse.data : [];
|
const houses = Array.isArray(housesResponse.data) ? housesResponse.data : [];
|
||||||
|
|
||||||
// 更新 houseMap
|
// 更新 batchMap 和 houseMap
|
||||||
this.houseMap = new Map(houses.map(h => [h.id, h.name]));
|
this.houseMap = new Map(houses.map(h => [h.id, h.name]));
|
||||||
|
this.batchMap = new Map(batches.map(batch => [batch.id, batch.batch_number]));
|
||||||
this.pigBatchesData = this.assembleData(batches, pens);
|
this.pigBatchesData = this.assembleData(batches, pens);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -141,12 +171,19 @@ export default {
|
|||||||
if (pen.pig_batch_id && batchMap.has(pen.pig_batch_id)) {
|
if (pen.pig_batch_id && batchMap.has(pen.pig_batch_id)) {
|
||||||
const penWithDetails = {
|
const penWithDetails = {
|
||||||
...pen,
|
...pen,
|
||||||
house_name: this.houseMap.get(pen.house_id) || '未知猪舍'
|
house_name: this.houseMap.get(pen.house_id) || '未知猪舍',
|
||||||
|
batch_number: batchMap.get(pen.pig_batch_id)?.batch_number || null
|
||||||
};
|
};
|
||||||
batchMap.get(pen.pig_batch_id).pens.push(penWithDetails);
|
batchMap.get(pen.pig_batch_id).pens.push(penWithDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Array.from(batchMap.values());
|
// Calculate unassigned_pig_count for each batch using currentTotalQuantity and currentTotalPigsInPens
|
||||||
|
const assembledBatches = Array.from(batchMap.values());
|
||||||
|
assembledBatches.forEach(batch => {
|
||||||
|
// Use currentTotalQuantity and currentTotalPigsInPens directly from the batch object
|
||||||
|
batch.unassigned_pig_count = (batch.currentTotalQuantity || 0) - (batch.currentTotalPigsInPens || 0);
|
||||||
|
});
|
||||||
|
return assembledBatches;
|
||||||
},
|
},
|
||||||
// --- 猪群操作 ---
|
// --- 猪群操作 ---
|
||||||
handleAddBatch() {
|
handleAddBatch() {
|
||||||
@@ -198,34 +235,30 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// --- 猪栏操作 (在猪群管理中) ---
|
// --- 猪栏操作 (在猪群管理中) ---
|
||||||
handleAddPen(batch) {
|
handleAddPen(house) {
|
||||||
this.currentPen = { pig_batch_id: batch.id }; // 预设猪栏所属批次
|
this.currentPen = { ...house }; // 修正:这里应该是传入house对象,而不是pen对象
|
||||||
this.isEditPen = false;
|
this.isEditPen = false;
|
||||||
this.penDialogVisible = true;
|
this.penDialogVisible = true;
|
||||||
},
|
},
|
||||||
handleEditPen(pen) {
|
handleModifyPigCountPen(pen) {
|
||||||
this.currentPen = { ...pen };
|
this.currentPen = { ...pen };
|
||||||
this.isEditPen = true;
|
this.isEditPen = true;
|
||||||
this.penDialogVisible = true;
|
this.penDialogVisible = true;
|
||||||
},
|
},
|
||||||
async handleDeletePen(pen) {
|
async handleRemovePen(pen) {
|
||||||
try {
|
try {
|
||||||
await this.$confirm(`确认删除猪栏 "${pen.pen_number}" 吗?`, '提示', {
|
await this.$confirm(`确认将猪栏 "${pen.pen_number}" 从猪群中移除吗?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
});
|
});
|
||||||
await deletePen(pen.id);
|
await removePenFromBatch(pen.id, pen.pig_batch_id);
|
||||||
this.$message.success('删除成功');
|
this.$message.success('猪栏已成功从猪群中移除');
|
||||||
// 本地更新数据
|
await this.loadData(); // Refresh data to show updated state
|
||||||
const batch = this.pigBatchesData.find(b => b.id === pen.pig_batch_id);
|
|
||||||
if (batch) {
|
|
||||||
batch.pens = batch.pens.filter(p => p.id !== pen.id);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err !== 'cancel') {
|
if (err !== 'cancel') {
|
||||||
this.$message.error('删除失败: ' + (err.message || '未知错误'));
|
this.$message.error('移除失败: ' + (err.message || '未知错误'));
|
||||||
console.error('Failed to delete pen:', err);
|
console.error('Failed to remove pen from batch:', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -253,6 +286,35 @@ export default {
|
|||||||
this.$message.success('猪栏添加成功');
|
this.$message.success('猪栏添加成功');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
async handleAssignPenToBatch({ batchId, penId }) {
|
||||||
|
try {
|
||||||
|
await assignPensToBatch(batchId, { penIds: [penId] });
|
||||||
|
this.$message.success('猪栏分配成功');
|
||||||
|
await this.loadData(); // Refresh data to show assigned pen
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error('分配猪栏失败: ' + (error.response?.data?.message || error.message || '未知错误'));
|
||||||
|
console.error('Failed to assign pen to batch:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// --- 调栏操作 ---
|
||||||
|
handleTransferPigs(batch) {
|
||||||
|
this.currentBatchForTransfer = batch;
|
||||||
|
this.transferDialogVisible = true;
|
||||||
|
},
|
||||||
|
handleTransferSuccess() {
|
||||||
|
this.transferDialogVisible = false;
|
||||||
|
this.loadData(); // 重新加载数据以反映变化
|
||||||
|
},
|
||||||
|
handleTransferPigsAcrossBatches(batch) {
|
||||||
|
console.log('handleTransferPigsAcrossBatches called with batch:', batch);
|
||||||
|
this.currentBatchForTransferAcrossBatches = batch;
|
||||||
|
this.transferAcrossBatchesDialogVisible = true;
|
||||||
|
console.log('transferAcrossBatchesDialogVisible set to:', this.transferAcrossBatchesDialogVisible);
|
||||||
|
},
|
||||||
|
handleTransferAcrossBatchesSuccess() {
|
||||||
|
this.transferAcrossBatchesDialogVisible = false;
|
||||||
|
this.loadData(); // 重新加载数据以反映变化
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
<div class="title-container">
|
<div class="title-container">
|
||||||
<h2 class="page-title">栏舍管理</h2>
|
<h2 class="page-title">栏舍管理</h2>
|
||||||
<el-button type="text" @click="loadData" class="refresh-btn" title="刷新列表">
|
<el-button type="text" @click="loadData" class="refresh-btn" title="刷新列表">
|
||||||
<el-icon :size="20"><Refresh /></el-icon>
|
<el-icon :size="20">
|
||||||
|
<Refresh/>
|
||||||
|
</el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" @click="handleAddHouse">添加猪舍</el-button>
|
<el-button type="primary" @click="handleAddHouse">添加猪舍</el-button>
|
||||||
@@ -15,18 +17,18 @@
|
|||||||
|
|
||||||
<!-- 加载状态 -->
|
<!-- 加载状态 -->
|
||||||
<div v-if="loading" class="loading">
|
<div v-if="loading" class="loading">
|
||||||
<el-skeleton animated />
|
<el-skeleton animated/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 错误状态 -->
|
<!-- 错误状态 -->
|
||||||
<div v-else-if="error" class="error">
|
<div v-else-if="error" class="error">
|
||||||
<el-alert
|
<el-alert
|
||||||
title="获取栏舍数据失败"
|
title="获取栏舍数据失败"
|
||||||
:description="error"
|
:description="error"
|
||||||
type="error"
|
type="error"
|
||||||
show-icon
|
show-icon
|
||||||
closable
|
closable
|
||||||
@close="error = null"
|
@close="error = null"
|
||||||
/>
|
/>
|
||||||
<el-button type="primary" @click="loadData" class="retry-btn">重新加载</el-button>
|
<el-button type="primary" @click="loadData" class="retry-btn">重新加载</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -34,47 +36,48 @@
|
|||||||
<!-- 数据展示或空状态 -->
|
<!-- 数据展示或空状态 -->
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<PigHouseList
|
<PigHouseList
|
||||||
v-if="pigHousesData.length > 0"
|
v-if="pigHousesData.length > 0"
|
||||||
:pigHouses="pigHousesData"
|
:pigHouses="pigHousesData"
|
||||||
@edit-house="handleEditHouse"
|
@edit-house="handleEditHouse"
|
||||||
@delete-house="handleDeleteHouse"
|
@delete-house="handleDeleteHouse"
|
||||||
@add-pen="handleAddPen"
|
@add-pen="handleAddPen"
|
||||||
@edit-pen="handleEditPen"
|
@edit-pen="handleEditPen"
|
||||||
@delete-pen="handleDeletePen"
|
@delete-pen="handleDeletePen"
|
||||||
|
@toggle-house-expand="handleToggleHouseExpand"
|
||||||
/>
|
/>
|
||||||
<el-empty v-else description="暂无数据" />
|
<el-empty v-else description="暂无数据"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
<!-- 猪舍表单对话框 -->
|
<!-- 猪舍表单对话框 -->
|
||||||
<PigHouseForm
|
<PigHouseForm
|
||||||
v-model:visible="houseDialogVisible"
|
v-model:visible="houseDialogVisible"
|
||||||
:house-data="currentHouse"
|
:house-data="currentHouse"
|
||||||
:is-edit="isEditHouse"
|
:is-edit="isEditHouse"
|
||||||
@success="handleHouseSuccess"
|
@success="handleHouseSuccess"
|
||||||
@cancel="houseDialogVisible = false"
|
@cancel="houseDialogVisible = false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 猪栏表单对话框 -->
|
<!-- 猪栏表单对话框 -->
|
||||||
<PenForm
|
<PenForm
|
||||||
v-model:visible="penDialogVisible"
|
v-model:visible="penDialogVisible"
|
||||||
:pen-data="currentPen"
|
:pen-data="currentPen"
|
||||||
:is-edit="isEditPen"
|
:is-edit="isEditPen"
|
||||||
@success="handlePenSuccess"
|
@success="handlePenSuccess"
|
||||||
@cancel="penDialogVisible = false"
|
@cancel="penDialogVisible = false"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getPigHouses, deletePigHouse } from '@/api/pigHouse.js';
|
import {getPigHouses, deletePigHouse} from '@/api/pigHouse.js';
|
||||||
import { getPens, deletePen } from '@/api/pen.js';
|
import {getPens, deletePen} from '@/api/pen.js';
|
||||||
import { getPigBatches } from '@/api/pigBatch.js';
|
import {getPigBatches} from '@/api/pigBatch.js';
|
||||||
import PigHouseList from '@/components/PigHouseList.vue';
|
import PigHouseList from '@/components/PigHouseList.vue';
|
||||||
import PigHouseForm from '@/components/PigHouseForm.vue';
|
import PigHouseForm from '@/components/PigHouseForm.vue';
|
||||||
import PenForm from '@/components/PenForm.vue';
|
import PenForm from '@/components/PenForm.vue';
|
||||||
import { Refresh } from '@element-plus/icons-vue';
|
import {Refresh} from '@element-plus/icons-vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PigFarmManagementView',
|
name: 'PigFarmManagementView',
|
||||||
@@ -136,7 +139,7 @@ export default {
|
|||||||
houses.forEach(house => {
|
houses.forEach(house => {
|
||||||
// 确保保留 isExpanded 状态
|
// 确保保留 isExpanded 状态
|
||||||
const existingHouse = this.pigHousesData.find(h => h.id === house.id);
|
const existingHouse = this.pigHousesData.find(h => h.id === house.id);
|
||||||
houseMap.set(house.id, { ...house, pens: [], isExpanded: existingHouse ? existingHouse.isExpanded : false });
|
houseMap.set(house.id, {...house, pens: [], isExpanded: existingHouse ? existingHouse.isExpanded : false});
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const pen of pens) {
|
for (const pen of pens) {
|
||||||
@@ -157,7 +160,7 @@ export default {
|
|||||||
this.houseDialogVisible = true;
|
this.houseDialogVisible = true;
|
||||||
},
|
},
|
||||||
handleEditHouse(house) {
|
handleEditHouse(house) {
|
||||||
this.currentHouse = { ...house };
|
this.currentHouse = {...house};
|
||||||
this.isEditHouse = true;
|
this.isEditHouse = true;
|
||||||
this.houseDialogVisible = true;
|
this.houseDialogVisible = true;
|
||||||
},
|
},
|
||||||
@@ -187,23 +190,23 @@ export default {
|
|||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// 保留 pens 和 isExpanded 状态
|
// 保留 pens 和 isExpanded 状态
|
||||||
const existingHouse = this.pigHousesData[index];
|
const existingHouse = this.pigHousesData[index];
|
||||||
this.pigHousesData[index] = { ...newHouseData, pens: existingHouse.pens, isExpanded: existingHouse.isExpanded };
|
this.pigHousesData[index] = {...newHouseData, pens: existingHouse.pens, isExpanded: existingHouse.isExpanded};
|
||||||
}
|
}
|
||||||
this.$message.success('猪舍更新成功');
|
this.$message.success('猪舍更新成功');
|
||||||
} else {
|
} else {
|
||||||
// 添加新猪舍
|
// 添加新猪舍
|
||||||
this.pigHousesData.push({ ...newHouseData, pens: [], isExpanded: false });
|
this.pigHousesData.push({...newHouseData, pens: [], isExpanded: false});
|
||||||
this.$message.success('猪舍添加成功');
|
this.$message.success('猪舍添加成功');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// --- 猪栏操作 ---
|
// --- 猪栏操作 ---
|
||||||
handleAddPen(house) {
|
handleAddPen(house) {
|
||||||
this.currentPen = { house_id: house.id };
|
this.currentPen = {house_id: house.id};
|
||||||
this.isEditPen = false;
|
this.isEditPen = false;
|
||||||
this.penDialogVisible = true;
|
this.penDialogVisible = true;
|
||||||
},
|
},
|
||||||
handleEditPen(pen) {
|
handleEditPen(pen) {
|
||||||
this.currentPen = { ...pen };
|
this.currentPen = {...pen};
|
||||||
this.isEditPen = true;
|
this.isEditPen = true;
|
||||||
this.penDialogVisible = true;
|
this.penDialogVisible = true;
|
||||||
},
|
},
|
||||||
@@ -251,6 +254,12 @@ export default {
|
|||||||
this.$message.success('猪栏添加成功');
|
this.$message.success('猪栏添加成功');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
handleToggleHouseExpand(houseId) {
|
||||||
|
const house = this.pigHousesData.find(h => h.id === houseId);
|
||||||
|
if (house) {
|
||||||
|
house.isExpanded = !house.isExpanded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,6 +321,7 @@ export default {
|
|||||||
.pig-farm-management {
|
.pig-farm-management {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-header {
|
.card-header {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 15px;
|
gap: 15px;
|
||||||
|
|||||||
Reference in New Issue
Block a user