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 |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/service/device_plc.go b/service/device_plc.go
index 8b4e722..d76e781 100644
--- a/service/device_plc.go
+++ b/service/device_plc.go
@@ -19,8 +19,9 @@
 }
 
 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:      "",
@@ -37,6 +38,7 @@
 		}, ecode.OK
 	}
 	if err != nil {
+		logx.Errorf("GetDevicePlc failed:%v", err)
 		return nil, ecode.DBErr
 	}
 
@@ -46,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
@@ -70,7 +74,7 @@
 	if record.ID == 0 {
 		err = model.NewDevicePlcSearch().Create(&record)
 	} else {
-		err = model.NewDevicePlcSearch().SetId(record.ID).Save(&record)
+		err = model.NewDevicePlcSearch().Save(&record)
 	}
 
 	if err != nil {

--
Gitblit v1.8.0