From d6831b733a4a97f2271c544c92ce33701634a97b Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期五, 29 三月 2024 13:55:17 +0800 Subject: [PATCH] 修复楼层匹配 --- models/device.go | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/models/device.go b/models/device.go index 473ff0f..854ae65 100644 --- a/models/device.go +++ b/models/device.go @@ -1,6 +1,9 @@ package models -import "gorm.io/gorm" +import ( + "gorm.io/gorm" + "time" +) type Device struct { Id string `gorm:"column:id;primary_key;" json:"id"` @@ -37,6 +40,7 @@ if err == gorm.ErrRecordNotFound { // 璁板綍涓嶅瓨鍦紝鍒涘缓鏂拌褰� db.Create(&d) + } else { // 鍏朵粬閿欒锛屼綘鍙互杩涜閫傚綋鐨勫鐞� return err @@ -53,5 +57,15 @@ db.Save(&existingDevice) } + // 璁板綍浣嶇疆鐨勫巻鍙�, 缁欎汉鑴告姄鎷嶅尮閰嶆ゼ灞� + if existingDevice.Pos != "" { + var pos = Positions{ + DeviceId: d.Id, + Pos: d.Pos, + CreateTime: time.Now().Unix(), + } + + db.Create(&pos) + } return nil } -- Gitblit v1.8.0