From 3e9a1a28b1283e40bc7edb94e2370c74e7fd68e0 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期五, 17 五月 2024 15:54:29 +0800
Subject: [PATCH] 添加订阅查询接口

---
 models/device.go |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/models/device.go b/models/device.go
index 5ef3ef3..1fe4e4c 100644
--- a/models/device.go
+++ b/models/device.go
@@ -1,17 +1,20 @@
 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:"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,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