From 332fc6ad5edca596ecd23876aa9db7452b45f804 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 29 五月 2024 02:58:21 +0800
Subject: [PATCH] 添加人员抓拍处理

---
 models/cache.go |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/models/cache.go b/models/cache.go
index 54becc2..5c0dd44 100644
--- a/models/cache.go
+++ b/models/cache.go
@@ -2,6 +2,7 @@
 
 type Cache struct {
 	Id         uint   `gorm:"column:id;primary_key;auto_increment;unique;not null;"`
+	Type       string `gorm:"column:type;"` // 娑堟伅绫诲瀷 1400, basic
 	Data       string `gorm:"column:data;type:text"`
 	CreateTime int64  `gorm:"column:create_time;"`
 	Retry      int    `gorm:"column:retry;"`
@@ -11,6 +12,10 @@
 	return "caches"
 }
 
+func (c *Cache) First() error {
+	return db.Table(c.TableName()).First(c).Error
+}
+
 func (c *Cache) FindAll() ([]Cache, error) {
 	var caches []Cache
 	if err := db.Table(c.TableName()).Find(&caches).Error; err != nil {
@@ -18,6 +23,15 @@
 	}
 
 	return caches, nil
+}
+
+func (c *Cache) Count() (int64, error) {
+	var total int64
+	if err := db.Table(c.TableName()).Count(&total).Error; err != nil {
+		return total, err
+	}
+
+	return total, nil
 }
 
 func (c *Cache) Save() error {
@@ -31,3 +45,8 @@
 func (c *Cache) Delete() error {
 	return db.Table(c.TableName()).Where("id = ?", c.Id).Delete(c).Error
 }
+
+func (c *Cache) Clean() error {
+	sql := "DELETE FROM caches WHERE id NOT IN (SELECT id FROM caches ORDER BY id DESC LIMIT 15000);"
+	return db.Table(c.TableName()).Exec(sql).Error
+}

--
Gitblit v1.8.0