model

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConstraint

func CreateConstraint(db *gorm.DB, constraint *Constraint) error

CreateConstraint 创建约束

func CreateTag

func CreateTag(db *gorm.DB, tag *Tag) error

CreateTag 新增一个标签

func CreateTask

func CreateTask(db *gorm.DB, task *Task) error

CreateTask 创建任务

func CreateTimeLog

func CreateTimeLog(db *gorm.DB, tl *TimeLog) error

CreateTimeLog 新增一条时间日志

func DeleteConstraint

func DeleteConstraint(db *gorm.DB, id uint) error

DeleteConstraint 删除约束 (软删除)

func DeleteTag

func DeleteTag(db *gorm.DB, id uint) error

DeleteTag 删除标签

func DeleteTask

func DeleteTask(db *gorm.DB, id uint) error

DeleteTask 删除任务 (软删除)

func DeleteTimeLog

func DeleteTimeLog(db *gorm.DB, id uint) error

DeleteTimeLog 删除时间日志

func GetSingaporeLocation

func GetSingaporeLocation() *time.Location

GetSingaporeLocation 返回新加坡时区,供其他包使用

func GetTaskStats

func GetTaskStats(db *gorm.DB, date time.Time) (map[string]interface{}, error)

GetTaskStats 获取任务统计信息

func InitDao

func InitDao(cfg *config.Config, loggerInstance logger.Logger)

func MarkConstraintAsActive

func MarkConstraintAsActive(db *gorm.DB, constraintID uint) error

MarkConstraintAsActive 重新激活约束

func MarkConstraintAsCompleted

func MarkConstraintAsCompleted(db *gorm.DB, constraintID uint, endReason string) error

MarkConstraintAsCompleted 标记约束为完成

func MarkTaskAsCompleted

func MarkTaskAsCompleted(db *gorm.DB, taskID uint) error

MarkTaskAsCompleted 标记任务为完成

func MarkTaskAsIncomplete

func MarkTaskAsIncomplete(db *gorm.DB, taskID uint) error

MarkTaskAsIncomplete 标记任务为未完成

func SuspendTask

func SuspendTask(db *gorm.DB, taskID uint) error

SuspendTask 暂停任务

func UnsuspendTask

func UnsuspendTask(db *gorm.DB, taskID uint) error

UnsuspendTask 取消暂停任务

func UpdateConstraint

func UpdateConstraint(db *gorm.DB, constraint *Constraint) error

UpdateConstraint 更新约束

func UpdateTag

func UpdateTag(db *gorm.DB, tag *Tag) error

UpdateTag 更新标签

func UpdateTask

func UpdateTask(db *gorm.DB, task *Task) error

UpdateTask 更新任务

func UpdateTimeLog

func UpdateTimeLog(db *gorm.DB, tl *TimeLog) error

UpdateTimeLog 更新时间日志

Types

type Constraint

type Constraint struct {
	ID              uint           `gorm:"primaryKey" json:"id"`
	Description     string         `gorm:"column:description;not null;type:text" json:"description"`
	EndReason       string         `gorm:"column:end_reason;type:text" json:"end_reason"`
	PunishmentQuote string         `gorm:"column:punishment_quote;not null;type:text" json:"punishment_quote"`
	StartDate       time.Time      `gorm:"column:start_date;not null" json:"start_date"`
	EndDate         *time.Time     `gorm:"column:end_date" json:"end_date"`
	IsActive        bool           `gorm:"column:is_active;default:true" json:"is_active"`
	CreatedAt       time.Time      `json:"created_at"`
	UpdatedAt       time.Time      `json:"updated_at"`
	DeletedAt       gorm.DeletedAt `gorm:"index" json:"-"`
}

func GetActiveConstraints

func GetActiveConstraints(db *gorm.DB) ([]Constraint, error)

GetActiveConstraints 获取活跃的约束

func GetAllConstraints

func GetAllConstraints(db *gorm.DB) ([]Constraint, error)

GetAllConstraints 获取所有约束

func GetConstraintByID

func GetConstraintByID(db *gorm.DB, id uint) (*Constraint, error)

GetConstraintByID 根据ID获取约束

func GetConstraintsByDateRange

func GetConstraintsByDateRange(db *gorm.DB, startDate, endDate time.Time) ([]Constraint, error)

GetConstraintsByDateRange 根据日期范围获取约束

func (Constraint) TableName

func (Constraint) TableName() string

type DBProvider

type DBProvider interface {
	Db() *gorm.DB
}

type Dao

type Dao struct {
	RawDB *sql.DB
	// contains filtered or unexported fields
}

func GetDao

func GetDao() *Dao

func (*Dao) AdminGetAllCache

func (d *Dao) AdminGetAllCache()

func (*Dao) Begin

func (d *Dao) Begin() *TxDao

func (*Dao) Db

func (d *Dao) Db() *gorm.DB

func (*Dao) GetCache

func (d *Dao) GetCache(key string) (any, bool)

func (*Dao) WriteCache

func (d *Dao) WriteCache(key string, value any, seconds int64)

type Model

type Model struct {
	*gorm.Model
}

type Tag

type Tag struct {
	ID          uint           `gorm:"primaryKey" json:"id"`
	Name        string         `gorm:"column:name;not null;unique" json:"name"`
	Color       string         `gorm:"column:color" json:"color"`
	Description string         `gorm:"column:description" json:"description"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"-"`
}

Tag 表示一个标签

func GetTagByID

func GetTagByID(db *gorm.DB, id uint) (*Tag, error)

GetTagByID 根据ID获取标签

func GetTagByName

func GetTagByName(db *gorm.DB, name string) (*Tag, error)

GetTagByName 根据名称获取标签

func ListTags

func ListTags(db *gorm.DB, conds ...interface{}) ([]Tag, error)

ListTags 查询标签列表

func (Tag) TableName

func (Tag) TableName() string

type Task

type Task struct {
	ID               uint           `gorm:"primaryKey" json:"id"`
	Title            string         `gorm:"column:title;not null;size:200" json:"title"`
	Description      string         `gorm:"column:description;type:text" json:"description"`
	TagID            uint           `gorm:"column:tag_id;not null" json:"tag_id"`
	Tag              Tag            `gorm:"foreignKey:TagID" json:"tag"`
	DueDate          time.Time      `gorm:"column:due_date;not null" json:"due_date"`
	EstimatedMinutes int            `gorm:"column:estimated_minutes;not null" json:"estimated_minutes"`
	IsCompleted      bool           `gorm:"column:is_completed;default:false" json:"is_completed"`
	CompletedAt      *time.Time     `gorm:"column:completed_at" json:"completed_at"`
	IsSuspended      bool           `gorm:"column:is_suspended;default:false" json:"is_suspended"`
	CreatedAt        time.Time      `json:"created_at"`
	UpdatedAt        time.Time      `json:"updated_at"`
	DeletedAt        gorm.DeletedAt `gorm:"index" json:"-"`
}

func GetAllTasks

func GetAllTasks(db *gorm.DB, includeSuspended bool, includeCompleted bool) ([]Task, error)

GetAllTasks 获取所有任务 includeSuspended: 是否包含暂停的任务 includeCompleted: 是否包含已完成的任务

func GetCompletedTasksInDateRange

func GetCompletedTasksInDateRange(db *gorm.DB, startDate, endDate time.Time) ([]Task, error)

GetCompletedTasksInDateRange 获取指定日期范围内的已完成任务

func GetTaskByID

func GetTaskByID(db *gorm.DB, id uint) (*Task, error)

GetTaskByID 根据ID获取任务

func GetTasksByDate

func GetTasksByDate(db *gorm.DB, date time.Time, includeSuspended bool, includeCompleted bool) ([]Task, error)

GetTasksByDate 根据日期获取任务 includeSuspended: 是否包含暂停的任务 includeCompleted: 是否包含已完成的任务

func GetTasksByDateRange

func GetTasksByDateRange(db *gorm.DB, startDate, endDate time.Time) ([]Task, error)

GetTasksByDateRange 根据日期范围获取任务

func (Task) TableName

func (Task) TableName() string

type TimeLog

type TimeLog struct {
	gorm.Model
	UserID    uint       `gorm:"column:user_id" json:"user_id"`
	StartTime time.Time  `gorm:"column:start_time" json:"start_time"`
	EndTime   *time.Time `gorm:"column:end_time" json:"end_time"`
	TagID     uint       `gorm:"column:tag_id" json:"tag_id"`
	Tag       Tag        `gorm:"foreignKey:TagID" json:"tag"`
	TaskID    *uint      `gorm:"column:task_id" json:"task_id,omitempty"`
	Task      *Task      `gorm:"foreignKey:TaskID" json:"task,omitempty"`
	Remark    string     `gorm:"column:remark" json:"remarks"`
}

func GetTimeLogByID

func GetTimeLogByID(db *gorm.DB, id uint) (*TimeLog, error)

GetTimeLogByID 根据ID获取时间日志

func ListTimeLogs

func ListTimeLogs(db *gorm.DB, conds ...interface{}) ([]TimeLog, error)

ListTimeLogs 查询时间日志(可扩展条件)

func ListTimeLogsByLocalDateRange

func ListTimeLogsByLocalDateRange(db *gorm.DB, startDateStr, endDateStr string) ([]TimeLog, error)

ListTimeLogsByLocalDateRange 根据本地日期范围查询时间日志 startDateStr 和 endDateStr 格式为 "YYYY-MM-DD",会被解析为新加坡时区 数据库存储的是 UTC 时间,该函数会自动转换

func ListTimeLogsWithOptions

func ListTimeLogsWithOptions(db *gorm.DB, limit int, orderBy string, conds ...interface{}) ([]TimeLog, error)

ListTimeLogsWithOptions 查询时间日志(支持排序和限制)

func (TimeLog) TableName

func (TimeLog) TableName() string

type TxDao

type TxDao struct {
	*Dao
	// contains filtered or unexported fields
}

func (*TxDao) Commit

func (tx *TxDao) Commit() error

func (*TxDao) Db

func (tx *TxDao) Db() *gorm.DB

func (*TxDao) Rollback

func (tx *TxDao) Rollback() error

Jump to

Keyboard shortcuts

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