From cacf363f222e354cad6db18c4a00fb1097d35c2c Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 09 十一月 2023 14:30:58 +0800 Subject: [PATCH] fix --- service/device_plc.go | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/service/device_plc.go b/service/device_plc.go index fc5fadc..d76e781 100644 --- a/service/device_plc.go +++ b/service/device_plc.go @@ -19,21 +19,26 @@ } func (slf DevicePlcService) GetDevicePlc() (*model.DevicePlc, int) { - DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.System.DeviceId).First() + DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.CurrentDeviceID).First() if err == gorm.ErrRecordNotFound { + logx.Errorf("GetDevicePlc failed:%v", err) return &model.DevicePlc{ + DeviceID: "", Brand: "", Method: "", Address: "", Port: 0, BaudRate: 0, SerialName: "", + DataBit: 0, + StopBit: 0, + Parity: 0, IsOpen: false, - Detail: "", Details: make([]*model.DevicePlcAddress, 0), }, ecode.OK } if err != nil { + logx.Errorf("GetDevicePlc failed:%v", err) return nil, ecode.DBErr } @@ -43,9 +48,11 @@ func (slf DevicePlcService) GetDeviceChannelAmount() (int, error) { plcConfig, code := slf.GetDevicePlc() if code != ecode.OK || plcConfig.ID == 0 { + logx.Errorf("GetDeviceChannelAmount failed:%v, code:%v", plcConfig, code) return 0, errors.New("鏈幏鍙栧埌PLC鍦板潃锛岃鍦ㄥ伐鑹烘ā鍨嬪簱涓笂浼狅紒") } if len(plcConfig.Details) == 0 { + logx.Errorf("GetDeviceChannelAmount failed, addressList == 0, %+v", plcConfig) return 0, errors.New("鏈幏鍙栧埌PLC鍦板潃锛岃鍦ㄥ伐鑹烘ā鍨嬪簱涓笂浼狅紒") } return len(plcConfig.Details) / 2, nil @@ -64,11 +71,10 @@ return ecode.ParamsErr } record.Detail = string(detail) - - if plc.Id == 0 { + if record.ID == 0 { err = model.NewDevicePlcSearch().Create(&record) } else { - err = model.NewDevicePlcSearch().SetId(plc.Id).Save(&record) + err = model.NewDevicePlcSearch().Save(&record) } if err != nil { -- Gitblit v1.8.0