zhangzengfei
2024-03-29 d6831b733a4a97f2271c544c92ce33701634a97b
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
}