Files
backend/internal/model/schedule_course.go

33 lines
1.0 KiB
Go
Raw Normal View History

package model
import (
"time"
"gorm.io/gorm"
)
// ScheduleCourse 用户课表课程
type ScheduleCourse struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
UserID string `json:"user_id" gorm:"type:varchar(36);index;not null"`
Name string `json:"name" gorm:"type:varchar(120);not null"`
Teacher string `json:"teacher" gorm:"type:varchar(80)"`
Location string `json:"location" gorm:"type:varchar(120)"`
DayOfWeek int `json:"day_of_week" gorm:"index;not null"` // 0=周一, 6=周日
StartSection int `json:"start_section" gorm:"not null"`
EndSection int `json:"end_section" gorm:"not null"`
Weeks string `json:"weeks" gorm:"type:text;not null"` // JSON 数组字符串
Color string `json:"color" gorm:"type:varchar(20)"`
CreatedAt time.Time
UpdatedAt time.Time
}
func (s *ScheduleCourse) BeforeCreate(tx *gorm.DB) error {
refactor: improve system stability, performance, and code structure This commit introduces several architectural improvements and optimizations across the codebase: - **Performance & Reliability**: - Implemented Redis pipelining in `ConversationCache.CacheMessage` to reduce network round-trips. - Added a circuit breaker to the JPush client to prevent cascading failures. - Introduced batch deletion and batch member addition capabilities in repositories. - Added message idempotency support using `client_msg_id` and a Redis-based cache. - Optimized WebSocket handling with connection limits (total and per-user) and improved error logging. - **Code Refactoring**: - Refactored `Router` to use a `RouterDeps` struct, simplifying the constructor and improving maintainability. - Unified model ID generation logic using new `id_helper.go` (supporting UUID and Snowflake). - Standardized JSON serialization/deserialization in models using `json_helper.go`. - Refactored DTO conversion logic, specifically for `UserResponse` (using functional options) and `Report` responses. - Removed redundant/deprecated DTOs like `PostDetailResponse` and `TradeItemDetailResponse`. - **Cache Improvements**: - Enhanced `LayeredCache` with `SetRaw` to avoid double-encoding when promoting values from Redis to local cache. - Added `DeleteBatch` support to the cache interface. - **Other Changes**: - Cleaned up `config.go` by removing redundant default values and explicit environment variable overrides. - Improved WebSocket registration flow to handle connection limits gracefully.
2026-05-04 13:07:03 +08:00
SetUUIDIfEmpty(&s.ID)
return nil
}
func (ScheduleCourse) TableName() string {
return "schedule_courses"
}