From 8324f872ef3a4d0c978a9b1d062800c6a1701c12 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 01 十二月 2023 09:58:17 +0800
Subject: [PATCH] fix

---
 service/device.go |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/service/device.go b/service/device.go
index e0ff8ab..1906d99 100644
--- a/service/device.go
+++ b/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
@@ -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)
+	}
+}

--
Gitblit v1.8.0