From a6cfc30060b3dc2d3808a9f4b51f77b2c0000798 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期三, 22 五月 2024 03:06:29 +0800 Subject: [PATCH] 修复设备类型缓存类型错误的bug --- models/subplatform.go | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/models/subplatform.go b/models/subplatform.go index 470defe..34e08a4 100644 --- a/models/subplatform.go +++ b/models/subplatform.go @@ -1,8 +1,9 @@ package models +import "time" + type SubPlatform struct { Id string `gorm:"primary_key;" json:"id"` - HeartbeatTime string `gorm:"column:heartbeat_time" json:"heartbeat_time"` Name string `gorm:"not null;default:''" json:"name"` UserName string `gorm:"not null;default:''" json:"user_name"` Realm string `gorm:"not null;default:''" json:"realm"` @@ -10,6 +11,7 @@ Description string `gorm:"not null;default:''" json:"description"` RemoteIP string `gorm:"not null;default:''" json:"remote_ip"` RemotePort int `gorm:"not null;default:0" json:"remote_port"` + HeartbeatTime string `gorm:"column:heartbeat_time" json:"heartbeat_time"` CreateTime int64 `gorm:"column:create_time;autoCreateTime;" json:"create_time"` UpdateTime int64 `gorm:"column:update_time;autoUpdateTime" json:"-"` DeleteTime int64 `gorm:"column:delete_time" json:"-"` @@ -18,3 +20,28 @@ func (s *SubPlatform) TableName() string { return "sub_platforms" } + +func (s *SubPlatform) FindById(id string) error { + return db.Table(s.TableName()).First(&s, "id = ?", id).Error +} + +func (s *SubPlatform) Save() error { + return db.Table(s.TableName()).Save(s).Error +} + +func (s *SubPlatform) DeleteById(id string) error { + return db.Table(s.TableName()).Where("id = ?", id).Delete(s).Error +} + +func (s *SubPlatform) FindAll() ([]SubPlatform, error) { + var list []SubPlatform + if err := db.Table(s.TableName()).Find(&list).Error; err != nil { + return nil, err + } + + return list, nil +} + +func (s *SubPlatform) Keepalive(id string) error { + return db.Table(s.TableName()).Where("id = ?", id).Update("heartbeat_time", time.Now().Format("2006-01-02 15:04:05")).Error +} -- Gitblit v1.8.0