From 08e7f0e4148808ce435b213f09dc8b80eebb6613 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 26 十月 2023 11:00:24 +0800 Subject: [PATCH] fix --- model/device.go | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/model/device.go b/model/device.go index 46e2665..2919584 100644 --- a/model/device.go +++ b/model/device.go @@ -11,7 +11,7 @@ // 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"` //璁惧鏀寔鐨勫伐搴忥紝鐢ㄩ�楀彿鍒嗛殧 ProceduresArr []string `gorm:"-" json:"procedureAdd"` //璁惧鏀寔鐨勫伐搴忓垏鐗� @@ -19,10 +19,11 @@ 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 +65,11 @@ 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 +81,10 @@ db = db.Where("device_id = ?", slf.DeviceID) } + 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