From 53d80c839ad2aad0a0482ca43fca1fc3a95b9d1c Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 03 十一月 2023 17:30:54 +0800 Subject: [PATCH] 更改路由 --- model/device.go | 30 +++++++++++++++++++++++++----- 1 files changed, 25 insertions(+), 5 deletions(-) diff --git a/model/device.go b/model/device.go index 46e2665..a4f8edf 100644 --- a/model/device.go +++ b/model/device.go @@ -11,18 +11,20 @@ // Device 璁惧 Device struct { gorm.Model - DeviceID string `gorm:"unique;column:device_id;type:varchar(255);not null;default ''" json:"deviceID"` //璁惧缂栧彿 + DeviceID string `gorm:"column:device_id;type:varchar(255);not null;unique" json:"deviceID"` //璁惧缂栧彿 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:"procedureAdd"` //璁惧鏀寔鐨勫伐搴忓垏鐗� } DeviceSearch struct { Device - Order string - PageNum int - PageSize int - Orm *gorm.DB + Order string + PageNum int + PageSize int + Orm *gorm.DB + DeviceIDs []string } ) @@ -64,6 +66,16 @@ 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()) @@ -75,6 +87,14 @@ 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) } -- Gitblit v1.8.0