95 lines
4.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package schema
import (
"time"
"ifms/pkg/util"
)
// 设备类型1增氧机、2投喂机、3水循环
const (
DeviceTypeAeration = 1
DeviceTypeFeeding = 2
DeviceTypeWaterCirculation = 3
)
// 设备管理
type Device struct {
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
// 预加载信息
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:水循环配置;"`
}
// Defining the query parameters for the `Device` struct.
type DeviceQueryParam struct {
util.PaginationParam
DeviceName string `form:"device_name"`
Type *int `form:"type"`
}
// 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"` // 关联车间名称
DeviceFishPonds []*DeviceFishPond `json:"device_fish_ponds" gorm:"foreignKey:DeviceID;references:ID;comment:关联鱼池ID;"`
}
// 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"`
}