zhangzengfei
2024-05-22 2ef7bb54e8cdfea386fb5d09c48700bc2201b71f
调整数据清理策略
5个文件已修改
40 ■■■■■ 已修改文件
cron/cron.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/cache.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/positions.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/clean.go 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/nvcs.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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()
}
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
}
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;"`
}
service/clean.go
@@ -5,4 +5,7 @@
func CleanExpireData() {
    var pos models.Positions
    pos.Clean()
    var cache models.Cache
    cache.Clean()
}
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{