From 4497935a55e286ee922b99e6e478b7714a35d0b2 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 03 十一月 2023 16:28:33 +0800
Subject: [PATCH] fix
---
model/device.go | 40 ++++++++++++++++++++++++++++++----------
1 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/model/device.go b/model/device.go
index 0a1f686..a4f8edf 100644
--- a/model/device.go
+++ b/model/device.go
@@ -3,26 +3,28 @@
import (
"apsClient/pkg/sqlitex"
"fmt"
- "gorm.io/gorm"
+ "github.com/jinzhu/gorm"
"strings"
)
type (
// Device 璁惧
Device struct {
- gorm.Model `json:"-"`
- DeviceID string `gorm:"unique;column:device_id;type:varchar(255);not null;default '';comment:璁惧缂栧彿" json:"deviceID"` //璁惧缂栧彿
- ExtChannelAmount int `gorm:"type:tinyint;comment:棰濆鐨勯�氶亾鏁伴噺;default:0;" json:"extChannelAmount"`
- Procedures string `gorm:"column:procedure;type:varchar(255);not null;default '';comment:宸ュ簭" json:"procedures"` //璁惧鏀寔鐨勫伐搴忥紝鐢ㄩ�楀彿鍒嗛殧
- ProceduresArr []string `gorm:"-" json:"procedureAdd"` //璁惧鏀寔鐨勫伐搴忓垏鐗�
+ gorm.Model
+ 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