2025-06-12 14:39:27 +08:00
|
|
|
|
package schema
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"ifms/pkg/util"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 设备类型(1增氧机、2投喂机、3水循环)
|
|
|
|
|
const (
|
|
|
|
|
DeviceTypeAeration = 1
|
|
|
|
|
DeviceTypeFeeding = 2
|
|
|
|
|
DeviceTypeWaterCirculation = 3
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 设备管理
|
|
|
|
|
type Device struct {
|
2025-06-12 15:43:56 +08:00
|
|
|
|
ID int64 `json:"id" gorm:"primaryKey;comment:Unique ID;"` // Unique ID
|
|
|
|
|
TenantID string `json:"tenant_id" gorm:"size:32;"` // Tenant ID
|
|
|
|
|
DeviceNo string `json:"device_no" gorm:"size:32;comment:设备编号;"` // 设备编号
|
|
|
|
|
Name string `json:"name" gorm:"size:64;comment:设备名称;"` // 设备名称
|
|
|
|
|
Type int `json:"type" gorm:"comment:设备类型(1增氧机、2投喂机、3水循环);"` // 设备类型(1增氧机、2投喂机、3水循环)
|
|
|
|
|
Status bool `json:"status" gorm:"comment:设备状态(true=在线,false=离线);"` // 设备状态(true=在线,false=离线)
|
|
|
|
|
Model string `json:"model" gorm:"size:64;comment:设备型号;"` // 设备型号
|
|
|
|
|
WorkshopID int64 `json:"workshop_id" gorm:"foreignKey:ID;references:work_shop;comment:关联车间ID;"` // 关联车间ID
|
|
|
|
|
WorkshopName string `json:"workshop_name" gorm:"comment:关联车间名称;"` // 关联车间名称
|
|
|
|
|
CreatedAt time.Time `json:"created_at" gorm:"comment:Create time;"` // Create time
|
|
|
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"comment:Update time;"` // Update time
|
2025-06-12 14:39:27 +08:00
|
|
|
|
// 预加载信息
|
2025-06-12 15:43:56 +08:00
|
|
|
|
DeviceFishPonds []*DeviceFishPond `json:"device_fish_ponds" gorm:"foreignKey:DeviceID;references:ID;comment:关联鱼池ID;"`
|
|
|
|
|
DeviceConfigAeration *DeviceConfigAeration `json:"device_config_aeration" gorm:"foreignKey:DeviceID;references:ID;comment:增氧机配置;"`
|
|
|
|
|
DeviceConfigFeeding *DeviceConfigFeeding `json:"device_config_feeding" gorm:"foreignKey:DeviceID;references:ID;comment:投喂机配置;"`
|
|
|
|
|
DeviceConfigWaterCirculation *DeviceConfigWaterCirculation `json:"device_config_water_circulation" gorm:"foreignKey:DeviceID;references:ID;comment:水循环配置;"`
|
2025-06-12 14:39:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Defining the query parameters for the `Device` struct.
|
|
|
|
|
type DeviceQueryParam struct {
|
|
|
|
|
util.PaginationParam
|
2025-06-14 09:33:42 +08:00
|
|
|
|
DeviceName string `form:"device_name"`
|
|
|
|
|
Type *int `form:"type"`
|
2025-06-12 14:39:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Defining the query options for the `Device` struct.
|
|
|
|
|
type DeviceQueryOptions struct {
|
|
|
|
|
util.QueryOptions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Defining the query result for the `Device` struct.
|
|
|
|
|
type DeviceQueryResult struct {
|
|
|
|
|
Data Devices
|
|
|
|
|
PageResult *util.PaginationResult
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Defining the slice of `Device` struct.
|
|
|
|
|
type Devices []*Device
|
|
|
|
|
|
|
|
|
|
// Defining the data structure for creating a `Device` struct.
|
|
|
|
|
type DeviceForm struct {
|
|
|
|
|
TenantID string `json:"tenant_id"` // 租户ID
|
|
|
|
|
DeviceNo string `json:"device_no" binding:"required,max=32"` // 设备编号
|
|
|
|
|
Name string `json:"name" binding:"required,max=64"` // 设备名称
|
|
|
|
|
Type int `json:"type" binding:"required"` // 设备类型(1增氧机、2投喂机、3水循环)
|
|
|
|
|
Status bool `json:"status"` // 设备状态(true=在线,false=离线)
|
|
|
|
|
Model string `json:"model" binding:"required,max=64"` // 设备型号
|
|
|
|
|
WorkshopID int64 `json:"workshop_id" binding:"required"` // 关联车间ID
|
|
|
|
|
WorkshopName string `json:"workshop_name" binding:"required"` // 关联车间名称
|
2025-06-12 15:43:56 +08:00
|
|
|
|
DeviceFishPonds []*DeviceFishPond `json:"device_fish_ponds" gorm:"foreignKey:DeviceID;references:ID;comment:关联鱼池ID;"`
|
2025-06-12 14:39:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A validation function for the `DeviceForm` struct.
|
|
|
|
|
func (a *DeviceForm) Validate() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert `DeviceForm` to `Device` object.
|
|
|
|
|
func (a *DeviceForm) FillTo(device *Device) error {
|
|
|
|
|
device.TenantID = a.TenantID
|
|
|
|
|
device.DeviceNo = a.DeviceNo
|
|
|
|
|
device.Name = a.Name
|
|
|
|
|
device.Type = a.Type
|
|
|
|
|
device.Status = a.Status
|
|
|
|
|
device.Model = a.Model
|
|
|
|
|
device.WorkshopID = a.WorkshopID
|
|
|
|
|
device.WorkshopName = a.WorkshopName
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DeviceStatistics struct {
|
|
|
|
|
Type int `json:"type"`
|
|
|
|
|
Total int `json:"total"`
|
|
|
|
|
Online int `json:"online"`
|
|
|
|
|
Offline int `json:"offline"`
|
|
|
|
|
Rate int `json:"rate"`
|
|
|
|
|
}
|