49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package impl
|
||
|
||
import (
|
||
"ai_scheduler/internal/data/model"
|
||
"ai_scheduler/tmpl/dataTemp"
|
||
"ai_scheduler/utils"
|
||
"gorm.io/gorm"
|
||
"time"
|
||
)
|
||
|
||
type SessionImpl struct {
|
||
dataTemp.DataTemp
|
||
BaseRepository[model.AiSession]
|
||
}
|
||
|
||
func NewSessionImpl(db *utils.Db) *SessionImpl {
|
||
return &SessionImpl{
|
||
DataTemp: *dataTemp.NewDataTemp(db, new(model.AiSession)),
|
||
BaseRepository: NewBaseModel[model.AiSession](db.Client),
|
||
}
|
||
}
|
||
|
||
// WithUserId 条件:用户ID
|
||
func (impl *SessionImpl) WithUserId(userId interface{}) CondFunc {
|
||
return func(db *gorm.DB) *gorm.DB {
|
||
return db.Where("user_id = ?", userId)
|
||
}
|
||
}
|
||
|
||
// WithStartTime 条件:会话开始时间
|
||
func (impl *SessionImpl) WithStartTime(startTime time.Time) CondFunc {
|
||
return func(db *gorm.DB) *gorm.DB {
|
||
return db.Where("create_at >= ?", startTime)
|
||
}
|
||
}
|
||
|
||
// WithSysId 系统id
|
||
func (s *SessionImpl) WithSysId(sysId interface{}) CondFunc {
|
||
return func(db *gorm.DB) *gorm.DB {
|
||
return db.Where("sys_id = ?", sysId)
|
||
}
|
||
}
|
||
|
||
func (impl *SessionImpl) WithSessionId(sessionId interface{}) CondFunc {
|
||
return func(db *gorm.DB) *gorm.DB {
|
||
return db.Where("session_id = ?", sessionId)
|
||
}
|
||
}
|