From c84a97df024e2a1fbbb6d50a7bcb4b2e2a0838b8 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 07 十一月 2023 17:07:36 +0800 Subject: [PATCH] plc结果支持int32解析 --- service/device.go | 33 ++++++++++++++++++++++++++++++--- 1 files changed, 30 insertions(+), 3 deletions(-) diff --git a/service/device.go b/service/device.go index 06b2e47..e11b959 100644 --- a/service/device.go +++ b/service/device.go @@ -3,12 +3,18 @@ import ( "apsClient/conf" "apsClient/model" + "apsClient/model/response" "apsClient/pkg/logx" + "github.com/jinzhu/gorm" "os" + "strings" ) func GetDeviceIDList() (deviceIds []string, err error) { devices, err := model.NewDeviceSearch().SetDeviceMac(conf.Conf.System.DeviceId).FindNotTotal() + if err == gorm.ErrRecordNotFound { + return nil, nil + } if err != nil { return nil, err } @@ -17,6 +23,24 @@ deviceIds = append(deviceIds, device.DeviceID) } return deviceIds, nil +} + +func GetDeviceList() (deviceList []*response.Device, err error) { + devices, err := model.NewDeviceSearch().SetDeviceMac(conf.Conf.System.DeviceId).FindNotTotal() + if err == gorm.ErrRecordNotFound { + return nil, nil + } + if err != nil { + return nil, err + } + deviceList = make([]*response.Device, 0, len(devices)) + for _, device := range devices { + deviceList = append(deviceList, &response.Device{ + DeviceID: device.DeviceID, + DeviceName: device.DeviceName, + }) + } + return deviceList, nil } func InitCurrentDeviceID() (err error) { @@ -31,9 +55,9 @@ } if len(deviceList) == 0 { conf.Conf.CurrentDeviceID = conf.Conf.System.DeviceId - return nil + } else { + conf.Conf.CurrentDeviceID = deviceList[0] } - conf.Conf.CurrentDeviceID = deviceList[0] SetDeviceIDToFile(conf.Conf.CurrentDeviceID) return nil } @@ -55,5 +79,8 @@ logx.Errorf("鏃犳硶璇诲彇璁惧ID鏂囦欢: %v\n", err) return "" } - return string(data) + deviceId := string(data) + deviceId = strings.TrimSpace(deviceId) + deviceId = strings.Trim(deviceId, "\n") + return deviceId } -- Gitblit v1.8.0