From 4691c6c2efe7fccc74c75eb01b91009791960259 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期五, 17 五月 2024 22:59:32 +0800 Subject: [PATCH] 修复图片下载的bug --- models/device.go | 23 +++++++++++++++++++---- 1 files changed, 19 insertions(+), 4 deletions(-) diff --git a/models/device.go b/models/device.go index 473ff0f..1fe4e4c 100644 --- a/models/device.go +++ b/models/device.go @@ -1,12 +1,15 @@ package models -import "gorm.io/gorm" +import ( + "gorm.io/gorm" + "time" +) type Device struct { Id string `gorm:"column:id;primary_key;" json:"id"` Name string `gorm:"column:name" json:"name"` Addr string `gorm:"column:addr" json:"addr"` - Pos string `gorm:"column:pos" json:"pos"` + Floor string `gorm:"column:pos" json:"pos"` Ext string `gorm:"column:ext" json:"ext"` Ip string `gorm:"column:ip" json:"ip"` CreateTime int64 `gorm:"column:create_time;autoCreateTime;" json:"-"` @@ -37,21 +40,33 @@ if err == gorm.ErrRecordNotFound { // 璁板綍涓嶅瓨鍦紝鍒涘缓鏂拌褰� db.Create(&d) + } else { // 鍏朵粬閿欒锛屼綘鍙互杩涜閫傚綋鐨勫鐞� return err } } else { // 璁板綍瀛樺湪锛屾洿鏂扮幇鏈夎褰� - if d.Pos == "" || d.Ip == "" { + if d.Floor == "" || d.Ip == "" { return nil } - existingDevice.Pos = d.Pos + existingDevice.Floor = d.Floor existingDevice.Ip = d.Ip db.Save(&existingDevice) } + // 璁板綍浣嶇疆鐨勫巻鍙�, 缁欎汉鑴告姄鎷嶅尮閰嶆ゼ灞� + if existingDevice.Floor != "" { + var pos = Positions{ + DeviceId: d.Id, + Pos: d.Floor, + CreateTime: time.Now().Unix(), + TimeString: time.Now().Format("2006-01-02 15:04:05"), + } + + db.Create(&pos) + } return nil } -- Gitblit v1.8.0