From 3e72a10e4e596451efdfebf6b0b3105a0e6da39b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 27 十月 2023 16:05:53 +0800
Subject: [PATCH] add log
---
model/device_plc.go | 59 ++++++++++++++++++++++++++++++-----------------------------
1 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/model/device_plc.go b/model/device_plc.go
index d2690ea..a098e81 100644
--- a/model/device_plc.go
+++ b/model/device_plc.go
@@ -5,25 +5,28 @@
"apsClient/pkg/sqlitex"
"encoding/json"
"fmt"
- "gorm.io/gorm"
+ "github.com/jinzhu/gorm"
)
type (
// DevicePlc 璁惧鐨凱LC閰嶇疆
DevicePlc struct {
- gorm.Model `json:"-"`
- Id int `gorm:"primarykey;type:int;" json:"id"`
- Brand string `gorm:"type:varchar(191);comment:PLC鍝佺墝" json:"brand"`
- Method constvar.PlcMethod `gorm:"type:varchar(191);comment:鎺ュ彛鏂瑰紡" json:"method"`
- //PortName string `gorm:"type:varchar(191);comment:绔彛鍚嶇О" json:"portName"`
- //Frequency int `gorm:"type:int(11);comment:鏁版嵁鏇存柊棰戠巼 0-瀹炴椂鏇存柊 1-1娆�/绉�" json:"frequency"`
- Address string `gorm:"type:varchar(191);comment:PLC鍦板潃" json:"address"` //plc ip鍦板潃锛� method = modbusTCP鐢�
- Port int `gorm:"type:int(11);comment:绔彛" json:"port"` //plc 绔彛鍙凤紝 method = modbusTCP鐢�
- BaudRate int `gorm:"type:int(11);comment:娉㈢壒鐜�" json:"baudRate"` //涓插彛娉㈢壒鐜囷紝 method = serial鏃� 鐢�
- SerialName string `gorm:"type:int(11);comment:涓插彛鍚嶇О" json:"serialName"` //涓插彛鍚嶇О锛宮ethod = serial鏃� 鐢�
- IsOpen bool `gorm:"type:tinyint(1);comment:鏄惁寮�鍚�" json:"isOpen"`
- Detail string `gorm:"type:varchar(2048);comment:鏁版嵁璇︽儏" json:"-"`
+ gorm.Model
+ DeviceID string `gorm:"column:device_id;type:varchar(255);not null;unique" json:"deviceID"` //璁惧缂栧彿
+ Brand string `gorm:"type:varchar(191)" json:"brand"`
+ Method constvar.PlcMethod `gorm:"type:varchar(191)" json:"method"`
+ Address string `gorm:"type:varchar(191)" json:"address"` //plc ip鍦板潃锛� method = modbusTCP鐢�
+ Port int `json:"port"` //plc 绔彛鍙凤紝 method = modbusTCP鐢�
+ BaudRate int `json:"baudRate"` //涓插彛娉㈢壒鐜囷紝 method = serial鏃� 鐢�
+ SerialName string `json:"serialName"` //涓插彛鍚嶇О锛宮ethod = serial鏃� 鐢�
+
+ DataBit int `gorm:"type:int(11)" json:"dataBit"` //鏁版嵁浣嶏紝method = modbusRTU 鐢�
+ StopBit int `gorm:"type:int(11)" json:"stopBit"` //鍋滄浣嶏紝method = modbusRTU 鐢�
+ Parity constvar.Parity `gorm:"type:int(11)" json:"parity"` //鏍¢獙鏂瑰紡锛宮ethod = modbusRTU 鐢�
+
+ IsOpen bool `json:"isOpen"`
+ Detail string `gorm:"type:varchar(2048)" json:"-"`
Details []*DevicePlcAddress `gorm:"-" json:"details"`
@@ -33,7 +36,7 @@
}
DevicePlcAddress struct {
- Position int `json:"position"` // 鏁版嵁璧峰鍦板潃
+ Channel int32 `json:"channel"` // 鏁版嵁璧峰鍦板潃
StartAddress int `json:"startAddress"` // 鏁版嵁璧峰鍦板潃
Length int `json:"length"` // 鏁版嵁闀垮害
Type constvar.PlcStartAddressValueType `json:"type"` // 鏁版嵁绫诲瀷
@@ -82,16 +85,25 @@
return slf
}
-func (slf *DevicePlcSearch) SetId(id int) *DevicePlcSearch {
- slf.Id = id
+func (slf *DevicePlcSearch) SetId(id uint) *DevicePlcSearch {
+ slf.ID = id
+ return slf
+}
+
+func (slf *DevicePlcSearch) SetDeviceId(deviceId string) *DevicePlcSearch {
+ slf.DeviceID = deviceId
return slf
}
func (slf *DevicePlcSearch) build() *gorm.DB {
var db = slf.Orm.Table(slf.TableName())
- if slf.Id > 0 {
- db = db.Where("id = ?", slf.Id)
+ if slf.ID > 0 {
+ db = db.Where("id = ?", slf.ID)
+ }
+
+ if slf.DeviceID != "" {
+ db = db.Where("device_id = ?", slf.DeviceID)
}
if slf.Order != "" {
@@ -107,17 +119,6 @@
if err := db.Create(record).Error; err != nil {
return fmt.Errorf("create err: %v, record: %+v", err, record)
- }
-
- return nil
-}
-
-// CreateBatch 鎵归噺鎻掑叆
-func (slf *DevicePlcSearch) CreateBatch(records []*DevicePlc) error {
- var db = slf.build()
-
- if err := db.Create(&records).Error; err != nil {
- return fmt.Errorf("create batch err: %v, records: %+v", err, records)
}
return nil
--
Gitblit v1.8.0