package models import ( sql2 "database/sql" "eta/eta_api/global" "eta/eta_api/utils" "github.com/rdlucklib/rdluck_tools/paging" "time" ) // EnglishVideoCover 英文研报视频封面库 type EnglishVideoCover struct { Id int `gorm:"column:id;primaryKey;autoIncrement" description:"封面ID"` CoverName string `description:"封面名称"` CoverUrl string `description:"封面图地址"` IsDeleted int `description:"是否已删除 0-否 1-是"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` DeleteTime time.Time `description:"删除时间"` } func (item *EnglishVideoCover) TableName() string { return "english_video_cover" } func (item *EnglishVideoCover) Add() (err error) { err = global.DbMap[utils.DbNameReport].Create(item).Error return } func (item *EnglishVideoCover) Update(cols []string) (err error) { err = global.DbMap[utils.DbNameReport].Select(cols).Updates(item).Error return } // GetEnglishVideoCoverById 主键获取封面 func GetEnglishVideoCoverById(coverId int) (item *EnglishVideoCover, err error) { sql := `SELECT * FROM english_video_cover WHERE id = ? AND is_deleted = 0 LIMIT 1` err = global.DbMap[utils.DbNameReport].Raw(sql, coverId).First(&item).Error return } // GetEnglishVideoCoverPageList 获取封面库分页列表 func GetEnglishVideoCoverPageList(condition string, pars []interface{}, orderRule string, startSize, pageSize int) (total int, list []*EnglishVideoCover, err error) { sql := `SELECT * FROM english_video_cover WHERE is_deleted = 0 ` sql += condition if orderRule == "" { orderRule = ` ORDER BY modify_time DESC` } sql += orderRule totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z` var totalNull sql2.NullInt64 err = global.DbMap[utils.DbNameReport].Raw(totalSql, pars...).Scan(&totalNull).Error if err != nil { return } if totalNull.Valid { total = int(totalNull.Int64) } sql += ` LIMIT ?,?` pars = append(pars, startSize, pageSize) err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&list).Error return } // DeleteEnglishVideoCover 删除封面 func DeleteEnglishVideoCover(coverId int) (err error) { sql := `UPDATE english_video_cover SET is_deleted = 1, delete_time = NOW() WHERE id = ? LIMIT 1` err = global.DbMap[utils.DbNameReport].Exec(sql, coverId).Error return } type EnglishVideoCoverListResp struct { Paging *paging.PagingItem List []*EnglishVideoCoverItem `description:"列表数据"` } type EnglishVideoCoverItem struct { Id int `description:"封面ID"` CoverName string `description:"封面名称"` CoverUrl string `description:"封面图地址"` CreateTime string `description:"提问时间"` ModifyTime string `description:"修改时间"` } type EnglishVideoCoverSaveReq struct { Id int `description:"封面ID"` CoverName string `description:"封面名称"` CoverUrl string `description:"封面图地址"` } type EnglishVideoCoverOptionReq struct { Id int `description:"封面图ID"` }