From 2ef7bb54e8cdfea386fb5d09c48700bc2201b71f Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 22 五月 2024 01:22:47 +0800
Subject: [PATCH] 调整数据清理策略
---
models/cache.go | 5 +++++
cron/cron.go | 4 ++--
service/clean.go | 3 +++
models/positions.go | 4 ++--
service/nvcs.go | 24 ++++++++++--------------
5 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/cron/cron.go b/cron/cron.go
index 8aede29..e71e4e4 100644
--- a/cron/cron.go
+++ b/cron/cron.go
@@ -14,9 +14,9 @@
}
func Init() {
- s.Every(config.ForwardConf.RetryInterval).Minutes().StartImmediately().Do(service.ResendImageData)
+ s.Every(config.ForwardConf.RetryInterval).Minute().StartImmediately().Do(service.ResendImageData)
s.Every(config.ForwardConf.ReportInterval).Second().StartImmediately().Do(service.DeviceInfoReportTask)
- s.Every(1).Day().StartImmediately().Do(service.CleanExpireData)
+ s.Every(1).Hour().StartImmediately().Do(service.CleanExpireData)
s.StartAsync()
}
diff --git a/models/cache.go b/models/cache.go
index 45820ef..0a20fdd 100644
--- a/models/cache.go
+++ b/models/cache.go
@@ -32,3 +32,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 2000);"
+ return db.Table(c.TableName()).Exec(sql).Error
+}
diff --git a/models/positions.go b/models/positions.go
index 91198c7..d3a6cb1 100644
--- a/models/positions.go
+++ b/models/positions.go
@@ -4,9 +4,9 @@
type Positions struct {
Id uint `gorm:"column:id;primary_key;auto_increment;unique;not null;"`
- DeviceId string `gorm:"column:device_id;" json:"device_id"`
+ DeviceId string `gorm:"column:device_id;index" json:"device_id"`
Pos string `gorm:"column:pos" json:"pos"`
- CreateTime int64 `gorm:"column:create_time;"`
+ CreateTime int64 `gorm:"column:create_time;index"`
TimeString string `gorm:"column:time_string;"`
}
diff --git a/service/clean.go b/service/clean.go
index 4f4e69c..985a281 100644
--- a/service/clean.go
+++ b/service/clean.go
@@ -5,4 +5,7 @@
func CleanExpireData() {
var pos models.Positions
pos.Clean()
+
+ var cache models.Cache
+ cache.Clean()
}
diff --git a/service/nvcs.go b/service/nvcs.go
index 64464fa..acb1177 100644
--- a/service/nvcs.go
+++ b/service/nvcs.go
@@ -6,7 +6,6 @@
"fmt"
"io/ioutil"
"net"
- "strings"
"time"
"gat1400Exchange/config"
@@ -93,16 +92,16 @@
continue
}
- // 璁剧疆osd 鏍煎紡 "1F鍋� 鍥� 鏋�"
+ // 璁剧疆osd 鏍煎紡 "1F 鍥� 鏋�"
if config.NVCSConf.OSD != "" {
floorText := data.Elevator[0].Status.FloorName
- if data.Elevator[0].Status.RunDir == RunStop {
- floorText = floorText + "鍋�"
- } else if data.Elevator[0].Status.RunDir == RunUp {
- floorText = floorText + "涓�"
- } else {
- floorText = floorText + "涓�"
- }
+ //if data.Elevator[0].Status.RunDir == RunStop {
+ // floorText = floorText + "鍋�"
+ //} else if data.Elevator[0].Status.RunDir == RunUp {
+ // floorText = floorText + "涓�"
+ //} else {
+ // floorText = floorText + "涓�"
+ //}
floorText = floorText + " " + config.NVCSConf.OSD
@@ -117,11 +116,8 @@
elevator := data.Elevator[0]
// 绋嬪簭閮ㄧ讲鍦ㄨ澶囩, 瀛楃鍙犲姞鍣ㄤ笂鎶ョ殑鍚嶇О鍏佽涓虹┖. 鍦ㄤ簯绔�, 鍚嶇О蹇呴』涓庢憚鍍忔満鐩稿悓
- if config.ServeConf.Role != "agent" {
- elevator.Name = strings.Trim(elevator.Name, " ")
- if elevator.Name == "" {
- continue
- }
+ if elevator.Name == "" {
+ elevator.Name = "1"
}
var d = models.Positions{
--
Gitblit v1.8.0