Jelajahi Sumber

Fix 修复整点获取设备数据为空的问题

YueYunyun 2 tahun lalu
induk
melakukan
913e20952c

+ 2 - 2
SERVER/IotAdmin/common/middleware/permission.go

@@ -27,10 +27,10 @@ func AuthCheckRole() gin.HandlerFunc {
 		e := sdk.Runtime.GetCasbinKey(c.Request.Host)
 		res := permission.CheckRoleApi(c, v, e)
 		if res {
-			log.Infof("isTrue: %v role: %s method: %s path: %s", res, v["rolekey"], c.Request.Method, c.Request.URL.Path)
+			log.Debugf("isTrue: %v role: %s method: %s path: %s", res, v["rolekey"], c.Request.Method, c.Request.URL.Path)
 			c.Next()
 		} else {
-			log.Warnf("isTrue: %v role: %s method: %s path: %s message: %s", res, v["rolekey"], c.Request.Method, c.Request.URL.Path, "当前request无权限,请管理员确认!")
+			log.Warnf("isTrue: %v role: %s method: %s path: %s message: %s", res, v["rolekey"], c.Request.Method, c.Request.URL.Path, "当前接口无权限,请管理员确认!")
 			c.JSON(http.StatusOK, gin.H{
 				"code": 403,
 				"msg":  "对不起,您没有该接口访问权限,请联系管理员",

+ 0 - 1
SERVER/IotAdmin/iot/db/meter_device.go

@@ -46,7 +46,6 @@ func loadDtuDeviceMap(db *gorm.DB, arr *[]models.IotDevice) error {
 }
 
 func addDtuDevice(db *gorm.DB, device models.IotDevice) error {
-
 	if device.Type != constant.IotDeviceTypeGateway {
 		return errors.New("type is not gateway")
 	}

+ 4 - 1
SERVER/IotAdmin/iot/log/data.go

@@ -92,10 +92,13 @@ func GetLastData(sn string) (*iotStruct.LogData, error) {
 	}
 	str := string(bytes)
 	arr := strings.Split(str, "\r\n")
-	if len(arr) <= 1 {
+	if len(arr) < 1 {
 		return nil, fmt.Errorf("数据为空")
 	}
 	dataStr := arr[len(arr)-1]
+	if dataStr == "" {
+		return nil, fmt.Errorf("未采集到数据或数据解析失败")
+	}
 	data := &iotStruct.LogData{}
 	if err = json.Unmarshal([]byte(dataStr), data); err != nil {
 		return nil, err