Files
smart-crop-ui/crop-x/src/apis/modules/irrigation.ts

192 lines
5.8 KiB
TypeScript

import { request } from '../request'
import { ApiResponse, PaginatedResponse, QueryRequest } from '../types'
// 灌溉控制相关类型
export interface IrrigationSystem {
id: string
name: string
type: 'drip' | 'sprinkler' | 'flood' | 'micro_sprinkler'
location: string
landParcelId: string
area: number
waterSource: string
pumpCapacity: number
flowRate: number
pressure: number
status: 'active' | 'inactive' | 'maintenance'
installationDate: string
lastMaintenanceDate?: string
nextMaintenanceDate?: string
description?: string
tenantId: string
createdAt: string
updatedAt: string
}
export interface IrrigationZone {
id: string
systemId: string
name: string
area: number
cropType: string
soilType: string
waterRequirement: number
currentMoisture: number
targetMoisture: number
status: 'active' | 'inactive' | 'irrigating'
sensors: Array<{
id: string
type: 'moisture' | 'temperature' | 'humidity' | 'ph'
location: string
currentValue: number
unit: string
lastReading: string
}>
valves: Array<{
id: string
name: string
status: 'open' | 'closed'
flowRate: number
}>
createdAt: string
updatedAt: string
}
export interface IrrigationSchedule {
id: string
zoneId: string
name: string
type: 'fixed_time' | 'sensor_based' | 'weather_based'
startTime: string
duration: number
waterAmount: number
frequency: 'daily' | 'weekly' | 'custom'
daysOfWeek?: number[]
startDate: string
endDate?: string
priority: 'low' | 'medium' | 'high'
status: 'active' | 'paused' | 'completed' | 'cancelled'
conditions?: {
moistureThreshold?: number
weatherCondition?: string
temperatureRange?: {
min: number
max: number
}
}
createdAt: string
updatedAt: string
}
export interface MonitoringData {
id: string
zoneId: string
sensorType: 'moisture' | 'temperature' | 'humidity' | 'ph' | 'flow_rate' | 'pressure'
value: number
unit: string
timestamp: string
location?: string
}
export interface ControlCommand {
id: string
systemId: string
zoneId?: string
command: 'start_irrigation' | 'stop_irrigation' | 'open_valve' | 'close_valve' | 'adjust_flow_rate'
parameters: Record<string, any>
status: 'pending' | 'executing' | 'completed' | 'failed'
executedAt?: string
errorMessage?: string
createdAt: string
updatedAt: string
}
export const irrigationApi = {
// 系统控制
getSystemList: (params: QueryRequest): Promise<ApiResponse<PaginatedResponse<IrrigationSystem>>> => {
return request.get('/irrigation/systems', params)
},
getSystemDetail: (id: string): Promise<ApiResponse<IrrigationSystem>> => {
return request.get(`/irrigation/systems/${id}`)
},
createSystem: (data: Omit<IrrigationSystem, 'id' | 'createdAt' | 'updatedAt'>): Promise<ApiResponse<IrrigationSystem>> => {
return request.post('/irrigation/systems', data)
},
updateSystem: (id: string, data: Partial<IrrigationSystem>): Promise<ApiResponse<IrrigationSystem>> => {
return request.put(`/irrigation/systems/${id}`, data)
},
deleteSystem: (id: string): Promise<ApiResponse<void>> => {
return request.delete(`/irrigation/systems/${id}`)
},
startIrrigation: (systemId: string, zoneId?: string, duration?: number): Promise<ApiResponse<ControlCommand>> => {
return request.post(`/irrigation/systems/${systemId}/start`, { zoneId, duration })
},
stopIrrigation: (systemId: string, zoneId?: string): Promise<ApiResponse<ControlCommand>> => {
return request.post(`/irrigation/systems/${systemId}/stop`, { zoneId })
},
// 分区管理
getZoneList: (systemId: string, params: QueryRequest): Promise<ApiResponse<PaginatedResponse<IrrigationZone>>> => {
return request.get(`/irrigation/systems/${systemId}/zones`, params)
},
getZoneDetail: (id: string): Promise<ApiResponse<IrrigationZone>> => {
return request.get(`/irrigation/zones/${id}`)
},
createZone: (data: Omit<IrrigationZone, 'id' | 'createdAt' | 'updatedAt'>): Promise<ApiResponse<IrrigationZone>> => {
return request.post('/irrigation/zones', data)
},
updateZone: (id: string, data: Partial<IrrigationZone>): Promise<ApiResponse<IrrigationZone>> => {
return request.put(`/irrigation/zones/${id}`, data)
},
deleteZone: (id: string): Promise<ApiResponse<void>> => {
return request.delete(`/irrigation/zones/${id}`)
},
// 监控系统
getMonitoringData: (zoneId: string, params: QueryRequest & { sensorType?: string }): Promise<ApiResponse<PaginatedResponse<MonitoringData>>> => {
return request.get(`/irrigation/zones/${zoneId}/monitoring`, params)
},
getRealTimeData: (zoneId: string): Promise<ApiResponse<MonitoringData[]>> => {
return request.get(`/irrigation/zones/${zoneId}/realtime`)
},
// 调度系统
getScheduleList: (params: QueryRequest): Promise<ApiResponse<PaginatedResponse<IrrigationSchedule>>> => {
return request.get('/irrigation/schedules', params)
},
getScheduleDetail: (id: string): Promise<ApiResponse<IrrigationSchedule>> => {
return request.get(`/irrigation/schedules/${id}`)
},
createSchedule: (data: Omit<IrrigationSchedule, 'id' | 'createdAt' | 'updatedAt'>): Promise<ApiResponse<IrrigationSchedule>> => {
return request.post('/irrigation/schedules', data)
},
updateSchedule: (id: string, data: Partial<IrrigationSchedule>): Promise<ApiResponse<IrrigationSchedule>> => {
return request.put(`/irrigation/schedules/${id}`, data)
},
deleteSchedule: (id: string): Promise<ApiResponse<void>> => {
return request.delete(`/irrigation/schedules/${id}`)
},
pauseSchedule: (id: string): Promise<ApiResponse<IrrigationSchedule>> => {
return request.post(`/irrigation/schedules/${id}/pause`)
},
resumeSchedule: (id: string): Promise<ApiResponse<IrrigationSchedule>> => {
return request.post(`/irrigation/schedules/${id}/resume`)
}
}