|
@@ -2,8 +2,6 @@ package services
|
|
|
|
|
|
import (
|
|
|
"sparrow/pkg/models"
|
|
|
- "sparrow/pkg/rpcs"
|
|
|
- "sparrow/pkg/server"
|
|
|
"sparrow/services/knowoapi/model"
|
|
|
)
|
|
|
|
|
@@ -20,7 +18,7 @@ type DeviceService interface {
|
|
|
//获取近N日活跃设备数据
|
|
|
GetLivelyOfNumDays(uint, int) ([]map[string]interface{}, error)
|
|
|
//获取已经激活的设备列表
|
|
|
- GetDevices(vendorid uint, proid, pi, ps int, deviceid string) ([]*models.Devices, int, error)
|
|
|
+ GetDevices(vendorid uint, proid, pi, ps int, deviceid string) ([]models.Device, int, error)
|
|
|
}
|
|
|
|
|
|
type deviceservice struct {
|
|
@@ -33,36 +31,11 @@ func NewDeviceService(models *model.All) DeviceService {
|
|
|
models: models,
|
|
|
}
|
|
|
}
|
|
|
-func (a deviceservice) GetDevices(vendorid uint, proid, pi, ps int, deviceid string) ([]*models.Devices, int, error) {
|
|
|
+func (a deviceservice) GetDevices(vendorid uint, proid, pi, ps int, deviceid string) ([]models.Device, int, error) {
|
|
|
|
|
|
- datas, total, err := a.models.Device.GetDevices(vendorid, proid, pi, ps, deviceid)
|
|
|
-
|
|
|
- devicedatas := make([]*models.Devices, 0)
|
|
|
-
|
|
|
- for _, device := range datas {
|
|
|
- onlineargs := rpcs.ArgsGetDeviceOnlineStatus{
|
|
|
- Id: uint64(device.ID),
|
|
|
- }
|
|
|
-
|
|
|
- onlinereply := rpcs.ReplyGetDeviceOnlineStatus{}
|
|
|
- err = server.RPCCallByName(nil, "devicemanager", "DeviceManager.GetDeviceOnlineStatus", onlineargs, &onlinereply)
|
|
|
- if err != nil {
|
|
|
- server.Log.Errorf("get devie online status error: %v", err)
|
|
|
- }
|
|
|
-
|
|
|
- devices := new(models.Devices)
|
|
|
-
|
|
|
- devices.Device = device
|
|
|
-
|
|
|
- if int(onlinereply.HeartbeatInterval) > 0 {
|
|
|
-
|
|
|
- devices.Status = 1
|
|
|
- }
|
|
|
- devicedatas = append(devicedatas, devices)
|
|
|
- }
|
|
|
-
|
|
|
- return devicedatas, total, err
|
|
|
+ return a.models.Device.GetDevices(vendorid, proid, pi, ps, deviceid)
|
|
|
}
|
|
|
+
|
|
|
func (a deviceservice) GetDeviceCount(vendorid uint) (int, error) {
|
|
|
return a.models.Device.GetDeviceCount(vendorid)
|
|
|
}
|