| | |
| | | // Device 设备 |
| | | Device struct { |
| | | gorm.Model |
| | | DeviceID string `gorm:"unique;column:device_id;type:varchar(255);not null;default ''" json:"deviceID"` //设备编号 |
| | | ExtChannelAmount int `gorm:"type:tinyint;default:0" json:"extChannelAmount"` |
| | | Procedures string `gorm:"column:procedure;type:varchar(255);not null;default ''" json:"procedures"` //设备支持的工序,用逗号分隔 |
| | | ProceduresArr []string `gorm:"-" json:"procedureAdd"` //设备支持的工序切片 |
| | | DeviceID string `gorm:"column:device_id;type:varchar(255);not null;unique" json:"deviceID"` //设备编号 |
| | | DeviceName string `gorm:"column:device_name;type:varchar(255);" json:"deviceName"` //设备名称 |
| | | ExtChannelAmount int `gorm:"type:tinyint;default:0" json:"extChannelAmount"` |
| | | Procedures string `gorm:"column:procedure;type:varchar(255);not null;default ''" json:"procedures"` //设备支持的工序,用逗号分隔 |
| | | DeviceMac string `gorm:"type:varchar(255);" json:"deviceMac"` //绑定的工控机设备ID |
| | | ProceduresArr []string `gorm:"-" json:"ProceduresArr"` //设备支持的工序切片 |
| | | NeedSetProcessParams bool `gorm:"column:need_set_process_params" json:"needSetProcessParams"` //是否需要设置工艺参数 //设备支持的工序切片 |
| | | } |
| | | |
| | | DeviceSearch struct { |
| | | Device |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | DeviceIDs []string |
| | | } |
| | | ) |
| | | |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DeviceSearch) SetDeviceMac(deviceMac string) *DeviceSearch { |
| | | slf.DeviceMac = deviceMac |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DeviceSearch) SetDeviceIds(deviceIds []string) *DeviceSearch { |
| | | slf.DeviceIDs = deviceIds |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DeviceSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | |
| | | db = db.Where("device_id = ?", slf.DeviceID) |
| | | } |
| | | |
| | | if slf.DeviceMac != "" { |
| | | db = db.Where("device_mac = ?", slf.DeviceMac) |
| | | } |
| | | |
| | | if len(slf.DeviceIDs) != 0 { |
| | | db = db.Where("device_id in (?)", slf.DeviceIDs) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |