Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
80 lines
3.7 KiB
Go
80 lines
3.7 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// ReportingEvent represents a raw event for real-time analytics.
|
|
// Reference: Chatwoot ReportingEvent model — captures first_response, resolution_time,
|
|
// reply_time, avg_first_response_time, avg_resolution_time, resolutions_count,
|
|
// bot_resolutions_count, bot_handoffs_count.
|
|
type ReportingEvent struct {
|
|
Base
|
|
AccountID uint `gorm:"index;not null" json:"account_id"`
|
|
Name string `gorm:"size:100;index;not null" json:"name"` // metric name: first_response, resolution_time, etc.
|
|
Value float64 `json:"value"`
|
|
ValueInBusinessHours float64 `json:"value_in_business_hours"`
|
|
ConversationID *uint `gorm:"index" json:"conversation_id,omitempty"`
|
|
InboxID *uint `gorm:"index" json:"inbox_id,omitempty"`
|
|
UserID *uint `gorm:"index" json:"user_id,omitempty"`
|
|
EventStartTime time.Time `gorm:"index" json:"event_start_time"`
|
|
EventEndTime time.Time `gorm:"index" json:"event_end_time"`
|
|
|
|
Account *Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
|
|
Inbox *Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"`
|
|
Conversation *Conversation `gorm:"foreignKey:ConversationID" json:"conversation,omitempty"`
|
|
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
|
}
|
|
|
|
func (ReportingEvent) TableName() string { return "reporting_events" }
|
|
|
|
// DimensionType represents the dimension category for rollup aggregation.
|
|
type DimensionType string
|
|
|
|
const (
|
|
DimensionAccount DimensionType = "account"
|
|
DimensionAgent DimensionType = "agent"
|
|
DimensionInbox DimensionType = "inbox"
|
|
DimensionTeam DimensionType = "team"
|
|
DimensionLabel DimensionType = "label"
|
|
DimensionConversation DimensionType = "conversation"
|
|
)
|
|
|
|
// MetricName constants are used as string identifiers for reporting event queries.
|
|
const (
|
|
MetricNameFirstResponse = "first_response"
|
|
MetricNameReplyTime = "reply_time"
|
|
MetricNameResolutionTime = "resolution_time"
|
|
MetricNameBotResolutionsCount = "bot_resolutions_count"
|
|
MetricNameBotHandoffsCount = "bot_handoffs_count"
|
|
MetricBotResolutions = "bot_resolutions"
|
|
MetricBotHandoffs = "bot_handoffs"
|
|
)
|
|
|
|
// RollupMetric represents the metric names used in rollup records.
|
|
type RollupMetric string
|
|
|
|
const (
|
|
MetricResolutionsCount RollupMetric = "resolutions_count"
|
|
MetricFirstResponse RollupMetric = "first_response"
|
|
MetricResolutionTime RollupMetric = "resolution_time"
|
|
MetricReplyTime RollupMetric = "reply_time"
|
|
MetricBotResolutionsCount RollupMetric = "bot_resolutions_count"
|
|
MetricBotHandoffsCount RollupMetric = "bot_handoffs_count"
|
|
)
|
|
|
|
// ReportingEventsRollup stores pre-aggregated reporting data per day/dimension/metric.
|
|
// Reference: Chatwoot ReportingEventsRollup — unique index on (account_id, date, dimension_type, dimension_id, metric).
|
|
type ReportingEventsRollup struct {
|
|
Base
|
|
AccountID uint `gorm:"uniqueIndex:idx_rollup_unique;not null" json:"account_id"`
|
|
Date time.Time `gorm:"uniqueIndex:idx_rollup_unique;type:date;not null" json:"date"`
|
|
DimensionType DimensionType `gorm:"uniqueIndex:idx_rollup_unique;size:20;not null" json:"dimension_type"`
|
|
DimensionID uint `gorm:"uniqueIndex:idx_rollup_unique;not null" json:"dimension_id"`
|
|
Metric RollupMetric `gorm:"uniqueIndex:idx_rollup_unique;size:50;not null" json:"metric"`
|
|
Count int64 `json:"count"`
|
|
SumValue float64 `json:"sum_value"`
|
|
SumValueBusinessHours float64 `json:"sum_value_business_hours"`
|
|
}
|
|
|
|
func (ReportingEventsRollup) TableName() string { return "reporting_events_rollups" } |