| | |
| | | if !ok { |
| | | return |
| | | } |
| | | list, err := service.GetDeviceIDList() |
| | | list, err := service.GetDeviceList() |
| | | if err != nil { |
| | | ctx.Fail(ecode.DBErr) |
| | | return |
| | |
| | | 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, |
| | |
| | | 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"` //集群节点数量 |
| | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/model" |
| | | "apsClient/model/response" |
| | | "apsClient/pkg/logx" |
| | | "github.com/jinzhu/gorm" |
| | | "os" |
| | |
| | | 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 != "" { |