event

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Code generated by godddx, DO AVOID EDIT.

Package event 事件领域,负责管理 AI 检测事件的存储和查询。

事件由 AI 分析服务产生,每个检测到的目标对象(如 person、car)生成一条独立的事件记录。 事件关联到具体的设备 (DID) 和通道 (CID),并记录检测时间、置信度、边界框等信息。

主要功能:

  • 事件的增删改查
  • 按通道和时间范围查询事件
  • 事件图片的存储路径管理

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddEventInput

type AddEventInput struct {
	DID       string   `json:"-"`          // 设备 ID (API 层填充)
	CID       string   `json:"-"`          // 通道 ID (API 层填充)
	StartedAt orm.Time `json:"started_at"` // 事件开始时间 (毫秒时间戳)
	EndedAt   orm.Time `json:"ended_at"`   // 事件结束时间 (毫秒时间戳)
	Label     string   `json:"label"`      // 检测标签
	Score     float32  `json:"score"`      // 置信度
	Zones     string   `json:"zones"`      // 检测区域 JSON
	ImagePath string   `json:"image_path"` // 图片相对路径
	Model     string   `json:"model"`      // 分析模型名称
}

type Core

type Core struct {
	// contains filtered or unexported fields
}

Core business domain

func NewCore

func NewCore(store Storer) Core

NewCore create business domain

func (Core) AddEvent

func (c Core) AddEvent(ctx context.Context, in *AddEventInput) (*Event, error)

AddEvent 新增事件记录

func (Core) DelEvent

func (c Core) DelEvent(ctx context.Context, id int64) (*Event, error)

DelEvent 删除事件

func (Core) EditEvent

func (c Core) EditEvent(ctx context.Context, in *EditEventInput, id int64) (*Event, error)

EditEvent 更新事件信息

func (Core) FindEvents

func (c Core) FindEvents(ctx context.Context, in *FindEventInput) ([]*Event, int64, error)

FindEvents 分页查询事件列表,支持按 CID 和时间范围筛选

func (Core) GetEvent

func (c Core) GetEvent(ctx context.Context, id int64) (*Event, error)

GetEvent 根据 ID 查询单个事件

func (Core) StartCleanupWorker

func (c Core) StartCleanupWorker(days int)

StartCleanupWorker 启动定时清理协程,每天凌晨 3 点执行一次清理 days 参数指定保留的天数,超过该天数的事件将被删除

type EditEventInput

type EditEventInput struct {
	EndedAt orm.Time `json:"ended_at"` // 事件结束时间 (毫秒时间戳)
}

type Event

type Event struct {
	ID        int64    `gorm:"primaryKey" json:"id"`                                                                 // 事件 ID
	DID       string   `gorm:"column:did;notNull;default:'';comment:设备 ID (device 表的 id)" json:"did"`                // 设备 ID (device 表的 id)
	CID       string   `gorm:"column:cid;notNull;default:'';comment:通道 ID (channel 表的 id)" json:"cid"`               // 通道 ID (channel 表的 id)
	StartedAt orm.Time `gorm:"column:started_at;notNull;default:CURRENT_TIMESTAMP;comment:事件开始时间" json:"started_at"` // 事件开始时间
	EndedAt   orm.Time `gorm:"column:ended_at;notNull;default:CURRENT_TIMESTAMP;comment:事件结束时间" json:"ended_at"`     // 事件结束时间
	Label     string   `gorm:"column:label;notNull;default:'';comment:检测标签 (person, car 等)" json:"label"`            // 检测标签 (person, car 等)
	Score     float32  `gorm:"column:score;notNull;default:0;comment:置信度 (0.0-1.0)" json:"score"`                    // 置信度 (0.0-1.0)
	Zones     string   `gorm:"column:zones;notNull;default:'';comment:检测区域,JSON 格式存储边界框信息" json:"zones"`             // 检测区域,JSON 格式存储边界框信息
	ImagePath string   ``                                                                                            // 图片相对路径 (cid/年月日时分秒_随机6位.jpg)
	/* 128-byte string literal not displayed */
	Model     string   `gorm:"column:model;notNull;default:'';comment:分析模型名称" json:"model"`                        // 分析模型名称
	CreatedAt orm.Time `gorm:"column:created_at;notNull;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
	UpdatedAt orm.Time `gorm:"column:updated_at;notNull;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
}

Event domain model

func (*Event) CacheKey

func (e *Event) CacheKey() string

CacheKey 缓存主键,必须唯一 godddx 生成缓存代码时,依赖的主键 默认应该是 ID 字段,但也可以自定义

func (*Event) TableName

func (*Event) TableName() string

TableName database table name

type EventStorer

type EventStorer interface {
	Find(context.Context, *[]*Event, orm.Pager, ...orm.QueryOption) (int64, error)
	Get(context.Context, *Event, ...orm.QueryOption) error
	Add(context.Context, *Event) error
	Edit(context.Context, *Event, func(*Event), ...orm.QueryOption) error
	Del(context.Context, *Event, ...orm.QueryOption) error
	Count(context.Context, ...orm.QueryOption) (int64, error)

	Session(context.Context, ...func(*gorm.DB) error) error
	EditWithSession(*gorm.DB, *Event, func(b *Event) error, ...orm.QueryOption) error
}

EventStorer Instantiation interface

type FindEventInput

type FindEventInput struct {
	web.PagerFilter
	web.DateFilter
	DID   string `form:"did"`   // 设备 ID
	CID   string `form:"cid"`   // 通道 ID
	Label string `form:"label"` // 检测标签
}

type Storer

type Storer interface {
	Event() EventStorer
}

Storer data persistence

Directories

Path Synopsis
store
eventcache
Code generated by godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.
eventdb
Code generated by godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL