From 8aa296b660354adf440a005dcbc3883515ed71e2 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期一, 15 四月 2024 11:45:48 +0800
Subject: [PATCH] 修改新的上报协议
---
models/device.go | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/models/device.go b/models/device.go
index 5ef3ef3..89d2fb1 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"`
@@ -9,9 +12,9 @@
Pos 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:"create_time"`
- UpdateTime int64 `gorm:"column:update_time;autoUpdateTime" json:"update_time"`
- DeleteTime int64 `gorm:"column:delete_time" json:"delete_time"`
+ CreateTime int64 `gorm:"column:create_time;autoCreateTime;" json:"-"`
+ UpdateTime int64 `gorm:"column:update_time;autoUpdateTime" json:"-"`
+ DeleteTime int64 `gorm:"column:delete_time" json:"-"`
}
func (d *Device) TableName() string {
@@ -37,6 +40,7 @@
if err == gorm.ErrRecordNotFound {
// 璁板綍涓嶅瓨鍦紝鍒涘缓鏂拌褰�
db.Create(&d)
+
} else {
// 鍏朵粬閿欒锛屼綘鍙互杩涜閫傚綋鐨勫鐞�
return err
@@ -53,5 +57,16 @@
db.Save(&existingDevice)
}
+ // 璁板綍浣嶇疆鐨勫巻鍙�, 缁欎汉鑴告姄鎷嶅尮閰嶆ゼ灞�
+ if existingDevice.Pos != "" {
+ var pos = Positions{
+ DeviceId: d.Id,
+ Pos: d.Pos,
+ CreateTime: time.Now().Unix(),
+ TimeString: time.Now().Format("2006-01-02 15:04:05"),
+ }
+
+ db.Create(&pos)
+ }
return nil
}
--
Gitblit v1.8.0