zhangqian
2023-11-13 6267ca2039e6538e4f687071e71e2ad2dda11d09
service/device.go
@@ -2,6 +2,7 @@
import (
   "apsClient/conf"
   "apsClient/constvar"
   "apsClient/model"
   "apsClient/model/response"
   "apsClient/pkg/logx"
@@ -45,7 +46,7 @@
   return deviceList, nil
}
func InitCurrentDeviceID() (err error) {
func InitCurrentDeviceID(ServerID string) (err error) {
   currentDeviceID := ReadDeviceIDFromFile()
   if currentDeviceID != "" {
      conf.Conf.CurrentDeviceID = currentDeviceID
@@ -55,10 +56,12 @@
   if err != nil {
      return err
   }
   if len(deviceList) == 0 {
      conf.Conf.CurrentDeviceID = conf.Conf.System.DeviceId
   } else {
   if len(deviceList) >= 0 {
      conf.Conf.CurrentDeviceID = deviceList[0]
   } else if ServerID != "" {
      conf.Conf.CurrentDeviceID = ServerID
   } else {
      conf.Conf.CurrentDeviceID = conf.Conf.System.DeviceId
   }
   SetDeviceIDToFile(conf.Conf.CurrentDeviceID)
   return nil
@@ -106,3 +109,14 @@
   }
   return device, nil
}
// ReportsSystemDeviceToCloud 创建同步设备id记录
func ReportsSystemDeviceToCloud(systemDeviceID string) {
   err := model.NewReportsToCloudSearch(nil).Create(&model.ReportsToCloud{
      ReportType: constvar.ReportTypeSystemDeviceID,
      Content:    systemDeviceID,
   })
   if err != nil {
      logx.Errorf("ReportsSystemDeviceToCloud create record error:%v", err)
   }
}