| | |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/constvar" |
| | | "apsClient/model" |
| | | "apsClient/model/response" |
| | | "apsClient/pkg/logx" |
| | |
| | | return deviceList, nil |
| | | } |
| | | |
| | | func InitCurrentDeviceID() (err error) { |
| | | func InitCurrentDeviceID(ServerID string) (err error) { |
| | | currentDeviceID := ReadDeviceIDFromFile() |
| | | if currentDeviceID != "" { |
| | | conf.Conf.CurrentDeviceID = currentDeviceID |
| | |
| | | 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 |
| | |
| | | } |
| | | 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) |
| | | } |
| | | } |