43 lines
950 B
Go
43 lines
950 B
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
|
||
BaseModel[model.AiSession]
|
||
}
|
||
|
||
func NewSessionImpl(db *utils.Db) *SessionImpl {
|
||
return &SessionImpl{
|
||
DataTemp: *dataTemp.NewDataTemp(db, new(model.AiSession)),
|
||
BaseModel: BaseModel[model.AiSession]{},
|
||
}
|
||
}
|
||
|
||
// 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)
|
||
}
|
||
}
|