From 2d6875c93b25d0b7336c7fa11e066d213259fe2e Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 25 四月 2024 10:02:01 +0800 Subject: [PATCH] 更改定时任务时区设置 --- model/device_plc.go | 27 ++++++++++++++++++--------- 1 files changed, 18 insertions(+), 9 deletions(-) diff --git a/model/device_plc.go b/model/device_plc.go index 2a2ccaa..2d40004 100644 --- a/model/device_plc.go +++ b/model/device_plc.go @@ -12,16 +12,21 @@ // DevicePlc 璁惧鐨凱LC閰嶇疆 DevicePlc struct { - gorm.Model - DeviceID string `gorm:"column:device_id;type:varchar(255);not null;unique_index" json:"deviceID"` //璁惧缂栧彿 + CommonModel + 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鏃� 鐢� - IsOpen bool `json:"isOpen"` - Detail string `gorm:"type:varchar(2048)" json:"-"` + + 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"` @@ -36,6 +41,7 @@ Length int `json:"length"` // 鏁版嵁闀垮害 Type constvar.PlcStartAddressValueType `json:"type"` // 鏁版嵁绫诲瀷 FieldName constvar.PlcStartAddressType `json:"fieldName"` // 瀵瑰簲绯荤粺瀛楁 + Endian constvar.EndianType `json:"endian"` // 瀛楄妭瀛樺偍椤哄簭锛宐ig(ABCD)/little(CDBA)/mix(CDAB) } DevicePlcSearch struct { @@ -52,12 +58,15 @@ } func (slf *DevicePlc) AfterFind(tx *gorm.DB) error { - details := make([]*DevicePlcAddress, 0) - err := json.Unmarshal([]byte(slf.Detail), &details) - if err != nil { - return err + if slf.Detail != "" { + details := make([]*DevicePlcAddress, 0) + err := json.Unmarshal([]byte(slf.Detail), &details) + if err != nil { + return err + } + slf.Details = details } - slf.Details = details + return nil } -- Gitblit v1.8.0