From 87f105455c788e8804dc154014f1d7936b080771 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 07 十一月 2023 09:57:39 +0800 Subject: [PATCH] 设备列表返回设备名 --- service/device.go | 19 +++++++++++++++++++ model/response/common.go | 7 ++++++- api/v1/device.go | 4 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/api/v1/device.go b/api/v1/device.go index c107808..6f16b3a 100644 --- a/api/v1/device.go +++ b/api/v1/device.go @@ -67,7 +67,7 @@ if !ok { return } - list, err := service.GetDeviceIDList() + list, err := service.GetDeviceList() if err != nil { ctx.Fail(ecode.DBErr) return @@ -75,7 +75,7 @@ resp := response.DeviceListResponse{ SystemDeviceID: conf.Conf.System.DeviceId, CurrentDeviceID: conf.Conf.CurrentDeviceID, - DeviceIDList: list, + DeviceList: list, SystemDeviceStatus: response.SystemDeviceStatusNormal, ClusterStatus: conf.Conf.SerfClusterStatus, ClusterNodeQuantity: conf.Conf.ClusterNodeQuantity, diff --git a/model/response/common.go b/model/response/common.go index 699292f..aee78c3 100644 --- a/model/response/common.go +++ b/model/response/common.go @@ -79,10 +79,15 @@ SystemDeviceStatusUnNormal SystemDeviceStatus = 2 //寮傚父 ) +type Device struct { + DeviceID string `json:"deviceID,omitempty"` + DeviceName string `json:"deviceName,omitempty"` +} + type DeviceListResponse struct { SystemDeviceID string `json:"systemDeviceID,omitempty"` //宸ユ帶鏈鸿澶嘔D CurrentDeviceID string `json:"currentDeviceID,omitempty"` //褰撳墠閫夊畾鐨勭敓浜ц澶� - DeviceIDList []string `json:"deviceIDList,omitempty"` //鐢熶骇璁惧id鍒楄〃 + DeviceList []*Device `json:"deviceList,omitempty"` //鐢熶骇璁惧id鍒楄〃 SystemDeviceStatus SystemDeviceStatus `json:"systemDeviceStatus"` //璁惧鐘舵�� ClusterStatus string `json:"clusterStatus"` //闆嗙兢鐘舵�� ClusterNodeQuantity int `json:"clusterNodeQuantity"` //闆嗙兢鑺傜偣鏁伴噺 diff --git a/service/device.go b/service/device.go index 8ad1d23..e11b959 100644 --- a/service/device.go +++ b/service/device.go @@ -3,6 +3,7 @@ import ( "apsClient/conf" "apsClient/model" + "apsClient/model/response" "apsClient/pkg/logx" "github.com/jinzhu/gorm" "os" @@ -24,6 +25,24 @@ 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) { currentDeviceID := ReadDeviceIDFromFile() if currentDeviceID != "" { -- Gitblit v1.8.0