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 | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/model/device_plc.go b/model/device_plc.go index c68b1f3..2d40004 100644 --- a/model/device_plc.go +++ b/model/device_plc.go @@ -12,7 +12,7 @@ // DevicePlc 璁惧鐨凱LC閰嶇疆 DevicePlc struct { - gorm.Model + 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"` @@ -41,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 { @@ -57,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 } @@ -127,7 +131,7 @@ func (slf *DevicePlcSearch) Save(record *DevicePlc) error { var db = slf.build() - if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { + if err := db.Omit("CreatedAt").Save(record).Error; err != nil { return fmt.Errorf("save err: %v, record: %+v", err, record) } -- Gitblit v1.8.0