fix
zhangqian
2023-12-01 8324f872ef3a4d0c978a9b1d062800c6a1701c12
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 {
   if len(deviceList) > 0 {
      conf.Conf.CurrentDeviceID = deviceList[0]
   } else if conf.Conf.System.DeviceId != "" {
      conf.Conf.CurrentDeviceID = conf.Conf.System.DeviceId
   } else {
      conf.Conf.CurrentDeviceID = deviceList[0]
      conf.Conf.CurrentDeviceID = ServerID
   }
   SetDeviceIDToFile(conf.Conf.CurrentDeviceID)
   return nil
@@ -93,5 +96,27 @@
      return errors.New("设备不存在")
   }
   device.NeedSetProcessParams = needSetProcessParams
   return model.NewDeviceSearch().SetID(device.ID).Save(device)
   return model.NewDeviceSearch().SetID(device.ID).UpdateByMap(map[string]interface{}{"need_set_process_params": needSetProcessParams})
}
func GetCurrentDevice() (device *model.Device, err error) {
   if conf.Conf.CurrentDeviceID == "" {
      return nil, errors.New("当前设备ID不存在,请检查")
   }
   device, err = model.NewDeviceSearch().SetDeviceId(conf.Conf.CurrentDeviceID).First()
   if err == gorm.ErrRecordNotFound {
      return nil, errors.New("设备不存在")
   }
   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)
   }
}