You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
package service
|
|
|
|
import (
|
|
"errors"
|
|
"main_program/common"
|
|
"main_program/config"
|
|
"main_program/entity"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type srtFileService struct{}
|
|
|
|
var SrtFileService srtFileService
|
|
|
|
func (srt *srtFileService) QueryOneNotScanVideoId() (videoId string, err error) {
|
|
var srtFile entity.Srtfile
|
|
result := common.MysqlDB.Where(&entity.Srtfile{IsScan: 0}).First(&srtFile)
|
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
|
return "", errors.New("no srtFile")
|
|
} else {
|
|
return srtFile.VideoId, nil
|
|
}
|
|
}
|
|
|
|
func (srt *srtFileService) QuerySrtFilesByVideoId(videoId string) (srtFiles []entity.Srtfile, err error) {
|
|
var srtFileEntitys []entity.Srtfile
|
|
result := common.MysqlDB.Where(&entity.Srtfile{VideoId: videoId}).Find(&srtFileEntitys)
|
|
if result.Error != nil {
|
|
return nil, errors.New("query srtFiles failed")
|
|
} else {
|
|
return srtFileEntitys, nil
|
|
}
|
|
}
|
|
|
|
func (srt *srtFileService) QueryOneNotScanVideoIdByRegion(region string) (videoId string, err error) {
|
|
var srtFile entity.Srtfile
|
|
sqlStr := "SELECT Srtfile.* FROM Srtfile JOIN Channel ON Srtfile.channelId = Channel.channelId WHERE Channel.region = ? and Srtfile.isScan = 0 limit 1;"
|
|
result := common.MysqlDB.Raw(sqlStr, region).First(&srtFile)
|
|
if result.Error != nil {
|
|
return "", errors.New("no srtFile")
|
|
} else {
|
|
return srtFile.VideoId, nil
|
|
}
|
|
}
|
|
|
|
func (srt *srtFileService) UpdateIsScanById(id int, isScan int) (err error) {
|
|
result := common.MysqlDB.Model(&entity.Srtfile{Id: uint(id)}).Update("isScan", isScan)
|
|
if result.Error != nil {
|
|
config.Logger.Error(result.Error)
|
|
return errors.New("update srtFile failed")
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|