|
@@ -1,6 +1,7 @@
|
|
package services
|
|
package services
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "github.com/gogf/gf/util/guid"
|
|
"sparrow/pkg/models"
|
|
"sparrow/pkg/models"
|
|
"sparrow/pkg/rpcs"
|
|
"sparrow/pkg/rpcs"
|
|
"sparrow/pkg/server"
|
|
"sparrow/pkg/server"
|
|
@@ -20,9 +21,13 @@ type DeviceService interface {
|
|
//获取近N日活跃设备数据
|
|
//获取近N日活跃设备数据
|
|
GetLivelyOfNumDays(string, int) ([]map[string]interface{}, error)
|
|
GetLivelyOfNumDays(string, int) ([]map[string]interface{}, error)
|
|
//获取已经激活的设备列表
|
|
//获取已经激活的设备列表
|
|
- GetDevices(vendorid string, proid, pi, ps int, deviceid string) ([]*models.Devices, int, error)
|
|
|
|
|
|
+ GetDevices(vendorid, proid string, pi, ps int, deviceid string) ([]*models.Devices, int, error)
|
|
//获取用户下所有设备的数量,在线设备的数量,离线设备的数量
|
|
//获取用户下所有设备的数量,在线设备的数量,离线设备的数量
|
|
GetDevicesCountByVenderId(vendorid string) (map[string]interface{}, error)
|
|
GetDevicesCountByVenderId(vendorid string) (map[string]interface{}, error)
|
|
|
|
+ // 发起设备OTA升级
|
|
|
|
+ Upgrade(params *models.UpgradeParams) error
|
|
|
|
+ // GetUpgradeProgress 获取ota升级进度
|
|
|
|
+ GetUpgradeProgress(deviceId string) (rpcs.ReplyOtaProgress, error)
|
|
}
|
|
}
|
|
|
|
|
|
type deviceservice struct {
|
|
type deviceservice struct {
|
|
@@ -35,7 +40,7 @@ func NewDeviceService(models *model.All) DeviceService {
|
|
models: models,
|
|
models: models,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-func (a deviceservice) GetDevices(vendorid string, proid, pi, ps int, deviceid string) ([]*models.Devices, int, error) {
|
|
|
|
|
|
+func (a deviceservice) GetDevices(vendorid, proid string, pi, ps int, deviceid string) ([]*models.Devices, int, error) {
|
|
|
|
|
|
data, total, err := a.models.Device.GetDevices(vendorid, proid, pi, ps, deviceid)
|
|
data, total, err := a.models.Device.GetDevices(vendorid, proid, pi, ps, deviceid)
|
|
|
|
|
|
@@ -123,3 +128,45 @@ func (a deviceservice) GetDevicesCountByVenderId(vendorid string) (map[string]in
|
|
|
|
|
|
return deviceCount, nil
|
|
return deviceCount, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (a deviceservice) Upgrade(param *models.UpgradeParams) error {
|
|
|
|
+
|
|
|
|
+ var fileArgs rpcs.ArgsOtaFile
|
|
|
|
+ fileArgs.FileData = param.File
|
|
|
|
+ fileArgs.FileId = guid.S()
|
|
|
|
+ var reply rpcs.ReplyEmptyResult
|
|
|
|
+
|
|
|
|
+ err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.SavaFile", fileArgs, &reply)
|
|
|
|
+ if err != nil {
|
|
|
|
+ server.Log.Errorf("OTA升级文件保存失败:%v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var args rpcs.ArgsUpgrade4G
|
|
|
|
+ args.DeviceId = param.DeviceID
|
|
|
|
+ args.FileId = fileArgs.FileId
|
|
|
|
+ args.FileSize = param.FileSize
|
|
|
|
+
|
|
|
|
+ err = server.RPCCallByName(nil, rpcs.MQTTAccessName, "Access.UpgradeFor4G", args, &reply)
|
|
|
|
+ if err != nil {
|
|
|
|
+ server.Log.Errorf("4G模组OTA升级失败:%v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (a deviceservice) GetUpgradeProgress(deviceId string) (rpcs.ReplyOtaProgress, error) {
|
|
|
|
+ var args rpcs.ArgsOtaProgress
|
|
|
|
+ args.DeviceId = deviceId
|
|
|
|
+
|
|
|
|
+ var reply rpcs.ReplyOtaProgress
|
|
|
|
+
|
|
|
|
+ err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetProgress", args, &reply)
|
|
|
|
+ if err != nil {
|
|
|
|
+ server.Log.Errorf("OTA升级进度获取失败:%v", err)
|
|
|
|
+ return reply, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return reply, nil
|
|
|
|
+}
|