dailyStats

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentMonthSum

func GetCurrentMonthSum(key StatType) int64

GetCurrentMonthSum 获取指定统计项在本月内的总和

func GetSumInRange

func GetSumInRange(key StatType, days int) int64

GetSumInRange 获取指定统计项在一段时间内的总和

func Increment

func Increment(date time.Time, key StatType, delta int64) error

Increment 增加统计值 (Upsert)

func InitStats

func InitStats(date time.Time, key StatType) error

InitStats 初始化某天的统计项(如果不存在则创建,初始值为 0)

func SetValue

func SetValue(date time.Time, key StatType, value int64) error

SetValue 直接设置统计值 (用于修复数据)

Types

type Entity

type Entity struct {
	StatDate  time.Time `gorm:"primaryKey;column:stat_date;type:date;not null;" json:"statDate"`       // 日期,格式 YYYY-MM-DD
	StatKey   string    `gorm:"primaryKey;column:stat_key;type:varchar(128);not null;" json:"statKey"` // 统计项的 Key (带前缀)
	StatValue int64     `gorm:"column:stat_value;type:bigint;not null;default:0;" json:"statValue"`    // 统计数值
}

func GetStatsInRange

func GetStatsInRange(keys []StatType, startDate, endDate string) ([]*Entity, error)

GetStatsInRange 获取指定时间范围内的统计项列表

func (*Entity) TableName

func (itself *Entity) TableName() string

type StatType

type StatType string

StatType 统计项枚举

const (
	StatTypeRegCount     StatType = "reg_count"     // 注册用户数
	StatTypeArticleCount StatType = "article_count" // 帖子发布数
	StatTypeReplyCount   StatType = "reply_count"   // 回复发布数
)

Jump to

Keyboard shortcuts

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