zhangqian
2023-11-07 87f105455c788e8804dc154014f1d7936b080771
设备列表返回设备名
3个文件已修改
30 ■■■■■ 已修改文件
api/v1/device.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/common.go 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/device.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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,
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"`  //工控机设备ID
    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"`       //集群节点数量
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 != "" {