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.

56 lines
1.6 KiB

package service
import (
"errors"
"main_program/common"
5 months ago
"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
}
}
5 months ago
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
5 months ago
sqlStr := "SELECT Srtfile.* FROM Srtfile JOIN Channel ON Srtfile.channelId = Channel.channelId WHERE Channel.region = ? and Srtfile.isScan = 0 limit 1;"
5 months ago
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
}
}